wp_pre_insert_user_data
Filter HookDescription
Filters user data before the record is created or updated. It only includes data in the users table, not any user metadata. the current UTC timestamp. }Hook Information
| File Location | wp-includes/user.phpView on GitHub | 
| Hook Type | Filter | 
| Line Number | 2477 | 
Hook Parameters
| Type | Name | Description | 
|---|---|---|
| array | $data | { Values and keys for the user. | 
| bool | $update | Whether the user is being updated rather than created. | 
| int|null | $user_id | ID of the user to be updated, or NULL if the user is being created. | 
| array | $userdata | The raw array of data passed to wp_insert_user(). | 
Usage Examples
                        Basic Usage
                    
                    <?php
// Hook into wp_pre_insert_user_data
add_filter('wp_pre_insert_user_data', 'my_custom_filter', 10, 4);
function my_custom_filter($data, $update, $user_id, $userdata) {
    // Your custom filtering logic here
    return $data;
}
Source Code Context
                        wp-includes/user.php:2477
                        - How this hook is used in WordPress core
                    
                    <?php
2472  	 * }
2473  	 * @param bool     $update   Whether the user is being updated rather than created.
2474  	 * @param int|null $user_id  ID of the user to be updated, or NULL if the user is being created.
2475  	 * @param array    $userdata The raw array of data passed to wp_insert_user().
2476  	 */
2477  	$data = apply_filters( 'wp_pre_insert_user_data', $data, $update, ( $update ? $user_id : null ), $userdata );
2478  
2479  	if ( empty( $data ) || ! is_array( $data ) ) {
2480  		return new WP_Error( 'empty_data', __( 'Not enough data to create this user.' ) );
2481  	}
2482  
PHP Documentation
<?php
/**
	 * Filters user data before the record is created or updated.
	 *
	 * It only includes data in the users table, not any user metadata.
	 *
	 * @since 4.9.0
	 * @since 5.8.0 The `$userdata` parameter was added.
	 * @since 6.8.0 The user's password is now hashed using bcrypt by default instead of phpass.
	 *
	 * @param array    $data {
	 *     Values and keys for the user.
	 *
	 *     @type string $user_login      The user's login. Only included if $update == false
	 *     @type string $user_pass       The user's password.
	 *     @type string $user_email      The user's email.
	 *     @type string $user_url        The user's url.
	 *     @type string $user_nicename   The user's nice name. Defaults to a URL-safe version of user's login.
	 *     @type string $display_name    The user's display name.
	 *     @type string $user_registered MySQL timestamp describing the moment when the user registered. Defaults to
	 *                                   the current UTC timestamp.
	 * }
	 * @param bool     $update   Whether the user is being updated rather than created.
	 * @param int|null $user_id  ID of the user to be updated, or NULL if the user is being created.
	 * @param array    $userdata The raw array of data passed to wp_insert_user().
	 */
                        Quick Info
                    
                    - Hook Type: Filter
- Parameters: 4
- File: wp-includes/user.php
                        Related Hooks
                    
                    Related hooks will be displayed here in future updates.
