WordPress.org

Support

Support » Plugins and Hacks » [Resolved] How to rename custom roles ?

[Resolved] How to rename custom roles ?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Vladimir Garagulya

    @shinephp

    Hello,

    It’s not possible with URE directly, while it is a good feature request for future version.
    For this time you can go this way. Add code below to your theme functions.php file:

    add_filter( 'init', 'change_role_names');
    function change_role_names() {<br />
        global $wp_roles;</p>
        if ( ! isset( $wp_roles ) )
            $wp_roles = new WP_Roles();
        $wp_roles->roles['manager']['name'] = 'new_manager';
        $wp_roles->role_names['manager'] = 'new_manager';
    }

    Then select role ‘new_manager’ in URE and press Update, may be you will should to add/delete some capability to really save changes. After that you will have renamed role in your database and can delete code above from functions.php.

    Great it seems to work. But what happens when I re-name again my re-named role? I see 2 different roles: the original one and the new one > is it normal ?
    Thank you

    Plugin Author Vladimir Garagulya

    @shinephp

    You should have only one role as renaming executed in place. If something went wrong and you got role copy, you can delete unneeded one – URE can do that.

    Well it doesn’t seem to work. I’m placing this in functions.php

    add_filter( ‘init’, ‘change_role_names’);
    function change_role_names() {
    global $wp_roles;

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

    $wp_roles->roles[‘SiteManager’][‘name’] = ‘Gestionnaire’;
    $wp_roles->role_names[‘SiteManager’] = ‘Gestionnaire’;
    }

    Then I get 2 roles: Gestionnaire and SiteManager but when I click on Gestionnaire it redirects to SiteManager. When I click update on SiteManager all options are back and saved but it’s still called SiteManager and Gestionnaire still redirect to it.
    And if I delete the lines from functions.php Gestionnaire is removed.

    Something related to uppercase?

    Plugin Author Vladimir Garagulya

    @shinephp

    Yes, your role has id ‘manager’ and name ‘Manager’, you should use
    $wp_roles->roles[‘manager’][‘name’] = ‘Gestionnaire’;
    to work with the same old role. It will keep old id ‘manager’ but for user interface becomes ‘Gestionnaire’.

    So it doesn’t really change the name, only UI name.. OK.
    Thank you Vladimir

    Hi,

    I’ve noticed that the renamed role does not impact other network subsites (= a user with role “SiteManager” is still displayed under “SiteManager” and not “Gestionnaire” – the renamed role, applied to all sites).

    Is it normal?

    Thanks

    Plugin Author Vladimir Garagulya

    @shinephp

    Hi,

    Yes, it is current behavior. And this can be named as a bug.
    ure_lib.php, at line #228 has this code:

    if (!isset($ure_roles[$ure_currentRole])) {
        $ure_roles[$ure_currentRole]['name'] = $ure_currentRoleName;
      }

    Thus, as renaming role by trick above we change just role name, but not its ID, URE doesn’t change role name for other sites of the network. I will investigate this and make decision on this code to the next URE update.
    Thanks for letting me to look on my code from other side.

    Regards,
    Vladimir.

    Hi,

    Ah ok.

    You’re welcome..

    Thanks for improving your plugin anyway.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Resolved] How to rename custom roles ?’ is closed to new replies.