Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Insert hooked block into editor
  • Loading branch information
ockham committed Dec 4, 2024
commit 20a547069c199315d8c0dcfba6969693b75f3cf7
26 changes: 20 additions & 6 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -1295,16 +1295,30 @@ function insert_hooked_blocks_into_rest_response( $response, $post ) {
'ignoredHookedBlocks' => $ignored_hooked_blocks,
);
}
$content = get_comment_delimited_block_content(
'core/navigation',
$attributes,
$response->data['content']['raw']

$post_type_to_wrapper_block_mappings = array(
'wp_navigation' => 'core/navigation',
'wp_post' => 'core/post-content',
);

if ( isset( $post_type_to_wrapper_block_mappings[ $post->post_type ] ) ) {
$wrapper_block_type = $post_type_to_wrapper_block_mappings[ $post->post_type ];

$content = get_comment_delimited_block_content(
$wrapper_block_type,
$attributes,
$response->data['content']['raw']
);
} else {
$content = $response->data['content']['raw'];
}

$content = apply_block_hooks_to_content( $content, $post );

// Remove mock Navigation block wrapper.
$content = remove_serialized_parent_block( $content );
if ( isset( $post_type_to_wrapper_block_mappings[ $post->post_type ] ) ) {
// Remove mock block wrapper.
$content = remove_serialized_parent_block( $content );
}

$response->data['content']['raw'] = $content;

Expand Down
3 changes: 2 additions & 1 deletion src/wp-includes/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,8 @@
// Update ignoredHookedBlocks postmeta for wp_navigation post type.
add_filter( 'rest_pre_insert_wp_navigation', 'update_ignored_hooked_blocks_postmeta' );

// Inject hooked blocks into the wp_navigation post type REST response.
// Inject hooked blocks into the post and wp_navigation post type REST response.
add_filter( 'rest_prepare_wp_navigation', 'insert_hooked_blocks_into_rest_response', 10, 2 );
add_filter( 'rest_prepare_post', 'insert_hooked_blocks_into_rest_response', 10, 2 );

unset( $filter, $action );