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() {
register_nav_menus(
array(
'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' );
Update:
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.
$menu
an array when you call the function? Did you test that?print_r($menu);
to see what the variable looks like. Just make sure everything is back to normal when you finish debugging.foreach()
call and replaced it with theprint_r($menu)
. Here is the paste of the output: pastebin.com/LSjLxHVC