1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* AJAX Functions |
4
|
|
|
* |
5
|
|
|
* Process the front-end AJAX actions. |
6
|
|
|
* |
7
|
|
|
* @package Give |
8
|
|
|
* @subpackage Functions/AJAX |
9
|
|
|
* @copyright Copyright (c) 2016, WordImpress |
10
|
|
|
* @license https://opensource.org/licenses/gpl-license GNU Public License |
11
|
|
|
* @since 1.0 |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
// Exit if accessed directly. |
15
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
16
|
|
|
exit; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Check if AJAX works as expected |
21
|
|
|
* Note: Do not use this function before init hook. |
22
|
|
|
* |
23
|
|
|
* @since 1.0 |
24
|
|
|
* |
25
|
|
|
* @return bool True if AJAX works, false otherwise |
26
|
|
|
*/ |
27
|
|
|
function give_test_ajax_works() { |
28
|
|
|
// Handle ajax. |
29
|
|
|
if ( doing_action( 'wp_ajax_nopriv_give_test_ajax' ) ) { |
30
|
|
|
wp_die( 0, 200 ); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
// Check if the Airplane Mode plugin is installed. |
34
|
|
|
if ( class_exists( 'Airplane_Mode_Core' ) ) { |
35
|
|
|
|
36
|
|
|
$airplane = Airplane_Mode_Core::getInstance(); |
37
|
|
|
|
38
|
|
|
if ( method_exists( $airplane, 'enabled' ) ) { |
39
|
|
|
|
40
|
|
|
if ( $airplane->enabled() ) { |
41
|
|
|
return true; |
42
|
|
|
} |
43
|
|
|
} else { |
44
|
|
|
|
45
|
|
|
if ( 'on' === $airplane->check_status() ) { |
46
|
|
|
return true; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
add_filter( 'block_local_requests', '__return_false' ); |
52
|
|
|
|
53
|
|
|
if ( Give_Cache::get( '_give_ajax_works', true ) ) { |
54
|
|
|
return true; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$params = array( |
58
|
|
|
'sslverify' => false, |
59
|
|
|
'timeout' => 30, |
60
|
|
|
'body' => array( |
61
|
|
|
'action' => 'give_test_ajax', |
62
|
|
|
), |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
$ajax = wp_remote_post( give_get_ajax_url(), $params ); |
66
|
|
|
|
67
|
|
|
$works = true; |
68
|
|
|
|
69
|
|
|
if ( is_wp_error( $ajax ) ) { |
70
|
|
|
|
71
|
|
|
$works = false; |
72
|
|
|
|
73
|
|
|
} else { |
74
|
|
|
|
75
|
|
|
if ( empty( $ajax['response'] ) ) { |
76
|
|
|
$works = false; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if ( empty( $ajax['response']['code'] ) || 200 !== (int) $ajax['response']['code'] ) { |
80
|
|
|
$works = false; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if ( empty( $ajax['response']['message'] ) || 'OK' !== $ajax['response']['message'] ) { |
84
|
|
|
$works = false; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
if ( ! isset( $ajax['body'] ) || 0 !== (int) $ajax['body'] ) { |
88
|
|
|
$works = false; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if ( $works ) { |
93
|
|
|
Give_Cache::set( '_give_ajax_works', '1', DAY_IN_SECONDS, true ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return apply_filters( 'give_test_ajax_works', $works ); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
add_action( 'wp_ajax_nopriv_give_test_ajax', 'give_test_ajax_works' ); |
100
|
|
|
|
101
|
|
|
/** |
102
|
2 |
|
* Get AJAX URL |
103
|
|
|
* |
104
|
2 |
|
* @since 1.0 |
105
|
2 |
|
* |
106
|
|
|
* @param array $query |
107
|
2 |
|
* |
108
|
|
|
* @return string |
109
|
|
|
*/ |
110
|
|
|
function give_get_ajax_url( $query = array() ) { |
111
|
2 |
|
$scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
112
|
|
|
|
113
|
|
|
$current_url = give_get_current_page_url(); |
114
|
|
|
$ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
115
|
|
|
|
116
|
|
|
if ( preg_match( '/^https/', $current_url ) && ! preg_match( '/^https/', $ajax_url ) ) { |
117
|
|
|
$ajax_url = preg_replace( '/^http/', 'https', $ajax_url ); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
if ( ! empty( $query ) ) { |
121
|
|
|
$ajax_url = add_query_arg( $query, $ajax_url ); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
return apply_filters( 'give_ajax_url', $ajax_url ); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Loads Checkout Login Fields via AJAX |
129
|
|
|
* |
130
|
|
|
* @since 1.0 |
131
|
|
|
* |
132
|
|
|
* @return void |
133
|
|
|
*/ |
134
|
|
|
function give_load_checkout_login_fields() { |
135
|
|
|
/** |
136
|
|
|
* Fire when render login fields via ajax. |
137
|
|
|
* |
138
|
|
|
* @since 1.7 |
139
|
|
|
*/ |
140
|
|
|
do_action( 'give_donation_form_login_fields' ); |
141
|
|
|
|
142
|
|
|
give_die(); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
add_action( 'wp_ajax_nopriv_give_checkout_login', 'give_load_checkout_login_fields' ); |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Load Checkout Fields |
149
|
|
|
* |
150
|
|
|
* @since 1.3.6 |
151
|
|
|
* |
152
|
|
|
* @return void |
153
|
|
|
*/ |
154
|
|
|
function give_load_checkout_fields() { |
155
|
|
|
$form_id = isset( $_POST['form_id'] ) ? $_POST['form_id'] : ''; |
|
|
|
|
156
|
|
|
|
157
|
|
|
ob_start(); |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Fire to render registration/login form. |
161
|
|
|
* |
162
|
|
|
* @since 1.7 |
163
|
|
|
*/ |
164
|
|
|
do_action( 'give_donation_form_register_login_fields', $form_id ); |
165
|
|
|
|
166
|
|
|
$fields = ob_get_clean(); |
167
|
|
|
|
168
|
|
|
wp_send_json( array( |
169
|
|
|
'fields' => wp_json_encode( $fields ), |
170
|
|
|
'submit' => wp_json_encode( give_get_donation_form_submit_button( $form_id ) ), |
171
|
|
|
) ); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
add_action( 'wp_ajax_nopriv_give_cancel_login', 'give_load_checkout_fields' ); |
175
|
|
|
add_action( 'wp_ajax_nopriv_give_checkout_register', 'give_load_checkout_fields' ); |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Get Form Title via AJAX (used only in WordPress Admin) |
179
|
|
|
* |
180
|
|
|
* @since 1.0 |
181
|
|
|
* |
182
|
|
|
* @return void |
183
|
|
|
*/ |
184
|
|
|
function give_ajax_get_form_title() { |
185
|
|
|
if ( isset( $_POST['form_id'] ) ) { |
186
|
|
|
$title = get_the_title( $_POST['form_id'] ); |
|
|
|
|
187
|
|
|
if ( $title ) { |
188
|
|
|
echo $title; |
|
|
|
|
189
|
|
|
} else { |
190
|
|
|
echo 'fail'; |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
give_die(); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
add_action( 'wp_ajax_give_get_form_title', 'give_ajax_get_form_title' ); |
197
|
|
|
add_action( 'wp_ajax_nopriv_give_get_form_title', 'give_ajax_get_form_title' ); |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Retrieve a states drop down |
201
|
|
|
* |
202
|
|
|
* @since 1.0 |
203
|
|
|
* |
204
|
|
|
* @return void |
205
|
|
|
*/ |
206
|
|
|
function give_ajax_get_states_field() { |
207
|
|
|
$states_found = false; |
208
|
|
|
$show_field = true; |
209
|
|
|
$states_require = true; |
210
|
|
|
// Get the Country code from the $_POST. |
211
|
|
|
$country = sanitize_text_field( $_POST['country'] ); |
|
|
|
|
212
|
|
|
|
213
|
|
|
// Get the field name from the $_POST. |
214
|
|
|
$field_name = sanitize_text_field( $_POST['field_name'] ); |
|
|
|
|
215
|
|
|
|
216
|
|
|
$label = __( 'State', 'give' ); |
217
|
|
|
$states_label = give_get_states_label(); |
218
|
|
|
|
219
|
|
|
$default_state = ''; |
220
|
|
|
if ( $country === give_get_country() ) { |
221
|
|
|
$default_state = give_get_state(); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
// Check if $country code exists in the array key for states label. |
225
|
|
|
if ( array_key_exists( $country, $states_label ) ) { |
226
|
|
|
$label = $states_label[ $country ]; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
if ( empty( $country ) ) { |
230
|
|
|
$country = give_get_country(); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
$states = give_get_states( $country ); |
234
|
|
|
if ( ! empty( $states ) ) { |
235
|
|
|
$args = array( |
236
|
|
|
'name' => $field_name, |
237
|
|
|
'id' => $field_name, |
238
|
|
|
'class' => $field_name . ' give-select', |
239
|
|
|
'options' => $states, |
240
|
|
|
'show_option_all' => false, |
241
|
|
|
'show_option_none' => false, |
242
|
|
|
'placeholder' => $label, |
243
|
|
|
'selected' => $default_state, |
244
|
|
|
); |
245
|
|
|
$data = Give()->html->select( $args ); |
246
|
|
|
$states_found = true; |
247
|
|
|
} else { |
248
|
|
|
$data = 'nostates'; |
249
|
|
|
|
250
|
|
|
// Get the country list that does not have any states init. |
251
|
|
|
$no_states_country = give_no_states_country_list(); |
252
|
|
|
|
253
|
|
|
// Check if $country code exists in the array key. |
254
|
|
|
if ( array_key_exists( $country, $no_states_country ) ) { |
255
|
|
|
$show_field = false; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
// Get the country list that does not require states. |
259
|
|
|
$states_not_required_country_list = give_states_not_required_country_list(); |
260
|
|
|
|
261
|
|
|
// Check if $country code exists in the array key. |
262
|
|
|
if ( array_key_exists( $country, $states_not_required_country_list ) ) { |
263
|
|
|
$states_require = false; |
264
|
|
|
} |
265
|
|
|
} |
266
|
|
|
$response = array( |
267
|
|
|
'success' => true, |
268
|
|
|
'states_found' => $states_found, |
269
|
|
|
'states_label' => $label, |
270
|
|
|
'show_field' => $show_field, |
271
|
|
|
'states_require' => $states_require, |
272
|
|
|
'data' => $data, |
273
|
|
|
'default_state' => $default_state, |
274
|
|
|
); |
275
|
|
|
wp_send_json( $response ); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
add_action( 'wp_ajax_give_get_states', 'give_ajax_get_states_field' ); |
279
|
|
|
add_action( 'wp_ajax_nopriv_give_get_states', 'give_ajax_get_states_field' ); |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* Retrieve donation forms via AJAX for chosen dropdown search field. |
283
|
|
|
* |
284
|
|
|
* @since 1.0 |
285
|
|
|
* |
286
|
|
|
* @return void |
287
|
|
|
*/ |
288
|
|
|
function give_ajax_form_search() { |
289
|
|
|
$results = array(); |
290
|
|
|
$search = esc_sql( sanitize_text_field( $_POST['s'] ) ); |
|
|
|
|
291
|
|
|
|
292
|
|
|
$args = array( |
293
|
|
|
'post_type' => 'give_forms', |
294
|
|
|
's' => $search, |
295
|
|
|
'update_post_term_cache' => false, |
296
|
|
|
'update_post_meta_cache' => false, |
297
|
|
|
'cache_results' => false, |
298
|
|
|
'no_found_rows' => true, |
299
|
|
|
'post_status' => 'publish', |
300
|
|
|
'orderby' => 'title', |
301
|
|
|
'order' => 'ASC', |
302
|
|
|
'posts_per_page' => empty( $search ) ? 30 : -1, |
303
|
|
|
); |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* Filter to modify Ajax form search args |
307
|
|
|
* |
308
|
|
|
* @since 2.1 |
309
|
|
|
* |
310
|
|
|
* @param array $args Query argument for WP_query |
311
|
|
|
* |
312
|
|
|
* @return array $args Query argument for WP_query |
313
|
|
|
*/ |
314
|
|
|
$args = (array) apply_filters( 'give_ajax_form_search_args', $args ); |
315
|
|
|
|
316
|
|
|
// get all the donation form. |
317
|
|
|
$query = new WP_Query( $args ); |
318
|
|
|
if ( $query->have_posts() ) { |
319
|
|
|
while ( $query->have_posts() ) { |
320
|
|
|
$query->the_post(); |
321
|
|
|
global $post; |
322
|
|
|
|
323
|
|
|
$results[] = array( |
324
|
|
|
'id' => $post->ID, |
325
|
|
|
'name' => $post->post_title, |
326
|
|
|
); |
327
|
|
|
} |
328
|
|
|
wp_reset_postdata(); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* Filter to modify Ajax form search result |
333
|
|
|
* |
334
|
|
|
* @since 2.1 |
335
|
|
|
* |
336
|
|
|
* @param array $results Contain the Donation Form id |
337
|
|
|
* |
338
|
|
|
* @return array $results Contain the Donation Form id |
339
|
|
|
*/ |
340
|
|
|
$results = (array) apply_filters( 'give_ajax_form_search_responce', $results ); |
341
|
|
|
|
342
|
|
|
wp_send_json( $results ); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
add_action( 'wp_ajax_give_form_search', 'give_ajax_form_search' ); |
346
|
|
|
add_action( 'wp_ajax_nopriv_give_form_search', 'give_ajax_form_search' ); |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* Search the donors database via Ajax |
350
|
|
|
* |
351
|
|
|
* @since 1.0 |
352
|
|
|
* |
353
|
|
|
* @return void |
354
|
|
|
*/ |
355
|
|
|
function give_ajax_donor_search() { |
356
|
|
|
global $wpdb; |
357
|
|
|
|
358
|
|
|
$search = esc_sql( sanitize_text_field( $_POST['s'] ) ); |
|
|
|
|
359
|
|
|
$results = array(); |
360
|
|
|
if ( ! current_user_can( 'view_give_reports' ) ) { |
361
|
|
|
$donors = array(); |
362
|
|
|
} else { |
363
|
|
|
$donors = $wpdb->get_results( "SELECT id,name,email FROM $wpdb->donors WHERE `name` LIKE '%$search%' OR `email` LIKE '%$search%' LIMIT 50" ); |
|
|
|
|
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
if ( $donors ) { |
367
|
|
|
foreach ( $donors as $donor ) { |
368
|
|
|
|
369
|
|
|
$results[] = array( |
370
|
|
|
'id' => $donor->id, |
371
|
|
|
'name' => $donor->name . ' (' . $donor->email . ')', |
372
|
|
|
); |
373
|
|
|
} |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
wp_send_json( $results ); |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
add_action( 'wp_ajax_give_donor_search', 'give_ajax_donor_search' ); |
380
|
|
|
|
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* Searches for users via ajax and returns a list of results |
384
|
|
|
* |
385
|
|
|
* @since 1.0 |
386
|
|
|
* |
387
|
|
|
* @return void |
388
|
|
|
*/ |
389
|
|
|
function give_ajax_search_users() { |
390
|
|
|
$results = array(); |
391
|
|
|
|
392
|
|
|
if ( current_user_can( 'manage_give_settings' ) ) { |
393
|
|
|
|
394
|
|
|
$search = esc_sql( sanitize_text_field( $_POST['s'] ) ); |
|
|
|
|
395
|
|
|
|
396
|
|
|
$get_users_args = array( |
397
|
|
|
'number' => 9999, |
398
|
|
|
'search' => $search . '*', |
399
|
|
|
); |
400
|
|
|
|
401
|
|
|
$get_users_args = apply_filters( 'give_search_users_args', $get_users_args ); |
402
|
|
|
|
403
|
|
|
$found_users = apply_filters( 'give_ajax_found_users', get_users( $get_users_args ), $search ); |
404
|
|
|
$results = array(); |
405
|
|
|
|
406
|
|
|
if ( $found_users ) { |
407
|
|
|
|
408
|
|
|
foreach ( $found_users as $user ) { |
409
|
|
|
|
410
|
|
|
$results[] = array( |
411
|
|
|
'id' => $user->ID, |
412
|
|
|
'name' => esc_html( $user->user_login . ' (' . $user->user_email . ')' ), |
413
|
|
|
); |
414
|
|
|
} |
415
|
|
|
} |
416
|
|
|
}// End if(). |
417
|
|
|
|
418
|
|
|
wp_send_json( $results ); |
419
|
|
|
|
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
add_action( 'wp_ajax_give_user_search', 'give_ajax_search_users' ); |
423
|
|
|
|
424
|
|
|
|
425
|
|
|
/** |
426
|
|
|
* Queries page by title and returns page ID and title in JSON format. |
427
|
|
|
* |
428
|
|
|
* Note: this function in for internal use. |
429
|
|
|
* |
430
|
|
|
* @since 2.1 |
431
|
|
|
* |
432
|
|
|
* @return string |
433
|
|
|
*/ |
434
|
|
|
function give_ajax_pages_search() { |
435
|
|
|
$data = array(); |
436
|
|
|
$args = array( |
437
|
|
|
'post_type' => 'page', |
438
|
|
|
's' => give_clean( $_POST['s'] ), |
|
|
|
|
439
|
|
|
); |
440
|
|
|
|
441
|
|
|
$query = new WP_Query( $args ); |
442
|
|
|
|
443
|
|
|
// Query posts by title. |
444
|
|
|
if ( $query->have_posts() ) { |
445
|
|
|
while ( $query->have_posts() ) { |
446
|
|
|
$query->the_post(); |
447
|
|
|
|
448
|
|
|
$data[] = array( |
449
|
|
|
'id' => get_the_ID(), |
450
|
|
|
'name' => get_the_title(), |
451
|
|
|
); |
452
|
|
|
} |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
wp_send_json( $data ); |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
add_action( 'wp_ajax_give_pages_search', 'give_ajax_pages_search' ); |
459
|
|
|
|
460
|
|
|
/** |
461
|
|
|
* Retrieve Categories via AJAX for chosen dropdown search field. |
462
|
|
|
* |
463
|
|
|
* @since 2.1 |
464
|
|
|
* |
465
|
|
|
* @return void |
466
|
|
|
*/ |
467
|
|
View Code Duplication |
function give_ajax_categories_search() { |
|
|
|
|
468
|
|
|
$results = array(); |
469
|
|
|
|
470
|
|
|
/** |
471
|
|
|
* Filter to modify Ajax tags search args |
472
|
|
|
* |
473
|
|
|
* @since 2.1 |
474
|
|
|
* |
475
|
|
|
* @param array $args argument for get_terms |
476
|
|
|
* |
477
|
|
|
* @return array $args argument for get_terms |
478
|
|
|
*/ |
479
|
|
|
$args = (array) apply_filters( 'give_forms_categories_dropdown_args', array( |
480
|
|
|
'number' => 30, |
481
|
|
|
'name__like' => esc_sql( sanitize_text_field( $_POST['s'] ) ) |
|
|
|
|
482
|
|
|
) ); |
483
|
|
|
|
484
|
|
|
$categories = get_terms( 'give_forms_category', $args ); |
485
|
|
|
|
486
|
|
|
foreach ( $categories as $category ) { |
487
|
|
|
$results[] = array( |
488
|
|
|
'id' => $category->term_id, |
489
|
|
|
'name' => $category->name, |
490
|
|
|
); |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
/** |
494
|
|
|
* Filter to modify Ajax tags search result |
495
|
|
|
* |
496
|
|
|
* @since 2.1 |
497
|
|
|
* |
498
|
|
|
* @param array $results Contain the categories id and name |
499
|
|
|
* |
500
|
|
|
* @return array $results Contain the categories id and name |
501
|
|
|
*/ |
502
|
|
|
$results = (array) apply_filters( 'give_forms_categories_dropdown_responce', $results ); |
503
|
|
|
|
504
|
|
|
wp_send_json( $results ); |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
add_action( 'wp_ajax_give_categories_search', 'give_ajax_categories_search' ); |
508
|
|
|
|
509
|
|
|
/** |
510
|
|
|
* Retrieve Tags via AJAX for chosen dropdown search field. |
511
|
|
|
* |
512
|
|
|
* @since 2.1 |
513
|
|
|
* |
514
|
|
|
* @return void |
515
|
|
|
*/ |
516
|
|
View Code Duplication |
function give_ajax_tags_search() { |
|
|
|
|
517
|
|
|
$results = array(); |
518
|
|
|
|
519
|
|
|
/** |
520
|
|
|
* Filter to modify Ajax tags search args |
521
|
|
|
* |
522
|
|
|
* @since 2.1 |
523
|
|
|
* |
524
|
|
|
* @param array $args argument for get_terms |
525
|
|
|
* |
526
|
|
|
* @return array $args argument for get_terms |
527
|
|
|
*/ |
528
|
|
|
$args = (array) apply_filters( 'give_forms_tags_dropdown_args', array( |
529
|
|
|
'number' => 30, |
530
|
|
|
'name__like' => esc_sql( sanitize_text_field( $_POST['s'] ) ) |
|
|
|
|
531
|
|
|
) ); |
532
|
|
|
|
533
|
|
|
$categories = get_terms( 'give_forms_tag', $args ); |
534
|
|
|
|
535
|
|
|
foreach ( $categories as $category ) { |
536
|
|
|
$results[] = array( |
537
|
|
|
'id' => $category->term_id, |
538
|
|
|
'name' => $category->name, |
539
|
|
|
); |
540
|
|
|
} |
541
|
|
|
|
542
|
|
|
/** |
543
|
|
|
* Filter to modify Ajax tags search result |
544
|
|
|
* |
545
|
|
|
* @since 2.1 |
546
|
|
|
* |
547
|
|
|
* @param array $results Contain the tags id and name |
548
|
|
|
* |
549
|
|
|
* @return array $results Contain the tags id and name |
550
|
|
|
*/ |
551
|
|
|
$results = (array) apply_filters( 'give_forms_tags_dropdown_responce', $results ); |
552
|
|
|
|
553
|
|
|
wp_send_json( $results ); |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
add_action( 'wp_ajax_give_tags_search', 'give_ajax_tags_search' ); |
557
|
|
|
|
558
|
|
|
/** |
559
|
|
|
* Check for Price Variations (Multi-level donation forms) |
560
|
|
|
* |
561
|
|
|
* @since 1.5 |
562
|
|
|
* |
563
|
|
|
* @return void |
564
|
|
|
*/ |
565
|
|
|
function give_check_for_form_price_variations() { |
566
|
|
|
|
567
|
|
|
if ( ! current_user_can( 'edit_give_forms', get_current_user_id() ) ) { |
568
|
|
|
die( '-1' ); |
569
|
|
|
} |
570
|
|
|
|
571
|
|
|
$form_id = intval( $_POST['form_id'] ); |
|
|
|
|
572
|
|
|
$form = get_post( $form_id ); |
573
|
|
|
|
574
|
|
|
if ( 'give_forms' !== $form->post_type ) { |
575
|
|
|
die( '-2' ); |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
if ( give_has_variable_prices( $form_id ) ) { |
579
|
|
|
$variable_prices = give_get_variable_prices( $form_id ); |
580
|
|
|
|
581
|
|
|
if ( $variable_prices ) { |
582
|
|
|
$ajax_response = '<select class="give_price_options_select give-select give-select" name="give_price_option">'; |
583
|
|
|
|
584
|
|
|
if ( isset( $_POST['all_prices'] ) ) { |
|
|
|
|
585
|
|
|
$ajax_response .= '<option value="all">' . esc_html__( 'All Levels', 'give' ) . '</option>'; |
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
foreach ( $variable_prices as $key => $price ) { |
589
|
|
|
|
590
|
|
|
$level_text = ! empty( $price['_give_text'] ) ? esc_html( $price['_give_text'] ) : give_currency_filter( give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) ); |
591
|
|
|
|
592
|
|
|
$ajax_response .= '<option value="' . esc_attr( $price['_give_id']['level_id'] ) . '">' . $level_text . '</option>'; |
593
|
|
|
} |
594
|
|
|
$ajax_response .= '</select>'; |
595
|
|
|
echo $ajax_response; |
|
|
|
|
596
|
|
|
} |
597
|
|
|
} |
598
|
|
|
|
599
|
|
|
give_die(); |
600
|
|
|
} |
601
|
|
|
|
602
|
|
|
add_action( 'wp_ajax_give_check_for_form_price_variations', 'give_check_for_form_price_variations' ); |
603
|
|
|
|
604
|
|
|
|
605
|
|
|
/** |
606
|
|
|
* Check for Variation Prices HTML (Multi-level donation forms) |
607
|
|
|
* |
608
|
|
|
* @since 1.6 |
609
|
|
|
* |
610
|
|
|
* @return void |
611
|
|
|
*/ |
612
|
|
|
function give_check_for_form_price_variations_html() { |
613
|
|
|
if ( ! current_user_can( 'edit_give_payments', get_current_user_id() ) ) { |
614
|
|
|
wp_die(); |
615
|
|
|
} |
616
|
|
|
|
617
|
|
|
$form_id = ! empty( $_POST['form_id'] ) ? intval( $_POST['form_id'] ) : false; |
|
|
|
|
618
|
|
|
$payment_id = ! empty( $_POST['payment_id'] ) ? intval( $_POST['payment_id'] ) : false; |
|
|
|
|
619
|
|
|
if ( empty( $form_id ) || empty( $payment_id ) ) { |
620
|
|
|
wp_die(); |
621
|
|
|
} |
622
|
|
|
|
623
|
|
|
$form = get_post( $form_id ); |
624
|
|
|
if ( ! empty( $form->post_type ) && 'give_forms' !== $form->post_type ) { |
625
|
|
|
wp_die(); |
626
|
|
|
} |
627
|
|
|
|
628
|
|
|
if ( ! give_has_variable_prices( $form_id ) || ! $form_id ) { |
|
|
|
|
629
|
|
|
esc_html_e( 'n/a', 'give' ); |
630
|
|
|
} else { |
631
|
|
|
$prices_atts = array(); |
632
|
|
View Code Duplication |
if ( $variable_prices = give_get_variable_prices( $form_id ) ) { |
|
|
|
|
633
|
|
|
foreach ( $variable_prices as $variable_price ) { |
634
|
|
|
$prices_atts[ $variable_price['_give_id']['level_id'] ] = give_format_amount( $variable_price['_give_amount'], array( 'sanitize' => false ) ); |
635
|
|
|
} |
636
|
|
|
} |
637
|
|
|
|
638
|
|
|
// Variable price dropdown options. |
639
|
|
|
$variable_price_dropdown_option = array( |
640
|
|
|
'id' => $form_id, |
641
|
|
|
'name' => 'give-variable-price', |
642
|
|
|
'chosen' => true, |
643
|
|
|
'show_option_all' => '', |
644
|
|
|
'show_option_none' => '', |
645
|
|
|
'select_atts' => 'data-prices=' . esc_attr( json_encode( $prices_atts ) ), |
646
|
|
|
); |
647
|
|
|
|
648
|
|
|
if ( $payment_id ) { |
|
|
|
|
649
|
|
|
// Payment object. |
650
|
|
|
$payment = new Give_Payment( $payment_id ); |
651
|
|
|
|
652
|
|
|
// Payment meta. |
653
|
|
|
$payment_meta = $payment->get_meta(); |
654
|
|
|
$variable_price_dropdown_option['selected'] = $payment_meta['price_id']; |
655
|
|
|
} |
656
|
|
|
|
657
|
|
|
// Render variable prices select tag html. |
658
|
|
|
give_get_form_variable_price_dropdown( $variable_price_dropdown_option, true ); |
659
|
|
|
} |
660
|
|
|
|
661
|
|
|
give_die(); |
662
|
|
|
} |
663
|
|
|
|
664
|
|
|
add_action( 'wp_ajax_give_check_for_form_price_variations_html', 'give_check_for_form_price_variations_html' ); |
665
|
|
|
|
666
|
|
|
/** |
667
|
|
|
* Send Confirmation Email For Complete Donation History Access. |
668
|
|
|
* |
669
|
|
|
* @since 1.8.17 |
670
|
|
|
* |
671
|
|
|
* @return bool |
672
|
|
|
*/ |
673
|
|
|
function give_confirm_email_for_donation_access() { |
674
|
|
|
|
675
|
|
|
// Verify Security using Nonce. |
676
|
|
|
if ( ! check_ajax_referer( 'give_ajax_nonce', 'nonce' ) ) { |
677
|
|
|
return false; |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
// Bail Out, if email is empty. |
681
|
|
|
if ( empty( $_POST['email'] ) ) { |
|
|
|
|
682
|
|
|
return false; |
683
|
|
|
} |
684
|
|
|
|
685
|
|
|
$donor = Give()->donors->get_donor_by( 'email', give_clean( $_POST['email'] ) ); |
|
|
|
|
686
|
|
|
if ( Give()->email_access->can_send_email( $donor->id ) ) { |
687
|
|
|
$return = array(); |
688
|
|
|
$email_sent = Give()->email_access->send_email( $donor->id, $donor->email ); |
689
|
|
|
|
690
|
|
|
if ( ! $email_sent ) { |
691
|
|
|
$return['status'] = 'error'; |
692
|
|
|
$return['message'] = Give()->notices->print_frontend_notice( |
693
|
|
|
__( 'Unable to send email. Please try again.', 'give' ), |
694
|
|
|
false, |
695
|
|
|
'error' |
696
|
|
|
); |
697
|
|
|
} |
698
|
|
|
|
699
|
|
|
$return['status'] = 'success'; |
700
|
|
|
|
701
|
|
|
/** |
702
|
|
|
* Filter to modify access mail send notice |
703
|
|
|
* |
704
|
|
|
* @since 2.1.3 |
705
|
|
|
* |
706
|
|
|
* @param string Send notice message for email access. |
707
|
|
|
* |
708
|
|
|
* @return string $message Send notice message for email access. |
709
|
|
|
*/ |
710
|
|
|
$message = (string) apply_filters( 'give_email_access_mail_send_notice', __( 'Please check your email and click on the link to access your complete donation history.', 'give' ) ); |
711
|
|
|
|
712
|
|
|
$return['message'] = Give()->notices->print_frontend_notice( |
713
|
|
|
$message, |
714
|
|
|
false, |
715
|
|
|
'success' |
716
|
|
|
); |
717
|
|
|
|
|
|
|
|
718
|
|
|
|
719
|
|
|
} else { |
720
|
|
|
$value = Give()->email_access->verify_throttle / 60; |
721
|
|
|
$return['status'] = 'error'; |
722
|
|
|
|
723
|
|
|
/** |
724
|
|
|
* Filter to modify email access exceed notices message. |
725
|
|
|
* |
726
|
|
|
* @since 2.1.3 |
727
|
|
|
* |
728
|
|
|
* @param string $message email access exceed notices message |
729
|
|
|
* @param int $value email access exceed times |
730
|
|
|
* |
731
|
|
|
* @return string $message email access exceed notices message |
732
|
|
|
*/ |
733
|
|
|
$message = (string) apply_filters( |
734
|
|
|
'give_email_access_requests_exceed_notice', |
735
|
|
|
sprintf( |
736
|
|
|
__( 'Too many access email requests detected. Please wait %s before requesting a new donation history access link.', 'give' ), |
737
|
|
|
sprintf( _n( '%s minute', '%s minutes', $value, 'give' ), $value ) |
738
|
|
|
), |
739
|
|
|
$value |
740
|
|
|
); |
741
|
|
|
|
742
|
|
|
$return['message'] = Give()->notices->print_frontend_notice( |
743
|
|
|
$message, |
744
|
|
|
false, |
745
|
|
|
'error' |
746
|
|
|
); |
747
|
|
|
} |
748
|
|
|
|
749
|
|
|
echo json_encode( $return ); |
750
|
|
|
give_die(); |
751
|
|
|
} |
752
|
|
|
|
753
|
|
|
add_action( 'wp_ajax_nopriv_give_confirm_email_for_donations_access', 'give_confirm_email_for_donation_access' ); |
754
|
|
|
|
755
|
|
|
/** |
756
|
|
|
* Render receipt by ajax |
757
|
|
|
* Note: only for internal use |
758
|
|
|
* |
759
|
|
|
* @since 2.2.0 |
760
|
|
|
*/ |
761
|
|
|
function __give_get_receipt(){ |
762
|
|
|
if( ! isset( $_GET['shortcode_atts'] ) ) { |
|
|
|
|
763
|
|
|
give_die(); |
764
|
|
|
} |
765
|
|
|
|
766
|
|
|
$atts = urldecode_deep( give_clean( $_GET['shortcode_atts'] ) ); |
|
|
|
|
767
|
|
|
$data = give_receipt_shortcode( $atts ); |
768
|
|
|
|
769
|
|
|
wp_send_json( $data ); |
770
|
|
|
} |
771
|
|
|
add_action( 'wp_ajax_get_receipt', '__give_get_receipt' ); |
772
|
|
|
add_action( 'wp_ajax_nopriv_get_receipt', '__give_get_receipt' ); |
773
|
|
|
|