From e30332892d9cc0d6f58c4e1cb71f6f6d9eb401a8 Mon Sep 17 00:00:00 2001 From: CatalinMatea Date: Fri, 20 Jan 2023 16:39:46 +0200 Subject: [PATCH 1/4] add dependencies check --- globalpayments-gateway-provider-for-woocommerce.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/globalpayments-gateway-provider-for-woocommerce.php b/globalpayments-gateway-provider-for-woocommerce.php index 4d69067..b042811 100644 --- a/globalpayments-gateway-provider-for-woocommerce.php +++ b/globalpayments-gateway-provider-for-woocommerce.php @@ -87,3 +87,12 @@ function globalpayments_update_plugin_version( WP_Upgrader $wp_upgrader, $hook_e } } add_action( 'upgrader_process_complete', 'globalpayments_update_plugin_version', 10, 2 ); + +$requiredExtensions = [ 'curl', 'dom', 'openssl', 'json', 'zlib', 'intl', 'mbstring', 'xml' ]; +foreach ($requiredExtensions as $ext) { + if (!extension_loaded($ext)) { + add_action( 'admin_notices', function () use ($ext) { + echo '

The GlobalPayments WooCommerce plugin requires the ' . $ext . ' extension.' . '

'; + }); + } +} From 7f85fac91a7d30bd1c22ed398cb07fc4d047334e Mon Sep 17 00:00:00 2001 From: CatalinMatea Date: Fri, 20 Jan 2023 17:20:44 +0200 Subject: [PATCH 2/4] add dependencies check --- ...ments-gateway-provider-for-woocommerce.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/globalpayments-gateway-provider-for-woocommerce.php b/globalpayments-gateway-provider-for-woocommerce.php index b042811..c46ce2e 100644 --- a/globalpayments-gateway-provider-for-woocommerce.php +++ b/globalpayments-gateway-provider-for-woocommerce.php @@ -15,6 +15,16 @@ return; } +$requiredExtensions = [ 'curl', 'dom', 'openssl', 'json', 'zlib', 'intl', 'mbstring', 'xml' ]; +foreach ($requiredExtensions as $ext) { + if (!extension_loaded($ext)) { + add_action( 'admin_notices', function () use ($ext) { + $message = sprintf( __( 'The GlobalPayments WooCommerce plugin requires the %s extension.', 'globalpayments-gateway-provider-for-woocommerce' ), $ext ); + echo '

' . $message . '

'; + }); + } +} + /** * Autoload SDK. */ @@ -87,12 +97,3 @@ function globalpayments_update_plugin_version( WP_Upgrader $wp_upgrader, $hook_e } } add_action( 'upgrader_process_complete', 'globalpayments_update_plugin_version', 10, 2 ); - -$requiredExtensions = [ 'curl', 'dom', 'openssl', 'json', 'zlib', 'intl', 'mbstring', 'xml' ]; -foreach ($requiredExtensions as $ext) { - if (!extension_loaded($ext)) { - add_action( 'admin_notices', function () use ($ext) { - echo '

The GlobalPayments WooCommerce plugin requires the ' . $ext . ' extension.' . '

'; - }); - } -} From c496bf41fc3f19666db03a741a6a62c791739965 Mon Sep 17 00:00:00 2001 From: CatalinMatea Date: Mon, 23 Jan 2023 13:56:17 +0200 Subject: [PATCH 3/4] add dependencies check --- ...ments-gateway-provider-for-woocommerce.php | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/globalpayments-gateway-provider-for-woocommerce.php b/globalpayments-gateway-provider-for-woocommerce.php index c46ce2e..83cf72c 100644 --- a/globalpayments-gateway-provider-for-woocommerce.php +++ b/globalpayments-gateway-provider-for-woocommerce.php @@ -7,24 +7,48 @@ * Requires PHP: 7.1 * WC tested up to: 7.2.2 * Author: Global Payments -*/ + */ defined( 'ABSPATH' ) || exit; if ( version_compare( PHP_VERSION, '7.1', '<' ) ) { + add_action( 'admin_notices', function () { + $message = sprintf( __( 'Your PHP version is %s but GlobalPayments For WooCommerce requires version 7.1+.', 'globalpayments-gateway-provider-for-woocommerce' ), PHP_VERSION ); + echo '

' . $message . '

'; + } ); + return; } -$requiredExtensions = [ 'curl', 'dom', 'openssl', 'json', 'zlib', 'intl', 'mbstring', 'xml' ]; -foreach ($requiredExtensions as $ext) { - if (!extension_loaded($ext)) { - add_action( 'admin_notices', function () use ($ext) { - $message = sprintf( __( 'The GlobalPayments WooCommerce plugin requires the %s extension.', 'globalpayments-gateway-provider-for-woocommerce' ), $ext ); - echo '

' . $message . '

'; - }); +register_activation_hook( __FILE__, 'plugin_activation' ); + +function plugin_activation() { + $requiredExtensions = [ 'curl', 'dom', 'openssl', 'json', 'zlib', 'intl', 'mbstring', 'xml' ]; + foreach ( $requiredExtensions as $ext ) { + if ( ! extension_loaded( $ext ) ) { + $notices = get_option( 'plugin_deferred_admin_notices', array() ); + $notices[] = sprintf( __( 'The GlobalPayments WooCommerce plugin requires the %s extension.', 'globalpayments-gateway-provider-for-woocommerce' ), $ext ); + update_option( 'plugin_deferred_admin_notices', $notices ); + } + } +} + +add_action( 'admin_notices', 'plugin_admin_notices' ); +function plugin_admin_notices() { + if ( $notices = get_option( 'plugin_deferred_admin_notices' ) ) { + foreach ( $notices as $notice ) { + echo "

$notice

"; + } + delete_option( 'plugin_deferred_admin_notices' ); + deactivate_plugins( __FILE__ ); } } +register_deactivation_hook( __FILE__, 'plugin_deactivation' ); +function plugin_deactivation() { + delete_option( 'plugin_deferred_admin_notices' ); +} + /** * Autoload SDK. */ From d7724f411bbce2cc785fd2779b638b9674ecb680 Mon Sep 17 00:00:00 2001 From: CatalinMatea Date: Mon, 30 Jan 2023 11:42:14 +0200 Subject: [PATCH 4/4] add dependencies check --- ...ments-gateway-provider-for-woocommerce.php | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/globalpayments-gateway-provider-for-woocommerce.php b/globalpayments-gateway-provider-for-woocommerce.php index 83cf72c..5c1945b 100644 --- a/globalpayments-gateway-provider-for-woocommerce.php +++ b/globalpayments-gateway-provider-for-woocommerce.php @@ -20,33 +20,33 @@ return; } -register_activation_hook( __FILE__, 'plugin_activation' ); +register_activation_hook( __FILE__, 'globalpayments_plugin_activation' ); -function plugin_activation() { +function globalpayments_plugin_activation() { $requiredExtensions = [ 'curl', 'dom', 'openssl', 'json', 'zlib', 'intl', 'mbstring', 'xml' ]; foreach ( $requiredExtensions as $ext ) { if ( ! extension_loaded( $ext ) ) { - $notices = get_option( 'plugin_deferred_admin_notices', array() ); + $notices = get_option( 'globalpayments_plugin_deferred_admin_notices', array() ); $notices[] = sprintf( __( 'The GlobalPayments WooCommerce plugin requires the %s extension.', 'globalpayments-gateway-provider-for-woocommerce' ), $ext ); - update_option( 'plugin_deferred_admin_notices', $notices ); + update_option( 'globalpayments_plugin_deferred_admin_notices', $notices ); } } } -add_action( 'admin_notices', 'plugin_admin_notices' ); -function plugin_admin_notices() { - if ( $notices = get_option( 'plugin_deferred_admin_notices' ) ) { +add_action( 'admin_notices', 'globalpayments_plugin_admin_notices' ); +function globalpayments_plugin_admin_notices() { + if ( $notices = get_option( 'globalpayments_plugin_deferred_admin_notices' ) ) { foreach ( $notices as $notice ) { echo "

$notice

"; } - delete_option( 'plugin_deferred_admin_notices' ); + delete_option( 'globalpayments_plugin_deferred_admin_notices' ); deactivate_plugins( __FILE__ ); } } -register_deactivation_hook( __FILE__, 'plugin_deactivation' ); -function plugin_deactivation() { - delete_option( 'plugin_deferred_admin_notices' ); +register_deactivation_hook( __FILE__, 'globalpayments_plugin_deactivation' ); +function globalpayments_plugin_deactivation() { + delete_option( 'globalpayments_plugin_deferred_admin_notices' ); } /**