Automattic\WooCommerce\Internal\RestApi\Routes\V4\Products
Controller::create_item
Create a single item. Handles cleanup of orphaned images if product creation fails.
Method of the class: Controller{}
No Hooks.
Returns
WP_REST_Response|WP_Error. Response object on success, or WP_Error object on failure.
Usage
$Controller = new Controller(); $Controller->create_item( $request );
- $request(WP_REST_Request) (required)
- Request object.
Controller::create_item() Controller::create item code WC 10.4.3
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;
}