0
function remove_admin_menu_items() {
    $blog_id = get_current_blog_id();
    if ($blog_id == 1) {
        $remove_menu_items = array(__('Team Members'),__('Policies'),__('Comments'));
    } else {
        $remove_menu_items = array(__('Services'),__('Testimonials'),__('About'),__('Comments'));
    }
    global $menu;
    end ($menu);
    while (prev($menu)){
        $item =  array_map( 'trim', explode(' ',$menu[key($menu)][0]) );
        print_r($item);


        // Array ( [0] => Events ) Array ( [0] => Services ) 
        // Array ( [0] => Team [1] => Members )

        if(in_array($item[0] != NULL?$item[0]:"" , $remove_menu_items)){
            unset($menu[key($menu)]);

        } 
    }  
}
add_action('admin_menu', 'remove_admin_menu_items');

I have a function that removes certain menu items depending which blog it is on a multisite. I'm unsure has to how to tackle 'Team Members' with the white space. At what point does it need to be kept as is for matching the characters and when to change the white spacing. I've tried various trims and array manipulation but none seem to work.

In the first line commented out part is typically what the menu items output with print_r(), but with Team Member it displays as per the second line.

0

There are more reliable functions to remove menus and submenus in WP admin area. Those functions are remove_menu_page and remove_submenu_page. I don't know if the menus you want to remove are top level menus or submenus neither the slug of the menus (needed for these functions), so I can not give you the exact code you need.

Example: remove edit.php?post_type=team (top level menu for custom post type "team") for blog with ID = 1 and remove edit-comments.php for the rest of blogs:

add_action('admin_menu', 'cyb_remove_admin_menu_items');
function cyb_remove_admin_menu_items() {
    $blog_id = get_current_blog_id();
    if ($blog_id == 1) {
        remove_menu_page('edit.php?post_type=team');
    } else {
       remove_menu_page('edit-comments.php');
    }

}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.