-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathneuralab-wc-wspay.php
159 lines (144 loc) · 3.47 KB
/
neuralab-wc-wspay.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
/**
* Plugin Name: Neuralab WooCommerce WSPay Payment Gateway
* Plugin URI: https://github.com/Neuralab/WSPay-WooCommerce-Payment-Gateway
* Description: WooCommerce WSPay Payment Gateway
* Version: 0.9.4
* Author: Neuralab
* Author URI: https://neuralab.net
* Developer: Matej
* Text Domain: wcwspay
* Requires at least: 4.7
* Requires PHP: 5.6
*
* WC requires at least: 3.0.0
* WC tested up to: 5.0
*
* License: MIT
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! function_exists( 'wcwspay_is_woocommerce_active' ) ) {
/**
* Return true if Woocommerce plugin is active.
*
* @since 0.1
* @return boolean
*/
function wcwspay_is_woocommerce_active() {
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ) {
return true;
}
return false;
}
}
if ( ! function_exists( 'wcwspay_admin_notice_missing_woocommerce' ) ) {
/**
* Echo admin notice HTML for missing WooCommerce plugin.
*
* @since 0.1
*/
function wcwspay_admin_notice_missing_woocommerce() {
global $current_screen;
if ( $current_screen->parent_base === 'plugins' ) {
?>
<div class="notice notice-error">
<p>
<?php
/* translators: %s: link to WooCommerce */
echo sprintf( esc_html__( 'Please install and activate %s before activating the Neuralab WooCommerce WSPay Payment Gateway!', 'wcwspay' ), '<a href="http://www.woothemes.com/woocommerce/" target="_blank">WooCommerce</a>' );
?>
</p>
</div>
<?php
}
}
}
if ( ! wcwspay_is_woocommerce_active() ) {
add_action( 'admin_notices', 'wcwspay_admin_notice_missing_woocommerce' );
return;
}
if ( ! class_exists( 'WC_WSPay_Main' ) ) {
class WC_WSPay_Main {
/**
* Current plugin's version.
*
* @var string
*/
const VERSION = '0.9.4';
/**
* Instance of the current class, null before first usage.
*
* @var WC_WSPay_Main
*/
protected static $instance = null;
/**
* Class constructor.
*
* @codeCoverageIgnore
* @since 0.1
*/
protected function __construct() {
require_once 'includes/core/class-wc-wspay-payment-gateway.php';
}
/**
* Installation procedure.
*
* @static
* @since 0.1
*/
public static function install() {
if ( ! current_user_can( 'activate_plugins' ) ) {
return false;
}
}
/**
* Uninstallation procedure.
*
* @static
* @since 0.1
*/
public static function uninstall() {
if ( ! current_user_can( 'activate_plugins' ) ) {
return false;
}
delete_option( 'woocommerce_neuralab-wcwspay_settings' );
wp_cache_flush();
}
/**
* Return class instance.
*
* @static
* @since 0.1
* @return WC_WSPay_Main
*/
public static function get_instance() {
// @codeCoverageIgnoreStart
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
// @codeCoverageIgnoreEnd
return self::$instance;
}
/**
* Cloning is forbidden.
*
* @since 0.1
*/
public function __clone() {
return wp_die( 'Cloning is forbidden!' );
}
/**
* Unserializing instances of this class is forbidden.
*
* @since 0.1
*/
public function __wakeup() {
return wp_die( 'Unserializing instances is forbidden!' );
}
}
}
register_activation_hook( __FILE__, [ 'WC_WSPay_Main', 'install' ] );
register_uninstall_hook( __FILE__, [ 'WC_WSPay_Main', 'uninstall' ] );
add_action( 'plugins_loaded', [ 'WC_WSPay_Main', 'get_instance' ], 0 );