WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_REST_Attachments_Controller::update_item() public WP 4.7.0

Updates a single attachment.

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

Хуки из метода
Возвращает

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) (обязательный)
Full details about the request.

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

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

Код WP_REST_Attachments_Controller::update_item() WP 5.5.3

<?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;
}