Make WordPress Core

Opened 2 months ago

Last modified 4 days ago

#60759 new enhancement

Block Hooks: Harmonize ignoredHookedBlocks metadata injection logic

Reported by: bernhard-reiter's profile Bernhard Reiter Owned by:
Milestone: 6.6 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch
Focuses: Cc:

Description

As of [57790] and https://github.com/WordPress/gutenberg/pull/59561, both the Templates and the Navigation endpoints use the `rest_pre_insert_*` filter to inject the ignoredHookedBlocks metadata attribute into anchor blocks, prior to persisting a template, template part, or navigation menu to the database.

It has been requested that these methods be harmonized, i.e. to use the inject_ignored_hooked_blocks_metadata_attributes filter for both templates/parts and navigation menus. In particular, this would allow removing some of the filters that are currently present in the Navigation block in favor of more "generic" functions.

Conceptually, the relevant filters are indeed quite similar; the major difference is that the one for the Navigation block (block_core_navigation_update_ignore_hooked_blocks_meta) injects a _wp_ignored_hooked_blocks post meta into the wp_navigation post object, in order to allow hooked blocks to be inserted as a Navigation block's first or last child (see #59743).

To harmonize the filters, we would thus have to add a conditional in inject_ignored_hooked_blocks_metadata_attributes to set the post meta if the post type is wp_navigation. (Later on, we might consider extending this to include template parts, where it might also be desirable to insert hooked blocks as a Template Part block's first or last child; however, this should be tackled separately, in order not to conflate refactoring and adding new functionality.)


Eventually, it might also be possible to harmonize injection of hooked blocks (which happens upon reading from the database, unlike the injection of the ignoredHookedBlocks attribute discussed above, which happens upon writing to it.)

Change History (4)

This ticket was mentioned in Slack in #core by bernhardreiter. View the logs.


2 months ago

#2 @Bernhard Reiter
2 months ago

  • Milestone changed from Awaiting Review to 6.6

This ticket was mentioned in PR #6550 on WordPress/wordpress-develop by @tomjcafferkey.


5 days ago
#3

  • Keywords has-patch added

@tomjcafferkey commented on PR #6550:


4 days ago
#4

@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.

Note: See TracTickets for help on using tickets.