Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

WP Custom Menu Error - Invalid argument supplied for foreach() WordPress

  • SOLVED

Have a WordPress installation that is generating an error message when trying to manage custom menus.

We are running 3.0.5.

I have tried updating the files mentioned with a new download of WordPress (same version), but that did not help.

The custom menu functionality still works, just generates the error message, and drops the left admin navigation bar.

The error happens when we either click a custom menu name tab (to select it to manage that custom menu) or when we click "save" to update a custom menu.

It works, but generates an error, does not look good for the client.

On top of that...when using certain plugins (example: Easing Slider), when enabled, generates a fatal error, and we get a white screen (and the custom menu functionality does not work at all).

I am pretty sure these are related...and need it fixed asap.

Answers (3)

2011-04-19

Maor Barazany answers:

First, try to de-activate <strong>all</strong> plugins and also select the default twenty ten theme, and see if the error is still there.
If not, try to go back to your theme and recheck, it might be some code in your theme that generates the error.
Then if still works ok - try to activate one plugin at a time and check, till you will find which plugn might cause this.


Maor Barazany comments:

It might be that something with code in your theme where you use the register_nav_menu has some error.

Please paste here the code you are using for the registering nav menus.


Leonard Ghazarian comments:

##################################################################################################################################
// REGISTER CUSTOM MENUS
##################################################################################################################################
// is the option active?
if ($OPTION['wps_wp_custom_menus']) {

add_action( 'init', 'register_NWS_menus' );

function register_NWS_menus() {
register_nav_menus(
array(
'primary-menu' => __( 'Primary Menu - below logo' ),
'secondary-menu' => __( 'Secondary Menu - top right' ),
'tertiary-menu' => __( 'Tertiary Menu - in small footer' )
)
);
}
}


Leonard Ghazarian comments:

I switched back to the 2010 theme...and we still get the error.


Maor Barazany comments:

Have you tried to disable all plugins as I suggested and re-check?

Your register_nav_menus function looks ok.


Leonard Ghazarian comments:

Yes, see comment below.

I honestly think it's the WordPress installation....but not sure how to fix that...

Not the theme, switched back to 2010...not the plugins, disabled all.


Leonard Ghazarian comments:

The register_nav_menu code above was in the parent theme, not the child, btw.


Maor Barazany comments:

