PluginProbe ʕ •ᴥ•ʔ
WooCommerce Square / 5.5.0
WooCommerce Square v5.5.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 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 / woocommerce-square.php
woocommerce-square Last commit date
build 2 days ago i18n 2 days ago includes 2 days ago templates 1 year ago vendor 2 days ago apple-developer-merchantid-domain-association 2 years ago changelog.txt 2 days ago license.txt 3 years ago readme.txt 2 days ago woocommerce-square.php 2 days ago
woocommerce-square.php
557 lines
1 <?php
2 /**
3 * Plugin Name: WooCommerce Square
4 * Requires Plugins: woocommerce
5 * Version: 5.5.0
6 * Plugin URI: https://woocommerce.com/products/square/
7 * Requires at least: 6.9
8 * Tested up to: 7.1
9 * Requires PHP: 7.4
10 * PHP tested up to: 8.4
11 *
12 * Description: Securely accept payments, synchronize sales, and seamlessly manage inventory and product data between WooCommerce and Square POS.
13 * Author: WooCommerce
14 * Author URI: https://www.woocommerce.com/
15 * Text Domain: woocommerce-square
16 * Domain Path: /i18n/languages/
17 *
18 * License: GPL-3.0-or-later
19 * License URI: http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 or later
20 *
21 * @author WooCommerce
22 * @copyright Copyright (c) 2019, Automattic, Inc.
23 * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 or later
24 *
25 * WC requires at least: 10.9
26 * WC tested up to: 11.1
27 */
28
29 defined( 'ABSPATH' ) || exit;
30
31 if ( ! defined( 'WC_SQUARE_PLUGIN_VERSION' ) ) {
32 define( 'WC_SQUARE_PLUGIN_VERSION', '5.5.0' ); // WRCS: DEFINED_VERSION.
33 }
34
35 if ( ! defined( 'WC_SQUARE_PLUGIN_URL' ) ) {
36 define( 'WC_SQUARE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
37 }
38
39 if ( ! defined( 'WC_SQUARE_PLUGIN_PATH' ) ) {
40 define( 'WC_SQUARE_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
41 }
42
43 if ( ! defined( 'WC_SQUARE_OPTION_ANY' ) ) {
44 define( 'WC_SQUARE_OPTION_ANY', 'Any' );
45 }
46
47 if ( ! defined( 'WC_SQUARE_SYNC_ORDERS_EVENT_HOOK' ) ) {
48 define( 'WC_SQUARE_SYNC_ORDERS_EVENT_HOOK', 'wc_square_sync_orders' );
49 }
50
51 /**
52 * The plugin loader class.
53 *
54 * @since 2.0.0
55 */
56 class WooCommerce_Square_Loader {
57
58
59 /** minimum PHP version required by this plugin */
60 const MINIMUM_PHP_VERSION = '7.4.0';
61
62 /** minimum WordPress version required by this plugin */
63 const MINIMUM_WP_VERSION = '6.9';
64
65 /** minimum WooCommerce version required by this plugin */
66 const MINIMUM_WC_VERSION = '10.9';
67
68 /**
69 * SkyVerge plugin framework version used by this plugin
70 * Constant is left as it is for legacy purposes.
71 **/
72 const FRAMEWORK_VERSION = '5.4.0';
73
74 /** the plugin name, for displaying notices */
75 const PLUGIN_NAME = 'Square for WooCommerce';
76
77
78 /** @var WooCommerce_Square_Loader single instance of this class */
79 private static $instance;
80
81 /** @var array the admin notices to add */
82 private $notices = array();
83
84
85 /**
86 * Constructs the class.
87 *
88 * @since 2.0.0
89 */
90 protected function __construct() {
91 add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 );
92 add_action( 'before_woocommerce_init', array( $this, 'declare_features_compatibility' ) );
93 /*
94 * Bootstrap the extension on plugins_loaded.
95 *
96 * This ensures that the extension is loaded after WooCommerce Core and to
97 * ensure the WC_VERSION constant is defined prior to checking for compatibility.
98 */
99 add_action( 'plugins_loaded', array( $this, 'init_plugin' ) );
100 }
101
102
103 /**
104 * Cloning instances is forbidden due to singleton pattern.
105 *
106 * @since 2.0.0
107 */
108 public function __clone() {
109
110 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
111 _doing_it_wrong( __FUNCTION__, sprintf( 'You cannot clone instances of %s.', get_class( $this ) ), '2.0.0' );
112 }
113
114
115 /**
116 * Unserializing instances is forbidden due to singleton pattern.
117 *
118 * @since 2.0.0
119 */
120 public function __wakeup() {
121
122 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
123 _doing_it_wrong( __FUNCTION__, sprintf( 'You cannot unserialize instances of %s.', get_class( $this ) ), '2.0.0' );
124 }
125
126
127 /**
128 * Initializes the plugin.
129 *
130 * @since 2.0.0
131 */
132 public function init_plugin() {
133
134 if ( ! $this->is_environment_compatible() ) {
135 return;
136 }
137
138 $this->load_framework();
139
140 // autoload plugin and vendor files
141 $loader = require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
142
143 // register plugin namespace with autoloader
144 if ( is_object( $loader ) && method_exists( $loader, 'addPsr4' ) ) {
145 $loader->addPsr4( 'WooCommerce\\Square\\', __DIR__ . '/includes' );
146 } else {
147 // require_once returns true rather than the ClassLoader when something loaded the same
148 // autoloader first, which is what happens under PHPUnit. Register the namespace directly
149 // so the plugin still resolves its own classes instead of fataling here.
150 spl_autoload_register(
151 static function ( $class_name ) {
152 $prefix = 'WooCommerce\\Square\\';
153 if ( 0 !== strncmp( $class_name, $prefix, strlen( $prefix ) ) ) {
154 return;
155 }
156 $file = __DIR__ . '/includes/' . str_replace( '\\', '/', substr( $class_name, strlen( $prefix ) ) ) . '.php';
157 if ( file_exists( $file ) ) {
158 require_once $file;
159 }
160 }
161 );
162 }
163
164 require_once plugin_dir_path( __FILE__ ) . 'includes/Functions.php';
165
166 // fire it up!
167 wc_square();
168
169 add_action( 'woocommerce_blocks_payment_method_type_registration', array( $this, 'register_payment_method_block_integrations' ), 5, 1 );
170 }
171
172
173 /**
174 * Loads the base framework classes.
175 *
176 * @since 2.0.0
177 */
178 protected function load_framework() {
179 require_once plugin_dir_path( __FILE__ ) . 'includes/Framework/Plugin.php';
180 require_once plugin_dir_path( __FILE__ ) . 'includes/Framework/PaymentGateway/Payment_Gateway_Plugin.php';
181 }
182
183
184 /**
185 * Gets the framework version in namespace form.
186 *
187 * @since 2.0.0
188 *
189 * @return string
190 */
191 protected function get_framework_version_namespace() {
192
193 return 'v' . str_replace( '.', '_', $this->get_framework_version() );
194 }
195
196
197 /**
198 * Gets the framework version used by this plugin.
199 *
200 * @since 2.0.0
201 *
202 * @return string
203 */
204 protected function get_framework_version() {
205
206 return self::FRAMEWORK_VERSION;
207 }
208
209 /**
210 * Adds notices for out-of-date WordPress and/or WooCommerce versions.
211 *
212 * @since 2.0.0
213 * @deprecated 4.6.3 Use \WooCommerce_Square_Loader::is_environment_compatible() instead.
214 */
215 public function add_plugin_notices() {
216 _deprecated_function( __METHOD__, '4.6.3', '\WooCommerce_Square_Loader::is_environment_compatible()' );
217 $this->is_environment_compatible();
218 }
219
220
221 /**
222 * Determines if the required plugins are compatible.
223 *
224 * @since 2.0.0
225 * @deprecated 4.6.3 Use \WooCommerce_Square_Loader::is_environment_compatible() instead.
226 *
227 * @return bool
228 */
229 protected function plugins_compatible() {
230 _deprecated_function( __METHOD__, '4.6.3', '\WooCommerce_Square_Loader::is_environment_compatible()' );
231 return $this->is_environment_compatible();
232 }
233
234
235 /**
236 * Determines if the WordPress compatible.
237 *
238 * @since 2.0.0
239 *
240 * @return bool
241 */
242 protected function is_wp_compatible() {
243
244 if ( ! self::MINIMUM_WP_VERSION ) {
245 return true;
246 }
247
248 return version_compare( get_bloginfo( 'version' ), self::MINIMUM_WP_VERSION, '>=' );
249 }
250
251
252 /**
253 * Determines if the WooCommerce compatible.
254 *
255 * @since 2.0.0
256 *
257 * @return bool
258 */
259 protected function is_wc_compatible() {
260
261 if ( ! self::MINIMUM_WC_VERSION ) {
262 return true;
263 }
264
265 return defined( 'WC_VERSION' ) && version_compare( WC_VERSION, self::MINIMUM_WC_VERSION, '>=' );
266 }
267
268
269 /**
270 * Deactivates the plugin.
271 *
272 * @since 2.0.0
273 */
274 protected function deactivate_plugin() {
275
276 deactivate_plugins( plugin_basename( __FILE__ ) );
277
278 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
279 if ( isset( $_GET['activate'] ) ) {
280 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
281 unset( $_GET['activate'] );
282 }
283 }
284
285
286 /**
287 * Adds an admin notice to be displayed.
288 *
289 * @since 2.0.0
290 *
291 * @param string $slug the slug for the notice
292 * @param string $class the css class for the notice
293 * @param string $message the notice message
294 */
295 public function add_admin_notice( $slug, $class, $message ) {
296
297 $this->notices[ $slug ] = array(
298 'class' => $class,
299 'message' => $message,
300 );
301 }
302
303
304 /**
305 * Displays any admin notices added with \WooCommerce_Square_Loader::add_admin_notice()
306 *
307 * @since 2.0.0
308 */
309 public function admin_notices() {
310
311 foreach ( (array) $this->notices as $notice_key => $notice ) {
312
313 ?>
314 <div class="<?php echo esc_attr( $notice['class'] ); ?>">
315 <p>
316 <?php
317 echo wp_kses(
318 $notice['message'],
319 array(
320 'a' => array(
321 'href' => array(),
322 'target' => array(),
323 ),
324 'code' => array(),
325 'strong' => array(),
326 'br' => array(),
327 )
328 );
329 ?>
330 </p>
331 </div>
332 <?php
333 }
334 }
335
336
337 /**
338 * Determines if the server environment is compatible with this plugin.
339 *
340 * Override this method to add checks for more than just the PHP version.
341 *
342 * @since 2.0.0
343 *
344 * @return bool
345 */
346 public function is_environment_compatible() {
347 static $error_message_registered = false;
348 $is_wc_compatible = $this->is_wc_compatible();
349 $is_wp_compatible = $this->is_wp_compatible();
350 $is_php_valid = $this->is_php_version_valid();
351 $is_opcache_config_valid = $this->is_opcache_save_message_enabled();
352 $error_message = '';
353
354 if ( ! $is_php_valid || ! $is_opcache_config_valid || ! $is_wc_compatible || ! $is_wp_compatible ) {
355 if ( $error_message_registered ) {
356 // Error message has already been registered, do not register again.
357 return false;
358 }
359 $error_message .= sprintf(
360 // translators: plugin name
361 __( '<strong>All features in %1$s have been disabled</strong> due to unsupported settings:<br>', 'woocommerce-square' ),
362 self::PLUGIN_NAME
363 );
364 }
365
366 if ( ! $is_php_valid ) {
367 $error_message .= sprintf(
368 // translators: minimum PHP version, current PHP version
369 __( '&bull;&nbsp;<strong>Invalid PHP version: </strong>The minimum PHP version required is %1$s. You are running %2$s.<br>', 'woocommerce-square' ),
370 self::MINIMUM_PHP_VERSION,
371 PHP_VERSION
372 );
373 }
374
375 if ( ! $is_opcache_config_valid ) {
376 $error_message .= sprintf(
377 // translators: link to documentation
378 __( '&bull;&nbsp;<strong>Invalid OPcache config: </strong><a href="%s" target="_blank">Please ensure the <code>save_comments</code> PHP option is enabled.</a> You may need to contact your hosting provider to change caching options.<br />', 'woocommerce-square' ),
379 'https://woocommerce.com/document/woocommerce-square/troubleshooting/#recommended-caching-settings'
380 );
381 }
382
383 if ( ! $is_wc_compatible ) {
384 if ( ! defined( 'WC_VERSION' ) ) {
385 $error_message .= sprintf(
386 // translators: 1: Minimum required WooCommerce version.
387 __( '&bull;&nbsp;<strong>WooCommerce is not installed: </strong>The plugin requires WooCommerce version %1$s or later be installed.<br>', 'woocommerce-square' ),
388 self::MINIMUM_WC_VERSION
389 );
390 } else {
391 $error_message .= sprintf(
392 // translators: 1: Plugin name, 2: Minimum required WooCommerce version, 3: Opening link to upgrade screen, 4: Closing link, 5: Opening link to download page, 6: Closing link.
393 '&bull;&nbsp;%1$s requires WooCommerce version %2$s or higher. Please %3$supdate WooCommerce%4$s to the latest version, or %5$sdownload the minimum required version &raquo;%6$s<br>',
394 '<strong>' . self::PLUGIN_NAME . '</strong>',
395 self::MINIMUM_WC_VERSION,
396 '<a href="' . esc_url( admin_url( 'update-core.php' ) ) . '">',
397 '</a>',
398 '<a href="' . esc_url( $this->get_woocommerce_download_link( 'minimum' ) ) . '">',
399 '</a>'
400 );
401 }
402 }
403
404 if ( ! $is_wp_compatible ) {
405 $error_message .= sprintf(
406 // translators: 1: Plugin name, 2: Minimum required WordPress version, 3: Opening link to upgrade screen, 4: Closing link.
407 '&bull;&nbsp;%s requires WordPress version %s or higher. Please %supdate WordPress &raquo;%s<br>',
408 '<strong>' . self::PLUGIN_NAME . '</strong>',
409 self::MINIMUM_WP_VERSION,
410 '<a href="' . esc_url( admin_url( 'update-core.php' ) ) . '">',
411 '</a>'
412 );
413 }
414
415 if ( ! empty( $error_message ) && ! $error_message_registered ) {
416 $error_message_registered = true;
417 $this->add_admin_notice(
418 'bad_environment',
419 'error',
420 $error_message
421 );
422 }
423
424 return $is_php_valid && $is_opcache_config_valid && $is_wc_compatible && $is_wp_compatible;
425 }
426
427 /**
428 * Get the WooCommerce download link for a specific version.
429 *
430 * Ensures the download link is correct for major versions of WooCommerce by
431 * ensuring that specific download links match the tagged version and include
432 * three parts in the version number.
433 *
434 * @since 4.6.3
435 *
436 * @param string|int|float $version The version of WooCommerce to get the download link for.
437 * Accepts a version number in the forms of 'x', 'x.x' or 'x.x.x'.
438 * Accepts the strings 'minimum' and 'latest'.
439 * Defaults to 'latest'.
440 * @return string The download link for the WooCommerce version.
441 */
442 public function get_woocommerce_download_link( $version = 'latest' ) {
443 $version = (string) $version;
444 $version = strtolower( $version );
445
446 if ( preg_match( '/^(\d+\.)*(\d+)$/', $version ) || 'minimum' === $version ) {
447 if ( 'minimum' === $version ) {
448 $version_download_string = self::MINIMUM_WC_VERSION;
449 } else {
450 $version_download_string = $version;
451 }
452 $version_parts = explode( '.', $version_download_string );
453 /*
454 * Ensure the version string has at least 3 parts.
455 *
456 * Publicly major versions are listed as two parts, eg 6.7, but the
457 * tag published to the WordPress.org repository uses three parts,
458 * eg 6.7.0.
459 *
460 * This is to ensure the download link is correct.
461 */
462 $version_part_count = count( $version_parts ); // Coding standards don't allow for count() in the while condition.
463 while ( $version_part_count < 3 ) {
464 $version_parts[] = '0';
465 $version_part_count = count( $version_parts );
466 }
467 $version_download_string = implode( '.', $version_parts );
468 } else {
469 // Default to latest version.
470 $version_download_string = 'latest-stable';
471 }
472
473 return "https://downloads.wordpress.org/plugin/woocommerce.{$version_download_string}.zip";
474 }
475
476 /**
477 * Declares support for WooCommerce features.
478 */
479 public function declare_features_compatibility() {
480 if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
481 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
482
483 if ( ! $this->is_environment_compatible() ) {
484 /*
485 * Environment not compatible, do not configure features.
486 *
487 * The autoloader is not configured if the environment is not compatible,
488 * so calling the line below will result in a fatal error on such systems.
489 */
490 return;
491 }
492 }
493 }
494
495 /**
496 * Returns true if opcache.save_comments is enabled.
497 *
498 * @since 3.0.2
499 *
500 * @return boolean
501 */
502 protected function is_opcache_save_message_enabled() {
503 $zend_optimizer_plus = extension_loaded( 'Zend Optimizer+' ) && '0' === ( ini_get( 'zend_optimizerplus.save_comments' ) || '0' === ini_get( 'opcache.save_comments' ) );
504 $zend_opcache = extension_loaded( 'Zend OPcache' ) && '0' === ini_get( 'opcache.save_comments' );
505
506 return ! ( $zend_optimizer_plus || $zend_opcache );
507 }
508
509 /**
510 * Returns true if the PHP version of the environment
511 * meets the requirement.
512 *
513 * @since 3.0.2
514 *
515 * @return boolean
516 */
517 protected function is_php_version_valid() {
518 return version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '>=' );
519 }
520
521 /**
522 * Register the Square Credit Card checkout block integration class
523 *
524 * @since 2.5.0
525 */
526 public function register_payment_method_block_integrations( $payment_method_registry ) {
527 if ( class_exists( '\Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
528 $payment_method_registry->register( new WooCommerce\Square\Gateway\Blocks_Handler() );
529 $payment_method_registry->register( new WooCommerce\Square\Gateway\Cash_App_Pay_Blocks_Handler() );
530 }
531 }
532
533
534 /**
535 * Gets the main plugin loader instance.
536 *
537 * Ensures only one instance can be loaded.
538 *
539 * @since 2.0.0
540 *
541 * @return \WooCommerce_Square_Loader
542 */
543 public static function instance() {
544
545 if ( null === self::$instance ) {
546 self::$instance = new self();
547 }
548
549 return self::$instance;
550 }
551
552
553 }
554
555 // fire it up!
556 WooCommerce_Square_Loader::instance();
557