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