Team Control extension: hide some Menus

Hi,

I want to hide this 3 Menus with all sub menus for specific role:

  1. Settings
  2. Status
  3. Go to WP Admin (at the very bottom of menu sidebar, net to logout)

I create a new User Role and set the permission, as per attached screenshot.

I try to hide them using other plugins but failed: Advanced Access Manager, Admin Menu Editor, Adminimize plugins.

Hi @Irfantony,

thanks for reaching MainWP.

You can use this code to unset certain Menu items:

Settings page example:

add_filter( 'mainwp_main_menu_disable_menu_items', 'mycustom2_mainwp_main_menu_disable_menu_items' );
if ( !function_exists( 'mycustom2_mainwp_main_menu_disable_menu_items' ) ) {
  function mycustom2_mainwp_main_menu_disable_menu_items( $disable_menus ) {	 
	  if (isset( $disable_menus['level_2']['Settings']) ){
		  $disable_menus['level_2']['Settings'] = true;
	  }
	  return  $disable_menus;
  }
}

Status page example:

add_filter( 'mainwp_main_menu_disable_menu_items', 'mycustom2_mainwp_main_menu_disable_menu_items' );
if ( !function_exists( 'mycustom2_mainwp_main_menu_disable_menu_items' ) ) {
  function mycustom2_mainwp_main_menu_disable_menu_items( $disable_menus ) {	 
	  if (isset( $disable_menus['level_2']['ServerInformation']) ){
		  $disable_menus['level_2']['ServerInformation'] = true;
	  }
	  return  $disable_menus;
  }
}

Now, if you need this only for a specific role, you can wrap this code with a IF condition:

if( current_user_can(  'user-role-here'  )  ) {
    // code snippet here
}

I hope this make sense, let me know how it goes.

Thank you @bogdan

I did try those snippets but it’s not working on my site.
I try both Settings and Status menu and play around with other MainWP Menus but still, not working.

I guess because the Menus on MainWP Dashboard is not part of WP core menu?

Hi @Irfantony,

thanks for getting back to me.

I just updated code snippets in my previous post. Can you please try with the updated code?

Hi @bogdan

Thank you for the new scripts. It’s work like a charm.
And I add this to hide for specific user role:

if( current_user_can(  'user-role-here'  )  ) {
    // code snippet here
}

I try to revise the code to hide “Go to WP Admin” link but it’s not working right away:

.....  
function hideadminlink_mainwp_main_menu_disable_menu_items ( $disable_menus ) {     
      if (isset( $disable_menus['level_2']['Go to WP Admin']) ){
          $disable_menus['level_2']['Go to WP Admin'] = true;
      }
      return  $disable_menus;
  }
.....

I may missing some details here…

Sorry if it sound like asking too much but I need to hide some MainWP menus and add some links on dashboard. The available menu editors (AAM, Admin Menu Editor, etc.) can’t find MainWP menus.

I can hide Extensions menu from specific role (let’s say “va”) using the above script but the whole sub-menu is hidden as well. Is it possible to add link on dashboard menu?

What I need is adding 2 menus (under Users menu):
https:// mydomain.com/wp-admin/admin.php?page=Extensions-Advanced-Uptime-Monitor-Extension
https:// mydomain.com/wp-admin/admin.php?page=Extensions-Mainwp-Pro-Reports-Extension

TIA

Hi,

For removing the Got to WP Admin item, please try this code with this version:

add_filter( 'mainwp_go_back_wpadmin_link', 'mycustom_mainwp_go_back_wpadmin_link' );
if ( !function_exists( 'mycustom_mainwp_go_back_wpadmin_link' ) ) {
  function mycustom_mainwp_go_back_wpadmin_link(  $links ) {	 
	  return  false;
  }
}		 

I assume this version is a modified MainWP plugin.

If I delete the original MainWP plugin and install this version, are all Extensions and its settings are gone?

Reinstalling the MainWP Dashboard plugin does not remove any data from the database so all your settings will stay.

Hi @bogdan

The script + this version MainWP is working combo. But… the logout button is gone as well. There’s no way to logout unless user type the logout URL logout into browser like this: https:// mydomain.com/wp-login.php?action=logout

So, appreciate if you could provide the script to add link on MainWP sidebar menu, then it’s solved. The available Dashboard Customizer plugins don’t work on MainWP menu.

TIA

Hi Irfan,

here is the code example for adding custom menu items:

add_filter( 'mainwp_main_menu', 'mycustom_mainwp_main_menu', 10, 1 );
function mycustom_mainwp_main_menu( $left_menu ) {
	$index                                               = 0;
	$sub_menu_after                       = array_splice( $left_menu['mainwp_tab'], $index );
	$addition_item                            = array();
	$addition_item[]                         = 'Logout';
	$addition_item[]                         = 'logout-item';
	$addition_item[]                         = '/wp-login.php?action=logout';
	$left_menu['mainwp_tab'][] = $addition_item;
	$left_menu['mainwp_tab']    = array_merge( $left_menu['mainwp_tab'], $sub_menu_after );
	return $left_menu;
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.