PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 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 All 255 releases
← All changes | includes/ajax-functions.php +304 -225 2.3.04.16.9 View file →
@@ -5,14 +5,16 @@
5 5 * Process the front-end AJAX actions.
6 6 *
7 7 * @package Give
8 8 * @subpackage Functions/AJAX
9 - * @copyright Copyright (c) 2016, WordImpress
9 + * @copyright Copyright (c) 2016, GiveWP
10 10 * @license https://opensource.org/licenses/gpl-license GNU Public License
11 11 * @since 1.0
12 12 */
13 13
14 14 // Exit if accessed directly.
15 +use Give\Helpers\Form\Template as FormTemplateUtils;
16 +
15 17 if ( ! defined( 'ABSPATH' ) ) {
16 18 exit;
17 19 }
18 20
@@ -21,11 +23,13 @@
21 23 * Note: Do not use this function before init hook.
22 24 *
23 25 * @since 1.0
24 26 *
27 + * @param bool $force Flag to test ajax by discarding cache result
28 + *
25 29 * @return bool True if AJAX works, false otherwise
26 30 */
27 -function give_test_ajax_works() {
31 +function give_test_ajax_works( $force = false ) {
28 32 // Handle ajax.
29 33 if ( doing_action( 'wp_ajax_nopriv_give_test_ajax' ) ) {
30 34 wp_die( 0, 200 );
31 35 }
@@ -49,51 +53,56 @@
49 53 }
50 54
51 55 add_filter( 'block_local_requests', '__return_false' );
52 56
53 - if ( Give_Cache::get( '_give_ajax_works', true ) ) {
54 - return true;
55 - }
57 + $works = Give_Cache::get( '_give_ajax_works', true );
56 58
57 - $params = array(
58 - 'sslverify' => false,
59 - 'timeout' => 30,
60 - 'body' => array(
61 - 'action' => 'give_test_ajax',
62 - ),
63 - );
59 + if ( ! $works || $force ) {
60 + $params = [
61 + 'sslverify' => false,
62 + 'timeout' => 30,
63 + 'body' => [
64 + 'action' => 'give_test_ajax',
65 + ],
66 + ];
64 67
65 - $ajax = wp_remote_post( give_get_ajax_url(), $params );
68 + $ajax = wp_remote_post( give_get_ajax_url(), $params );
66 69
67 - $works = true;
70 + $works = true;
68 71
69 - if ( is_wp_error( $ajax ) ) {
72 + if ( is_wp_error( $ajax ) ) {
70 73
71 - $works = false;
74 + $works = false;
72 75
73 - } else {
76 + } else {
74 77
75 - if ( empty( $ajax['response'] ) ) {
76 - $works = false;
77 - }
78 + if ( empty( $ajax['response'] ) ) {
79 + $works = false;
80 + }
78 81
79 - if ( empty( $ajax['response']['code'] ) || 200 !== (int) $ajax['response']['code'] ) {
80 - $works = false;
81 - }
82 + if ( empty( $ajax['response']['code'] ) || 200 !== (int) $ajax['response']['code'] ) {
83 + $works = false;
84 + }
82 85
83 - if ( empty( $ajax['response']['message'] ) || 'OK' !== $ajax['response']['message'] ) {
84 - $works = false;
86 + if ( empty( $ajax['response']['message'] ) || 'OK' !== $ajax['response']['message'] ) {
87 + $works = false;
88 + }
89 +
90 + if ( ! isset( $ajax['body'] ) || 0 !== (int) $ajax['body'] ) {
91 + $works = false;
92 + }
85 93 }
86 94
87 - if ( ! isset( $ajax['body'] ) || 0 !== (int) $ajax['body'] ) {
88 - $works = false;
95 + if ( $works ) {
96 + Give_Cache::set( '_give_ajax_works', '1', DAY_IN_SECONDS, true );
89 97 }
90 98 }
91 99
92 - if ( $works ) {
93 - Give_Cache::set( '_give_ajax_works', '1', DAY_IN_SECONDS, true );
94 - }
95 -
100 + /**
101 + * Filter the output
102 + *
103 + * @since 1.0
104 + */
96 105 return apply_filters( 'give_test_ajax_works', $works );
97 106 }
98 107
99 108 add_action( 'wp_ajax_nopriv_give_test_ajax', 'give_test_ajax_works' );
@@ -106,9 +115,9 @@
106 115 * @param array $query
107 116 *
108 117 * @return string
109 118 */
110 -function give_get_ajax_url( $query = array() ) {
119 +function give_get_ajax_url( $query = [] ) {
111 120 $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';
112 121
113 122 $current_url = give_get_current_page_url();
114 123 $ajax_url = admin_url( 'admin-ajax.php', $scheme );
@@ -120,9 +129,9 @@
120 129 if ( ! empty( $query ) ) {
121 130 $ajax_url = add_query_arg( $query, $ajax_url );
122 131 }
123 132
124 - return apply_filters( 'give_ajax_url', $ajax_url );
133 + return esc_url_raw( apply_filters( 'give_ajax_url', $ajax_url ) );
125 134 }
126 135
127 136 /**
128 137 * Loads Checkout Login Fields via AJAX
@@ -164,118 +173,107 @@
164 173 do_action( 'give_donation_form_register_login_fields', $form_id );
165 174
166 175 $fields = ob_get_clean();
167 176
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 - ) );
177 + wp_send_json(
178 + [
179 + 'fields' => wp_json_encode( $fields ),
180 + 'submit' => wp_json_encode( give_get_donation_form_submit_button( $form_id ) ),
181 + ]
182 + );
172 183 }
173 184
185 +add_action( 'wp_ajax_give_cancel_login', 'give_load_checkout_fields' );
174 186 add_action( 'wp_ajax_nopriv_give_cancel_login', 'give_load_checkout_fields' );
175 187 add_action( 'wp_ajax_nopriv_give_checkout_register', 'give_load_checkout_fields' );
176 188
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 189
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 190 /**
200 191 * Retrieve a states drop down
201 192 *
193 + * @since 2.30.0 add 'state_label' & 'states' to response
202 194 * @since 1.0
203 195 *
204 196 * @return void
205 197 */
206 198 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'] );
199 + $states_found = false;
200 + $show_field = true;
201 + $states_require = true;
202 + // Get the Country code from the $_POST.
203 + $country = sanitize_text_field($_POST['country']);
212 204
213 - // Get the field name from the $_POST.
214 - $field_name = sanitize_text_field( $_POST['field_name'] );
205 + // Get the field name from the $_POST.
206 + $field_name = sanitize_text_field($_POST['field_name']);
215 207
216 - $label = __( 'State', 'give' );
217 - $states_label = give_get_states_label();
208 + $label = __('State', 'give');
209 + $states_label = give_get_states_label();
218 210
219 - $default_state = '';
220 - if ( give_get_country() === $country ) {
221 - $default_state = give_get_state();
222 - }
211 + $default_state = '';
212 + if (give_get_country() === $country) {
213 + $default_state = give_get_state();
214 + }
223 215
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 - }
216 + // Check if $country code exists in the array key for states label.
217 + if (array_key_exists($country, $states_label)) {
218 + $label = $states_label[$country];
219 + }
228 220
229 - if ( empty( $country ) ) {
230 - $country = give_get_country();
231 - }
221 + if (empty($country)) {
222 + $country = give_get_country();
223 + }
232 224
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';
225 + $states = give_get_states($country);
226 + if (!empty($states)) {
227 + $args = [
228 + 'name' => $field_name,
229 + 'id' => $field_name,
230 + 'class' => $field_name . ' give-select',
231 + 'options' => $states,
232 + 'show_option_all' => false,
233 + 'show_option_none' => false,
234 + 'placeholder' => $label,
235 + 'selected' => $default_state,
236 + 'autocomplete' => 'address-level1',
237 + ];
238 + $data = Give()->html->select($args);
239 + $states_found = true;
240 + } else {
241 + $data = 'nostates';
249 242
250 - // Get the country list that does not have any states init.
251 - $no_states_country = give_no_states_country_list();
243 + // Get the country list that does not have any states init.
244 + $no_states_country = give_no_states_country_list();
252 245
253 - // Check if $country code exists in the array key.
254 - if ( array_key_exists( $country, $no_states_country ) ) {
255 - $show_field = false;
256 - }
246 + // Check if $country code exists in the array key.
247 + if (array_key_exists($country, $no_states_country)) {
248 + $show_field = false;
249 + }
257 250
258 - // Get the country list that does not require states.
259 - $states_not_required_country_list = give_states_not_required_country_list();
251 + // Get the country list that does not require states.
252 + $states_not_required_country_list = give_states_not_required_country_list();
260 253
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 - }
254 + // Check if $country code exists in the array key.
255 + if (array_key_exists($country, $states_not_required_country_list)) {
256 + $states_require = false;
257 + }
258 + }
266 259
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 );
260 + $response = [
261 + 'success' => true,
262 + 'states_found' => $states_found,
263 + 'states_label' => $label,
264 + 'show_field' => $show_field,
265 + 'states_require' => $states_require,
266 + 'data' => $data,
267 + 'default_state' => $default_state,
268 + 'city_require' => !array_key_exists($country, give_city_not_required_country_list()),
269 + 'zip_require' => !array_key_exists($country, give_get_country_list_without_postcodes()),
270 + 'state_label' => $label,
271 + 'states' => array_map(static function ($state) {
272 + return html_entity_decode($state, ENT_QUOTES);
273 + }, $states),
274 + ];
275 + wp_send_json($response);
278 276 }
279 277
280 278 add_action( 'wp_ajax_give_get_states', 'give_ajax_get_states_field' );
281 279 add_action( 'wp_ajax_nopriv_give_get_states', 'give_ajax_get_states_field' );
@@ -287,12 +285,12 @@
287 285 *
288 286 * @return void
289 287 */
290 288 function give_ajax_form_search() {
291 - $results = array();
289 + $results = [];
292 290 $search = esc_sql( sanitize_text_field( $_POST['s'] ) );
293 291
294 - $args = array(
292 + $args = [
295 293 'post_type' => 'give_forms',
296 294 's' => $search,
297 295 'update_post_term_cache' => false,
298 296 'update_post_meta_cache' => false,
@@ -301,9 +299,9 @@
301 299 'post_status' => 'publish',
302 300 'orderby' => 'title',
303 301 'order' => 'ASC',
304 302 'posts_per_page' => empty( $search ) ? 30 : -1,
305 - );
303 + ];
306 304
307 305 /**
308 306 * Filter to modify Ajax form search args
309 307 *
@@ -321,12 +319,12 @@
321 319 while ( $query->have_posts() ) {
322 320 $query->the_post();
323 321 global $post;
324 322
325 - $results[] = array(
323 + $results[] = [
326 324 'id' => $post->ID,
327 325 'name' => $post->post_title,
328 - );
326 + ];
329 327 }
330 328 wp_reset_postdata();
331 329 }
332 330
@@ -338,9 +336,9 @@
338 336 * @param array $results Contain the Donation Form id
339 337 *
340 338 * @return array $results Contain the Donation Form id
341 339 */
342 - $results = (array) apply_filters( 'give_ajax_form_search_responce', $results );
340 + $results = (array) apply_filters( 'give_ajax_form_search_response', $results );
343 341
344 342 wp_send_json( $results );
345 343 }
346 344
@@ -357,11 +355,11 @@
357 355 function give_ajax_donor_search() {
358 356 global $wpdb;
359 357
360 358 $search = esc_sql( sanitize_text_field( $_POST['s'] ) );
361 - $results = array();
359 + $results = [];
362 360 if ( ! current_user_can( 'view_give_reports' ) ) {
363 - $donors = array();
361 + $donors = [];
364 362 } else {
365 363 $donors = $wpdb->get_results( "SELECT id,name,email FROM $wpdb->donors WHERE `name` LIKE '%$search%' OR `email` LIKE '%$search%' LIMIT 50" );
366 364 }
367 365
@@ -367,12 +365,12 @@
367 365
368 366 if ( $donors ) {
369 367 foreach ( $donors as $donor ) {
370 368
371 - $results[] = array(
369 + $results[] = [
372 370 'id' => $donor->id,
373 371 'name' => $donor->name . ' (' . $donor->email . ')',
374 - );
372 + ];
375 373 }
376 374 }
377 375
378 376 wp_send_json( $results );
@@ -388,32 +386,32 @@
388 386 *
389 387 * @return void
390 388 */
391 389 function give_ajax_search_users() {
392 - $results = array();
390 + $results = [];
393 391
394 392 if ( current_user_can( 'manage_give_settings' ) ) {
395 393
396 394 $search = esc_sql( sanitize_text_field( $_POST['s'] ) );
397 395
398 - $get_users_args = array(
396 + $get_users_args = [
399 397 'number' => 9999,
400 398 'search' => $search . '*',
401 - );
399 + ];
402 400
403 401 $get_users_args = apply_filters( 'give_search_users_args', $get_users_args );
404 402
405 403 $found_users = apply_filters( 'give_ajax_found_users', get_users( $get_users_args ), $search );
406 - $results = array();
404 + $results = [];
407 405
408 406 if ( $found_users ) {
409 407
410 408 foreach ( $found_users as $user ) {
411 409
412 - $results[] = array(
410 + $results[] = [
413 411 'id' => $user->ID,
414 412 'name' => esc_html( $user->user_login . ' (' . $user->user_email . ')' ),
415 - );
413 + ];
416 414 }
417 415 }
418 416 }// End if().
419 417
@@ -433,13 +431,13 @@
433 431 *
434 432 * @return string
435 433 */
436 434 function give_ajax_pages_search() {
437 - $data = array();
438 - $args = array(
435 + $data = [];
436 + $args = [
439 437 'post_type' => 'page',
440 438 's' => give_clean( $_POST['s'] ),
441 - );
439 + ];
442 440
443 441 $query = new WP_Query( $args );
444 442
445 443 // Query posts by title.
@@ -446,12 +444,12 @@
446 444 if ( $query->have_posts() ) {
447 445 while ( $query->have_posts() ) {
448 446 $query->the_post();
449 447
450 - $data[] = array(
448 + $data[] = [
451 449 'id' => get_the_ID(),
452 450 'name' => get_the_title(),
453 - );
451 + ];
454 452 }
455 453 }
456 454
457 455 wp_send_json( $data );
@@ -466,9 +464,9 @@
466 464 *
467 465 * @return void
468 466 */
469 467 function give_ajax_categories_search() {
470 - $results = array();
468 + $results = [];
471 469
472 470 /**
473 471 * Filter to modify Ajax tags search args
474 472 *
@@ -477,20 +475,23 @@
477 475 * @param array $args argument for get_terms
478 476 *
479 477 * @return array $args argument for get_terms
480 478 */
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 - ) );
479 + $args = (array) apply_filters(
480 + 'give_forms_categories_dropdown_args',
481 + [
482 + 'number' => 30,
483 + 'name__like' => esc_sql( sanitize_text_field( $_POST['s'] ) ),
484 + ]
485 + );
485 486
486 487 $categories = get_terms( 'give_forms_category', $args );
487 488
488 489 foreach ( $categories as $category ) {
489 - $results[] = array(
490 + $results[] = [
490 491 'id' => $category->term_id,
491 492 'name' => $category->name,
492 - );
493 + ];
493 494 }
494 495
495 496 /**
496 497 * Filter to modify Ajax tags search result
@@ -515,9 +516,9 @@
515 516 *
516 517 * @return void
517 518 */
518 519 function give_ajax_tags_search() {
519 - $results = array();
520 + $results = [];
520 521
521 522 /**
522 523 * Filter to modify Ajax tags search args
523 524 *
@@ -526,20 +527,23 @@
526 527 * @param array $args argument for get_terms
527 528 *
528 529 * @return array $args argument for get_terms
529 530 */
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 - ) );
531 + $args = (array) apply_filters(
532 + 'give_forms_tags_dropdown_args',
533 + [
534 + 'number' => 30,
535 + 'name__like' => esc_sql( sanitize_text_field( $_POST['s'] ) ),
536 + ]
537 + );
534 538
535 539 $categories = get_terms( 'give_forms_tag', $args );
536 540
537 541 foreach ( $categories as $category ) {
538 - $results[] = array(
542 + $results[] = [
539 543 'id' => $category->term_id,
540 544 'name' => $category->name,
541 - );
545 + ];
542 546 }
543 547
544 548 /**
545 549 * Filter to modify Ajax tags search result
@@ -569,9 +573,9 @@
569 573 if ( ! current_user_can( 'edit_give_forms', get_current_user_id() ) ) {
570 574 die( '-1' );
571 575 }
572 576
573 - $form_id = intval( $_POST['form_id'] );
577 + $form_id = absint( $_POST['form_id'] );
574 578 $form = get_post( $form_id );
575 579
576 580 if ( 'give_forms' !== $form->post_type ) {
577 581 die( '-2' );
@@ -588,9 +592,9 @@
588 592 }
589 593
590 594 foreach ( $variable_prices as $key => $price ) {
591 595
592 - $level_text = ! empty( $price['_give_text'] ) ? esc_html( $price['_give_text'] ) : give_currency_filter( give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) );
596 + $level_text = ! empty( $price['_give_text'] ) ? esc_html( $price['_give_text'] ) : give_currency_filter( give_format_amount( $price['_give_amount'], [ 'sanitize' => false ] ) );
593 597
594 598 $ajax_response .= '<option value="' . esc_attr( $price['_give_id']['level_id'] ) . '">' . $level_text . '</option>';
595 599 }
596 600 $ajax_response .= '</select>';
@@ -615,10 +619,10 @@
615 619 if ( ! current_user_can( 'edit_give_payments', get_current_user_id() ) ) {
616 620 wp_die();
617 621 }
618 622
619 - $form_id = ! empty( $_POST['form_id'] ) ? intval( $_POST['form_id'] ) : false;
620 - $payment_id = ! empty( $_POST['payment_id'] ) ? intval( $_POST['payment_id'] ) : false;
623 + $form_id = ! empty( $_POST['form_id'] ) ? absint( $_POST['form_id'] ) : false;
624 + $payment_id = ! empty( $_POST['payment_id'] ) ? absint( $_POST['payment_id'] ) : false;
621 625 if ( empty( $form_id ) || empty( $payment_id ) ) {
622 626 wp_die();
623 627 }
624 628
@@ -629,17 +633,17 @@
629 633
630 634 if ( ! give_has_variable_prices( $form_id ) || ! $form_id ) {
631 635 esc_html_e( 'n/a', 'give' );
632 636 } else {
633 - $prices_atts = array();
637 + $prices_atts = [];
634 638 if ( $variable_prices = give_get_variable_prices( $form_id ) ) {
635 639 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 ) );
640 + $prices_atts[ $variable_price['_give_id']['level_id'] ] = give_format_amount( $variable_price['_give_amount'], [ 'sanitize' => false ] );
637 641 }
638 642 }
639 643
640 644 // Variable price dropdown options.
641 - $variable_price_dropdown_option = array(
645 + $variable_price_dropdown_option = [
642 646 'id' => $form_id,
643 647 'name' => 'give-variable-price',
644 648 'chosen' => true,
645 649 'show_option_all' => '',
@@ -644,9 +648,9 @@
644 648 'chosen' => true,
645 649 'show_option_all' => '',
646 650 'show_option_none' => '',
647 651 'select_atts' => 'data-prices=' . esc_attr( json_encode( $prices_atts ) ),
648 - );
652 + ];
649 653
650 654 if ( $payment_id ) {
651 655 // Payment object.
652 656 $payment = new Give_Payment( $payment_id );
@@ -667,8 +671,9 @@
667 671
668 672 /**
669 673 * Send Confirmation Email For Complete Donation History Access.
670 674 *
675 + * @since 4.16.1 Always return a uniform success response regardless of donor existence or throttle state.
671 676 * @since 1.8.17
672 677 *
673 678 * @return bool
674 679 */
@@ -684,71 +689,32 @@
684 689 return false;
685 690 }
686 691
687 692 $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 );
693 + if ( is_object( $donor ) && Give()->email_access->can_send_email( $donor->id ) ) {
694 + Give()->email_access->send_email( $donor->id, $donor->email );
695 + }
691 696
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 - }
697 + $return = [];
698 + $return['status'] = 'success';
700 699
701 - $return['status'] = 'success';
700 + /**
701 + * Filter to modify access mail send notice
702 + *
703 + * @since 2.1.3
704 + *
705 + * @param string Send notice message for email access.
706 + *
707 + * @return string $message Send notice message for email access.
708 + */
709 + $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' ) );
702 710
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' ) );
711 + $return['message'] = Give_Notices::print_frontend_notice(
712 + $message,
713 + false,
714 + 'success'
715 + );
713 716
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 717 echo json_encode( $return );
752 718 give_die();
753 719 }
754 720
@@ -757,18 +723,131 @@
757 723 /**
758 724 * Render receipt by ajax
759 725 * Note: only for internal use
760 726 *
727 + * @since 4.9.0 rename function - PHP 8 compatibility
761 728 * @since 2.2.0
762 729 */
763 -function __give_get_receipt(){
764 - if( ! isset( $_GET['shortcode_atts'] ) ) {
730 +function give_get_receipt() {
731 +
732 + $get_data = give_clean( filter_input_array( INPUT_GET ) );
733 +
734 + if ( ! isset( $get_data['shortcode_atts'] ) ) {
765 735 give_die();
766 736 }
767 737
768 - $atts = urldecode_deep( give_clean( $_GET['shortcode_atts'] ) );
738 + $atts = (array) json_decode( $get_data['shortcode_atts'] );
769 739 $data = give_receipt_shortcode( $atts );
770 740
771 741 wp_send_json( $data );
772 742 }
773 -add_action( 'wp_ajax_get_receipt', '__give_get_receipt' );
774 -add_action( 'wp_ajax_nopriv_get_receipt', '__give_get_receipt' );
743 +add_action( 'wp_ajax_get_receipt', 'give_get_receipt');
744 +add_action( 'wp_ajax_nopriv_get_receipt', 'give_get_receipt');
745 +
746 +/**
747 + * Get ajax url to render content from other website into thickbox
748 + * Note: only for internal use
749 + *
750 + * @param array $args
751 + *
752 + * @return string
753 + * @since 2.5.0
754 + */
755 +function give_modal_ajax_url( $args = [] ) {
756 + $args = wp_parse_args(
757 + $args,
758 + [
759 + 'action' => 'give_get_content_by_ajax',
760 + '_wpnonce' => wp_create_nonce( 'give_get_content_by_ajax' ),
761 + ]
762 + );
763 +
764 + return esc_url_raw( add_query_arg( $args, admin_url( '/admin-ajax.php' ) ) );
765 +}
766 +
767 +
768 +/**
769 + * Return content from url
770 + * Note: only for internal use
771 + *
772 + * @todo use get_version endpoint to read changelog or cache add-ons infro from update_plugins option
773 + *
774 + * @return string
775 + * @since 2.5.0
776 + */
777 +function give_get_content_by_ajax_handler() {
778 + check_admin_referer( 'give_get_content_by_ajax' );
779 +
780 + if ( empty( $_GET['url'] ) ) {
781 + die();
782 + }
783 +
784 + /**
785 + * Restrict requests to GiveWP.com plugin readme.txt file only.
786 + * @link https://owasp.org/www-community/attacks/Server_Side_Request_Forgery
787 + *
788 + * @since 2.25.2
789 + */
790 + if(! preg_match('^https://givewp.com/downloads/plugins/(.*)/readme.txt$^', $_GET['url'])) {
791 + die();
792 + }
793 +
794 + // Handle changelog render request.
795 + if (
796 + ! empty( $_GET['show_changelog'] )
797 + && (int) give_clean( $_GET['show_changelog'] )
798 + ) {
799 + $msg = __( 'Sorry, unable to load changelog.', 'give' );
800 + $url = urldecode_deep( give_clean( $_GET['url'] ) );
801 +
802 + $response = wp_remote_get( $url );
803 +
804 + if ( is_wp_error( $response ) ) {
805 + echo "$msg<br><br><code>Error: {$response->get_error_message()}</code>";
806 + exit;
807 + }
808 +
809 + $response = wp_remote_retrieve_body( $response );
810 +
811 + if ( false === strpos( $response, '== Changelog ==' ) ) {
812 + echo $msg;
813 + exit;
814 + }
815 +
816 + $changelog = explode( '== Changelog ==', $response );
817 + $changelog = end( $changelog );
818 +
819 + echo give_get_format_md( $changelog );
820 + }
821 +
822 + do_action( 'give_get_content_by_ajax_handler' );
823 +
824 + exit;
825 +}
826 +
827 +add_action( 'wp_ajax_give_get_content_by_ajax', 'give_get_content_by_ajax_handler' );
828 +
829 +
830 +/**
831 + * Get form template for ajax request.
832 + *
833 + * Note: only for internal use
834 + *
835 + * @since 2.7.0
836 + */
837 +function give_get_form_template_id() {
838 + check_ajax_referer( 'give-donation-form-widget', 'security' );
839 +
840 + $formId = isset( $_POST['formId'] ) ? absint( $_POST['formId'] ) : 0;
841 +
842 + // Send error response if form id does not mentioned.
843 + if ( ! $formId ) {
844 + wp_send_json_error();
845 + }
846 +
847 + $templateID = FormTemplateUtils::getActiveID( $formId );
848 + $templateID = $templateID ?: 'legacy';
849 +
850 + wp_send_json_success( $templateID );
851 +}
852 +add_action( 'wp_ajax_give_get_form_template_id', 'give_get_form_template_id' );
853 +add_action( 'wp_ajax_no_priv_give_get_form_template_id', 'give_get_form_template_id' );