Title: WP_REST_Attachments_Controller::get_item_schema
Published: December 6, 2016
Last modified: February 24, 2026

---

# WP_REST_Attachments_Controller::get_item_schema(): array

## In this article

 * [Return](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_item_schema/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_item_schema/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_item_schema/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_item_schema/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_item_schema/?output_format=md#wp--skip-link--target)

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

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_item_schema/?output_format=md#return)󠁿

 array Item schema as an array.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_item_schema/?output_format=md#source)󠁿

    ```php
    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 );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php#L1056)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php#L1056-L1167)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_item_schema/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_REST_Posts_Controller::get_item_schema()](https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/get_item_schema/)`wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php` |

Retrieves the post’s schema, conforming to JSON Schema.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  |

| Used by | Description | 
| [WP_REST_Attachments_Controller::create_item()](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/create_item/)`wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php` |

Creates a single attachment.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_item_schema/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_attachments_controller%2Fget_item_schema%2F)
before being able to contribute a note or feedback.