Skip to content
Closed
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions src/wp-content/themes/twentytwentyfour/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
29 changes: 28 additions & 1 deletion src/wp-includes/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
10 changes: 7 additions & 3 deletions src/wp-includes/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down