$wp_admin_bar->add_menu( array(
'parent' => $menu_id,
'id' => $menu_id . '-example',
'title' => __( 'Example Menu Item', 'example' ),
'href' => get_admin_url( $blog->userblog_id, 'edit.php?post_type=example' ),
) );
Lets say i have a plugin that add a new menu item for an example custom post type to blog menu. Problem is if i have lots of blogs but this plugin activated on only 1 blog, its only showing when i am in that blog and adding example menu to every blog menu group even that plugin is not activated in those blogs..
Example:
I activate plugin in blogid:2 but didnt activate it in blogid:3 or blogid:4. When i am in blogid:2 plugin adding that menu to all blogs. When i am in blogid:3 or blogid:4, i cant see that menu in blogid:2’s list
What is proper way to fix this?
Update: I am trying to add those links for each blog activated that plugin in “My Sites” list
Answer remade and now working as per the Question specifications.
To add a menu item to each site of the network if an specific plugin is active in that site, I’m using a Must Use plugin. It only runs if
is_multisite()
and ifis_admin_bar_showing()
.In this example, the plugin is instantiated with the following values that check for the plugin Analytics360º and remove all default menu items:
Analytics360
analytics360/analytics360.php
index.php?page=analytics360.php
array( 'newpost', 'comments', 'visit', 'dashboard' )