• Resolved Gabe Shackle

    (@hereswhatidid)


    As soon as I add a call to remove_menu_page in my functions.php I get several errors in the Pages and Menus section of the admin. The error is always:

    Warning: Invalid argument supplied for foreach() in ~sitepath~\wp-admin\includes\plugin.php on line 1261

    It doesn’t appear to matter what menu I try to remove, if any calls to that function are made it causes the error to occur. A couple specific places it occurs is when using Quick Update on a post/page or when adding items to a Menu.

    I’m calling the remove_menu_page from the ‘admin_init’ hook.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Gabe Shackle

    (@hereswhatidid)

    Sorry, just found the bug post for it. I was using the wrong hook. The correct hook is ‘admin_menu’

    timfarley

    (@timfarley)

    Thanks for the post – helped me solve that annoying issue as well. Just to clarify for anyone who stumbles onto this post: If you have a function to hide some of the menu items on the left side admin panel, like this:

    function mytheme_remove_menu_pages() {
    	remove_menu_page('link-manager.php');
    	remove_menu_page('edit.php');
    	remove_menu_page('upload.php');
    	remove_menu_page('edit-comments.php');
    }
    add_action( 'admin_init', 'mytheme_remove_menu_pages' );

    Change the last line to
    add_action( 'admin_menu', 'mytheme_remove_menu_pages' );

    Great solution timfarley.. thanks!

    Thanks for posting this! I thought I was going to have to troubleshoot forever, but I changed my code to the following and it works!

    What was Causing the error:
    I was changing post status to “draft” via quick edit.

    This is the error I had:
    Warning: Invalid argument supplied for foreach() in (blah blah) …plugin.php on line 1261

    Here is the code I changed like @timfarley posted above:

    add_action( 'admin_menu', 'nz_remove_menu_pages' );
    
    function nz_remove_menu_pages() {
      // If the user does not have access to publish posts
      if(!current_user_can('activate_plugins')) {
        // Remove the "Tools" menu
        remove_menu_page('tools.php');
      }
    }

    First line had previously been:
    add_action( ‘admin_init’, ‘nz_remove_menu_pages’ );

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Using remove_menu_page causes error throughout other admin sections’ is closed to new replies.