Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1674,9 +1674,15 @@ function block_core_navigation_insert_hooked_blocks_into_rest_response( $respons
$rest_prepare_wp_navigation_core_callback = 'block_core_navigation_' . 'insert_hooked_blocks_into_rest_response';

/*
* 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_insert_hooked_blocks_into_rest_response` filter in the following cases:
* - If Core has added the `insert_hooked_blocks_into_rest_response` 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_prepare_wp_navigation_core_callback` filter has already been added.
*/
if ( function_exists( 'set_ignored_hooked_blocks_metadata' ) && ! has_filter( 'rest_prepare_wp_navigation', $rest_prepare_wp_navigation_core_callback ) ) {
if (
! has_filter( 'rest_prepare_wp_navigation', 'insert_hooked_blocks_into_rest_response' ) &&
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the main question for this PR is if we're happy with this tentative name (insert_hooked_blocks_into_rest_response).

function_exists( 'set_ignored_hooked_blocks_metadata' ) &&
! has_filter( 'rest_prepare_wp_navigation', $rest_prepare_wp_navigation_core_callback )
) {
add_filter( 'rest_prepare_wp_navigation', 'block_core_navigation_insert_hooked_blocks_into_rest_response', 10, 3 );
}