Support » Plugin: ACF Timber Integration » Invalid argument supplied for foreach()

  • Resolved benfurfie


    Hey guys. Thanks for the great plugin.

    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.

Viewing 1 replies (of 1 total)
  • Plugin Author Daniel Telbis



    Sorry for the late response and thank you for pointing out the issue. We didn’t get any notifications from WordPress about the support issue, now it’s fixed.
    The global variable $_wp_registered_nav_menus is a WordPress variable and stores all menus registered using the register_nav_menu() function. I assume that you didn’t have any registered menus.

Viewing 1 replies (of 1 total)
  • The topic ‘Invalid argument supplied for foreach()’ is closed to new replies.