PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 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 All 256 releases
← All changes | includes/ajax-functions.php +270 -198 2.3.14.17.0 View file →
@@ -11,8 +11,10 @@
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
@@ -54,15 +56,15 @@
54 56
55 57 $works = Give_Cache::get( '_give_ajax_works', true );
56 58
57 59 if ( ! $works || $force ) {
58 - $params = array(
60 + $params = [
59 61 'sslverify' => false,
60 62 'timeout' => 30,
61 - 'body' => array(
63 + 'body' => [
62 64 'action' => 'give_test_ajax',
63 - ),
64 - );
65 + ],
66 + ];
65 67
66 68 $ajax = wp_remote_post( give_get_ajax_url(), $params );
67 69
68 70 $works = true;
@@ -113,9 +115,9 @@
113 115 * @param array $query
114 116 *
115 117 * @return string
116 118 */
117 -function give_get_ajax_url( $query = array() ) {
119 +function give_get_ajax_url( $query = [] ) {
118 120 $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';
119 121
120 122 $current_url = give_get_current_page_url();
121 123 $ajax_url = admin_url( 'admin-ajax.php', $scheme );
@@ -127,9 +129,9 @@
127 129 if ( ! empty( $query ) ) {
128 130 $ajax_url = add_query_arg( $query, $ajax_url );
129 131 }
130 132
131 - return apply_filters( 'give_ajax_url', $ajax_url );
133 + return esc_url_raw( apply_filters( 'give_ajax_url', $ajax_url ) );
132 134 }
133 135
134 136 /**
135 137 * Loads Checkout Login Fields via AJAX
@@ -171,118 +173,107 @@
171 173 do_action( 'give_donation_form_register_login_fields', $form_id );
172 174
173 175 $fields = ob_get_clean();
174 176
175 - wp_send_json( array(
176 - 'fields' => wp_json_encode( $fields ),
177 - 'submit' => wp_json_encode( give_get_donation_form_submit_button( $form_id ) ),
178 - ) );
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 + );
179 183 }
180 184
185 +add_action( 'wp_ajax_give_cancel_login', 'give_load_checkout_fields' );
181 186 add_action( 'wp_ajax_nopriv_give_cancel_login', 'give_load_checkout_fields' );
182 187 add_action( 'wp_ajax_nopriv_give_checkout_register', 'give_load_checkout_fields' );
183 188
184 -/**
185 - * Get Form Title via AJAX (used only in WordPress Admin)
186 - *
187 - * @since 1.0
188 - *
189 - * @return void
190 - */
191 -function give_ajax_get_form_title() {
192 - if ( isset( $_POST['form_id'] ) ) {
193 - $title = get_the_title( $_POST['form_id'] );
194 - if ( $title ) {
195 - echo $title;
196 - } else {
197 - echo 'fail';
198 - }
199 - }
200 - give_die();
201 -}
202 189
203 -add_action( 'wp_ajax_give_get_form_title', 'give_ajax_get_form_title' );
204 -add_action( 'wp_ajax_nopriv_give_get_form_title', 'give_ajax_get_form_title' );
205 -
206 190 /**
207 191 * Retrieve a states drop down
208 192 *
193 + * @since 2.30.0 add 'state_label' & 'states' to response
209 194 * @since 1.0
210 195 *
211 196 * @return void
212 197 */
213 198 function give_ajax_get_states_field() {
214 - $states_found = false;
215 - $show_field = true;
216 - $states_require = true;
217 - // Get the Country code from the $_POST.
218 - $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']);
219 204
220 - // Get the field name from the $_POST.
221 - $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']);
222 207
223 - $label = __( 'State', 'give' );
224 - $states_label = give_get_states_label();
208 + $label = __('State', 'give');
209 + $states_label = give_get_states_label();
225 210
226 - $default_state = '';
227 - if ( give_get_country() === $country ) {
228 - $default_state = give_get_state();
229 - }
211 + $default_state = '';
212 + if (give_get_country() === $country) {
213 + $default_state = give_get_state();
214 + }
230 215
231 - // Check if $country code exists in the array key for states label.
232 - if ( array_key_exists( $country, $states_label ) ) {
233 - $label = $states_label[ $country ];
234 - }
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 + }
235 220
236 - if ( empty( $country ) ) {
237 - $country = give_get_country();
238 - }
221 + if (empty($country)) {
222 + $country = give_get_country();
223 + }
239 224
240 - $states = give_get_states( $country );
241 - if ( ! empty( $states ) ) {
242 - $args = array(
243 - 'name' => $field_name,
244 - 'id' => $field_name,
245 - 'class' => $field_name . ' give-select',
246 - 'options' => $states,
247 - 'show_option_all' => false,
248 - 'show_option_none' => false,
249 - 'placeholder' => $label,
250 - 'selected' => $default_state,
251 - );
252 - $data = Give()->html->select( $args );
253 - $states_found = true;
254 - } else {
255 - $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';
256 242
257 - // Get the country list that does not have any states init.
258 - $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();
259 245
260 - // Check if $country code exists in the array key.
261 - if ( array_key_exists( $country, $no_states_country ) ) {
262 - $show_field = false;
263 - }
246 + // Check if $country code exists in the array key.
247 + if (array_key_exists($country, $no_states_country)) {
248 + $show_field = false;
249 + }
264 250
265 - // Get the country list that does not require states.
266 - $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();
267 253
268 - // Check if $country code exists in the array key.
269 - if ( array_key_exists( $country, $states_not_required_country_list ) ) {
270 - $states_require = false;
271 - }
272 - }
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 + }
273 259
274 - $response = array(
275 - 'success' => true,
276 - 'states_found' => $states_found,
277 - 'states_label' => $label,
278 - 'show_field' => $show_field,
279 - 'states_require' => $states_require,
280 - 'data' => $data,
281 - 'default_state' => $default_state,
282 - 'city_require' => ! array_key_exists( $country, give_city_not_required_country_list() ),
283 - );
284 - 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);
285 276 }
286 277
287 278 add_action( 'wp_ajax_give_get_states', 'give_ajax_get_states_field' );
288 279 add_action( 'wp_ajax_nopriv_give_get_states', 'give_ajax_get_states_field' );
@@ -294,12 +285,12 @@
294 285 *
295 286 * @return void
296 287 */
297 288 function give_ajax_form_search() {
298 - $results = array();
289 + $results = [];
299 290 $search = esc_sql( sanitize_text_field( $_POST['s'] ) );
300 291
301 - $args = array(
292 + $args = [
302 293 'post_type' => 'give_forms',
303 294 's' => $search,
304 295 'update_post_term_cache' => false,
305 296 'update_post_meta_cache' => false,
@@ -308,9 +299,9 @@
308 299 'post_status' => 'publish',
309 300 'orderby' => 'title',
310 301 'order' => 'ASC',
311 302 'posts_per_page' => empty( $search ) ? 30 : -1,
312 - );
303 + ];
313 304
314 305 /**
315 306 * Filter to modify Ajax form search args
316 307 *
@@ -328,12 +319,12 @@
328 319 while ( $query->have_posts() ) {
329 320 $query->the_post();
330 321 global $post;
331 322
332 - $results[] = array(
323 + $results[] = [
333 324 'id' => $post->ID,
334 325 'name' => $post->post_title,
335 - );
326 + ];
336 327 }
337 328 wp_reset_postdata();
338 329 }
339 330
@@ -345,9 +336,9 @@
345 336 * @param array $results Contain the Donation Form id
346 337 *
347 338 * @return array $results Contain the Donation Form id
348 339 */
349 - $results = (array) apply_filters( 'give_ajax_form_search_responce', $results );
340 + $results = (array) apply_filters( 'give_ajax_form_search_response', $results );
350 341
351 342 wp_send_json( $results );
352 343 }
353 344
@@ -364,11 +355,11 @@
364 355 function give_ajax_donor_search() {
365 356 global $wpdb;
366 357
367 358 $search = esc_sql( sanitize_text_field( $_POST['s'] ) );
368 - $results = array();
359 + $results = [];
369 360 if ( ! current_user_can( 'view_give_reports' ) ) {
370 - $donors = array();
361 + $donors = [];
371 362 } else {
372 363 $donors = $wpdb->get_results( "SELECT id,name,email FROM $wpdb->donors WHERE `name` LIKE '%$search%' OR `email` LIKE '%$search%' LIMIT 50" );
373 364 }
374 365
@@ -374,12 +365,12 @@
374 365
375 366 if ( $donors ) {
376 367 foreach ( $donors as $donor ) {
377 368
378 - $results[] = array(
369 + $results[] = [
379 370 'id' => $donor->id,
380 371 'name' => $donor->name . ' (' . $donor->email . ')',
381 - );
372 + ];
382 373 }
383 374 }
384 375
385 376 wp_send_json( $results );
@@ -395,32 +386,32 @@
395 386 *
396 387 * @return void
397 388 */
398 389 function give_ajax_search_users() {
399 - $results = array();
390 + $results = [];
400 391
401 392 if ( current_user_can( 'manage_give_settings' ) ) {
402 393
403 394 $search = esc_sql( sanitize_text_field( $_POST['s'] ) );
404 395
405 - $get_users_args = array(
396 + $get_users_args = [
406 397 'number' => 9999,
407 398 'search' => $search . '*',
408 - );
399 + ];
409 400
410 401 $get_users_args = apply_filters( 'give_search_users_args', $get_users_args );
411 402
412 403 $found_users = apply_filters( 'give_ajax_found_users', get_users( $get_users_args ), $search );
413 - $results = array();
404 + $results = [];
414 405
415 406 if ( $found_users ) {
416 407
417 408 foreach ( $found_users as $user ) {
418 409
419 - $results[] = array(
410 + $results[] = [
420 411 'id' => $user->ID,
421 412 'name' => esc_html( $user->user_login . ' (' . $user->user_email . ')' ),
422 - );
413 + ];
423 414 }
424 415 }
425 416 }// End if().
426 417
@@ -440,13 +431,13 @@
440 431 *
441 432 * @return string
442 433 */
443 434 function give_ajax_pages_search() {
444 - $data = array();
445 - $args = array(
435 + $data = [];
436 + $args = [
446 437 'post_type' => 'page',
447 438 's' => give_clean( $_POST['s'] ),
448 - );
439 + ];
449 440
450 441 $query = new WP_Query( $args );
451 442
452 443 // Query posts by title.
@@ -453,12 +444,12 @@
453 444 if ( $query->have_posts() ) {
454 445 while ( $query->have_posts() ) {
455 446 $query->the_post();
456 447
457 - $data[] = array(
448 + $data[] = [
458 449 'id' => get_the_ID(),
459 450 'name' => get_the_title(),
460 - );
451 + ];
461 452 }
462 453 }
463 454
464 455 wp_send_json( $data );
@@ -473,9 +464,9 @@
473 464 *
474 465 * @return void
475 466 */
476 467 function give_ajax_categories_search() {
477 - $results = array();
468 + $results = [];
478 469
479 470 /**
480 471 * Filter to modify Ajax tags search args
481 472 *
@@ -484,20 +475,23 @@
484 475 * @param array $args argument for get_terms
485 476 *
486 477 * @return array $args argument for get_terms
487 478 */
488 - $args = (array) apply_filters( 'give_forms_categories_dropdown_args', array(
489 - 'number' => 30,
490 - 'name__like' => esc_sql( sanitize_text_field( $_POST['s'] ) )
491 - ) );
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 + );
492 486
493 487 $categories = get_terms( 'give_forms_category', $args );
494 488
495 489 foreach ( $categories as $category ) {
496 - $results[] = array(
490 + $results[] = [
497 491 'id' => $category->term_id,
498 492 'name' => $category->name,
499 - );
493 + ];
500 494 }
501 495
502 496 /**
503 497 * Filter to modify Ajax tags search result
@@ -522,9 +516,9 @@
522 516 *
523 517 * @return void
524 518 */
525 519 function give_ajax_tags_search() {
526 - $results = array();
520 + $results = [];
527 521
528 522 /**
529 523 * Filter to modify Ajax tags search args
530 524 *
@@ -533,20 +527,23 @@
533 527 * @param array $args argument for get_terms
534 528 *
535 529 * @return array $args argument for get_terms
536 530 */
537 - $args = (array) apply_filters( 'give_forms_tags_dropdown_args', array(
538 - 'number' => 30,
539 - 'name__like' => esc_sql( sanitize_text_field( $_POST['s'] ) )
540 - ) );
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 + );
541 538
542 539 $categories = get_terms( 'give_forms_tag', $args );
543 540
544 541 foreach ( $categories as $category ) {
545 - $results[] = array(
542 + $results[] = [
546 543 'id' => $category->term_id,
547 544 'name' => $category->name,
548 - );
545 + ];
549 546 }
550 547
551 548 /**
552 549 * Filter to modify Ajax tags search result
@@ -576,9 +573,9 @@
576 573 if ( ! current_user_can( 'edit_give_forms', get_current_user_id() ) ) {
577 574 die( '-1' );
578 575 }
579 576
580 - $form_id = intval( $_POST['form_id'] );
577 + $form_id = absint( $_POST['form_id'] );
581 578 $form = get_post( $form_id );
582 579
583 580 if ( 'give_forms' !== $form->post_type ) {
584 581 die( '-2' );
@@ -595,9 +592,9 @@
595 592 }
596 593
597 594 foreach ( $variable_prices as $key => $price ) {
598 595
599 - $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 ] ) );
600 597
601 598 $ajax_response .= '<option value="' . esc_attr( $price['_give_id']['level_id'] ) . '">' . $level_text . '</option>';
602 599 }
603 600 $ajax_response .= '</select>';
@@ -622,10 +619,10 @@
622 619 if ( ! current_user_can( 'edit_give_payments', get_current_user_id() ) ) {
623 620 wp_die();
624 621 }
625 622
626 - $form_id = ! empty( $_POST['form_id'] ) ? intval( $_POST['form_id'] ) : false;
627 - $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;
628 625 if ( empty( $form_id ) || empty( $payment_id ) ) {
629 626 wp_die();
630 627 }
631 628
@@ -636,17 +633,17 @@
636 633
637 634 if ( ! give_has_variable_prices( $form_id ) || ! $form_id ) {
638 635 esc_html_e( 'n/a', 'give' );
639 636 } else {
640 - $prices_atts = array();
637 + $prices_atts = [];
641 638 if ( $variable_prices = give_get_variable_prices( $form_id ) ) {
642 639 foreach ( $variable_prices as $variable_price ) {
643 - $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 ] );
644 641 }
645 642 }
646 643
647 644 // Variable price dropdown options.
648 - $variable_price_dropdown_option = array(
645 + $variable_price_dropdown_option = [
649 646 'id' => $form_id,
650 647 'name' => 'give-variable-price',
651 648 'chosen' => true,
652 649 'show_option_all' => '',
@@ -651,9 +648,9 @@
651 648 'chosen' => true,
652 649 'show_option_all' => '',
653 650 'show_option_none' => '',
654 651 'select_atts' => 'data-prices=' . esc_attr( json_encode( $prices_atts ) ),
655 - );
652 + ];
656 653
657 654 if ( $payment_id ) {
658 655 // Payment object.
659 656 $payment = new Give_Payment( $payment_id );
@@ -674,8 +671,9 @@
674 671
675 672 /**
676 673 * Send Confirmation Email For Complete Donation History Access.
677 674 *
675 + * @since 4.16.1 Always return a uniform success response regardless of donor existence or throttle state.
678 676 * @since 1.8.17
679 677 *
680 678 * @return bool
681 679 */
@@ -691,71 +689,32 @@
691 689 return false;
692 690 }
693 691
694 692 $donor = Give()->donors->get_donor_by( 'email', give_clean( $_POST['email'] ) );
695 - if ( Give()->email_access->can_send_email( $donor->id ) ) {
696 - $return = array();
697 - $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 + }
698 696
699 - if ( ! $email_sent ) {
700 - $return['status'] = 'error';
701 - $return['message'] = Give()->notices->print_frontend_notice(
702 - __( 'Unable to send email. Please try again.', 'give' ),
703 - false,
704 - 'error'
705 - );
706 - }
697 + $return = [];
698 + $return['status'] = 'success';
707 699
708 - $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' ) );
709 710
710 - /**
711 - * Filter to modify access mail send notice
712 - *
713 - * @since 2.1.3
714 - *
715 - * @param string Send notice message for email access.
716 - *
717 - * @return string $message Send notice message for email access.
718 - */
719 - $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 + );
720 716
721 - $return['message'] = Give()->notices->print_frontend_notice(
722 - $message,
723 - false,
724 - 'success'
725 - );
726 -
727 -
728 - } else {
729 - $value = Give()->email_access->verify_throttle / 60;
730 - $return['status'] = 'error';
731 -
732 - /**
733 - * Filter to modify email access exceed notices message.
734 - *
735 - * @since 2.1.3
736 - *
737 - * @param string $message email access exceed notices message
738 - * @param int $value email access exceed times
739 - *
740 - * @return string $message email access exceed notices message
741 - */
742 - $message = (string) apply_filters(
743 - 'give_email_access_requests_exceed_notice',
744 - sprintf(
745 - __( 'Too many access email requests detected. Please wait %s before requesting a new donation history access link.', 'give' ),
746 - sprintf( _n( '%s minute', '%s minutes', $value, 'give' ), $value )
747 - ),
748 - $value
749 - );
750 -
751 - $return['message'] = Give()->notices->print_frontend_notice(
752 - $message,
753 - false,
754 - 'error'
755 - );
756 - }
757 -
758 717 echo json_encode( $return );
759 718 give_die();
760 719 }
761 720
@@ -764,18 +723,131 @@
764 723 /**
765 724 * Render receipt by ajax
766 725 * Note: only for internal use
767 726 *
727 + * @since 4.9.0 rename function - PHP 8 compatibility
768 728 * @since 2.2.0
769 729 */
770 -function __give_get_receipt(){
771 - 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'] ) ) {
772 735 give_die();
773 736 }
774 737
775 - $atts = urldecode_deep( give_clean( $_GET['shortcode_atts'] ) );
738 + $atts = (array) json_decode( $get_data['shortcode_atts'] );
776 739 $data = give_receipt_shortcode( $atts );
777 740
778 741 wp_send_json( $data );
779 742 }
780 -add_action( 'wp_ajax_get_receipt', '__give_get_receipt' );
781 -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' );