Record Where Each User Signed Up
Notes how every new account was created (registration form, admin screen, checkout, REST API or WP-CLI) and shows it in a "Signed up via" column on the Users screen.
Opens WPIDE on
Code
add_action( 'user_register', function ( $user_id ) {
if ( defined( 'WP_CLI' ) && WP_CLI ) {
$source = 'WP-CLI';
} elseif ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
$source = 'REST API';
} elseif ( did_action( 'woocommerce_checkout_process' ) || did_action( 'woocommerce_before_checkout_process' ) ) {
$source = 'Checkout';
} elseif ( is_admin() && current_user_can( 'create_users' ) && ! wp_doing_ajax() ) {
$source = 'Admin';
} elseif ( isset( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
$source = 'Registration form';
} else {
$source = 'Front-end form';
}
update_user_meta( $user_id, 'wpide_signup_source', $source );
} );
add_filter( 'manage_users_columns', function ( $columns ) {
$columns['wpide_signup_source'] = 'Signed up via';
return $columns;
} );
add_filter( 'manage_users_custom_column', function ( $output, $column, $user_id ) {
if ( 'wpide_signup_source' === $column ) {
$source = get_user_meta( $user_id, 'wpide_signup_source', true );
$output = $source ? esc_html( $source ) : '—';
}
return $output;
}, 10, 3 );
Notes
Only accounts created after activation are labelled.
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.