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
This commit is contained in:
desrosj 2021-05-25 17:39:57 +00:00
parent b797aa3b53
commit a07a6490ab
2 changed files with 18 additions and 10 deletions

View File

@ -2012,6 +2012,7 @@ function wp_insert_user( $userdata ) {
* It only includes data in the users table, not any user metadata. * It only includes data in the users table, not any user metadata.
* *
* @since 4.9.0 * @since 4.9.0
* @since 5.8.0 The $userdata parameter was added.
* *
* @param array $data { * @param array $data {
* Values and keys for the user. * 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 * @type string $user_registered MySQL timestamp describing the moment when the user registered. Defaults to
* the current UTC timestamp. * the current UTC timestamp.
* } * }
* @param bool $update Whether the user is being updated rather than 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 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 ) ) { if ( empty( $data ) || ! is_array( $data ) ) {
return new WP_Error( 'empty_data', __( 'Not enough data to create this user.' ) ); 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 )`. * Does not include contact methods. These are added using `wp_get_user_contact_methods( $user )`.
* *
* @since 4.4.0 * @since 4.4.0
* @since 5.8.0 The $userdata parameter was added.
* *
* @param array $meta { * @param array $meta {
* Default meta values and keys for the user. * Default meta values and keys for the user.
@ -2072,10 +2075,11 @@ function wp_insert_user( $userdata ) {
* Default 'true'. * Default 'true'.
* @type string $locale User's locale. Default empty. * @type string $locale User's locale. Default empty.
* } * }
* @param WP_User $user User object. * @param WP_User $user User object.
* @param bool $update Whether the user is being updated rather than created. * @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. // Update user meta.
foreach ( $meta as $key => $value ) { foreach ( $meta as $key => $value ) {
@ -2101,11 +2105,13 @@ function wp_insert_user( $userdata ) {
* Fires immediately after an existing user is updated. * Fires immediately after an existing user is updated.
* *
* @since 2.0.0 * @since 2.0.0
* @since 5.8.0 The $userdata parameter was added.
* *
* @param int $user_id User ID. * @param int $user_id User ID.
* @param WP_User $old_user_data Object containing user's data prior to update. * @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 ( isset( $userdata['spam'] ) && $userdata['spam'] != $old_user_data->spam ) {
if ( 1 == $userdata['spam'] ) { if ( 1 == $userdata['spam'] ) {
@ -2133,10 +2139,12 @@ function wp_insert_user( $userdata ) {
* Fires immediately after a new user is registered. * Fires immediately after a new user is registered.
* *
* @since 1.5.0 * @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; return $user_id;

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @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. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.