Closed warever37 closed 5 years ago
@warever37 Can you please provide the code where you define your plugins, and call tgmpa()
?
Hi @GaryJones, attached is the file.
@warever37 That's the TGMPA file, rather than the config file which is needed.
Please see and follow http://tgmpluginactivation.com/configuration/, which is needed for you to define which plugins you want to mark as required or recommended.
Without that, you will indeed get the error above, since $plugins
in the foreach
won't have been defined.
@jrfnl We could add some sort of validation for $plugins
, before calling foreach
, to help authors better identify what the issue is?
@GaryJones Unfortunately I have no experience at all in this :(
I've read the page you were referring to, but couldn't understand what to do.
Is the config file located in a particular folder that I can send to you?
If you're seeing the error, but you're not a developer, then I'm guessing that a theme or plugin you've got active is the cause of the problem.
Try switching themes and see if the issue disappears. If so, contact the theme author and get them to fix it.
If it doesn't remove the warning, then try disabling plugins until you can narrow down which is the cause, and contact that author.
@GaryJones I agree. I think the issue is with the theme.
I'll contact the theme developers and see if they can get this fixed.
Thanks.
@jrfnl We could add some sort of validation for $plugins, before calling foreach, to help authors better identify what the issue is?
The only way you can get this error is by calling tgmpa()
without the plugins parameter - which would throw a notice about a missing required param - or with $plugins
not being a Traversable
or array
.
In that case, the theme/plugin has no business calling TGMPA anyway and the error alerts them to this.
We could do a try/catch
or an is_iterable()
or is_array()
check and throw a notice instead, but the net effect would be the same.
In this case, the Sydney theme doesn't initialize the $plugins
variable - which would throw a notice the dev clearly didn't see or ignored -, conditionally defines the plugins to recommend, but still calls tgmpa()
even when these plugins are installed and the $plugins
variable therefore is still undefined. This is just sloppy coding in the theme by a theme author who clearly hasn't got error notices turned on during development.
Just adding a $plugins = array();
at the start of their function would already fix this. Wrapping the call to tgmpa()
within a check for if ( ! empty( $plugins ) )
also would.
See: https://themes.trac.wordpress.org/browser/sydney/1.48/functions.php#L422-L441
I saw a similar question earlier this week on the fora: https://wordpress.org/support/topic/warning-invalid-argument-supplied-for-foreach-108/ so I suspect it's something in the latest release of the Sydney theme.
Pinging @athemes for their attention then.
Hi,
I'm getting this error in the back-end of my Wordpress website, but it's not showing on the font-end which is good.
Why am I getting this error?
NOTE: I'm not a programmer and I have very little knowledge of coding, i.e. I didn't change any files, it happened suddenly.
The PHP file is up-to-date (version 2.6.1) and my Wordpress version and all the other plugins are up-to-date as well.
I have attached a screenshot of both the error and the code on the specified line.
What seems to be the problem?
Thank you.
![2 php code](https://user-images.githubusercontent.com/41250608/42731312-24460cc2-8813-11e8-9a09-58dc337aabbb.png)