Skip to content

Commit

Permalink
Navigation block: Check for update_ignored_hooked_blocks_postmeta in …
Browse files Browse the repository at this point in the history
…core (#61903)

Adding another `has_filter` check before adding the Navigation blocks filter to store `ignoredHookedBlocks` metadata as this functionality is being moved into WP core.

Co-authored-by: Bernie Reiter <96308+ockham@users.noreply.github.com>
  • Loading branch information
tjcafferkey and ockham committed May 27, 2024
1 parent 5deecb2 commit 68ac168
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -1617,10 +1617,16 @@ function block_core_navigation_update_ignore_hooked_blocks_meta( $post ) {
$rest_insert_wp_navigation_core_callback = 'block_core_navigation_' . 'update_ignore_hooked_blocks_meta'; // phpcs:ignore Generic.Strings.UnnecessaryStringConcat.Found

/*
* Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5
* that are not present in Gutenberg's WP 6.5 compatibility layer.
* Do not add the `block_core_navigation_update_ignore_hooked_blocks_meta` filter in the following cases:
* - If Core has added the `update_ignored_hooked_blocks_postmeta` filter already (WP >= 6.6);
* - or if the `set_ignored_hooked_blocks_metadata` function is unavailable (which is required for the filter to work. It was introduced by WP 6.5 but is not present in Gutenberg's WP 6.5 compatibility layer);
* - or if the `$rest_insert_wp_navigation_core_callback` filter has already been added.
*/
if ( function_exists( 'set_ignored_hooked_blocks_metadata' ) && ! has_filter( 'rest_pre_insert_wp_navigation', $rest_insert_wp_navigation_core_callback ) ) {
if (
! has_filter( 'rest_pre_insert_wp_navigation', 'update_ignored_hooked_blocks_postmeta' ) &&
function_exists( 'set_ignored_hooked_blocks_metadata' ) &&
! has_filter( 'rest_pre_insert_wp_navigation', $rest_insert_wp_navigation_core_callback )
) {
add_filter( 'rest_pre_insert_wp_navigation', 'block_core_navigation_update_ignore_hooked_blocks_meta' );
}

Expand Down

0 comments on commit 68ac168

Please sign in to comment.