PluginProbe ʕ •ᴥ•ʔ
WooCommerce Square / 5.3.0
WooCommerce Square v5.3.0
5.4.1 5.4.0 trunk 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.7.0 2.8.0 2.9.0 2.9.1 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.2.0 3.3.0 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.7.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 4.0.0 4.1.0 4.2.0 4.2.1 4.2.2 4.2.3 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.9.0 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 4.9.8 4.9.9 5.0.0 5.0.1 5.1.0 5.1.1 5.1.2 5.2.0 5.3.0 5.3.1 5.3.2 5.3.3
woocommerce-square / includes / Admin.php
woocommerce-square / includes Last commit date
API 3 months ago Admin 3 months ago Emails 1 year ago Framework 3 months ago Gateway 3 months ago Handlers 3 months ago Sync 5 months ago Utilities 3 months ago AJAX.php 1 year ago API.php 3 months ago Admin.php 9 months ago Coupons.php 3 months ago Functions.php 3 years ago Gateway.php 3 months ago Lifecycle.php 1 year ago Plugin.php 3 months ago Settings.php 3 months ago WC_Order_Square.php 2 years ago WC_Payments_Compatibility.php 1 year ago
Admin.php
372 lines
1 <?php
2 /**
3 * WooCommerce Square
4 *
5 * This source file is subject to the GNU General Public License v3.0
6 * that is bundled with this package in the file license.txt.
7 * It is also available through the world-wide-web at this URL:
8 * http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 or later
9 * If you did not receive a copy of the license and are unable to
10 * obtain it through the world-wide-web, please send an email
11 * to license@woocommerce.com so we can send you a copy immediately.
12 *
13 * DISCLAIMER
14 *
15 * Do not edit or add to this file if you wish to upgrade WooCommerce Square to newer
16 * versions in the future. If you wish to customize WooCommerce Square for your
17 * needs please refer to https://docs.woocommerce.com/document/woocommerce-square/
18 *
19 * @author WooCommerce
20 * @copyright Copyright: (c) 2019, Automattic, Inc.
21 * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 or later
22 */
23
24 namespace WooCommerce\Square;
25
26 defined( 'ABSPATH' ) || exit;
27
28 use WooCommerce\Square\Admin\Analytics\Revenue;
29 use WooCommerce\Square\Handlers\Products;
30 use WooCommerce\Square\Handlers\Product;
31
32 /**
33 * The base admin handler class.
34 *
35 * @since 2.0.0
36 */
37 class Admin {
38
39
40 /**
41 * Product handler.
42 *
43 * @var Handlers\Products
44 */
45 private $products_handler;
46
47 /**
48 * Privacy handler.
49 *
50 * @var Admin\Privacy
51 */
52 private $privacy_handler;
53
54 /**
55 * Plugin
56 *
57 * @var Plugin plugin instance
58 */
59 private $plugin;
60
61
62 /**
63 * Constructs the class.
64 *
65 * @since 2.0.0
66 *
67 * @param Plugin $plugin plugin instance.
68 */
69 public function __construct( Plugin $plugin ) {
70
71 $this->plugin = $plugin;
72
73 $this->products_handler = $this->plugin->get_products_handler();
74
75 // privacy
76 $this->privacy_handler = new Admin\Privacy();
77
78 new Revenue();
79
80 $this->add_hooks();
81 }
82
83
84 /**
85 * Adds the action & filter hooks.
86 *
87 * @since 2.0.0
88 */
89 private function add_hooks() {
90
91 // add the settings page.
92 add_filter(
93 'woocommerce_get_settings_pages',
94 function ( $pages ) {
95
96 $pages[] = new Admin\Settings_Page( $this->get_plugin()->get_settings_handler() );
97
98 return $pages;
99 }
100 );
101
102 // load admin scripts.
103 add_action(
104 'admin_enqueue_scripts',
105 function ( $hook ) {
106 $this->load_scripts_styles( $hook );
107 }
108 );
109 }
110
111
112 /**
113 * Loads and enqueues admin scripts and styles.
114 *
115 * @param string $hook The current admin page.
116 *
117 * @since 2.0.0
118 */
119 private function load_scripts_styles( $hook ) {
120 global $typenow;
121
122 if ( 'product' === $typenow ) {
123
124 wp_enqueue_script(
125 'wc-square-admin-products',
126 $this->get_plugin()->get_plugin_url() . '/build/assets/admin/wc-square-admin-products.js',
127 array( 'jquery' ),
128 Plugin::VERSION,
129 true
130 );
131
132 wp_enqueue_style(
133 'wc-square-admin-products',
134 $this->get_plugin()->get_plugin_url() . '/build/assets/admin/wc-square-admin-products-styles.css',
135 array(),
136 Plugin::VERSION
137 );
138
139 wp_localize_script(
140 'wc-square-admin-products',
141 'wc_square_admin_products',
142 array(
143 'ajax_url' => admin_url( 'admin-ajax.php' ),
144 'settings_url' => esc_url( $this->get_plugin()->get_settings_url() ),
145 'variable_product_types' => $this->get_variable_product_types(),
146 'synced_with_square_taxonomy' => Product::SYNCED_WITH_SQUARE_TAXONOMY,
147 'is_product_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_product_sync_enabled(),
148 'is_woocommerce_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_woocommerce(),
149 'is_square_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_square(),
150 'is_inventory_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_inventory_sync_enabled(),
151 'get_quick_edit_product_details_nonce' => wp_create_nonce( 'get-quick-edit-product-details' ),
152 'fetch_product_stock_with_square_nonce' => wp_create_nonce( 'fetch-product-stock-with-square' ),
153 'supported_products_for_sync' => array( 'simple', 'variable' ),
154 'i18n' => array(
155 'inventory_tracking_disabled' => __( 'Inventory tracking is disabled for this product', 'woocommerce-square' ),
156 'synced_with_square' => __( 'Synced with Square', 'woocommerce-square' ),
157 'managed_by_square' => __( 'Managed by Square', 'woocommerce-square' ),
158 'fetch_stock_with_square' => __( 'Fetch stock from Square', 'woocommerce-square' ),
159 'sync_inventory' => __( 'Sync inventory', 'woocommerce-square' ),
160 'sync_stock_from_square' => __( 'Sync stock from Square', 'woocommerce-square' ),
161 'attribute_name_too_long' => __( 'Attribute name is too long, maximum allowed are 65 characters', 'woocommerce-square' ),
162 'too_many_attributes' => __( 'Too many attributes, maximum allowed are 6.', 'woocommerce-square' ),
163 /* translators: %d - maximum allowed attribute values */
164 'too_many_attribute_values' => __( 'Too many attribute values: %d (max 250)', 'woocommerce-square' ),
165 'too_many_variations' => __( 'Too many variations, maximum allowed are 250.', 'woocommerce-square' ),
166 ),
167 )
168 );
169 } elseif ( $this->get_plugin()->is_plugin_settings() ) {
170 wp_enqueue_style(
171 'wc-square-admin',
172 $this->get_plugin()->get_plugin_url() . '/build/assets/admin/wc-square-admin.css',
173 array(),
174 Plugin::VERSION
175 );
176
177 wp_enqueue_media();
178
179 wp_enqueue_script(
180 'wc-square-admin-settings',
181 $this->get_plugin()->get_plugin_url() . '/build/assets/admin/wc-square-admin-settings.js',
182 array( 'jquery', 'jquery-blockui', 'backbone', 'wc-backbone-modal' ),
183 Plugin::VERSION,
184 true
185 );
186
187 $sync_job = $this->get_plugin()->get_sync_handler()->get_job_in_progress();
188
189 if ( $sync_job ) {
190 $existing_sync_id = $sync_job->id;
191 } else {
192 $existing_sync_id = false;
193 }
194
195 wp_localize_script(
196 'wc-square-admin-settings',
197 'wc_square_admin_settings',
198 array(
199 'ajax_url' => admin_url( 'admin-ajax.php' ),
200 'is_product_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_product_sync_enabled(),
201 'is_woocommerce_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_woocommerce(),
202 'is_square_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_square(),
203 'is_inventory_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_inventory_sync_enabled(),
204 'is_sandbox' => $this->get_plugin()->get_settings_handler()->is_sandbox(),
205 'existing_sync_job_id' => $existing_sync_id,
206 'import_products_from_square' => wp_create_nonce( 'import-products-from-square' ),
207 'sync_products_with_square' => wp_create_nonce( 'sync-products-with-square' ),
208 'get_sync_with_square_status_nonce' => wp_create_nonce( 'get-sync-with-square-status' ),
209 'handle_sync_with_square_records' => wp_create_nonce( 'handle-sync-with-square-records' ),
210 'i18n' => array(
211 'resolved' => __( 'Resolved', 'woocommerce-square' ),
212 'no_records_found' => __( 'No records found', 'woocommerce-square' ),
213 'skipped' => __( 'Skipped', 'woocommerce-square' ),
214 'updated' => __( 'Updated', 'woocommerce-square' ),
215 'imported' => __( 'Imported', 'woocommerce-square' ),
216 'sync_inventory_label' => array(
217 'square' => __( 'Enable to fetch inventory changes from Square', 'woocommerce-square' ),
218 'woocommerce' => __( 'Enable to push inventory changes to Square', 'woocommerce-square' ),
219 ),
220 'sync_inventory_description' => array(
221 'square' => __( 'Inventory is fetched from Square periodically and updated in WooCommerce', 'woocommerce-square' ),
222 'woocommerce' => sprintf(
223 /* translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag */
224 __( 'Inventory is %1$salways fetched from Square%2$s periodically to account for sales from other channels.', 'woocommerce-square' ),
225 '<strong>',
226 '</strong>'
227 ),
228 ),
229 ),
230 )
231 );
232
233 $asset_file = WC_SQUARE_PLUGIN_PATH . 'build/settings.asset.php';
234
235 if ( ! file_exists( $asset_file ) ) {
236 return;
237 }
238
239 $asset = include $asset_file;
240
241 wp_enqueue_script(
242 'woocommerce-square-settings-js',
243 WC_SQUARE_PLUGIN_URL . 'build/settings.js',
244 $asset['dependencies'],
245 $asset['version'],
246 array(
247 'in_footer' => true,
248 )
249 );
250
251 $gift_card_placeholder_url = Products::get_gift_card_default_placeholder_url();
252
253 if ( empty( $gift_card_placeholder_url ) ) {
254 $gift_card_placeholder_url = WC_SQUARE_PLUGIN_URL . 'build/images/gift-card-featured-image.png';
255 }
256
257 wp_localize_script(
258 'woocommerce-square-settings-js',
259 'wcSquareSettings',
260 array(
261 'nonce' => wp_create_nonce( 'wc_square_settings' ),
262 'homeUrl' => home_url(),
263 'adminUrl' => admin_url(),
264 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
265 'depsCheck' => $this->get_plugin()->get_dependency_handler()->meets_php_dependencies(),
266 'gcPlaceholderUrl' => esc_url( $gift_card_placeholder_url ),
267 )
268 );
269
270 wp_enqueue_style(
271 'woocommerce-square-settings-css',
272 WC_SQUARE_PLUGIN_URL . 'build/settings.css',
273 array(),
274 $asset['version'],
275 );
276 } elseif ( 'woocommerce_page_woocommerce-square-onboarding' === $hook ) {
277 $asset_file = WC_SQUARE_PLUGIN_PATH . 'build/onboarding.asset.php';
278
279 if ( ! file_exists( $asset_file ) ) {
280 return;
281 }
282
283 $asset = include $asset_file;
284
285 wp_enqueue_script(
286 'woocommerce-square-onboarding-js',
287 WC_SQUARE_PLUGIN_URL . 'build/onboarding.js',
288 $asset['dependencies'],
289 $asset['version'],
290 array(
291 'in_footer' => true,
292 )
293 );
294
295 wp_localize_script(
296 'woocommerce-square-onboarding-js',
297 'wcSquareSettings',
298 array(
299 'nonce' => wp_create_nonce( 'wc_square_settings' ),
300 'homeUrl' => home_url(),
301 'adminUrl' => admin_url(),
302 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
303 )
304 );
305
306 wp_enqueue_style(
307 'woocommerce-square-onboarding-css',
308 WC_SQUARE_PLUGIN_URL . 'build/onboarding.css',
309 array(),
310 $asset['version'],
311 );
312
313 wp_localize_script(
314 'woocommerce-square-onboarding-js',
315 'wcSquareOnboarding',
316 array(
317 'plugin_version' => WC_SQUARE_PLUGIN_VERSION,
318 'is_mobile' => wp_is_mobile(),
319 )
320 );
321 }
322
323 wp_enqueue_style( 'wp-components' );
324 }
325
326
327 /**
328 * Gets a list of variable product types.
329 *
330 * @since 2.0.0
331 *
332 * @return string[]
333 */
334 private function get_variable_product_types() {
335
336 /**
337 * Filters the variable product types.
338 *
339 * @since 2.0.0
340 *
341 * @param string[] array of product types
342 */
343 return (array) apply_filters( 'wc_square_variable_product_types', array( 'variable', 'variable-subscription' ) );
344 }
345
346
347 /**
348 * Gets the products handler.
349 *
350 * @since 2.0.0
351 *
352 * @return Admin\Products
353 */
354 public function get_products_handler() {
355
356 return $this->products_handler;
357 }
358
359
360 /**
361 * Gets the plugin instance.
362 *
363 * @since 2.0.0
364 *
365 * @return Plugin
366 */
367 protected function get_plugin() {
368
369 return $this->plugin;
370 }
371 }
372