WP_REST_Font_Families_Controller::prepare_item_for_response( WP_Post $item, WP_REST_Request $request ): WP_REST_Response

In this article

Prepares a single font family output for response.

Parameters

$itemWP_Postrequired
Post object.
$requestWP_REST_Requestrequired
Request object.

Return

WP_REST_Response Response object.

Source

public function prepare_item_for_response( $item, $request ) {
	$fields = $this->get_fields_for_response( $request );
	$data   = array();

	if ( rest_is_field_included( 'id', $fields ) ) {
		$data['id'] = $item->ID;
	}

	if ( rest_is_field_included( 'theme_json_version', $fields ) ) {
		$data['theme_json_version'] = static::LATEST_THEME_JSON_VERSION_SUPPORTED;
	}

	if ( rest_is_field_included( 'font_faces', $fields ) ) {
		$data['font_faces'] = $this->get_font_face_ids( $item->ID );
	}

	if ( rest_is_field_included( 'font_family_settings', $fields ) ) {
		$data['font_family_settings'] = $this->get_settings_from_post( $item );
	}

	$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
	$data    = $this->add_additional_fields_to_object( $data, $request );
	$data    = $this->filter_response_by_context( $data, $context );

	$response = rest_ensure_response( $data );

	if ( rest_is_field_included( '_links', $fields ) ) {
		$links = $this->prepare_links( $item );
		$response->add_links( $links );
	}

	/**
	 * Filters the font family data for a REST API response.
	 *
	 * @since 6.5.0
	 *
	 * @param WP_REST_Response $response The response object.
	 * @param WP_Post          $post     Font family post object.
	 * @param WP_REST_Request  $request  Request object.
	 */
	return apply_filters( 'rest_prepare_wp_font_family', $response, $item, $request );
}

Hooks

apply_filters( ‘rest_prepare_wp_font_family’, WP_REST_Response $response, WP_Post $post, WP_REST_Request $request )

Filters the font family data for a REST API response.

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

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