|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Admin Actions |
|
4
|
|
|
* |
|
5
|
|
|
* @package Give |
|
6
|
|
|
* @subpackage Admin/Actions |
|
7
|
|
|
* @copyright Copyright (c) 2016, WordImpress |
|
8
|
|
|
* @license https://opensource.org/licenses/gpl-license GNU Public License |
|
9
|
|
|
* @since 1.0 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
// Exit if accessed directly. |
|
13
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
14
|
|
|
exit; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Load wp editor by ajax. |
|
19
|
|
|
* |
|
20
|
|
|
* @since 1.8 |
|
21
|
|
|
*/ |
|
22
|
|
|
function give_load_wp_editor() { |
|
23
|
|
|
if ( ! isset( $_POST['wp_editor'] ) ) { |
|
|
|
|
|
|
24
|
|
|
die(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
$wp_editor = json_decode( base64_decode( $_POST['wp_editor'] ), true ); |
|
|
|
|
|
|
28
|
|
|
$wp_editor[2]['textarea_name'] = $_POST['textarea_name']; |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
wp_editor( $wp_editor[0], $_POST['wp_editor_id'], $wp_editor[2] ); |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
die(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
add_action( 'wp_ajax_give_load_wp_editor', 'give_load_wp_editor' ); |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Redirect admin to clean url give admin pages. |
|
40
|
|
|
* |
|
41
|
|
|
* @since 1.8 |
|
42
|
|
|
* |
|
43
|
|
|
* @return bool |
|
44
|
|
|
*/ |
|
45
|
|
|
function give_redirect_to_clean_url_admin_pages() { |
|
46
|
|
|
// Give admin pages. |
|
47
|
|
|
$give_pages = array( |
|
48
|
|
|
'give-payment-history', |
|
49
|
|
|
'give-donors', |
|
50
|
|
|
'give-reports', |
|
51
|
|
|
'give-tools' |
|
|
|
|
|
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
// Get current page. |
|
55
|
|
|
$current_page = isset( $_GET['page'] ) ? esc_attr( $_GET['page'] ) : ''; |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
// Bailout. |
|
58
|
|
|
if ( |
|
59
|
|
|
empty( $current_page ) |
|
60
|
|
|
|| empty( $_GET['_wp_http_referer'] ) |
|
|
|
|
|
|
61
|
|
|
|| ! in_array( $current_page, $give_pages ) |
|
62
|
|
|
) { |
|
63
|
|
|
return false; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Verify current page request. |
|
68
|
|
|
* |
|
69
|
|
|
* @since 1.8 |
|
70
|
|
|
*/ |
|
71
|
|
|
$redirect = apply_filters( "give_validate_{$current_page}", true ); |
|
72
|
|
|
|
|
73
|
|
|
if ( $redirect ) { |
|
74
|
|
|
// Redirect. |
|
75
|
|
|
wp_redirect( |
|
76
|
|
|
remove_query_arg( |
|
77
|
|
|
array( '_wp_http_referer', '_wpnonce' ), |
|
78
|
|
|
wp_unslash( $_SERVER['REQUEST_URI'] ) |
|
|
|
|
|
|
79
|
|
|
) |
|
80
|
|
|
); |
|
81
|
|
|
exit; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
add_action( 'admin_init', 'give_redirect_to_clean_url_admin_pages' ); |
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Hide Outdated PHP Notice Shortly. |
|
90
|
|
|
* |
|
91
|
|
|
* This code is used with AJAX call to hide outdated PHP notice for a short period of time |
|
92
|
|
|
* |
|
93
|
|
|
* @since 1.8.9 |
|
94
|
|
|
* |
|
95
|
|
|
* @return void |
|
96
|
|
|
*/ |
|
97
|
|
|
function give_hide_outdated_php_notice() { |
|
98
|
|
|
|
|
99
|
|
|
if ( ! isset( $_POST['_give_hide_outdated_php_notices_shortly'] ) ) { |
|
|
|
|
|
|
100
|
|
|
give_die(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
// Transient key name. |
|
104
|
|
|
$transient_key = "_give_hide_outdated_php_notices_shortly"; |
|
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
if ( Give_Cache::get( $transient_key, true ) ) { |
|
107
|
|
|
return; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
// Hide notice for 24 hours. |
|
111
|
|
|
Give_Cache::set( $transient_key, true, DAY_IN_SECONDS, true ); |
|
112
|
|
|
|
|
113
|
|
|
give_die(); |
|
114
|
|
|
|
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
add_action( 'wp_ajax_give_hide_outdated_php_notice', 'give_hide_outdated_php_notice' ); |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Updates state list. |
|
121
|
|
|
* |
|
122
|
|
|
* This code changes the state list in general settings when the country is changed. |
|
123
|
|
|
* |
|
124
|
|
|
* @return void |
|
125
|
|
|
*/ |
|
126
|
|
|
function give_update_states() { |
|
127
|
|
|
$country_code = filter_input( INPUT_POST, 'country_code', FILTER_SANITIZE_STRING ); |
|
128
|
|
|
$states_list = give_states_list(); |
|
129
|
|
|
echo wp_json_encode( $states_list[ $country_code ] ); |
|
130
|
|
|
wp_die(); |
|
131
|
|
|
} |
|
132
|
|
|
add_action( 'wp_ajax_give_update_states', 'give_update_states' ); |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Register admin notices. |
|
136
|
|
|
* |
|
137
|
|
|
* @since 1.8.9 |
|
138
|
|
|
*/ |
|
139
|
|
|
function _give_register_admin_notices() { |
|
140
|
|
|
// Bailout. |
|
141
|
|
|
if( ! is_admin() ) { |
|
|
|
|
|
|
142
|
|
|
return; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
// Add payment bulk notice. |
|
146
|
|
|
if ( |
|
147
|
|
|
current_user_can( 'edit_give_payments' ) |
|
148
|
|
|
&& isset( $_GET['action'] ) |
|
149
|
|
|
&& ! empty( $_GET['action'] ) |
|
150
|
|
|
&& isset( $_GET['payment'] ) |
|
151
|
|
|
&& ! empty( $_GET['payment'] ) |
|
152
|
|
|
) { |
|
153
|
|
|
$payment_count = isset( $_GET['payment'] ) ? count( $_GET['payment'] ) : 0; |
|
|
|
|
|
|
154
|
|
|
|
|
155
|
|
|
switch ( $_GET['action'] ) { |
|
|
|
|
|
|
156
|
|
View Code Duplication |
case 'delete': |
|
|
|
|
|
|
157
|
|
|
Give()->notices->register_notice( array( |
|
158
|
|
|
'id' => 'bulk_action_delete', |
|
159
|
|
|
'type' => 'updated', |
|
160
|
|
|
'description' => sprintf( |
|
161
|
|
|
_n( |
|
162
|
|
|
'Successfully deleted one transaction.', |
|
163
|
|
|
'Successfully deleted %d transactions.', |
|
164
|
|
|
$payment_count, |
|
165
|
|
|
'give' |
|
166
|
|
|
), |
|
167
|
|
|
$payment_count ), |
|
|
|
|
|
|
168
|
|
|
'show' => true, |
|
169
|
|
|
) ); |
|
170
|
|
|
|
|
171
|
|
|
break; |
|
172
|
|
|
|
|
173
|
|
View Code Duplication |
case 'resend-receipt': |
|
|
|
|
|
|
174
|
|
|
Give()->notices->register_notice( array( |
|
175
|
|
|
'id' => 'bulk_action_resend_receipt', |
|
176
|
|
|
'type' => 'updated', |
|
177
|
|
|
'description' => sprintf( |
|
178
|
|
|
_n( |
|
179
|
|
|
'Successfully sent email receipt to one recipient.', |
|
180
|
|
|
'Successfully sent email receipts to %d recipients.', |
|
181
|
|
|
$payment_count, |
|
182
|
|
|
'give' |
|
183
|
|
|
), |
|
184
|
|
|
$payment_count |
|
185
|
|
|
), |
|
186
|
|
|
'show' => true, |
|
187
|
|
|
) ); |
|
188
|
|
|
break; |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
// Add give message notices. |
|
193
|
|
|
if ( ! empty( $_GET['give-message'] ) ) { |
|
|
|
|
|
|
194
|
|
|
// Donation reports errors. |
|
195
|
|
|
if ( current_user_can( 'view_give_reports' ) ) { |
|
196
|
|
|
switch ( $_GET['give-message'] ) { |
|
|
|
|
|
|
197
|
|
View Code Duplication |
case 'donation_deleted' : |
|
|
|
|
|
|
198
|
|
|
Give()->notices->register_notice( array( |
|
199
|
|
|
'id' => 'give-donation-deleted', |
|
200
|
|
|
'type' => 'updated', |
|
201
|
|
|
'description' => __( 'The donation has been deleted.', 'give' ), |
|
202
|
|
|
'show' => true, |
|
203
|
|
|
) ); |
|
204
|
|
|
break; |
|
205
|
|
View Code Duplication |
case 'email_sent' : |
|
|
|
|
|
|
206
|
|
|
Give()->notices->register_notice( array( |
|
207
|
|
|
'id' => 'give-payment-sent', |
|
208
|
|
|
'type' => 'updated', |
|
209
|
|
|
'description' => __( 'The donation receipt has been resent.', 'give' ), |
|
210
|
|
|
'show' => true, |
|
211
|
|
|
) ); |
|
212
|
|
|
break; |
|
213
|
|
View Code Duplication |
case 'refreshed-reports' : |
|
|
|
|
|
|
214
|
|
|
Give()->notices->register_notice( array( |
|
215
|
|
|
'id' => 'give-refreshed-reports', |
|
216
|
|
|
'type' => 'updated', |
|
217
|
|
|
'description' => __( 'The reports cache has been cleared.', 'give' ), |
|
218
|
|
|
'show' => true, |
|
219
|
|
|
) ); |
|
220
|
|
|
break; |
|
221
|
|
View Code Duplication |
case 'donation-note-deleted' : |
|
|
|
|
|
|
222
|
|
|
Give()->notices->register_notice( array( |
|
223
|
|
|
'id' => 'give-donation-note-deleted', |
|
224
|
|
|
'type' => 'updated', |
|
225
|
|
|
'description' => __( 'The donation note has been deleted.', 'give' ), |
|
226
|
|
|
'show' => true, |
|
227
|
|
|
) ); |
|
228
|
|
|
break; |
|
229
|
|
|
} |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
// Give settings notices and errors. |
|
233
|
|
|
if ( current_user_can( 'manage_give_settings' ) ) { |
|
234
|
|
|
switch ( $_GET['give-message'] ) { |
|
|
|
|
|
|
235
|
|
View Code Duplication |
case 'settings-imported' : |
|
|
|
|
|
|
236
|
|
|
Give()->notices->register_notice( array( |
|
237
|
|
|
'id' => 'give-settings-imported', |
|
238
|
|
|
'type' => 'updated', |
|
239
|
|
|
'description' => __( 'The settings have been imported.', 'give' ), |
|
240
|
|
|
'show' => true, |
|
241
|
|
|
) ); |
|
242
|
|
|
break; |
|
243
|
|
View Code Duplication |
case 'api-key-generated' : |
|
|
|
|
|
|
244
|
|
|
Give()->notices->register_notice( array( |
|
245
|
|
|
'id' => 'give-api-key-generated', |
|
246
|
|
|
'type' => 'updated', |
|
247
|
|
|
'description' => __( 'API keys have been generated.', 'give' ), |
|
248
|
|
|
'show' => true, |
|
249
|
|
|
) ); |
|
250
|
|
|
break; |
|
251
|
|
View Code Duplication |
case 'api-key-exists' : |
|
|
|
|
|
|
252
|
|
|
Give()->notices->register_notice( array( |
|
253
|
|
|
'id' => 'give-api-key-exists', |
|
254
|
|
|
'type' => 'updated', |
|
255
|
|
|
'description' => __( 'The specified user already has API keys.', 'give' ), |
|
256
|
|
|
'show' => true, |
|
257
|
|
|
) ); |
|
258
|
|
|
break; |
|
259
|
|
View Code Duplication |
case 'api-key-regenerated' : |
|
|
|
|
|
|
260
|
|
|
Give()->notices->register_notice( array( |
|
261
|
|
|
'id' => 'give-api-key-regenerated', |
|
262
|
|
|
'type' => 'updated', |
|
263
|
|
|
'description' => __( 'API keys have been regenerated.', 'give' ), |
|
264
|
|
|
'show' => true, |
|
265
|
|
|
) ); |
|
266
|
|
|
break; |
|
267
|
|
View Code Duplication |
case 'api-key-revoked' : |
|
|
|
|
|
|
268
|
|
|
Give()->notices->register_notice( array( |
|
269
|
|
|
'id' => 'give-api-key-revoked', |
|
270
|
|
|
'type' => 'updated', |
|
271
|
|
|
'description' => __( 'API keys have been revoked.', 'give' ), |
|
272
|
|
|
'show' => true, |
|
273
|
|
|
) ); |
|
274
|
|
|
break; |
|
275
|
|
View Code Duplication |
case 'sent-test-email' : |
|
|
|
|
|
|
276
|
|
|
Give()->notices->register_notice( array( |
|
277
|
|
|
'id' => 'give-sent-test-email', |
|
278
|
|
|
'type' => 'updated', |
|
279
|
|
|
'description' => __( 'The test email has been sent.', 'give' ), |
|
280
|
|
|
'show' => true, |
|
281
|
|
|
) ); |
|
282
|
|
|
break; |
|
283
|
|
View Code Duplication |
case 'matched-success-failure-page': |
|
|
|
|
|
|
284
|
|
|
Give()->notices->register_notice( array( |
|
285
|
|
|
'id' => 'give-matched-success-failure-page', |
|
286
|
|
|
'type' => 'updated', |
|
287
|
|
|
'description' => __( 'You cannot set the success and failed pages to the same page', 'give' ), |
|
288
|
|
|
'show' => true, |
|
289
|
|
|
) ); |
|
290
|
|
|
break; |
|
291
|
|
|
} |
|
292
|
|
|
} |
|
293
|
|
|
// Payments errors. |
|
294
|
|
|
if ( current_user_can( 'edit_give_payments' ) ) { |
|
295
|
|
|
switch ( $_GET['give-message'] ) { |
|
|
|
|
|
|
296
|
|
View Code Duplication |
case 'note-added' : |
|
|
|
|
|
|
297
|
|
|
Give()->notices->register_notice( array( |
|
298
|
|
|
'id' => 'give-note-added', |
|
299
|
|
|
'type' => 'updated', |
|
300
|
|
|
'description' => __( 'The donation note has been added.', 'give' ), |
|
301
|
|
|
'show' => true, |
|
302
|
|
|
) ); |
|
303
|
|
|
break; |
|
304
|
|
View Code Duplication |
case 'payment-updated' : |
|
|
|
|
|
|
305
|
|
|
Give()->notices->register_notice( array( |
|
306
|
|
|
'id' => 'give-payment-updated', |
|
307
|
|
|
'type' => 'updated', |
|
308
|
|
|
'description' => __( 'The donation has been updated.', 'give' ), |
|
309
|
|
|
'show' => true, |
|
310
|
|
|
) ); |
|
311
|
|
|
break; |
|
312
|
|
|
} |
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
|
|
// Donor Notices. |
|
316
|
|
|
if ( current_user_can( 'edit_give_payments' ) ) { |
|
317
|
|
|
switch ( $_GET['give-message'] ) { |
|
|
|
|
|
|
318
|
|
View Code Duplication |
case 'donor-deleted' : |
|
|
|
|
|
|
319
|
|
|
Give()->notices->register_notice( array( |
|
320
|
|
|
'id' => 'give-donor-deleted', |
|
321
|
|
|
'type' => 'updated', |
|
322
|
|
|
'description' => __( 'The donor has been deleted.', 'give' ), |
|
323
|
|
|
'show' => true, |
|
324
|
|
|
) ); |
|
325
|
|
|
break; |
|
326
|
|
|
|
|
327
|
|
View Code Duplication |
case 'email-added' : |
|
|
|
|
|
|
328
|
|
|
Give()->notices->register_notice( array( |
|
329
|
|
|
'id' => 'give-donor-email-added', |
|
330
|
|
|
'type' => 'updated', |
|
331
|
|
|
'description' => __( 'Donor email added.', 'give' ), |
|
332
|
|
|
'show' => true, |
|
333
|
|
|
) ); |
|
334
|
|
|
break; |
|
335
|
|
|
|
|
336
|
|
View Code Duplication |
case 'email-removed' : |
|
|
|
|
|
|
337
|
|
|
Give()->notices->register_notice( array( |
|
338
|
|
|
'id' => 'give-donor-email-removed', |
|
339
|
|
|
'type' => 'updated', |
|
340
|
|
|
'description' => __( 'Donor email removed.', 'give' ), |
|
341
|
|
|
'show' => true, |
|
342
|
|
|
) ); |
|
343
|
|
|
break; |
|
344
|
|
|
|
|
345
|
|
View Code Duplication |
case 'email-remove-failed' : |
|
|
|
|
|
|
346
|
|
|
Give()->notices->register_notice( array( |
|
347
|
|
|
'id' => 'give-donor-email-remove-failed', |
|
348
|
|
|
'type' => 'updated', |
|
349
|
|
|
'description' => __( 'Failed to remove donor email.', 'give' ), |
|
350
|
|
|
'show' => true, |
|
351
|
|
|
) ); |
|
352
|
|
|
break; |
|
353
|
|
|
|
|
354
|
|
View Code Duplication |
case 'primary-email-updated' : |
|
|
|
|
|
|
355
|
|
|
Give()->notices->register_notice( array( |
|
356
|
|
|
'id' => 'give-donor-primary-email-updated', |
|
357
|
|
|
'type' => 'updated', |
|
358
|
|
|
'description' => __( 'Primary email updated for donor.', 'give' ), |
|
359
|
|
|
'show' => true, |
|
360
|
|
|
) ); |
|
361
|
|
|
break; |
|
362
|
|
|
|
|
363
|
|
View Code Duplication |
case 'primary-email-failed' : |
|
|
|
|
|
|
364
|
|
|
Give()->notices->register_notice( array( |
|
365
|
|
|
'id' => 'give-donor-primary-email-failed', |
|
366
|
|
|
'type' => 'updated', |
|
367
|
|
|
'description' => __( 'Failed to set primary email.', 'give' ), |
|
368
|
|
|
'show' => true, |
|
369
|
|
|
) ); |
|
370
|
|
|
break; |
|
371
|
|
|
} |
|
372
|
|
|
} |
|
373
|
|
|
} |
|
374
|
|
|
} |
|
375
|
|
|
|
|
376
|
|
|
add_action( 'admin_notices', '_give_register_admin_notices', - 1 ); |
|
377
|
|
|
|
|
378
|
|
|
|
|
379
|
|
|
/** |
|
380
|
|
|
* Display admin bar when active. |
|
381
|
|
|
* |
|
382
|
|
|
* @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference. |
|
383
|
|
|
* |
|
384
|
|
|
* @return bool |
|
385
|
|
|
*/ |
|
386
|
|
|
function _give_show_test_mode_notice_in_admin_bar( $wp_admin_bar ) { |
|
387
|
|
|
$is_test_mode = ! empty( $_POST['test_mode'] ) ? |
|
|
|
|
|
|
388
|
|
|
give_is_setting_enabled( $_POST['test_mode'] ) : |
|
|
|
|
|
|
389
|
|
|
give_is_test_mode(); |
|
390
|
|
|
|
|
391
|
|
|
if ( |
|
392
|
|
|
! current_user_can( 'view_give_reports' ) || |
|
393
|
|
|
! $is_test_mode |
|
394
|
|
|
) { |
|
395
|
|
|
return false; |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
|
|
// Add the main siteadmin menu item. |
|
399
|
|
|
$wp_admin_bar->add_menu( array( |
|
400
|
|
|
'id' => 'give-test-notice', |
|
401
|
|
|
'href' => admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=gateways' ), |
|
402
|
|
|
'parent' => 'top-secondary', |
|
403
|
|
|
'title' => esc_html__( 'Give Test Mode Active', 'give' ), |
|
404
|
|
|
'meta' => array( 'class' => 'give-test-mode-active' ), |
|
405
|
|
|
) ); |
|
406
|
|
|
|
|
407
|
|
|
return true; |
|
408
|
|
|
} |
|
409
|
|
|
add_action( 'admin_bar_menu', '_give_show_test_mode_notice_in_admin_bar', 1000, 1 ); |