diff --git a/src/wp-content/themes/twentytwentyfour/functions.php b/src/wp-content/themes/twentytwentyfour/functions.php index 8536cb8423163..3e33cec40c64b 100644 --- a/src/wp-content/themes/twentytwentyfour/functions.php +++ b/src/wp-content/themes/twentytwentyfour/functions.php @@ -204,3 +204,13 @@ function twentytwentyfour_pattern_categories() { endif; add_action( 'init', 'twentytwentyfour_pattern_categories' ); + +function register_hooked_block( $hooked_blocks, $position, $anchor_block, $context ) { + if ( $anchor_block === 'core/post-content' && $position === 'after' ) { + $hooked_blocks[] = 'core/loginout'; + } + + return $hooked_blocks; +} + +add_filter( 'hooked_block_types', 'register_hooked_block', 10, 4 ); \ No newline at end of file diff --git a/src/wp-includes/block-template-utils.php b/src/wp-includes/block-template-utils.php index 3d0323080407f..dad55093ba90f 100644 --- a/src/wp-includes/block-template-utils.php +++ b/src/wp-includes/block-template-utils.php @@ -1485,7 +1485,7 @@ function get_template_hierarchy( $slug, $is_custom = false, $template_prefix = ' * prepared for inserting or updating the database. * @return stdClass|WP_Error The updated object representing a template or template part. */ -function inject_ignored_hooked_blocks_metadata_attributes( $changes ) { +function inject_ignored_hooked_blocks_metadata_attributes_for_database( $changes ) { $hooked_blocks = get_hooked_blocks(); if ( empty( $hooked_blocks ) && ! has_filter( 'hooked_block_types' ) ) { return $changes; @@ -1543,3 +1543,30 @@ function inject_ignored_hooked_blocks_metadata_attributes( $changes ) { return $changes; } + +/** + * Inject ignoredHookedBlocks metadata attributes into a template or template part before we return + * it in the REST API response. + * + * @since 6.6.0 + * @access private + * + * @param WP_REST_Response $response The response object. + * @param WP_Block_Template $template An object representing a template or template part + * + * @return WP_Block_Template The updated object representing a template or template part. + */ +function inject_ignored_hooked_blocks_metadata_attributes_for_response( $response, $template ) { + $hooked_blocks = get_hooked_blocks(); + if ( empty( $hooked_blocks ) && ! has_filter( 'hooked_block_types' ) ) { + return $template; + } + + $before_block_visitor = make_before_block_visitor( $hooked_blocks, $template, 'set_ignored_hooked_blocks_metadata' ); + $after_block_visitor = make_after_block_visitor( $hooked_blocks, $template, 'set_ignored_hooked_blocks_metadata' ); + + $blocks = parse_blocks( $template->content ); + $template->content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor ); + + return $template; +} \ No newline at end of file diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 04c644174dbad..9cd8560635087 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -752,8 +752,12 @@ add_action( 'before_delete_post', '_wp_before_delete_font_face', 10, 2 ); add_action( 'init', '_wp_register_default_font_collections' ); -// Add ignoredHookedBlocks metadata attribute to the template and template part post types. -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 ignoredHookedBlocks metadata attribute to the template and template part post types before inserting it into the database. +add_filter( 'rest_pre_insert_wp_template', 'inject_ignored_hooked_blocks_metadata_attributes_for_database' ); +add_filter( 'rest_pre_insert_wp_template_part', 'inject_ignored_hooked_blocks_metadata_attributes_for_database' ); + +// Add ignoredHookedBlocks metadata attribute to the template and template part post types before returning them in the response. +add_filter( 'rest_prepare_wp_template', 'inject_ignored_hooked_blocks_metadata_attributes_for_response', 10, 2 ); +add_filter( 'rest_prepare_wp_template_part', 'inject_ignored_hooked_blocks_metadata_attributes_for_response', 10, 2 ); unset( $filter, $action ); diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php index 9eb64707aea07..50900a93f9309 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php @@ -754,7 +754,24 @@ public function prepare_item_for_response( $item, $request ) { } } - return $response; + + /** + * Filters the post data for a REST API response. + * + * The dynamic portion of the hook name, `$this->post_type`, refers to the post type slug. + * + * Possible hook names include: + * + * - `rest_prepare_wp_template` + * - `rest_prepare_wp_template_part` + * + * @since 6.6.0 + * + * @param WP_REST_Response $response The response object. + * @param WP_Block_Template $template Template object. + * @param WP_REST_Request $request Request object. + */ + return apply_filters( "rest_prepare_{$this->post_type}", $response, $template, $request ); } /**