I am making system where I am delegating a lot of functionality to the front end of a system using WordPress. I have listed all the roles (most of the custom) and need to ability for a logged in user to edit the name of the role or delete it.
I cant find any normal WP functions to do this, or plugins that allow the simple solution I need, so I was thinking I may need to run a MYSQL query to change the info but.. have you seen the wp_options table with the user role information?? Its a massive mess and I dont really want to destroy the system.
Any suggestions?
Thanks in advance.
There’s a whole host of functions specifically for this purpose;
http://codex.wordpress.org/Function_Reference#User_and_Author_Functions
Of particular interest (but not limited to) are,
As well as numerous other user related functions that will allow you to verify/validate their authority based upon your use-case scenario and so on.
Looking in
wp-includes/capabilities.php
you we can see that the role_names are held in an array, therefore something to the effect of,Might need a little tweaking as that’s untested.
Edit:
I just found this: is-there-way-to-rename-user-role-name-without-plugin – check it out. Virtually identical to what I am suggesting but with the exception of instantiating the class and checking that the variable
$wp_roles
is actually defined/set. I’ll assume that it works on the basis that its marked correctly but naturally please test this to confirm.But in a similar fashion looking at the following which is taken directly from core installation file
wp-includes/capabilities.php
line 133,…we can see,
…therefore updating the $display_name argument of an existing role will have the same desired effect without actually modifying the role itself so as to preserve its users associated with the role.
Don’t work with that mess
Open the file “wp-includes/capabilities.php”
Inside there are 3 classes “WP_Roles”, “WP_Role” & “WP_User”
These 3 classes are capable of easily handling every functionality related to user roles & capabilities
If youâre looking for a plugin, you should try out the Members plugin by Justin Tadlock. It contains an easy and clean role manager.
I highly recommend to have a look at the code too. Justinâs code really is top-notch, a true delight in contrast with many other WP plugins.