Skip to content

Commit 90742cd

Browse files
committed
Allow :: is_environment_compatible() to be called multiple times.
1 parent 22df9ba commit 90742cd

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

woocommerce-square.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,18 @@ public function admin_notices() {
326326
* @return bool
327327
*/
328328
public function is_environment_compatible() {
329-
$is_wc_compatible = $this->is_wc_compatible();
330-
$is_wp_compatible = $this->is_wp_compatible();
331-
$is_php_valid = $this->is_php_version_valid();
332-
$is_opcache_config_valid = $this->is_opcache_save_message_enabled();
333-
$error_message = '';
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 = '';
334335

335336
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+
}
336341
$error_message .= sprintf(
337342
// translators: plugin name
338343
__( '<strong>All features in %1$s have been disabled</strong> due to unsupported settings:<br>', 'woocommerce-square' ),
@@ -389,7 +394,8 @@ public function is_environment_compatible() {
389394
);
390395
}
391396

392-
if ( ! empty( $error_message ) ) {
397+
if ( ! empty( $error_message ) && ! $error_message_registered ) {
398+
$error_message_registered = true;
393399
$this->add_admin_notice(
394400
'bad_environment',
395401
'error',
@@ -456,6 +462,10 @@ public function declare_features_compatibility() {
456462
if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
457463
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
458464

465+
if ( ! $this->is_environment_compatible() ) {
466+
// Environment not compatible, do not configure features.
467+
return;
468+
}
459469
new \WooCommerce\Square\Admin\Product_Editor_Compatibility();
460470
}
461471
}

0 commit comments

Comments
 (0)