Several sites getting "Invalid argument supplied for foreach()" error on child when trying to add

We’re trying to bring all of our sites into our existing MainWP setup. Most are working, but several are showing a “Public key already set” error on the Dashboard site when we try to add them. Deactivating and reactivating the child plugin didn’t solve the issue, nor did disabling all other plugins. These sites don’t really have many plugins in common, but the fact that disabling everything except the child plugin rules that out. None of these sites are going through Cloudflare (but we do have sites that are that work, so… :man_shrugging:). Looking at the error log on the child sites in question, we see the following error on all of them:

[2024-02-14 21:38:04] production.ERROR: Invalid argument supplied for foreach() {"userId":5,"exception":"[object] (ErrorException(code: 0): Invalid argument supplied for foreach() at /www/wp-content/plugins/mainwp-child/class/class-mainwp-security.php:667)
[stacktrace]
#0 /www/wp-content/plugins/mainwp-child/class/class-mainwp-security.php(667): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'Invalid argumen...', '/www/wp-content...', 667, Array)
#1 /www/wp-content/plugins/mainwp-child/class/class-mainwp-security.php(605): MainWP\\Child\\MainWP_Security::wpcore_updated_ok()
#2 /www/wp-content/plugins/mainwp-child/class/class-mainwp-child-stats.php(249): MainWP\\Child\\MainWP_Security::get_stats_security()
#3 /www/wp-content/plugins/mainwp-child/class/class-mainwp-connect.php(138): MainWP\\Child\\MainWP_Child_Stats->get_site_stats(Array)
#4 /www/wp-content/plugins/mainwp-child/class/class-mainwp-child.php(307): MainWP\\Child\\MainWP_Connect->register_site()
#5 /wordpress/wp-includes/class-wp-hook.php(324): MainWP\\Child\\MainWP_Child->parse_init('')
#6 /wordpress/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#7 /wordpress/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#8 /wordpress/wp-settings.php(646): do_action('init')
#9 /www/wp-config.php(110): require_once('/wordpress/wp-s...')
#10 /wordpress/wp-config.php(5): require('/www/wp-config....')
#11 /wordpress/wp-load.php(50): require_once('/wordpress/wp-c...')
#12 /wordpress/wp-admin/admin-ajax.php(22): require_once('/wordpress/wp-l...')
#13 {main}
"} 

Hey @ksolomon75

Welcome to the MainWP community.

We have a special tool designed to reset your MainWP Child Site Plugin settings to their default state as if the plugin was newly installed.

You can access the tool here: Reset MainWP Child Plugin Settings to Default.

This tool should be installed like a standard plugin, but please ensure it is only used on the CHILD SITE.

  1. Download the Plugin .Zip

  2. Install like any other Plugin

  3. Activate the plugin. It will automatically run and deactivate itself.

  4. It is crucial for security purposes that you remove this tool from your site after completing the reset process.

After that, try adding the child site to the Dashboard once more. And naturally, make sure that the Dashboard and Child plugins are up to date.

@bojan Thanks for the reply, but that didn’t help. I tried it on most of the sites (still two more to try), and I get the same issue. Same error message in the logs as the initial post.

EDIT: I have now tried it on all sites exhibiting this error, and it didn’t help on any of them.

@ksolomon75
Thanks for trying that.

We’ve looked further into the error log.

It appears that the MainWP Child plugin is missing some required information about the WordPress installation during the security check process.

  1. Did you do any custom work on the site (e.g., removing WP Core version information)?

  2. And can you please send me the System Report from the child site in a private message? Just click on my name and then click Message button.

The System Report is available on the Child Sites’ WP Admin > Settings > MainWP Child > Server Information page.

Nope, no custom work beyond Flywheel’s oddities, but it doesn’t seem to be a Flywheel issue, since all of our sites are hosted with them.and the majority are working as they should. I will send the system report as soon as I’m done here…I’ll also send a report for a site that’s working that uses the same framework for comparison.

1 Like

Hey @ksolomon75

Thanks for the Child Site’s system report.

To eliminate any potential conflicts, can you temporarily switch to a default WordPress theme (e.g., Twenty Twenty-Four) and, if possible, try deactivating all other plugins except for the MainWP Child plugin and see if you can reconnect the site then?

Also, try temporarily disabling any server-side security you might have (Imunify360, mod_security, firewalls, etc.) and see if that helps.

Finally, can you please run a Test Connection for one of the disconnected child sites and see what response you get?

Just to provide an update on this -

We’ve made a small change in the MainWP Child plugin to how it checks for certain values of a Child Site.

@ksolomon75 has confirmed that the change fixes the issue, and it will be included in the next release of MainWP.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.