Abort if we have no mapping data

This commit is contained in:
Mike Jolley 2017-05-19 14:59:05 +01:00
parent aeb3234ec6
commit e860a8d307
1 changed files with 9 additions and 4 deletions

View File

@ -222,11 +222,16 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
'/Download * URL/' => 'esc_url',
);
$headers = ! empty( $this->mapped_keys ) ? $this->mapped_keys : $this->raw_keys;
$parse_functions = array();
$parse_functions = array();
$this->parsed_data = array();
// If we have no mapped data, abort.
if ( empty( $this->mapped_keys ) ) {
return;
}
// Figure out the parse function for each column.
foreach ( $headers as $index => $heading ) {
foreach ( $this->mapped_keys as $index => $heading ) {
$parse_function = 'esc_attr';
if ( isset( $data_formatting[ $heading ] ) ) {
@ -247,7 +252,7 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
foreach ( $this->raw_data as $row ) {
$item = array();
foreach ( $row as $index => $field ) {
$item[ $headers[ $index ] ] = call_user_func( $parse_functions[ $index ], $field );
$item[ $this->mapped_keys[ $index ] ] = call_user_func( $parse_functions[ $index ], $field );
}
$this->parsed_data[] = $item;
}