Ticket #41155: 41155.patch
File 41155.patch, 27.0 KB (added by , 7 years ago) |
---|
-
src/wp-admin/css/admin-menu.css
10 10 position: fixed; 11 11 top: 0; 12 12 bottom: -120px; 13 z-index: 1; /* positive z-index to avoid elastic scrolling woes in Safari */ 13 z-index: 1; 14 15 /* positive z-index to avoid elastic scrolling woes in Safari */ 14 16 } 15 17 16 18 #adminmenu { … … 38 40 /* New Menu icons */ 39 41 40 42 .icon16:before { 41 color: #82878c; /* same as new icons */ 43 color: #82878c; 44 45 /* same as new icons */ 42 46 font: normal 20px/1 dashicons; 43 47 speak: none; 44 48 padding: 6px 0; … … 141 145 #adminmenuwrap { 142 146 position: relative; 143 147 float: left; 144 z-index: 9990;148 z-index: 10001; 145 149 } 146 150 147 151 /* side admin menu */ … … 167 171 168 172 #adminmenu .wp-submenu a { 169 173 color: #b4b9be; 170 color: rgba(240, 245,250,0.7);174 color: rgba(240, 245, 250, 0.7); 171 175 } 172 176 173 177 #adminmenu .wp-submenu a:hover, … … 203 207 padding: 7px 0 8px; 204 208 z-index: 9999; 205 209 background-color: #32373c; 206 -webkit-box-shadow: 0 3px 5px rgba(0, 0,0,0.2);207 box-shadow: 0 3px 5px rgba(0, 0,0,0.2);210 -webkit-box-shadow: 0 3px 5px rgba(0, 0, 0, 0.2); 211 box-shadow: 0 3px 5px rgba(0, 0, 0, 0.2); 208 212 } 209 213 210 214 .js #adminmenu .sub-open, … … 340 344 #adminmenu .wp-menu-image img { 341 345 padding: 9px 0 0 0; 342 346 opacity: 0.6; 343 filter: alpha(opacity =60);347 filter: alpha(opacity = 60); 344 348 } 345 349 346 350 #adminmenu div.wp-menu-name { … … 364 368 365 369 div.wp-menu-image:before { 366 370 color: #a0a5aa; 367 color: rgba(240, 245,250,0.6);371 color: rgba(240, 245, 250, 0.6); 368 372 padding: 7px 0; 369 373 -webkit-transition: all .1s ease-in-out; 370 374 transition: all .1s ease-in-out; … … 372 376 373 377 #adminmenu div.wp-menu-image:before { 374 378 color: #a0a5aa; 375 color: rgba(240, 245,250,0.6);379 color: rgba(240, 245, 250, 0.6); 376 380 } 377 381 378 382 #adminmenu li.wp-has-current-submenu:hover div.wp-menu-image:before, … … 419 423 .no-font-face.auto-fold #adminmenu .wp-menu-name { 420 424 margin-left: 0; 421 425 } 426 422 427 /* End no @font-face support */ 423 428 424 429 /* Sticky admin menu */ … … 487 492 #adminmenu li.menu-top:hover .wp-menu-image img, 488 493 #adminmenu li.wp-has-current-submenu .wp-menu-image img { 489 494 opacity: 1; 490 filter: alpha(opacity =100);495 filter: alpha(opacity = 100); 491 496 } 492 497 493 498 #adminmenu li.wp-menu-separator { … … 538 543 } 539 544 540 545 #adminmenu li.current a .awaiting-mod, 541 #adminmenu 546 #adminmenu li a.wp-has-current-submenu .update-plugins { 542 547 background-color: #00b9eb; 543 548 color: #fff; 544 549 } … … 679 684 padding-left: 14px; 680 685 } 681 686 682 683 687 .auto-fold #adminmenu li.menu-top .wp-submenu > li > a { 684 688 padding-left: 12px; 685 689 } … … 750 754 -ms-transform: none; 751 755 transform: none; 752 756 } 753 754 757 } 755 758 756 @media screen and ( max-width: 782px) {759 @media screen and (max-width: 782px) { 757 760 .auto-fold #wpcontent { 758 761 position: relative; 759 762 margin-left: 0; … … 940 943 .auto-fold #adminmenu { 941 944 top: 46px; 942 945 } 943 } 946 } 947 No newline at end of file -
src/wp-includes/user.php
31 31 * @return WP_User|WP_Error WP_User on success, WP_Error on failure. 32 32 */ 33 33 function wp_signon( $credentials = array(), $secure_cookie = '' ) { 34 if ( empty( $credentials) ) {34 if ( empty( $credentials ) ) { 35 35 $credentials = array(); // Back-compat for plugins passing an empty string. 36 36 37 if ( ! empty( $_POST['log']) )37 if ( ! empty( $_POST['log'] ) ) 38 38 $credentials['user_login'] = $_POST['log']; 39 if ( ! empty( $_POST['pwd']) )39 if ( ! empty( $_POST['pwd'] ) ) 40 40 $credentials['user_password'] = $_POST['pwd']; 41 if ( ! empty( $_POST['rememberme']) )41 if ( ! empty( $_POST['rememberme'] ) ) 42 42 $credentials['remember'] = $_POST['rememberme']; 43 43 } 44 44 45 if ( ! empty($credentials['remember']) )45 if ( ! empty( $credentials['remember'] ) ) 46 46 $credentials['remember'] = true; 47 47 else 48 48 $credentials['remember'] = false; … … 82 82 */ 83 83 $secure_cookie = apply_filters( 'secure_signon_cookie', $secure_cookie, $credentials ); 84 84 85 global $auth_secure_cookie; // XXX ugly hack to pass this to wp_authenticate_cookie 85 global $auth_secure_cookie; // XXX ugly hack to pass this to wp_authenticate_cookie. 86 86 $auth_secure_cookie = $secure_cookie; 87 87 88 add_filter( 'authenticate', 'wp_authenticate_cookie', 30, 3);88 add_filter( 'authenticate', 'wp_authenticate_cookie', 30, 3 ); 89 89 90 $user = wp_authenticate( $credentials['user_login'], $credentials['user_password']);90 $user = wp_authenticate( $credentials['user_login'], $credentials['user_password'] ); 91 91 92 92 if ( is_wp_error($user) ) { 93 if ( $user->get_error_codes() == array( 'empty_username', 'empty_password') ) {94 $user = new WP_Error( '', '');93 if ( $user->get_error_codes() == array( 'empty_username', 'empty_password' ) ) { 94 $user = new WP_Error( '', '' ); 95 95 } 96 96 97 97 return $user; 98 98 } 99 99 100 wp_set_auth_cookie( $user->ID, $credentials['remember'], $secure_cookie);100 wp_set_auth_cookie( $user->ID, $credentials['remember'], $secure_cookie ); 101 101 /** 102 102 * Fires after the user has successfully logged in. 103 103 * … … 120 120 * @param string $password Password for authentication. 121 121 * @return WP_User|WP_Error WP_User on success, WP_Error on failure. 122 122 */ 123 function wp_authenticate_username_password( $user, $username, $password) {123 function wp_authenticate_username_password( $user, $username, $password ) { 124 124 if ( $user instanceof WP_User ) { 125 125 return $user; 126 126 } 127 127 128 if ( empty( $username) || empty($password) ) {128 if ( empty( $username ) || empty( $password ) ) { 129 129 if ( is_wp_error( $user ) ) 130 130 return $user; 131 131 132 132 $error = new WP_Error(); 133 133 134 if ( empty( $username) )135 $error->add( 'empty_username', __('<strong>ERROR</strong>: The username field is empty.'));134 if ( empty( $username ) ) 135 $error->add( 'empty_username', __( '<strong>ERROR</strong>: The username field is empty.' ) ); 136 136 137 if ( empty( $password) )138 $error->add( 'empty_password', __('<strong>ERROR</strong>: The password field is empty.'));137 if ( empty( $password ) ) 138 $error->add( 'empty_password', __( '<strong>ERROR</strong>: The password field is empty.' ) ); 139 139 140 140 return $error; 141 141 } 142 142 143 $user = get_user_by( 'login', $username);143 $user = get_user_by( 'login', $username ); 144 144 145 if ( ! $user ) {145 if ( ! $user ) { 146 146 return new WP_Error( 'invalid_username', 147 147 __( '<strong>ERROR</strong>: Invalid username.' ) . 148 148 ' <a href="' . wp_lostpassword_url() . '">' . … … 161 161 * @param string $password Password to check against the user. 162 162 */ 163 163 $user = apply_filters( 'wp_authenticate_user', $user, $password ); 164 if ( is_wp_error( $user) )164 if ( is_wp_error( $user ) ) 165 165 return $user; 166 166 167 167 if ( ! wp_check_password( $password, $user->user_pass, $user->ID ) ) { … … 204 204 $error = new WP_Error(); 205 205 206 206 if ( empty( $email ) ) { 207 $error->add( 'empty_username', __( '<strong>ERROR</strong>: The email field is empty.' ) ); // Uses 'empty_username' for back-compat with wp_signon() 207 $error->add( 'empty_username', __( '<strong>ERROR</strong>: The email field is empty.' ) ); // Uses 'empty_username' for back-compat with wp_signon(). 208 208 } 209 209 210 210 if ( empty( $password ) ) { … … 264 264 * @param string $password Password. If not empty, cancels the cookie authentication. 265 265 * @return WP_User|WP_Error WP_User on success, WP_Error on failure. 266 266 */ 267 function wp_authenticate_cookie( $user, $username, $password) {267 function wp_authenticate_cookie( $user, $username, $password ) { 268 268 if ( $user instanceof WP_User ) { 269 269 return $user; 270 270 } 271 271 272 if ( empty( $username) && empty($password) ) {272 if ( empty( $username ) && empty( $password ) ) { 273 273 $user_id = wp_validate_auth_cookie(); 274 274 if ( $user_id ) 275 275 return new WP_User($user_id); … … 281 281 else 282 282 $auth_cookie = AUTH_COOKIE; 283 283 284 if ( ! empty($_COOKIE[$auth_cookie]) )285 return new WP_Error( 'expired_session', __('Please log in again.'));284 if ( ! empty( $_COOKIE[$auth_cookie] ) ) 285 return new WP_Error( 'expired_session', __( 'Please log in again.' ) ); 286 286 287 287 // If the cookie is not set, be silent. 288 288 } … … 337 337 return $user_id; 338 338 } 339 339 340 if ( is_blog_admin() || is_network_admin() || empty( $_COOKIE[ LOGGED_IN_COOKIE] ) ) {340 if ( is_blog_admin() || is_network_admin() || empty( $_COOKIE[ LOGGED_IN_COOKIE ] ) ) { 341 341 return false; 342 342 } 343 343 344 return wp_validate_auth_cookie( $_COOKIE[ LOGGED_IN_COOKIE], 'logged_in' );344 return wp_validate_auth_cookie( $_COOKIE[ LOGGED_IN_COOKIE ], 'logged_in' ); 345 345 } 346 346 347 347 /** … … 416 416 return $count; 417 417 } 418 418 419 // 420 // User option functions 421 // 419 // User option functions. 422 420 423 421 /** 424 422 * Get the current user's ID … … 456 454 function get_user_option( $option, $user = 0, $deprecated = '' ) { 457 455 global $wpdb; 458 456 459 if ( ! empty( $deprecated ) )457 if ( ! empty( $deprecated ) ) 460 458 _deprecated_argument( __FUNCTION__, '3.0.0' ); 461 459 462 460 if ( empty( $user ) ) … … 511 509 function update_user_option( $user_id, $option_name, $newvalue, $global = false ) { 512 510 global $wpdb; 513 511 514 if ( ! $global )512 if ( ! $global ) 515 513 $option_name = $wpdb->get_blog_prefix() . $option_name; 516 514 517 515 return update_user_meta( $user_id, $option_name, $newvalue ); … … 528 526 * 529 527 * @global wpdb $wpdb WordPress database abstraction object. 530 528 * 531 * @param int $user_id User ID 529 * @param int $user_id User ID. 532 530 * @param string $option_name User option name. 533 531 * @param bool $global Optional. Whether option name is global or blog specific. 534 532 * Default false (blog specific). … … 537 535 function delete_user_option( $user_id, $option_name, $global = false ) { 538 536 global $wpdb; 539 537 540 if ( ! $global )538 if ( ! $global ) 541 539 $option_name = $wpdb->get_blog_prefix() . $option_name; 542 540 return delete_user_meta( $user_id, $option_name ); 543 541 } … … 558 556 $args = wp_parse_args( $args ); 559 557 $args['count_total'] = false; 560 558 561 $user_search = new WP_User_Query( $args);559 $user_search = new WP_User_Query( $args ); 562 560 563 561 return (array) $user_search->get_results(); 564 562 } … … 571 569 * 572 570 * @global wpdb $wpdb WordPress database abstraction object. 573 571 * 574 * @param int $user_id User ID 572 * @param int $user_id User ID. 575 573 * @param bool $all Whether to retrieve all sites, or only sites that are not 576 574 * marked as deleted, archived, or spam. 577 575 * @return array A list of the user's sites. An empty array if the user doesn't exist … … 582 580 583 581 $user_id = (int) $user_id; 584 582 585 // Logged out users can't have sites 583 // Logged out users can't have sites. 586 584 if ( empty( $user_id ) ) 587 585 return array(); 588 586 … … 613 611 $site_id = get_current_blog_id(); 614 612 $sites = array( $site_id => new stdClass ); 615 613 $sites[ $site_id ]->userblog_id = $site_id; 616 $sites[ $site_id ]->blogname = get_option( 'blogname');614 $sites[ $site_id ]->blogname = get_option( 'blogname' ); 617 615 $sites[ $site_id ]->domain = ''; 618 616 $sites[ $site_id ]->path = ''; 619 617 $sites[ $site_id ]->site_id = 1; 620 $sites[ $site_id ]->siteurl = get_option( 'siteurl');618 $sites[ $site_id ]->siteurl = get_option( 'siteurl' ); 621 619 $sites[ $site_id ]->archived = 0; 622 620 $sites[ $site_id ]->spam = 0; 623 621 $sites[ $site_id ]->deleted = 0; … … 709 707 } 710 708 711 709 // Technically not needed, but does save calls to get_site and get_user_meta 712 // in the event that the function is called when a user isn't logged in 710 // in the event that the function is called when a user isn't logged in. 713 711 if ( empty( $user_id ) ) { 714 712 return false; 715 713 } else { … … 738 736 return false; 739 737 } 740 738 741 // no underscore before capabilities in $base_capabilities_key 739 // no underscore before capabilities in $base_capabilities_key. 742 740 $base_capabilities_key = $wpdb->base_prefix . 'capabilities'; 743 741 $site_capabilities_key = $wpdb->base_prefix . $blog_id . '_capabilities'; 744 742 745 if ( isset( $keys[ $base_capabilities_key ] ) && $blog_id == 1) {743 if ( isset( $keys[ $base_capabilities_key ] ) && 1 == $blog_id ) { 746 744 return true; 747 745 } 748 746 … … 767 765 * @param bool $unique Optional, default is false. Whether the same key should not be added. 768 766 * @return int|false Meta ID on success, false on failure. 769 767 */ 770 function add_user_meta( $user_id, $meta_key, $meta_value, $unique = false) {771 return add_metadata( 'user', $user_id, $meta_key, $meta_value, $unique);768 function add_user_meta( $user_id, $meta_key, $meta_value, $unique = false ) { 769 return add_metadata( 'user', $user_id, $meta_key, $meta_value, $unique ); 772 770 } 773 771 774 772 /** … … 781 779 * @since 3.0.0 782 780 * @link https://codex.wordpress.org/Function_Reference/delete_user_meta 783 781 * 784 * @param int $user_id User ID 782 * @param int $user_id User ID. 785 783 * @param string $meta_key Metadata name. 786 784 * @param mixed $meta_value Optional. Metadata value. 787 785 * @return bool True on success, false on failure. 788 786 */ 789 function delete_user_meta( $user_id, $meta_key, $meta_value = '') {790 return delete_metadata( 'user', $user_id, $meta_key, $meta_value);787 function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) { 788 return delete_metadata( 'user', $user_id, $meta_key, $meta_value ); 791 789 } 792 790 793 791 /** … … 801 799 * @param bool $single Whether to return a single value. 802 800 * @return mixed Will be an array if $single is false. Will be value of meta data field if $single is true. 803 801 */ 804 function get_user_meta( $user_id, $key = '', $single = false) {805 return get_metadata( 'user', $user_id, $key, $single);802 function get_user_meta( $user_id, $key = '', $single = false ) { 803 return get_metadata( 'user', $user_id, $key, $single ); 806 804 } 807 805 808 806 /** … … 822 820 * @param mixed $prev_value Optional. Previous value to check before removing. 823 821 * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. 824 822 */ 825 function update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '') {826 return update_metadata( 'user', $user_id, $meta_key, $meta_value, $prev_value);823 function update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' ) { 824 return update_metadata( 'user', $user_id, $meta_key, $meta_value, $prev_value ); 827 825 } 828 826 829 827 /** … … 839 837 * 840 838 * @global wpdb $wpdb WordPress database abstraction object. 841 839 * 842 * @param string $strategy 'time' or 'memory' 840 * @param string $strategy 'time' or 'memory'. 843 841 * @return array Includes a grand total and an array of counts indexed by role strings. 844 842 */ 845 function count_users( $strategy = 'time') {843 function count_users( $strategy = 'time' ) { 846 844 global $wpdb; 847 845 848 // Initialize 846 // Initialize. 849 847 $id = get_current_blog_id(); 850 $blog_prefix = $wpdb->get_blog_prefix( $id);848 $blog_prefix = $wpdb->get_blog_prefix( $id ); 851 849 $result = array(); 852 850 853 851 if ( 'time' == $strategy ) { … … 859 857 $select_count[] = $wpdb->prepare( "COUNT(NULLIF(`meta_value` LIKE %s, false))", '%' . $wpdb->esc_like( '"' . $this_role . '"' ) . '%'); 860 858 } 861 859 $select_count[] = "COUNT(NULLIF(`meta_value` = 'a:0:{}', false))"; 862 $select_count = implode( ', ', $select_count);860 $select_count = implode( ', ', $select_count ); 863 861 864 862 // Add the meta_value index to the selection list, then run the query. 865 863 $row = $wpdb->get_row( " … … 899 897 " ); 900 898 901 899 foreach ( $users_of_blog as $caps_meta ) { 902 $b_roles = maybe_unserialize( $caps_meta);900 $b_roles = maybe_unserialize( $caps_meta ); 903 901 if ( ! is_array( $b_roles ) ) 904 902 continue; 905 903 if ( empty( $b_roles ) ) { … … 906 904 $avail_roles['none']++; 907 905 } 908 906 foreach ( $b_roles as $b_role => $val ) { 909 if ( isset( $avail_roles[$b_role]) ) {907 if ( isset( $avail_roles[$b_role] ) ) { 910 908 $avail_roles[$b_role]++; 911 909 } else { 912 910 $avail_roles[$b_role] = 1; … … 916 914 917 915 $result['total_users'] = count( $users_of_blog ); 918 916 $result['avail_roles'] =& $avail_roles; 919 } 917 } // End if(). 920 918 921 919 if ( is_multisite() ) { 922 920 $result['avail_roles']['none'] = 0; … … 954 952 $user = get_userdata( $for_user_id ); 955 953 956 954 if ( ! $user ) { 957 $user_ID = 0;955 $user_ID = 0; 958 956 $user_level = 0; 959 $userdata = null;957 $userdata = null; 960 958 $user_login = $user_email = $user_url = $user_identity = ''; 961 959 return; 962 960 } … … 1129 1127 } 1130 1128 1131 1129 $output .= "</select>"; 1132 } 1130 } // End if(). 1133 1131 1134 1132 /** 1135 1133 * Filters the wp_dropdown_users() HTML output. … … 1162 1160 * 'attribute' and 'js'. 1163 1161 * @return mixed Sanitized value. 1164 1162 */ 1165 function sanitize_user_field( $field, $value, $user_id, $context) {1163 function sanitize_user_field( $field, $value, $user_id, $context ) { 1166 1164 $int_fields = array('ID'); 1167 if ( in_array( $field, $int_fields) )1165 if ( in_array( $field, $int_fields ) ) 1168 1166 $value = (int) $value; 1169 1167 1170 1168 if ( 'raw' == $context ) 1171 1169 return $value; 1172 1170 1173 if ( ! is_string($value) && !is_numeric($value) )1171 if ( ! is_string( $value ) && ! is_numeric( $value ) ) 1174 1172 return $value; 1175 1173 1176 1174 $prefixed = false !== strpos( $field, 'user_' ); … … 1199 1197 if ( 'description' == $field ) 1200 1198 $value = esc_html( $value ); // textarea_escaped? 1201 1199 else 1202 $value = esc_attr( $value);1200 $value = esc_attr( $value ); 1203 1201 } elseif ( 'db' == $context ) { 1204 1202 if ( $prefixed ) { 1205 1203 /** This filter is documented in wp-includes/post.php */ … … 1240 1238 */ 1241 1239 $value = apply_filters( "user_{$field}", $value, $user_id, $context ); 1242 1240 } 1243 } 1241 } // End if(). 1244 1242 1245 1243 if ( 'user_url' == $field ) 1246 1244 $value = esc_url($value); … … 1258 1256 * 1259 1257 * @since 3.0.0 1260 1258 * 1261 * @param object|WP_User $user User object to be cached 1259 * @param object|WP_User $user User object to be cached. 1262 1260 * @return bool|null Returns false on failure. 1263 1261 */ 1264 1262 function update_user_caches( $user ) { … … 1270 1268 $user = $user->data; 1271 1269 } 1272 1270 1273 wp_cache_add( $user->ID, $user, 'users');1274 wp_cache_add( $user->user_login, $user->ID, 'userlogins');1275 wp_cache_add( $user->user_email, $user->ID, 'useremail');1276 wp_cache_add( $user->user_nicename, $user->ID, 'userslugs');1271 wp_cache_add( $user->ID, $user, 'users' ); 1272 wp_cache_add( $user->user_login, $user->ID, 'userlogins' ); 1273 wp_cache_add( $user->user_email, $user->ID, 'useremail' ); 1274 wp_cache_add( $user->user_nicename, $user->ID, 'userslugs' ); 1277 1275 } 1278 1276 1279 1277 /** … … 1282 1280 * @since 3.0.0 1283 1281 * @since 4.4.0 'clean_user_cache' action was added. 1284 1282 * 1285 * @param WP_User|int $user User object or ID to be cleaned from the cache 1283 * @param WP_User|int $user User object or ID to be cleaned from the cache. 1286 1284 */ 1287 1285 function clean_user_cache( $user ) { 1288 1286 if ( is_numeric( $user ) ) … … 1424 1422 1425 1423 // Are we updating or creating? 1426 1424 if ( ! empty( $userdata['ID'] ) ) { 1427 $ID = ( int) $userdata['ID'];1425 $ID = ( int ) $userdata['ID']; 1428 1426 $update = true; 1429 1427 $old_user_data = get_userdata( $ID ); 1430 1428 … … 1432 1430 return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) ); 1433 1431 } 1434 1432 1435 // hashed in wp_update_user(), plaintext if called directly 1433 // hashed in wp_update_user(), plaintext if called directly. 1436 1434 $user_pass = ! empty( $userdata['user_pass'] ) ? $userdata['user_pass'] : $old_user_data->user_pass; 1437 1435 } else { 1438 1436 $update = false; 1439 // Hash the password 1437 // Hash the password. 1440 1438 $user_pass = wp_hash_password( $userdata['user_pass'] ); 1441 1439 } 1442 1440 … … 1453 1451 */ 1454 1452 $pre_user_login = apply_filters( 'pre_user_login', $sanitized_user_login ); 1455 1453 1456 //Remove any non-printable chars from the login string to see if we have ended up with an empty username 1454 //Remove any non-printable chars from the login string to see if we have ended up with an empty username. 1457 1455 $user_login = trim( $pre_user_login ); 1458 1456 1459 1457 // user_login must be between 0 and 60 characters. 1460 1458 if ( empty( $user_login ) ) { 1461 return new WP_Error( 'empty_user_login', __('Cannot create a user with an empty login name.') );1459 return new WP_Error( 'empty_user_login', __( 'Cannot create a user with an empty login name.' ) ); 1462 1460 } elseif ( mb_strlen( $user_login ) > 60 ) { 1463 1461 return new WP_Error( 'user_login_too_long', __( 'Username may not be longer than 60 characters.' ) ); 1464 1462 } … … 1629 1627 1630 1628 if ( $user_nicename_check ) { 1631 1629 $suffix = 2; 1632 while ( $user_nicename_check) {1630 while ( $user_nicename_check ) { 1633 1631 // user_nicename allows 50 chars. Subtract one for a hyphen, plus the length of the suffix. 1634 1632 $base_length = 49 - mb_strlen( $suffix ); 1635 1633 $alt_user_nicename = mb_substr( $user_nicename, 0, $base_length ) . "-$suffix"; … … 1696 1694 if ( isset( $userdata['role'] ) ) { 1697 1695 $user->set_role( $userdata['role'] ); 1698 1696 } elseif ( ! $update ) { 1699 $user->set_role( get_option('default_role'));1697 $user->set_role( get_option( 'default_role' ) ); 1700 1698 } 1701 1699 wp_cache_delete( $user_id, 'users' ); 1702 1700 wp_cache_delete( $user_login, 'userlogins' ); … … 1741 1739 * @param mixed $userdata An array of user data or a user object of type stdClass or WP_User. 1742 1740 * @return int|WP_Error The updated user's ID or a WP_Error object if the user could not be updated. 1743 1741 */ 1744 function wp_update_user( $userdata) {1742 function wp_update_user( $userdata ) { 1745 1743 if ( $userdata instanceof stdClass ) { 1746 1744 $userdata = get_object_vars( $userdata ); 1747 1745 } elseif ( $userdata instanceof WP_User ) { … … 1753 1751 return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) ); 1754 1752 } 1755 1753 1756 // First, get all of the original fields 1754 // First, get all of the original fields. 1757 1755 $user_obj = get_userdata( $ID ); 1758 1756 if ( ! $user_obj ) { 1759 1757 return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) ); … … 1761 1759 1762 1760 $user = $user_obj->to_array(); 1763 1761 1764 // Add additional custom fields 1762 // Add additional custom fields. 1765 1763 foreach ( _get_additional_user_keys( $user_obj ) as $key ) { 1766 1764 $user[ $key ] = get_user_meta( $ID, $key, true ); 1767 1765 } … … 1770 1768 $user = add_magic_quotes( $user ); 1771 1769 1772 1770 if ( ! empty( $userdata['user_pass'] ) && $userdata['user_pass'] !== $user_obj->user_pass ) { 1773 // If password is changing, hash it now 1771 // If password is changing, hash it now. 1774 1772 $plaintext_pass = $userdata['user_pass']; 1775 1773 $userdata['user_pass'] = wp_hash_password( $userdata['user_pass'] ); 1776 1774 … … 1875 1873 $pass_change_email['message'] = str_replace( '###SITEURL###', home_url(), $pass_change_email['message'] ); 1876 1874 1877 1875 wp_mail( $pass_change_email['to'], sprintf( $pass_change_email['subject'], $blog_name ), $pass_change_email['message'], $pass_change_email['headers'] ); 1878 } 1876 } // End if(). 1879 1877 1880 1878 if ( ! empty( $send_email_change_email ) ) { 1881 1879 /* translators: Do not translate USERNAME, ADMIN_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */ … … 1930 1928 $email_change_email['message'] = str_replace( '###SITEURL###', home_url(), $email_change_email['message'] ); 1931 1929 1932 1930 wp_mail( $email_change_email['to'], sprintf( $email_change_email['subject'], $blog_name ), $email_change_email['message'], $email_change_email['headers'] ); 1933 } 1931 } // End if(). 1934 1932 1935 1933 if ( $switched_locale ) { 1936 1934 restore_previous_locale(); 1937 1935 } 1938 } 1936 } // End if(). 1939 1937 1940 1938 // Update the cookies if the password changed. 1941 1939 $current_user = wp_get_current_user(); 1942 1940 if ( $current_user->ID == $ID ) { 1943 if ( isset( $plaintext_pass) ) {1941 if ( isset( $plaintext_pass ) ) { 1944 1942 wp_clear_auth_cookie(); 1945 1943 1946 1944 // Here we calculate the expiration length of the current auth cookie and compare it to the default expiration. … … 1972 1970 * @return int|WP_Error The newly created user's ID or a WP_Error object if the user could not 1973 1971 * be created. 1974 1972 */ 1975 function wp_create_user( $username, $password, $email = '') {1973 function wp_create_user( $username, $password, $email = '' ) { 1976 1974 $user_login = wp_slash( $username ); 1977 $user_email = wp_slash( $email 1975 $user_email = wp_slash( $email ); 1978 1976 $user_pass = $password; 1979 1977 1980 $userdata = compact( 'user_login', 'user_email', 'user_pass');1981 return wp_insert_user( $userdata);1978 $userdata = compact( 'user_login', 'user_email', 'user_pass' ); 1979 return wp_insert_user( $userdata ); 1982 1980 } 1983 1981 1984 1982 /** … … 2014 2012 $methods = array( 2015 2013 'aim' => __( 'AIM' ), 2016 2014 'yim' => __( 'Yahoo IM' ), 2017 'jabber' => __( 'Jabber / Google Talk' ) 2015 'jabber' => __( 'Jabber / Google Talk' ), 2018 2016 ); 2019 2017 } 2020 2018 … … 2024 2022 * @since 2.9.0 2025 2023 * 2026 2024 * @param array $methods Array of contact methods and their labels. 2025 * 2027 2026 * @param WP_User $user WP_User object. 2028 2027 */ 2029 2028 return apply_filters( 'user_contactmethods', $methods, $user ); … … 2165 2164 * @param string $login The user login. 2166 2165 * @return WP_User|WP_Error WP_User object on success, WP_Error object for invalid or expired keys. 2167 2166 */ 2168 function check_password_reset_key( $key, $login) {2167 function check_password_reset_key( $key, $login ) { 2169 2168 global $wpdb, $wp_hasher; 2170 2169 2171 2170 $key = preg_replace('/[^a-z0-9]/i', '', $key); 2172 2171 2173 if ( empty( $key ) || ! is_string( $key ) )2172 if ( empty( $key ) || ! is_string( $key ) ) 2174 2173 return new WP_Error('invalid_key', __('Invalid key')); 2175 2174 2176 if ( empty($login) || ! is_string($login) )2175 if ( empty($login) || ! is_string($login) ) 2177 2176 return new WP_Error('invalid_key', __('Invalid key')); 2178 2177 2179 2178 $row = $wpdb->get_row( $wpdb->prepare( "SELECT ID, user_activation_key FROM $wpdb->users WHERE user_login = %s", $login ) ); … … 2211 2210 if ( $hash_is_correct && $expiration_time && time() < $expiration_time ) { 2212 2211 return get_userdata( $row->ID ); 2213 2212 } elseif ( $hash_is_correct && $expiration_time ) { 2214 // Key has an expiration time that's passed 2213 // Key has an expiration time that's passed. 2215 2214 return new WP_Error( 'expired_key', __( 'Invalid key' ) ); 2216 2215 } 2217 2216 … … 2241 2240 * 2242 2241 * @since 2.5.0 2243 2242 * 2244 * @param object $user The user 2245 * @param string $new_pass New password for the user in plaintext 2243 * @param object $user The user. 2244 * @param string $new_pass New password for the user in plaintext. 2246 2245 */ 2247 2246 function reset_password( $user, $new_pass ) { 2248 2247 /** … … 2274 2273 * 2275 2274 * @since 2.5.0 2276 2275 * 2277 * @param string $user_login User's username for logging in 2278 * @param string $user_email User's email address to send password and add 2276 * @param string $user_login User's username for logging in. 2277 * @param string $user_email User's email address to send password and add. 2279 2278 * @return int|WP_Error Either user's ID or error on failure. 2280 2279 */ 2281 2280 function register_new_user( $user_login, $user_email ) { … … 2291 2290 */ 2292 2291 $user_email = apply_filters( 'user_registration_email', $user_email ); 2293 2292 2294 // Check the username 2295 if ( $sanitized_user_login == '') {2293 // Check the username. 2294 if ( '' == $sanitized_user_login ) { 2296 2295 $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Please enter a username.' ) ); 2297 2296 } elseif ( ! validate_username( $user_login ) ) { 2298 2297 $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) ); … … 2308 2307 } 2309 2308 } 2310 2309 2311 // Check the email address 2312 if ( $user_email == '') {2310 // Check the email address. 2311 if ( '' == $user_email ) { 2313 2312 $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your email address.' ) ); 2314 2313 } elseif ( ! is_email( $user_email ) ) { 2315 2314 $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn’t correct.' ) ); … … 2506 2505 return $current_user; 2507 2506 } 2508 2507 2509 // Upgrade stdClass to WP_User 2508 // Upgrade stdClass to WP_User. 2510 2509 if ( is_object( $current_user ) && isset( $current_user->ID ) ) { 2511 2510 $cur_id = $current_user->ID; 2512 2511 $current_user = null;