0

I would like to hide some submenus from the Dashboard for non admin users. I'm using the remove_submenu_page function but I'm not using it properly since it doesn't work and sub menus are still displayed. http://codex.wordpress.org/Function_Reference/remove_submenu_page

I'm trying to hide sub menus from a plugin called Newsletter for non admins :

  • wp-admin/admin.php?page=newsletter_main_index
  • wp-admin/admin.php?page=newsletter_main_main
  • wp-admin/admin.php?page=newsletter_main_diagnostic
  • wp-admin/admin.php?page=newsletter_subscription_profile

Here's the code I used in functions.php but I can't get it right:

    function ns_remove_admin_menus() {
        global $menu;
        global $current_user;
        if ($current_user->ID != 1) {
            remove_submenu_page( 'admin.php?page=', 'newsletter_main_index' );
            remove_submenu_page( 'admin.php', 'newsletter_main_index' );
        }
    }
    add_action('admin_init', 'ns_remove_admin_menus', 999 );

Any idea how I could make it work?

1 Answer 1

1

Use the action admin_menu as opposed to admin_init. You also need to adjust your use of remove_submenu_page to match the way Newsletter adds menu items:

remove_submenu_page( 'newsletter_main_index', 'newsletter_main_index' );
remove_submenu_page( 'newsletter_main_index', 'newsletter_main_main' );
remove_submenu_page( 'newsletter_main_index', 'newsletter_main_diagnostic' );
remove_submenu_page( 'newsletter_main_index', 'newsletter_subscription_profile' );
5
  • Tried remove_submenu_page( 'admin.php', 'newsletter_main_index' ); remove_submenu_page( 'admin', 'newsletter_main_index' ); add_action('admin_menu', 'ns_remove_admin_menus', 999 ); with no luck Commented Apr 2, 2014 at 17:38
  • Do you want to remove the whole of "Newsletter" from the admin menu, or just sub menu items from "Newsletter"? Commented Apr 2, 2014 at 17:42
  • Only submenus items (the ones listed in my initial post). Commented Apr 2, 2014 at 17:46
  • Gotcha. See revised answer. Commented Apr 2, 2014 at 17:49
  • I thought the id slug for the parent menu was admin.php , thanks Commented Apr 2, 2014 at 18:47

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.