WordPress.org

Make WordPress Core

Ticket #27881: 27881-user.2.diff

File 27881-user.2.diff, 5.9 KB (added by DrewAPicture, 6 years ago)

Docs tweaks

  • 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.
    16591663         *
    16601664         * @since 2.0.3
    16611665         *
    1662          * @param string $user_url The user's URL.
     1666         * @param string $raw_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.
    16701674         *
    16711675         * @since 2.0.3
    16721676         *
    1673          * @param string $user_email The user's email.
     1677         * @param string $raw_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!' ) );
    16791683        }
    16801684        $nickname = empty( $userdata['nickname'] ) ? $user_login : $userdata['nickname'];
     1685
    16811686        /**
    16821687         * Filter a user's nickname before the user is created or updated.
    16831688         *
     
    16851690         *
    16861691         * @param string $nickname The user's nickname.
    16871692         */
    1688         $nickname = apply_filters( 'pre_user_nickname', $nickname );
     1693        $meta['nickname'] = apply_filters( 'pre_user_nickname', $nickname );
    16891694
    16901695        $first_name = empty( $userdata['first_name'] ) ? '' : $userdata['first_name'];
    16911696
     
    16961701         *
    16971702         * @param string $first_name The user's first name.
    16981703         */
    1699         $first_name = apply_filters( 'pre_user_first_name', $first_name );
     1704        $meta['first_name'] = apply_filters( 'pre_user_first_name', $first_name );
    17001705
    17011706        $last_name = empty( $userdata['last_name'] ) ? '' : $userdata['last_name'];
    17021707
     
    17071712         *
    17081713         * @param string $last_name The user's last name.
    17091714         */
    1710         $last_name = apply_filters( 'pre_user_last_name', $last_name );
     1715        $meta['last_name'] = apply_filters( 'pre_user_last_name', $last_name );
    17111716
    17121717        if ( empty( $userdata['display_name'] ) ) {
    17131718                if ( $update ) {
    17141719                        $display_name = $user_login;
    1715                 } elseif ( $first_name && $last_name ) {
     1720                } elseif ( $meta['first_name'] && $meta['last_name'] ) {
    17161721                        /* 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;
     1722                        $display_name = sprintf( _x( '%1$s %2$s', 'Display name based on first name and last name' ), $meta['first_name'], $meta['last_name'] );
     1723                } elseif ( $meta['first_name'] ) {
     1724                        $display_name = $meta['first_name'];
     1725                } elseif ( $meta['last_name'] ) {
     1726                        $display_name = $meta['last_name'];
    17221727                } else {
    17231728                        $display_name = $user_login;
    17241729                }
     
    17441749         *
    17451750         * @param string $description The user's description.
    17461751         */
    1747         $description = apply_filters( 'pre_user_description', $description );
     1752        $meta['description'] = apply_filters( 'pre_user_description', $description );
    17481753
    1749         $rich_editing = empty( $userdata['rich_editing'] ) ? 'true' : $userdata['rich_editing'];
     1754        $meta['rich_editing'] = empty( $userdata['rich_editing'] ) ? 'true' : $userdata['rich_editing'];
    17501755
    1751         $comment_shortcuts = empty( $userdata['comment_shortcuts'] ) ? 'false' : $userdata['comment_shortcuts'];
     1756        $meta['comment_shortcuts'] = empty( $userdata['comment_shortcuts'] ) ? 'false' : $userdata['comment_shortcuts'];
    17521757
    17531758        $admin_color = empty( $userdata['admin_color'] ) ? 'fresh' : $userdata['admin_color'];
    1754         $admin_color = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $admin_color );
     1759        $meta['admin_color'] = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $admin_color );
    17551760
    1756         $use_ssl = empty( $userdata['use_ssl'] ) ? 0 : $userdata['use_ssl'];
     1761        $meta['use_ssl'] = empty( $userdata['use_ssl'] ) ? 0 : $userdata['use_ssl'];
    17571762
    17581763        $user_registered = empty( $userdata['user_registered'] ) ? gmdate( 'Y-m-d H:i:s' ) : $userdata['user_registered'];
    17591764
    1760         $show_admin_bar_front = empty( $userdata['show_admin_bar_front'] ) ? 'true' : $userdata['show_admin_bar_front'];
     1765        $meta['show_admin_bar_front'] = empty( $userdata['show_admin_bar_front'] ) ? 'true' : $userdata['show_admin_bar_front'];
    17611766
    17621767        $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));
    17631768
     
    17711776                $user_nicename = $alt_user_nicename;
    17721777        }
    17731778
    1774         $data = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' );
    1775         $data = wp_unslash( $data );
     1779        $compacted = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' );
     1780        $data = wp_unslash( $compacted );
    17761781
    17771782        if ( $update ) {
    17781783                $wpdb->update( $wpdb->users, $data, compact( 'ID' ) );
     
    17841789
    17851790        $user = new WP_User( $user_id );
    17861791
    1787         foreach ( _get_additional_user_keys( $user ) as $key ) {
    1788                 if ( isset( $$key ) ) {
    1789                         update_user_meta( $user_id, $key, $$key );
     1792        // Update user meta.
     1793        foreach ( $meta as $key => $value ) {
     1794                update_user_meta( $user_id, $key, $value );
     1795        }
     1796
     1797        foreach ( wp_get_user_contact_methods( $user ) as $key => $value ) {
     1798                if ( isset( $userdata[ $key ] ) ) {
     1799                        update_user_meta( $user_id, $key, $userdata[ $key ] );
    17901800                }
    17911801        }
    17921802