Is there anyway to rename a user role name via hook, instead of using plugin?
Edit
For example, administrator
» owner
Is there anyway to rename a user role name via hook, instead of using plugin?
For example, administrator
» owner
You must be logged in to post a comment.
http://www.garyc40.com/2010/04/ultimate-guide-to-roles-and-capabilities/
Actually, there are many ways to achieve that:
With pure php and mysql you can edit the serialized entry in the db. Indeed, WordPress stores the serialized array of roles in
wp_options
table.So:
SELECT option_value as serialized_string FROM wp_options WHERE option_name = 'wp_user_roles';
$rolesArray = unserialize($serialized_string)
$rolesArray['role_key']['name'] = "New name"
echo serialize($rolesArray)
option_value
content with output from the previous pointIf you feel confident with WordPress, you can even use the embedded WordPress REPL in wp-cli to fetch the stored value with
get_option('wp_user_roles')
and then useupdate_option
to update it.And (always) remember to backup the db before options manipulation 😉
Otherwise, if you donât care about role_key valueâ¦
â¦itâs very easy to achieve that with wp-cli:
$ wp role create new_role 'New Role' --clone=old_role
$ wp role delete old_role
If you are using WP version 4.7+ you may accomplish this using the
wp_roles_init
action like so:A simple solution would be to just add a user role using
add_role
, that way you can name it whatever you want and add whatever capabilities you want.http://codex.wordpress.org/Function_Reference/add_role
You can create a custom localization file. Get this file: http://svn.automattic.com/wordpress-i18n/pot/trunk/wordpress.pot and edit using PoEdit tool (for example). In next step save localization file as en_GB.mo (or other) and edit wp-config file:
define (“WPLANG”, “en_GB”);
You can edit it directly in your DB, and it will be edited permanently for your website. Here is where WP keeps user roles