Make WordPress Core

Ticket #41057: 41057-src-wp-includes-user.patch

File 41057-src-wp-includes-user.patch, 24.0 KB (added by yahil, 8 years ago)

improved coding standards for user.php

  • src/wp-includes/user.php

     
    2626 * @return WP_User|WP_Error WP_User on success, WP_Error on failure.
    2727 */
    2828function wp_signon( $credentials = array(), $secure_cookie = '' ) {
    29         if ( empty($credentials) ) {
     29        if ( empty( $credentials ) ) {
    3030                $credentials = array(); // Back-compat for plugins passing an empty string.
    3131
    32                 if ( ! empty($_POST['log']) )
     32                if ( ! empty( $_POST['log'] ) )
    3333                        $credentials['user_login'] = $_POST['log'];
    34                 if ( ! empty($_POST['pwd']) )
     34                if ( ! empty( $_POST['pwd'] ) )
    3535                        $credentials['user_password'] = $_POST['pwd'];
    36                 if ( ! empty($_POST['rememberme']) )
     36                if ( ! empty( $_POST['rememberme'] ) )
    3737                        $credentials['remember'] = $_POST['rememberme'];
    3838        }
    3939
    40         if ( !empty($credentials['remember']) )
     40        if ( ! empty( $credentials['remember'] ) )
    4141                $credentials['remember'] = true;
    4242        else
    4343                $credentials['remember'] = false;
     
    7777         */
    7878        $secure_cookie = apply_filters( 'secure_signon_cookie', $secure_cookie, $credentials );
    7979
    80         global $auth_secure_cookie; // XXX ugly hack to pass this to wp_authenticate_cookie
     80        global $auth_secure_cookie; // XXX ugly hack to pass this to wp_authenticate_cookie.
    8181        $auth_secure_cookie = $secure_cookie;
    8282
    83         add_filter('authenticate', 'wp_authenticate_cookie', 30, 3);
     83        add_filter( 'authenticate', 'wp_authenticate_cookie', 30, 3 );
    8484
    85         $user = wp_authenticate($credentials['user_login'], $credentials['user_password']);
     85        $user = wp_authenticate( $credentials['user_login'], $credentials['user_password'] );
    8686
    8787        if ( is_wp_error($user) ) {
    88                 if ( $user->get_error_codes() == array('empty_username', 'empty_password') ) {
    89                         $user = new WP_Error('', '');
     88                if ( $user->get_error_codes() == array( 'empty_username', 'empty_password' ) ) {
     89                        $user = new WP_Error( '', '' );
    9090                }
    9191
    9292                return $user;
    9393        }
    9494
    95         wp_set_auth_cookie($user->ID, $credentials['remember'], $secure_cookie);
     95        wp_set_auth_cookie( $user->ID, $credentials['remember'], $secure_cookie );
    9696        /**
    9797         * Fires after the user has successfully logged in.
    9898         *
     
    115115 * @param string                $password Password for authentication.
    116116 * @return WP_User|WP_Error WP_User on success, WP_Error on failure.
    117117 */
    118 function wp_authenticate_username_password($user, $username, $password) {
     118function wp_authenticate_username_password( $user, $username, $password ) {
    119119        if ( $user instanceof WP_User ) {
    120120                return $user;
    121121        }
    122122
    123         if ( empty($username) || empty($password) ) {
     123        if ( empty( $username ) || empty( $password ) ) {
    124124                if ( is_wp_error( $user ) )
    125125                        return $user;
    126126
    127127                $error = new WP_Error();
    128128
    129                 if ( empty($username) )
    130                         $error->add('empty_username', __('<strong>ERROR</strong>: The username field is empty.'));
     129                if ( empty( $username ) )
     130                        $error->add( 'empty_username', __( '<strong>ERROR</strong>: The username field is empty.' ) );
    131131
    132                 if ( empty($password) )
    133                         $error->add('empty_password', __('<strong>ERROR</strong>: The password field is empty.'));
     132                if ( empty( $password ) )
     133                        $error->add( 'empty_password', __( '<strong>ERROR</strong>: The password field is empty.' ) );
    134134
    135135                return $error;
    136136        }
    137137
    138         $user = get_user_by('login', $username);
     138        $user = get_user_by( 'login', $username );
    139139
    140         if ( !$user ) {
     140        if ( ! $user ) {
    141141                return new WP_Error( 'invalid_username',
    142142                        __( '<strong>ERROR</strong>: Invalid username.' ) .
    143143                        ' <a href="' . wp_lostpassword_url() . '">' .
     
    156156         * @param string           $password Password to check against the user.
    157157         */
    158158        $user = apply_filters( 'wp_authenticate_user', $user, $password );
    159         if ( is_wp_error($user) )
     159        if ( is_wp_error( $user ) )
    160160                return $user;
    161161
    162162        if ( ! wp_check_password( $password, $user->user_pass, $user->ID ) ) {
     
    199199                $error = new WP_Error();
    200200
    201201                if ( empty( $email ) ) {
    202                         $error->add( 'empty_username', __( '<strong>ERROR</strong>: The email field is empty.' ) ); // Uses 'empty_username' for back-compat with wp_signon()
     202                        $error->add( 'empty_username', __( '<strong>ERROR</strong>: The email field is empty.' ) ); // Uses 'empty_username' for back-compat with wp_signon().
    203203                }
    204204
    205205                if ( empty( $password ) ) {
     
    259259 * @param string                $password Password. If not empty, cancels the cookie authentication.
    260260 * @return WP_User|WP_Error WP_User on success, WP_Error on failure.
    261261 */
    262 function wp_authenticate_cookie($user, $username, $password) {
     262function wp_authenticate_cookie( $user, $username, $password ) {
    263263        if ( $user instanceof WP_User ) {
    264264                return $user;
    265265        }
    266266
    267         if ( empty($username) && empty($password) ) {
     267        if ( empty( $username ) && empty( $password ) ) {
    268268                $user_id = wp_validate_auth_cookie();
    269269                if ( $user_id )
    270270                        return new WP_User($user_id);
     
    276276                else
    277277                        $auth_cookie = AUTH_COOKIE;
    278278
    279                 if ( !empty($_COOKIE[$auth_cookie]) )
    280                         return new WP_Error('expired_session', __('Please log in again.'));
     279                if ( ! empty( $_COOKIE[$auth_cookie] ) )
     280                        return new WP_Error( 'expired_session', __( 'Please log in again.' ) );
    281281
    282282                // If the cookie is not set, be silent.
    283283        }
     
    332332                return $user_id;
    333333        }
    334334
    335         if ( is_blog_admin() || is_network_admin() || empty( $_COOKIE[LOGGED_IN_COOKIE] ) ) {
     335        if ( is_blog_admin() || is_network_admin() || empty( $_COOKIE[ LOGGED_IN_COOKIE ] ) ) {
    336336                return false;
    337337        }
    338338
    339         return wp_validate_auth_cookie( $_COOKIE[LOGGED_IN_COOKIE], 'logged_in' );
     339        return wp_validate_auth_cookie( $_COOKIE[ LOGGED_IN_COOKIE ], 'logged_in' );
    340340}
    341341
    342342/**
     
    411411        return $count;
    412412}
    413413
    414 //
    415 // User option functions
    416 //
     414// User option functions.
    417415
    418416/**
    419417 * Get the current user's ID
     
    451449function get_user_option( $option, $user = 0, $deprecated = '' ) {
    452450        global $wpdb;
    453451
    454         if ( !empty( $deprecated ) )
     452        if ( ! empty( $deprecated ) )
    455453                _deprecated_argument( __FUNCTION__, '3.0.0' );
    456454
    457455        if ( empty( $user ) )
     
    506504function update_user_option( $user_id, $option_name, $newvalue, $global = false ) {
    507505        global $wpdb;
    508506
    509         if ( !$global )
     507        if ( ! $global )
    510508                $option_name = $wpdb->get_blog_prefix() . $option_name;
    511509
    512510        return update_user_meta( $user_id, $option_name, $newvalue );
     
    523521 *
    524522 * @global wpdb $wpdb WordPress database abstraction object.
    525523 *
    526  * @param int    $user_id     User ID
     524 * @param int    $user_id     User ID.
    527525 * @param string $option_name User option name.
    528526 * @param bool   $global      Optional. Whether option name is global or blog specific.
    529527 *                            Default false (blog specific).
     
    532530function delete_user_option( $user_id, $option_name, $global = false ) {
    533531        global $wpdb;
    534532
    535         if ( !$global )
     533        if ( ! $global )
    536534                $option_name = $wpdb->get_blog_prefix() . $option_name;
    537535        return delete_user_meta( $user_id, $option_name );
    538536}
     
    553551        $args = wp_parse_args( $args );
    554552        $args['count_total'] = false;
    555553
    556         $user_search = new WP_User_Query($args);
     554        $user_search = new WP_User_Query( $args );
    557555
    558556        return (array) $user_search->get_results();
    559557}
     
    566564 *
    567565 * @global wpdb $wpdb WordPress database abstraction object.
    568566 *
    569  * @param int  $user_id User ID
     567 * @param int  $user_id User ID.
    570568 * @param bool $all     Whether to retrieve all sites, or only sites that are not
    571569 *                      marked as deleted, archived, or spam.
    572570 * @return array A list of the user's sites. An empty array if the user doesn't exist
     
    577575
    578576        $user_id = (int) $user_id;
    579577
    580         // Logged out users can't have sites
     578        // Logged out users can't have sites.
    581579        if ( empty( $user_id ) )
    582580                return array();
    583581
     
    608606                $site_id = get_current_blog_id();
    609607                $sites = array( $site_id => new stdClass );
    610608                $sites[ $site_id ]->userblog_id = $site_id;
    611                 $sites[ $site_id ]->blogname = get_option('blogname');
     609                $sites[ $site_id ]->blogname = get_option( 'blogname' );
    612610                $sites[ $site_id ]->domain = '';
    613611                $sites[ $site_id ]->path = '';
    614612                $sites[ $site_id ]->site_id = 1;
    615                 $sites[ $site_id ]->siteurl = get_option('siteurl');
     613                $sites[ $site_id ]->siteurl = get_option( 'siteurl' );
    616614                $sites[ $site_id ]->archived = 0;
    617615                $sites[ $site_id ]->spam = 0;
    618616                $sites[ $site_id ]->deleted = 0;
     
    704702        }
    705703
    706704        // Technically not needed, but does save calls to get_site and get_user_meta
    707         // in the event that the function is called when a user isn't logged in
     705        // in the event that the function is called when a user isn't logged in.
    708706        if ( empty( $user_id ) ) {
    709707                return false;
    710708        } else {
     
    733731                return false;
    734732        }
    735733
    736         // no underscore before capabilities in $base_capabilities_key
     734        // no underscore before capabilities in $base_capabilities_key.
    737735        $base_capabilities_key = $wpdb->base_prefix . 'capabilities';
    738736        $site_capabilities_key = $wpdb->base_prefix . $blog_id . '_capabilities';
    739737
    740         if ( isset( $keys[ $base_capabilities_key ] ) && $blog_id == 1 ) {
     738        if ( isset( $keys[ $base_capabilities_key ] ) && 1 == $blog_id ) {
    741739                return true;
    742740        }
    743741
     
    762760 * @param bool   $unique     Optional, default is false. Whether the same key should not be added.
    763761 * @return int|false Meta ID on success, false on failure.
    764762 */
    765 function add_user_meta($user_id, $meta_key, $meta_value, $unique = false) {
    766         return add_metadata('user', $user_id, $meta_key, $meta_value, $unique);
     763function add_user_meta( $user_id, $meta_key, $meta_value, $unique = false ) {
     764        return add_metadata( 'user', $user_id, $meta_key, $meta_value, $unique );
    767765}
    768766
    769767/**
     
    776774 * @since 3.0.0
    777775 * @link https://codex.wordpress.org/Function_Reference/delete_user_meta
    778776 *
    779  * @param int    $user_id    User ID
     777 * @param int    $user_id    User ID.
    780778 * @param string $meta_key   Metadata name.
    781779 * @param mixed  $meta_value Optional. Metadata value.
    782780 * @return bool True on success, false on failure.
    783781 */
    784 function delete_user_meta($user_id, $meta_key, $meta_value = '') {
    785         return delete_metadata('user', $user_id, $meta_key, $meta_value);
     782function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) {
     783        return delete_metadata( 'user', $user_id, $meta_key, $meta_value );
    786784}
    787785
    788786/**
     
    796794 * @param bool   $single  Whether to return a single value.
    797795 * @return mixed Will be an array if $single is false. Will be value of meta data field if $single is true.
    798796 */
    799 function get_user_meta($user_id, $key = '', $single = false) {
    800         return get_metadata('user', $user_id, $key, $single);
     797function get_user_meta( $user_id, $key = '', $single = false ) {
     798        return get_metadata( 'user', $user_id, $key, $single );
    801799}
    802800
    803801/**
     
    817815 * @param mixed  $prev_value Optional. Previous value to check before removing.
    818816 * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure.
    819817 */
    820 function update_user_meta($user_id, $meta_key, $meta_value, $prev_value = '') {
    821         return update_metadata('user', $user_id, $meta_key, $meta_value, $prev_value);
     818function update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' ) {
     819        return update_metadata( 'user', $user_id, $meta_key, $meta_value, $prev_value );
    822820}
    823821
    824822/**
     
    834832 *
    835833 * @global wpdb $wpdb WordPress database abstraction object.
    836834 *
    837  * @param string $strategy 'time' or 'memory'
     835 * @param string $strategy 'time' or 'memory'.
    838836 * @return array Includes a grand total and an array of counts indexed by role strings.
    839837 */
    840 function count_users($strategy = 'time') {
     838function count_users( $strategy = 'time' ) {
    841839        global $wpdb;
    842840
    843         // Initialize
     841        // Initialize.
    844842        $id = get_current_blog_id();
    845         $blog_prefix = $wpdb->get_blog_prefix($id);
     843        $blog_prefix = $wpdb->get_blog_prefix( $id );
    846844        $result = array();
    847845
    848846        if ( 'time' == $strategy ) {
     
    854852                        $select_count[] = $wpdb->prepare( "COUNT(NULLIF(`meta_value` LIKE %s, false))", '%' . $wpdb->esc_like( '"' . $this_role . '"' ) . '%');
    855853                }
    856854                $select_count[] = "COUNT(NULLIF(`meta_value` = 'a:0:{}', false))";
    857                 $select_count = implode(', ', $select_count);
     855                $select_count = implode( ', ', $select_count );
    858856
    859857                // Add the meta_value index to the selection list, then run the query.
    860858                $row = $wpdb->get_row( "
     
    894892                " );
    895893
    896894                foreach ( $users_of_blog as $caps_meta ) {
    897                         $b_roles = maybe_unserialize($caps_meta);
     895                        $b_roles = maybe_unserialize( $caps_meta );
    898896                        if ( ! is_array( $b_roles ) )
    899897                                continue;
    900898                        if ( empty( $b_roles ) ) {
     
    901899                                $avail_roles['none']++;
    902900                        }
    903901                        foreach ( $b_roles as $b_role => $val ) {
    904                                 if ( isset($avail_roles[$b_role]) ) {
     902                                if ( isset( $avail_roles[$b_role] ) ) {
    905903                                        $avail_roles[$b_role]++;
    906904                                } else {
    907905                                        $avail_roles[$b_role] = 1;
     
    911909
    912910                $result['total_users'] = count( $users_of_blog );
    913911                $result['avail_roles'] =& $avail_roles;
    914         }
     912        } // End if().
    915913
    916914        if ( is_multisite() ) {
    917915                $result['avail_roles']['none'] = 0;
     
    949947        $user = get_userdata( $for_user_id );
    950948
    951949        if ( ! $user ) {
    952                 $user_ID = 0;
     950                $user_ID    = 0;
    953951                $user_level = 0;
    954                 $userdata = null;
     952                $userdata   = null;
    955953                $user_login = $user_email = $user_url = $user_identity = '';
    956954                return;
    957955        }
     
    11241122                }
    11251123
    11261124                $output .= "</select>";
    1127         }
     1125        } // End if().
    11281126
    11291127        /**
    11301128         * Filters the wp_dropdown_users() HTML output.
     
    11571155 *                        'attribute' and 'js'.
    11581156 * @return mixed Sanitized value.
    11591157 */
    1160 function sanitize_user_field($field, $value, $user_id, $context) {
     1158function sanitize_user_field( $field, $value, $user_id, $context ) {
    11611159        $int_fields = array('ID');
    1162         if ( in_array($field, $int_fields) )
     1160        if ( in_array( $field, $int_fields ) )
    11631161                $value = (int) $value;
    11641162
    11651163        if ( 'raw' == $context )
    11661164                return $value;
    11671165
    1168         if ( !is_string($value) && !is_numeric($value) )
     1166        if ( ! is_string( $value ) && ! is_numeric( $value ) )
    11691167                return $value;
    11701168
    11711169        $prefixed = false !== strpos( $field, 'user_' );
     
    11941192                if ( 'description' == $field )
    11951193                        $value = esc_html( $value ); // textarea_escaped?
    11961194                else
    1197                         $value = esc_attr($value);
     1195                        $value = esc_attr( $value );
    11981196        } elseif ( 'db' == $context ) {
    11991197                if ( $prefixed ) {
    12001198                        /** This filter is documented in wp-includes/post.php */
     
    12351233                         */
    12361234                        $value = apply_filters( "user_{$field}", $value, $user_id, $context );
    12371235                }
    1238         }
     1236        } // End if().
    12391237
    12401238        if ( 'user_url' == $field )
    12411239                $value = esc_url($value);
     
    12531251 *
    12541252 * @since 3.0.0
    12551253 *
    1256  * @param object|WP_User $user User object to be cached
     1254 * @param object|WP_User $user User object to be cached.
    12571255 * @return bool|null Returns false on failure.
    12581256 */
    12591257function update_user_caches( $user ) {
     
    12651263                $user = $user->data;
    12661264        }
    12671265
    1268         wp_cache_add($user->ID, $user, 'users');
    1269         wp_cache_add($user->user_login, $user->ID, 'userlogins');
    1270         wp_cache_add($user->user_email, $user->ID, 'useremail');
    1271         wp_cache_add($user->user_nicename, $user->ID, 'userslugs');
     1266        wp_cache_add( $user->ID, $user, 'users' );
     1267        wp_cache_add( $user->user_login, $user->ID, 'userlogins' );
     1268        wp_cache_add( $user->user_email, $user->ID, 'useremail' );
     1269        wp_cache_add( $user->user_nicename, $user->ID, 'userslugs' );
    12721270}
    12731271
    12741272/**
     
    12771275 * @since 3.0.0
    12781276 * @since 4.4.0 'clean_user_cache' action was added.
    12791277 *
    1280  * @param WP_User|int $user User object or ID to be cleaned from the cache
     1278 * @param WP_User|int $user User object or ID to be cleaned from the cache.
    12811279 */
    12821280function clean_user_cache( $user ) {
    12831281        if ( is_numeric( $user ) )
     
    14191417
    14201418        // Are we updating or creating?
    14211419        if ( ! empty( $userdata['ID'] ) ) {
    1422                 $ID = (int) $userdata['ID'];
     1420                $ID = ( int ) $userdata['ID'];
    14231421                $update = true;
    14241422                $old_user_data = get_userdata( $ID );
    14251423
     
    14271425                        return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) );
    14281426                }
    14291427
    1430                 // hashed in wp_update_user(), plaintext if called directly
     1428                // hashed in wp_update_user(), plaintext if called directly.
    14311429                $user_pass = ! empty( $userdata['user_pass'] ) ? $userdata['user_pass'] : $old_user_data->user_pass;
    14321430        } else {
    14331431                $update = false;
    1434                 // Hash the password
     1432                // Hash the password.
    14351433                $user_pass = wp_hash_password( $userdata['user_pass'] );
    14361434        }
    14371435
     
    14481446         */
    14491447        $pre_user_login = apply_filters( 'pre_user_login', $sanitized_user_login );
    14501448
    1451         //Remove any non-printable chars from the login string to see if we have ended up with an empty username
     1449        //Remove any non-printable chars from the login string to see if we have ended up with an empty username.
    14521450        $user_login = trim( $pre_user_login );
    14531451
    14541452        // user_login must be between 0 and 60 characters.
    14551453        if ( empty( $user_login ) ) {
    1456                 return new WP_Error('empty_user_login', __('Cannot create a user with an empty login name.') );
     1454                return new WP_Error( 'empty_user_login', __( 'Cannot create a user with an empty login name.' ) );
    14571455        } elseif ( mb_strlen( $user_login ) > 60 ) {
    14581456                return new WP_Error( 'user_login_too_long', __( 'Username may not be longer than 60 characters.' ) );
    14591457        }
     
    16241622
    16251623        if ( $user_nicename_check ) {
    16261624                $suffix = 2;
    1627                 while ($user_nicename_check) {
     1625                while ( $user_nicename_check ) {
    16281626                        // user_nicename allows 50 chars. Subtract one for a hyphen, plus the length of the suffix.
    16291627                        $base_length = 49 - mb_strlen( $suffix );
    16301628                        $alt_user_nicename = mb_substr( $user_nicename, 0, $base_length ) . "-$suffix";
     
    16911689        if ( isset( $userdata['role'] ) ) {
    16921690                $user->set_role( $userdata['role'] );
    16931691        } elseif ( ! $update ) {
    1694                 $user->set_role(get_option('default_role'));
     1692                $user->set_role( get_option( 'default_role' ) );
    16951693        }
    16961694        wp_cache_delete( $user_id, 'users' );
    16971695        wp_cache_delete( $user_login, 'userlogins' );
     
    17361734 * @param mixed $userdata An array of user data or a user object of type stdClass or WP_User.
    17371735 * @return int|WP_Error The updated user's ID or a WP_Error object if the user could not be updated.
    17381736 */
    1739 function wp_update_user($userdata) {
     1737function wp_update_user( $userdata ) {
    17401738        if ( $userdata instanceof stdClass ) {
    17411739                $userdata = get_object_vars( $userdata );
    17421740        } elseif ( $userdata instanceof WP_User ) {
     
    17481746                return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) );
    17491747        }
    17501748
    1751         // First, get all of the original fields
     1749        // First, get all of the original fields.
    17521750        $user_obj = get_userdata( $ID );
    17531751        if ( ! $user_obj ) {
    17541752                return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) );
     
    17561754
    17571755        $user = $user_obj->to_array();
    17581756
    1759         // Add additional custom fields
     1757        // Add additional custom fields.
    17601758        foreach ( _get_additional_user_keys( $user_obj ) as $key ) {
    17611759                $user[ $key ] = get_user_meta( $ID, $key, true );
    17621760        }
     
    17651763        $user = add_magic_quotes( $user );
    17661764
    17671765        if ( ! empty( $userdata['user_pass'] ) && $userdata['user_pass'] !== $user_obj->user_pass ) {
    1768                 // If password is changing, hash it now
     1766                // If password is changing, hash it now.
    17691767                $plaintext_pass = $userdata['user_pass'];
    17701768                $userdata['user_pass'] = wp_hash_password( $userdata['user_pass'] );
    17711769
     
    18701868                        $pass_change_email['message'] = str_replace( '###SITEURL###', home_url(), $pass_change_email['message'] );
    18711869
    18721870                        wp_mail( $pass_change_email['to'], sprintf( $pass_change_email['subject'], $blog_name ), $pass_change_email['message'], $pass_change_email['headers'] );
    1873                 }
     1871                } // End if().
    18741872
    18751873                if ( ! empty( $send_email_change_email ) ) {
    18761874                        /* translators: Do not translate USERNAME, ADMIN_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */
     
    19251923                        $email_change_email['message'] = str_replace( '###SITEURL###', home_url(), $email_change_email['message'] );
    19261924
    19271925                        wp_mail( $email_change_email['to'], sprintf( $email_change_email['subject'], $blog_name ), $email_change_email['message'], $email_change_email['headers'] );
    1928                 }
     1926                } // End if().
    19291927
    19301928                if ( $switched_locale ) {
    19311929                        restore_previous_locale();
    19321930                }
    1933         }
     1931        } // End if().
    19341932
    19351933        // Update the cookies if the password changed.
    19361934        $current_user = wp_get_current_user();
    19371935        if ( $current_user->ID == $ID ) {
    1938                 if ( isset($plaintext_pass) ) {
     1936                if ( isset( $plaintext_pass ) ) {
    19391937                        wp_clear_auth_cookie();
    19401938
    19411939                        // Here we calculate the expiration length of the current auth cookie and compare it to the default expiration.
     
    19671965 * @return int|WP_Error The newly created user's ID or a WP_Error object if the user could not
    19681966 *                      be created.
    19691967 */
    1970 function wp_create_user($username, $password, $email = '') {
     1968function wp_create_user( $username, $password, $email = '' ) {
    19711969        $user_login = wp_slash( $username );
    1972         $user_email = wp_slash( $email    );
     1970        $user_email = wp_slash( $email );
    19731971        $user_pass = $password;
    19741972
    1975         $userdata = compact('user_login', 'user_email', 'user_pass');
    1976         return wp_insert_user($userdata);
     1973        $userdata = compact( 'user_login', 'user_email', 'user_pass' );
     1974        return wp_insert_user( $userdata );
    19771975}
    19781976
    19791977/**
     
    20092007                $methods = array(
    20102008                        'aim'    => __( 'AIM' ),
    20112009                        'yim'    => __( 'Yahoo IM' ),
    2012                         'jabber' => __( 'Jabber / Google Talk' )
     2010                        'jabber' => __( 'Jabber / Google Talk' ),
    20132011                );
    20142012        }
    20152013
     
    20192017         * @since 2.9.0
    20202018         *
    20212019         * @param array   $methods Array of contact methods and their labels.
     2020         *
    20222021         * @param WP_User $user    WP_User object.
    20232022         */
    20242023        return apply_filters( 'user_contactmethods', $methods, $user );
     
    21602159 * @param string $login     The user login.
    21612160 * @return WP_User|WP_Error WP_User object on success, WP_Error object for invalid or expired keys.
    21622161 */
    2163 function check_password_reset_key($key, $login) {
     2162function check_password_reset_key( $key, $login ) {
    21642163        global $wpdb, $wp_hasher;
    21652164
    21662165        $key = preg_replace('/[^a-z0-9]/i', '', $key);
    21672166
    2168         if ( empty( $key ) || !is_string( $key ) )
     2167        if ( empty( $key ) || ! is_string( $key ) )
    21692168                return new WP_Error('invalid_key', __('Invalid key'));
    21702169
    2171         if ( empty($login) || !is_string($login) )
     2170        if ( empty($login) || ! is_string($login) )
    21722171                return new WP_Error('invalid_key', __('Invalid key'));
    21732172
    21742173        $row = $wpdb->get_row( $wpdb->prepare( "SELECT ID, user_activation_key FROM $wpdb->users WHERE user_login = %s", $login ) );
     
    22062205        if ( $hash_is_correct && $expiration_time && time() < $expiration_time ) {
    22072206                return get_userdata( $row->ID );
    22082207        } elseif ( $hash_is_correct && $expiration_time ) {
    2209                 // Key has an expiration time that's passed
     2208                // Key has an expiration time that's passed.
    22102209                return new WP_Error( 'expired_key', __( 'Invalid key' ) );
    22112210        }
    22122211
     
    22362235 *
    22372236 * @since 2.5.0
    22382237 *
    2239  * @param object $user     The user
    2240  * @param string $new_pass New password for the user in plaintext
     2238 * @param object $user     The user.
     2239 * @param string $new_pass New password for the user in plaintext.
    22412240 */
    22422241function reset_password( $user, $new_pass ) {
    22432242        /**
     
    22692268 *
    22702269 * @since 2.5.0
    22712270 *
    2272  * @param string $user_login User's username for logging in
    2273  * @param string $user_email User's email address to send password and add
     2271 * @param string $user_login User's username for logging in.
     2272 * @param string $user_email User's email address to send password and add.
    22742273 * @return int|WP_Error Either user's ID or error on failure.
    22752274 */
    22762275function register_new_user( $user_login, $user_email ) {
     
    22862285         */
    22872286        $user_email = apply_filters( 'user_registration_email', $user_email );
    22882287
    2289         // Check the username
    2290         if ( $sanitized_user_login == '' ) {
     2288        // Check the username.
     2289        if ( '' == $sanitized_user_login ) {
    22912290                $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Please enter a username.' ) );
    22922291        } elseif ( ! validate_username( $user_login ) ) {
    22932292                $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) );
     
    23032302                }
    23042303        }
    23052304
    2306         // Check the email address
    2307         if ( $user_email == '' ) {
     2305        // Check the email address.
     2306        if ( '' == $user_email ) {
    23082307                $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your email address.' ) );
    23092308        } elseif ( ! is_email( $user_email ) ) {
    23102309                $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn&#8217;t correct.' ) );
     
    25012500                        return $current_user;
    25022501                }
    25032502
    2504                 // Upgrade stdClass to WP_User
     2503                // Upgrade stdClass to WP_User.
    25052504                if ( is_object( $current_user ) && isset( $current_user->ID ) ) {
    25062505                        $cur_id = $current_user->ID;
    25072506                        $current_user = null;