Check if file ID is not empty and exists

Closes #21587
This commit is contained in:
Claudio Sanches 2018-10-16 13:01:51 -03:00
parent df55670bf0
commit 00c1a9016a
4 changed files with 4 additions and 4 deletions

View File

@ -1532,7 +1532,7 @@ class WC_API_Products extends WC_API_Resource {
} }
$download = new WC_Product_Download(); $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_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 ) ); $download->set_file( apply_filters( 'woocommerce_file_download_path', $file['file'], $product, $key ) );
$files[] = $download; $files[] = $download;

View File

@ -2036,7 +2036,7 @@ class WC_API_Products extends WC_API_Resource {
} }
$download = new WC_Product_Download(); $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_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 ) ); $download->set_file( apply_filters( 'woocommerce_file_download_path', $file['file'], $product, $key ) );
$files[] = $download; $files[] = $download;

View File

@ -960,7 +960,7 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller {
} }
$download = new WC_Product_Download(); $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_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 ) ); $download->set_file( apply_filters( 'woocommerce_file_download_path', $file['file'], $product, $key ) );
$files[] = $download; $files[] = $download;

View File

@ -1196,7 +1196,7 @@ class WC_REST_Products_V2_Controller extends WC_REST_Legacy_Products_Controller
} }
$download = new WC_Product_Download(); $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_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 ) ); $download->set_file( apply_filters( 'woocommerce_file_download_path', $file['file'], $product, $key ) );
$files[] = $download; $files[] = $download;