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:
parent
b797aa3b53
commit
a07a6490ab
|
@ -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.
|
||||||
|
@ -2027,8 +2028,9 @@ function wp_insert_user( $userdata ) {
|
||||||
* }
|
* }
|
||||||
* @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.
|
||||||
|
@ -2074,8 +2077,9 @@ function wp_insert_user( $userdata ) {
|
||||||
* }
|
* }
|
||||||
* @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;
|
||||||
|
|
|
@ -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.
|
||||||
|
|
Loading…
Reference in New Issue