Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/check dependencies #40

Open
wants to merge 4 commits into
base: release/next-release
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion globalpayments-gateway-provider-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +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 '<div class="notice notice-error"><p>' . $message . '</p></div>';
} );

return;
}

register_activation_hook( __FILE__, 'plugin_activation' );

function plugin_activation() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please prefix the function name with "globalpayments_" to avoid name collision with other plugins.

$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() );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please prefix the option name with "globalpayments_" instead of "plugin_" to avoid name collision with other plugins.

$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() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please prefix the function name with "globalpayments_" to avoid name collision with other plugins.

if ( $notices = get_option( 'plugin_deferred_admin_notices' ) ) {
foreach ( $notices as $notice ) {
echo "<div class='notice notice-error'><p>$notice</p></div>";
}
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.
*/
Expand Down