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

Block Hooks: Apply to Post Content (on frontend) #7889

Closed

Conversation

ockham
Copy link
Contributor

@ockham ockham commented Nov 25, 2024

Port of WordPress/gutenberg#67272.

Trac ticket: https://core.trac.wordpress.org/ticket/61074


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.

@ockham ockham self-assigned this Nov 25, 2024
Copy link

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@@ -192,6 +192,7 @@
add_filter( 'the_title', 'convert_chars' );
add_filter( 'the_title', 'trim' );

add_filter( 'the_content', 'apply_block_hooks_to_content', 8 ); // BEFORE do_blocks().
Copy link
Contributor Author

Choose a reason for hiding this comment

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

apply_block_hooks_to_content parses blocks, traverses the block tree (to insert hooked blocks), and reserializes them. Note that it's followed immediately by do_blocks (on the line below), which also parses blocks.

This means that in theory, there's some potential for optimization (parse only once inside of do_blocks, and traverse to insert hooked blocks there).

In practice, I'm not sure if that's viable, or if that might cause some collisions; in particular if do_blocks is already used in other contexts where hooked blocks are already inserted (through a different mechanism), e.g. in templates or wp_navigation posts.

@ockham
Copy link
Contributor Author

ockham commented Nov 26, 2024

I have drafted an alternative PR based on this one to explore also inserting hooked blocks into Post Content in the editor: #7898

@ockham
Copy link
Contributor Author

ockham commented Dec 3, 2024

Closing in favor of #7898.

@ockham ockham closed this Dec 3, 2024
@ockham ockham deleted the update/apply-block-hooks-to-post-content branch December 3, 2024 13:00
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.

1 participant