Ticket #36376: for36376.diff
File for36376.diff, 2.3 KB (added by , 7 years ago) |
---|
-
src/wp-includes/class-wp-user.php
486 486 * 487 487 * @return array List of all capabilities for the user. 488 488 */ 489 public function get_role_caps() {489 public function get_role_caps() { 490 490 $switch_site = false; 491 491 if ( is_multisite() && $this->site_id != get_current_blog_id() ) { 492 492 $switch_site = true; … … 494 494 switch_to_blog( $this->site_id ); 495 495 } 496 496 497 $wp_roles = wp_roles();497 $wp_roles = wp_roles(); 498 498 499 // Filter out caps that are not role names and assign to $this->roles.500 if ( is_array( $this->caps ) ) {501 $this->roles = array_filter( array_keys( $this->caps ), array( $wp_roles, 'is_role' ) );499 // Filter out caps that are not role names and assign to $this->roles. 500 if ( is_array( $this->caps ) ) { 501 $this->roles = array_filter( array_keys( $this->caps ), array( $wp_roles, 'is_role' ) ); 502 502 } 503 503 504 // Build $allcaps from role caps, overlay user's $caps. 505 $this->allcaps = array(); 506 foreach ( (array) $this->roles as $role ) { 507 $the_role = $wp_roles->get_role( $role ); 508 $this->allcaps = array_merge( (array) $this->allcaps, (array) $the_role->capabilities ); 509 } 510 $this->allcaps = array_merge( (array) $this->allcaps, (array) $this->caps ); 504 // Build $allcaps from role caps, overlay user's $caps. 505 $this->allcaps = array(); 506 foreach ( (array) $this->roles as $role ) { 507 $the_role = $wp_roles->get_role( $role ); 511 508 509 /* 510 * Merge role capabilities. 511 * Have to use this approach, instead of array_merge, 512 * to make sure a "0" in one role doesn't overwrite a "1" on another. 513 */ 514 foreach( (array) $the_role->capabilities as $cap => $value ) { 515 if ( ! isset( $this->allcaps[ $cap ] ) || ( ! $this->allcaps[ $cap ] && $value ) ) { 516 $this->allcaps[ $cap ] = $value; 517 } 518 } 519 } 520 521 // Merge role capabilities. 522 foreach( (array) $this->caps as $cap => $value ) { 523 if ( ! isset( $this->allcaps[ $cap ] ) || ( ! $this->allcaps[ $cap ] && $value ) ) { 524 $this->allcaps[ $cap ] = $value; 525 } 526 } 527 512 528 if ( $switch_site ) { 513 529 restore_current_blog(); 514 530 } 515 531 516 return $this->allcaps;517 }532 return $this->allcaps; 533 } 518 534 519 535 /** 520 536 * Add role to user.