insert_hooked_blocks_into_rest_response( WP_REST_Response $response, WP_Post $post ): WP_REST_Response

In this article

Hooks into the REST API response for the Posts endpoint and adds the first and last inner blocks.

Parameters

$responseWP_REST_Responserequired
The response object.
$postWP_Postrequired
Post object.

Return

WP_REST_Response The response object.

Source

function insert_hooked_blocks_into_rest_response( $response, $post ) {	if ( empty( $response->data['content']['raw'] ) ) {	return $response;	}	$response->data['content']['raw'] = apply_block_hooks_to_content_from_post_object(	$response->data['content']['raw'],	$post,	'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata'	);	// 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.	$priority = has_filter( 'the_content', 'apply_block_hooks_to_content_from_post_object' );	if ( false !== $priority ) {	remove_filter( 'the_content', 'apply_block_hooks_to_content_from_post_object', $priority );	}	/** This filter is documented in wp-includes/post-template.php */	$response->data['content']['rendered'] = apply_filters(	'the_content',	$response->data['content']['raw']	);	// Restore the filter if it was set initially.	if ( false !== $priority ) {	add_filter( 'the_content', 'apply_block_hooks_to_content_from_post_object', $priority );	}	return $response; } 

Hooks

apply_filters( ‘the_content’, string $content )

Filters the post content.

Changelog

VersionDescription
6.8.0Support non-wp_navigation post types.
6.6.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.