-
Notifications
You must be signed in to change notification settings - Fork 0
/
swedbank-pay-payment-menu.php
130 lines (112 loc) · 3.6 KB
/
swedbank-pay-payment-menu.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php // phpcs:disable
/*
* Plugin Name: Swedbank Pay Payment Menu
* Plugin URI: https://www.swedbankpay.com/
* Description: Provides the Swedbank Pay Payment Menu for WooCommerce.
* Author: Swedbank Pay
* Author URI: https://profiles.wordpress.org/swedbankpay/
* License: Apache License 2.0
* License URI: http://www.apache.org/licenses/LICENSE-2.0
* Version: 3.6.4
* Text Domain: swedbank-pay-woocommerce-checkout
* Domain Path: /languages
* WC requires at least: 5.5.1
* WC tested up to: 9.3.1
*/
use SwedbankPay\Checkout\WooCommerce\Swedbank_Pay_Plugin;
defined( 'ABSPATH' ) || exit;
include_once( dirname( __FILE__ ) . '/includes/class-swedbank-pay-plugin.php' );
/**
* @SuppressWarnings(PHPMD.CamelCaseClassName)
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
* @SuppressWarnings(PHPMD.CamelCaseParameterName)
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
* @SuppressWarnings(PHPMD.CamelCaseVariableName)
* @SuppressWarnings(PHPMD.MissingImport)
* @SuppressWarnings(PHPMD.StaticAccess)
*/
class Swedbank_Pay_Payment_Menu extends Swedbank_Pay_Plugin {
const TEXT_DOMAIN = 'swedbank-pay-woocommerce-checkout';
// phpcs:enable
/**
* Constructor
*/
public function __construct() {
define( 'SwedbankPay\Checkout\WooCommerce\PLUGIN_PATH', plugin_basename( __FILE__ ) );
if ( in_array( 'swedbank-pay-checkout/swedbank-pay-woocommerce-checkout.php', get_option( 'active_plugins' ) ) ) { //phpcs:ignore
return;
}
parent::__construct();
// Activation
register_activation_hook( __FILE__, array( $this, 'install' ) );
// Actions
add_action( 'plugins_loaded', array( $this, 'init' ), 0 );
add_action( 'woocommerce_loaded', array( $this, 'woocommerce_loaded' ), 30 );
add_action(
'before_woocommerce_init',
function() {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility(
'custom_order_tables',
__FILE__,
true
);
}
}
);
}
/**
* Init localisations and files
* @return void
*/
public function init() {
// Localization
load_plugin_textdomain(
'swedbank-pay-woocommerce-checkout',
false,
dirname( plugin_basename( __FILE__ ) ) . '/languages'
);
}
/**
* WooCommerce Loaded: load classes
* @return void
*/
public function woocommerce_loaded() {
// Check if WooCommerce is missing
if ( ! class_exists( 'WooCommerce', false ) || ! defined( 'WC_ABSPATH' ) ) {
add_action( 'admin_notices', __CLASS__ . '::missing_woocommerce_notice' );
return;
}
include_once( dirname( __FILE__ ) . '/includes/class-swedbank-pay-payment-gateway-checkout.php' );
// Register Gateway
Swedbank_Pay_Payment_Menu::register_gateway( Swedbank_Pay_Payment_Gateway_Checkout::class );
}
/**
* Check if WooCommerce is missing, and deactivate the plugin if needs
*/
public static function missing_woocommerce_notice() {
?>
<div id="message" class="error">
<p class="main">
<strong><?php echo esc_html__( 'WooCommerce is inactive or missing.', 'swedbank-pay-woocommerce-checkout' ); ?></strong>
</p>
<p>
<?php
echo esc_html__( 'WooCommerce plugin is inactive or missing. Please install and active it.', 'swedbank-pay-woocommerce-checkout' );
echo '<br />';
echo sprintf(
/* translators: 1: plugin name */ esc_html__( //phpcs:ignore
'%1$s will be deactivated.',
'swedbank-pay-woocommerce-checkout'
),
self::PLUGIN_NAME
);
?>
</p>
</div>
<?php
// Deactivate the plugin
deactivate_plugins( plugin_basename( __FILE__ ), true );
}
}
new Swedbank_Pay_Payment_Menu();