1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Plugin Name: PaiementPro for Give |
4
|
|
|
* Version: 1.0.2 |
5
|
|
|
* Author: PaiementPro |
6
|
|
|
* Author URI: https://paiementpro.net |
7
|
|
|
* Plugin URI: https://wordpress.org/plugins/paiementpro-for-give/ |
8
|
|
|
* Description: Accept donations for GiveWP using PaiementPro payment gateway. |
9
|
|
|
* Requires at least: 4.8 |
10
|
|
|
* Requires PHP: 5.6 |
11
|
|
|
* Text Domain: paiementpro-for-give |
12
|
|
|
* License: GPL v2 or later |
13
|
|
|
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
// Bailout, if accessed directly. |
17
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
18
|
|
|
exit; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
if ( ! class_exists( 'PaiementPro4Give' ) ) { |
22
|
|
|
|
23
|
|
|
final class PaiementPro4Give { |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Instance. |
27
|
|
|
* |
28
|
|
|
* @since 1.0.0 |
29
|
|
|
* @access static |
30
|
|
|
* @var |
31
|
|
|
*/ |
32
|
|
|
static private $instance; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Notices (array) |
36
|
|
|
* |
37
|
|
|
* @since 1.0.3 |
38
|
|
|
* |
39
|
|
|
* @var array |
40
|
|
|
*/ |
41
|
|
|
public $notices = []; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Singleton pattern. |
45
|
|
|
* |
46
|
|
|
* @since 1.0.0 |
47
|
|
|
* @access private |
48
|
|
|
*/ |
49
|
|
|
private function __construct() { |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get instance. |
54
|
|
|
* |
55
|
|
|
* @return static |
56
|
|
|
* @since 1.0.0 |
57
|
|
|
* @access static |
58
|
|
|
* |
59
|
|
|
*/ |
60
|
|
|
static function get_instance() { |
|
|
|
|
61
|
|
|
if ( null === static::$instance ) { |
|
|
|
|
62
|
|
|
self::$instance = new self(); |
63
|
|
|
self::$instance->setup(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return self::$instance; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Setup PaiementPro for Give. |
71
|
|
|
* |
72
|
|
|
* @return void |
73
|
|
|
* @since 1.0.0 |
74
|
|
|
* @access private |
75
|
|
|
* |
76
|
|
|
*/ |
77
|
|
|
private function setup() { |
78
|
|
|
// Setup constants. |
79
|
|
|
$this->setup_constants(); |
80
|
|
|
|
81
|
|
|
// Give init hook. |
82
|
|
|
add_action( 'plugins_loaded', [ $this, 'init' ], 101 ); |
|
|
|
|
83
|
|
|
add_action( 'admin_notices', [ $this, 'admin_notices' ], 15 ); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Setup constants. |
88
|
|
|
* |
89
|
|
|
* @return void |
90
|
|
|
* @since 1.0 |
91
|
|
|
* @access public |
92
|
|
|
* |
93
|
|
|
*/ |
94
|
|
|
public function setup_constants() { |
95
|
|
|
if ( ! defined( 'PAIEMENTPRO4GIVE_VERSION' ) ) { |
96
|
|
|
define( 'PAIEMENTPRO4GIVE_VERSION', '1.0.2' ); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
if ( ! defined( 'PAIEMENTPRO4GIVE_MIN_GIVE_VER' ) ) { |
100
|
|
|
define( 'PAIEMENTPRO4GIVE_MIN_GIVE_VER', '2.5.0' ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
if ( ! defined( 'PAIEMENTPRO4GIVE_PLUGIN_FILE' ) ) { |
104
|
|
|
define( 'PAIEMENTPRO4GIVE_PLUGIN_FILE', __FILE__ ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
if ( ! defined( 'PAIEMENTPRO4GIVE_PLUGIN_BASENAME' ) ) { |
108
|
|
|
define( 'PAIEMENTPRO4GIVE_PLUGIN_BASENAME', plugin_basename( PAIEMENTPRO4GIVE_PLUGIN_FILE ) ); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
if ( ! defined( 'PAIEMENTPRO4GIVE_PLUGIN_DIR' ) ) { |
112
|
|
|
define( 'PAIEMENTPRO4GIVE_PLUGIN_DIR', plugin_dir_path( PAIEMENTPRO4GIVE_PLUGIN_FILE ) ); |
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
if ( ! defined( 'PAIEMENTPRO4GIVE_PLUGIN_URL' ) ) { |
116
|
|
|
define( 'PAIEMENTPRO4GIVE_PLUGIN_URL', plugin_dir_url( PAIEMENTPRO4GIVE_PLUGIN_FILE ) ); |
|
|
|
|
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Load the text domain. |
122
|
|
|
* |
123
|
|
|
* @access private |
124
|
|
|
* @return void |
125
|
|
|
* @since 1.0.0 |
126
|
|
|
* |
127
|
|
|
*/ |
128
|
|
|
public function load_textdomain() { |
129
|
|
|
|
130
|
|
|
// Set filter for plugin's languages directory. |
131
|
|
|
$lang_dir = dirname( PAIEMENTPRO4GIVE_PLUGIN_BASENAME ) . '/languages/'; |
132
|
|
|
$lang_dir = apply_filters( 'paiementpro4give_languages_directory', $lang_dir ); |
|
|
|
|
133
|
|
|
|
134
|
|
|
// Traditional WordPress plugin locale filter. |
135
|
|
|
$locale = apply_filters( 'plugin_locale', get_locale(), 'paiementpro-for-give' ); |
|
|
|
|
136
|
|
|
$mo_file = sprintf( '%1$s-%2$s.mo', 'paiementpro-for-give', $locale ); |
137
|
|
|
|
138
|
|
|
// Setup paths to current locale file. |
139
|
|
|
$local_mo_file = $lang_dir . $mo_file; |
140
|
|
|
$global_mo_file = WP_LANG_DIR . '/paiementpro-for-give/' . $mo_file; |
|
|
|
|
141
|
|
|
|
142
|
|
|
if ( file_exists( $global_mo_file ) ) { |
143
|
|
|
load_textdomain( 'paiementpro-for-give', $global_mo_file ); |
|
|
|
|
144
|
|
|
} elseif ( file_exists( $local_mo_file ) ) { |
145
|
|
|
load_textdomain( 'paiementpro-for-give', $local_mo_file ); |
146
|
|
|
} else { |
147
|
|
|
// Load the default language files. |
148
|
|
|
load_plugin_textdomain( 'paiementpro-for-give', false, $lang_dir ); |
|
|
|
|
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Set hooks |
154
|
|
|
* |
155
|
|
|
* @return void |
156
|
|
|
* @since 1.0.0 |
157
|
|
|
* @access public |
158
|
|
|
* |
159
|
|
|
*/ |
160
|
|
|
public function init() { |
161
|
|
|
// Bailout, if environment is not suitable for loading plugin. |
162
|
|
|
if ( ! $this->check_environment() ) { |
163
|
|
|
return; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
$this->load_textdomain(); |
167
|
|
|
|
168
|
|
|
require_once PAIEMENTPRO4GIVE_PLUGIN_DIR . 'includes/helpers.php'; |
169
|
|
|
require_once PAIEMENTPRO4GIVE_PLUGIN_DIR . 'includes/admin/settings.php'; |
170
|
|
|
require_once PAIEMENTPRO4GIVE_PLUGIN_DIR . 'includes/payment-methods/class-paiementpro4give-mtn-money-ci.php'; |
171
|
|
|
require_once PAIEMENTPRO4GIVE_PLUGIN_DIR . 'includes/payment-methods/class-paiementpro4give-mtn-money-bj.php'; |
172
|
|
|
require_once PAIEMENTPRO4GIVE_PLUGIN_DIR . 'includes/payment-methods/class-paiementpro4give-moov-money-ci.php'; |
173
|
|
|
require_once PAIEMENTPRO4GIVE_PLUGIN_DIR . 'includes/payment-methods/class-paiementpro4give-moov-money-bj.php'; |
174
|
|
|
require_once PAIEMENTPRO4GIVE_PLUGIN_DIR . 'includes/payment-methods/class-paiementpro4give-orange-money-ci.php'; |
175
|
|
|
require_once PAIEMENTPRO4GIVE_PLUGIN_DIR . 'includes/payment-methods/class-paiementpro4give-orange-money-bf.php'; |
176
|
|
|
require_once PAIEMENTPRO4GIVE_PLUGIN_DIR . 'includes/payment-methods/class-paiementpro4give-orange-money-ml.php'; |
177
|
|
|
require_once PAIEMENTPRO4GIVE_PLUGIN_DIR . 'includes/payment-methods/class-paiementpro4give-card.php'; |
178
|
|
|
require_once PAIEMENTPRO4GIVE_PLUGIN_DIR . 'includes/filters.php'; |
179
|
|
|
require_once PAIEMENTPRO4GIVE_PLUGIN_DIR . 'includes/actions.php'; |
180
|
|
|
|
181
|
|
|
// Display admin notice when admin credentials to process payments are not set. |
182
|
|
|
if ( |
183
|
|
|
! paiementpro4give_get_merchant_id() || |
184
|
|
|
! paiementpro4give_get_credential_id() || |
185
|
|
|
! paiementpro4give_get_api_url() |
186
|
|
|
) { |
187
|
|
|
PaiementPro4Give()->add_admin_notice( |
188
|
|
|
'empty-credentials', |
189
|
|
|
'error', |
190
|
|
|
__( 'Please save the <strong>Merchant ID</strong> and <strong>Credential ID</strong> to accept donations via PaiementPro.', 'give' ) |
|
|
|
|
191
|
|
|
); |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Check plugin environment. |
197
|
|
|
* |
198
|
|
|
* @return bool |
199
|
|
|
* @since 1.0.0 |
200
|
|
|
* @access public |
201
|
|
|
* |
202
|
|
|
*/ |
203
|
|
|
public function check_environment() { |
204
|
|
|
// Flag to check whether plugin file is loaded or not. |
205
|
|
|
$is_working = true; |
206
|
|
|
|
207
|
|
|
// Load plugin helper functions. |
208
|
|
|
if ( ! function_exists( 'is_plugin_active' ) ) { |
209
|
|
|
require_once ABSPATH . '/wp-admin/includes/plugin.php'; |
|
|
|
|
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/* Check to see if Give is activated, if it isn't deactivate and show a banner. */ |
213
|
|
|
// Check for if give plugin activate or not. |
214
|
|
|
$is_give_active = defined( 'GIVE_PLUGIN_BASENAME' ) ? is_plugin_active( GIVE_PLUGIN_BASENAME ) : false; |
|
|
|
|
215
|
|
|
|
216
|
|
|
if ( empty( $is_give_active ) ) { |
217
|
|
|
// Show admin notice. |
218
|
|
|
$this->add_admin_notice( 'prompt_give_activate', 'error', sprintf( __( '<strong>Activation Error:</strong> You must have the <a href="%s" target="_blank">Give</a> plugin installed and activated for <strong>PaiementPro for Give</strong> to activate.', 'give' ), 'https://givewp.com' ) ); |
|
|
|
|
219
|
|
|
$is_working = false; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
return $is_working; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Check plugin for Give environment. |
227
|
|
|
* |
228
|
|
|
* @return bool |
229
|
|
|
* @since 1.0.0 |
230
|
|
|
* @access public |
231
|
|
|
* |
232
|
|
|
*/ |
233
|
|
|
public function get_environment_warning() { |
234
|
|
|
// Flag to check whether plugin file is loaded or not. |
235
|
|
|
$is_working = true; |
236
|
|
|
|
237
|
|
|
// Verify dependency cases. |
238
|
|
|
if ( |
239
|
|
|
defined( 'GIVE_VERSION' ) |
240
|
|
|
&& version_compare( GIVE_VERSION, PAIEMENTPRO4GIVE_MIN_GIVE_VER, '<' ) |
|
|
|
|
241
|
|
|
) { |
242
|
|
|
|
243
|
|
|
/* Min. Give. plugin version. */ |
244
|
|
|
// Show admin notice. |
245
|
|
|
$this->add_admin_notice( 'prompt_give_incompatible', 'error', sprintf( __( '<strong>Activation Error:</strong> You must have the <a href="%1$s" target="_blank">Give</a> core version %2$s for the "iPay88 for Give" add-on to activate.', 'give' ), 'https://givewp.com', PAIEMENTPRO4GIVE_MIN_GIVE_VER ) ); |
|
|
|
|
246
|
|
|
|
247
|
|
|
$is_working = false; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
return $is_working; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* Allow this class and other classes to add notices. |
255
|
|
|
* |
256
|
|
|
* @param $slug |
257
|
|
|
* @param $class |
258
|
|
|
* @param $message |
259
|
|
|
* |
260
|
|
|
* @since 1.0.0 |
261
|
|
|
* |
262
|
|
|
*/ |
263
|
|
|
public function add_admin_notice( $slug, $class, $message ) { |
264
|
|
|
$this->notices[ $slug ] = [ |
265
|
|
|
'class' => $class, |
266
|
|
|
'message' => $message, |
267
|
|
|
]; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Display admin notices. |
272
|
|
|
* |
273
|
|
|
* @since 1.0.0 |
274
|
|
|
*/ |
275
|
|
|
public function admin_notices() { |
276
|
|
|
|
277
|
|
|
$allowed_tags = [ |
278
|
|
|
'a' => [ |
279
|
|
|
'href' => [], |
280
|
|
|
'title' => [], |
281
|
|
|
'class' => [], |
282
|
|
|
'id' => [], |
283
|
|
|
], |
284
|
|
|
'br' => [], |
285
|
|
|
'em' => [], |
286
|
|
|
'span' => [ |
287
|
|
|
'class' => [], |
288
|
|
|
], |
289
|
|
|
'strong' => [], |
290
|
|
|
]; |
291
|
|
|
|
292
|
|
|
foreach ( (array) $this->notices as $notice_key => $notice ) { |
293
|
|
|
echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
|
|
|
294
|
|
|
echo wp_kses( $notice['message'], $allowed_tags ); |
|
|
|
|
295
|
|
|
echo '</p></div>'; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
} |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* Returns class object instance. |
303
|
|
|
* |
304
|
|
|
* @return PaiementPro4Give bool|object |
305
|
|
|
* @since 1.0.0 |
306
|
|
|
* |
307
|
|
|
*/ |
308
|
|
|
function PaiementPro4Give() { |
309
|
|
|
return PaiementPro4Give::get_instance(); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
PaiementPro4Give(); |
313
|
|
|
} |
314
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.