Make WordPress Core

Ticket #47522: 47522.2.patch

File 47522.2.patch, 4.4 KB (added by Takahashi_Fumiki, 6 years ago)

Fix function by removing debug code.

  • src/wp-admin/includes/user.php

     
    8888                        $user->user_url = preg_match( '/^(' . $protocols . '):/is', $user->user_url ) ? $user->user_url : 'http://' . $user->user_url;
    8989                }
    9090        }
    91         if ( isset( $_POST['first_name'] ) ) {
    92                 $user->first_name = sanitize_text_field( $_POST['first_name'] );
     91        foreach ( wp_get_user_name_parts() as $key => $label ) {
     92                if ( isset( $_POST[ $key ] ) ) {
     93                        $user->{$key} = sanitize_text_field( $_POST[ $key ] );
     94                }
    9395        }
    94         if ( isset( $_POST['last_name'] ) ) {
    95                 $user->last_name = sanitize_text_field( $_POST['last_name'] );
    96         }
    9796        if ( isset( $_POST['nickname'] ) ) {
    9897                $user->nickname = sanitize_text_field( $_POST['nickname'] );
    9998        }
  • src/wp-admin/user-edit.php

     
    425425</td></tr>
    426426                <?php } ?>
    427427
    428 <tr class="user-first-name-wrap">
    429         <th><label for="first_name"><?php _e( 'First Name' ); ?></label></th>
    430         <td><input type="text" name="first_name" id="first_name" value="<?php echo esc_attr( $profileuser->first_name ); ?>" class="regular-text" /></td>
     428<?php foreach ( wp_get_user_name_parts() as $key => $label ) : ?>
     429<tr class="user-<?php echo esc_attr( str_replace( '_', '-', $key ) ) ?>-wrap">
     430        <th><label for="<?php echo esc_attr( $key ) ?>"><?php echo esc_html( $label ); ?></label></th>
     431        <td><input type="text" name="<?php echo esc_attr( $key ) ?>" id="<?php echo esc_attr( $key ) ?>" value="<?php echo esc_attr( $profileuser->{$key}); ?>" class="regular-text" /></td>
    431432</tr>
     433<?php endforeach; ?>
    432434
    433 <tr class="user-last-name-wrap">
    434         <th><label for="last_name"><?php _e( 'Last Name' ); ?></label></th>
    435         <td><input type="text" name="last_name" id="last_name" value="<?php echo esc_attr( $profileuser->last_name ); ?>" class="regular-text" /></td>
    436 </tr>
    437 
    438435<tr class="user-nickname-wrap">
    439436        <th><label for="nickname"><?php _e( 'Nickname' ); ?> <span class="description"><?php _e( '(required)' ); ?></span></label></th>
    440437        <td><input type="text" name="nickname" id="nickname" value="<?php echo esc_attr( $profileuser->nickname ); ?>" class="regular-text" /></td>
  • src/wp-includes/user.php

     
    21352135}
    21362136
    21372137/**
     2138 * Get user name parts.
     2139 *
     2140 * Default name parts are first_name and last_name.
     2141 *
     2142 * @since 5.3.0
     2143 *
     2144 * @return array An associative array consists of user_meta key as key and label as value.
     2145 */
     2146function wp_get_user_name_parts() {
     2147        $default = [
     2148                'first_name'  => __( 'First Name' ),
     2149                'middle_name' => __( 'Middle Name' ),
     2150                'last_name'   => __( 'Last Name' ),
     2151        ];
     2152        $user_locale = get_user_locale();
     2153        /**
     2154         * Filters user name parts.
     2155         *
     2156         * @since 5.3.0
     2157         *
     2158         * @param array  $name_parts  An associative array consists of user_meta key as key and label as value.
     2159         * @param string $user_locale User locale
     2160         */
     2161        $name_parts = (array) apply_filters( 'user_name_parts', $default, $user_locale );
     2162        /*
     2163         * translators: Control name order in your locale. If last name precedes first name, 'last_name,first_name'.
     2164         * A middle name is required, 'first_name,middle_name,last_name'.
     2165         * Other name parts can be added by user_name_parts filters.
     2166         */
     2167        $name_order = _x( 'first_name,last_name', 'Name order. Do not translate!' );
     2168        /**
     2169         * Order of user name parts. Must be included in name parts.
     2170         *
     2171         * @since 5.3.0
     2172         *
     2173         * @param array  $name_order  An array of user_meta key.
     2174         * @param string $user_locale User locale.
     2175         */
     2176        $name_order = (array) apply_filters( 'user_name_parts_order', array_map( 'trim', explode( ',', $name_order ) ), $user_locale );
     2177        $name_order = array_filter( $name_order, function( $key ) use ( $name_parts ) {
     2178                return isset( $name_parts[ $key ] );
     2179        } );
     2180        $allowed_parts = [];
     2181        foreach ( $name_order as $key ) {
     2182                $allowed_parts[ $key ] = $name_parts[ $key ];
     2183        }
     2184        return empty( $allowed_parts ) ? [
     2185                'first_name'  => __( 'First Name' ),
     2186                'last_name'   => __( 'Last Name' ),
     2187        ] : $allowed_parts;
     2188}
     2189
     2190/**
    21382191 * Set up the user contact methods.
    21392192 *
    21402193 * Default contact methods were removed in 3.6. A filter dictates contact methods.