PluginProbe ʕ •ᴥ•ʔ
WooCommerce Square / 5.4.2
WooCommerce Square v5.4.2
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 15 hours ago i18n 15 hours ago includes 15 hours ago templates 1 year ago vendor 15 hours ago apple-developer-merchantid-domain-association 2 years ago changelog.txt 15 hours ago license.txt 3 years ago readme.txt 15 hours ago woocommerce-square.php 15 hours ago
woocommerce-square.php
539 lines
1 <?php
2 /**
3 * Plugin Name: WooCommerce Square
4 * Requires Plugins: woocommerce
5 * Version: 5.4.2
6 * Plugin URI: https://woocommerce.com/products/square/
7 * Requires at least: 6.9
8 * Tested up to: 7.0
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.8
26 * WC tested up to: 11.0
27 */
28
29 defined( 'ABSPATH' ) || exit;
30
31 if ( ! defined( 'WC_SQUARE_PLUGIN_VERSION' ) ) {
32 define( 'WC_SQUARE_PLUGIN_VERSION', '5.4.2' ); // 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.8';
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 $loader->addPsr4( 'WooCommerce\\Square\\', __DIR__ . '/includes' );
145
146 require_once plugin_dir_path( __FILE__ ) . 'includes/Functions.php';
147
148 // fire it up!
149 wc_square();
150
151 add_action( 'woocommerce_blocks_payment_method_type_registration', array( $this, 'register_payment_method_block_integrations' ), 5, 1 );
152 }
153
154
155 /**
156 * Loads the base framework classes.
157 *
158 * @since 2.0.0
159 */
160 protected function load_framework() {
161 require_once plugin_dir_path( __FILE__ ) . 'includes/Framework/Plugin.php';
162 require_once plugin_dir_path( __FILE__ ) . 'includes/Framework/PaymentGateway/Payment_Gateway_Plugin.php';
163 }
164
165
166 /**
167 * Gets the framework version in namespace form.
168 *
169 * @since 2.0.0
170 *
171 * @return string
172 */
173 protected function get_framework_version_namespace() {
174
175 return 'v' . str_replace( '.', '_', $this->get_framework_version() );
176 }
177
178
179 /**
180 * Gets the framework version used by this plugin.
181 *
182 * @since 2.0.0
183 *
184 * @return string
185 */
186 protected function get_framework_version() {
187
188 return self::FRAMEWORK_VERSION;
189 }
190
191 /**
192 * Adds notices for out-of-date WordPress and/or WooCommerce versions.
193 *
194 * @since 2.0.0
195 * @deprecated 4.6.3 Use \WooCommerce_Square_Loader::is_environment_compatible() instead.
196 */
197 public function add_plugin_notices() {
198 _deprecated_function( __METHOD__, '4.6.3', '\WooCommerce_Square_Loader::is_environment_compatible()' );
199 $this->is_environment_compatible();
200 }
201
202
203 /**
204 * Determines if the required plugins are compatible.
205 *
206 * @since 2.0.0
207 * @deprecated 4.6.3 Use \WooCommerce_Square_Loader::is_environment_compatible() instead.
208 *
209 * @return bool
210 */
211 protected function plugins_compatible() {
212 _deprecated_function( __METHOD__, '4.6.3', '\WooCommerce_Square_Loader::is_environment_compatible()' );
213 return $this->is_environment_compatible();
214 }
215
216
217 /**
218 * Determines if the WordPress compatible.
219 *
220 * @since 2.0.0
221 *
222 * @return bool
223 */
224 protected function is_wp_compatible() {
225
226 if ( ! self::MINIMUM_WP_VERSION ) {
227 return true;
228 }
229
230 return version_compare( get_bloginfo( 'version' ), self::MINIMUM_WP_VERSION, '>=' );
231 }
232
233
234 /**
235 * Determines if the WooCommerce compatible.
236 *
237 * @since 2.0.0
238 *
239 * @return bool
240 */
241 protected function is_wc_compatible() {
242
243 if ( ! self::MINIMUM_WC_VERSION ) {
244 return true;
245 }
246
247 return defined( 'WC_VERSION' ) && version_compare( WC_VERSION, self::MINIMUM_WC_VERSION, '>=' );
248 }
249
250
251 /**
252 * Deactivates the plugin.
253 *
254 * @since 2.0.0
255 */
256 protected function deactivate_plugin() {
257
258 deactivate_plugins( plugin_basename( __FILE__ ) );
259
260 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
261 if ( isset( $_GET['activate'] ) ) {
262 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
263 unset( $_GET['activate'] );
264 }
265 }
266
267
268 /**
269 * Adds an admin notice to be displayed.
270 *
271 * @since 2.0.0
272 *
273 * @param string $slug the slug for the notice
274 * @param string $class the css class for the notice
275 * @param string $message the notice message
276 */
277 public function add_admin_notice( $slug, $class, $message ) {
278
279 $this->notices[ $slug ] = array(
280 'class' => $class,
281 'message' => $message,
282 );
283 }
284
285
286 /**
287 * Displays any admin notices added with \WooCommerce_Square_Loader::add_admin_notice()
288 *
289 * @since 2.0.0
290 */
291 public function admin_notices() {
292
293 foreach ( (array) $this->notices as $notice_key => $notice ) {
294
295 ?>
296 <div class="<?php echo esc_attr( $notice['class'] ); ?>">
297 <p>
298 <?php
299 echo wp_kses(
300 $notice['message'],
301 array(
302 'a' => array(
303 'href' => array(),
304 'target' => array(),
305 ),
306 'code' => array(),
307 'strong' => array(),
308 'br' => array(),
309 )
310 );
311 ?>
312 </p>
313 </div>
314 <?php
315 }
316 }
317
318
319 /**
320 * Determines if the server environment is compatible with this plugin.
321 *
322 * Override this method to add checks for more than just the PHP version.
323 *
324 * @since 2.0.0
325 *
326 * @return bool
327 */
328 public function is_environment_compatible() {
329 static $error_message_registered = false;
330 $is_wc_compatible = $this->is_wc_compatible();
331 $is_wp_compatible = $this->is_wp_compatible();
332 $is_php_valid = $this->is_php_version_valid();
333 $is_opcache_config_valid = $this->is_opcache_save_message_enabled();
334 $error_message = '';
335
336 if ( ! $is_php_valid || ! $is_opcache_config_valid || ! $is_wc_compatible || ! $is_wp_compatible ) {
337 if ( $error_message_registered ) {
338 // Error message has already been registered, do not register again.
339 return false;
340 }
341 $error_message .= sprintf(
342 // translators: plugin name
343 __( '<strong>All features in %1$s have been disabled</strong> due to unsupported settings:<br>', 'woocommerce-square' ),
344 self::PLUGIN_NAME
345 );
346 }
347
348 if ( ! $is_php_valid ) {
349 $error_message .= sprintf(
350 // translators: minimum PHP version, current PHP version
351 __( '&bull;&nbsp;<strong>Invalid PHP version: </strong>The minimum PHP version required is %1$s. You are running %2$s.<br>', 'woocommerce-square' ),
352 self::MINIMUM_PHP_VERSION,
353 PHP_VERSION
354 );
355 }
356
357 if ( ! $is_opcache_config_valid ) {
358 $error_message .= sprintf(
359 // translators: link to documentation
360 __( '&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' ),
361 'https://woocommerce.com/document/woocommerce-square/troubleshooting/#recommended-caching-settings'
362 );
363 }
364
365 if ( ! $is_wc_compatible ) {
366 if ( ! defined( 'WC_VERSION' ) ) {
367 $error_message .= sprintf(
368 // translators: 1: Minimum required WooCommerce version.
369 __( '&bull;&nbsp;<strong>WooCommerce is not installed: </strong>The plugin requires WooCommerce version %1$s or later be installed.<br>', 'woocommerce-square' ),
370 self::MINIMUM_WC_VERSION
371 );
372 } else {
373 $error_message .= sprintf(
374 // 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.
375 '&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>',
376 '<strong>' . self::PLUGIN_NAME . '</strong>',
377 self::MINIMUM_WC_VERSION,
378 '<a href="' . esc_url( admin_url( 'update-core.php' ) ) . '">',
379 '</a>',
380 '<a href="' . esc_url( $this->get_woocommerce_download_link( 'minimum' ) ) . '">',
381 '</a>'
382 );
383 }
384 }
385
386 if ( ! $is_wp_compatible ) {
387 $error_message .= sprintf(
388 // translators: 1: Plugin name, 2: Minimum required WordPress version, 3: Opening link to upgrade screen, 4: Closing link.
389 '&bull;&nbsp;%s requires WordPress version %s or higher. Please %supdate WordPress &raquo;%s<br>',
390 '<strong>' . self::PLUGIN_NAME . '</strong>',
391 self::MINIMUM_WP_VERSION,
392 '<a href="' . esc_url( admin_url( 'update-core.php' ) ) . '">',
393 '</a>'
394 );
395 }
396
397 if ( ! empty( $error_message ) && ! $error_message_registered ) {
398 $error_message_registered = true;
399 $this->add_admin_notice(
400 'bad_environment',
401 'error',
402 $error_message
403 );
404 }
405
406 return $is_php_valid && $is_opcache_config_valid && $is_wc_compatible && $is_wp_compatible;
407 }
408
409 /**
410 * Get the WooCommerce download link for a specific version.
411 *
412 * Ensures the download link is correct for major versions of WooCommerce by
413 * ensuring that specific download links match the tagged version and include
414 * three parts in the version number.
415 *
416 * @since 4.6.3
417 *
418 * @param string|int|float $version The version of WooCommerce to get the download link for.
419 * Accepts a version number in the forms of 'x', 'x.x' or 'x.x.x'.
420 * Accepts the strings 'minimum' and 'latest'.
421 * Defaults to 'latest'.
422 * @return string The download link for the WooCommerce version.
423 */
424 public function get_woocommerce_download_link( $version = 'latest' ) {
425 $version = (string) $version;
426 $version = strtolower( $version );
427
428 if ( preg_match( '/^(\d+\.)*(\d+)$/', $version ) || 'minimum' === $version ) {
429 if ( 'minimum' === $version ) {
430 $version_download_string = self::MINIMUM_WC_VERSION;
431 } else {
432 $version_download_string = $version;
433 }
434 $version_parts = explode( '.', $version_download_string );
435 /*
436 * Ensure the version string has at least 3 parts.
437 *
438 * Publicly major versions are listed as two parts, eg 6.7, but the
439 * tag published to the WordPress.org repository uses three parts,
440 * eg 6.7.0.
441 *
442 * This is to ensure the download link is correct.
443 */
444 $version_part_count = count( $version_parts ); // Coding standards don't allow for count() in the while condition.
445 while ( $version_part_count < 3 ) {
446 $version_parts[] = '0';
447 $version_part_count = count( $version_parts );
448 }
449 $version_download_string = implode( '.', $version_parts );
450 } else {
451 // Default to latest version.
452 $version_download_string = 'latest-stable';
453 }
454
455 return "https://downloads.wordpress.org/plugin/woocommerce.{$version_download_string}.zip";
456 }
457
458 /**
459 * Declares support for WooCommerce features.
460 */
461 public function declare_features_compatibility() {
462 if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
463 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
464
465 if ( ! $this->is_environment_compatible() ) {
466 /*
467 * Environment not compatible, do not configure features.
468 *
469 * The autoloader is not configured if the environment is not compatible,
470 * so calling the line below will result in a fatal error on such systems.
471 */
472 return;
473 }
474 }
475 }
476
477 /**
478 * Returns true if opcache.save_comments is enabled.
479 *
480 * @since 3.0.2
481 *
482 * @return boolean
483 */
484 protected function is_opcache_save_message_enabled() {
485 $zend_optimizer_plus = extension_loaded( 'Zend Optimizer+' ) && '0' === ( ini_get( 'zend_optimizerplus.save_comments' ) || '0' === ini_get( 'opcache.save_comments' ) );
486 $zend_opcache = extension_loaded( 'Zend OPcache' ) && '0' === ini_get( 'opcache.save_comments' );
487
488 return ! ( $zend_optimizer_plus || $zend_opcache );
489 }
490
491 /**
492 * Returns true if the PHP version of the environment
493 * meets the requirement.
494 *
495 * @since 3.0.2
496 *
497 * @return boolean
498 */
499 protected function is_php_version_valid() {
500 return version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '>=' );
501 }
502
503 /**
504 * Register the Square Credit Card checkout block integration class
505 *
506 * @since 2.5.0
507 */
508 public function register_payment_method_block_integrations( $payment_method_registry ) {
509 if ( class_exists( '\Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
510 $payment_method_registry->register( new WooCommerce\Square\Gateway\Blocks_Handler() );
511 $payment_method_registry->register( new WooCommerce\Square\Gateway\Cash_App_Pay_Blocks_Handler() );
512 }
513 }
514
515
516 /**
517 * Gets the main plugin loader instance.
518 *
519 * Ensures only one instance can be loaded.
520 *
521 * @since 2.0.0
522 *
523 * @return \WooCommerce_Square_Loader
524 */
525 public static function instance() {
526
527 if ( null === self::$instance ) {
528 self::$instance = new self();
529 }
530
531 return self::$instance;
532 }
533
534
535 }
536
537 // fire it up!
538 WooCommerce_Square_Loader::instance();
539