From 3c164427caa4751ede84ec2d055a10f7c650b2e1 Mon Sep 17 00:00:00 2001 From: Taylor Lovett Date: Fri, 9 Sep 2016 22:41:41 -0400 Subject: [PATCH 1/2] Add filter to continue uploading images if one fails (api) --- includes/api/class-wc-rest-products-controller.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/api/class-wc-rest-products-controller.php b/includes/api/class-wc-rest-products-controller.php index faca353871c..c6a109dad61 100644 --- a/includes/api/class-wc-rest-products-controller.php +++ b/includes/api/class-wc-rest-products-controller.php @@ -754,7 +754,9 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller { $upload = wc_rest_upload_image_from_url( esc_url_raw( $image['src'] ) ); if ( is_wp_error( $upload ) ) { - throw new WC_REST_Exception( 'woocommerce_product_image_upload_error', $upload->get_error_message(), 400 ); + if ( ! apply_filters( 'woocommerce_rest_suppress_image_upload_error', false, $upload, $product_id, $images ) ) { + throw new WC_REST_Exception( 'woocommerce_product_image_upload_error', $upload->get_error_message(), 400 ); + } } $attachment_id = wc_rest_set_uploaded_image_as_attachment( $upload, $product_id ); From 6eae03c6df4c81aa84a797c843be84f07603cd34 Mon Sep 17 00:00:00 2001 From: Taylor Lovett Date: Fri, 9 Sep 2016 23:49:45 -0400 Subject: [PATCH 2/2] Make sure to continue to next image on error --- includes/api/class-wc-rest-products-controller.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/api/class-wc-rest-products-controller.php b/includes/api/class-wc-rest-products-controller.php index c6a109dad61..4367fb6f394 100644 --- a/includes/api/class-wc-rest-products-controller.php +++ b/includes/api/class-wc-rest-products-controller.php @@ -756,6 +756,8 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller { if ( is_wp_error( $upload ) ) { if ( ! apply_filters( 'woocommerce_rest_suppress_image_upload_error', false, $upload, $product_id, $images ) ) { throw new WC_REST_Exception( 'woocommerce_product_image_upload_error', $upload->get_error_message(), 400 ); + } else { + continue; } }