0

I have added to my-plugin submenu a custom view of the user list using users.php and a my_plugin_view argument to filter the request:

add_submenu_page(
            "my-plugin",
            'Subscribers',
            'Subscribers',
            'edit_users',
            'users.php?my_plugin_view=subscribers'
        );  

When /users.php?my_plugin_view=subscribers is open the admin sidebar toggle Users > All Users instead of My Plugin > Subscribers

I have tried:

if( isset($_GET['my_plugin_view']) ){

    remove_submenu_page( 'users.php' );
}

but this removes the All Users section from the sidebar and doesn't toggle the plugin menu as expected.

How to keep the plugin submenu open on viewing a custom version of users.php ?

1 Answer 1

0

You must use a different parent slug (first parameter) to keep the user menu as you want.

An example,

add_action('admin_menu', 'register_subscriber_submenu_page');

function wpdocs_register_subscriber_submenu_page() {
      add_submenu_page(
           'users.php',
           'Subscribers',
           'Subscribers',
           'manage_options',
           'custom-submenu-page', 
           'custom_callback_function'
      );
  }

Try to prefix your plugin page slug, you can have conflict with such a name : 'subscribers' -> your-plugin-subscribers .

You will find more details add_submenu_page

Hope it helps

2
  • Thanks. This is opening the "Users" sub-menu and I d'like to have it in the Plugin sub-menu. Am I missing something?
    – RafaSashi
    Commented Nov 12, 2016 at 12:39
  • Basically I have the same result with your version than doing: add_users_page( 'All Subscribers', 'All Subscribers', 'administrator', 'users.php?prefix_view=subscribers' );
    – RafaSashi
    Commented Nov 12, 2016 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.