pre_user_login

Filters the user_login, also known as the username, before it is added to the site.

Description

apply_filters( 'pre_user_login', (bool) $sanitize_user ); 

Parameters (1)

0. $sanitize_user (bool) => sanitize_user( wp_unslash( $_REQUEST['user_login'] ), true )
The sanitized username.

Usage

To run the hook, copy the example below.
  1. $sanitize_user = apply_filters( 'pre_user_login', $sanitize_user ); 
  2.  
  3. if ( !empty( $sanitize_user ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the pre_user_login callback 
  2. function filter_pre_user_login( $sanitize_user ) { 
  3. // make filter magic happen here... 
  4. return $sanitize_user
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'pre_user_login', 'filter_pre_user_login', 10, 1 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'pre_user_login', 'filter_pre_user_login', 10, 1 ); 

Defined (2)

The filter is defined in the following location(s).

/wp-admin/user-new.php  
  1. $new_user_login = apply_filters( 'pre_user_login', sanitize_user( wp_unslash( $_REQUEST['user_login'] ), true ) ); 
/wp-includes/user.php  
  1. $pre_user_login = apply_filters( 'pre_user_login', $sanitized_user_login );