Have you done any changes in WP core files?
Where have you downloaded it from? Is it an install downloaded from official wordpress.org site? or have you used an auto installation from your host?
If it was an auto installation from the host service, please download WP official from wordpress.org and replace all files of folders wp-admin, wp-includes and root directory (backup first, and don't forget to keep you wp-config.php).

Another thing, do you have in the wp-config a line like this?
define('WP_DEBUG', true);
If so, make it false and re-check.

Another thing - what are the file permissions for the WP files and folders in your server?


Maor Barazany comments:

Well, I made another check. This has nothing with the nav-menus.
The menu.php file in 3.0.5 deals with the admin menu of WordPress, which means all admin menus list that are on the left (posts/pages/media/general options etc).

Have you tried to re-install a fresh copy of WP from the official site, and check this with the default 2010 theme and with no plugin activated?

If it is not helpful yet, go 2010 functions.php file and add at the start of it a test line -
global $menu; var_dump($menu);, refresh the admin page and paste here the text it spits out.


Leonard Ghazarian comments:

It's an official copy of WP...I have done many WP sites, never seen this before.

wp_debug was already false.

i re-uploaded all files of folders wp-admin, wp-includes and root directory...still getting error.


Leonard Ghazarian comments:

<blockquote>Have you tried to re-install a fresh copy of WP from the official site, and check this with the default 2010 theme and with no plugin activated?</blockquote> - not sure how this would help. i have installed many WP sites with custom themes and never had this issue.

i added the code to the functions.php, switched to 2010 theme, gave "NULL" at the very top.


Leonard Ghazarian comments:

when i click on a specific menu item, i get this:


string(2) "12"


Maor Barazany comments:

Try this temp code for debugging the $menu -


add_action('admin_menu', 'tc_test');
function tc_test(){
global $menu;
echo '<pre>';
print_r($menu);
echo '</pre>';
}


Leonard Ghazarian comments:

getting this right away

NULL
Array
(
[2] => Array
(
[0] => Dashboard
[1] => read
[2] => index.php
[3] =>
[4] => menu-top menu-top-first menu-icon-dashboard
[5] => menu-dashboard
[6] => div
)

[4] => Array
(
[0] =>
[1] => read
[2] => separator1
[3] =>
[4] => wp-menu-separator
)

[5] => Array
(
[0] => Posts
[1] => edit_posts
[2] => edit.php
[3] =>
[4] => open-if-no-js menu-top menu-icon-post
[5] => menu-posts
[6] => div
)

[10] => Array
(
[0] => Media
[1] => upload_files
[2] => upload.php
[3] =>
[4] => menu-top menu-icon-media
[5] => menu-media
[6] => div
)

[15] => Array
(
[0] => Links
[1] => manage_links
[2] => link-manager.php
[3] =>
[4] => menu-top menu-icon-links
[5] => menu-links
[6] => div
)

[20] => Array
(
[0] => Pages
[1] => edit_pages
[2] => edit.php?post_type=page
[3] =>
[4] => menu-top menu-icon-page
[5] => menu-pages
[6] => div
)

[25] => Array
(
[0] => Comments 0
[1] => edit_posts
[2] => edit-comments.php
[3] =>
[4] => menu-top menu-icon-comments
[5] => menu-comments
[6] => div
)

[59] => Array
(
[0] =>
[1] => read
[2] => separator2
[3] =>
[4] => wp-menu-separator
)

[60] => Array
(
[0] => Appearance
[1] => switch_themes
[2] => themes.php
[3] =>
[4] => menu-top menu-icon-appearance
[5] => menu-appearance
[6] => div
)

[65] => Array
(
[0] => Plugins 1
[1] => activate_plugins
[2] => plugins.php
[3] =>
[4] => menu-top menu-icon-plugins
[5] => menu-plugins
[6] => div
)

[70] => Array
(
[0] => Users
[1] => list_users
[2] => users.php
[3] =>
[4] => menu-top menu-icon-users
[5] => menu-users
[6] => div
)

[75] => Array
(
[0] => Tools
[1] => edit_posts
[2] => tools.php
[3] =>
[4] => menu-top menu-icon-tools
[5] => menu-tools
[6] => div
)

[80] => Array
(
[0] => Settings
[1] => manage_options
[2] => options-general.php
[3] =>
[4] => menu-top menu-icon-settings
[5] => menu-settings
[6] => div
)

[99] => Array
(
[0] =>
[1] => read
[2] => separator-last
[3] =>
[4] => wp-menu-separator-last
)

)


Leonard Ghazarian comments:

and this when i try accessing one of the custom menus

string(2) "12"
Warning: Invalid argument supplied for foreach() in /home/jacob/public_html/wp-admin/menu.php on line 240

Warning: Invalid argument supplied for foreach() in /home/jacob/public_html/wp-admin/menu.php on line 303
12A AA A A A A AA A A A A A

Warning: Invalid argument supplied for foreach() in /home/jacob/public_html/wp-admin/menu.php on line 332

Warning: Invalid argument supplied for foreach() in /home/jacob/public_html/wp-admin/menu.php on line 348

Warning: uksort() [function.uksort]: The argument should be an array in /home/jacob/public_html/wp-admin/menu.php on line 405

Warning: Invalid argument supplied for foreach() in /home/jacob/public_html/wp-admin/menu.php on line 372


Maor Barazany comments:

Is that error in the screenshot appears on each admin screen, or only when you go to the menus admin menu?


Leonard Ghazarian comments:

the errors only show when i access a custom menu on the menus page.


Maor Barazany comments:

Well, after all the tests I suspect that there is still an issue with one of the plugins.

Try resetting the plugins folder by FTP or PhpMyAdmin. Sometimes, an apparently inactive plugin can still cause problems...

Use the [[LINK href="http://codex.wordpress.org/FAQ_Troubleshooting#How_to_deactivate_all_plugins_when_not_able_to_access_the_administrative_menus.3F"]]guidelines here[[/LINK]] for this reset.

Ask me here if you have any question for this resetting process (it is very short and easy)


Leonard Ghazarian comments:

very frustrating! still did not work. :(

i changed the plugins folder to old, and created a new one...verified that WP admin plugins list was empty...still getting the error:


Warning: Invalid argument supplied for foreach() in /home/jacob/public_html/wp-admin/menu.php on line 240

Warning: Invalid argument supplied for foreach() in /home/jacob/public_html/wp-admin/menu.php on line 303

Warning: Invalid argument supplied for foreach() in /home/jacob/public_html/wp-admin/menu.php on line 332

Warning: Invalid argument supplied for foreach() in /home/jacob/public_html/wp-admin/menu.php on line 348

Warning: uksort() [function.uksort]: The argument should be an array in /home/jacob/public_html/wp-admin/menu.php on line 405

Warning: Invalid argument supplied for foreach() in /home/jacob/public_html/wp-admin/menu.php on line 372




Maor Barazany comments:

When your plugins folder is empty now, try to do that also with your themes folder under wp-content.
Then create a new themes folder and paste there the default 2010 theme and activate it, and see again.


Leonard Ghazarian comments:

empty plugins folder...and uploaded 2010 theme from fresh download, and still getting the error.

can we reset the menu functionality somehow...

i think that part of the installation is the issue...regardless of what theme, plugins...the functionality for the custom menus is the issue.


Maor Barazany comments:

I don't think there is a way to reset the menus menu, but it is better to try change the name of your menu named 'menu' to something else, since it might "confuse" the system.

If not helping, try to upgrade to latest WP 3.1.1 and see if it helps (anyway it is better to have the lateset WP version installed)

Do you have data in this temp site? (posts/pages/settings etc?)
If not, maybe a fresh install with a new database could help (backup current db ofcourse).


Leonard Ghazarian comments:

ok, on the same hosting acct...in a subfolder, i just installed 3.0.5, and without doing anything else...no plugins, no themes...i am getting that error.

on the same server i installed another WP, and it's fine.

must be something with this specific hosting acct?


Leonard Ghazarian comments:

ok, figured out the issue...

the theme/framework we are using for WordPress is asking:

Security warning: set the value *register_globals* in the php ini to *Off* !! Contact your Host if you do not know where this is done!

because of that...we have php_flag register_globals off in our htaccess file...

and it's giving us the issues. once i remove that, the menu error goes away...but we get that security warning displayed on the site.

any way around this?


Maor Barazany comments:

You should check with your host and ask them to set register_globals to off. This is a server setting, that usually should be turned off for security issues.


Leonard Ghazarian comments:

yup, that is what the admin said too...since it's our own server, we turned it off...

and now all is good!

Thanks for your help...i am awarding you the correct answer because of all the steps we went through! :)


Maor Barazany comments:

Thanks you and I'm happy it all went ok at the end! :)

2011-04-19

AdamGold answers:

I don't think there's any chance that WP fresh files won't work, so 2 solutions:
1. First, download a new package of WP (your version, not 3.1.1) and replace menu.php in wp-admin directory.
2. If that didn't work, disable all your plugins and try again.


Leonard Ghazarian comments:

As I mentioned in my OP, replacing the files that are displayed in the error did not solve the issue (same version as we are using).

2011-04-19

Hameedullah Khan answers:

Its definitely your plugins... disable all of them and enable one by one until you get the errors again... or provide the list of plugins so we can figure out which plugin might be causing the issue.


Leonard Ghazarian comments:

Not the plugins...I disabled all...still getting the error.

These are the only plugins being used:

Easing Slider
Gravity Forms
postMash (Filter)
Quick Page/Post Redirect
ShowID for Post/Page/Category/Tag/Comment
WP-Memory-Usage


Hameedullah Khan comments:

Can you please rename your menus. I have once experience the similar type of issue when I was using "menu" as my custom menu name. Its worth a try.


Leonard Ghazarian comments:

renamed all 3 custom menus...still getting the error. :(