PluginProbe ʕ •ᴥ•ʔ
WooCommerce Square / 3.8.1
WooCommerce Square v3.8.1
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
assets 3 years ago build 3 years ago i18n 3 years ago includes 3 years ago templates 3 years ago vendor 3 years ago apple-developer-merchantid-domain-association 5 years ago changelog.txt 3 years ago license.txt 3 years ago readme.txt 3 years ago woocommerce-square.php 3 years ago
woocommerce-square.php
460 lines
1 <?php
2 /**
3 * Plugin Name: WooCommerce Square
4 * Version: 3.8.1
5 * Plugin URI: https://woocommerce.com/products/square/
6 * Requires at least: 5.8
7 * Tested up to: 6.2.0
8 * Requires PHP: 7.4
9 *
10 * Description: Adds ability to sync inventory between WooCommerce and Square POS. In addition, you can also make purchases through the Square payment gateway.
11 * Author: WooCommerce
12 * Author URI: https://www.woocommerce.com/
13 * Text Domain: woocommerce-square
14 * Domain Path: /i18n/languages/
15 *
16 * Copyright: © 2023 WooCommerce
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: 6.8
26 * WC tested up to: 7.6
27 */
28
29 defined( 'ABSPATH' ) || exit;
30
31 require_once plugin_dir_path( __FILE__ ) . 'vendor/woocommerce/action-scheduler/action-scheduler.php';
32
33 if ( ! defined( 'WC_SQUARE_PLUGIN_VERSION' ) ) {
34 define( 'WC_SQUARE_PLUGIN_VERSION', '3.8.1' ); // WRCS: DEFINED_VERSION.
35 }
36
37 if ( ! defined( 'WC_SQUARE_PLUGIN_URL' ) ) {
38 define( 'WC_SQUARE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
39 }
40
41 if ( ! defined( 'WC_SQUARE_PLUGIN_PATH' ) ) {
42 define( 'WC_SQUARE_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
43 }
44
45 /**
46 * The plugin loader class.
47 *
48 * @since 2.0.0
49 */
50 class WooCommerce_Square_Loader {
51
52
53 /** minimum PHP version required by this plugin */
54 const MINIMUM_PHP_VERSION = '7.4.0';
55
56 /** minimum WordPress version required by this plugin */
57 const MINIMUM_WP_VERSION = '5.8';
58
59 /** minimum WooCommerce version required by this plugin */
60 const MINIMUM_WC_VERSION = '6.8';
61
62 /**
63 * SkyVerge plugin framework version used by this plugin
64 * Constant is left as it is for legacy purposes.
65 **/
66 const FRAMEWORK_VERSION = '5.4.0';
67
68 /** the plugin name, for displaying notices */
69 const PLUGIN_NAME = 'Square for WooCommerce';
70
71
72 /** @var WooCommerce_Square_Loader single instance of this class */
73 private static $instance;
74
75 /** @var array the admin notices to add */
76 private $notices = array();
77
78
79 /**
80 * Constructs the class.
81 *
82 * @since 2.0.0
83 */
84 protected function __construct() {
85 add_action( 'admin_init', array( $this, 'add_plugin_notices' ) );
86 add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 );
87
88 // if the environment check fails, don't initialize the plugin.
89 if ( $this->is_environment_compatible() ) {
90 add_action( 'plugins_loaded', array( $this, 'init_plugin' ) );
91 add_action( 'woocommerce_blocks_payment_method_type_registration', array( $this, 'register_payment_method_block_integrations' ), 5, 1 );
92 add_action( 'before_woocommerce_init', array( $this, 'declare_hpos_compatibility' ) );
93 }
94 }
95
96
97 /**
98 * Cloning instances is forbidden due to singleton pattern.
99 *
100 * @since 2.0.0
101 */
102 public function __clone() {
103
104 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
105 _doing_it_wrong( __FUNCTION__, sprintf( 'You cannot clone instances of %s.', get_class( $this ) ), '2.0.0' );
106 }
107
108
109 /**
110 * Unserializing instances is forbidden due to singleton pattern.
111 *
112 * @since 2.0.0
113 */
114 public function __wakeup() {
115
116 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
117 _doing_it_wrong( __FUNCTION__, sprintf( 'You cannot unserialize instances of %s.', get_class( $this ) ), '2.0.0' );
118 }
119
120
121 /**
122 * Initializes the plugin.
123 *
124 * @since 2.0.0
125 */
126 public function init_plugin() {
127
128 if ( ! $this->plugins_compatible() ) {
129 return;
130 }
131
132 $this->load_framework();
133
134 // autoload plugin and vendor files
135 $loader = require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
136
137 // register plugin namespace with autoloader
138 $loader->addPsr4( 'WooCommerce\\Square\\', __DIR__ . '/includes' );
139
140 require_once plugin_dir_path( __FILE__ ) . 'includes/Functions.php';
141
142 // fire it up!
143 wc_square();
144 }
145
146
147 /**
148 * Loads the base framework classes.
149 *
150 * @since 2.0.0
151 */
152 protected function load_framework() {
153 require_once plugin_dir_path( __FILE__ ) . 'includes/Framework/Plugin.php';
154 require_once plugin_dir_path( __FILE__ ) . 'includes/Framework/PaymentGateway/Payment_Gateway_Plugin.php';
155 }
156
157
158 /**
159 * Gets the framework version in namespace form.
160 *
161 * @since 2.0.0
162 *
163 * @return string
164 */
165 protected function get_framework_version_namespace() {
166
167 return 'v' . str_replace( '.', '_', $this->get_framework_version() );
168 }
169
170
171 /**
172 * Gets the framework version used by this plugin.
173 *
174 * @since 2.0.0
175 *
176 * @return string
177 */
178 protected function get_framework_version() {
179
180 return self::FRAMEWORK_VERSION;
181 }
182
183 /**
184 * Adds notices for out-of-date WordPress and/or WooCommerce versions.
185 *
186 * @since 2.0.0
187 */
188 public function add_plugin_notices() {
189
190 if ( ! $this->is_wp_compatible() ) {
191
192 $this->add_admin_notice(
193 'update_wordpress',
194 'error',
195 sprintf(
196 '%s requires WordPress version %s or higher. Please %supdate WordPress &raquo;%s',
197 '<strong>' . self::PLUGIN_NAME .
198 '</strong>',
199 self::MINIMUM_WP_VERSION,
200 '<a href="' . esc_url( admin_url( 'update-core.php' ) ) . '">',
201 '</a>'
202 )
203 );
204 }
205
206 if ( ! $this->is_wc_compatible() ) {
207
208 $this->add_admin_notice(
209 'update_woocommerce',
210 'error',
211 sprintf(
212 '%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',
213 '<strong>' . self::PLUGIN_NAME . '</strong>',
214 self::MINIMUM_WC_VERSION,
215 '<a href="' . esc_url( admin_url( 'update-core.php' ) ) . '">',
216 '</a>',
217 '<a href="' . esc_url( 'https://downloads.wordpress.org/plugin/woocommerce.' . self::MINIMUM_WC_VERSION . '.zip' ) . '">',
218 '</a>'
219 )
220 );
221 }
222 }
223
224
225 /**
226 * Determines if the required plugins are compatible.
227 *
228 * @since 2.0.0
229 *
230 * @return bool
231 */
232 protected function plugins_compatible() {
233
234 return $this->is_wp_compatible() && $this->is_wc_compatible();
235 }
236
237
238 /**
239 * Determines if the WordPress compatible.
240 *
241 * @since 2.0.0
242 *
243 * @return bool
244 */
245 protected function is_wp_compatible() {
246
247 if ( ! self::MINIMUM_WP_VERSION ) {
248 return true;
249 }
250
251 return version_compare( get_bloginfo( 'version' ), self::MINIMUM_WP_VERSION, '>=' );
252 }
253
254
255 /**
256 * Determines if the WooCommerce compatible.
257 *
258 * @since 2.0.0
259 *
260 * @return bool
261 */
262 protected function is_wc_compatible() {
263
264 if ( ! self::MINIMUM_WC_VERSION ) {
265 return true;
266 }
267
268 return defined( 'WC_VERSION' ) && version_compare( WC_VERSION, self::MINIMUM_WC_VERSION, '>=' );
269 }
270
271
272 /**
273 * Deactivates the plugin.
274 *
275 * @since 2.0.0
276 */
277 protected function deactivate_plugin() {
278
279 deactivate_plugins( plugin_basename( __FILE__ ) );
280
281 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
282 if ( isset( $_GET['activate'] ) ) {
283 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
284 unset( $_GET['activate'] );
285 }
286 }
287
288
289 /**
290 * Adds an admin notice to be displayed.
291 *
292 * @since 2.0.0
293 *
294 * @param string $slug the slug for the notice
295 * @param string $class the css class for the notice
296 * @param string $message the notice message
297 */
298 public function add_admin_notice( $slug, $class, $message ) {
299
300 $this->notices[ $slug ] = array(
301 'class' => $class,
302 'message' => $message,
303 );
304 }
305
306
307 /**
308 * Displays any admin notices added with \WooCommerce_Square_Loader::add_admin_notice()
309 *
310 * @since 2.0.0
311 */
312 public function admin_notices() {
313
314 foreach ( (array) $this->notices as $notice_key => $notice ) {
315
316 ?>
317 <div class="<?php echo esc_attr( $notice['class'] ); ?>">
318 <p>
319 <?php
320 echo wp_kses(
321 $notice['message'],
322 array(
323 'a' => array(
324 'href' => array(),
325 'target' => array(),
326 ),
327 'code' => array(),
328 'strong' => array(),
329 'br' => array(),
330 )
331 );
332 ?>
333 </p>
334 </div>
335 <?php
336 }
337 }
338
339
340 /**
341 * Determines if the server environment is compatible with this plugin.
342 *
343 * Override this method to add checks for more than just the PHP version.
344 *
345 * @since 2.0.0
346 *
347 * @return bool
348 */
349 public function is_environment_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 ) {
355 $error_message .= sprintf(
356 // translators: plugin name
357 __( '<strong>All features in %1$s have been disabled</strong> due to unsupported settings:<br>', 'woocommerce-square' ),
358 self::PLUGIN_NAME
359 );
360 }
361
362 if ( ! $is_php_valid ) {
363 $error_message .= sprintf(
364 // translators: minimum PHP version, current PHP version
365 __( '&bull;&nbsp;<strong>Invalid PHP version: </strong>The minimum PHP version required is %1$s. You are running %2$s.<br>', 'woocommerce-square' ),
366 self::MINIMUM_PHP_VERSION,
367 PHP_VERSION
368 );
369 }
370
371 if ( ! $is_opcache_config_valid ) {
372 $error_message .= sprintf(
373 // translators: link to documentation
374 __( '&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.', 'woocommerce-square' ),
375 'https://woocommerce.com/document/woocommerce-square/troubleshooting/#section-3'
376 );
377 }
378
379 if ( ! empty( $error_message ) ) {
380 $this->add_admin_notice(
381 'bad_environment',
382 'error',
383 $error_message
384 );
385 }
386
387 return $is_php_valid && $is_opcache_config_valid;
388 }
389
390 /**
391 * Declares support for HPOS.
392 */
393 public function declare_hpos_compatibility() {
394 if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
395 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
396 }
397 }
398
399 /**
400 * Returns true if opcache.save_comments is enabled.
401 *
402 * @since 3.0.2
403 *
404 * @return boolean
405 */
406 protected function is_opcache_save_message_enabled() {
407 $zend_optimizer_plus = extension_loaded( 'Zend Optimizer+' ) && '0' === ( ini_get( 'zend_optimizerplus.save_comments' ) || '0' === ini_get( 'opcache.save_comments' ) );
408 $zend_opcache = extension_loaded( 'Zend OPcache' ) && '0' === ini_get( 'opcache.save_comments' );
409
410 return ! ( $zend_optimizer_plus || $zend_opcache );
411 }
412
413 /**
414 * Returns true if the PHP version of the environment
415 * meets the requirement.
416 *
417 * @since 3.0.2
418 *
419 * @return boolean
420 */
421 protected function is_php_version_valid() {
422 return version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '>=' );
423 }
424
425 /**
426 * Register the Square Credit Card checkout block integration class
427 *
428 * @since 2.5.0
429 */
430 public function register_payment_method_block_integrations( $payment_method_registry ) {
431 if ( class_exists( '\Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
432 $payment_method_registry->register( new WooCommerce\Square\Gateway\Blocks_Handler() );
433 }
434 }
435
436
437 /**
438 * Gets the main plugin loader instance.
439 *
440 * Ensures only one instance can be loaded.
441 *
442 * @since 2.0.0
443 *
444 * @return \WooCommerce_Square_Loader
445 */
446 public static function instance() {
447
448 if ( null === self::$instance ) {
449 self::$instance = new self();
450 }
451
452 return self::$instance;
453 }
454
455
456 }
457
458 // fire it up!
459 WooCommerce_Square_Loader::instance();
460