I recently moved a wordpress install from my local instance to a dev server. For the move, I installed a clean version of wordpress 3.4, moved exact duplicates of the file structre, and used the import / export feature to bring the posts in.

I then went in and set the necessary widgets, and settings. I've done this 100 times, and never had this problem. Here is the error:

Warning: Invalid argument supplied for foreach() in /home/content/46/9411746/html/dev/wp-admin/includes/plugin.php on line 1285

It only appears in the admin menu. I see it when I try to add a widget, change a setting, work with menus, or update meta data for a post. It pops up all over the admin menu.

Here is the function triggering the error in includes/plugin.php

function remove_menu_page( $menu_slug ) {
global $menu;

foreach ( $menu as $i => $item ) {
    if ( $menu_slug == $item[2] ) {
        unset( $menu[$i] );
        return $item;

return false;

I'm using appearance > menus and have two registered here in functions.php here:

add_action( 'init', 'register_my_menus' );

function register_my_menus() {
      'header-nav' => __( 'Main Header Navigation', 'kyosay' ),
      'footer-nav' => __( 'Footer Navigation', 'kyosay' )

I am doing some other customization of the admin panel, reordering some menu items and eliminating others that my clients don't need. I can include that code if you think it's relevant.

Since this issue is triggered in core, I'm at a loss as to how to fix it. NOTE: The issue is not happening on my local build. Thoughts?

Edit: added remove_menu_items code from functions.php for reference

function remove_menu_items() {
remove_menu_page('link-manager.php'); // Links
remove_menu_page('edit-comments.php'); // Comments
add_action( 'admin_init', 'remove_menu_items' );

I have eliminated functions.php as the source of this issue. It seems to be triggered on Ajax events (dragging a new widget to a sidebar, updating a meta-box, etc. I'm going to uninstall and reinstall and see if it's still happening. Could this have something to do with the web host (godaddy) ? It's not showing up on my local build at all.

  • Is $menu an array when you call the function? Did you test that?
    – fuxia
    Jun 16 '12 at 22:43
  • how do I test that without editing core? sry haven't had an issue like this before, not very experience w/ php debugging
    – timshutes
    Jun 16 '12 at 22:48
  • It is fine to edit core files for debugging purposes, like doing a print_r($menu); to see what the variable looks like. Just make sure everything is back to normal when you finish debugging. Jun 16 '12 at 23:03
  • ok I got the print_r($menu); to work. I took out the foreach() call and replaced it with the print_r($menu). Here is the paste of the output: pastebin.com/LSjLxHVC
    – timshutes
    Jun 16 '12 at 23:10
  • That doesn't look like it would cause that error... Jun 16 '12 at 23:11

This usually happens when you are trying to do admin navigation stuff and you aren't hooked into admin_menu. If you hook in before that, $menu hasn't been created yet.

add_action('admin_menu', 'my_plugin_add_menu');

function my_plugin_add_menu(){
    $ptype = 'my_post_type';
    $ptype_obj = get_post_type_object( $ptype );
    add_submenu_page( 'my-menu-item', $ptype_obj->labels->name, $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype" );
  • I tried removing all the admin nav stuff and the issue still remained. Here is a paste of the relevant functions.php code - do you see anything there? pastebin.com/2f1AaxPU
    – timshutes
    Jun 16 '12 at 23:06
  • Are you using admin_init or admin_menu? There is a difference... Jun 16 '12 at 23:08
  • add_action( 'init', 'register_my_menus' );
    – timshutes
    Jun 16 '12 at 23:12
  • I'm talking about for when you call 'remove_menu_page' Jun 16 '12 at 23:13
  • added the remove_menu_page code above
    – timshutes
    Jun 16 '12 at 23:14

I had a similar problem with wordpress, just added an if statement to check the argument as follows

    //use $thearray here

and the warning was gone!!

  • This isn't really a problem with WordPress. It is problem with PHP, and checking the value as you have done will solve certain 'notice' issues. It is not clear that it will solve this one. In fact, if $thearray has to be set for some function to work, then it doesn't solve the problem it just masks the message. It is not possible to tell if this a fix or not without knowing exactly what triggers the notice.
    – s_ha_dum
    Feb 4 '13 at 18:45
  • i was looking for a way to silence the warning on my blog because it was making the page ugly, and i get your point, but why does it behave this way? The reason i was checking is to make sure $thearray is an array, which indeed is... so? I am really puzzled. Checking again...
    – Karibe
    Feb 4 '13 at 22:47
  • Yes, there are cases where you just need to silence the warning but there are also cases where this indicates a deeper problem, a problem where things might actually be broken. That is my worry.
    – s_ha_dum
    Feb 5 '13 at 14:47

Your Answer

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

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