PluginProbe
WooCommerce Square / 2.0.7
WooCommerce Square v2.0.7
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.0.7, at includes/Plugin.php

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