Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.