Support » Fixing WordPress » User Role Name Change Problem

  • Resolved Tom Carroll

    (@twcarroll2)


    I am working on my site and I am setting up a members only forum and directory. In order to ease the learning curve of my support staff, I wanted to change the role names (not the actual roles) as follows:

    Subscriber -> Pending
    Contributor -> Member
    Author (unchanged)
    Editor -> Moderator
    Administrator (unchanged)

    I used the following code and put it at the top of the theme’s functions.php file via the internal WP Editor:

    function wps_change_role_name() {
    global $wp_roles;
    if ( ! isset( $wp_roles ) )
    $wp_roles = new WP_Roles();
    $wp_roles->roles[‘contributor’][‘name’] = ‘Member’;
    $wp_roles->role_names[‘contributor’] = ‘Member’;
    $wp_roles->roles[‘editor’][‘name’] = ‘Moderator’;
    $wp_roles->role_names[‘editor’] = ‘Moderator’;
    $wp_roles->roles[‘subscriber’][‘name’] = ‘Pending’;
    $wp_roles->role_names[‘subscriber’] = ‘Pending’;
    }
    add_action(‘init’, ‘wps_change_role_name’);

    That was working great, but then I was told during a support call to a plug-in author that I cannot do that and it will interfere with a lot of things. So, I went back to the functions.php file for the theme and I removed that block of code, thinking it would stop changing the role names. It did not. The role names remained “Pending, Member, and Moderator” in the Users list. So, I put the following code into the functions.php for the theme in an attempt to restore the default role names:

    if ( !function_exists( ‘populate_roles’ ) ) {
    require_once( ABSPATH . ‘wp-admin/includes/schema.php’ );
    }
    
    populate_roles();

    This did not work. So, I went back to what I initially did, and inserted this code after removing the above code.

    function wps_change_role_name() {
    global $wp_roles;
    if ( ! isset( $wp_roles ) )
    $wp_roles = new WP_Roles();
    $wp_roles->roles[‘contributor’][‘name’] = ‘Contributor’;
    $wp_roles->role_names[‘contributor’] = ‘Contributor’;
    $wp_roles->roles[‘editor’][‘name’] = ‘Editor’;
    $wp_roles->role_names[‘editor’] = ‘Editor’;
    $wp_roles->roles[‘subscriber’][‘name’] = ‘Subscriber’;
    $wp_roles->role_names[‘subscriber’] = ‘Subscriber’;
    }
    add_action(‘init’, ‘wps_change_role_name’);

    I then viewed the Users panel and their roles name were restored to the stock role names, Subscriber, Contributor, and Moderator. I then tried removing the code from the functions.php thinking it was no longer needed but, this does not work unless this code is always present in the theme. When I remove the code from the functions.php, the role names revert back to Pending, Member, Moderator.

    The interesting thing to me is the plug-in I am using (WP Symposium) shows the stock role names in all lower case, not mixed case, like the role names are set to whether they are set to the stock role names or the modified role names I used. Even when, for example, the role names being displayed in the Users panel would be “Pending”, the plug-in will display the role as “subscriber” but, if the role name being displayed in the Users panel is displayed “Subscriber, the plug-in output remains “subscriber.”

    I removed the code from the functions.php and I tried reinstalling WordPress via the dashboard, but even that did not restore those names.

    Is this a theme issue, or a deeper issue with WordPress? I would appreciate any insight as to how I can get this fixed.

    Tom
    https://www.alkiesworldwide.org/

Viewing 1 replies (of 1 total)
  • For some reason, it was not restoring the wp_options table. I searched for “Pending” using phpMyAdmin and found the entries for wp_user_roles in the wp_options table. After I directly modified that field and entered the correct names s:10:”Subscriber”, s:11:”Contributor”, and s:6:”Editor” everything is working like it is supposed to.

Viewing 1 replies (of 1 total)
  • The topic ‘User Role Name Change Problem’ is closed to new replies.