Changeset 52823
- Timestamp:
- 03/06/2022 04:09:06 PM (19 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-user.php
r51851 r52823 543 543 } 544 544 545 if ( in_array( $role, $this->roles, true ) ) { 546 return; 547 } 548 545 549 $this->caps[ $role ] = true; 546 550 update_user_meta( $this->ID, $this->cap_key, $this->caps ); … … 570 574 return; 571 575 } 576 572 577 unset( $this->caps[ $role ] ); 573 578 update_user_meta( $this->ID, $this->cap_key, $this->caps ); … … 607 612 608 613 $old_roles = $this->roles; 614 609 615 if ( ! empty( $role ) ) { 610 616 $this->caps[ $role ] = true; 611 617 $this->roles = array( $role => true ); 612 618 } else { 613 $this->roles = false; 614 } 619 $this->roles = array(); 620 } 621 615 622 update_user_meta( $this->ID, $this->cap_key, $this->caps ); 616 623 $this->get_role_caps(); 617 624 $this->update_user_level_from_caps(); 625 626 foreach ( $old_roles as $old_role ) { 627 if ( ! $old_role || $old_role === $role ) { 628 continue; 629 } 630 631 /** This action is documented in wp-includes/class-wp-user.php */ 632 do_action( 'remove_user_role', $this->ID, $old_role ); 633 } 634 635 if ( $role && ! in_array( $role, $old_roles, true ) ) { 636 /** This action is documented in wp-includes/class-wp-user.php */ 637 do_action( 'add_user_role', $this->ID, $role ); 638 } 618 639 619 640 /** -
trunk/tests/phpunit/tests/user/capabilities.php
r52010 r52823 1624 1624 $caps = $user->caps; 1625 1625 $this->assertNotEmpty( $user->caps ); 1626 1626 1627 $user->set_role( 'administrator' ); 1627 1628 $this->assertNotEmpty( $user->caps ); 1628 1629 $this->assertSame( $caps, $user->caps ); 1630 } 1631 1632 /** 1633 * @ticket 54164 1634 */ 1635 public function test_set_role_fires_remove_user_role_and_add_user_role_hooks() { 1636 $user = self::$users['administrator']; 1637 1638 $remove_user_role = new MockAction(); 1639 $add_user_role = new MockAction(); 1640 add_action( 'remove_user_role', array( $remove_user_role, 'action' ) ); 1641 add_action( 'add_user_role', array( $add_user_role, 'action' ) ); 1642 1643 $user->set_role( 'editor' ); 1644 $this->assertSame( 1, $remove_user_role->get_call_count() ); 1645 $this->assertSame( 1, $add_user_role->get_call_count() ); 1629 1646 } 1630 1647
Note: See TracChangeset
for help on using the changeset viewer.