Completed
Push — master ( 787d36...3cef28 )
by Mike
09:17
created

WC_Admin_Assets::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 5
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
1 ignored issue
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 20 and the first side effect is on line 12.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Load assets
4
 *
5
 * @author      WooThemes
6
 * @category    Admin
7
 * @package     WooCommerce/Admin
8
 * @version     2.1.0
9
 */
10
11
if ( ! defined( 'ABSPATH' ) ) {
12
	exit;
13
}
14
15
if ( ! class_exists( 'WC_Admin_Assets' ) ) :
16
17
/**
18
 * WC_Admin_Assets Class.
19
 */
20
class WC_Admin_Assets {
21
22
	/**
23
	 * Hook in tabs.
24
	 */
25
	public function __construct() {
26
		add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) );
27
		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
28
		add_action( 'admin_head',            array( $this, 'product_taxonomy_styles' ) );
29
	}
30
31
	/**
32
	 * Enqueue styles.
33
	 */
34
	public function admin_styles() {
35
		global $wp_scripts;
36
37
		$screen         = get_current_screen();
38
		$screen_id      = $screen ? $screen->id : '';
39
		$jquery_version = isset( $wp_scripts->registered['jquery-ui-core']->ver ) ? $wp_scripts->registered['jquery-ui-core']->ver : '1.9.2';
40
41
		// Register admin styles
42
		wp_register_style( 'woocommerce_admin_menu_styles', WC()->plugin_url() . '/assets/css/menu.css', array(), WC_VERSION );
43
		wp_register_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), WC_VERSION );
44
		wp_register_style( 'jquery-ui-style', '//code.jquery.com/ui/' . $jquery_version . '/themes/smoothness/jquery-ui.css', array(), $jquery_version );
45
		wp_register_style( 'woocommerce_admin_dashboard_styles', WC()->plugin_url() . '/assets/css/dashboard.css', array(), WC_VERSION );
46
		wp_register_style( 'woocommerce_admin_print_reports_styles', WC()->plugin_url() . '/assets/css/reports-print.css', array(), WC_VERSION, 'print' );
47
48
		// Sitewide menu CSS
49
		wp_enqueue_style( 'woocommerce_admin_menu_styles' );
50
51
		// Admin styles for WC pages only
52
		if ( in_array( $screen_id, wc_get_screen_ids() ) ) {
53
			wp_enqueue_style( 'woocommerce_admin_styles' );
54
			wp_enqueue_style( 'jquery-ui-style' );
55
			wp_enqueue_style( 'wp-color-picker' );
56
		}
57
58
		if ( in_array( $screen_id, array( 'dashboard' ) ) ) {
59
			wp_enqueue_style( 'woocommerce_admin_dashboard_styles' );
60
		}
61
62
		if ( in_array( $screen_id, array( 'woocommerce_page_wc-reports', 'toplevel_page_wc-reports' ) ) ) {
63
			wp_enqueue_style( 'woocommerce_admin_print_reports_styles' );
64
		}
65
66
		/**
67
		 * @deprecated 2.3
68
		 */
69
70
		if ( has_action( 'woocommerce_admin_css' ) ) {
71
			do_action( 'woocommerce_admin_css' );
72
			_deprecated_function( 'The woocommerce_admin_css action', '2.3', 'admin_enqueue_scripts' );
73
		}
74
	}
75
76
77
	/**
78
	 * Enqueue scripts.
79
	 */
80
	public function admin_scripts() {
81
		global $wp_query, $post;
82
83
		$screen       = get_current_screen();
84
		$screen_id    = $screen ? $screen->id : '';
85
		$wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce' ) );
86
		$suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
87
88
		// Register scripts
89
		wp_register_script( 'woocommerce_admin', WC()->plugin_url() . '/assets/js/admin/woocommerce_admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui', 'jquery-ui-sortable', 'jquery-ui-widget', 'jquery-ui-core', 'jquery-tiptip' ), WC_VERSION );
