WP_REST_Search_Controller::get_item_schema(): array

In this article

Retrieves the item schema, conforming to JSON Schema.

Return

array Item schema data.

Source

public function get_item_schema() {
	if ( $this->schema ) {
		return $this->add_additional_fields_schema( $this->schema );
	}

	$types    = array();
	$subtypes = array();

	foreach ( $this->search_handlers as $search_handler ) {
		$types[]  = $search_handler->get_type();
		$subtypes = array_merge( $subtypes, $search_handler->get_subtypes() );
	}

	$types    = array_unique( $types );
	$subtypes = array_unique( $subtypes );

	$schema = array(
		'$schema'    => 'http://json-schema.org/draft-04/schema#',
		'title'      => 'search-result',
		'type'       => 'object',
		'properties' => array(
			self::PROP_ID      => array(
				'description' => __( 'Unique identifier for the object.' ),
				'type'        => array( 'integer', 'string' ),
				'context'     => array( 'view', 'embed' ),
				'readonly'    => true,
			),
			self::PROP_TITLE   => array(
				'description' => __( 'The title for the object.' ),
				'type'        => 'string',
				'context'     => array( 'view', 'embed' ),
				'readonly'    => true,
			),
			self::PROP_URL     => array(
				'description' => __( 'URL to the object.' ),
				'type'        => 'string',
				'format'      => 'uri',
				'context'     => array( 'view', 'embed' ),
				'readonly'    => true,
			),
			self::PROP_TYPE    => array(
				'description' => __( 'Object type.' ),
				'type'        => 'string',
				'enum'        => $types,
				'context'     => array( 'view', 'embed' ),
				'readonly'    => true,
			),
			self::PROP_SUBTYPE => array(
				'description' => __( 'Object subtype.' ),
				'type'        => 'string',
				'enum'        => $subtypes,
				'context'     => array( 'view', 'embed' ),
				'readonly'    => true,
			),
		),
	);

	$this->schema = $schema;

	return $this->add_additional_fields_schema( $this->schema );
}

Changelog

VersionDescription
5.0.0Introduced.

User Contributed Notes

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