Help me hide admin menu item in WP dashboard

Can someone help me understand what I am doing incorrectly here? I am trying to hide the “Members” menu item in Wordpress Dashboard from administrators. Here is what I have:

Members (menu item is /wp-admin/admin.php?page=members-settings

Here’s what I have so far:

function wp_ninja_dashboards ()
{
	global $current_user;
	$role = $current_user->roles[0];
	if($role == "administrator")
	{
		remove_menu_page('admin.php?page=members-settings');
	}
}

add_action('admin_menu','wp_ninja_dashboards');

?>

I don’t think you will get much WP specific help here.

This appears to be a WP plugin. You would have more success asking on their support forum.

You should add some debug output to make things more visible.

For example you could var_dump($role) or could echo just something inside your if statement.

It is fairly possible, that the administrator has more than just this one role, so it isn’t neccessarily the first one in the roles array.

It also depends where you are adding the code, if it is getting run at all.

You should find out if the hook is fired at all as well with a simpler action.

    echo '<pre>' . print_r( $GLOBALS[ 'menu' ], true) . '</pre>';
} );

will print you the current menu structure to see if you are on the right path.

Sponsor our Newsletter | Privacy Policy | Terms of Service