WC_REST_Products_Controller::create_itempublicWC 1.0

Create a single item. Handles cleanup of orphaned images if product creation fails.

Method of the class: WC_REST_Products_Controller{}

No Hooks.

Returns

WP_REST_Response|WP_Error. Response object on success, or WP_Error object on failure.

Usage

$WC_REST_Products_Controller = new WC_REST_Products_Controller();
$WC_REST_Products_Controller->create_item( $request );
$request(WP_REST_Request) (required)
Request object.

WC_REST_Products_Controller::create_item() code WC 10.3.6

public function create_item( $request ) {
	$this->processed_attachment_ids_for_request = array();

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

	if ( is_wp_error( $response ) ) {
		if ( ! empty( $this->processed_attachment_ids_for_request ) ) {
			// Handle deletion of orphaned images.
			foreach ( $this->processed_attachment_ids_for_request as $attachment_id ) {
				wp_delete_attachment( (int) $attachment_id, true );
			}
		}
	}

	$this->processed_attachment_ids_for_request = array();

	return $response;
}