WP_REST_Block_Patterns_Controller::get_item_schema()publicWP 6.0.0

Retrieves the block pattern schema, conforming to JSON Schema.

Метод класса: WP_REST_Block_Patterns_Controller{}

Хуков нет.

Возвращает

Массив. Item schema data.

Использование

$WP_REST_Block_Patterns_Controller = new WP_REST_Block_Patterns_Controller();
$WP_REST_Block_Patterns_Controller->get_item_schema();

Список изменений

С версии 6.0.0 Введена.
С версии 6.3.0 Added source property.

Код WP_REST_Block_Patterns_Controller::get_item_schema() WP 6.5.2

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

	$schema = array(
		'$schema'    => 'http://json-schema.org/draft-04/schema#',
		'title'      => 'block-pattern',
		'type'       => 'object',
		'properties' => array(
			'name'           => array(
				'description' => __( 'The pattern name.' ),
				'type'        => 'string',
				'readonly'    => true,
				'context'     => array( 'view', 'edit', 'embed' ),
			),
			'title'          => array(
				'description' => __( 'The pattern title, in human readable format.' ),
				'type'        => 'string',
				'readonly'    => true,
				'context'     => array( 'view', 'edit', 'embed' ),
			),
			'content'        => array(
				'description' => __( 'The pattern content.' ),
				'type'        => 'string',
				'readonly'    => true,
				'context'     => array( 'view', 'edit', 'embed' ),
			),
			'description'    => array(
				'description' => __( 'The pattern detailed description.' ),
				'type'        => 'string',
				'readonly'    => true,
				'context'     => array( 'view', 'edit', 'embed' ),
			),
			'viewport_width' => array(
				'description' => __( 'The pattern viewport width for inserter preview.' ),
				'type'        => 'number',
				'readonly'    => true,
				'context'     => array( 'view', 'edit', 'embed' ),
			),
			'inserter'       => array(
				'description' => __( 'Determines whether the pattern is visible in inserter.' ),
				'type'        => 'boolean',
				'readonly'    => true,
				'context'     => array( 'view', 'edit', 'embed' ),
			),
			'categories'     => array(
				'description' => __( 'The pattern category slugs.' ),
				'type'        => 'array',
				'readonly'    => true,
				'context'     => array( 'view', 'edit', 'embed' ),
			),
			'keywords'       => array(
				'description' => __( 'The pattern keywords.' ),
				'type'        => 'array',
				'readonly'    => true,
				'context'     => array( 'view', 'edit', 'embed' ),
			),
			'block_types'    => array(
				'description' => __( 'Block types that the pattern is intended to be used with.' ),
				'type'        => 'array',
				'readonly'    => true,
				'context'     => array( 'view', 'edit', 'embed' ),
			),
			'post_types'     => array(
				'description' => __( 'An array of post types that the pattern is restricted to be used with.' ),
				'type'        => 'array',
				'readonly'    => true,
				'context'     => array( 'view', 'edit', 'embed' ),
			),
			'template_types' => array(
				'description' => __( 'An array of template types where the pattern fits.' ),
				'type'        => 'array',
				'readonly'    => true,
				'context'     => array( 'view', 'edit', 'embed' ),
			),
			'source'         => array(
				'description' => __( 'Where the pattern comes from e.g. core' ),
				'type'        => 'string',
				'readonly'    => true,
				'context'     => array( 'view', 'edit', 'embed' ),
				'enum'        => array(
					'core',
					'plugin',
					'theme',
					'pattern-directory/core',
					'pattern-directory/theme',
					'pattern-directory/featured',
				),
			),
		),
	);

	$this->schema = $schema;

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