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

Preload paths: avoid fatal error on Widgets page. #39470

Merged
merged 1 commit into from
Mar 17, 2022

Conversation

jeherve
Copy link
Contributor

@jeherve jeherve commented Mar 15, 2022

Follow-up to #39256

What and why?

#39256 added some logic using the block_editor_rest_api_preload_paths filter. That works well, but on a fresh installation of WordPress, that filter may sometimes return multidimensional arrays. This is the case on the Widgets page for example, where the filter's array of paths to preload will be as follows:

Array
(
    [0] => Array
        (
            [0] => /wp/v2/media
            [1] => OPTIONS
        )

    [1] => /wp/v2/sidebars?context=edit&per_page=-1
    [2] => /wp/v2/widgets?context=edit&per_page=-1&_embed=about
)

In this situation, when running a version of the Gutenberg plugin including #39256, we end up with this Fatal error when loading the widgets screen:

PHP Fatal error:  Uncaught TypeError: strpos(): Argument #1 ($haystack) must be of type string, array given in /var/www/html/wp-content/plugins/gutenberg/lib/compat/wordpress-6.0/edit-form-blocks.php:44

How?

  • This PR solves the issue by ensuring that we're dealing with a string when checking for a matching path.

Testing Instructions

  1. Start with a site that runs Gutenberg trunk.
  2. Activate a theme that supports sidebars, such as Twenty Twenty.
  3. Go to Appearance > Widgets and notice the Fatal error.
  4. Apply this patch, and notice that the error disappears.

@jeherve
Copy link
Contributor Author

jeherve commented Mar 15, 2022

cc @jsnajdr who worked on #39256.

Copy link
Member

@jsnajdr jsnajdr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks for fixing! 👍

@jsnajdr
Copy link
Member

jsnajdr commented Mar 17, 2022

Hi @jeherve 👋 Can you please rebase your PR branch onto latest trunk? That should be all you need to make the performance and e2e tests pass again. Then we can merge the patch.

@jeherve
Copy link
Contributor Author

jeherve commented Mar 17, 2022

Sure thing; done.

@jsnajdr jsnajdr merged commit 7aa0426 into WordPress:trunk Mar 17, 2022
@github-actions github-actions bot added this to the Gutenberg 12.9 milestone Mar 17, 2022
@jeherve jeherve deleted the fix/fatal-widgets-page branch March 17, 2022 10:06
jostnes pushed a commit to jostnes/gutenberg that referenced this pull request Mar 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants