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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-exporters.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-exporters.php
245 lines
1 <?php
2 /**
3 * Init WooCommerce data exporters.
4 *
5 * @package WooCommerce\Admin
6 * @version x.x.x
7 */
8
9 use Automattic\Jetpack\Constants;
10 use Automattic\WooCommerce\Enums\ProductType;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 /**
17 * WC_Admin_Exporters Class.
18 */
19 class WC_Admin_Exporters {
20
21 /**
22 * Array of exporter IDs.
23 *
24 * @var string[]
25 */
26 protected $exporters = array();
27
28 /**
29 * Constructor.
30 */
31 public function __construct() {
32 if ( ! $this->export_allowed() ) {
33 return;
34 }
35
36 add_action( 'admin_menu', array( $this, 'add_to_menus' ) );
37 add_action( 'admin_head', array( $this, 'hide_from_menus' ) );
38 add_action( 'admin_head', array( $this, 'menu_highlight_for_product_export' ) );
39 add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
40 add_action( 'admin_init', array( $this, 'download_export_file' ) );
41 add_action( 'wp_ajax_woocommerce_do_ajax_product_export', array( $this, 'do_ajax_product_export' ) );
42
43 // Register WooCommerce exporters.
44 $this->exporters['product_exporter'] = array(
45 'menu' => 'edit.php?post_type=product',
46 'name' => __( 'Product Export', 'woocommerce' ),
47 'capability' => 'export',
48 'callback' => array( $this, 'product_exporter' ),
49 );
50 }
51
52 /**
53 * Return true if WooCommerce export is allowed for current user, false otherwise.
54 *
55 * @return bool Whether current user can perform export.
56 */
57 protected function export_allowed() {
58 return current_user_can( 'edit_products' ) && current_user_can( 'export' );
59 }
60
61 /**
62 * Add menu items for our custom exporters.
63 */
64 public function add_to_menus() {
65 foreach ( $this->exporters as $id => $exporter ) {
66 add_submenu_page( $exporter['menu'], $exporter['name'], $exporter['name'], $exporter['capability'], $id, $exporter['callback'] );
67 }
68 }
69
70 /**
71 * Hide menu items from view so the pages exist, but the menu items do not.
72 */
73 public function hide_from_menus() {
74 global $submenu;
75
76 foreach ( $this->exporters as $id => $exporter ) {
77 if ( isset( $submenu[ $exporter['menu'] ] ) ) {
78 foreach ( $submenu[ $exporter['menu'] ] as $key => $menu ) {
79 if ( $id === $menu[2] ) {
80 unset( $submenu[ $exporter['menu'] ][ $key ] );
81 }
82 }
83 }
84 }
85 }
86
87 /**
88 * Highlight Products > All Products submenu for Product Exporter.
89 */
90 public function menu_highlight_for_product_export() {
91 global $submenu_file;
92
93 $screen = get_current_screen();
94
95 if ( $screen && 'product_page_product_exporter' === $screen->id ) {
96 $submenu_file = 'edit.php?post_type=product'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
97 }
98 }
99
100 /**
101 * Enqueue scripts.
102 */
103 public function admin_scripts() {
104 $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min';
105 $version = Constants::get_constant( 'WC_VERSION' );
106 wp_register_script( 'wc-product-export', WC()->plugin_url() . '/assets/js/admin/wc-product-export' . $suffix . '.js', array( 'jquery' ), $version );
107 wp_localize_script(
108 'wc-product-export',
109 'wc_product_export_params',
110 array(
111 'export_nonce' => wp_create_nonce( 'wc-product-export' ),
112 )
113 );
114 }
115
116 /**
117 * Export page UI.
118 */
119 public function product_exporter() {
120 include_once WC_ABSPATH . 'includes/export/class-wc-product-csv-exporter.php';
121 include_once dirname( __FILE__ ) . '/views/html-admin-page-product-export.php';
122 }
123
124 /**
125 * Serve the generated file.
126 */
127 public function download_export_file() {
128 if ( isset( $_GET['action'], $_GET['nonce'] ) && wp_verify_nonce( wp_unslash( $_GET['nonce'] ), 'product-csv' ) && 'download_product_csv' === wp_unslash( $_GET['action'] ) ) { // WPCS: input var ok, sanitization ok.
129 include_once WC_ABSPATH . 'includes/export/class-wc-product-csv-exporter.php';
130 $exporter = new WC_Product_CSV_Exporter();
131
132 if ( ! empty( $_GET['filename'] ) ) { // WPCS: input var ok.
133 $exporter->set_filename( wp_unslash( $_GET['filename'] ) ); // WPCS: input var ok, sanitization ok.
134 }
135
136 $exporter->export();
137 }
138 }
139
140 /**
141 * AJAX callback for doing the actual export to the CSV file.
142 */
143 public function do_ajax_product_export() {
144 check_ajax_referer( 'wc-product-export', 'security' );
145
146 if ( ! $this->export_allowed() ) {
147 wp_send_json_error( array( 'message' => __( 'Insufficient privileges to export products.', 'woocommerce' ) ) );
148 }
149
150 include_once WC_ABSPATH . 'includes/export/class-wc-product-csv-exporter.php';
151
152 $step = isset( $_POST['step'] ) ? absint( $_POST['step'] ) : 1; // WPCS: input var ok, sanitization ok.
153 $exporter = new WC_Product_CSV_Exporter();
154
155 if ( ! empty( $_POST['columns'] ) ) { // WPCS: input var ok.
156 $exporter->set_column_names( wp_unslash( $_POST['columns'] ) ); // WPCS: input var ok, sanitization ok.
157 }
158
159 if ( ! empty( $_POST['selected_columns'] ) ) { // WPCS: input var ok.
160 $exporter->set_columns_to_export( wp_unslash( $_POST['selected_columns'] ) ); // WPCS: input var ok, sanitization ok.
161 }
162
163 if ( ! empty( $_POST['export_meta'] ) ) { // WPCS: input var ok.
164 $exporter->enable_meta_export( true );
165 }
166
167 if ( ! empty( $_POST['export_types'] ) ) { // WPCS: input var ok.
168 $exporter->set_product_types_to_export( wp_unslash( $_POST['export_types'] ) ); // WPCS: input var ok, sanitization ok.
169 }
170
171 if ( ! empty( $_POST['export_category'] ) && is_array( $_POST['export_category'] ) ) {// WPCS: input var ok.
172 $exporter->set_product_category_to_export( wp_unslash( array_values( $_POST['export_category'] ) ) ); // WPCS: input var ok, sanitization ok.
173 }
174
175 // Set specific product IDs if provided.
176 if ( ! empty( $_POST['export_product_ids'] ) ) { // WPCS: input var ok.
177 $ids_raw = explode( ',', sanitize_text_field( wp_unslash( $_POST['export_product_ids'] ) ) ); // WPCS: input var ok, sanitization ok.
178
179 if ( ! empty( $ids_raw ) ) {
180 $exporter->set_product_ids_to_export( $ids_raw );
181 }
182 }
183
184 if ( ! empty( $_POST['filename'] ) ) { // WPCS: input var ok.
185 $exporter->set_filename( wp_unslash( $_POST['filename'] ) ); // WPCS: input var ok, sanitization ok.
186 }
187
188 $exporter->set_page( $step );
189 $exporter->generate_file();
190
191 $query_args = apply_filters(
192 'woocommerce_export_get_ajax_query_args',
193 array(
194 'nonce' => wp_create_nonce( 'product-csv' ),
195 'action' => 'download_product_csv',
196 'filename' => $exporter->get_filename(),
197 )
198 );
199
200 if ( 100 === $exporter->get_percent_complete() ) {
201 wp_send_json_success(
202 array(
203 'step' => 'done',
204 'percentage' => 100,
205 'url' => add_query_arg( $query_args, admin_url( 'edit.php?post_type=product&page=product_exporter' ) ),
206 )
207 );
208 } else {
209 wp_send_json_success(
210 array(
211 'step' => ++$step,
212 'percentage' => $exporter->get_percent_complete(),
213 'columns' => $exporter->get_column_names(),
214 )
215 );
216 }
217 }
218
219 /**
220 * Gets the product types that can be exported.
221 *
222 * @since 5.1.0
223 * @return array The product types keys and labels.
224 */
225 public static function get_product_types() {
226 $product_types = wc_get_product_types();
227 $product_types[ ProductType::VARIATION ] = __( 'Product variations', 'woocommerce' );
228
229 /**
230 * Allow third-parties to filter the exportable product types.
231 *
232 * @since 5.1.0
233 * @param array $product_types {
234 * The product type key and label.
235 *
236 * @type string Product type key - eg 'variable', 'simple' etc.
237 * @type string A translated product label which appears in the export product type dropdown.
238 * }
239 */
240 return apply_filters( 'woocommerce_exporter_product_types', $product_types );
241 }
242 }
243
244 new WC_Admin_Exporters();
245