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
|
|
|
* Register admin notices. |
121
|
|
|
* |
122
|
|
|
* @since 1.8.9 |
123
|
|
|
*/ |
124
|
|
|
function _give_register_admin_notices() { |
125
|
|
|
// Bailout. |
126
|
|
|
if ( ! is_admin() ) { |
127
|
|
|
return; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
// Bulk action notices. |
131
|
|
|
if ( |
132
|
|
|
isset( $_GET['action'] ) && |
133
|
|
|
! empty( $_GET['action'] ) |
134
|
|
|
) { |
135
|
|
|
|
136
|
|
|
// Add payment bulk notice. |
137
|
|
|
if ( |
138
|
|
|
current_user_can( 'edit_give_payments' ) && |
139
|
|
|
isset( $_GET['payment'] ) && |
140
|
|
|
! empty( $_GET['payment'] ) |
141
|
|
|
) { |
142
|
|
|
$payment_count = isset( $_GET['payment'] ) ? count( $_GET['payment'] ) : 0; |
|
|
|
|
143
|
|
|
|
144
|
|
|
switch ( $_GET['action'] ) { |
|
|
|
|
145
|
|
View Code Duplication |
case 'delete': |
|
|
|
|
146
|
|
|
Give()->notices->register_notice( array( |
147
|
|
|
'id' => 'bulk_action_delete', |
148
|
|
|
'type' => 'updated', |
149
|
|
|
'description' => sprintf( |
150
|
|
|
_n( |
151
|
|
|
'Successfully deleted one donation.', |
152
|
|
|
'Successfully deleted %d donations.', |
153
|
|
|
$payment_count, |
154
|
|
|
'give' |
155
|
|
|
), |
156
|
|
|
$payment_count ), |
|
|
|
|
157
|
|
|
'show' => true, |
158
|
|
|
) ); |
159
|
|
|
|
160
|
|
|
break; |
161
|
|
|
|
162
|
|
View Code Duplication |
case 'resend-receipt': |
|
|
|
|
163
|
|
|
Give()->notices->register_notice( array( |
164
|
|
|
'id' => 'bulk_action_resend_receipt', |
165
|
|
|
'type' => 'updated', |
166
|
|
|
'description' => sprintf( |
167
|
|
|
_n( |
168
|
|
|
'Successfully sent email receipt to one recipient.', |
169
|
|
|
'Successfully sent email receipts to %d recipients.', |
170
|
|
|
$payment_count, |
171
|
|
|
'give' |
172
|
|
|
), |
173
|
|
|
$payment_count |
174
|
|
|
), |
175
|
|
|
'show' => true, |
176
|
|
|
) ); |
177
|
|
|
break; |
178
|
|
|
|
179
|
|
|
case 'set-status-publish' : |
180
|
|
|
case 'set-status-pending' : |
181
|
|
|
case 'set-status-processing' : |
182
|
|
|
case 'set-status-refunded' : |
183
|
|
|
case 'set-status-revoked' : |
184
|
|
|
case 'set-status-failed' : |
185
|
|
|
case 'set-status-cancelled' : |
186
|
|
|
case 'set-status-abandoned' : |
187
|
|
View Code Duplication |
case 'set-status-preapproval' : |
|
|
|
|
188
|
|
|
Give()->notices->register_notice( array( |
189
|
|
|
'id' => 'bulk_action_status_change', |
190
|
|
|
'type' => 'updated', |
191
|
|
|
'description' => _n( |
192
|
|
|
'Donation status updated successfully.', |
193
|
|
|
'Donation statuses updated successfully.', |
194
|
|
|
$payment_count, |
195
|
|
|
'give' |
196
|
|
|
), |
197
|
|
|
'show' => true, |
198
|
|
|
) ); |
199
|
|
|
break; |
200
|
|
|
} |
|
|
|
|
201
|
|
|
|
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
// Add give message notices. |
206
|
|
|
if ( ! empty( $_GET['give-message'] ) ) { |
|
|
|
|
207
|
|
|
// Donation reports errors. |
208
|
|
|
if ( current_user_can( 'view_give_reports' ) ) { |
209
|
|
|
switch ( $_GET['give-message'] ) { |
|
|
|
|
210
|
|
View Code Duplication |
case 'donation_deleted' : |
|
|
|
|
211
|
|
|
Give()->notices->register_notice( array( |
212
|
|
|
'id' => 'give-donation-deleted', |
213
|
|
|
'type' => 'updated', |
214
|
|
|
'description' => __( 'The donation has been deleted.', 'give' ), |
215
|
|
|
'show' => true, |
216
|
|
|
) ); |
217
|
|
|
break; |
218
|
|
View Code Duplication |
case 'email_sent' : |
|
|
|
|
219
|
|
|
Give()->notices->register_notice( array( |
220
|
|
|
'id' => 'give-payment-sent', |
221
|
|
|
'type' => 'updated', |
222
|
|
|
'description' => __( 'The donation receipt has been resent.', 'give' ), |
223
|
|
|
'show' => true, |
224
|
|
|
) ); |
225
|
|
|
break; |
226
|
|
View Code Duplication |
case 'refreshed-reports' : |
|
|
|
|
227
|
|
|
Give()->notices->register_notice( array( |
228
|
|
|
'id' => 'give-refreshed-reports', |
229
|
|
|
'type' => 'updated', |
230
|
|
|
'description' => __( 'The reports cache has been cleared.', 'give' ), |
231
|
|
|
'show' => true, |
232
|
|
|
) ); |
233
|
|
|
break; |
234
|
|
View Code Duplication |
case 'donation-note-deleted' : |
|
|
|
|
235
|
|
|
Give()->notices->register_notice( array( |
236
|
|
|
'id' => 'give-donation-note-deleted', |
237
|
|
|
'type' => 'updated', |
238
|
|
|
'description' => __( 'The donation note has been deleted.', 'give' ), |
239
|
|
|
'show' => true, |
240
|
|
|
) ); |
241
|
|
|
break; |
242
|
|
|
} |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
// Give settings notices and errors. |
246
|
|
|
if ( current_user_can( 'manage_give_settings' ) ) { |
247
|
|
|
switch ( $_GET['give-message'] ) { |
|
|
|
|
248
|
|
View Code Duplication |
case 'settings-imported' : |
|
|
|
|
249
|
|
|
Give()->notices->register_notice( array( |
250
|
|
|
'id' => 'give-settings-imported', |
251
|
|
|
'type' => 'updated', |
252
|
|
|
'description' => __( 'The settings have been imported.', 'give' ), |
253
|
|
|
'show' => true, |
254
|
|
|
) ); |
255
|
|
|
break; |
256
|
|
View Code Duplication |
case 'api-key-generated' : |
|
|
|
|
257
|
|
|
Give()->notices->register_notice( array( |
258
|
|
|
'id' => 'give-api-key-generated', |
259
|
|
|
'type' => 'updated', |
260
|
|
|
'description' => __( 'API keys have been generated.', 'give' ), |
261
|
|
|
'show' => true, |
262
|
|
|
) ); |
263
|
|
|
break; |
264
|
|
View Code Duplication |
case 'api-key-exists' : |
|
|
|
|
265
|
|
|
Give()->notices->register_notice( array( |
266
|
|
|
'id' => 'give-api-key-exists', |
267
|
|
|
'type' => 'updated', |
268
|
|
|
'description' => __( 'The specified user already has API keys.', 'give' ), |
269
|
|
|
'show' => true, |
270
|
|
|
) ); |
271
|
|
|
break; |
272
|
|
View Code Duplication |
case 'api-key-regenerated' : |
|
|
|
|
273
|
|
|
Give()->notices->register_notice( array( |
274
|
|
|
'id' => 'give-api-key-regenerated', |
275
|
|
|
'type' => 'updated', |
276
|
|
|
'description' => __( 'API keys have been regenerated.', 'give' ), |
277
|
|
|
'show' => true, |
278
|
|
|
) ); |
279
|
|
|
break; |
280
|
|
View Code Duplication |
case 'api-key-revoked' : |
|
|
|
|
281
|
|
|
Give()->notices->register_notice( array( |
282
|
|
|
'id' => 'give-api-key-revoked', |
283
|
|
|
'type' => 'updated', |
284
|
|
|
'description' => __( 'API keys have been revoked.', 'give' ), |
285
|
|
|
'show' => true, |
286
|
|
|
) ); |
287
|
|
|
break; |
288
|
|
View Code Duplication |
case 'sent-test-email' : |
|
|
|
|
289
|
|
|
Give()->notices->register_notice( array( |
290
|
|
|
'id' => 'give-sent-test-email', |
291
|
|
|
'type' => 'updated', |
292
|
|
|
'description' => __( 'The test email has been sent.', 'give' ), |
293
|
|
|
'show' => true, |
294
|
|
|
) ); |
295
|
|
|
break; |
296
|
|
View Code Duplication |
case 'matched-success-failure-page': |
|
|
|
|
297
|
|
|
Give()->notices->register_notice( array( |
298
|
|
|
'id' => 'give-matched-success-failure-page', |
299
|
|
|
'type' => 'updated', |
300
|
|
|
'description' => __( 'You cannot set the success and failed pages to the same page', 'give' ), |
301
|
|
|
'show' => true, |
302
|
|
|
) ); |
303
|
|
|
break; |
304
|
|
|
} |
305
|
|
|
} |
306
|
|
|
// Payments errors. |
307
|
|
|
if ( current_user_can( 'edit_give_payments' ) ) { |
308
|
|
|
switch ( $_GET['give-message'] ) { |
|
|
|
|
309
|
|
View Code Duplication |
case 'note-added' : |
|
|
|
|
310
|
|
|
Give()->notices->register_notice( array( |
311
|
|
|
'id' => 'give-note-added', |
312
|
|
|
'type' => 'updated', |
313
|
|
|
'description' => __( 'The donation note has been added.', 'give' ), |
314
|
|
|
'show' => true, |
315
|
|
|
) ); |
316
|
|
|
break; |
317
|
|
View Code Duplication |
case 'payment-updated' : |
|
|
|
|
318
|
|
|
Give()->notices->register_notice( array( |
319
|
|
|
'id' => 'give-payment-updated', |
320
|
|
|
'type' => 'updated', |
321
|
|
|
'description' => __( 'The donation has been updated.', 'give' ), |
322
|
|
|
'show' => true, |
323
|
|
|
) ); |
324
|
|
|
break; |
325
|
|
|
} |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
// Donor Notices. |
329
|
|
|
if ( current_user_can( 'edit_give_payments' ) ) { |
330
|
|
|
switch ( $_GET['give-message'] ) { |
|
|
|
|
331
|
|
View Code Duplication |
case 'donor-deleted' : |
|
|
|
|
332
|
|
|
Give()->notices->register_notice( array( |
333
|
|
|
'id' => 'give-donor-deleted', |
334
|
|
|
'type' => 'updated', |
335
|
|
|
'description' => __( 'The selected donor(s) has been deleted.', 'give' ), |
336
|
|
|
'show' => true, |
337
|
|
|
) ); |
338
|
|
|
break; |
339
|
|
|
|
340
|
|
View Code Duplication |
case 'donor-donations-deleted' : |
|
|
|
|
341
|
|
|
Give()->notices->register_notice( array( |
342
|
|
|
'id' => 'give-donor-donations-deleted', |
343
|
|
|
'type' => 'updated', |
344
|
|
|
'description' => __( 'The selected donor(s) and its associated donations has been deleted.', 'give' ), |
345
|
|
|
'show' => true, |
346
|
|
|
) ); |
347
|
|
|
break; |
348
|
|
|
|
349
|
|
View Code Duplication |
case 'confirm-delete-donor' : |
|
|
|
|
350
|
|
|
Give()->notices->register_notice( array( |
351
|
|
|
'id' => 'give-confirm-delete-donor', |
352
|
|
|
'type' => 'updated', |
353
|
|
|
'description' => __( 'You must confirm to delete the selected donor(s).', 'give' ), |
354
|
|
|
'show' => true, |
355
|
|
|
) ); |
356
|
|
|
break; |
357
|
|
|
|
358
|
|
View Code Duplication |
case 'invalid-donor-id' : |
|
|
|
|
359
|
|
|
Give()->notices->register_notice( array( |
360
|
|
|
'id' => 'give-invalid-donor-id', |
361
|
|
|
'type' => 'updated', |
362
|
|
|
'description' => __( 'Invalid Donor ID.', 'give' ), |
363
|
|
|
'show' => true, |
364
|
|
|
) ); |
365
|
|
|
break; |
366
|
|
|
|
367
|
|
|
case 'donor-delete-failed' : |
368
|
|
|
Give()->notices->register_notice( array( |
369
|
|
|
'id' => 'give-donor-delete-failed', |
370
|
|
|
'type' => 'error', |
371
|
|
|
'description' => __( 'Unable to delete selected donor(s).', 'give' ), |
372
|
|
|
'show' => true, |
373
|
|
|
) ); |
374
|
|
|
break; |
375
|
|
|
|
376
|
|
View Code Duplication |
case 'email-added' : |
|
|
|
|
377
|
|
|
Give()->notices->register_notice( array( |
378
|
|
|
'id' => 'give-donor-email-added', |
379
|
|
|
'type' => 'updated', |
380
|
|
|
'description' => __( 'Donor email added.', 'give' ), |
381
|
|
|
'show' => true, |
382
|
|
|
) ); |
383
|
|
|
break; |
384
|
|
|
|
385
|
|
View Code Duplication |
case 'email-removed' : |
|
|
|
|
386
|
|
|
Give()->notices->register_notice( array( |
387
|
|
|
'id' => 'give-donor-email-removed', |
388
|
|
|
'type' => 'updated', |
389
|
|
|
'description' => __( 'Donor email removed.', 'give' ), |
390
|
|
|
'show' => true, |
391
|
|
|
) ); |
392
|
|
|
break; |
393
|
|
|
|
394
|
|
View Code Duplication |
case 'email-remove-failed' : |
|
|
|
|
395
|
|
|
Give()->notices->register_notice( array( |
396
|
|
|
'id' => 'give-donor-email-remove-failed', |
397
|
|
|
'type' => 'updated', |
398
|
|
|
'description' => __( 'Failed to remove donor email.', 'give' ), |
399
|
|
|
'show' => true, |
400
|
|
|
) ); |
401
|
|
|
break; |
402
|
|
|
|
403
|
|
View Code Duplication |
case 'primary-email-updated' : |
|
|
|
|
404
|
|
|
Give()->notices->register_notice( array( |
405
|
|
|
'id' => 'give-donor-primary-email-updated', |
406
|
|
|
'type' => 'updated', |
407
|
|
|
'description' => __( 'Primary email updated for donor.', 'give' ), |
408
|
|
|
'show' => true, |
409
|
|
|
) ); |
410
|
|
|
break; |
411
|
|
|
|
412
|
|
View Code Duplication |
case 'primary-email-failed' : |
|
|
|
|
413
|
|
|
Give()->notices->register_notice( array( |
414
|
|
|
'id' => 'give-donor-primary-email-failed', |
415
|
|
|
'type' => 'updated', |
416
|
|
|
'description' => __( 'Failed to set primary email.', 'give' ), |
417
|
|
|
'show' => true, |
418
|
|
|
) ); |
419
|
|
|
break; |
420
|
|
|
|
421
|
|
View Code Duplication |
case 'reconnect-user' : |
|
|
|
|
422
|
|
|
Give()->notices->register_notice( array( |
423
|
|
|
'id' => 'give-donor-reconnect-user', |
424
|
|
|
'type' => 'updated', |
425
|
|
|
'description' => __( 'User has been successfully connected with Donor.', 'give' ), |
426
|
|
|
'show' => true, |
427
|
|
|
) ); |
428
|
|
|
break; |
429
|
|
|
|
430
|
|
View Code Duplication |
case 'profile-updated' : |
|
|
|
|
431
|
|
|
Give()->notices->register_notice( array( |
432
|
|
|
'id' => 'give-donor-profile-updated', |
433
|
|
|
'type' => 'updated', |
434
|
|
|
'description' => __( 'Donor information updated successfully.', 'give' ), |
435
|
|
|
'show' => true, |
436
|
|
|
) ); |
437
|
|
|
break; |
438
|
|
|
} |
439
|
|
|
} |
440
|
|
|
} |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
add_action( 'admin_notices', '_give_register_admin_notices', - 1 ); |
444
|
|
|
|
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* Display admin bar when active. |
448
|
|
|
* |
449
|
|
|
* @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference. |
450
|
|
|
* |
451
|
|
|
* @return bool |
452
|
|
|
*/ |
453
|
|
|
function _give_show_test_mode_notice_in_admin_bar( $wp_admin_bar ) { |
454
|
|
|
$is_test_mode = ! empty( $_POST['test_mode'] ) ? |
|
|
|
|
455
|
|
|
give_is_setting_enabled( $_POST['test_mode'] ) : |
|
|
|
|
456
|
|
|
give_is_test_mode(); |
457
|
|
|
|
458
|
|
|
if ( |
459
|
|
|
! current_user_can( 'view_give_reports' ) || |
460
|
|
|
! $is_test_mode |
461
|
|
|
) { |
462
|
|
|
return false; |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
// Add the main site admin menu item. |
466
|
|
|
$wp_admin_bar->add_menu( array( |
467
|
|
|
'id' => 'give-test-notice', |
468
|
|
|
'href' => admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=gateways' ), |
469
|
|
|
'parent' => 'top-secondary', |
470
|
|
|
'title' => __( 'Give Test Mode Active', 'give' ), |
471
|
|
|
'meta' => array( 'class' => 'give-test-mode-active' ), |
472
|
|
|
) ); |
473
|
|
|
|
474
|
|
|
return true; |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
add_action( 'admin_bar_menu', '_give_show_test_mode_notice_in_admin_bar', 1000, 1 ); |
478
|
|
|
|
479
|
|
|
/** |
480
|
|
|
* Add Link to Import page in from donation archive and donation single page |
481
|
|
|
* |
482
|
|
|
* @since 1.8.13 |
483
|
|
|
*/ |
484
|
|
|
function give_import_page_link_callback() { |
485
|
|
|
?> |
486
|
|
|
<a href="<?php echo esc_url( give_import_page_url() ); ?>" |
487
|
|
|
class="page-import-action page-title-action"><?php _e( 'Import Donations', 'give' ); ?></a> |
488
|
|
|
|
489
|
|
|
<?php |
490
|
|
|
// Check if view donation single page only. |
491
|
|
|
if ( ! empty( $_REQUEST['view'] ) && 'view-payment-details' === (string) give_clean( $_REQUEST['view'] ) && 'give-payment-history' === give_clean( $_REQUEST['page'] ) ) { |
|
|
|
|
492
|
|
|
?> |
493
|
|
|
<style type="text/css"> |
494
|
|
|
.wrap #transaction-details-heading { |
495
|
|
|
display: inline-block; |
496
|
|
|
} |
497
|
|
|
</style> |
498
|
|
|
<?php |
499
|
|
|
} |
500
|
|
|
} |
501
|
|
|
|
502
|
|
|
add_action( 'give_payments_page_top', 'give_import_page_link_callback', 11 ); |
503
|
|
|
|
504
|
|
|
/** |
505
|
|
|
* Load donation import ajax callback |
506
|
|
|
* Fire when importing from CSV start |
507
|
|
|
* |
508
|
|
|
* @since 1.8.13 |
509
|
|
|
* |
510
|
|
|
* @return json $json_data |
511
|
|
|
*/ |
512
|
|
|
function give_donation_import_callback() { |
513
|
|
|
$import_setting = array(); |
514
|
|
|
$fields = isset( $_POST['fields'] ) ? $_POST['fields'] : null; |
|
|
|
|
515
|
|
|
|
516
|
|
|
parse_str( $fields ); |
517
|
|
|
|
518
|
|
|
$import_setting['create_user'] = $create_user; |
519
|
|
|
$import_setting['mode'] = $mode; |
520
|
|
|
$import_setting['delimiter'] = $delimiter; |
521
|
|
|
$import_setting['csv'] = $csv; |
522
|
|
|
$import_setting['delete_csv'] = $delete_csv; |
523
|
|
|
|
524
|
|
|
// Parent key id. |
525
|
|
|
$main_key = maybe_unserialize( $main_key ); |
526
|
|
|
|
527
|
|
|
$current = absint( $_REQUEST['current'] ); |
|
|
|
|
528
|
|
|
$total_ajax = absint( $_REQUEST['total_ajax'] ); |
|
|
|
|
529
|
|
|
$start = absint( $_REQUEST['start'] ); |
|
|
|
|
530
|
|
|
$end = absint( $_REQUEST['end'] ); |
|
|
|
|
531
|
|
|
$next = absint( $_REQUEST['next'] ); |
|
|
|
|
532
|
|
|
$total = absint( $_REQUEST['total'] ); |
|
|
|
|
533
|
|
|
$per_page = absint( $_REQUEST['per_page'] ); |
|
|
|
|
534
|
|
|
if ( empty( $delimiter ) ) { |
535
|
|
|
$delimiter = ','; |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
// Processing done here. |
539
|
|
|
$raw_data = give_get_donation_data_from_csv( $csv, $start, $end, $delimiter ); |
540
|
|
|
$raw_key = maybe_unserialize( $mapto ); |
541
|
|
|
|
542
|
|
|
// Prevent normal emails. |
543
|
|
|
remove_action( 'give_complete_donation', 'give_trigger_donation_receipt', 999 ); |
544
|
|
|
remove_action( 'give_insert_user', 'give_new_user_notification', 10 ); |
545
|
|
|
remove_action( 'give_insert_payment', 'give_payment_save_page_data' ); |
546
|
|
|
|
547
|
|
|
$current_key = $start; |
548
|
|
|
foreach ( $raw_data as $row_data ) { |
549
|
|
|
$import_setting['donation_key'] = $current_key; |
550
|
|
|
give_save_import_donation_to_db( $raw_key, $row_data, $main_key, $import_setting ); |
551
|
|
|
$current_key++; |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
// Check if function exists or not. |
555
|
|
|
if ( function_exists( 'give_payment_save_page_data' ) ) { |
556
|
|
|
add_action( 'give_insert_payment', 'give_payment_save_page_data' ); |
557
|
|
|
} |
558
|
|
|
add_action( 'give_insert_user', 'give_new_user_notification', 10, 2 ); |
559
|
|
|
add_action( 'give_complete_donation', 'give_trigger_donation_receipt', 999 ); |
560
|
|
|
|
561
|
|
|
if ( $next == false ) { |
|
|
|
|
562
|
|
|
$json_data = array( |
563
|
|
|
'success' => true, |
564
|
|
|
'message' => __( 'All donation uploaded successfully!', 'give' ), |
565
|
|
|
); |
566
|
|
|
} else { |
567
|
|
|
$index_start = $start; |
568
|
|
|
$index_end = $end; |
569
|
|
|
$last = false; |
570
|
|
|
$next = true; |
571
|
|
|
if ( $next ) { |
572
|
|
|
$index_start = $index_start + $per_page; |
573
|
|
|
$index_end = $per_page + ( $index_start - 1 ); |
574
|
|
|
} |
575
|
|
|
if ( $index_end >= $total ) { |
576
|
|
|
$index_end = $total; |
577
|
|
|
$last = true; |
578
|
|
|
} |
579
|
|
|
$json_data = array( |
580
|
|
|
'raw_data' => $raw_data, |
581
|
|
|
'raw_key' => $raw_key, |
582
|
|
|
'next' => $next, |
583
|
|
|
'start' => $index_start, |
584
|
|
|
'end' => $index_end, |
585
|
|
|
'last' => $last, |
586
|
|
|
); |
587
|
|
|
} |
588
|
|
|
|
589
|
|
|
$url = give_import_page_url( array( |
590
|
|
|
'step' => '4', |
591
|
|
|
'importer-type' => 'import_donations', |
592
|
|
|
'csv' => $csv, |
593
|
|
|
'total' => $total, |
594
|
|
|
'delete_csv' => $import_setting['delete_csv'], |
595
|
|
|
'success' => ( isset( $json_data['success'] ) ? $json_data['success'] : '' ), |
596
|
|
|
) ); |
597
|
|
|
$json_data['url'] = $url; |
598
|
|
|
|
599
|
|
|
$current ++; |
600
|
|
|
$json_data['current'] = $current; |
601
|
|
|
|
602
|
|
|
$percentage = ( 100 / ( $total_ajax + 1 ) ) * $current; |
603
|
|
|
$json_data['percentage'] = $percentage; |
604
|
|
|
|
605
|
|
|
$json_data = apply_filters( 'give_import_ajax_responces', $json_data, $fields ); |
606
|
|
|
wp_die( json_encode( $json_data ) ); |
607
|
|
|
} |
608
|
|
|
|
609
|
|
|
add_action( 'wp_ajax_give_donation_import', 'give_donation_import_callback' ); |
610
|
|
|
|
611
|
|
|
/** |
612
|
|
|
* Load core settings import ajax callback |
613
|
|
|
* Fire when importing from JSON start |
614
|
|
|
* |
615
|
|
|
* @since 1.8.17 |
616
|
|
|
* |
617
|
|
|
* @return json $json_data |
618
|
|
|
*/ |
619
|
|
|
|
620
|
|
|
function give_core_settings_import_callback() { |
621
|
|
|
$fields = isset( $_POST['fields'] ) ? $_POST['fields'] : null; |
|
|
|
|
622
|
|
|
parse_str( $fields, $fields ); |
623
|
|
|
|
624
|
|
|
$json_data['success'] = false; |
625
|
|
|
|
626
|
|
|
/** |
627
|
|
|
* Filter to Modify fields that are being pass by the ajax before importing of the core setting start. |
628
|
|
|
* |
629
|
|
|
* @access public |
630
|
|
|
* |
631
|
|
|
* @since 1.8.17 |
632
|
|
|
* |
633
|
|
|
* @param array $fields |
634
|
|
|
* |
635
|
|
|
* @return array $fields |
636
|
|
|
*/ |
637
|
|
|
$fields = (array) apply_filters( 'give_import_core_settings_fields', $fields ); |
638
|
|
|
|
639
|
|
|
$file_name = ( ! empty( $fields['file_name'] ) ? give_clean( $fields['file_name'] ) : false ); |
640
|
|
|
|
641
|
|
|
if ( ! empty( $file_name ) ) { |
642
|
|
|
$type = ( ! empty( $fields['type'] ) ? give_clean( $fields['type'] ) : 'merge' ); |
643
|
|
|
|
644
|
|
|
// Get the json data from the file and then alter it in array format |
645
|
|
|
$json_string = give_get_core_settings_json( $file_name ); |
|
|
|
|
646
|
|
|
$json_to_array = json_decode( $json_string, true ); |
647
|
|
|
|
648
|
|
|
// get the current settign from the options table. |
649
|
|
|
$host_give_options = get_option( 'give_settings', array() ); |
650
|
|
|
|
651
|
|
|
// Save old settins for backup. |
652
|
|
|
update_option( 'give_settings_old', $host_give_options ); |
653
|
|
|
|
654
|
|
|
/** |
655
|
|
|
* Filter to Modify Core Settings that are being going to get import in options table as give settings. |
656
|
|
|
* |
657
|
|
|
* @access public |
658
|
|
|
* |
659
|
|
|
* @since 1.8.17 |
660
|
|
|
* |
661
|
|
|
* @param array $json_to_array Setting that are being going to get imported |
662
|
|
|
* @param array $type Type of Import |
663
|
|
|
* @param array $host_give_options Setting old setting that used to be in the options table. |
664
|
|
|
* @param array $fields Data that is being send from the ajax |
665
|
|
|
* |
666
|
|
|
* @return array $json_to_array Setting that are being going to get imported |
667
|
|
|
*/ |
668
|
|
|
$json_to_array = (array) apply_filters( 'give_import_core_settings_data', $json_to_array, $type, $host_give_options, $fields ); |
669
|
|
|
|
670
|
|
|
update_option( 'give_settings', $json_to_array ); |
671
|
|
|
|
672
|
|
|
$json_data['success'] = true; |
673
|
|
|
} |
674
|
|
|
|
675
|
|
|
$json_data['percentage'] = 100; |
676
|
|
|
|
677
|
|
|
/** |
678
|
|
|
* Filter to Modify core import setting page url |
679
|
|
|
* |
680
|
|
|
* @access public |
681
|
|
|
* |
682
|
|
|
* @since 1.8.17 |
683
|
|
|
* |
684
|
|
|
* @return array $url |
685
|
|
|
*/ |
686
|
|
|
$json_data['url'] = give_import_page_url( (array) apply_filters( 'give_import_core_settings_success_url', array( |
687
|
|
|
'step' => ( empty( $json_data['success'] ) ? '1' : '3' ), |
688
|
|
|
'importer-type' => 'import_core_setting', |
689
|
|
|
'success' => ( empty( $json_data['success'] ) ? '0' : '1' ), |
690
|
|
|
) ) ); |
691
|
|
|
|
692
|
|
|
wp_send_json( $json_data ); |
693
|
|
|
} |
694
|
|
|
|
695
|
|
|
add_action( 'wp_ajax_give_core_settings_import', 'give_core_settings_import_callback' ); |
696
|
|
|
|
697
|
|
|
/** |
698
|
|
|
* Initializes blank slate content if a list table is empty. |
699
|
|
|
* |
700
|
|
|
* @since 1.8.13 |
701
|
|
|
*/ |
702
|
|
|
function give_blank_slate() { |
703
|
|
|
$blank_slate = new Give_Blank_Slate(); |
704
|
|
|
$blank_slate->init(); |
705
|
|
|
} |
706
|
|
|
|
707
|
|
|
add_action( 'current_screen', 'give_blank_slate' ); |
708
|
|
|
|
709
|
|
|
/** |
710
|
|
|
* Get Array of WP User Roles. |
711
|
|
|
* |
712
|
|
|
* @since 1.8.13 |
713
|
|
|
* |
714
|
|
|
* @return array |
715
|
|
|
*/ |
716
|
|
|
function give_get_user_roles() { |
717
|
|
|
$user_roles = array(); |
718
|
|
|
|
719
|
|
|
// Loop through User Roles. |
720
|
|
|
foreach ( get_editable_roles() as $role_name => $role_info ): |
721
|
|
|
$user_roles[ $role_name ] = $role_info['name']; |
722
|
|
|
endforeach; |
723
|
|
|
|
724
|
|
|
return $user_roles; |
725
|
|
|
} |