WordPress.org

Make WordPress Core

Ticket #27881: 27881-user.diff

File 27881-user.diff, 5.7 KB (added by wonderboymusic, 6 years ago)
  • src/wp-includes/user.php

     
    16431643        } else {
    16441644                $user_nicename = $userdata['user_nicename'];
    16451645        }
     1646
     1647        // store values to save in user meta
     1648        $meta = array();
     1649
    16461650        /**
    16471651         * Filter a user's nicename before the user is created or updated.
    16481652         *
     
    16521656         */
    16531657        $user_nicename = apply_filters( 'pre_user_nicename', $user_nicename );
    16541658
    1655         $user_url = empty( $userdata['user_url'] ) ? '' : $userdata['user_url'];
     1659        $raw_user_url = empty( $userdata['user_url'] ) ? '' : $userdata['user_url'];
    16561660
    16571661        /**
    16581662         * Filter a user's URL before the user is created or updated.
     
    16611665         *
    16621666         * @param string $user_url The user's URL.
    16631667         */
    1664         $user_url = apply_filters( 'pre_user_url', $user_url );
     1668        $user_url = apply_filters( 'pre_user_url', $raw_user_url );
    16651669
    1666         $user_email = empty( $userdata['user_email'] ) ? '' : $userdata['user_email'];
     1670        $raw_user_email = empty( $userdata['user_email'] ) ? '' : $userdata['user_email'];
    16671671
    16681672        /**
    16691673         * Filter a user's email before the user is created or updated.
     
    16721676         *
    16731677         * @param string $user_email The user's email.
    16741678         */
    1675         $user_email = apply_filters( 'pre_user_email', $user_email );
     1679        $user_email = apply_filters( 'pre_user_email', $raw_user_email );
    16761680
    16771681        if ( ! $update && ! defined( 'WP_IMPORTING' ) && email_exists( $user_email ) ) {
    16781682                return new WP_Error( 'existing_user_email', __( 'Sorry, that email address is already used!' ) );
     
    16851689         *
    16861690         * @param string $nickname The user's nickname.
    16871691         */
    1688         $nickname = apply_filters( 'pre_user_nickname', $nickname );
     1692        $meta['nickname'] = apply_filters( 'pre_user_nickname', $nickname );
    16891693
    16901694        $first_name = empty( $userdata['first_name'] ) ? '' : $userdata['first_name'];
    16911695
     
    16961700         *
    16971701         * @param string $first_name The user's first name.
    16981702         */
    1699         $first_name = apply_filters( 'pre_user_first_name', $first_name );
     1703        $meta['first_name'] = apply_filters( 'pre_user_first_name', $first_name );
    17001704
    17011705        $last_name = empty( $userdata['last_name'] ) ? '' : $userdata['last_name'];
    17021706
     
    17071711         *
    17081712         * @param string $last_name The user's last name.
    17091713         */
    1710         $last_name = apply_filters( 'pre_user_last_name', $last_name );
     1714        $meta['last_name'] = apply_filters( 'pre_user_last_name', $last_name );
    17111715
    17121716        if ( empty( $userdata['display_name'] ) ) {
    17131717                if ( $update ) {
    17141718                        $display_name = $user_login;
    1715                 } elseif ( $first_name && $last_name ) {
     1719                } elseif ( $meta['first_name'] && $meta['last_name'] ) {
    17161720                        /* translators: 1: first name, 2: last name */
    1717                         $display_name = sprintf( _x( '%1$s %2$s', 'Display name based on first name and last name' ), $first_name, $last_name );
    1718                 } elseif ( $first_name ) {
    1719                         $display_name = $first_name;
    1720                 } elseif ( $last_name ) {
    1721                         $display_name = $last_name;
     1721                        $display_name = sprintf( _x( '%1$s %2$s', 'Display name based on first name and last name' ), $meta['first_name'], $meta['last_name'] );
     1722                } elseif ( $meta['first_name'] ) {
     1723                        $display_name = $meta['first_name'];
     1724                } elseif ( $meta['last_name'] ) {
     1725                        $display_name = $meta['last_name'];
    17221726                } else {
    17231727                        $display_name = $user_login;
    17241728                }
     
    17441748         *
    17451749         * @param string $description The user's description.
    17461750         */
    1747         $description = apply_filters( 'pre_user_description', $description );
     1751        $meta['description'] = apply_filters( 'pre_user_description', $description );
    17481752
    1749         $rich_editing = empty( $userdata['rich_editing'] ) ? 'true' : $userdata['rich_editing'];
     1753        $meta['rich_editing'] = empty( $userdata['rich_editing'] ) ? 'true' : $userdata['rich_editing'];
    17501754
    1751         $comment_shortcuts = empty( $userdata['comment_shortcuts'] ) ? 'false' : $userdata['comment_shortcuts'];
     1755        $meta['comment_shortcuts'] = empty( $userdata['comment_shortcuts'] ) ? 'false' : $userdata['comment_shortcuts'];
    17521756
    17531757        $admin_color = empty( $userdata['admin_color'] ) ? 'fresh' : $userdata['admin_color'];
    1754         $admin_color = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $admin_color );
     1758        $meta['admin_color'] = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $admin_color );
    17551759
    1756         $use_ssl = empty( $userdata['use_ssl'] ) ? 0 : $userdata['use_ssl'];
     1760        $meta['use_ssl'] = empty( $userdata['use_ssl'] ) ? 0 : $userdata['use_ssl'];
    17571761
    17581762        $user_registered = empty( $userdata['user_registered'] ) ? gmdate( 'Y-m-d H:i:s' ) : $userdata['user_registered'];
    17591763
    1760         $show_admin_bar_front = empty( $userdata['show_admin_bar_front'] ) ? 'true' : $userdata['show_admin_bar_front'];
     1764        $meta['show_admin_bar_front'] = empty( $userdata['show_admin_bar_front'] ) ? 'true' : $userdata['show_admin_bar_front'];
    17611765
    17621766        $user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1" , $user_nicename, $user_login));
    17631767
     
    17711775                $user_nicename = $alt_user_nicename;
    17721776        }
    17731777
    1774         $data = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' );
    1775         $data = wp_unslash( $data );
     1778        $compacted = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' );
     1779        $data = wp_unslash( $compacted );
    17761780
    17771781        if ( $update ) {
    17781782                $wpdb->update( $wpdb->users, $data, compact( 'ID' ) );
     
    17841788
    17851789        $user = new WP_User( $user_id );
    17861790
    1787         foreach ( _get_additional_user_keys( $user ) as $key ) {
    1788                 if ( isset( $$key ) ) {
    1789                         update_user_meta( $user_id, $key, $$key );
     1791        foreach ( $meta as $key => $value ) {
     1792                update_user_meta( $user_id, $key, $value );
     1793        }
     1794
     1795        foreach ( wp_get_user_contact_methods( $user ) as $key => $value ) {
     1796                if ( isset( $userdata[ $key ] ) ) {
     1797                        update_user_meta( $user_id, $key, $userdata[ $key ] );
    17901798                }
    17911799        }
    17921800