0

I have a function which looks like below, where the goal is to remove New Post and Manage Comments from the "My Sites" dropdown. This works well if I replace {$node_id} with a blogs id. But I want this to work for all multisites you have in your "My sites" list. That means I need to get all the blog id's. This is how far I have come, but it doesn't work.

add_action( 'admin_bar_menu', 'remove_nodes_from_mysites', 999 );
function remove_nodes_from_mysites( $wp_admin_bar ) {
    $blog_ids = get_sites();

    foreach($blog_ids as $key) {
        foreach($key as $k => $val) {
            $node_id = $k['blog_id'];

            $wp_admin_bar->remove_node( "blog-{$node_id}-n" );
            $wp_admin_bar->remove_node( "blog-{$node_id}-c" );
        }
    }
}
0

Here, try this:

add_action( 'admin_bar_menu', 'remove_nodes_from_mysites', 999 );
function remove_nodes_from_mysites( $wp_admin_bar ) {
    $user_blogs = get_blogs_of_user( get_current_user_id() );
    foreach ( $user_blogs as $user_blog ) {
        $wp_admin_bar->remove_node( "blog-" . $user_blog->userblog_id . "-n" );
        $wp_admin_bar->remove_node( "blog-" . $user_blog->userblog_id . "-c" );
    }
}

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.