-
Notifications
You must be signed in to change notification settings - Fork 1
/
give-moneris.php
executable file
·374 lines (319 loc) · 9.16 KB
/
give-moneris.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<?php
/**
* Plugin Name: Give - Moneris
* Plugin URI: https://givewp.com/addons/moneris-gateway/
* Description: Adds support to accept donations via the Moneris Payment gateway.
* Version: 1.1.0
* Author: GiveWP
* Author URI: https://givewp.com
* License: GNU General Public License v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: give-moneris
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Give_Moneris' ) ) :
/**
* Class Give_Moneris
*
* @since 1.0.0
*/
final class Give_Moneris {
/**
* Instance.
*
* @since 1.0.0
* @access private
*
* @var Give_Moneris
*/
private static $instance;
/**
* Notices (array)
*
* @since 1.0.0
*
* @var array
*/
public $notices = array();
/**
* Get instance.
*
* @since 1.0.0
* @access public
*
* @return Give_Moneris
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
self::$instance->setup();
}
return self::$instance;
}
/**
* Setup Give Moneris.
*
* @since 1.0.0
* @access private
*/
private function setup() {
// Setup constants.
$this->setup_constants();
// Give init hook.
add_action( 'give_init', array( $this, 'init' ), 10 );
add_action( 'admin_init', array( $this, 'check_environment' ), 999 );
add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 );
}
/**
* Setup constants
*
* Defines useful constants to use throughout the add-on.
*
* @since 1.0.0
* @access private
*/
private function setup_constants() {
if ( ! defined( 'GIVE_MONERIS_VERSION' ) ) {
define( 'GIVE_MONERIS_VERSION', '1.1.0' );
}
if ( ! defined( 'GIVE_MONERIS_MIN_GIVE_VERSION' ) ) {
define( 'GIVE_MONERIS_MIN_GIVE_VERSION', '2.3.0' );
}
if ( ! defined( 'GIVE_MONERIS_MIN_PHP_VERSION' ) ) {
define( 'GIVE_MONERIS_MIN_PHP_VERSION', '5.4' );
}
if ( ! defined( 'GIVE_MONERIS_PLUGIN_FILE' ) ) {
define( 'GIVE_MONERIS_PLUGIN_FILE', __FILE__ );
}
if ( ! defined( 'GIVE_MONERIS_PLUGIN_DIR' ) ) {
define( 'GIVE_MONERIS_PLUGIN_DIR', plugin_dir_path( GIVE_MONERIS_PLUGIN_FILE ) );
}
if ( ! defined( 'GIVE_MONERIS_PLUGIN_URL' ) ) {
define( 'GIVE_MONERIS_PLUGIN_URL', plugin_dir_url( GIVE_MONERIS_PLUGIN_FILE ) );
}
if ( ! defined( 'GIVE_MONERIS_PLUGIN_BASENAME' ) ) {
define( 'GIVE_MONERIS_PLUGIN_BASENAME', plugin_basename( GIVE_MONERIS_PLUGIN_FILE ) );
}
}
/**
* Initialize Plugin after plugins loaded.
*
* @since 1.0.0
*/
public function init() {
// Load Text Domain for Give - Moneris Integration.
load_plugin_textdomain( 'give-moneris', false, GIVE_MONERIS_PLUGIN_BASENAME . '/languages' );
$this->licensing();
if ( ! $this->get_environment_warning() ) {
return;
}
$this->includes();
$this->activation_banner();
}
/**
* Include required files.
*
* @since 1.0.0
*/
public function includes() {
require_once GIVE_MONERIS_PLUGIN_DIR . '/includes/admin/class-give-moneris-admin-settings.php';
require_once GIVE_MONERIS_PLUGIN_DIR . '/includes/admin/admin-filters.php';
require_once GIVE_MONERIS_PLUGIN_DIR . '/includes/admin/admin-actions.php';
require_once GIVE_MONERIS_PLUGIN_DIR . '/includes/scripts.php';
require_once GIVE_MONERIS_PLUGIN_DIR . '/includes/misc-functions.php';
require_once GIVE_MONERIS_PLUGIN_DIR . '/includes/class-moneris-api.php';
require_once GIVE_MONERIS_PLUGIN_DIR . '/includes/class-give-moneris-gateway.php';
}
/**
* Plugin Licensing.
*
* @since 1.0.0
*/
public function licensing() {
if ( class_exists( 'Give_License' ) ) {
new Give_License( GIVE_MONERIS_PLUGIN_FILE, 'Moneris Gateway', GIVE_MONERIS_VERSION, 'WordImpress', 'moneris_license_key' );
}
}
/**
* Check plugin environment.
*
* @since 1.0.0
* @access public
*
* @return bool
*/
public function check_environment() {
// Flag to check whether plugin file is loaded or not.
$is_working = true;
// Load plugin helper functions.
if ( ! function_exists( 'is_plugin_active' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}
// Check if Give Core plugin is active or not.
$is_give_active = defined( 'GIVE_PLUGIN_BASENAME' ) ? is_plugin_active( GIVE_PLUGIN_BASENAME ) : false;
if ( empty( $is_give_active ) ) {
// Show admin notice.
$this->add_admin_notice(
'prompt_give_activate',
'error',
sprintf(
/* translators: 1. Strong Text, 2. Intro Text, 3. URL, 4. Plugin Name, 5. End Text. */
'<strong>%1$s</strong> %2$s <a href="%3$s" target="_blank">%4$s</a> %5$s',
__( 'Activation Error:', 'give-moneris' ),
__( 'You must have the', 'give-moneris' ),
esc_url_raw( 'https://givewp.com' ),
__( 'Give', 'give-moneris' ),
__( 'plugin installed and activated for Give - Moneris to activate.', 'give-moneris' )
)
);
$is_working = false;
}
return $is_working;
}
/**
* Check plugin for Give environment.
*
* @since 1.0.0
* @access public
*
* @return bool
*/
public function get_environment_warning() {
// Flag to check whether plugin file is loaded or not.
$is_working = true;
// Verify dependency cases.
if (
defined( 'GIVE_VERSION' )
&& version_compare( GIVE_VERSION, GIVE_MONERIS_MIN_GIVE_VERSION, '<' )
) {
// Display notice when minimum Give Core plugin version is not found.
$this->add_admin_notice(
'prompt_give_incompatible',
'error',
sprintf(
/* translators: 1. Strong Text, 2. Intro Text, 3. URL, 4. Plugin Name, 5. Plugin Text, 6. Plugin Version, 7. End Text */
'<strong>%1$s</strong> %2$s <a href="%3$s" target="_blank">%4$s</a> %5$s %6$s %7$s',
__( 'Activation Error:', 'give-moneris' ),
__( 'You must have the', 'give-moneris' ),
esc_url_raw( 'https://givewp.com' ),
__( 'Give', 'give-moneris' ),
__( 'core version', 'give-moneris' ),
GIVE_MONERIS_MIN_GIVE_VERSION,
__( 'for the Give - Moneris add-on to activate.', 'give-moneris' )
)
);
$is_working = false;
}
if ( version_compare( phpversion(), GIVE_MONERIS_MIN_PHP_VERSION, '<' ) ) {
$this->add_admin_notice(
'prompt_give_incompatible',
'error',
sprintf(
/* translators: 1. Strong Text, 2. Intro Text, 3. URL, 4. PHP text, 5. Min Plugin Version, 6. End Text */
'<strong>%1$s</strong> %2$s <a href="%3$s" target="_blank">%4$s</a> %5$s %6$s',
__( 'Activation Error:', 'give-moneris' ),
__( 'You must have the', 'give-moneris' ),
esc_url_raw( 'https://givewp.com/documentation/core/requirements/' ),
__( 'PHP version', 'give-moneris' ),
GIVE_MONERIS_MIN_PHP_VERSION,
__( 'or above for the Give - Moneris gateway add-on to activate.', 'give-moneris' )
)
);
$is_working = false;
}
return $is_working;
}
/**
* Allow this class and other classes to add notices.
*
* @since 1.0.0
*
* @param string $slug Admin Notice Slug.
* @param string $class Admin Notice Type.
* @param string $message Admin Notice Message.
*/
public function add_admin_notice( $slug, $class, $message ) {
$this->notices[ $slug ] = array(
'class' => $class,
'message' => $message,
);
}
/**
* Display admin notices.
*
* @since 1.0.0
*/
public function admin_notices() {
$allowed_tags = array(
'a' => array(
'href' => array(),
'title' => array(),
'class' => array(),
'id' => array(),
),
'br' => array(),
'em' => array(),
'span' => array(
'class' => array(),
),
'strong' => array(),
);
foreach ( (array) $this->notices as $notice_key => $notice ) {
echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
echo wp_kses( $notice['message'], $allowed_tags );
echo '</p></div>';
}
}
/**
* Show activation banner for this add-on.
*
* @since 1.0.0
*
* @return bool
*/
public function activation_banner() {
// Check for activation banner inclusion.
if (
! class_exists( 'Give_Addon_Activation_Banner' )
&& file_exists( GIVE_PLUGIN_DIR . 'includes/admin/class-addon-activation-banner.php' )
) {
include GIVE_PLUGIN_DIR . 'includes/admin/class-addon-activation-banner.php';
}
// Initialize activation welcome banner.
if ( class_exists( 'Give_Addon_Activation_Banner' ) ) {
// Only runs on admin.
$args = array(
'file' => GIVE_MONERIS_PLUGIN_FILE,
'name' => __( 'Moneris Gateway', 'give-moneris' ),
'version' => GIVE_MONERIS_VERSION,
'settings_url' => admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=gateways§ion=moneris-settings' ),
'documentation_url' => 'http://docs.givewp.com/addon-moneris',
'support_url' => 'https://givewp.com/support/',
'testing' => false,
);
new Give_Addon_Activation_Banner( $args );
}
return true;
}
}
endif;
/**
* The main function responsible for returning the one true Give_Moneris instance
* to functions everywhere.
*
* Use this function like you would a global variable, except without needing
* to declare the global.
*
* Example: <?php $moneris = Give_Moneris(); ?>
*
* @since 1.0.0
*
* @return Give_Moneris|bool
*/
function Give_Moneris() {
return Give_Moneris::get_instance();
}
Give_Moneris();