Okay
  Public Ticket #3733597
How to hide in dashboard one of menu element for specific user role
Closed

Comments

  •  2
    Lukasz started the conversation

    Hi i have sales agents and some of them has second user role "can-have-subagents" and I want to show the "Subagents" menu will be shown only for sales agent have "can-have-subagents" user role.

    Could You help me please ?

  •  2,212
    WebWizards replied

    Hi Lukasz,

    I believe that you're referring to the "My Team" tab / menu item on the agent dashboard, is that right?

     

    I believe you can achieve it, by adding this PHP snippet to your site:

    add_filter('salesking_dashboard_menu_items', function($menu) {
        $user = wp_get_current_user();
        if ( ! in_array('can-have-subagents', (array) $user->roles)) {
            unset($menu['team']);
        }
        return $menu;
    }, 10, 1);
    
    add_filter('option_salesking_enable_teams_setting', function($val){
    
    	$user = wp_get_current_user();
    	if ( ! in_array('can-have-subagents', (array) $user->roles)) {
    	    $val = 0;
    	}
    
    	return $val;
    }, 10, 1);

     

    It should remove 'My Team' for any users that do not have that role.

     

    Let me know if that can solve it for you,

    Kind regards,

    Stefan