Support » Plugin: Multisite Admin Bar Switcher » add some custom menu to array

  • Resolved igornn

    (@igornn)


    Hi,
    i want to add some custom menu to array:

    $pages[‘bookings’] = array (‘url’ => ‘admin.php?page=rtb-bookings’);

    thats working and showing this menu in all sites.

    the question is how to add this menu only if plugin is activated in some of the blogs? if the plugin is not activated, then this menu should not be shown under the blogs that the plugin is not activated.

    i tried to make this work like:

    if(is_plugin_active('restaurant-reservations/restaurant-reservations.php')) {
    		$pages['bookings'] = array ('url' => 'admin.php?page=rtb-bookings');
    		}

    but the problem is, if i in some blog that the plugin does not activate, this will not show the menu item in all blogs And vice versa.

    can you help me to make this work?

    Thanks

    https://wordpress.org/plugins/multisite-admin-bar-switcher/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author flynsarmy

    (@flynsarmy)

    Perhaps something like:

    add_filter('mabs_blog_pages', function($pages, $id, $user) {
        if ( is_plugin_active('restaurant-reservations/restaurant-reservations.php') ) {
            $pages['bookings'] = array ('url' => 'admin.php?page=rtb-bookings');
        }
    
        return $pages;
    }, 10, 3);

    Hi,
    thanks for the filter, but as i said i have the same problem.
    Once I go to blog where this plugin not activated then all other blogs in the list not showing this menu (but some of them have this plugin activated)

    i think i need some loop true all sites with help of switch_to_blog( $blog_id );

    can you help me to make this work?

    Thanks

    Plugin Author flynsarmy

    (@flynsarmy)

    $id is the blog ID. You can switch_to_blog($id), check is_plugin_active and if so add to the array. don’t forget to restore_current_blog().

    add_filter('mabs_blog_pages', function($pages, $blog_id, $user) {
        switch_to_blog($blog_id);
        if ( is_plugin_active('restaurant-reservations/restaurant-reservations.php') ) {
            $pages['bookings'] = array ('url' => 'admin.php?page=rtb-bookings');
        }
        restore_current_blog();
    
        return $pages;
    }, 10, 3);

    Thanks. i have tried this but no luck.

    it seems not checking all the blogs to see witch one have this plugin enabled and witch no.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘add some custom menu to array’ is closed to new replies.