Invalid argument supplied for foreach()
-
Hey guys. Thanks for the great plugin.
Stack:
Server: Laravel Valet
WordPress 4.9.2 using Bedrock
Plugins installed:
ACF 5.6.7
Timber Library 1.6.0
ACF Timber Integration 1.2.1
Theme: Timber Starter Theme
Clean install database.On activating the current version (with WP_DEBUG true) there is an xdebug notice that there is an Warning: Invalid argument supplied for foreach() in …/acf-timber-integration/acf-timber-integration.php on line 99.
On investigating, it appears that while you have defined the variable $_wp_registered_nav_menus on the global level, there is no other reference to it within the plugin, nor in Timber Library.
On var_dumping the variable it returns as null.
I created a menu to double check it wasn’t because there was no menu being returned. However, the warning still persisted.
On diving into the code, it became apparent that while you while you have defined the variable $_wp_registered_nav_menus, there is no value assigned to it. So when the foreach loop tries to run, it’s running against a null value – hence returning the invalid argument warning.
From reading the code, it appears it is supposed to be taking the menu values and adding them to the global context.
When I added the line:
$_wp_registered_nav_menus = $content['menus'];
on the line underneath$content['menus'] = array();
, it removed the error.I’m not 100 per cent sure that is the value that is supposed to be assigned to that variable, but it was the one that made the most sense.
Hopefully it helps.
- The topic ‘Invalid argument supplied for foreach()’ is closed to new replies.