WP_REST_Attachments_Controller::get_item_schema()publicWP 4.7.0

Retrieves the attachment's schema, conforming to JSON Schema.

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

Хуков нет.

Возвращает

Массив. Item schema as an array.

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

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

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

С версии 4.7.0 Введена.

Код WP_REST_Attachments_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 = parent::get_item_schema();

	$schema['properties']['alt_text'] = array(
		'description' => __( 'Alternative text to display when attachment is not displayed.' ),
		'type'        => 'string',
		'context'     => array( 'view', 'edit', 'embed' ),
		'arg_options' => array(
			'sanitize_callback' => 'sanitize_text_field',
		),
	);

	$schema['properties']['caption'] = array(
		'description' => __( 'The attachment caption.' ),
		'type'        => 'object',
		'context'     => array( 'view', 'edit', 'embed' ),
		'arg_options' => array(
			'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database().
			'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database().
		),
		'properties'  => array(
			'raw'      => array(
				'description' => __( 'Caption for the attachment, as it exists in the database.' ),
				'type'        => 'string',
				'context'     => array( 'edit' ),
			),
			'rendered' => array(
				'description' => __( 'HTML caption for the attachment, transformed for display.' ),
				'type'        => 'string',
				'context'     => array( 'view', 'edit', 'embed' ),
				'readonly'    => true,
			),
		),
	);

	$schema['properties']['description'] = array(
		'description' => __( 'The attachment description.' ),
		'type'        => 'object',
		'context'     => array( 'view', 'edit' ),
		'arg_options' => array(
			'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database().
			'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database().
		),
		'properties'  => array(
			'raw'      => array(
				'description' => __( 'Description for the attachment, as it exists in the database.' ),
				'type'        => 'string',
				'context'     => array( 'edit' ),
			),
			'rendered' => array(
				'description' => __( 'HTML description for the attachment, transformed for display.' ),
				'type'        => 'string',
				'context'     => array( 'view', 'edit' ),
				'readonly'    => true,
			),
		),
	);

	$schema['properties']['media_type'] = array(
		'description' => __( 'Attachment type.' ),
		'type'        => 'string',
		'enum'        => array( 'image', 'file' ),
		'context'     => array( 'view', 'edit', 'embed' ),
		'readonly'    => true,
	);

	$schema['properties']['mime_type'] = array(
		'description' => __( 'The attachment MIME type.' ),
		'type'        => 'string',
		'context'     => array( 'view', 'edit', 'embed' ),
		'readonly'    => true,
	);

	$schema['properties']['media_details'] = array(
		'description' => __( 'Details about the media file, specific to its type.' ),
		'type'        => 'object',
		'context'     => array( 'view', 'edit', 'embed' ),
		'readonly'    => true,
	);

	$schema['properties']['post'] = array(
		'description' => __( 'The ID for the associated post of the attachment.' ),
		'type'        => 'integer',
		'context'     => array( 'view', 'edit' ),
	);

	$schema['properties']['source_url'] = array(
		'description' => __( 'URL to the original attachment file.' ),
		'type'        => 'string',
		'format'      => 'uri',
		'context'     => array( 'view', 'edit', 'embed' ),
		'readonly'    => true,
	);

	$schema['properties']['missing_image_sizes'] = array(
		'description' => __( 'List of the missing image sizes of the attachment.' ),
		'type'        => 'array',
		'items'       => array( 'type' => 'string' ),
		'context'     => array( 'edit' ),
		'readonly'    => true,
	);

	unset( $schema['properties']['password'] );

	$this->schema = $schema;

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