WordPress.org

Ready to get started?Download WordPress

Forums

User Role Editor
[resolved] Hide Default User Roles (4 posts)

  1. Kyle H
    Member
    Posted 1 year ago #

    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/

  2. Vladimir Garagulya
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  3. Kyle H
    Member
    Posted 1 year ago #

    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?

  4. Clayton Kreisel
    Member
    Posted 1 month ago #

    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' );

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.