WordPress.org

Make WordPress Core

Ticket #15458: wp_update_users.15458.2.diff

File wp_update_users.15458.2.diff, 3.1 KB (added by scribu, 7 years ago)
  • wp-includes/capabilities.php

    diff --git wp-includes/capabilities.php wp-includes/capabilities.php
    index deb50ce..310d248 100644
    class WP_User { 
    474474         *
    475475         * @param string $field The field to query against: 'id', 'slug', 'email' or 'login'
    476476         * @param string|int $value The field value
     477         * @return object Raw user object
    477478         */
    478479        static function get_data_by( $field, $value ) {
    479480                global $wpdb;
    class WP_User { 
    618619         * property matching the 'cap_key' exists and is an array. If so, it will be
    619620         * used.
    620621         *
     622         * @access protected
    621623         * @since 2.1.0
    622624         *
    623625         * @param string $cap_key Optional capability key
    624          * @access protected
    625626         */
    626627        function _init_caps( $cap_key = '' ) {
    627628                global $wpdb;
  • wp-includes/user.php

    diff --git wp-includes/user.php wp-includes/user.php
    index e339eb5..ff96038 100644
    function wp_insert_user($userdata) { 
    13531353                $user_id = (int) $wpdb->insert_id;
    13541354        }
    13551355
    1356         update_user_meta( $user_id, 'first_name', $first_name );
    1357         update_user_meta( $user_id, 'last_name', $last_name );
    1358         update_user_meta( $user_id, 'nickname', $nickname );
    1359         update_user_meta( $user_id, 'description', $description );
    1360         update_user_meta( $user_id, 'rich_editing', $rich_editing );
    1361         update_user_meta( $user_id, 'comment_shortcuts', $comment_shortcuts );
    1362         update_user_meta( $user_id, 'admin_color', $admin_color );
    1363         update_user_meta( $user_id, 'use_ssl', $use_ssl );
    1364         update_user_meta( $user_id, 'show_admin_bar_front', $show_admin_bar_front );
    1365 
    1366         $user = new WP_User($user_id);
    1367 
    1368         foreach ( _wp_get_user_contactmethods( $user ) as $method => $name ) {
    1369                 if ( empty($$method) )
    1370                         $$method = '';
    1371 
    1372                 update_user_meta( $user_id, $method, $$method );
     1356        $user = new WP_User( $user_id );
     1357
     1358        foreach ( _get_additional_user_keys( $user ) as $key ) {
     1359                update_user_meta( $user_id, $key, $$key );
    13731360        }
    13741361
    13751362        if ( isset($role) )
    function wp_update_user($userdata) { 
    14111398        $ID = (int) $userdata['ID'];
    14121399
    14131400        // First, get all of the original fields
    1414         $user = WP_User::get_data_by('id', $ID);
     1401        $user_obj = get_userdata( $ID );
     1402
     1403        $user = get_object_vars( $user_obj->data );
     1404
     1405        // Add additional custom fields
     1406        foreach ( _get_additional_user_keys( $user ) as $key ) {
     1407                $user[ $key ] = get_user_meta( $ID, $key, true );
     1408        }
    14151409
    14161410        // Escape data pulled from DB.
    1417         $user = add_magic_quotes(get_object_vars($user));
     1411        $user = add_magic_quotes( $user );
    14181412
    14191413        // If password is changing, hash it now.
    14201414        if ( ! empty($userdata['user_pass']) ) {
    function wp_create_user($username, $password, $email = '') { 
    14651459
    14661460
    14671461/**
     1462 * Return a list of meta keys that wp_insert_user() is supposed to set.
     1463 *
     1464 * @access private
     1465 * @since 3.3.0
     1466 *
     1467 * @param object $user WP_User instance
     1468 * @return array
     1469 */
     1470function _get_additional_user_keys( $user ) {
     1471        $keys = array( 'first_name', 'last_name', 'nickname', 'description', 'rich_editing', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front' );
     1472        return array_merge( $keys, array_keys( _wp_get_user_contactmethods( $user ) ) );
     1473}
     1474
     1475/**
    14681476 * Set up the default contact methods
    14691477 *
    14701478 * @access private