WP_REST_Attachments_Controller::get_edit_media_item_args(): array

In this article

Gets the request args for the edit item route.

Return

array

Source

protected function get_edit_media_item_args() {
	$args = array(
		'src'       => array(
			'description' => __( 'URL to the edited image file.' ),
			'type'        => 'string',
			'format'      => 'uri',
			'required'    => true,
		),
		// The `modifiers` param takes precedence over the older format.
		'modifiers' => array(
			'description' => __( 'Array of image edits.' ),
			'type'        => 'array',
			'minItems'    => 1,
			'items'       => array(
				'description' => __( 'Image edit.' ),
				'type'        => 'object',
				'required'    => array(
					'type',
					'args',
				),
				'oneOf'       => array(
					array(
						'title'      => __( 'Flip' ),
						'properties' => array(
							'type' => array(
								'description' => __( 'Flip type.' ),
								'type'        => 'string',
								'enum'        => array( 'flip' ),
							),
							'args' => array(
								'description' => __( 'Flip arguments.' ),
								'type'        => 'object',
								'required'    => array(
									'flip',
								),
								'properties'  => array(
									'flip' => array(
										'description' => __( 'Flip direction.' ),
										'type'        => 'object',
										'required'    => array(
											'horizontal',
											'vertical',
										),
										'properties'  => array(
											'horizontal' => array(
												'description' => __( 'Whether to flip in the horizontal direction.' ),
												'type' => 'boolean',
											),
											'vertical' => array(
												'description' => __( 'Whether to flip in the vertical direction.' ),
												'type' => 'boolean',
											),
										),
									),
								),
							),
						),
					),
					array(
						'title'      => __( 'Rotation' ),
						'properties' => array(
							'type' => array(
								'description' => __( 'Rotation type.' ),
								'type'        => 'string',
								'enum'        => array( 'rotate' ),
							),
							'args' => array(
								'description' => __( 'Rotation arguments.' ),
								'type'        => 'object',
								'required'    => array(
									'angle',
								),
								'properties'  => array(
									'angle' => array(
										'description' => __( 'Angle to rotate clockwise in degrees.' ),
										'type'        => 'number',
									),
								),
							),
						),
					),
					array(
						'title'      => __( 'Crop' ),
						'properties' => array(
							'type' => array(
								'description' => __( 'Crop type.' ),
								'type'        => 'string',
								'enum'        => array( 'crop' ),
							),
							'args' => array(
								'description' => __( 'Crop arguments.' ),
								'type'        => 'object',
								'required'    => array(
									'left',
									'top',
									'width',
									'height',
								),
								'properties'  => array(
									'left'   => array(
										'description' => __( 'Horizontal position from the left to begin the crop as a percentage of the image width.' ),
										'type'        => 'number',
									),
									'top'    => array(
										'description' => __( 'Vertical position from the top to begin the crop as a percentage of the image height.' ),
										'type'        => 'number',
									),
									'width'  => array(
										'description' => __( 'Width of the crop as a percentage of the image width.' ),
										'type'        => 'number',
									),
									'height' => array(
										'description' => __( 'Height of the crop as a percentage of the image height.' ),
										'type'        => 'number',
									),
								),
							),
						),
					),
				),
			),
		),
		'rotation'  => array(
			'description'      => __( 'The amount to rotate the image clockwise in degrees. DEPRECATED: Use `modifiers` instead.' ),
			'type'             => 'integer',
			'minimum'          => 0,
			'exclusiveMinimum' => true,
			'maximum'          => 360,
			'exclusiveMaximum' => true,
		),
		'x'         => array(
			'description' => __( 'As a percentage of the image, the x position to start the crop from. DEPRECATED: Use `modifiers` instead.' ),
			'type'        => 'number',
			'minimum'     => 0,
			'maximum'     => 100,
		),
		'y'         => array(
			'description' => __( 'As a percentage of the image, the y position to start the crop from. DEPRECATED: Use `modifiers` instead.' ),
			'type'        => 'number',
			'minimum'     => 0,
			'maximum'     => 100,
		),
		'width'     => array(
			'description' => __( 'As a percentage of the image, the width to crop the image to. DEPRECATED: Use `modifiers` instead.' ),
			'type'        => 'number',
			'minimum'     => 0,
			'maximum'     => 100,
		),
		'height'    => array(
			'description' => __( 'As a percentage of the image, the height to crop the image to. DEPRECATED: Use `modifiers` instead.' ),
			'type'        => 'number',
			'minimum'     => 0,
			'maximum'     => 100,
		),
	);

	/*
	 * Get the args based on the post schema. This calls `rest_get_endpoint_args_for_schema()`,
	 * which also takes care of sanitization and validation.
	 */
	$update_item_args = $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE );

	if ( isset( $update_item_args['caption'] ) ) {
		$args['caption'] = $update_item_args['caption'];
	}

	if ( isset( $update_item_args['description'] ) ) {
		$args['description'] = $update_item_args['description'];
	}

	if ( isset( $update_item_args['title'] ) ) {
		$args['title'] = $update_item_args['title'];
	}

	if ( isset( $update_item_args['post'] ) ) {
		$args['post'] = $update_item_args['post'];
	}

	if ( isset( $update_item_args['alt_text'] ) ) {
		$args['alt_text'] = $update_item_args['alt_text'];
	}

	return $args;
}

Changelog

VersionDescription
6.9.0Adds flips capability and editable fields for the newly-created attachment post.
5.5.0Introduced.

User Contributed Notes

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