WordPress.org

Make WordPress Core

Changeset 51005


Ignore:
Timestamp:
05/25/2021 05:38:30 PM (5 months ago)
Author:
desrosj
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user.php

    r50981 r51005  
    20132013     *
    20142014     * @since 4.9.0
     2015     * @since 5.8.0 The $userdata parameter was added.
    20152016     *
    20162017     * @param array    $data {
     
    20262027     *                                   the current UTC timestamp.
    20272028     * }
    2028      * @param bool     $update Whether the user is being updated rather than created.
    2029      * @param int|null $id     ID of the user to be updated, or NULL if the user is being created.
    2030      */
    2031     $data = apply_filters( 'wp_pre_insert_user_data', $data, $update, $update ? (int) $ID : null );
     2029     * @param bool     $update   Whether the user is being updated rather than created.
     2030     * @param int|null $id       ID of the user to be updated, or NULL if the user is being created.
     2031     * @param array    $userdata The raw array of data passed to wp_insert_user().
     2032     */
     2033    $data = apply_filters( 'wp_pre_insert_user_data', $data, $update, ( $update ? (int) $ID : null ), $userdata );
    20322034
    20332035    if ( empty( $data ) || ! is_array( $data ) ) {
     
    20552057     *
    20562058     * @since 4.4.0
     2059     * @since 5.8.0 The $userdata parameter was added.
    20572060     *
    20582061     * @param array $meta {
     
    20732076     *     @type string   $locale               User's locale. Default empty.
    20742077     * }
    2075      * @param WP_User $user   User object.
    2076      * @param bool    $update Whether the user is being updated rather than created.
    2077      */
    2078     $meta = apply_filters( 'insert_user_meta', $meta, $user, $update );
     2078     * @param WP_User $user     User object.
     2079     * @param bool    $update   Whether the user is being updated rather than created.
     2080     * @param array   $userdata The raw array of data passed to wp_insert_user().
     2081     */
     2082    $meta = apply_filters( 'insert_user_meta', $meta, $user, $update, $userdata );
    20792083
    20802084    // Update user meta.
     
    21022106         *
    21032107         * @since 2.0.0
     2108         * @since 5.8.0 The $userdata parameter was added.
    21042109         *
    21052110         * @param int     $user_id       User ID.
    21062111         * @param WP_User $old_user_data Object containing user's data prior to update.
     2112         * @param array   $userdata      The raw array of data passed to wp_insert_user().
    21072113         */
    2108         do_action( 'profile_update', $user_id, $old_user_data );
     2114        do_action( 'profile_update', $user_id, $old_user_data, $userdata );
    21092115
    21102116        if ( isset( $userdata['spam'] ) && $userdata['spam'] != $old_user_data->spam ) {
     
    21342140         *
    21352141         * @since 1.5.0
     2142         * @since 5.8.0 The $userdata parameter was added.
    21362143         *
    2137          * @param int $user_id User ID.
     2144         * @param int   $user_id  User ID.
     2145         * @param array $userdata The raw array of data passed to wp_insert_user().
    21382146         */
    2139         do_action( 'user_register', $user_id );
     2147        do_action( 'user_register', $user_id, $userdata );
    21402148    }
    21412149
Note: See TracChangeset for help on using the changeset viewer.