WordPress at a glance
функция не описана

WP_REST_Attachments_Controller::update_item() public WP 4.7.0

Updates a single attachment.

It's a method of the class: WP_REST_Attachments_Controller{}

Hooks from the method
Возвращает

WP_REST_Response/WP_Error. Response object on success, WP_Error object on failure.

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

$WP_REST_Attachments_Controller = new WP_REST_Attachments_Controller();
$WP_REST_Attachments_Controller->update_item( $request );
$request(WP_REST_Request) (required)
Full details about the request.

Changelog

Since 4.7.0 Introduced.

Код WP_REST_Attachments_Controller::update_item() WP 5.5.1

<?php
public function update_item( $request ) {
	if ( ! empty( $request['post'] ) && in_array( get_post_type( $request['post'] ), array( 'revision', 'attachment' ), true ) ) {
		return new WP_Error(
			'rest_invalid_param',
			__( 'Invalid parent type.' ),
			array( 'status' => 400 )
		);
	}

	$response = parent::update_item( $request );

	if ( is_wp_error( $response ) ) {
		return $response;
	}

	$response = rest_ensure_response( $response );
	$data     = $response->get_data();

	if ( isset( $request['alt_text'] ) ) {
		update_post_meta( $data['id'], '_wp_attachment_image_alt', $request['alt_text'] );
	}

	$attachment = get_post( $request['id'] );

	$fields_update = $this->update_additional_fields_for_object( $attachment, $request );

	if ( is_wp_error( $fields_update ) ) {
		return $fields_update;
	}

	$request->set_param( 'context', 'edit' );

	/** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php */
	do_action( 'rest_after_insert_attachment', $attachment, $request, false );

	$response = $this->prepare_item_for_response( $attachment, $request );
	$response = rest_ensure_response( $response );

	return $response;
}