• Does this plugin determine role based on the role label and not the role slug?

    I’m having an issue where a role relabeled as “Administrator” is auto-filling to all the admin capabilities ( regardless if they’ve been updated ) even though the parenthesis next to the label states that the role is an “editor”. Whenever I update the editor role (labeled as Administrator) it gives the editor role administrator capabilities.

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

    (@shinephp)

    Every role has id (slug) and name (label) in URE terms. URE works with roles stuff via their id and uses their names just for visualisation.

    I tried to rename ‘Editor’ role to ‘Administrator’ inside URE and did not see any change of the capabilities list granted to it.

    Share the step by step scenario to repeat this.

    Thread Starter Howdy_McGee

    (@howdy_mcgee)

    Ah, I did not relabel the role through URE, I relabelled it via the code snippet below:

    /**
     * Relabel Roles
     * 
     * @return void
     */
    function prefix_relabel_roles() {
    	
    	global $wp_roles;
    	
    	if( empty( $wp_roles ) ) {
    		$wp_roles = new WP_Roles();
    	}
    	
    	if( isset( $wp_roles->roles['editor'] ) ) {
    		$wp_roles->roles['editor']['name'] 	= esc_html__( 'Administrator' );
    		$wp_roles->role_names['editor'] 	= esc_html__( 'Administrator' );
    	}
    	
    	if( isset( $wp_roles->roles['administrator'] ) ) {
    		$wp_roles->roles['administrator']['name'] 	= esc_html__( 'Super Admin' );
    		$wp_roles->role_names['administrator'] 		= esc_html__( 'Super Admin' );
    	}
    	
    }
    add_action( 'init', 'prefix_relabel_roles' );

    After using the above hook, if I go to the User Role Editor and click “Administrator (editor)” from the drop down, they suddenly have all the Administrator capabilities selected.

    Plugin Author Vladimir Garagulya

    (@shinephp)

    Thanks for the clarification. I still can not reproduce the described effect.

    I installed code above as MU plugin. See renamed ‘Administrator (editor)’, ‘Superadmin (administrator)’ roles at User Role Editor, but original editor role has the same list of capabilities as before renaming, as it should be.
    I tested renamed role update: adding and removing capabilities.

    Re-check, if any JavaScript error appears at URE page? It may prevent view update. You may don’t see real role content in this case.

    Thread Starter Howdy_McGee

    (@howdy_mcgee)

    I can copy and paste the above code into a fresh install either as a MU plugin or straight into the themes functions.php file and I get the same result.

    I can rename the editor and it appears -> https://snag.gy/f0s8zR.jpg

    https://snag.gy/hmBGZH.jpg

    When I comment out the rename, it reverts back to normal -> https://snag.gy/yK67xB.jpg

    No JavaScript errors. Windows 10, Google Chrome, all up to date.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Relabeling Role Issue’ is closed to new replies.