| 1 |
<?php |
| 2 |
|
| 3 |
namespace LIBRARY; |
| 4 |
|
| 5 |
class WXRImporter extends \AwesomeMotive\WPContentImporter2\WXRImporter { |
| 6 |
|
| 7 |
public function __construct( $options = array() ) { |
| 8 |
parent::__construct( $options ); |
| 9 |
$current_user_obj = wp_get_current_user(); |
| 10 |
$this->mapping['user_slug'][ $current_user_obj->user_login ] = $current_user_obj->ID; |
| 11 |
|
| 12 |
if ( class_exists( 'WooCommerce' ) ) { |
| 13 |
add_filter( 'wxr_importer.pre_process.term', array( $this, 'woocommerce_product_attributes_registration' ), 10, 1 ); |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
public function get_importer_data() { |
| 18 |
return array( |
| 19 |
'mapping' => $this->mapping, |
| 20 |
'requires_remapping' => $this->requires_remapping, |
| 21 |
'exists' => $this->exists, |
| 22 |
'user_slug_override' => $this->user_slug_override, |
| 23 |
'url_remap' => $this->url_remap, |
| 24 |
'featured_images' => $this->featured_images, |
| 25 |
); |
| 26 |
} |
| 27 |
|
| 28 |
public function set_importer_data( $data ) { |
| 29 |
$this->mapping = empty( $data['mapping'] ) ? array() : $data['mapping']; |
| 30 |
$this->requires_remapping = empty( $data['requires_remapping'] ) ? array() : $data['requires_remapping']; |
| 31 |
$this->exists = empty( $data['exists'] ) ? array() : $data['exists']; |
| 32 |
$this->user_slug_override = empty( $data['user_slug_override'] ) ? array() : $data['user_slug_override']; |
| 33 |
$this->url_remap = empty( $data['url_remap'] ) ? array() : $data['url_remap']; |
| 34 |
$this->featured_images = empty( $data['featured_images'] ) ? array() : $data['featured_images']; |
| 35 |
} |
| 36 |
|
| 37 |
public function woocommerce_product_attributes_registration( $data ) { |
| 38 |
global $wpdb; |
| 39 |
|
| 40 |
if ( strstr( $data['taxonomy'], 'pa_' ) ) { |
| 41 |
if ( ! taxonomy_exists( $data['taxonomy'] ) ) { |
| 42 |
$attribute_name = wc_sanitize_taxonomy_name( str_replace( 'pa_', '', $data['taxonomy'] ) ); |
| 43 |
|
| 44 |
if ( ! in_array( $attribute_name, wc_get_attribute_taxonomies() ) ) { |
| 45 |
$attribute = array( |
| 46 |
'attribute_label' => $attribute_name, |
| 47 |
'attribute_name' => $attribute_name, |
| 48 |
'attribute_type' => 'select', |
| 49 |
'attribute_orderby' => 'menu_order', |
| 50 |
'attribute_public' => 0 |
| 51 |
); |
| 52 |
$wpdb->insert( $wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute ); |
| 53 |
delete_transient( 'wc_attribute_taxonomies' ); |
| 54 |
} |
| 55 |
|
| 56 |
register_taxonomy( |
| 57 |
$data['taxonomy'], |
| 58 |
apply_filters( 'woocommerce_taxonomy_objects_' . $data['taxonomy'], array( 'product' ) ), |
| 59 |
apply_filters( 'woocommerce_taxonomy_args_' . $data['taxonomy'], array( |
| 60 |
'hierarchical' => true, |
| 61 |
'show_ui' => false, |
| 62 |
'query_var' => true, |
| 63 |
'rewrite' => false, |
| 64 |
) ) |
| 65 |
); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
return $data; |
| 70 |
} |
| 71 |
} |
| 72 |
|