Merge pull request #15811 from danielhuesken/fix_importer_filtype
Importer fix file type detection on local path
This commit is contained in:
commit
f6240a1626
|
@ -228,19 +228,19 @@ class WC_Product_CSV_Importer_Controller {
|
||||||
* @return string|WP_Error
|
* @return string|WP_Error
|
||||||
*/
|
*/
|
||||||
public function handle_upload() {
|
public function handle_upload() {
|
||||||
$valid_filetypes = apply_filters( 'woocommerce_csv_product_import_valid_filetypes', array( 'text/csv', 'text/plain' ) );
|
$valid_filetypes = apply_filters( 'woocommerce_csv_product_import_valid_filetypes', array( 'csv' => 'text/csv', 'txt' => 'text/plain' ) );
|
||||||
|
|
||||||
if ( empty( $_POST['file_url'] ) ) {
|
if ( empty( $_POST['file_url'] ) ) {
|
||||||
if ( ! isset( $_FILES['import'] ) ) {
|
if ( ! isset( $_FILES['import'] ) ) {
|
||||||
return new WP_Error( 'woocommerce_product_csv_importer_upload_file_empty', __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.', 'woocommerce' ) );
|
return new WP_Error( 'woocommerce_product_csv_importer_upload_file_empty', __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.', 'woocommerce' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! in_array( $_FILES['import']['type'], $valid_filetypes ) ) {
|
$filetype = wp_check_filetype( $_FILES['import']['name'], $valid_filetypes );
|
||||||
|
if ( ! in_array( $filetype['type'], $valid_filetypes ) ) {
|
||||||
return new WP_Error( 'woocommerce_product_csv_importer_upload_file_invalid', __( 'Invalid file type. The importer supports CSV and TXT file formats.', 'woocommerce' ) );
|
return new WP_Error( 'woocommerce_product_csv_importer_upload_file_invalid', __( 'Invalid file type. The importer supports CSV and TXT file formats.', 'woocommerce' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$overrides = array( 'test_form' => false, 'test_type' => false );
|
$overrides = array( 'test_form' => false, 'mimes' => $valid_filetypes );
|
||||||
$_FILES['import']['name'] .= '.txt';
|
|
||||||
$upload = wp_handle_upload( $_FILES['import'], $overrides );
|
$upload = wp_handle_upload( $_FILES['import'], $overrides );
|
||||||
|
|
||||||
if ( isset( $upload['error'] ) ) {
|
if ( isset( $upload['error'] ) ) {
|
||||||
|
@ -268,7 +268,7 @@ class WC_Product_CSV_Importer_Controller {
|
||||||
|
|
||||||
return $upload['file'];
|
return $upload['file'];
|
||||||
} elseif ( file_exists( ABSPATH . $_POST['file_url'] ) ) {
|
} elseif ( file_exists( ABSPATH . $_POST['file_url'] ) ) {
|
||||||
$filetype = wp_check_filetype( ABSPATH . $_POST['file_url'] );
|
$filetype = wp_check_filetype( ABSPATH . $_POST['file_url'], $valid_filetypes );
|
||||||
if ( ! in_array( $filetype['type'], $valid_filetypes ) ) {
|
if ( ! in_array( $filetype['type'], $valid_filetypes ) ) {
|
||||||
return new WP_Error( 'woocommerce_product_csv_importer_upload_file_invalid', __( 'Invalid file type. The importer supports CSV and TXT file formats.', 'woocommerce' ) );
|
return new WP_Error( 'woocommerce_product_csv_importer_upload_file_invalid', __( 'Invalid file type. The importer supports CSV and TXT file formats.', 'woocommerce' ) );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue