-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Refresh: Implement 'the_block_template_html' filter for the block template #6533
base: trunk
Are you sure you want to change the base?
Refresh: Implement 'the_block_template_html' filter for the block template #6533
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
@joemcgill This is still pending tests, correct? |
@westonruter I think adding some tests could be good. However, the way this was implemented seems to be fully compatible with the previous behavior, so previous tests for block-templates should cover this change. I'll spend some time verifying and see if there are some places where additional test coverage should be added. |
The fix here is purely for performance, so there's no bug that can be tested otherwise? |
As far as I can tell, this wouldn't have any direct impact on performance—if anything, moving from hard coded functions to hooks, is probably slower—but it does provide the opportunity for post processing that needs to be run across the whole template to be handled in one place in the future, which would be better. |
I thought Core-55996 is intended to be a performance fix by avoiding the same functions being run on the content more than once? |
I've manually tested this, and everything still works as expected (embeds, shortcodes, etc) across patterns, templates, and content. I also tried using the |
That's correct. Though, @felixarntz questioned whether running certain filters twice was a bad thing in this comment. This PR does not address that question, but only moves the hard-coded function calls for the block template canvas to a filter. To finish addressing the original ticket, I think we would need to move some post-processing off of the post content block since it is being run on the full template, but that will need a bit more thinking. Either way, having this filter in place is a step towards addressing the original ticket concerns and addresses the use case @ryelle ran into. I'd be happy to open a separate ticket specifically for proposing the filter, but since he already had the implementation here, I just refreshed his PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joemcgill This looks solid to me. Sharing a few considerations we may want to think through.
add_filter( 'the_block_template_html', 'wptexturize' ); | ||
add_filter( 'the_block_template_html', 'wp_filter_content_tags' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having the order of these two purely defined by the order of these two add_filter()
calls, I think we should use priority 12
on wp_filter_content_tags
, also for consistency with how it is intentionally done elsewhere as of 6560f46.
add_filter( 'the_block_template_html', 'wptexturize' ); | |
add_filter( 'the_block_template_html', 'wp_filter_content_tags' ); | |
add_filter( 'the_block_template_html', 'wptexturize' ); | |
add_filter( 'the_block_template_html', 'wp_filter_content_tags', 12 ); |
add_filter( 'the_block_template_html', 'wp_filter_content_tags' ); | ||
add_filter( 'the_block_template_html', 'convert_smilies', 20 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the original code that is being changed here, convert_smilies()
was run before wp_filter_content_tags()
. While I'm not opposed to use the same priority as convert_smilies
uses elsewhere, we should make sure using a different order here wasn't an intentional decision (and there is a good chance it wasn't).
But if we don't feel strongly, it would be safer to leave out the priority on convert_smilies()
so that the original order is maintained.
add_filter( 'the_block_template_html', 'wp_filter_content_tags' ); | |
add_filter( 'the_block_template_html', 'convert_smilies', 20 ); | |
add_filter( 'the_block_template_html', 'wp_filter_content_tags', 12 ); | |
add_filter( 'the_block_template_html', 'convert_smilies' ); |
add_filter( 'the_block_template_html', 'shortcode_unautop', 7 ); | ||
add_filter( 'the_block_template_html', 'do_shortcode', 8 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this maintains the original order of the function, I wonder whether we could align this with the filter order execution on the other similar scenarios, e.g. on the_content
. On those, shortcode_unautop
uses the default 10
and do_shortcode
uses 11
.
I know this comment is a bit opposite of my other comment, but I'm purely throwing it out there for consideration. I wonder why it was even decided in the first place to use a different order here.
On another note: If we used 10
and 11
here, it would also allow to use 8
for the filters in the WP_Embed
class, which is another place to make things more consistent.
add_filter( 'the_block_template_html', 'shortcode_unautop', 7 ); | |
add_filter( 'the_block_template_html', 'do_shortcode', 8 ); | |
add_filter( 'the_block_template_html', 'shortcode_unautop' ); | |
add_filter( 'the_block_template_html', 'do_shortcode', 11 ); |
@@ -30,6 +30,7 @@ class WP_Embed { | |||
*/ | |||
public function __construct() { | |||
// Hack to get the [embed] shortcode to run before wpautop(). | |||
add_filter( 'the_block_template_html', array( $this, 'run_shortcode' ), 6 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go with my other suggestion on adjusting the shortcode filter priorities, we could align this:
add_filter( 'the_block_template_html', array( $this, 'run_shortcode' ), 6 ); | |
add_filter( 'the_block_template_html', array( $this, 'run_shortcode' ), 8 ); |
@@ -38,6 +39,7 @@ public function __construct() { | |||
add_shortcode( 'embed', '__return_false' ); | |||
|
|||
// Attempts to embed all URLs in a post. | |||
add_filter( 'the_block_template_html', array( $this, 'autoembed' ), 6 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go with my other suggestion on adjusting the shortcode filter priorities, we could align this:
add_filter( 'the_block_template_html', array( $this, 'autoembed' ), 6 ); | |
add_filter( 'the_block_template_html', array( $this, 'autoembed' ), 8 ); |
Another use case for a filter like this is described in WordPress/gutenberg#61212. |
@joemcgill Is it? That filter allows attributes to be added to the |
@joemcgill Is this something you're still planning to get back to? I think foundationally the PR looks good, mostly minor feedback to address, plus this now needs a refresh due to a merge conflict. |
This refreshes #5188
Trac ticket: https://core.trac.wordpress.org/ticket/55996
Trac ticket: https://core.trac.wordpress.org/ticket/61446
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.