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

Fix WP_Block_Supports class compatibility with Gutenberg-provided class #640

Closed
wants to merge 14 commits into from
Closed

Fix WP_Block_Supports class compatibility with Gutenberg-provided class #640

wants to merge 14 commits into from

Conversation

oandregal
Copy link
Member

@oandregal oandregal commented Oct 21, 2020

Related:

The WP_Block_Supports class is a new addition that will come with 5.6 and acts as a register of the kind of features a block supports. It's already on WordPress 5.6 beta1 and we need to fix how core and the plugin play together in a number of situations:

plugin + WordPress < 5.6 (core has a WP_Block_Supports class)
plugin + WordPress >= 5.6 (core doesn't have a WP_Block_Supports class) 

@oandregal oandregal changed the title Remove/global current parsed block Fix WP_Block_Supports class compatibility with Gutenberg-provided class Oct 22, 2020
…urrent code

Since:

    https://core.trac.wordpress.org/ticket/49927
    Commit 910de8f at wordpress-develop

we no longer use the render method of WP_Block_Type,
but its equivalent at WP_Block.

There's still some tests that use that old path that were failing
because the render_callback was called with only 2 arguments
instead of the three that WP_Block uses.

This commit:

- Signals WP_Block_Type->render as deprecated.
- Patch it to pass a null value as the third argument
  (it represents an instance of WP_Block).
Because the render_callback is now wrapped by a function
at src/wp-includes/class-wp-block-supports.php it'll
be callable. So we pass null as the callback
and the wrapper won't be attached.
By using is_callable we make sure that we don't change any
callback behavior:

- if the original callback is callable => attach the wrapper
- if the original callback is not callable => no wrapper
@youknowriad
Copy link
Contributor

I won't be able to test this today but it's looking good to me if anyone wants to ship it :)

@oandregal
Copy link
Member Author

Some testing Instructions:

  • Create a post and add the LatestPost block.
  • Publish.
  • In the front-end (but also in the editor), the UL element should have the wp-block-latest-posts class attached.

I've reproduced these instructions with WordPress 5.6 beta1 with and without this patch in the following scenarios: no Gutenberg plugin installed, with gutenberg 9.2.1, with Gutenberg master. In Gutenberg master without this patch, the class isn't attached and there are some PHP errors.

I think this is ready to go. Anyone to review? Was hoping to land this before next Tuesday (beta 2).

@oandregal oandregal deleted the remove/global-current-parsed-block branch October 26, 2020 08:31
oandregal pushed a commit to WordPress/gutenberg that referenced this pull request Oct 26, 2020
…ss (#26417)

This PR ports the changes from the core PR at WordPress/wordpress-develop#640

Co-authored-by: Jon Surrell <jon.surrell@automattic.com>
Co-authored-by: Miguel Fonseca <miguelcsf@gmail.com>
@talldan
Copy link
Contributor

talldan commented Oct 26, 2020

Thanks for fixing this ❤️

oandregal pushed a commit to WordPress/gutenberg that referenced this pull request Oct 26, 2020
…ss (#26417)

This PR ports the changes from the core PR at WordPress/wordpress-develop#640

Co-authored-by: Jon Surrell <jon.surrell@automattic.com>
Co-authored-by: Miguel Fonseca <miguelcsf@gmail.com>
@hellofromtonya
Copy link
Contributor

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.

4 participants