Fixing ‘Invalid argument supplied for foreach()’ PHP Warning in WordPress

I ran into a problem recently on a WordPress site that I manage where I was unable to disable and uninstall numerous plug-ins. After looking through the error logs on the web server, I found the following warning showing up repeatedly in the PHP error log:

PHP Warning: Invalid argument supplied for foreach() in /var/www/html/example.com/wp-cron.php on line 117

Here’s what I did to identify and fix the problem.


Before getting into details, this how-to will assume that you have basic knowledge working with Linux servers and MySQL databases, that you have access to and are familiar reviewing error logs on your server, that you have access to the database for your WordPress website through phpmyadmin or some other database tool, and that you have a backup of your WordPress site that you can restore in case things go sideways.


The problem I ran into was that I was unable to disable or uninstall some plug-ins on the WordPress website. Every time I tried, I encountered the white screen of death, aka WSOD.

Upon reviewing error logs on the server, I discovered the PHP Warning noted above. While it seems harmless (it is just a warning after all), it turns out that the cron job in the database for the WordPress website was corrupted. I confirmed it by logging into the database, opening the wp_options table, and looking at the value for the option name ‘cron’. If you’re not able to browse the table, you can run the following query to see the row value:

SELECT * FROM alb_options WHERE option_name = 'cron';

The quick fix is to reset the cron value, which can be done by clearing the value. The following query will do the trick:

UPDATE alb_options SET option_value = '' WHERE option_name = 'cron';

Once cleared, WordPress will recreate the cron value the next time the website is accessed. Once reset, you should no longer see the foreach() PHP Warning in your log files. Even better, you’ll be able to manage your plug-ins properly again, including the ability to uninstall.

In my case, the corruption was the result of a hack that added thousands of users to the WordPress install. Your case may not be the result of a hack but could be due to a poorly configured plug-in or other issue. In any case, you may want to check various areas of your WordPress website, starting with the User area, just to confirm that everything looks good.

Leave a Reply

Your email address will not be published. Required fields are marked *