[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
Mon Oct 24 15:19:22 UTC 2022


#54572: Add a function for updating the existing role instead of removing, then
adding one
-------------------------------------------------+-------------------------
 Reporter:  maksimkuzmin                         |       Owner:
                                                 |  davidbaumwald
     Type:  enhancement                          |      Status:  reopened
 Priority:  normal                               |   Milestone:  6.1
Component:  Role/Capability                      |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests commit      |     Focuses:
  dev-reviewed                                   |
-------------------------------------------------+-------------------------
Changes (by SergeyBiryukov):

 * keywords:  has-patch has-unit-tests commit dev-feedback => has-patch has-
     unit-tests commit dev-reviewed


Comment:

 [54673] looks good to apply to the 6.1 branch.

 I'm not sure yet what the right solution would be here, but I think
 comment:29 does bring up a good point that existing methods can be used
 for this.

 Also, looking at the ticket description:
 > Say, I already have a role `picture_admin`. I might want to alter its
 display name, or capabilities as an array, or both at once. What I'm
 forced to do now is this (not taking peculiar ways of editing wp_options
 table in account):
 >
 > {{{#!php
 > <?php
 >
 > remove_role( 'picture_admin' );
 > add_role( 'picture_admin', $display_name, $capabilities );
 > }}}

 I might be missing something, but wouldn't `add_role()` work for updating
 the role without removing it first? Based on a brief reading of
 `WP_Roles::add_role()`, it seems like it should just overwrite the
 existing role definition.

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


More information about the wp-trac mailing list