wordpress-develop icon indicating copy to clipboard operation
wordpress-develop copied to clipboard

Block Hooks API: Harmonize ignoredHookedBlocks metadata injection logic

Open tjcafferkey opened this issue 1 year ago • 3 comments

This PR aims to haromize the injection of the ignoredHookedBlocks data. We currently have two points of processing for this with the first being for wp_template & wp_template_part and the second being for wp_navigation which is stored separately in the wp_postmeta table. For us to combine these into a single approach this PR has a conditional statement to handle wp_navigation items separately.

I've also created (and tested) a new function to build template objects (WP_Template) from database objects (stdClass) which is where we intercept this data when the controller prepares it for the database.

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


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.

tjcafferkey avatar May 14 '24 13:05 tjcafferkey

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.

github-actions[bot] avatar May 14 '24 13:05 github-actions[bot]

@ockham interested to know your thoughts on this approach. I can see an argument against the new function (_build_block_template_object_from_database_object) but without it the function inject_ignored_hooked_blocks_metadata_attributes becomes somewhat unwieldy and potentially hard to navigation.

I would prefer to write more unit tests but will wait on your feedback on the general approach before doing so.

tjcafferkey avatar May 15 '24 10:05 tjcafferkey

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props tomjcafferkey, bernhard-reiter.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

github-actions[bot] avatar May 15 '24 10:05 github-actions[bot]

Hmm, looks like inject_ignored_hooked_blocks_metadata_attributes was previously really template-specific. I'm second-guessing now if it makes sense to use it as a shared filter for both rest_pre_insert_wp_template (and _part) on the one hand, and for rest_pre_insert_wp_navigation on the other, when we have to accommodate vastly different logic for those cases under the roof of that function after all 😕

I'm starting to think that we should after all start with a distinct filter function for rest_pre_insert_wp_navigation (basically copying over block_core_navigation_update_ignore_hooked_blocks_meta), and then work backwards from there 🤔

ockham avatar May 21 '24 15:05 ockham

I'm starting to think that we should after all start with a distinct filter function for rest_pre_insert_wp_navigation (basically copying over block_core_navigation_update_ignore_hooked_blocks_meta), and then work backwards from there 🤔

We could probably extract a helper function for the applying the Block Hooks algorithm itself (i.e. running get_hooked_blocks, creating the visitors, and running traverse_and_serialized_blocks) that could hopefully be used by both inject_ignored_hooked_blocks_metadata_attributes and block_core_navigation_update_ignore_hooked_blocks_meta (or whatever we'll rename the latter to).

ockham avatar May 21 '24 15:05 ockham

We could probably extract a helper function for the applying the Block Hooks algorithm itself (i.e. running get_hooked_blocks, creating the visitors, and running traverse_and_serialized_blocks) that could hopefully be used by both inject_ignored_hooked_blocks_metadata_attributes and block_core_navigation_update_ignore_hooked_blocks_meta (or whatever we'll rename the latter to).

I think it makes sense to keep the two concerns (injecting the data into template markup vs updating it in wp_postmeta) separate.

I've experimented with this approach here https://github.com/WordPress/wordpress-develop/pull/6604

Keen to know how you feel it compares to this one based on your comments above.

tjcafferkey avatar May 22 '24 11:05 tjcafferkey

I've experimented with this approach here #6604

Keen to know how you feel it compares to this one based on your comments above.

Loving it! That one reads a lot more naturally IMO 😄

ockham avatar May 23 '24 18:05 ockham

Should we close this one in favor of https://github.com/WordPress/wordpress-develop/pull/6604? 😊

ockham avatar May 27 '24 09:05 ockham

Should we close this one in favor of https://github.com/WordPress/wordpress-develop/pull/6604? 😊

Closing 😄

tjcafferkey avatar May 28 '24 09:05 tjcafferkey