Record and Show the Registration IP Address
Saves the IP address each new account was created from and shows it in the Users list, which helps spot bulk fake sign-ups.
Opens WPIDE on
Code
add_action( 'user_register', function ( $user_id ) {
if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
$ip = filter_var( wp_unslash( $_SERVER['REMOTE_ADDR'] ), FILTER_VALIDATE_IP );
if ( $ip ) {
update_user_meta( $user_id, 'wpide_registration_ip', $ip );
}
}
} );
add_filter( 'manage_users_columns', function ( $columns ) {
if ( current_user_can( 'manage_options' ) ) {
$columns['wpide_reg_ip'] = 'Registration IP';
}
return $columns;
} );
add_filter( 'manage_users_custom_column', function ( $output, $column, $user_id ) {
if ( 'wpide_reg_ip' === $column ) {
$ip = get_user_meta( $user_id, 'wpide_registration_ip', true );
return $ip ? '<code>' . esc_html( $ip ) . '</code>' : '—';
}
return $output;
}, 10, 3 );
Notes
IP addresses are personal data, so mention them in your privacy policy (behind a proxy you may see the proxy address).
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.