Changeset 42343 for trunk/src/wp-includes/class-wp-user.php
- Timestamp:
- 11/30/2017 11:09:33 PM (9 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/class-wp-user.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-user.php
r42151 r42343 123 123 public function __construct( $id = 0, $name = '', $site_id = '' ) { 124 124 if ( ! isset( self::$back_compat_keys ) ) { 125 $prefix = $GLOBALS['wpdb']->prefix;125 $prefix = $GLOBALS['wpdb']->prefix; 126 126 self::$back_compat_keys = array( 127 'user_firstname' => 'first_name',128 'user_lastname' => 'last_name',129 'user_description' => 'description',130 'user_level' => $prefix . 'user_level',131 $prefix . 'usersettings' => $prefix . 'user-settings',127 'user_firstname' => 'first_name', 128 'user_lastname' => 'last_name', 129 'user_description' => 'description', 130 'user_level' => $prefix . 'user_level', 131 $prefix . 'usersettings' => $prefix . 'user-settings', 132 132 $prefix . 'usersettingstime' => $prefix . 'user-settings-time', 133 133 ); … … 144 144 if ( ! empty( $id ) && ! is_numeric( $id ) ) { 145 145 $name = $id; 146 $id = 0;146 $id = 0; 147 147 } 148 148 … … 170 170 public function init( $data, $site_id = '' ) { 171 171 $this->data = $data; 172 $this->ID = (int) $data->ID;172 $this->ID = (int) $data->ID; 173 173 174 174 $this->for_site( $site_id ); … … 200 200 // Make sure the value is numeric to avoid casting objects, for example, 201 201 // to int 1. 202 if ( ! is_numeric( $value ) ) 202 if ( ! is_numeric( $value ) ) { 203 203 return false; 204 } 204 205 $value = intval( $value ); 205 if ( $value < 1 ) 206 if ( $value < 1 ) { 206 207 return false; 208 } 207 209 } else { 208 210 $value = trim( $value ); 209 211 } 210 212 211 if ( ! $value )213 if ( ! $value ) { 212 214 return false; 215 } 213 216 214 217 switch ( $field ) { 215 218 case 'id': 216 $user_id = $value;219 $user_id = $value; 217 220 $db_field = 'ID'; 218 221 break; 219 222 case 'slug': 220 $user_id = wp_cache_get($value, 'userslugs');223 $user_id = wp_cache_get( $value, 'userslugs' ); 221 224 $db_field = 'user_nicename'; 222 225 break; 223 226 case 'email': 224 $user_id = wp_cache_get($value, 'useremail');227 $user_id = wp_cache_get( $value, 'useremail' ); 225 228 $db_field = 'user_email'; 226 229 break; 227 230 case 'login': 228 $value = sanitize_user( $value );229 $user_id = wp_cache_get($value, 'userlogins');231 $value = sanitize_user( $value ); 232 $user_id = wp_cache_get( $value, 'userlogins' ); 230 233 $db_field = 'user_login'; 231 234 break; … … 235 238 236 239 if ( false !== $user_id ) { 237 if ( $user = wp_cache_get( $user_id, 'users' ) ) 240 if ( $user = wp_cache_get( $user_id, 'users' ) ) { 238 241 return $user; 239 } 240 241 if ( !$user = $wpdb->get_row( $wpdb->prepare( 242 "SELECT * FROM $wpdb->users WHERE $db_field = %s", $value 243 ) ) ) 242 } 243 } 244 245 if ( ! $user = $wpdb->get_row( 246 $wpdb->prepare( 247 "SELECT * FROM $wpdb->users WHERE $db_field = %s", $value 248 ) 249 ) ) { 244 250 return false; 251 } 245 252 246 253 update_user_caches( $user ); … … 259 266 public function __isset( $key ) { 260 267 if ( 'id' == $key ) { 261 _deprecated_argument( 'WP_User->id', '2.1.0', 268 _deprecated_argument( 269 'WP_User->id', '2.1.0', 262 270 sprintf( 263 271 /* translators: %s: WP_User->ID */ … … 269 277 } 270 278 271 if ( isset( $this->data->$key ) ) 279 if ( isset( $this->data->$key ) ) { 272 280 return true; 273 274 if ( isset( self::$back_compat_keys[ $key ] ) ) 281 } 282 283 if ( isset( self::$back_compat_keys[ $key ] ) ) { 275 284 $key = self::$back_compat_keys[ $key ]; 285 } 276 286 277 287 return metadata_exists( 'user', $this->ID, $key ); … … 288 298 public function __get( $key ) { 289 299 if ( 'id' == $key ) { 290 _deprecated_argument( 'WP_User->id', '2.1.0', 300 _deprecated_argument( 301 'WP_User->id', '2.1.0', 291 302 sprintf( 292 303 /* translators: %s: WP_User->ID */ … … 301 312 $value = $this->data->$key; 302 313 } else { 303 if ( isset( self::$back_compat_keys[ $key ] ) ) 314 if ( isset( self::$back_compat_keys[ $key ] ) ) { 304 315 $key = self::$back_compat_keys[ $key ]; 316 } 305 317 $value = get_user_meta( $this->ID, $key, true ); 306 318 } … … 326 338 public function __set( $key, $value ) { 327 339 if ( 'id' == $key ) { 328 _deprecated_argument( 'WP_User->id', '2.1.0', 340 _deprecated_argument( 341 'WP_User->id', '2.1.0', 329 342 sprintf( 330 343 /* translators: %s: WP_User->ID */ … … 349 362 public function __unset( $key ) { 350 363 if ( 'id' == $key ) { 351 _deprecated_argument( 'WP_User->id', '2.1.0', 364 _deprecated_argument( 365 'WP_User->id', '2.1.0', 352 366 sprintf( 353 367 /* translators: %s: WP_User->ID */ … … 487 501 488 502 //Filter out caps that are not role names and assign to $this->roles 489 if ( is_array( $this->caps ) ) 503 if ( is_array( $this->caps ) ) { 490 504 $this->roles = array_filter( array_keys( $this->caps ), array( $wp_roles, 'is_role' ) ); 505 } 491 506 492 507 //Build $allcaps from role caps, overlay user's $caps 493 508 $this->allcaps = array(); 494 509 foreach ( (array) $this->roles as $role ) { 495 $the_role = $wp_roles->get_role( $role );510 $the_role = $wp_roles->get_role( $role ); 496 511 $this->allcaps = array_merge( (array) $this->allcaps, (array) $the_role->capabilities ); 497 512 } … … 519 534 } 520 535 521 $this->caps[ $role] = true;536 $this->caps[ $role ] = true; 522 537 update_user_meta( $this->ID, $this->cap_key, $this->caps ); 523 538 $this->get_role_caps(); … … 543 558 */ 544 559 public function remove_role( $role ) { 545 if ( ! in_array($role, $this->roles) )560 if ( ! in_array( $role, $this->roles ) ) { 546 561 return; 547 unset( $this->caps[$role] ); 562 } 563 unset( $this->caps[ $role ] ); 548 564 update_user_meta( $this->ID, $this->cap_key, $this->caps ); 549 565 $this->get_role_caps(); … … 573 589 */ 574 590 public function set_role( $role ) { 575 if ( 1 == count( $this->roles ) && $role == current( $this->roles ) ) 591 if ( 1 == count( $this->roles ) && $role == current( $this->roles ) ) { 576 592 return; 577 578 foreach ( (array) $this->roles as $oldrole ) 579 unset( $this->caps[$oldrole] ); 593 } 594 595 foreach ( (array) $this->roles as $oldrole ) { 596 unset( $this->caps[ $oldrole ] ); 597 } 580 598 581 599 $old_roles = $this->roles; 582 if ( ! empty( $role ) ) {583 $this->caps[ $role] = true;584 $this->roles = array( $role => true );600 if ( ! empty( $role ) ) { 601 $this->caps[ $role ] = true; 602 $this->roles = array( $role => true ); 585 603 } else { 586 604 $this->roles = false; … … 656 674 */ 657 675 public function add_cap( $cap, $grant = true ) { 658 $this->caps[ $cap] = $grant;676 $this->caps[ $cap ] = $grant; 659 677 update_user_meta( $this->ID, $this->cap_key, $this->caps ); 660 678 $this->get_role_caps(); … … 724 742 // Multisite super admin has all caps by definition, Unless specifically denied. 725 743 if ( is_multisite() && is_super_admin( $this->ID ) ) { 726 if ( in_array( 'do_not_allow', $caps) )744 if ( in_array( 'do_not_allow', $caps ) ) { 727 745 return false; 746 } 728 747 return true; 729 748 } … … 750 769 // Must have ALL requested caps. 751 770 foreach ( (array) $caps as $cap ) { 752 if ( empty( $capabilities[ $cap ] ) ) 771 if ( empty( $capabilities[ $cap ] ) ) { 753 772 return false; 773 } 754 774 } 755 775
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)