Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting invalid argument error with 7.7 and 7.7.1 #20907

Closed
johnfleming opened this issue Mar 14, 2020 · 3 comments · Fixed by #20939
Closed

Getting invalid argument error with 7.7 and 7.7.1 #20907

johnfleming opened this issue Mar 14, 2020 · 3 comments · Fixed by #20939
Assignees
Labels
Needs Testing Needs further testing to be confirmed. [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended [Type] Plugin Interoperability Incompatibilities between a specific plugin and the block editor. Close with workaround notes.

Comments

@johnfleming
Copy link

Describe the bug
Using Gutenberg 7.7.1 on site, kindneyindiana.org with Editors Kit plugin. Getting error on Editors Kit landing page when Gutenberg active (Don't get it with just 5.3.2

Invalid Argument supplied for foreach() in /home/customer/www/kidneyindiana.org/public_html/wp-content/plugins/gutenberg/lib/client-assets.php on line 619

Contacted developer. He asked me to report here since Gutenberg throwing the error

To reproduce
Steps to reproduce the behavior:

  1. Go to admin
  2. Click on 'Setting, Editors Kit
  3. See error

Expected behavior
No error

Screenshots
If applicable, add screenshots to help explain your problem.
2020-03-14_15-24-24

Desktop (please complete the following information):

  • OS: [OSX Catalina]
  • Browser [Chroms
  • Version [Version 80.0.3987.132]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context

  • Please add the version of Gutenberg you are using in the description. 7.7.1
  • To report a security issue, please visit the WordPress HackerOne program: https://hackerone.com/wordpress.
@jorgefilipecosta jorgefilipecosta added [Type] Bug An existing feature does not function as intended Needs Testing Needs further testing to be confirmed. labels Mar 16, 2020
@aduth
Copy link
Member

aduth commented Mar 16, 2020

After some initial debugging, I traced it back to this code:

foreach ( $settings['imageSizes'] as $size ) {
$key = $size['slug'];
if ( isset( $all_sizes[ $key ] ) ) {
$image_dimensions[ $key ] = $all_sizes[ $key ];
}
}

This was added as part of #17151 (cc @ryelle).

It’s a feature which will be included in the upcoming WordPress 5.4 release. This specific code was backported as part of the commit at WordPress/wordpress-develop@437ac63 .

I believe the warning may only affect the plugin, based on how the message is about the foreach argument being invalid. In the core adaptation of the code, $available_image_sizes is guaranteed to be an array (source). In the plugin, I’m not sure $settings['imageSizes'] is safe to assume as such (thus causing the warning).

Action items:

  • Test the combination of this plugin with WordPress 5.4.0 RC 2 to verify the above assumptions about it only affecting the plugin.
  • Fix the plugin code above to be more durable about the values it is expecting to iterate in the foreach loop. It's quite possible it's assuming some code which only exists in 5.4.x. Since the plugin supports WordPress 5.3.x, it should be expected to work there as well.

@aduth aduth added the [Type] Plugin Interoperability Incompatibilities between a specific plugin and the block editor. Close with workaround notes. label Mar 16, 2020
@aduth
Copy link
Member

aduth commented Mar 16, 2020

I've confirmed this issue is not present with EditorsKit + WordPress 5.4 RC 2.

Based on the steps to reproduce, I was able to track this back to an incompatibility with this line of code in EditorsKit welcome screen:

https://github.com/phpbits/block-options/blob/8a018909bb7407719afc23282a7303e2f5eb5357/includes/class-editorskit-welcome.php#L126

Since EditorsKit is running the block_editor_settings filter with an empty array, Gutenberg's subsequent iteration of foreach ( $settings['imageSizes'] ) will cause a warning to be logged.

There's two options here to address this:

  1. EditorsKit could provide all of the expected settings properties, to maximize compatibility with filters which may assume those properties to be present.
  2. As noted in Getting invalid argument error with 7.7 and 7.7.1 #20907 (comment), Gutenberg's filtering should be made to be more durable about the inputs it works with.
    1. Don't assume that imageSizes is an array.
    2. Avoid assigning imageDimensions if already assigned (?), if the idea is that this code need only exist as compatibility for 5.3.2 (it should likely be moved to compat.php, with comments indicating some future removal once minimum version requirement is bumped).

@aduth
Copy link
Member

aduth commented Mar 16, 2020

Fix proposed at #20939

@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Testing Needs further testing to be confirmed. [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended [Type] Plugin Interoperability Incompatibilities between a specific plugin and the block editor. Close with workaround notes.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants