PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.3.0
GiveWP – Donation Plugin and Fundraising Platform v2.3.0
4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / ajax-functions.php
give / includes Last commit date
admin 7 years ago api 7 years ago deprecated 7 years ago donors 7 years ago emails 7 years ago forms 7 years ago gateways 7 years ago libraries 7 years ago payments 7 years ago actions.php 7 years ago ajax-functions.php 7 years ago class-give-async-process.php 8 years ago class-give-background-updater.php 7 years ago class-give-cache.php 7 years ago class-give-cli-commands.php 8 years ago class-give-comment.php 7 years ago class-give-cron.php 8 years ago class-give-db-comments-meta.php 7 years ago class-give-db-comments.php 7 years ago class-give-db-donor-meta.php 8 years ago class-give-db-donors.php 7 years ago class-give-db-form-meta.php 8 years ago class-give-db-logs-meta.php 8 years ago class-give-db-logs.php 7 years ago class-give-db-meta.php 7 years ago class-give-db-payment-meta.php 7 years ago class-give-db-sequential-ordering.php 7 years ago class-give-db-sessions.php 7 years ago class-give-db.php 7 years ago class-give-donate-form.php 8 years ago class-give-donor-wall-widget.php 7 years ago class-give-donor.php 7 years ago class-give-email-access.php 7 years ago class-give-html-elements.php 7 years ago class-give-license-handler.php 7 years ago class-give-logging.php 8 years ago class-give-readme-parser.php 8 years ago class-give-roles.php 8 years ago class-give-scripts.php 7 years ago class-give-session.php 7 years ago class-give-stats.php 8 years ago class-give-template-loader.php 8 years ago class-give-tooltips.php 8 years ago class-give-translation.php 8 years ago class-notices.php 7 years ago country-functions.php 7 years ago currency-functions.php 7 years ago error-tracking.php 8 years ago filters.php 7 years ago formatting.php 7 years ago import-functions.php 7 years ago install.php 7 years ago login-register.php 8 years ago misc-functions.php 7 years ago plugin-compatibility.php 8 years ago post-types.php 7 years ago price-functions.php 7 years ago process-donation.php 7 years ago shortcodes.php 7 years ago template-functions.php 8 years ago user-functions.php 7 years ago
ajax-functions.php
775 lines
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 * Get AJAX URL
103 *
104 * @since 1.0
105 *
106 * @param array $query
107 *
108 * @return string
109 */
110 function give_get_ajax_url( $query = array() ) {
111 $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 ( give_get_country() === $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
267 $response = array(
268 'success' => true,
269 'states_found' => $states_found,
270 'states_label' => $label,
271 'show_field' => $show_field,
272 'states_require' => $states_require,
273 'data' => $data,
274 'default_state' => $default_state,
275 'city_require' => ! array_key_exists( $country, give_city_not_required_country_list() ),
276 );
277 wp_send_json( $response );
278 }
279
280 add_action( 'wp_ajax_give_get_states', 'give_ajax_get_states_field' );
281 add_action( 'wp_ajax_nopriv_give_get_states', 'give_ajax_get_states_field' );
282
283 /**
284 * Retrieve donation forms via AJAX for chosen dropdown search field.
285 *
286 * @since 1.0
287 *
288 * @return void
289 */
290 function give_ajax_form_search() {
291 $results = array();
292 $search = esc_sql( sanitize_text_field( $_POST['s'] ) );
293
294 $args = array(
295 'post_type' => 'give_forms',
296 's' => $search,
297 'update_post_term_cache' => false,
298 'update_post_meta_cache' => false,
299 'cache_results' => false,
300 'no_found_rows' => true,
301 'post_status' => 'publish',
302 'orderby' => 'title',
303 'order' => 'ASC',
304 'posts_per_page' => empty( $search ) ? 30 : -1,
305 );
306
307 /**
308 * Filter to modify Ajax form search args
309 *
310 * @since 2.1
311 *
312 * @param array $args Query argument for WP_query
313 *
314 * @return array $args Query argument for WP_query
315 */
316 $args = (array) apply_filters( 'give_ajax_form_search_args', $args );
317
318 // get all the donation form.
319 $query = new WP_Query( $args );
320 if ( $query->have_posts() ) {
321 while ( $query->have_posts() ) {
322 $query->the_post();
323 global $post;
324
325 $results[] = array(
326 'id' => $post->ID,
327 'name' => $post->post_title,
328 );
329 }
330 wp_reset_postdata();
331 }
332
333 /**
334 * Filter to modify Ajax form search result
335 *
336 * @since 2.1
337 *
338 * @param array $results Contain the Donation Form id
339 *
340 * @return array $results Contain the Donation Form id
341 */
342 $results = (array) apply_filters( 'give_ajax_form_search_responce', $results );
343
344 wp_send_json( $results );
345 }
346
347 add_action( 'wp_ajax_give_form_search', 'give_ajax_form_search' );
348 add_action( 'wp_ajax_nopriv_give_form_search', 'give_ajax_form_search' );
349
350 /**
351 * Search the donors database via Ajax
352 *
353 * @since 1.0
354 *
355 * @return void
356 */
357 function give_ajax_donor_search() {
358 global $wpdb;
359
360 $search = esc_sql( sanitize_text_field( $_POST['s'] ) );
361 $results = array();
362 if ( ! current_user_can( 'view_give_reports' ) ) {
363 $donors = array();
364 } else {
365 $donors = $wpdb->get_results( "SELECT id,name,email FROM $wpdb->donors WHERE `name` LIKE '%$search%' OR `email` LIKE '%$search%' LIMIT 50" );
366 }
367
368 if ( $donors ) {
369 foreach ( $donors as $donor ) {
370
371 $results[] = array(
372 'id' => $donor->id,
373 'name' => $donor->name . ' (' . $donor->email . ')',
374 );
375 }
376 }
377
378 wp_send_json( $results );
379 }
380
381 add_action( 'wp_ajax_give_donor_search', 'give_ajax_donor_search' );
382
383
384 /**
385 * Searches for users via ajax and returns a list of results
386 *
387 * @since 1.0
388 *
389 * @return void
390 */
391 function give_ajax_search_users() {
392 $results = array();
393
394 if ( current_user_can( 'manage_give_settings' ) ) {
395
396 $search = esc_sql( sanitize_text_field( $_POST['s'] ) );
397
398 $get_users_args = array(
399 'number' => 9999,
400 'search' => $search . '*',
401 );
402
403 $get_users_args = apply_filters( 'give_search_users_args', $get_users_args );
404
405 $found_users = apply_filters( 'give_ajax_found_users', get_users( $get_users_args ), $search );
406 $results = array();
407
408 if ( $found_users ) {
409
410 foreach ( $found_users as $user ) {
411
412 $results[] = array(
413 'id' => $user->ID,
414 'name' => esc_html( $user->user_login . ' (' . $user->user_email . ')' ),
415 );
416 }
417 }
418 }// End if().
419
420 wp_send_json( $results );
421
422 }
423
424 add_action( 'wp_ajax_give_user_search', 'give_ajax_search_users' );
425
426
427 /**
428 * Queries page by title and returns page ID and title in JSON format.
429 *
430 * Note: this function in for internal use.
431 *
432 * @since 2.1
433 *
434 * @return string
435 */
436 function give_ajax_pages_search() {
437 $data = array();
438 $args = array(
439 'post_type' => 'page',
440 's' => give_clean( $_POST['s'] ),
441 );
442
443 $query = new WP_Query( $args );
444
445 // Query posts by title.
446 if ( $query->have_posts() ) {
447 while ( $query->have_posts() ) {
448 $query->the_post();
449
450 $data[] = array(
451 'id' => get_the_ID(),
452 'name' => get_the_title(),
453 );
454 }
455 }
456
457 wp_send_json( $data );
458 }
459
460 add_action( 'wp_ajax_give_pages_search', 'give_ajax_pages_search' );
461
462 /**
463 * Retrieve Categories via AJAX for chosen dropdown search field.
464 *
465 * @since 2.1
466 *
467 * @return void
468 */
469 function give_ajax_categories_search() {
470 $results = array();
471
472 /**
473 * Filter to modify Ajax tags search args
474 *
475 * @since 2.1
476 *
477 * @param array $args argument for get_terms
478 *
479 * @return array $args argument for get_terms
480 */
481 $args = (array) apply_filters( 'give_forms_categories_dropdown_args', array(
482 'number' => 30,
483 'name__like' => esc_sql( sanitize_text_field( $_POST['s'] ) )
484 ) );
485
486 $categories = get_terms( 'give_forms_category', $args );
487
488 foreach ( $categories as $category ) {
489 $results[] = array(
490 'id' => $category->term_id,
491 'name' => $category->name,
492 );
493 }
494
495 /**
496 * Filter to modify Ajax tags search result
497 *
498 * @since 2.1
499 *
500 * @param array $results Contain the categories id and name
501 *
502 * @return array $results Contain the categories id and name
503 */
504 $results = (array) apply_filters( 'give_forms_categories_dropdown_responce', $results );
505
506 wp_send_json( $results );
507 }
508
509 add_action( 'wp_ajax_give_categories_search', 'give_ajax_categories_search' );
510
511 /**
512 * Retrieve Tags via AJAX for chosen dropdown search field.
513 *
514 * @since 2.1
515 *
516 * @return void
517 */
518 function give_ajax_tags_search() {
519 $results = array();
520
521 /**
522 * Filter to modify Ajax tags search args
523 *
524 * @since 2.1
525 *
526 * @param array $args argument for get_terms
527 *
528 * @return array $args argument for get_terms
529 */
530 $args = (array) apply_filters( 'give_forms_tags_dropdown_args', array(
531 'number' => 30,
532 'name__like' => esc_sql( sanitize_text_field( $_POST['s'] ) )
533 ) );
534
535 $categories = get_terms( 'give_forms_tag', $args );
536
537 foreach ( $categories as $category ) {
538 $results[] = array(
539 'id' => $category->term_id,
540 'name' => $category->name,
541 );
542 }
543
544 /**
545 * Filter to modify Ajax tags search result
546 *
547 * @since 2.1
548 *
549 * @param array $results Contain the tags id and name
550 *
551 * @return array $results Contain the tags id and name
552 */
553 $results = (array) apply_filters( 'give_forms_tags_dropdown_responce', $results );
554
555 wp_send_json( $results );
556 }
557
558 add_action( 'wp_ajax_give_tags_search', 'give_ajax_tags_search' );
559
560 /**
561 * Check for Price Variations (Multi-level donation forms)
562 *
563 * @since 1.5
564 *
565 * @return void
566 */
567 function give_check_for_form_price_variations() {
568
569 if ( ! current_user_can( 'edit_give_forms', get_current_user_id() ) ) {
570 die( '-1' );
571 }
572
573 $form_id = intval( $_POST['form_id'] );
574 $form = get_post( $form_id );
575
576 if ( 'give_forms' !== $form->post_type ) {
577 die( '-2' );
578 }
579
580 if ( give_has_variable_prices( $form_id ) ) {
581 $variable_prices = give_get_variable_prices( $form_id );
582
583 if ( $variable_prices ) {
584 $ajax_response = '<select class="give_price_options_select give-select give-select" name="give_price_option">';
585
586 if ( isset( $_POST['all_prices'] ) ) {
587 $ajax_response .= '<option value="all">' . esc_html__( 'All Levels', 'give' ) . '</option>';
588 }
589
590 foreach ( $variable_prices as $key => $price ) {
591
592 $level_text = ! empty( $price['_give_text'] ) ? esc_html( $price['_give_text'] ) : give_currency_filter( give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) );
593
594 $ajax_response .= '<option value="' . esc_attr( $price['_give_id']['level_id'] ) . '">' . $level_text . '</option>';
595 }
596 $ajax_response .= '</select>';
597 echo $ajax_response;
598 }
599 }
600
601 give_die();
602 }
603
604 add_action( 'wp_ajax_give_check_for_form_price_variations', 'give_check_for_form_price_variations' );
605
606
607 /**
608 * Check for Variation Prices HTML (Multi-level donation forms)
609 *
610 * @since 1.6
611 *
612 * @return void
613 */
614 function give_check_for_form_price_variations_html() {
615 if ( ! current_user_can( 'edit_give_payments', get_current_user_id() ) ) {
616 wp_die();
617 }
618
619 $form_id = ! empty( $_POST['form_id'] ) ? intval( $_POST['form_id'] ) : false;
620 $payment_id = ! empty( $_POST['payment_id'] ) ? intval( $_POST['payment_id'] ) : false;
621 if ( empty( $form_id ) || empty( $payment_id ) ) {
622 wp_die();
623 }
624
625 $form = get_post( $form_id );
626 if ( ! empty( $form->post_type ) && 'give_forms' !== $form->post_type ) {
627 wp_die();
628 }
629
630 if ( ! give_has_variable_prices( $form_id ) || ! $form_id ) {
631 esc_html_e( 'n/a', 'give' );
632 } else {
633 $prices_atts = array();
634 if ( $variable_prices = give_get_variable_prices( $form_id ) ) {
635 foreach ( $variable_prices as $variable_price ) {
636 $prices_atts[ $variable_price['_give_id']['level_id'] ] = give_format_amount( $variable_price['_give_amount'], array( 'sanitize' => false ) );
637 }
638 }
639
640 // Variable price dropdown options.
641 $variable_price_dropdown_option = array(
642 'id' => $form_id,
643 'name' => 'give-variable-price',
644 'chosen' => true,
645 'show_option_all' => '',
646 'show_option_none' => '',
647 'select_atts' => 'data-prices=' . esc_attr( json_encode( $prices_atts ) ),
648 );
649
650 if ( $payment_id ) {
651 // Payment object.
652 $payment = new Give_Payment( $payment_id );
653
654 // Payment meta.
655 $payment_meta = $payment->get_meta();
656 $variable_price_dropdown_option['selected'] = $payment_meta['price_id'];
657 }
658
659 // Render variable prices select tag html.
660 give_get_form_variable_price_dropdown( $variable_price_dropdown_option, true );
661 }
662
663 give_die();
664 }
665
666 add_action( 'wp_ajax_give_check_for_form_price_variations_html', 'give_check_for_form_price_variations_html' );
667
668 /**
669 * Send Confirmation Email For Complete Donation History Access.
670 *
671 * @since 1.8.17
672 *
673 * @return bool
674 */
675 function give_confirm_email_for_donation_access() {
676
677 // Verify Security using Nonce.
678 if ( ! check_ajax_referer( 'give_ajax_nonce', 'nonce' ) ) {
679 return false;
680 }
681
682 // Bail Out, if email is empty.
683 if ( empty( $_POST['email'] ) ) {
684 return false;
685 }
686
687 $donor = Give()->donors->get_donor_by( 'email', give_clean( $_POST['email'] ) );
688 if ( Give()->email_access->can_send_email( $donor->id ) ) {
689 $return = array();
690 $email_sent = Give()->email_access->send_email( $donor->id, $donor->email );
691
692 if ( ! $email_sent ) {
693 $return['status'] = 'error';
694 $return['message'] = Give()->notices->print_frontend_notice(
695 __( 'Unable to send email. Please try again.', 'give' ),
696 false,
697 'error'
698 );
699 }
700
701 $return['status'] = 'success';
702
703 /**
704 * Filter to modify access mail send notice
705 *
706 * @since 2.1.3
707 *
708 * @param string Send notice message for email access.
709 *
710 * @return string $message Send notice message for email access.
711 */
712 $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' ) );
713
714 $return['message'] = Give()->notices->print_frontend_notice(
715 $message,
716 false,
717 'success'
718 );
719
720
721 } else {
722 $value = Give()->email_access->verify_throttle / 60;
723 $return['status'] = 'error';
724
725 /**
726 * Filter to modify email access exceed notices message.
727 *
728 * @since 2.1.3
729 *
730 * @param string $message email access exceed notices message
731 * @param int $value email access exceed times
732 *
733 * @return string $message email access exceed notices message
734 */
735 $message = (string) apply_filters(
736 'give_email_access_requests_exceed_notice',
737 sprintf(
738 __( 'Too many access email requests detected. Please wait %s before requesting a new donation history access link.', 'give' ),
739 sprintf( _n( '%s minute', '%s minutes', $value, 'give' ), $value )
740 ),
741 $value
742 );
743
744 $return['message'] = Give()->notices->print_frontend_notice(
745 $message,
746 false,
747 'error'
748 );
749 }
750
751 echo json_encode( $return );
752 give_die();
753 }
754
755 add_action( 'wp_ajax_nopriv_give_confirm_email_for_donations_access', 'give_confirm_email_for_donation_access' );
756
757 /**
758 * Render receipt by ajax
759 * Note: only for internal use
760 *
761 * @since 2.2.0
762 */
763 function __give_get_receipt(){
764 if( ! isset( $_GET['shortcode_atts'] ) ) {
765 give_die();
766 }
767
768 $atts = urldecode_deep( give_clean( $_GET['shortcode_atts'] ) );
769 $data = give_receipt_shortcode( $atts );
770
771 wp_send_json( $data );
772 }
773 add_action( 'wp_ajax_get_receipt', '__give_get_receipt' );
774 add_action( 'wp_ajax_nopriv_get_receipt', '__give_get_receipt' );
775