From 00c1a9016a01015880c9c6ddfb2ea9ceddb16c84 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 16 Oct 2018 13:01:51 -0300 Subject: [PATCH] Check if file ID is not empty and exists Closes #21587 --- includes/api/legacy/v2/class-wc-api-products.php | 2 +- includes/api/legacy/v3/class-wc-api-products.php | 2 +- includes/api/v1/class-wc-rest-products-controller.php | 2 +- includes/api/v2/class-wc-rest-products-v2-controller.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/api/legacy/v2/class-wc-api-products.php b/includes/api/legacy/v2/class-wc-api-products.php index 0da071ccb15..bfc75184b63 100644 --- a/includes/api/legacy/v2/class-wc-api-products.php +++ b/includes/api/legacy/v2/class-wc-api-products.php @@ -1532,7 +1532,7 @@ class WC_API_Products extends WC_API_Resource { } $download = new WC_Product_Download(); - $download->set_id( $file['id'] ? $file['id'] : wp_generate_uuid4() ); + $download->set_id( ! empty( $file['id'] ) ? $file['id'] : wp_generate_uuid4() ); $download->set_name( $file['name'] ? $file['name'] : wc_get_filename_from_url( $file['file'] ) ); $download->set_file( apply_filters( 'woocommerce_file_download_path', $file['file'], $product, $key ) ); $files[] = $download; diff --git a/includes/api/legacy/v3/class-wc-api-products.php b/includes/api/legacy/v3/class-wc-api-products.php index 71062b2820d..d8d02d0df1d 100644 --- a/includes/api/legacy/v3/class-wc-api-products.php +++ b/includes/api/legacy/v3/class-wc-api-products.php @@ -2036,7 +2036,7 @@ class WC_API_Products extends WC_API_Resource { } $download = new WC_Product_Download(); - $download->set_id( $file['id'] ? $file['id'] : wp_generate_uuid4() ); + $download->set_id( ! empty( $file['id'] ) ? $file['id'] : wp_generate_uuid4() ); $download->set_name( $file['name'] ? $file['name'] : wc_get_filename_from_url( $file['file'] ) ); $download->set_file( apply_filters( 'woocommerce_file_download_path', $file['file'], $product, $key ) ); $files[] = $download; diff --git a/includes/api/v1/class-wc-rest-products-controller.php b/includes/api/v1/class-wc-rest-products-controller.php index 9d893f039c8..89bec84e489 100644 --- a/includes/api/v1/class-wc-rest-products-controller.php +++ b/includes/api/v1/class-wc-rest-products-controller.php @@ -960,7 +960,7 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller { } $download = new WC_Product_Download(); - $download->set_id( $file['id'] ? $file['id'] : wp_generate_uuid4() ); + $download->set_id( ! empty( $file['id'] ) ? $file['id'] : wp_generate_uuid4() ); $download->set_name( $file['name'] ? $file['name'] : wc_get_filename_from_url( $file['file'] ) ); $download->set_file( apply_filters( 'woocommerce_file_download_path', $file['file'], $product, $key ) ); $files[] = $download; diff --git a/includes/api/v2/class-wc-rest-products-v2-controller.php b/includes/api/v2/class-wc-rest-products-v2-controller.php index 1ed1c1e0acc..60b86a36b9a 100644 --- a/includes/api/v2/class-wc-rest-products-v2-controller.php +++ b/includes/api/v2/class-wc-rest-products-v2-controller.php @@ -1196,7 +1196,7 @@ class WC_REST_Products_V2_Controller extends WC_REST_Legacy_Products_Controller } $download = new WC_Product_Download(); - $download->set_id( $file['id'] ? $file['id'] : wp_generate_uuid4() ); + $download->set_id( ! empty( $file['id'] ) ? $file['id'] : wp_generate_uuid4() ); $download->set_name( $file['name'] ? $file['name'] : wc_get_filename_from_url( $file['file'] ) ); $download->set_file( apply_filters( 'woocommerce_file_download_path', $file['file'], $product, $key ) ); $files[] = $download;