• Resolved Evan Herman

    (@eherman24)


    So I am doing a site for a client, and they have requested 4 Seperate user roles. Admin, Editor, Contributor and Subscribers.

    The Admin, Editor and Contributor all will have access to the dashboard section of the site, all having access to various menu items. I have been working on this problem for two days now.

    The problem I run in to when using current_user_can(); is that the only role with exclusive capabilities is the admin, with ‘manage options’.

    The Editor has capabilities that the Contributor has and the Admin has capabilities that they both have. So I have three separate functions that check user roles and remove certain menu items based on those user roles.

    This is the section of code I have for the editor specifically..

    //REMOVE EDITOR MENU ITEMS
    	 	 function remove_editor_menus()
    {
        global $menu;
        global $current_user;
        get_currentuserinfo();
    
        if(! current_user_can('Editor'))
        {
            $restricted = array(__('Links'),
                                __('Appearance'),
                                __('Plugins'),
                                __('Users'),
                                __('Tools'),
                                __('Settings'),
                                __('Posts'),
                                __('Pages')
            );
            end ($menu);
            while (prev($menu)){
                $value = explode(' ',$menu[key($menu)][0]);
                if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
            }// end while
    
        }// end if
    }
    add_action('admin_menu', 'remove_editor_menus');

    Essentially what this code is doing is changing menus for ALL user roles. I am coming to the end of my rope trying to figure out how to do this.

    I have tried changing the $argument to ‘delete_others_posts’ but again….the admin can do this and it changes both menus.

    I figured I would have to check userID’s , but I just can not figure out how to assign certain menus based on user id’s.

Viewing 1 replies (of 1 total)
  • Thread Starter Evan Herman

    (@eherman24)

    I think I got them working…so it seems

    //REMOVE EDITOR MENU ITEMS
    	function remove_editor_menus()
    {
        global $menu;
        global $current_user;
    	$user_roles = $current_user->roles;
        $user_role = array_shift($user_roles);
        get_currentuserinfo();
    
        if($user_role == 'editor')
        {
            $restricted = array(__('Links'),
                                __('Appearance'),
                                __('Plugins'),
                                __('Users'),
    							__('Comments'),
                                __('Tools'),
                                __('Settings'),
    							__('Feedbacks'),
    							__('Profile'),
    							__('Media'),
    
    		);
            end ($menu);
            while (prev($menu)){
                $value = explode(' ',$menu[key($menu)][0]);
                if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
            }// end while
    
        }// end if
    }
    add_action('admin_menu', 'remove_editor_menus');
Viewing 1 replies (of 1 total)
  • The topic ‘Custom Menus based on User Roles??? Possible??’ is closed to new replies.