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

Navigation block: Remove more obsolete Block Hooks helpers #67193

Merged
merged 2 commits into from
Nov 27, 2024
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
31 changes: 2 additions & 29 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -1436,20 +1436,6 @@ function block_core_navigation_get_most_recently_published_navigation() {
return null;
}

/**
* Accepts the serialized markup of a block and its inner blocks, and returns serialized markup of the inner blocks.
*
* @since 6.5.0
*
* @param string $serialized_block The serialized markup of a block and its inner blocks.
* @return string
*/
function block_core_navigation_remove_serialized_parent_block( $serialized_block ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function is no longer used anywhere in the codebase (grep to verify).

$start = strpos( $serialized_block, '-->' ) + strlen( '-->' );
$end = strrpos( $serialized_block, '<!--' );
return substr( $serialized_block, $start, $end - $start );
}

/**
* Mock a parsed block for the Navigation block given its inner blocks and the `wp_navigation` post object.
* The `wp_navigation` post's `_wp_ignored_hooked_blocks` meta is queried to add the `metadata.ignoredHookedBlocks` attribute.
Expand Down Expand Up @@ -1504,19 +1490,6 @@ function block_core_navigation_mock_parsed_block( $inner_blocks, $post ) {
function block_core_navigation_insert_hooked_blocks( $inner_blocks, $post ) {
$mock_navigation_block = block_core_navigation_mock_parsed_block( $inner_blocks, $post );

if ( function_exists( 'apply_block_hooks_to_content' ) ) {
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 has been part of WP Core since 6.6 -- which is now the minimum requirement for Gutenberg, so it's guaranteed to exist.

$mock_navigation_block_markup = serialize_block( $mock_navigation_block );
return apply_block_hooks_to_content( $mock_navigation_block_markup, $post, 'insert_hooked_blocks' );
}

$hooked_blocks = get_hooked_blocks();
$before_block_visitor = null;
$after_block_visitor = null;

if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) {
$before_block_visitor = make_before_block_visitor( $hooked_blocks, $post, 'insert_hooked_blocks' );
$after_block_visitor = make_after_block_visitor( $hooked_blocks, $post, 'insert_hooked_blocks' );
}

return traverse_and_serialize_block( $mock_navigation_block, $before_block_visitor, $after_block_visitor );
$mock_navigation_block_markup = serialize_block( $mock_navigation_block );
return apply_block_hooks_to_content( $mock_navigation_block_markup, $post, 'insert_hooked_blocks' );
}
Loading