W3cubDocs

/WordPress

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

Hooks into the REST API response for the core/navigation block 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 ( ! isset( $response->data['content']['raw'] ) || ! isset( $response->data['content']['rendered'] ) ) {
		return $response;
	}

	$attributes            = array();
	$ignored_hooked_blocks = get_post_meta( $post->ID, '_wp_ignored_hooked_blocks', true );
	if ( ! empty( $ignored_hooked_blocks ) ) {
		$ignored_hooked_blocks  = json_decode( $ignored_hooked_blocks, true );
		$attributes['metadata'] = array(
			'ignoredHookedBlocks' => $ignored_hooked_blocks,
		);
	}
	$content = get_comment_delimited_block_content(
		'core/navigation',
		$attributes,
		$response->data['content']['raw']
	);

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

	// Remove mock Navigation block wrapper.
	$content = remove_serialized_parent_block( $content );

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

	/** This filter is documented in wp-includes/post-template.php */
	$response->data['content']['rendered'] = apply_filters( 'the_content', $content );

	return $response;
}

Hooks

apply_filters( ‘the_content’, string $content )

Filters the post content.

Changelog

Version Description
6.6.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/insert_hooked_blocks_into_rest_response