How do I hide Pages & Posts sections in MainWP?

Hello, I mostly strictly use MainWP for managing updates and for code snippets that I want deployed across all my client sites. As a result I never use the built-in Pages and Posts functionality but it’s always consuming space in the left-hand menu bar in MainWP. Is there a way to disable this at all so it’s hidden for the features I never use nor ever really intend to use?

Please reference this thread here: Remove multiple options for one user role only

1 Like

It isn’t working for me, but maybe I’m mis-using it? I obviously made a few small changes (i.e. the role used, etc) but am only ever seeing “Sites” in the menu bar and nothing else when it’s enabled.

Ultimately I only want to remove Pages and Posts and keep the rest, is there a different way to achieve this or a different coding change needed to the snippet?

Here’s my current snippet:

add_filter( 'mainwp_main_menu', 'd19_mainwp_main_menu', 10, 1 );
function d19_mainwp_main_menu( $left_menus ) {
	if ( current_user_can( 'administrator' ) ) {
		$left_menus = array();
		$left_menus['mainwp_tab'] = array( 
			array(
				'Sites',
				'Updates',
				'Plugins',
				'Themes',
				'Users',
				'Extensions',
				'Settings',
				'Info'
			)
		);
	}	
	return $left_menus;
}

I was able to make this work after finding different examples, but this seems like an inefficient method, is there perhaps a better way to clean up this snippet?

add_filter(
    "mainwp_main_menu_disable_menu_items",
    "d19_mainwp_main_menu_disable_menu_items"
);
if (!function_exists("d19_mainwp_main_menu_disable_menu_items")) {
    function d19_mainwp_main_menu_disable_menu_items($disable_menus)
    {
        if (isset($disable_menus["level_2"]["PageBulkManage"])) {
            $disable_menus["level_2"]["PageBulkManage"] = true;
        }
        if (isset($disable_menus["level_2"]["PostBulkManage"])) {
            $disable_menus["level_2"]["PostBulkManage"] = true;
        }
        if (isset($disable_menus["level_2"]["UserBulkManage"])) {
            $disable_menus["level_2"]["UserBulkManage"] = true;
        }
        return $disable_menus;
    }
}

What’s “inefficient” about this? Looks fine to me…

1 Like

Well for one it isn’t anything close to what you originally suggested so I feel like I’m doing something wrong, haha. But also it’d be nice if it was somehow an array where I didn’t need to duplicate the names of tabs each time. So was assuming there’s a better way, a more efficient way. It’d be nice if there was formal documentation from MainWP on how to hide menu items.

@d19dotca Yeah if it works it works, you are the only one that will see the code ;o) I know not the answer you were wanting lol

This was a quick addition a few years ago because somebody was asking about it on this Forum. Other than the How To’s on here, there was never a need for the documentation. You are like literally the 5th person that has asked about this.

I’m sure we could have @bogdan write up a short KB Article when there is some spare time to do so, but I can not give a ETA as to when this will be done at this time.

1 Like

Understandable it’s a low priority but it’s definitely not a one-off if there’s been more than 3 or 4 people asking for it. :wink: Hoping this can be improved in the future.

I’m trying to expand it to hide the new Clients page too but it’s not working. Here’s what I’m adding in currently, is the ManageClients supposed to be something different perhaps?

add_filter(
    "mainwp_main_menu_disable_menu_items",
    "d19_mainwp_main_menu_disable_menu_items"
);
if (!function_exists("d19_mainwp_main_menu_disable_menu_items")) {
    function d19_mainwp_main_menu_disable_menu_items($disable_menus)
    {
        if (isset($disable_menus["level_2"]["PageBulkManage"])) {
            $disable_menus["level_2"]["PageBulkManage"] = true;
        }
        if (isset($disable_menus["level_2"]["PostBulkManage"])) {
            $disable_menus["level_2"]["PostBulkManage"] = true;
        }
        if (isset($disable_menus["level_2"]["UserBulkManage"])) {
            $disable_menus["level_2"]["UserBulkManage"] = true;
        }
        if (isset($disable_menus["level_2"]["ManageClients"])) {
            $disable_menus["level_2"]["ManageClients"] = true;
        }
        return $disable_menus;
    }
}

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