[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
Fri Dec 3 17:14:51 UTC 2021
#54572: Add a function for updating the existing role instead of removing, then
adding one
--------------------------+-----------------------------
Reporter: maksimkuzmin | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: trunk
Severity: normal | Keywords:
Focuses: performance |
--------------------------+-----------------------------
While I was working on and developing multiple themes and plugins, I often
needed to update the existing role after using `add_role` function.
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 );
}}}
This code has multiple issues. First, I'll have to perform double query to
MySQL database, which affects performance and doesn't feel right to me.
Second, I won't be able to alter just one field as easily with one
function, I need to carry out the old variable for either display name or
capabilities every time I call this statement.
Instead, I propose having a neat way of easily updating roles via the
following statement:
{{{#!php
<?php
update_role( $role_name, 'New Display Name', $caps );
// or
update_role( $role_name, null, $caps );
// or
update_role( $role_name, 'New Display Name' );
}}}
Which also creates a role if it doesn't exist already.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/54572>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list