PluginProbe
WooCommerce Square / 2.2.0
WooCommerce Square v2.2.0
5.5.0 5.4.3 5.4.2 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 All 132 releases
woocommerce-square / includes / Plugin.php

Plugin.php in WooCommerce Square 2.2.0, at includes/Plugin.php

977 lines 26.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
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
22 */
23
24 namespace WooCommerce\Square;
25
26 defined( 'ABSPATH' ) || exit;
27
28 use SkyVerge\WooCommerce\PluginFramework\v5_4_0 as Framework;
29 use WooCommerce\Square\Handlers\Background_Job;
30 use WooCommerce\Square\Handlers\Email;
31 use WooCommerce\Square\Handlers\Order;
32 use WooCommerce\Square\Handlers\Product;
33 use WooCommerce\Square\Handlers\Sync;
34 use WooCommerce\Square\Handlers\Products;
35
36 /**
37 * The main plugin class.
38 *
39 * @since 2.0.0
40 */
41 class Plugin extends Framework\SV_WC_Payment_Gateway_Plugin {
42
43
44 /** plugin version number */
45 const VERSION = '2.2.0';
46
47 /** plugin ID */
48 const PLUGIN_ID = 'square';
49
50 /** string gateway ID */
51 const GATEWAY_ID = 'square_credit_card';
52
53
54 /** @var Plugin plugin instance */
55 protected static $instance;
56
57 /** @var Settings settings handler instance */
58 private $settings_handler;
59
60 /** @var Handlers\Connection connection handler instance */
61 private $connection_handler;
62
63 /** @var Admin admin handler instance */
64 private $admin_handler;
65
66 /** @var Sync sync handler instance */
67 private $sync_handler;
68
69 /** @var Background_Job background handler instance */
70 private $background_job_handler;
71
72 /** @var AJAX handler instance */
73 private $ajax_handler;
74
75 /** @var Email emails handler */
76 private $email_handler;
77
78 /** @var Order orders handler */
79 private $order_handler;
80
81 /** @var Products products handler */
82 private $products_handler;
83
84 /**
85 * Constructs the plugin.
86 *
87 * @since 2.0.0
88 */
89 public function __construct() {
90
91 parent::__construct(
92 self::PLUGIN_ID,
93 self::VERSION,
94 array(
95 'text_domain' => 'woocommerce-square',
96 'gateways' => array( self::GATEWAY_ID => Gateway::class ),
97 'require_ssl' => true,
98 'supports' => array(
99 self::FEATURE_CAPTURE_CHARGE,
100 self::FEATURE_CUSTOMER_ID,
101 self::FEATURE_MY_PAYMENT_METHODS,
102 ),
103 'dependencies' => array(
104 'php_extensions' => array( 'curl', 'json', 'mbstring' ),
105 ),
106 )
107 );
108
109 $this->includes();
110
111 /**
112 * Fires upon plugin loaded (legacy hook).
113 *
114 * @since 1.0.0
115 */
116 do_action( 'wc_square_loaded' );
117
118 add_action( 'woocommerce_register_taxonomy', array( $this, 'init_taxonomies' ) );
119
120 add_filter( 'woocommerce_locate_template', array( $this, 'locate_template' ), 20, 3 );
121 add_filter( 'woocommerce_locate_core_template', array( $this, 'locate_template' ), 20, 3 );
122 }
123
124
125 /**
126 * Includes required classes.
127 *
128 * @since 2.0.0
129 */
130 private function includes() {
131
132 $this->connection_handler = new Handlers\Connection( $this );
133
134 $this->sync_handler = new Sync( $this );
135
136 // background export must be loaded all the time, because otherwise background jobs simply won't work
137 require_once $this->get_framework_path() . '/utilities/class-sv-wp-async-request.php';
138 require_once $this->get_framework_path() . '/utilities/class-sv-wp-background-job-handler.php';
139 require_once $this->get_framework_path() . '/utilities/class-sv-wp-job-batch-handler.php';
140
141 $this->background_job_handler = new Background_Job();
142
143 $this->ajax_handler = new AJAX();
144
145 $this->email_handler = new Email();
146
147 $this->order_handler = new Order();
148 }
149
150
151 /**
152 * Adds API request logging.
153 *
154 * @internal
155 *
156 * @since 2.0.0
157 */
158 public function add_api_request_logging() {
159
160 if ( ! has_action( 'wc_' . $this->get_id() . '_api_request_performed' ) ) {
161 add_action( 'wc_' . $this->get_id() . '_api_request_performed', array( $this, 'log_api_request' ), 10, 2 );
162 }
163 }
164
165
166 /**
167 * Logs an API request & response.
168 *
169 * @since 2.0.0
170 *
171 * @param array $request request data
172 * @param array $response response data
173 * @param string|null $log_id log ID
174 */
175 public function log_api_request( $request, $response, $log_id = null ) {
176
177 if ( $this->get_settings_handler() && $this->get_settings_handler()->is_debug_enabled() ) {
178 parent::log_api_request( $request, $response, $log_id );
179 }
180 }
181
182
183 /**
184 * Initializes the lifecycle handler.
185 *
186 * @since 2.0.0
187 */
188 public function init_lifecycle_handler() {
189
190 $this->lifecycle_handler = new Lifecycle( $this );
191 }
192
193
194 /**
195 * Registers custom taxonomies.
196 *
197 * @internal
198 *
199 * @since 2.0.0
200 */
201 public function init_taxonomies() {
202
203 Product::init_taxonomies();
204 }
205
206
207 /**
208 * Initializes the general plugin functionality.
209 *
210 * @since 2.0.0
211 */
212 public function init_plugin() {
213
214 $this->settings_handler = new Settings( $this );
215 $this->products_handler = new Products( $this );
216
217 if ( ! $this->admin_handler && is_admin() ) {
218 $this->admin_handler = new Admin( $this );
219 }
220
221 do_action( 'wc_square_initialized' );
222 }
223
224
225 /**
226 * Locates the WooCommerce template files from our templates directory.
227 *
228 * @internal
229 *
230 * @since 2.0.0
231 *
232 * @param string $template already found template
233 * @param string $template_name searchable template name
234 * @param string $template_path template path
235 * @return string search result for the template
236 */
237 public function locate_template( $template, $template_name, $template_path ) {
238
239 // only keep looking if no custom theme template was found
240 // or if a default WooCommerce template was found
241 if ( ! $template || Framework\SV_WC_Helper::str_starts_with( $template, WC()->plugin_path() ) ) {
242
243 // set the path to our templates directory
244 $plugin_path = $this->get_plugin_path() . '/templates/';
245
246 // if a template is found, make it so
247 if ( is_readable( $plugin_path . $template_name ) ) {
248 $template = $plugin_path . $template_name;
249 }
250 }
251
252 return $template;
253 }
254
255
256 /** Admin methods *************************************************************************************************/
257
258
259 /**
260 * Adds admin notices.
261 *
262 * @since 2.0.0
263 */
264 public function add_admin_notices() {
265
266 parent::add_admin_notices();
267
268 // show any one-off messages
269 $this->get_message_handler()->show_messages();
270
271 // display a notice if the auto-refresh failed
272 if ( get_option( 'wc_' . $this->get_id() . '_refresh_failed', false ) ) {
273
274 $message = sprintf(
275 __( 'Heads up! There may be a problem with your connection to Square. In order to continue accepting payments, please %1$sdisconnect and re-connect your site%2$s.', 'woocommerce-square' ),
276 '<a href="' . esc_url( $this->get_settings_url() ) . '">',
277 '</a>'
278 );
279
280 $this->get_admin_notice_handler()->add_admin_notice(
281 $message,
282 'refresh-failed',
283 array(
284 'dismissible' => false,
285 'notice_class' => 'notice-warning',
286 )
287 );
288 }
289
290 if ( $this->get_settings_handler()->is_connected() ) {
291
292 $message = '<strong>' . __( 'You are connected to Square!', 'woocommerce-square' ) . '</strong>';
293
294 // prompt to set a location if not set
295 if ( ! $this->get_settings_handler()->get_location_id() ) {
296
297 if ( $this->is_plugin_settings() ) {
298
299 $instruction = __( 'To get started, set your business location.', 'woocommerce-square' );
300
301 } else {
302
303 $instruction = sprintf(
304 /* translators: Placeholders: %1$s - <a> tag, %2$s - </a> tag */
305 __( 'Visit the %1$splugin settings%2$s to set your business location.', 'woocommerce-square' ),
306 '<a href="' . esc_url( $this->get_settings_url() ) . '">',
307 '</a>'
308 );
309 }
310
311 $this->get_admin_notice_handler()->add_admin_notice( $message . ' ' . $instruction, 'set-location' );
312
313 } elseif ( ! $this->get_sync_handler()->get_last_synced_at() && $this->get_settings_handler()->is_product_sync_enabled() ) {
314
315 $message = __( 'You are ready to sync products!', 'woocommerce-square' );
316
317 if ( ! empty( Product::get_products_synced_with_square() ) ) {
318
319 $instruction = sprintf(
320 /* translators: Placeholders: %1$s - <strong> tag, %2$s - product count, %3$s - </strong> tag, %4$s - <a> tag, %5$s - </a> tag */
321 __( '%1$s%2$d products%3$s are marked "sync with Square". %4$sStart a new sync now &raquo;%5$s', 'woocommerce-square' ),
322 '<strong>',
323 count( Product::get_products_synced_with_square() ),
324 '</strong>',
325 '<a href="' . esc_url( add_query_arg( 'section', 'update', $this->get_settings_url() ) ) . '">',
326 '</a>'
327 );
328
329 } else {
330
331 $instruction = sprintf(
332 /* translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag, %3$s - <a> tag, %4$s - </a> tag */
333 __( '%1$sNo products%2$s are marked "sync with Square". %3$sUpdate your products to sync data &raquo;%4$s', 'woocommerce-square' ),
334 '<strong>',
335 '</strong>',
336 '<a href="' . esc_url( admin_url( 'edit.php?post_type=product' ) ) . '">',
337 '</a>'
338 );
339 }
340
341 $this->get_admin_notice_handler()->add_admin_notice( $message . ' ' . $instruction, 'set-location' );
342 }
343
344 // a notice for when WC stock handling is globally disabled
345 if ( 'yes' !== get_option( 'woocommerce_manage_stock' ) && $this->get_settings_handler()->is_inventory_sync_enabled() ) {
346
347 $message = sprintf(
348 __( 'Heads up! Square is configured to sync product inventory, but WooCommerce stock management is disabled. Please %1$senable stock management%2$s to ensure product inventory counts are kept in sync.', 'woocommerce-square' ),
349 '<a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=products&section=inventory' ) ) . '">',
350 '</a>'
351 );
352
353 $this->get_admin_notice_handler()->add_admin_notice(
354 $message,
355 'enable-wc-sync',
356 array(
357 'notice_class' => 'notice-warning',
358 )
359 );
360 }
361 } else {
362
363 if ( $this->is_plugin_settings() ) {
364
365 $instruction = __( 'To get started, connect with Square.', 'woocommerce-square' );
366
367 } else {
368
369 $instruction = sprintf(
370 /* translators: Placeholders: %1$s - <a> tag, %2$s - </a> tag */
371 __( 'To get started, %1$sconnect with Square &raquo;%2$s', 'woocommerce-square' ),
372 '<a href="' . esc_url( $this->get_settings_url() ) . '">',
373 '</a>'
374 );
375 }
376
377 $message = sprintf(
378 /* translators: Placeholders: %1$s - plugin name */
379 __( 'Thanks for installing %1$s!', 'woocommerce-square' ),
380 esc_html( $this->get_plugin_name() )
381 );
382
383 $this->get_admin_notice_handler()->add_admin_notice( $message . ' ' . $instruction, 'connect' );
384 }
385
386 // add a notice for out-of-bounds base locations
387 $this->add_base_location_admin_notice();
388
389 // add a notice when background processing is not supported
390 $this->add_background_processing_notice();
391
392 // add a notice when no refresh token is available
393 $this->add_missing_refresh_token_notice();
394
395 // add a tax-inclusive warning to product pages
396 $this->add_tax_inclusive_pricing_notice();
397
398 if ( get_option( 'wc_square_updated_to_2_0_0' ) ) {
399
400 $this->get_admin_notice_handler()->add_admin_notice(
401 sprintf(
402 /* translators: Placeholders: %1$s - plugin name, %2$ - plugin version number, %3$s - opening <a> HTML link tag, %4$s - closing </a> HTML link tag, %5$s - opening <a> HTML link tag, %6$s - closing </a> HTML link tag*/
403 esc_html__( '%1$s has been updated to version %2$s. In order to continue syncing product inventory, please make sure to disconnect and reconnect with Square from the %3$splugin settings%4$s and re-sync your products. Read more in the %5$supdated documentation%6$s.', 'woocommerce-square' ),
404 '<strong>' . esc_html( $this->get_plugin_name() ) . '</strong>',
405 $this->get_version(),
406 '<a href="' . esc_url( $this->get_settings_url() ) . '">',
407 '</a>',
408 '<a href="' . esc_url( $this->get_documentation_url() ) . '">',
409 '</a>'
410 ),
411 'updated-to-v2',
412 array( 'notice_class' => 'notice-warning' )
413 );
414 }
415 }
416
417
418 /**
419 * Adds a notice for out-of-bounds base locations.
420 *
421 * @since 2.0.0
422 */
423 protected function add_base_location_admin_notice() {
424
425 $accepted_countries = array(
426 'US',
427 'CA',
428 'GB',
429 'AU',
430 'JP',
431 );
432
433 $base_location = wc_get_base_location();
434
435 if ( isset( $base_location['country'] ) && ! in_array( $base_location['country'], $accepted_countries, true ) ) {
436
437 $this->get_admin_notice_handler()->add_admin_notice(
438 sprintf(
439 /* translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag, %3$s - 2-character country code, %4$s - comma separated list of 2-character country codes */
440 __( '%1$sWooCommerce Square:%2$s Your base country is %3$s, but Square can’t accept transactions from merchants outside of %4$s.', 'woocommerce-square' ),
441 '<strong>',
442 '</strong>',
443 esc_html( $base_location['country'] ),
444 esc_html( Framework\SV_WC_Helper::list_array_items( $accepted_countries ) )
445 ),
446 'wc-square-base-location',
447 array(
448 'notice_class' => 'notice-error',
449 )
450 );
451 }
452 }
453
454
455 /**
456 * Adds a notice when background processing is not supported.
457 *
458 * @since 2.0.0
459 */
460 protected function add_background_processing_notice() {
461
462 if ( $this->get_settings_handler()->is_product_sync_enabled() && ! $this->get_background_job_handler()->test_connection() ) {
463
464 $this->get_admin_notice_handler()->add_admin_notice(
465 sprintf(
466 /* translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag, %3$s - <a> tag, %4$s - </a> tag */
467 __( '%1$sWooCommerce Square:%2$s It looks like your site does not support background processing, which means large numbers of products may not sync successfully with Square. %3$sRead more here%4$s on how to resolve this.', 'woocommerce-square' ),
468 '<strong>',
469 '</strong>',
470 '<a href="https://docs.woocommerce.com/document/woocommerce-square/#sync-issues" target="_blank">',
471 '</a>'
472 ),
473 'wc-square-background-processing',
474 array(
475 'notice_class' => 'notice-warning',
476 )
477 );
478 }
479 }
480
481 /**
482 * Adds a notice if no refresh token has been cached.
483 *
484 * @since 2.0.5
485 */
486 protected function add_missing_refresh_token_notice() {
487 if ( $this->get_settings_handler()->is_sandbox() ) {
488 return;
489 }
490
491 $refresh_token = '';
492 $settings_handler = $this->get_settings_handler();
493
494 if ( method_exists( $settings_handler, 'get_access_token' ) ) {
495 $access_token = $settings_handler->get_access_token();
496 if ( empty( $access_token ) ) {
497 // We are already in a disconnected state, don't show the warning.
498 return;
499 }
500 }
501
502 if ( method_exists( $settings_handler, 'get_refresh_token' ) ) {
503 $refresh_token = $settings_handler->get_refresh_token();
504 }
505
506 if ( empty( $refresh_token ) ) {
507 $this->get_admin_notice_handler()->add_admin_notice(
508 sprintf(
509 /* translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag, %3$s - <a> tag, %4$s - </a> tag */
510 __( '%1$sWooCommerce Square:%2$s Automatic refreshing of the connection to Square is inactive. Please disconnect and reconnect to resolve.', 'woocommerce-square' ),
511 '<strong>',
512 '</strong>'
513 ),
514 'wc-square-missing-refresh-token',
515 array(
516 'dismissible' => false,
517 'notice_class' => 'notice-error',
518 )
519 );
520 }
521 }
522
523
524 /**
525 * Adds a tax-inclusive admin warning to product pages.
526 *
527 * @since 2.0.0
528 */
529 protected function add_tax_inclusive_pricing_notice() {
530 global $typenow;
531
532 // only show on product edit pages when configured that prices include tax
533 if ( 'product' === $typenow && isset( $_GET['action'], $_GET['post'] ) && 'edit' === $_GET['action'] && wc_prices_include_tax() && $this->get_settings_handler()->is_product_sync_enabled() ) {
534
535 $product = wc_get_product( (int) $_GET['post'] );
536
537 // only show for products configured as taxable and sync with Square
538 if ( $product instanceof \WC_Product && $product->is_taxable() && Product::is_synced_with_square( $product ) ) {
539
540 $this->get_admin_notice_handler()->add_admin_notice(
541 sprintf(
542 __( '%1$sWooCommerce Square:%2$s Product prices are entered inclusive of tax, but Square does not support syncing tax-inclusive prices. Please make sure your Square tax rates match your WooCommerce tax rates.', 'woocommerce-square' ),
543 '<strong>',
544 '</strong>'
545 ),
546 'wc-square-tax-inclusive',
547 array(
548 'notice_class' => 'notice-warning',
549 )
550 );
551 }
552 }
553 }
554
555
556 /**
557 * Adds admin notices for currency issues.
558 *
559 * @since 2.0.0
560 */
561 protected function add_currency_admin_notices() {
562
563 parent::add_currency_admin_notices();
564
565 if ( isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && $this->get_settings_handler()->is_connected() ) {
566
567 foreach ( $this->get_settings_handler()->get_locations() as $location ) {
568
569 if ( $this->get_settings_handler()->get_location_id() === $location->getId() && get_woocommerce_currency() !== $location->getCurrency() ) {
570
571 $this->get_admin_notice_handler()->add_admin_notice(
572 sprintf(
573 __( 'Heads up! Your store currency is %1$s but your configured Square business location currency is %2$s, so payments cannot be processed. Please %3$schoose a different business location%4$s or change your %5$sshop currency%6$s.', 'woocommerce-square' ),
574 '<strong>' . esc_html( get_woocommerce_currency() ) . '</strong>',
575 '<strong>' . esc_html( $location->getCurrency() ) . '</strong>',
576 '<a href="' . esc_url( $this->get_settings_url() ) . '">',
577 '</a>',
578 '<a href="' . esc_url( admin_url( 'admin.php?page=wc-settings' ) ) . '">',
579 '</a>'
580 ),
581 'wc-square-currency-mismatch',
582 array(
583 'notice_class' => 'notice-error',
584 )
585 );
586 }
587 }
588 }
589 }
590
591
592 /** Helper methods ************************************************************************************************/
593
594
595 /**
596 * Returns an idempotency key to be used in Square API requests.
597 *
598 * @since 2.0.0
599 *
600 * @param string $key_input
601 * @return string
602 */
603 public function get_idempotency_key( $key_input = '' ) {
604
605 if ( '' === $key_input ) {
606 $key_input = uniqid( '', false );
607 }
608
609 /**
610 * Filters an idempotency key.
611 *
612 * @since 2.0.0
613 *
614 * @param string $key_input
615 */
616 return apply_filters( 'wc_square_idempotency_key', md5( get_option( 'siteurl' ) ) . ':' . $key_input );
617 }
618
619
620 /** Conditional methods *******************************************************************************************/
621
622
623 /**
624 * Determines if viewing the plugin settings.
625 *
626 * @since 2.0.0
627 *
628 * @return bool
629 */
630 public function is_plugin_settings() {
631
632 return parent::is_plugin_settings() || ( isset( $_GET['page'], $_GET['tab'] ) && 'wc-settings' === $_GET['page'] && self::PLUGIN_ID === $_GET['tab'] );
633 }
634
635
636 /** Getter methods ************************************************************************************************/
637
638
639 /**
640 * Gets the main Square API handler.
641 *
642 * @since 2.0.0
643 *
644 * @param string|null $access_token API access token
645 * @return API
646 */
647 public function get_api( $access_token = null, $is_sandbox = null ) {
648
649 if ( ! $access_token ) {
650 $access_token = $this->get_settings_handler()->get_access_token();
651 }
652
653 if ( is_null( $is_sandbox ) ) {
654 $is_sandbox = $this->get_settings_handler()->is_sandbox();
655 }
656
657 return new API( $access_token, $is_sandbox );
658 }
659
660
661 /**
662 * Gets the connection handler.
663 *
664 * @since 2.0.0
665 *
666 * @return Handlers\Connection
667 */
668 public function get_connection_handler() {
669
670 return $this->connection_handler;
671 }
672
673
674 /**
675 * Gets the sync handler instance.
676 *
677 * @since 2.0.0
678 *
679 * @return Sync
680 */
681 public function get_sync_handler() {
682
683 return $this->sync_handler;
684 }
685
686
687 /**
688 * Gets the background sync handler instance.
689 *
690 * @since 2.0.0
691 *
692 * @return Background_Job
693 */
694 public function get_background_job_handler() {
695
696 return $this->background_job_handler;
697 }
698
699
700 /**
701 * Gets the settings handler instance.
702 *
703 * @since 2.0.0
704 *
705 * @return Settings
706 */
707 public function get_settings_handler() {
708
709 return $this->settings_handler;
710 }
711
712
713 /**
714 * Gets the admin handler instance.
715 *
716 * @since 2.0.0
717 *
718 * @return Admin|null
719 */
720 public function get_admin_handler() {
721
722 // throw a notice if calling before admin_init
723 Framework\SV_WC_Helper::maybe_doing_it_early( 'admin_init', __METHOD__, '2.0.0' );
724
725 return $this->admin_handler;
726 }
727
728
729 /**
730 * Gets the email handler instance.
731 *
732 * @since 2.0.0
733 *
734 * @return Email
735 */
736 public function get_email_handler() {
737
738 return $this->email_handler;
739 }
740
741
742 /**
743 * Gets the order handler instance.
744 *
745 * @since 2.0.0
746 *
747 * @return Order
748 */
749 public function get_order_handler() {
750
751 return $this->order_handler;
752 }
753
754 /**
755 * Get the products handler instance/
756 *
757 * @since 2.0.8
758 *
759 * @return Products
760 */
761 public function get_products_handler() {
762 return $this->products_handler;
763 }
764
765
766 /**
767 * Gets the deprecated hook details.
768 *
769 * @see Framework\SV_WC_Hook_Deprecator
770 *
771 * @since 2.0.0
772 *
773 * @return array
774 */
775 protected function get_deprecated_hooks() {
776
777 // the following are filters, except when an action is explicitly mentioned
778 $v2_0_0_removed_hooks = array(
779
780 // to filter the locale, the default WordPress filter should be used:
781 'woocommerce_square_plugin_locale' => array(
782 'replacement' => 'plugin_locale',
783 'map' => true,
784 ),
785
786 // sync square product variation properties
787 'woocommerce_square_currency' => array(), // used when passing a WooCommerce product price into a Square ItemVariation
788 'wc_square_sync_to_square_price' => array(), // used when passing a WooCommerce product price into a Square ItemVariation
789 'woocommerce_square_format_price' => array(), // formats the price coming from Square
790 'woocommerce_square_sync_from_square_description' => array(), // flag whether to add a description to created item
791
792 // we no longer filter inventory type in v2.0.0 and timeout is handled by background job differently
793 'woocommerce_square_inventory_type' => array(),
794 'woocommerce_square_inventory_sync_timeout_limit' => array(),
795 'woocommerce_square_inventory_poll_frequency' => array(),
796
797 // Square payment
798 'woocommerce_square_payment_form_trigger_element' => array(),
799 'woocommerce_square_payment_order_note' => array(
800 'replacement' => 'wc_square_payment_order_note',
801 'map' => true,
802 ),
803 'woocommerce_square_description' => array(), // front end payment fields description
804
805 // most gateway properties and settings can be mapped to new filters:
806 'woocommerce_square_api_url' => array(
807 'replacement' => 'wc_square_api_url',
808 'map' => true,
809 ), // filter is reinstated with name change for consistency
810 'woocommerce_square_payment_gateway_is_available' => array(
811 'replacement' => 'wc_gateway_square_credit_card_is_available',
812 'map' => true,
813 ), // filter handled by SkyVerge Framework
814 'woocommerce_square_integration_settings_args' => array(
815 'replacement' => 'woocommerce_settings_api_form_fields_square',
816 'map' => true,
817 ), // filters gateway settings
818 'woocommerce_square_integration_custom_settings' => array(
819 'replacement' => 'woocommerce_settings_tabs_square',
820 'map' => true,
821 ), // settings action hook
822
823 // API requests filters, these are handled differently and can't be mapped:
824 'woocommerce_square_request_args' => array(),
825 'woocommerce_square_request_retries' => array(),
826
827 // transients are no longer used to handle these cache types:
828 'woocommerce_square_business_location_cache' => array(),
829 'woocommerce_square_item_sku_cache' => array(),
830 'woocommerce_square_inventory_cache' => array(),
831 'woocommerce_square_sync_processing_ids_cache' => array(),
832 'woocommerce_square_manual_sync_processing_cache' => array(),
833 'woocommerce_square_syncing_square_ids_cache' => array(),
834 'woocommerce_square_syncing_wc_product_ids_cache' => array(),
835
836 // when a bulk sync action is triggered (action hook):
837 'woocommerce_square_bulk_syncing_square_to_wc' => array(),
838
839 // get_posts args filter, the new implementation has different scope:
840 'woocommerce_square_get_all_product_ids_args' => array(),
841
842 // idempotency key
843 'woocommerce_square_idempotency_key' => array(
844 'replacement' => 'wc_square_idempotency_key',
845 'map' => true,
846 ),
847
848 );
849
850 // add common array data for all removed hooks in version 2.0.0
851 foreach ( array_keys( $v2_0_0_removed_hooks ) as $hook_name ) {
852 $v2_0_0_removed_hooks[ $hook_name ]['version'] = '2.0.0';
853 $v2_0_0_removed_hooks[ $hook_name ]['removed'] = true;
854 }
855
856 return $v2_0_0_removed_hooks;
857 }
858
859
860 /**
861 * Gets the plugin name.
862 *
863 * @since 2.0.0
864 *
865 * @return string
866 */
867 public function get_plugin_name() {
868
869 return __( 'WooCommerce Square', 'woocommerce-square' );
870 }
871
872
873 /**
874 * Gets the settings URL.
875 *
876 * @since 2.0.0
877 *
878 * @param null|string $gateway_id gateway ID
879 * @return string
880 */
881 public function get_settings_url( $gateway_id = null ) {
882
883 $params = array(
884 'page' => 'wc-settings',
885 'tab' => self::PLUGIN_ID,
886 );
887
888 return add_query_arg( $params, admin_url( 'admin.php' ) );
889 }
890
891
892 /**
893 * Gets the sale page URL.
894 *
895 * @since 2.0.0
896 *
897 * @return string
898 */
899 public function get_sales_page_url() {
900
901 return 'https://woocommerce.com/products/square/';
902 }
903
904
905 /**
906 * Gets the documentation URL.
907 *
908 * @since 2.0.0
909 *
910 * @return string
911 */
912 public function get_documentation_url() {
913
914 return 'https://docs.woocommerce.com/document/woocommerce-square/';
915 }
916
917
918 /**
919 * Gets the plugin reviews page URL.
920 *
921 * Used for the 'Reviews' plugin action and review prompts.
922 *
923 * @since 2.1.7
924 *
925 * @return string
926 */
927 public function get_reviews_url() {
928
929 return $this->get_sales_page_url() ? $this->get_sales_page_url() . '#comments' : '';
930 }
931
932
933 /**
934 * Gets the support URL.
935 *
936 * @since 2.0.0
937 *
938 * @return string
939 */
940 public function get_support_url() {
941
942 return 'https://woocommerce.com/my-account/create-a-ticket/?select=1770503';
943 }
944
945
946 /**
947 * Gets __DIR__.
948 *
949 * @since 2.0.0
950 *
951 * @return string
952 */
953 protected function get_file() {
954
955 return __DIR__;
956 }
957
958
959 /**
960 * Gets the singleton instance of the plugin.
961 *
962 * @since 2.0.0
963 *
964 * @return Plugin
965 */
966 public static function instance() {
967
968 if ( null === self::$instance ) {
969 self::$instance = new self();
970 }
971
972 return self::$instance;
973 }
974
975
976 }
977