Users: Allow data to be filtered before updating or creating a user.
Props DaveFX. Fixes #40545. git-svn-id: https://develop.svn.wordpress.org/trunk@40980 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
1721af83d1
commit
b3ed160bd1
|
@ -1642,6 +1642,34 @@ function wp_insert_user( $userdata ) {
|
||||||
$compacted = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' );
|
$compacted = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' );
|
||||||
$data = wp_unslash( $compacted );
|
$data = wp_unslash( $compacted );
|
||||||
|
|
||||||
|
if ( ! $update ) {
|
||||||
|
$data = $data + compact( 'user_login' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters user data before the record is created or updated.
|
||||||
|
*
|
||||||
|
* It only includes data in the wp_users table wp_user, not any user metadata.
|
||||||
|
*
|
||||||
|
* @since 4.9.0
|
||||||
|
*
|
||||||
|
* @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 $id ID of the user to be updated, or NULL if the user is being created.
|
||||||
|
*/
|
||||||
|
$data = apply_filters( 'wp_pre_insert_user_data', $data, $update, $update ? (int) $ID : null );
|
||||||
|
|
||||||
if ( $update ) {
|
if ( $update ) {
|
||||||
if ( $user_email !== $old_user_data->user_email ) {
|
if ( $user_email !== $old_user_data->user_email ) {
|
||||||
$data['user_activation_key'] = '';
|
$data['user_activation_key'] = '';
|
||||||
|
@ -1649,7 +1677,7 @@ function wp_insert_user( $userdata ) {
|
||||||
$wpdb->update( $wpdb->users, $data, compact( 'ID' ) );
|
$wpdb->update( $wpdb->users, $data, compact( 'ID' ) );
|
||||||
$user_id = (int) $ID;
|
$user_id = (int) $ID;
|
||||||
} else {
|
} else {
|
||||||
$wpdb->insert( $wpdb->users, $data + compact( 'user_login' ) );
|
$wpdb->insert( $wpdb->users, $data );
|
||||||
$user_id = (int) $wpdb->insert_id;
|
$user_id = (int) $wpdb->insert_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue