wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



insert_hooked_blocks_into_rest_response › WordPress Function

Seit6.6.0
Veraltetn/v
insert_hooked_blocks_into_rest_response ( $response, $post )
Parameter: (2)
  • (WP_REST_Response) $response The response object.
    Erforderlich: Ja
  • (WP_Post) $post Post object.
    Erforderlich: Ja
Gibt zurück:
  • (WP_REST_Response) The response object.
Definiert in:
Codex:
Changelog:
  • 6.8.0

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



Quellcode

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;
}