WordPress.org

Ready to get started?Download WordPress

Forums

User Role Editor
[resolved] How to rename custom roles ? (10 posts)

  1. lOOis
    Member
    Posted 1 year ago #

    Hello Vladimir,

    I've created a new role "Manager" using URE. Is it possible to rename it using URE? If not, how could I do that?

    thank you very much

    http://wordpress.org/extend/plugins/user-role-editor/

  2. Vladimir Garagulya
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  3. lOOis
    Member
    Posted 1 year ago #

    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

  4. Vladimir Garagulya
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  5. lOOis
    Member
    Posted 1 year ago #

    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?

  6. Vladimir Garagulya
    Member
    Plugin Author

    Posted 1 year ago #

    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'.

  7. lOOis
    Member
    Posted 1 year ago #

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

  8. lOOis
    Member
    Posted 1 year ago #

    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

  9. Vladimir Garagulya
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  10. lOOis
    Member
    Posted 1 year ago #

    Hi,

    Ah ok.

    You're welcome..

    Thanks for improving your plugin anyway.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.