From a07a6490ab40217c7d540959fd664dae9bb40567 Mon Sep 17 00:00:00 2001 From: desrosj Date: Tue, 25 May 2021 17:39:57 +0000 Subject: [PATCH] Users: Pass on the user data received by `wp_insert_user()` to related hooks. This adds a new parameter to the action and filter hooks found in `wp_insert_user()` to pass the raw user data received through `$userdata` to hooked functions. This will allow hooked functions to perform more contextual adjustments to new users, and makes supplying custom user meta fields possible. Props johnbillion, audrasjb. Fixes #53110. Built from https://develop.svn.wordpress.org/trunk@51005 git-svn-id: http://core.svn.wordpress.org/trunk@50614 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/user.php | 26 +++++++++++++++++--------- wp-includes/version.php | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/wp-includes/user.php b/wp-includes/user.php index 4b1fa4b34f..0d50c1f6e3 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -2012,6 +2012,7 @@ function wp_insert_user( $userdata ) { * 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. * * @param array $data { * Values and keys for the user. @@ -2025,10 +2026,11 @@ function wp_insert_user( $userdata ) { * @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. + * @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. + * @param array $userdata The raw array of data passed to wp_insert_user(). */ - $data = apply_filters( 'wp_pre_insert_user_data', $data, $update, $update ? (int) $ID : null ); + $data = apply_filters( 'wp_pre_insert_user_data', $data, $update, ( $update ? (int) $ID : null ), $userdata ); if ( empty( $data ) || ! is_array( $data ) ) { return new WP_Error( 'empty_data', __( 'Not enough data to create this user.' ) ); @@ -2054,6 +2056,7 @@ function wp_insert_user( $userdata ) { * Does not include contact methods. These are added using `wp_get_user_contact_methods( $user )`. * * @since 4.4.0 + * @since 5.8.0 The $userdata parameter was added. * * @param array $meta { * Default meta values and keys for the user. @@ -2072,10 +2075,11 @@ function wp_insert_user( $userdata ) { * Default 'true'. * @type string $locale User's locale. Default empty. * } - * @param WP_User $user User object. - * @param bool $update Whether the user is being updated rather than created. + * @param WP_User $user User object. + * @param bool $update Whether the user is being updated rather than created. + * @param array $userdata The raw array of data passed to wp_insert_user(). */ - $meta = apply_filters( 'insert_user_meta', $meta, $user, $update ); + $meta = apply_filters( 'insert_user_meta', $meta, $user, $update, $userdata ); // Update user meta. foreach ( $meta as $key => $value ) { @@ -2101,11 +2105,13 @@ function wp_insert_user( $userdata ) { * Fires immediately after an existing user is updated. * * @since 2.0.0 + * @since 5.8.0 The $userdata parameter was added. * * @param int $user_id User ID. * @param WP_User $old_user_data Object containing user's data prior to update. + * @param array $userdata The raw array of data passed to wp_insert_user(). */ - do_action( 'profile_update', $user_id, $old_user_data ); + do_action( 'profile_update', $user_id, $old_user_data, $userdata ); if ( isset( $userdata['spam'] ) && $userdata['spam'] != $old_user_data->spam ) { if ( 1 == $userdata['spam'] ) { @@ -2133,10 +2139,12 @@ function wp_insert_user( $userdata ) { * Fires immediately after a new user is registered. * * @since 1.5.0 + * @since 5.8.0 The $userdata parameter was added. * - * @param int $user_id User ID. + * @param int $user_id User ID. + * @param array $userdata The raw array of data passed to wp_insert_user(). */ - do_action( 'user_register', $user_id ); + do_action( 'user_register', $user_id, $userdata ); } return $user_id; diff --git a/wp-includes/version.php b/wp-includes/version.php index 9bfb8eddd5..000ab6c5be 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.8-alpha-51004'; +$wp_version = '5.8-alpha-51005'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.