90
		wp_register_script( 'jquery-blockui', WC()->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.70', true );
91
		wp_register_script( 'jquery-tiptip', WC()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true );
92
		wp_register_script( 'accounting', WC()->plugin_url() . '/assets/js/accounting/accounting' . $suffix . '.js', array( 'jquery' ), '0.4.2' );
93
		wp_register_script( 'round', WC()->plugin_url() . '/assets/js/round/round' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
94
		wp_register_script( 'wc-admin-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'accounting', 'round', 'wc-enhanced-select', 'plupload-all', 'stupidtable', 'jquery-tiptip' ), WC_VERSION );
95
		wp_register_script( 'zeroclipboard', WC()->plugin_url() . '/assets/js/zeroclipboard/jquery.zeroclipboard' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
96
		wp_register_script( 'qrcode', WC()->plugin_url() . '/assets/js/jquery-qrcode/jquery.qrcode' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
97
		wp_register_script( 'stupidtable', WC()->plugin_url() . '/assets/js/stupidtable/stupidtable' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
98
		wp_register_script( 'serializejson', WC()->plugin_url() . '/assets/js/jquery-serializejson/jquery.serializejson' . $suffix . '.js', array( 'jquery' ), '2.6.1' );
99
		wp_register_script( 'flot', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
100
		wp_register_script( 'flot-resize', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.resize' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION );
101
		wp_register_script( 'flot-time', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.time' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION );
102
		wp_register_script( 'flot-pie', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.pie' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION );
103
		wp_register_script( 'flot-stack', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.stack' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION );
104
		wp_register_script( 'wc-settings-tax', WC()->plugin_url() . '/assets/js/admin/settings-views-html-settings-tax' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-blockui' ), WC_VERSION );
105
106
		// Chosen is @deprecated (2.3) in favour of select2, but is registered for backwards compat
107
		wp_register_script( 'ajax-chosen', WC()->plugin_url() . '/assets/js/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'chosen' ), WC_VERSION );
108
		wp_register_script( 'chosen', WC()->plugin_url() . '/assets/js/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
109
110
		// Select2 is the replacement for chosen
111
		wp_register_script( 'select2', WC()->plugin_url() . '/assets/js/select2/select2' . $suffix . '.js', array( 'jquery' ), '3.5.4' );
112
		wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'select2' ), WC_VERSION );
113
		wp_localize_script( 'wc-enhanced-select', 'wc_enhanced_select_params', array(
114
			'i18n_matches_1'            => _x( 'One result is available, press enter to select it.', 'enhanced select', 'woocommerce' ),
115
			'i18n_matches_n'            => _x( '%qty% results are available, use up and down arrow keys to navigate.', 'enhanced select', 'woocommerce' ),
116
			'i18n_no_matches'           => _x( 'No matches found', 'enhanced select', 'woocommerce' ),
117
			'i18n_ajax_error'           => _x( 'Loading failed', 'enhanced select', 'woocommerce' ),
118
			'i18n_input_too_short_1'    => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ),
119
			'i18n_input_too_short_n'    => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce' ),
120
			'i18n_input_too_long_1'     => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce' ),
121
			'i18n_input_too_long_n'     => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce' ),
122
			'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce' ),
123
			'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce' ),
124
			'i18n_load_more'            => _x( 'Loading more results&hellip;', 'enhanced select', 'woocommerce' ),
125
			'i18n_searching'            => _x( 'Searching&hellip;', 'enhanced select', 'woocommerce' ),
126
			'ajax_url'                  => admin_url( 'admin-ajax.php' ),
127
			'search_products_nonce'     => wp_create_nonce( 'search-products' ),
128
			'search_customers_nonce'    => wp_create_nonce( 'search-customers' )
129
		) );
130
131
		// Accounting
132
		wp_localize_script( 'accounting', 'accounting_params', array(
133
			'mon_decimal_point' => wc_get_price_decimal_separator()
134
		) );
135
136
		// WooCommerce admin pages
137
		if ( in_array( $screen_id, wc_get_screen_ids() ) ) {
138
			wp_enqueue_script( 'iris' );
139
			wp_enqueue_script( 'woocommerce_admin' );
140
			wp_enqueue_script( 'wc-enhanced-select' );
141
			wp_enqueue_script( 'jquery-ui-sortable' );
142
			wp_enqueue_script( 'jquery-ui-autocomplete' );
143
144
			$locale  = localeconv();
145
			$decimal = isset( $locale['decimal_point'] ) ? $locale['decimal_point'] : '.';
146
147
			$params = array(
148
				'i18n_decimal_error'                => sprintf( __( 'Please enter in decimal (%s) format without thousand separators.', 'woocommerce' ), $decimal ),
149
				'i18n_mon_decimal_error'            => sprintf( __( 'Please enter in monetary decimal (%s) format without thousand separators and currency symbols.', 'woocommerce' ), wc_get_price_decimal_separator() ),
150
				'i18n_country_iso_error'            => __( 'Please enter in country code with two capital letters.', 'woocommerce' ),
151
				'i18_sale_less_than_regular_error'  => __( 'Please enter in a value less than the regular price.', 'woocommerce' ),
152
				'decimal_point'                     => $decimal,
153
				'mon_decimal_point'                 => wc_get_price_decimal_separator()
154
			);
155
156
			wp_localize_script( 'woocommerce_admin', 'woocommerce_admin', $params );
157
		}
158
159
		// Edit product category pages
160
		if ( in_array( $screen_id, array( 'edit-product_cat' ) ) ) {
161
			wp_enqueue_media();
162
		}
163
164
		// Products
165 View Code Duplication
		if ( in_array( $screen_id, array( 'edit-product' ) ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
166
			wp_register_script( 'woocommerce_quick-edit', WC()->plugin_url() . '/assets/js/admin/quick-edit' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
167
			wp_enqueue_script( 'woocommerce_quick-edit' );
168
		}
169
170
		// Meta boxes
171
		if ( in_array( $screen_id, array( 'product', 'edit-product' ) ) ) {
172
			wp_enqueue_media();
173
			wp_register_script( 'wc-admin-product-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'media-models' ), WC_VERSION );
174
			wp_register_script( 'wc-admin-variation-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product-variation' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'serializejson', 'media-models' ), WC_VERSION );
175
176
			wp_enqueue_script( 'wc-admin-product-meta-boxes' );
177
			wp_enqueue_script( 'wc-admin-variation-meta-boxes' );
178
179
			$params = array(
180
				'post_id'                             => isset( $post->ID ) ? $post->ID : '',
181
				'plugin_url'                          => WC()->plugin_url(),
182
				'ajax_url'                            => admin_url( 'admin-ajax.php' ),
183
				'woocommerce_placeholder_img_src'     => wc_placeholder_img_src(),
184
				'add_variation_nonce'                 => wp_create_nonce( 'add-variation' ),
185
				'link_variation_nonce'                => wp_create_nonce( 'link-variations' ),
186
				'delete_variations_nonce'             => wp_create_nonce( 'delete-variations' ),
187
				'load_variations_nonce'               => wp_create_nonce( 'load-variations' ),
188
				'save_variations_nonce'               => wp_create_nonce( 'save-variations' ),
189
				'bulk_edit_variations_nonce'          => wp_create_nonce( 'bulk-edit-variations' ),
190
				'i18n_link_all_variations'            => esc_js( __( 'Are you sure you want to link all variations? This will create a new variation for each and every possible combination of variation attributes (max 50 per run).', 'woocommerce' ) ),
191
				'i18n_enter_a_value'                  => esc_js( __( 'Enter a value', 'woocommerce' ) ),
192
				'i18n_enter_menu_order'               => esc_js( __( 'Variation menu order (determines position in the list of variations)', 'woocommerce' ) ),
193
				'i18n_enter_a_value_fixed_or_percent' => esc_js( __( 'Enter a value (fixed or %)', 'woocommerce' ) ),
194
				'i18n_delete_all_variations'          => esc_js( __( 'Are you sure you want to delete all variations? This cannot be undone.', 'woocommerce' ) ),
195
				'i18n_last_warning'                   => esc_js( __( 'Last warning, are you sure?', 'woocommerce' ) ),
196
				'i18n_choose_image'                   => esc_js( __( 'Choose an image', 'woocommerce' ) ),
197
				'i18n_set_image'                      => esc_js( __( 'Set variation image', 'woocommerce' ) ),
198
				'i18n_variation_added'                => esc_js( __( "variation added", 'woocommerce' ) ),
199
				'i18n_variations_added'               => esc_js( __( "variations added", 'woocommerce' ) ),
200
				'i18n_no_variations_added'            => esc_js( __( "No variations added", 'woocommerce' ) ),
201
				'i18n_remove_variation'               => esc_js( __( 'Are you sure you want to remove this variation?', 'woocommerce' ) ),
202
				'i18n_scheduled_sale_start'           => esc_js( __( 'Sale start date (YYYY-MM-DD format or leave blank)', 'woocommerce' ) ),
203
				'i18n_scheduled_sale_end'             => esc_js( __( 'Sale end date (YYYY-MM-DD format or leave blank)', 'woocommerce' ) ),
204
				'i18n_edited_variations'              => esc_js( __( 'Save changes before changing page?', 'woocommerce' ) ),
205
				'i18n_variation_count_single'         => esc_js( __( '%qty% variation', 'woocommerce' ) ),
206
				'i18n_variation_count_plural'         => esc_js( __( '%qty% variations', 'woocommerce' ) ),
207
				'variations_per_page'                 => absint( apply_filters( 'woocommerce_admin_meta_boxes_variations_per_page', 15 ) )
208
			);
209
210
			wp_localize_script( 'wc-admin-variation-meta-boxes', 'woocommerce_admin_meta_boxes_variations', $params );
211
		}
212
		if ( in_array( str_replace( 'edit-', '', $screen_id ), wc_get_order_types( 'order-meta-boxes' ) ) ) {
213
			wp_register_script( 'wc-admin-order-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-order' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION );
214
			wp_register_script( 'wc-admin-order-meta-boxes-modal', WC()->plugin_url() . '/assets/js/admin/order-backbone-modal' . $suffix . '.js', array( 'underscore', 'backbone', 'wp-util', 'wc-admin-order-meta-boxes' ), WC_VERSION );
215
216
			wp_enqueue_script( 'wc-admin-order-meta-boxes' );
217
			wp_enqueue_script( 'wc-admin-order-meta-boxes-modal' );
218
219
			$params = array(
220
				'countries'              => json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ),
221
				'i18n_select_state_text' => esc_attr__( 'Select an option&hellip;', 'woocommerce' )
222
			);
223
224
			wp_localize_script( 'wc-admin-order-meta-boxes', 'woocommerce_admin_meta_boxes_order', $params );
225
		}
226 View Code Duplication
		if ( in_array( $screen_id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
227
			wp_register_script( 'wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION );
228
			wp_enqueue_script( 'wc-admin-coupon-meta-boxes' );
229
		}
230
		if ( in_array( str_replace( 'edit-', '', $screen_id ), array_merge( array( 'shop_coupon', 'product' ), wc_get_order_types( 'order-meta-boxes' ) ) ) ) {
231
			$params = array(
232
				'remove_item_notice'            => __( 'Are you sure you want to remove the selected items? If you have previously reduced this item\'s stock, or this order was submitted by a customer, you will need to manually restore the item\'s stock.', 'woocommerce' ),
233
				'i18n_select_items'             => __( 'Please select some items.', 'woocommerce' ),
234
				'i18n_do_refund'                => __( 'Are you sure you wish to process this refund? This action cannot be undone.', 'woocommerce' ),
235
				'i18n_delete_refund'            => __( 'Are you sure you wish to delete this refund? This action cannot be undone.', 'woocommerce' ),
236
				'i18n_delete_tax'               => __( 'Are you sure you wish to delete this tax column? This action cannot be undone.', 'woocommerce' ),
237
				'remove_item_meta'              => __( 'Remove this item meta?', 'woocommerce' ),
238
				'remove_attribute'              => __( 'Remove this attribute?', 'woocommerce' ),
239
				'name_label'                    => __( 'Name', 'woocommerce' ),
240
				'remove_label'                  => __( 'Remove', 'woocommerce' ),
241
				'click_to_toggle'               => __( 'Click to toggle', 'woocommerce' ),
242
				'values_label'                  => __( 'Value(s)', 'woocommerce' ),
243
				'text_attribute_tip'            => __( 'Enter some text, or some attributes by pipe (|) separating values.', 'woocommerce' ),
244
				'visible_label'                 => __( 'Visible on the product page', 'woocommerce' ),
245
				'used_for_variations_label'     => __( 'Used for variations', 'woocommerce' ),
246
				'new_attribute_prompt'          => __( 'Enter a name for the new attribute term:', 'woocommerce' ),
247
				'calc_totals'                   => __( 'Calculate totals based on order items, discounts, and shipping?', 'woocommerce' ),
248
				'calc_line_taxes'               => __( 'Calculate line taxes? This will calculate taxes based on the customers country. If no billing/shipping is set it will use the store base country.', 'woocommerce' ),
249
				'copy_billing'                  => __( 'Copy billing information to shipping information? This will remove any currently entered shipping information.', 'woocommerce' ),
250
				'load_billing'                  => __( 'Load the customer\'s billing information? This will remove any currently entered billing information.', 'woocommerce' ),
251
				'load_shipping'                 => __( 'Load the customer\'s shipping information? This will remove any currently entered shipping information.', 'woocommerce' ),
252
				'featured_label'                => __( 'Featured', 'woocommerce' ),
253
				'prices_include_tax'            => esc_attr( get_option( 'woocommerce_prices_include_tax' ) ),
254
				'tax_based_on'                  => esc_attr( get_option( 'woocommerce_tax_based_on' ) ),
255
				'round_at_subtotal'             => esc_attr( get_option( 'woocommerce_tax_round_at_subtotal' ) ),
256
				'no_customer_selected'          => __( 'No customer selected', 'woocommerce' ),
257
				'plugin_url'                    => WC()->plugin_url(),
258
				'ajax_url'                      => admin_url( 'admin-ajax.php' ),
259
				'order_item_nonce'              => wp_create_nonce( 'order-item' ),
260
				'add_attribute_nonce'           => wp_create_nonce( 'add-attribute' ),
261
				'save_attributes_nonce'         => wp_create_nonce( 'save-attributes' ),
262
				'calc_totals_nonce'             => wp_create_nonce( 'calc-totals' ),
263
				'get_customer_details_nonce'    => wp_create_nonce( 'get-customer-details' ),
264
				'search_products_nonce'         => wp_create_nonce( 'search-products' ),
265
				'grant_access_nonce'            => wp_create_nonce( 'grant-access' ),
266
				'revoke_access_nonce'           => wp_create_nonce( 'revoke-access' ),
267
				'add_order_note_nonce'          => wp_create_nonce( 'add-order-note' ),
268
				'delete_order_note_nonce'       => wp_create_nonce( 'delete-order-note' ),
269
				'calendar_image'                => WC()->plugin_url().'/assets/images/calendar.png',
270
				'post_id'                       => isset( $post->ID ) ? $post->ID : '',
271
				'base_country'                  => WC()->countries->get_base_country(),
272
				'currency_format_num_decimals'  => wc_get_price_decimals(),
273
				'currency_format_symbol'        => get_woocommerce_currency_symbol(),
274
				'currency_format_decimal_sep'   => esc_attr( wc_get_price_decimal_separator() ),
275
				'currency_format_thousand_sep'  => esc_attr( wc_get_price_thousand_separator() ),
276
				'currency_format'               => esc_attr( str_replace( array( '%1$s', '%2$s' ), array( '%s', '%v' ), get_woocommerce_price_format() ) ), // For accounting JS
277
				'rounding_precision'            => WC_ROUNDING_PRECISION,
278
				'tax_rounding_mode'             => WC_TAX_ROUNDING_MODE,
279
				'product_types'                 => array_map( 'sanitize_title', get_terms( 'product_type', array( 'hide_empty' => false, 'fields' => 'names' ) ) ),
280
				'i18n_download_permission_fail' => __( 'Could not grant access - the user may already have permission for this file or billing email is not set. Ensure the billing email is set, and the order has been saved.', 'woocommerce' ),
281
				'i18n_permission_revoke'        => __( 'Are you sure you want to revoke access to this download?', 'woocommerce' ),
282
				'i18n_tax_rate_already_exists'  => __( 'You cannot add the same tax rate twice!', 'woocommerce' ),
283
				'i18n_product_type_alert'       => __( 'Your product has variations! Before changing the product type, it is a good idea to delete the variations to avoid errors in the stock reports.', 'woocommerce' )
284
			);
285
286
			wp_localize_script( 'wc-admin-meta-boxes', 'woocommerce_admin_meta_boxes', $params );
287
		}
288
289
		// Term ordering - only when sorting by term_order
290
		if ( ( strstr( $screen_id, 'edit-pa_' ) || ( ! empty( $_GET['taxonomy'] ) && in_array( $_GET['taxonomy'], apply_filters( 'woocommerce_sortable_taxonomies', array( 'product_cat' ) ) ) ) ) && ! isset( $_GET['orderby'] ) ) {
291
292
			wp_register_script( 'woocommerce_term_ordering', WC()->plugin_url() . '/assets/js/admin/term-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), WC_VERSION );
293
			wp_enqueue_script( 'woocommerce_term_ordering' );
294
295
			$taxonomy = isset( $_GET['taxonomy'] ) ? wc_clean( $_GET['taxonomy'] ) : '';
296
297
			$woocommerce_term_order_params = array(
298
				'taxonomy' => $taxonomy
299
			);
300
301
			wp_localize_script( 'woocommerce_term_ordering', 'woocommerce_term_ordering_params', $woocommerce_term_order_params );
302
		}
303
304
		// Product sorting - only when sorting by menu order on the products page
305
		if ( current_user_can( 'edit_others_pages' ) && $screen_id == 'edit-product' && isset( $wp_query->query['orderby'] ) && $wp_query->query['orderby'] == 'menu_order title' ) {
306
			wp_register_script( 'woocommerce_product_ordering', WC()->plugin_url() . '/assets/js/admin/product-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), WC_VERSION, true );
307
			wp_enqueue_script( 'woocommerce_product_ordering' );
308
		}
309
310
		// Reports Pages
311
		if ( in_array( $screen_id, apply_filters( 'woocommerce_reports_screen_ids', array( $wc_screen_id . '_page_wc-reports', 'toplevel_page_wc-reports', 'dashboard' ) ) ) ) {
312
			wp_register_script( 'wc-reports', WC()->plugin_url() . '/assets/js/admin/reports' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker' ), WC_VERSION );
313
314
			wp_enqueue_script( 'wc-reports' );
315
			wp_enqueue_script( 'flot' );
316
			wp_enqueue_script( 'flot-resize' );
317
			wp_enqueue_script( 'flot-time' );
318
			wp_enqueue_script( 'flot-pie' );
319
			wp_enqueue_script( 'flot-stack' );
320
		}
321
322
		// API settings
323
		if ( $wc_screen_id . '_page_wc-settings' === $screen_id && isset( $_GET['section'] ) && 'keys' == $_GET['section'] ) {
324
			wp_register_script( 'wc-api-keys', WC()->plugin_url() . '/assets/js/admin/api-keys' . $suffix . '.js', array( 'jquery', 'woocommerce_admin', 'underscore', 'backbone', 'wp-util', 'qrcode', 'zeroclipboard' ), WC_VERSION, true );
325
			wp_enqueue_script( 'wc-api-keys' );
326
			wp_localize_script(
327
				'wc-api-keys',
328
				'woocommerce_admin_api_keys',
329
				array(
330
					'ajax_url'         => admin_url( 'admin-ajax.php' ),
331
					'update_api_nonce' => wp_create_nonce( 'update-api-key' )
332
				)
333
			);
334
		}
335
336
		// System status
337
		if ( $wc_screen_id . '_page_wc-status' === $screen_id ) {
338
			wp_enqueue_script( 'zeroclipboard' );
339
		}
340
341
		if ( in_array( $screen_id, array( 'user-edit', 'profile' ) ) ) {
342
			wp_register_script( 'wc-users', WC()->plugin_url() . '/assets/js/admin/users' . $suffix . '.js', array( 'jquery', 'wc-enhanced-select' ), WC_VERSION, true );
343
			wp_enqueue_script( 'wc-users' );
344
			wp_localize_script(
345
				'wc-users',
346
				'wc_users_params',
347
				array(
348
					'countries'              => json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ),
349
					'i18n_select_state_text' => esc_attr__( 'Select an option&hellip;', 'woocommerce' ),
350
				)
351
			);
352
		}
353
	}
354
355
	/**
356
	 * Admin Head.
357
	 *
358
	 * Outputs some styles in the admin <head> to show icons on the woocommerce admin pages.
359
	 */
360
	public function product_taxonomy_styles() {
361
362
		if ( ! current_user_can( 'manage_woocommerce' ) ) return;
363
		?>
364
		<style type="text/css">
365
			<?php if ( isset($_GET['taxonomy']) && $_GET['taxonomy']=='product_cat' ) : ?>
366
				.icon32-posts-product { background-position: -243px -5px !important; }
367
			<?php elseif ( isset($_GET['taxonomy']) && $_GET['taxonomy']=='product_tag' ) : ?>
368
				.icon32-posts-product { background-position: -301px -5px !important; }
369
			<?php endif; ?>
370
		</style>
371
		<?php
372
	}
373
}
374
375
endif;
376
377
return new WC_Admin_Assets();
378