Skip to main content
added 452 characters in body
Source Link
Dharma
  • 151
  • 1
  • 4

If you don’t care about role_key value…

…it’s very easyActually, there are many ways to achieve that with wp-cli:

  1. duplicate the existing role – $ wp role create new_role 'New Role' --clone=old_role
  2. then delete the old one – $ wp role delete old_role
  3. and last reassociate the user(s).

Otherwise…

…youWith pure php and mysql you can edit the serialized entry in the db. Wordpress Indeed, Wordpress stores the serialized array of roles in wp_options table. 

So:

  1. Fetch the serialized array:
    SELECT option_value as serialized_string FROM wp_options WHERE option_name = 'wp_user_roles';
  2. Unserialize the string – php: $rolesArray = unserialize($serialized_string)
  3. Change the role name – php: $rolesArray['role_key']['name'] = "New name"
  4. Serialize back the array – php: echo serialize($rolesArray)
  5. Replace the db option_value content with output from the previous point

If 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 use update_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:

  1. duplicate the existing role – $ wp role create new_role 'New Role' --clone=old_role
  2. delete the old one – $ wp role delete old_role
  3. then associate new_role to the user(s).
  4. eventually repeat step 1 and 2 until old_role = new_role

If you don’t care about role_key value…

…it’s very easy to achieve that with wp-cli:

  1. duplicate the existing role – $ wp role create new_role 'New Role' --clone=old_role
  2. then delete the old one – $ wp role delete old_role
  3. and last reassociate the user(s).

Otherwise…

…you can edit the serialized entry in the db. Wordpress stores the serialized array of roles in wp_options table. So:

  1. Fetch the serialized array:
    SELECT option_value as serialized_string FROM wp_options WHERE option_name = 'wp_user_roles';
  2. Unserialize the string – php: $rolesArray = unserialize($serialized_string)
  3. Change the role name – php: $rolesArray['role_key']['name'] = "New name"
  4. Serialize back the array – php: echo serialize($rolesArray)
  5. Replace the db option_value content with output from the previous point

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:

  1. Fetch the serialized array:
    SELECT option_value as serialized_string FROM wp_options WHERE option_name = 'wp_user_roles';
  2. Unserialize the string – php: $rolesArray = unserialize($serialized_string)
  3. Change the role name – php: $rolesArray['role_key']['name'] = "New name"
  4. Serialize back the array – php: echo serialize($rolesArray)
  5. Replace the db option_value content with output from the previous point

If 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 use update_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:

  1. duplicate the existing role – $ wp role create new_role 'New Role' --clone=old_role
  2. delete the old one – $ wp role delete old_role
  3. then associate new_role to the user(s).
  4. eventually repeat step 1 and 2 until old_role = new_role
Source Link
Dharma
  • 151
  • 1
  • 4

If you don’t care about role_key value…

…it’s very easy to achieve that with wp-cli:

  1. duplicate the existing role – $ wp role create new_role 'New Role' --clone=old_role
  2. then delete the old one – $ wp role delete old_role
  3. and last reassociate the user(s).

Otherwise…

…you can edit the serialized entry in the db. Wordpress stores the serialized array of roles in wp_options table. So:

  1. Fetch the serialized array:
    SELECT option_value as serialized_string FROM wp_options WHERE option_name = 'wp_user_roles';
  2. Unserialize the string – php: $rolesArray = unserialize($serialized_string)
  3. Change the role name – php: $rolesArray['role_key']['name'] = "New name"
  4. Serialize back the array – php: echo serialize($rolesArray)
  5. Replace the db option_value content with output from the previous point