WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'am creating WordPress function for editing role name

function change_role_name($role_name, $new_role_name, $display_name) {
    global $wp_roles;

    if ( ! isset( $wp_roles ) )
        $wp_roles = new WP_Roles();

    $role =& get_role($role_name);

    $wp_roles->roles[$role]['name'] = $new_role_name; //not working for sa
    $wp_roles->role_names[$role] = $display_name;           

problem here it don't change the role label name

share|improve this question

Those names are stored in the option wp_user_roles in the database table wp_options.

So, the following will change the name of the subscriber role:

$val = get_option( 'wp_user_roles' );
$val['subscriber']['name'] = 'PeDeBoi';
update_option( 'wp_user_roles', $val );

Apparently, this is harmless, but caveat emptor...

In your code, $wp_roles->roles[$role]['name'] = $new_role_name; doesn't work because it should be:

$wp_roles->roles[$role_name]['name'] = $new_role_name;

And $display_name doesn't make much sense.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.