Block Hooks: Apply to synced patterns.

Apply Block Hooks to synced patterns (i.e. `core/block` instances).

Props bernhard-reiter, gziolo.
Fixes #62704.
Built from https://develop.svn.wordpress.org/trunk@59543


git-svn-id: http://core.svn.wordpress.org/trunk@58929 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Bernhard Reiter 2024-12-19 13:26:28 +00:00
parent 87e7f72397
commit 13521bce0b
3 changed files with 14 additions and 3 deletions

View File

@ -1219,6 +1219,8 @@ function update_ignored_hooked_blocks_postmeta( $post ) {
if ( 'wp_navigation' === $post->post_type ) { if ( 'wp_navigation' === $post->post_type ) {
$wrapper_block_type = 'core/navigation'; $wrapper_block_type = 'core/navigation';
} elseif ( 'wp_block' === $post->post_type ) {
$wrapper_block_type = 'core/block';
} else { } else {
$wrapper_block_type = 'core/post-content'; $wrapper_block_type = 'core/post-content';
} }
@ -1291,7 +1293,7 @@ function insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata( &$parsed_a
* @return WP_REST_Response The response object. * @return WP_REST_Response The response object.
*/ */
function insert_hooked_blocks_into_rest_response( $response, $post ) { function insert_hooked_blocks_into_rest_response( $response, $post ) {
if ( empty( $response->data['content']['raw'] ) || empty( $response->data['content']['rendered'] ) ) { if ( empty( $response->data['content']['raw'] ) ) {
return $response; return $response;
} }
@ -1306,6 +1308,8 @@ function insert_hooked_blocks_into_rest_response( $response, $post ) {
if ( 'wp_navigation' === $post->post_type ) { if ( 'wp_navigation' === $post->post_type ) {
$wrapper_block_type = 'core/navigation'; $wrapper_block_type = 'core/navigation';
} elseif ( 'wp_block' === $post->post_type ) {
$wrapper_block_type = 'core/block';
} else { } else {
$wrapper_block_type = 'core/post-content'; $wrapper_block_type = 'core/post-content';
} }
@ -1327,6 +1331,11 @@ function insert_hooked_blocks_into_rest_response( $response, $post ) {
$response->data['content']['raw'] = $content; $response->data['content']['raw'] = $content;
// If the rendered content was previously empty, we leave it like that.
if ( empty( $response->data['content']['rendered'] ) ) {
return $response;
}
// `apply_block_hooks_to_content` is called above. Ensure it is not called again as a filter. // `apply_block_hooks_to_content` is called above. Ensure it is not called again as a filter.
$priority = has_filter( 'the_content', 'apply_block_hooks_to_content' ); $priority = has_filter( 'the_content', 'apply_block_hooks_to_content' );
if ( false !== $priority ) { if ( false !== $priority ) {

View File

@ -760,14 +760,16 @@ add_action( 'init', '_wp_register_default_font_collections' );
add_filter( 'rest_pre_insert_wp_template', 'inject_ignored_hooked_blocks_metadata_attributes' ); add_filter( 'rest_pre_insert_wp_template', 'inject_ignored_hooked_blocks_metadata_attributes' );
add_filter( 'rest_pre_insert_wp_template_part', 'inject_ignored_hooked_blocks_metadata_attributes' ); add_filter( 'rest_pre_insert_wp_template_part', 'inject_ignored_hooked_blocks_metadata_attributes' );
// Update ignoredHookedBlocks postmeta for wp_navigation post type. // Update ignoredHookedBlocks postmeta for some post types.
add_filter( 'rest_pre_insert_page', 'update_ignored_hooked_blocks_postmeta' ); add_filter( 'rest_pre_insert_page', 'update_ignored_hooked_blocks_postmeta' );
add_filter( 'rest_pre_insert_post', 'update_ignored_hooked_blocks_postmeta' ); add_filter( 'rest_pre_insert_post', 'update_ignored_hooked_blocks_postmeta' );
add_filter( 'rest_pre_insert_wp_block', 'update_ignored_hooked_blocks_postmeta' );
add_filter( 'rest_pre_insert_wp_navigation', 'update_ignored_hooked_blocks_postmeta' ); add_filter( 'rest_pre_insert_wp_navigation', 'update_ignored_hooked_blocks_postmeta' );
// Inject hooked blocks into the Posts endpoint REST response for some given post types. // Inject hooked blocks into the Posts endpoint REST response for some given post types.
add_filter( 'rest_prepare_page', 'insert_hooked_blocks_into_rest_response', 10, 2 ); add_filter( 'rest_prepare_page', 'insert_hooked_blocks_into_rest_response', 10, 2 );
add_filter( 'rest_prepare_post', 'insert_hooked_blocks_into_rest_response', 10, 2 ); add_filter( 'rest_prepare_post', 'insert_hooked_blocks_into_rest_response', 10, 2 );
add_filter( 'rest_prepare_wp_block', 'insert_hooked_blocks_into_rest_response', 10, 2 );
add_filter( 'rest_prepare_wp_navigation', 'insert_hooked_blocks_into_rest_response', 10, 2 ); add_filter( 'rest_prepare_wp_navigation', 'insert_hooked_blocks_into_rest_response', 10, 2 );
unset( $filter, $action ); unset( $filter, $action );

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.8-alpha-59542'; $wp_version = '6.8-alpha-59543';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.