[wp-trac] [WordPress Trac] #54572: Add a function for updating the existing role instead of removing, then adding one

WordPress Trac noreply at wordpress.org
Sun Apr 10 19:54:22 UTC 2022


#54572: Add a function for updating the existing role instead of removing, then
adding one
-------------------------------------------------+-------------------------
 Reporter:  maksimkuzmin                         |       Owner:  (none)
     Type:  enhancement                          |      Status:  reviewing
 Priority:  normal                               |   Milestone:  6.0
Component:  Role/Capability                      |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests needs-      |     Focuses:
  refresh                                        |  performance
-------------------------------------------------+-------------------------

Comment (by NomNom99):

 == Test Report

 === Environment

 **WordPress**: 6.0-alpha-52448-src
 **Browser**: Chrome, version 100.0.4896.75 (Official Build) (x86_64)
 **Operating System**: macOS Big Sur 11.6

 === Steps to test

 1. Clone WordPress-develop using `git at github.com:WordPress/wordpress-
 develop.git`
 2. Setup WordPress using [https://github.com/WordPress/wordpress-develop
 #to-start-the-development-environment-for-the-first-time this instruction]
 3. Pull the changes of this patch using the command `npm run grunt
 patch:54572`
 4. Open the `functions.php` file of the active theme.
 5. Copy-paste the following snippet in the `functions.php` file.

 {{{
 function ticket_54572() {
     add_role(
         'school_staff',
         'Teacher',
         get_role( 'contributor' )->capabilities
     );
 }
 add_action( 'init', 'ticket_54572' );
 }}}

 This will add a `Teacher` role with capabilities of a Contributor.

 6. Reload WordPress as admin and add a new user with the `Teacher` role.
 7. Replace the above copy-pasted with the following:

 {{{
 function ticket_54572() {
     update_role(
         'school_staff',
         'Principal',
         get_role( 'administrator' )->capabilities
     );
 }
 add_action( 'init', 'ticket_54572' );
 }}}

 8. Reload the WordPress site and observe that the name of the
 `school_staff` role is renamed from `Teacher` to `Principal` and the
 capabilities have changed from that of a Contributor to an Administrator.

 === Results
 - The patch is working as intended

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54572#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list