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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / admin / class-wc-admin-importers.php
woocommerce / includes / admin Last commit date
helper 2 months ago importers 1 year ago list-tables 1 month ago marketplace-suggestions 11 months ago meta-boxes 1 month ago notes 2 months ago plugin-updates 2 years ago reports 3 months ago settings 1 week ago views 1 month ago class-wc-admin-addons.php 9 months ago class-wc-admin-api-keys-table-list.php 2 years ago class-wc-admin-api-keys.php 11 months ago class-wc-admin-assets.php 1 month ago class-wc-admin-attributes.php 1 month ago class-wc-admin-brands.php 4 months ago class-wc-admin-customize.php 5 years ago class-wc-admin-dashboard-setup.php 1 month ago class-wc-admin-dashboard.php 4 months ago class-wc-admin-duplicate-product.php 5 months ago class-wc-admin-exporters.php 1 year ago class-wc-admin-help.php 2 years ago class-wc-admin-importers.php 11 months ago class-wc-admin-log-table-list.php 4 months ago class-wc-admin-marketplace-promotions.php 4 months ago class-wc-admin-menus.php 1 month ago class-wc-admin-meta-boxes.php 1 month ago class-wc-admin-notices.php 1 month ago class-wc-admin-permalink-settings.php 5 years ago class-wc-admin-pointers.php 3 years ago class-wc-admin-post-types.php 1 year ago class-wc-admin-profile.php 1 year ago class-wc-admin-reports.php 4 months ago class-wc-admin-settings.php 3 months ago class-wc-admin-setup-wizard.php 1 month ago class-wc-admin-status.php 1 year ago class-wc-admin-taxonomies.php 1 month ago class-wc-admin-upload-downloadable-product.php 2 years ago class-wc-admin-webhooks-table-list.php 1 month ago class-wc-admin-webhooks.php 1 month ago class-wc-admin.php 3 months ago wc-admin-functions.php 7 months ago wc-meta-box-functions.php 1 year ago woocommerce-legacy-reports.php 1 year ago
class-wc-admin-importers.php
271 lines
1 <?php //phpcs:ignore Generic.PHP.RequireStrictTypes.MissingDeclaration
2 /**
3 * Init WooCommerce data importers.
4 *
5 * @package WooCommerce\Admin
6 */
7
8 use Automattic\Jetpack\Constants;
9 use Automattic\WooCommerce\Internal\Integrations\WPPostsImporter;
10
11 defined( 'ABSPATH' ) || exit;
12
13 /**
14 * WC_Admin_Importers Class.
15 */
16 class WC_Admin_Importers {
17
18 /**
19 * Array of importer IDs.
20 *
21 * @var string[]
22 */
23 protected $importers = array();
24
25 /**
26 * Constructor.
27 */
28 public function __construct() {
29 if ( ! $this->import_allowed() ) {
30 return;
31 }
32
33 add_action( 'admin_menu', array( $this, 'add_to_menus' ) );
34 add_action( 'admin_init', array( $this, 'register_importers' ) );
35 add_action( 'admin_head', array( $this, 'hide_from_menus' ) );
36 add_action( 'admin_head', array( $this, 'menu_highlight_for_product_import' ) );
37 add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
38 add_action( 'wp_ajax_woocommerce_do_ajax_product_import', array( $this, 'do_ajax_product_import' ) );
39 add_action( 'in_admin_footer', array( $this, 'track_importer_exporter_view' ) );
40
41 /**
42 * Register the WP Posts importer.
43 */
44 $wp_posts_importer = wc_get_container()->get( WPPostsImporter::class );
45 $wp_posts_importer->register();
46
47 // Register WooCommerce importers.
48 $this->importers['product_importer'] = array(
49 'menu' => 'edit.php?post_type=product',
50 'name' => __( 'Product Import', 'woocommerce' ),
51 'capability' => 'import',
52 'callback' => array( $this, 'product_importer' ),
53 );
54 }
55
56 /**
57 * Return true if WooCommerce imports are allowed for current user, false otherwise.
58 *
59 * @return bool Whether current user can perform imports.
60 */
61 protected function import_allowed() {
62 return current_user_can( 'edit_products' ) && current_user_can( 'import' );
63 }
64
65 /**
66 * Add menu items for our custom importers.
67 */
68 public function add_to_menus() {
69 foreach ( $this->importers as $id => $importer ) {
70 add_submenu_page( $importer['menu'], $importer['name'], $importer['name'], $importer['capability'], $id, $importer['callback'] );
71 }
72 }
73
74 /**
75 * Hide menu items from view so the pages exist, but the menu items do not.
76 */
77 public function hide_from_menus() {
78 global $submenu;
79
80 foreach ( $this->importers as $id => $importer ) {
81 if ( isset( $submenu[ $importer['menu'] ] ) ) {
82 foreach ( $submenu[ $importer['menu'] ] as $key => $menu ) {
83 if ( $id === $menu[2] ) {
84 unset( $submenu[ $importer['menu'] ][ $key ] );
85 }
86 }
87 }
88 }
89 }
90
91 /**
92 * Highlight Products > All Products submenu for Product Importer.
93 */
94 public function menu_highlight_for_product_import() {
95 global $submenu_file;
96
97 $screen = get_current_screen();
98
99 if ( $screen && 'product_page_product_importer' === $screen->id ) {
100 $submenu_file = 'edit.php?post_type=product'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
101 }
102 }
103
104 /**
105 * Register importer scripts.
106 */
107 public function admin_scripts() {
108 $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min';
109 $version = Constants::get_constant( 'WC_VERSION' );
110 wp_register_script( 'wc-product-import', WC()->plugin_url() . '/assets/js/admin/wc-product-import' . $suffix . '.js', array( 'jquery' ), $version, true );
111 }
112
113 /**
114 * The product importer.
115 *
116 * This has a custom screen - the Tools > Import item is a placeholder.
117 * If we're on that screen, redirect to the custom one.
118 */
119 public function product_importer() {
120 if ( Constants::is_defined( 'WP_LOAD_IMPORTERS' ) ) {
121 wp_safe_redirect( admin_url( 'edit.php?post_type=product&page=product_importer&source=wordpress-importer' ) );
122 exit;
123 }
124
125 // phpcs:ignore
126 if ( isset( $_GET['source'] ) && 'wordpress-importer' === sanitize_text_field( wp_unslash( $_GET['source'] ) ) ) {
127 wc_admin_record_tracks_event( 'product_importer_view_from_wp_importer' );
128 }
129
130 include_once WC_ABSPATH . 'includes/import/class-wc-product-csv-importer.php';
131 include_once WC_ABSPATH . 'includes/admin/importers/class-wc-product-csv-importer-controller.php';
132
133 $importer = new WC_Product_CSV_Importer_Controller();
134 $importer->dispatch();
135 }
136
137 /**
138 * Register WordPress based importers.
139 */
140 public function register_importers() {
141 if ( Constants::is_defined( 'WP_LOAD_IMPORTERS' ) ) {
142 register_importer( 'woocommerce_product_csv', __( 'WooCommerce products (CSV)', 'woocommerce' ), __( 'Import <strong>products</strong> to your store via a csv file.', 'woocommerce' ), array( $this, 'product_importer' ) );
143 register_importer( 'woocommerce_tax_rate_csv', __( 'WooCommerce tax rates (CSV)', 'woocommerce' ), __( 'Import <strong>tax rates</strong> to your store via a csv file.', 'woocommerce' ), array( $this, 'tax_rates_importer' ) );
144 }
145 }
146
147 /**
148 * The tax rate importer which extends WP_Importer.
149 */
150 public function tax_rates_importer() {
151 require_once ABSPATH . 'wp-admin/includes/import.php';
152
153 if ( ! class_exists( 'WP_Importer' ) ) {
154 $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
155
156 if ( file_exists( $class_wp_importer ) ) {
157 require $class_wp_importer;
158 }
159 }
160
161 wc_admin_record_tracks_event( 'tax_rates_importer_view_from_wp_importer' );
162
163 require __DIR__ . '/importers/class-wc-tax-rate-importer.php';
164
165 $importer = new WC_Tax_Rate_Importer();
166 $importer->dispatch();
167 }
168
169 /**
170 * When running the WP XML importer, ensure attributes exist.
171 *
172 * WordPress import should work - however, it fails to import custom product attribute taxonomies.
173 * This code grabs the file before it is imported and ensures the taxonomies are created.
174 */
175 public function post_importer_compatibility() {
176 wc_deprecated_function( 'post_importer_compatibility', '10.1.0', 'A new integration with the WP WXR importer now filters the posts during import and registers the taxonomies, instead of initializing them at the start of the import and having to re-parse the file.' );
177
178 // phpcs:ignore WordPress.Security.NonceVerification.Missing
179 if ( empty( $_POST['import_id'] ) || ! class_exists( 'WXR_Parser' ) ) {
180 return;
181 }
182
183 // phpcs:ignore WordPress.Security.NonceVerification.Missing
184 $id = absint( $_POST['import_id'] );
185 $file = get_attached_file( $id );
186 $parser = new WXR_Parser();
187 $import_data = $parser->parse( $file );
188
189 if ( isset( $import_data['posts'] ) && ! empty( $import_data['posts'] ) ) {
190 foreach ( $import_data['posts'] as $post ) {
191 if ( 'product' === $post['post_type'] && ! empty( $post['terms'] ) ) {
192 foreach ( $post['terms'] as $term ) {
193 if ( strstr( $term['domain'], 'pa_' ) ) {
194 if ( ! taxonomy_exists( $term['domain'] ) ) {
195 $attribute_name = wc_attribute_taxonomy_slug( $term['domain'] );
196
197 // Create the taxonomy.
198 if ( ! in_array( $attribute_name, wc_get_attribute_taxonomies(), true ) ) {
199 wc_create_attribute(
200 array(
201 'name' => $attribute_name,
202 'slug' => $attribute_name,
203 'type' => 'select',
204 'order_by' => 'menu_order',
205 'has_archives' => false,
206 )
207 );
208 }
209
210 // Register the taxonomy now so that the import works!
211 register_taxonomy(
212 $term['domain'],
213 // phpcs:ignore
214 apply_filters( 'woocommerce_taxonomy_objects_' . $term['domain'], array( 'product' ) ),
215 // phpcs:ignore
216 apply_filters(
217 'woocommerce_taxonomy_args_' . $term['domain'],
218 array(
219 'hierarchical' => true,
220 'show_ui' => false,
221 'query_var' => true,
222 'rewrite' => false,
223 )
224 )
225 );
226 }
227 }
228 }
229 }
230 }
231 }
232 }
233
234 /**
235 * Ajax callback for importing one batch of products from a CSV.
236 */
237 public function do_ajax_product_import() {
238 if ( ! $this->import_allowed() ) {
239 wp_send_json_error( array( 'message' => __( 'Insufficient privileges to import products.', 'woocommerce' ) ) );
240 }
241
242 include_once WC_ABSPATH . 'includes/admin/importers/class-wc-product-csv-importer-controller.php';
243 WC_Product_CSV_Importer_Controller::dispatch_ajax();
244 }
245
246 /**
247 * Track importer/exporter view.
248 *
249 * @return void
250 */
251 public function track_importer_exporter_view() {
252 $screen = get_current_screen();
253
254 if ( ! isset( $screen->id ) ) {
255 return;
256 }
257
258 // Don't track if we're in a specific import screen.
259 // phpcs:ignore
260 if ( isset( $_GET['import'] ) ) {
261 return;
262 }
263
264 if ( 'import' === $screen->id || 'export' === $screen->id ) {
265 wc_admin_record_tracks_event( 'wordpress_' . $screen->id . '_view' );
266 }
267 }
268 }
269
270 new WC_Admin_Importers();
271