1

I have a multisite like this:

  • MainSite
    • Site1
    • Site2

I want to register submenu page

  • on active site in parent page /wp-admin/options-general.php
  • on network in parent page /network/settings.php

If I use below code snippet and activated from MainSite then it works.

add_action( 'network_admin_menu', __CLASS__ . '::menu' );
add_action( 'admin_menu', __CLASS__ . '::menu' );

static public function menu() {
    add_submenu_page(
        'options-general.php',
        'TEST',
        'TEST',
        'delete_users',
        'test-settings',
        __CLASS__ . '::render'
    );
}

But, If I activate it from Site1 or Site2 then:

  • It register menu only on active site parent page options-general.php
  • NOT on network in parent page /network/settings.php

I was tried to Switch to the MainSite by using switch_to_blog():

add_submenu_page(
    'options-general.php',
    'TEST',
    'TEST',
    'delete_users',
    'test-settings',
    __CLASS__ . '::render'
);

// Switch to the main blog
switch_to_blog( 1 );
    add_submenu_page(
        'options-general.php', // 'options-general.php',
        'TEST',
        'TEST',
        'delete_users',
        'test-settings',
        __CLASS__ . '::render'
    );
restore_current_blog();

and

add_submenu_page(
    'options-general.php',
    'TEST',
    'TEST',
    'delete_users',
    'test-settings',
    __CLASS__ . '::render'
);

// Switch to the main blog    
switch_to_blog( 1 );
    add_submenu_page(
        'settings.php', // 'settings.php'
        'TEST',
        'TEST',
        'delete_users',
        'test-settings',
        __CLASS__ . '::render'
    );
restore_current_blog();

But, Not have any success. Is there any solution?

EDIT1:

Is MainSite == Network? [Cause, Activated the plugin from MainSite it register the menu page on Network.]

So, Question is still unsolved! Is there any way to Activate plguin on Site1 or Site2 to register the submenu page on Network.

Thanks in advance.

  • Taking a guess here, but my thinking is you are using both the admin_menu and network_admin_menu hooks to add a menu page with the same slug, causing WP to skip the second call to add_submenu_page. I would try creating two separate callback functions (one for network, one for regular admin) with different slugs used in add_submenu_page and the use the same rendering callback. – brianjohnhanna Oct 11 '16 at 19:38

Your Answer

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

Browse other questions tagged or ask your own question.