Categories
How It Works

WordPress 3.1 and Network Menu

Do you have a plugin for use on WordPress that makes a menu? Is it BuddyPress or Network related? You need to read this right-freaking-now. Do not pass GO, do not collect $200. WordPress 3.1 will make your menus vanish!

This one’s really fast, but the word should get out there. It’s extremely important if you’ve built a BuddyPress plugin, because the BuddyPress menu has been moved. If you do not do this, your BuddyPress menus will vanish, and you will have very angry users.

WordPress 3.1 has moved the admin menu for MultiSite. Instead of having a Super Admin menu available on the sidebar of your Admin section all the time, there’s a new link in the header bar for Network Admin. Thats right, it’s its own page! The problem with this is that a lot of plugins aren’t ready for that and because of the move, their admin menu links vanished.

Thankfully it’s an easy fix!

The WP Codex Doc on Admin Menus tells us to use “admin_menu” when adding menus. Well, if you want your plugin to show up on the Network Admin page, you have to use “network_admin_menu” instead. (Trac #14435)

See? I said it was easy.

add_action( 'network_admin_menu', 'MENU_FUNCTION', ## );

There’s on catch to this. What if your plugin is for Multisite and NON MultiSite? Honestly I don’t know if this matters, but just to be safe, I would do this:

if ( is_multisite() ) { 
     add_action( 'network_admin_menu', 'MENU_FUNCTION', ## );
} else {
     add_action( 'admin_menu', 'MENU_FUNCTION', ## );
}

Or this:

     add_action( 'network_admin_menu', 'MENU_FUNCTION', ## );
     add_action( 'admin_menu', 'MENU_FUNCTION', ## );

That’s right! If it’s there and not-needed, it does no harm! I’m not 100% certain right now if you need to do this for the non-menu calls people make (like calling a function on admin_menu to check for installation), but I’ve been adding it in to no ill effects. I figure, the BuddyPress core code does it, so it can’t hurt!

8 replies on “WordPress 3.1 and Network Menu”

I think you can get away with adding both admin_menu and network_admin_menu … I only tested that from the 3.1 end mind you, and it doesn’t seem to adversely impact 3.1 😀 I don’t actually have any of my own plugins that need this, but I couldn’t figure out where the hell the menu for your plugin went this morning 😉 Oh the irony.

Ha, yeah, you can definitely hook it in both places. It’s just that top-level menus hooked in both places will show up on both the site dashboard AND the network admin dashboard if you don’t do the check.

Yay! Thanks for the insite into network_admin_menu(). I was wondering how to hook into that part of the admin menu and happened to stumble onto the answer on your site.

Thanks for posting this 🙂

if ( is_multisite() ) {
add_action( ‘network_admin_menu’, ‘MENU_FUNCTION’, ## );
} else {
add_action( ‘admin_menu’, ‘MENU_FUNCTION’, ## );
}

What file do I ad this block of code? functions.php?

Comments are closed.