Support » Plugin: User Role Editor » Hide Default User Roles

  • Resolved Kyle H

    (@cikez)


    First of all I would like to thank you for the great plugin.

    Now I have researched several sites and cannot for the life of me find a way to do this. I want to use User Role Editor to create my own custom user roles but I do not want the default user roles of wordpress to still be available in the dropdown menu’s. Example: Author, Subscriber, etc..

    Do you know if there is anyway to hide these roles completely?

    Thanks!

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

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

    (@shinephp)

    Try to add this code into your active theme functions.php file:

    if (!current_user_can('administrator')) {
    add_filter('editable_roles', 'exclude_role' );
    public function exclude_role($roles)
    {
    
        if (isset($roles['administrator'])) {
          unset($roles['administrator']);
        }
    
        return $roles;
    }
    }

    If it work for you, add code for the rest of WP roles.

    Vladimir,

    I tried adding the following code to my themes functions.php file and got

    if (!current_user_can('author')) {
    add_filter('editable_roles', 'exclude_role' );
    public function exclude_role($roles)
    {
    
        if (isset($roles['author'])) {
          unset($roles['author']);
        }
    
        return $roles;
    }
    }

    “HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.”

    Any ideas?

    Kyle,

    Get rid of the “public” in front of function. I ran this and everything works great.

    function exclude_role($roles) {
    
    		//Hide Defualt Roles
    	    if (isset($roles['author'])) {
    	      unset($roles['author']);
    	    }
    
    		if (isset($roles['editor'])) {
    	      unset($roles['editor']);
    	    }
    
    		if (isset($roles['subscriber'])) {
    	      unset($roles['subscriber']);
    	    }
    
    		if (isset($roles['contributor'])) {
    	      unset($roles['contributor']);
    	    }
    
    	    return $roles;
    	 }
    	 add_filter('editable_roles', 'exclude_role' );
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hide Default User Roles’ is closed to new replies.