PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0
1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 1.8.0 All 210 releases
charitable / includes / public / charitable-template-functions.php

charitable-template-functions.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.7.0, at includes/public/charitable-template-functions.php

1,099 lines 27.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Charitable Template Functions.
4 *
5 * Functions used with template hooks.
6 *
7 * @package Charitable/Functions/Templates
8 * @author David Bisset
9 * @copyright Copyright (c) 2022, WP Charitable LLC
10 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
11 * @since 1.0.0
12 * @version 1.6.49
13 */
14
15 // Exit if accessed directly.
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit;
18 }
19
20 // //////////////////////////////
21 // HEAD OUTPUT
22 // //////////////////////////////
23 if ( ! function_exists( 'charitable_template_custom_styles' ) ) :
24
25 /**
26 * Add custom styles to the <head> section.
27 *
28 * This is used on the wp_head action.
29 *
30 * @since 1.2.0
31 *
32 * @return void
33 */
34 function charitable_template_custom_styles() {
35 if ( ! apply_filters( 'charitable_add_custom_styles', true ) ) {
36 return;
37 }
38
39 $styles = get_transient( 'charitable_custom_styles' );
40
41 if ( false === $styles ) {
42
43 ob_start();
44
45 charitable_template( 'custom-styles.css.php' );
46
47 $styles = ob_get_clean();
48
49 $styles = charitable_compress_css( $styles );
50
51 set_transient( 'charitable_custom_styles', $styles, 0 );
52 }
53
54 echo $styles;
55 }
56
57 endif;
58
59 if ( ! function_exists( 'charitable_hide_admin_bar' ) ) :
60
61 /**
62 * Hides the admin bar from header.
63 *
64 * This is designed to be used when viewing the campaign widget.
65 *
66 * @since 1.3.0
67 *
68 * @return void
69 */
70 function charitable_hide_admin_bar() {
71 ?>
72 <style type="text/css" media="screen">
73 html { margin-top: 0 !important; }
74 * html body { margin-top: 0 !important; }
75 </style>
76 <?php
77 }
78
79 endif;
80
81 // //////////////////////////////
82 // BODY CLASSES
83 // //////////////////////////////
84 if ( ! function_exists( 'charitable_add_body_classes' ) ) :
85
86 /**
87 * Adds custom body classes to certain templates.
88 *
89 * @since 1.3.0
90 *
91 * @param string[] $classes Body classes.
92 * @return string[]
93 */
94 function charitable_add_body_classes( $classes ) {
95 if ( charitable_is_page( 'donation_receipt_page' ) ) {
96 $classes[] = 'campaign-donation-receipt';
97 }
98
99 if ( charitable_is_page( 'donation_processing_page' ) ) {
100 $classes[] = 'campaign-donation-processing';
101 }
102
103 if ( charitable_is_page( 'campaign_donation_page' ) ) {
104 $classes[] = 'campaign-donation-page';
105 }
106
107 if ( charitable_is_page( 'campaign_widget_page' ) ) {
108 $classes[] = 'campaign-widget';
109 }
110
111 if ( charitable_is_page( 'email_preview' ) ) {
112 $classes[] = 'email-preview';
113 }
114
115 return $classes;
116 }
117
118 endif;
119
120 // //////////////////////////////
121 // SINGLE CAMPAIGN CONTENT
122 // //////////////////////////////
123 if ( ! function_exists( 'charitable_template_campaign_description' ) ) :
124
125 /**
126 * Display the campaign description before the summary and rest of content.
127 *
128 * @since 1.0.0
129 *
130 * @param Charitable_Campaign $campaign The campaign object.
131 * @return void
132 */
133 function charitable_template_campaign_description( $campaign ) {
134 charitable_template( 'campaign/description.php', array( 'campaign' => $campaign ) );
135 }
136
137 endif;
138
139 if ( ! function_exists( 'charitable_template_campaign_finished_notice' ) ) :
140
141 /**
142 * Display the campaign finished notice.
143 *
144 * @since 1.0.0
145 *
146 * @param Charitable_Campaign $campaign The campaign object.
147 * @return void
148 */
149 function charitable_template_campaign_finished_notice( $campaign ) {
150 if ( ! $campaign->has_ended() ) {
151 return;
152 }
153
154 charitable_template( 'campaign/finished-notice.php', array( 'campaign' => $campaign ) );
155 }
156
157 endif;
158
159 if ( ! function_exists( 'charitable_template_campaign_percentage_raised' ) ) :
160
161 /**
162 * Display the percentage that the campaign has raised in summary block.
163 *
164 * @since 1.0.0
165 *
166 * @param Charitable_Campaign $campaign The campaign object.
167 * @return boolean True if the template was displayed. False otherwise.
168 */
169 function charitable_template_campaign_percentage_raised( $campaign ) {
170 if ( ! $campaign->has_goal() ) {
171 return false;
172 }
173
174 charitable_template( 'campaign/summary-percentage-raised.php', array( 'campaign' => $campaign ) );
175
176 return true;
177 }
178
179 endif;
180
181 if ( ! function_exists( 'charitable_template_campaign_donation_summary' ) ) :
182
183 /**
184 * Display campaign goal in summary block.
185 *
186 * @since 1.0.0
187 *
188 * @param Charitable_Campaign $campaign The campaign object.
189 * @return true
190 */
191 function charitable_template_campaign_donation_summary( $campaign ) {
192 charitable_template( 'campaign/summary-donations.php', array( 'campaign' => $campaign ) );
193 return true;
194 }
195
196 endif;
197
198 if ( ! function_exists( 'charitable_template_campaign_donor_count' ) ) :
199
200 /**
201 * Display number of campaign donors in summary block.
202 *
203 * @since 1.0.0
204 *
205 * @param Charitable_Campaign $campaign The campaign object.
206 * @return true
207 */
208 function charitable_template_campaign_donor_count( $campaign ) {
209 charitable_template( 'campaign/summary-donors.php', array( 'campaign' => $campaign ) );
210 return true;
211 }
212
213 endif;
214
215 if ( ! function_exists( 'charitable_template_campaign_time_left' ) ) :
216
217 /**
218 * Display the amount of time left in the campaign in the summary block.
219 *
220 * @since 1.0.0
221 *
222 * @param Charitable_Campaign $campaign The campaign object.
223 * @return boolean True if the template was displayed. False otherwise.
224 */
225 function charitable_template_campaign_time_left( $campaign ) {
226 if ( $campaign->is_endless() ) {
227 return false;
228 }
229
230 charitable_template( 'campaign/summary-time-left.php', array( 'campaign' => $campaign ) );
231 return true;
232 }
233
234 endif;
235
236 if ( ! function_exists( 'charitable_template_donate_button' ) ) :
237
238 /**
239 * Display donate button or link in the campaign summary.
240 *
241 * @since 1.0.0
242 *
243 * @param Charitable_Campaign $campaign The campaign object.
244 * @return boolean True if the template was displayed. False otherwise.
245 */
246 function charitable_template_donate_button( $campaign ) {
247 if ( ! $campaign->can_receive_donations() ) {
248 return false;
249 }
250
251 $campaign->donate_button_template();
252
253 return true;
254 }
255
256 endif;
257
258 if ( ! function_exists( 'charitable_template_campaign_summary' ) ) :
259
260 /**
261 * Display campaign summary before rest of campaign content.
262 *
263 * @since 1.0.0
264 *
265 * @param Charitable_Campaign $campaign The campaign object.
266 * @return void
267 */
268 function charitable_template_campaign_summary( $campaign ) {
269 charitable_template( 'campaign/summary.php', array( 'campaign' => $campaign ) );
270 }
271
272 endif;
273
274 if ( ! function_exists( 'charitable_template_campaign_progress_bar' ) ) :
275
276 /**
277 * Output the campaign progress bar.
278 *
279 * @since 1.0.0
280 *
281 * @param Charitable_Campaign $campaign The campaign object.
282 * @return void
283 */
284 function charitable_template_campaign_progress_bar( $campaign ) {
285 charitable_template( 'campaign/progress-bar.php', array( 'campaign' => $campaign ) );
286 }
287
288 endif;
289
290 if ( ! function_exists( 'charitable_template_campaign_donate_button' ) ) :
291
292 /**
293 * Output the campaign donate button.
294 *
295 * @since 1.0.0
296 *
297 * @param Charitable_Campaign $campaign The campaign object.
298 * @return void
299 */
300 function charitable_template_campaign_donate_button( $campaign ) {
301 charitable_template( 'campaign/donate-button.php', array( 'campaign' => $campaign ) );
302 }
303
304 endif;
305
306 if ( ! function_exists( 'charitable_template_campaign_donate_link' ) ) :
307
308 /**
309 * Output the campaign donate link.
310 *
311 * @since 1.0.0
312 *
313 * @param Charitable_Campaign $campaign The campaign object.
314 * @return void
315 */
316 function charitable_template_campaign_donate_link( $campaign ) {
317 charitable_template( 'campaign/donate-link.php', array( 'campaign' => $campaign ) );
318 }
319
320 endif;
321
322 if ( ! function_exists( 'charitable_template_campaign_status_tag' ) ) :
323
324 /**
325 * Output the campaign status tag.
326 *
327 * @since 1.0.0
328 *
329 * @param Charitable_Campaign $campaign The campaign object.
330 * @return void
331 */
332 function charitable_template_campaign_status_tag( $campaign ) {
333 charitable_template( 'campaign/status-tag.php', array( 'campaign' => $campaign ) );
334 }
335
336 endif;
337
338 if ( ! function_exists( 'charitable_template_campaign_donation_form_in_page' ) ) :
339
340 /**
341 * Add the donation form straight into the campaign page.
342 *
343 * @since 1.0.0
344 * @since 1.5.0 Function now returns true/false depending
345 * on whether the template is rendered.
346 *
347 * @param Charitable_Campaign $campaign The campaign object.
348 * @return boolean
349 */
350 function charitable_template_campaign_donation_form_in_page( Charitable_Campaign $campaign ) {
351 if ( $campaign->can_receive_donations() && 'same_page' == charitable_get_option( 'donation_form_display', 'separate_page' ) ) {
352 $donation_id = get_query_var( 'donation_id', false );
353
354 /* If a donation ID is included, make sure it belongs to the current user. */
355 if ( $donation_id && ! charitable_user_can_access_donation( $donation_id ) ) {
356 return false;
357 }
358
359 charitable_get_current_donation_form()->render();
360 return true;
361 }
362
363 return false;
364 }
365
366 endif;
367
368 if ( ! function_exists( 'charitable_template_campaign_modal_donation_window' ) ) :
369
370 /**
371 * Adds the modal donation window to a campaign page.
372 *
373 * @since 1.0.0
374 * @since 1.5.0 Function now returns true/false depending
375 * on whether the template is rendered.
376 *
377 * @global WP_Query $wp_query
378 * @return boolean
379 */
380 function charitable_template_campaign_modal_donation_window() {
381 global $wp_query;
382
383 if ( Charitable::CAMPAIGN_POST_TYPE != get_post_type() ) {
384 return false;
385 }
386
387 if ( isset( $wp_query->query_vars['donate'] ) ) {
388 return false;
389 }
390
391 $campaign = charitable_get_current_campaign();
392
393 if ( $campaign->can_receive_donations() && 'modal' == charitable_get_option( 'donation_form_display', 'separate_page' ) ) {
394 charitable_template( 'campaign/donate-modal-window.php', array( 'campaign' => $campaign ) );
395 return true;
396 }
397
398 return false;
399 }
400
401 endif;
402
403 // //////////////////////////////
404 // CAMPAIGN LOOP
405 // //////////////////////////////
406 if ( ! function_exists( 'charitable_template_campaign_loop' ) ) :
407
408 /**
409 * Display the campaign loop.
410 *
411 * This is used instead of the_content filter.
412 *
413 * @since 1.0.0
414 *
415 * @param WP_Query $campaigns Query with campaigns.
416 * @param int $columns Number of columns to use for loop.
417 * @return void
418 */
419 function charitable_template_campaign_loop( $campaigns = false, $columns = 1 ) {
420 if ( ! $campaigns ) {
421 global $wp_query;
422 $campaigns = $wp_query;
423 }
424
425 charitable_template(
426 'campaign-loop.php',
427 array(
428 'campaigns' => $campaigns,
429 'columns' => $columns,
430 )
431 );
432 }
433
434 endif;
435
436 if ( ! function_exists( 'charitable_template_responsive_styles' ) ) :
437
438 /**
439 * Add responsive styles for the campaign loop.
440 *
441 * @since 1.4.0
442 *
443 * @param WP_Query $campaigns The campaigns that will be displayed.
444 * @param array $args The view arguments.
445 * @return void
446 */
447 function charitable_template_responsive_styles( $campaigns, $args ) {
448 if ( ! isset( $args['responsive'] ) || ! $args['responsive'] ) {
449 return;
450 }
451
452 $breakpoint = '768px';
453
454 if ( preg_match( '/[px|em]/', $args['responsive'] ) ) {
455 $breakpoint = $args['responsive'];
456 }
457 ?>
458 <style type="text/css" media="screen">
459 @media only screen and (max-width: <?php echo $breakpoint; ?>) {
460 .campaign-loop.campaign-grid.masonry { -moz-column-count: 1; -webkit-column-count: 1; column-count: 1; }
461 .campaign-loop.campaign-grid .campaign,.campaign-loop.campaign-grid .campaign.hentry { width: 100% !important; }
462 }
463 </style>
464 <?php
465 }
466
467 endif;
468
469 if ( ! function_exists( 'charitable_template_campaign_loop_thumbnail' ) ) :
470
471 /**
472 * Output the campaign thumbnail on campaigns displayed within the loop.
473 *
474 * @since 1.0.0
475 *
476 * @param Charitable_Campaign $campaign The campaign object.
477 * @return void
478 */
479 function charitable_template_campaign_loop_thumbnail( $campaign ) {
480 charitable_template( 'campaign-loop/thumbnail.php', array( 'campaign' => $campaign ) );
481 }
482
483 endif;
484
485 if ( ! function_exists( 'charitable_template_campaign_loop_donation_stats' ) ) :
486
487 /**
488 * Output the campaign donation status on campaigns displayed within the loop.
489 *
490 * @since 1.0.0
491 *
492 * @param Charitable_Campaign $campaign The campaign object.
493 * @return void
494 */
495 function charitable_template_campaign_loop_donation_stats( $campaign ) {
496 charitable_template( 'campaign-loop/donation-stats.php', array( 'campaign' => $campaign ) );
497 }
498
499 endif;
500
501 if ( ! function_exists( 'charitable_template_campaign_loop_donate_link' ) ) :
502
503 /**
504 * Output the campaign donation status on campaigns displayed within the loop.
505 *
506 * @since 1.0.0
507 *
508 * @param Charitable_Campaign $campaign The campaign object.
509 * @param mixed[] $args Optional arguments.
510 * @return void
511 */
512 function charitable_template_campaign_loop_donate_link( $campaign, $args = array() ) {
513 if ( isset( $args['button'] ) && 'donate' != $args['button'] ) {
514 return;
515 }
516
517 $campaign->donate_button_loop_template();
518 }
519
520 endif;
521
522 if ( ! function_exists( 'charitable_template_campaign_loop_more_link' ) ) :
523
524 /**
525 * Output the read more link on campaigns displayed within the loop.
526 *
527 * @since 1.2.3
528 *
529 * @param Charitable_Campaign $campaign The campaign object.
530 * @param mixed[] $args Optional arguments.
531 * @return void
532 */
533 function charitable_template_campaign_loop_more_link( $campaign, $args = array() ) {
534 if ( ! isset( $args['button'] ) || 'details' !== $args['button'] ) {
535 return;
536 }
537
538 charitable_template( 'campaign-loop/more-link.php', array( 'campaign' => $campaign ) );
539 }
540
541 endif;
542
543 if ( ! function_exists( 'charitable_template_campaign_loop_add_modal' ) ) :
544
545 /**
546 * Checks if the modal option is enabled and hooks the modal template up to wp_footer if it is.
547 *
548 * @since 1.2.3
549 *
550 * @return void
551 */
552 function charitable_template_campaign_loop_add_modal() {
553 if ( 'modal' == charitable_get_option( 'donation_form_display', 'separate_page' ) ) {
554 add_action( 'wp_footer', 'charitable_template_campaign_loop_modal_donation_window' );
555 }
556 }
557
558 endif;
559
560 if ( ! function_exists( 'charitable_template_campaign_loop_modal_donation_window' ) ) :
561
562 /**
563 * Adds the modal donation window to the campaign loop.
564 *
565 * @since 1.2.3
566 *
567 * @return void
568 */
569 function charitable_template_campaign_loop_modal_donation_window() {
570 charitable_template( 'campaign-loop/donate-modal-window.php' );
571 }
572
573 endif;
574
575 /**********************************************/
576 /* DONATION FORM
577 /**********************************************/
578
579 if ( ! function_exists( 'charitable_template_donation_form' ) ) :
580
581 /**
582 * Display a campaign's donation form.
583 *
584 * @since 1.6.55
585 *
586 * @param int $campaign_id The campaign ID.
587 * @param array $args Args to pass to the view.
588 * @return false|void
589 */
590 function charitable_template_donation_form( $campaign_id, $args = array() ) {
591 if ( Charitable::CAMPAIGN_POST_TYPE !== get_post_type( $campaign_id ) ) {
592 return false;
593 }
594
595 if ( ! array_key_exists( 'campaign_id', $args ) ) {
596 $args['campaign_id'] = $campaign_id;
597 }
598
599 if ( ! charitable_campaign_can_receive_donations( $args['campaign_id'] ) ) {
600 return false;
601 }
602
603 $donation_id = get_query_var( 'donation_id', false );
604
605 /* If a donation ID is included, make sure it belongs to the current user. */
606 if ( $donation_id && ! charitable_user_can_access_donation( $donation_id ) ) {
607 return false;
608 }
609
610 if ( ! wp_script_is( 'charitable-script', 'enqueued' ) ) {
611 Charitable_Public::get_instance()->enqueue_donation_form_scripts();
612 }
613
614 $form = charitable_get_campaign( $campaign_id )->get_donation_form();
615
616 /**
617 * Do something before rendering the donation form.
618 *
619 * @since 1.0.0
620 *
621 * @param Charitable_Donation_Form $form The donation form instance.
622 */
623 do_action( 'charitable_donation_form_before', $form );
624
625 $args['form'] = $form;
626 $args['campaign'] = $form->get_campaign();
627
628 charitable_template( 'donation-form/form-donation.php', $args );
629
630 /**
631 * Do something after rendering the donation form.
632 *
633 * @since 1.0.0
634 *
635 * @param Charitable_Donation_Form $form The donation form instance.
636 */
637 do_action( 'charitable_donation_form_after', $form );
638 }
639
640 endif;
641
642 // //////////////////////////////
643 // DONATION RECEIPT
644 // //////////////////////////////
645 if ( ! function_exists( 'charitable_template_donation_receipt_content' ) ) :
646
647 /**
648 * Display the donation form. This is used with the_content filter.
649 *
650 * @since 1.0.0
651 *
652 * @param string $content Page content.
653 * @return string
654 */
655 function charitable_template_donation_receipt_content( $content ) {
656
657 if ( ! in_the_loop() || ! charitable_is_page( 'donation_receipt_page' ) ) {
658 return $content;
659 }
660
661 /* If we are NOT using the automatic option, this is a static page with the shortcode, so don't filter again. */
662 if ( 'auto' != charitable_get_option( 'donation_receipt_page', 'auto' ) ) {
663 return $content;
664 }
665
666 return charitable_template_donation_receipt_output( $content );
667
668 }
669
670 endif;
671
672 if ( ! function_exists( 'charitable_template_donation_receipt_output' ) ) :
673
674 /**
675 * Render the donation receipt. This can be used by the [donation_receipt] shortcode or through `the_content` filter.
676 *
677 * @since 1.0.0
678 * @since 1.5.0 Added $donation argument.
679 *
680 * @param string $content Page content.
681 * @param Charitable_Donation|null $donation Optional. Useful when the donation is not the current donation.
682 * @return string
683 */
684 function charitable_template_donation_receipt_output( $content, $donation = null ) {
685 if ( is_null( $donation ) ) {
686 $donation = charitable_get_current_donation();
687 }
688
689 if ( ! $donation || 'simple' != $donation->get_donation_type() ) {
690 return $content;
691 }
692
693 ob_start();
694
695 if ( ! $donation->is_from_current_user() ) {
696 charitable_template_from_session(
697 'donation-receipt/not-authorized.php',
698 array( 'content' => $content ),
699 'donation_receipt',
700 array( 'donation_id' => $donation->ID )
701 );
702
703 return ob_get_clean();
704 }
705
706 do_action( 'charitable_donation_receipt_page', $donation );
707
708 charitable_template(
709 'content-donation-receipt.php',
710 array(
711 'content' => $content,
712 'donation' => $donation,
713 )
714 );
715
716 $content = ob_get_clean();
717
718 return $content;
719 }
720
721 endif;
722
723 if ( ! function_exists( 'charitable_template_donation_receipt_summary' ) ) :
724
725 /**
726 * Display the donation receipt summary.
727 *
728 * @since 1.0.0
729 *
730 * @param Charitable_Donation $donation The Donation object.
731 * @return void
732 */
733 function charitable_template_donation_receipt_summary( Charitable_Donation $donation ) {
734 charitable_template( 'donation-receipt/summary.php', array( 'donation' => $donation ) );
735 }
736
737 endif;
738
739 if ( ! function_exists( 'charitable_template_donation_receipt_offline_payment_instructions' ) ) :
740
741 /**
742 * Display the offline payment instructions, if applicable.
743 *
744 * @since 1.0.0
745 *
746 * @param Charitable_Donation $donation The Donation object.
747 * @return void
748 */
749 function charitable_template_donation_receipt_offline_payment_instructions( Charitable_Donation $donation ) {
750 if ( 'offline' != $donation->get_gateway() ) {
751 return;
752 }
753
754 charitable_template( 'donation-receipt/offline-payment-instructions.php', array( 'donation' => $donation ) );
755 }
756
757 endif;
758
759 if ( ! function_exists( 'charitable_template_donation_receipt_details' ) ) :
760
761 /**
762 * Display the donation details.
763 *
764 * @since 1.0.0
765 *
766 * @param Charitable_Donation $donation The Donation object.
767 * @return void
768 */
769 function charitable_template_donation_receipt_details( Charitable_Donation $donation ) {
770 charitable_template( 'donation-receipt/details.php', array( 'donation' => $donation ) );
771 }
772
773
774 endif;
775
776 // //////////////////////////////
777 // DONATION FORM
778 // //////////////////////////////
779 if ( ! function_exists( 'charitable_template_donation_form_content' ) ) :
780
781 /**
782 * Display the donation form. This is used with the_content filter.
783 *
784 * @since 1.0.0
785 *
786 * @param string $content Page content.
787 * @return string
788 */
789 function charitable_template_donation_form_content( $content ) {
790
791 if ( ! charitable_is_main_loop() || ! charitable_is_page( 'campaign_donation_page' ) ) {
792 return $content;
793 }
794
795 if ( 'separate_page' != charitable_get_option( 'donation_form_display', 'separate_page' )
796 && false === get_query_var( 'donate', false ) ) {
797 return $content;
798 }
799
800 ob_start();
801
802 charitable_template( 'content-donation-form.php' );
803
804 return ob_get_clean();
805 }
806
807 endif;
808
809 if ( ! function_exists( 'charitable_template_donation_form_login' ) ) :
810
811 /**
812 * Display a prompt to login at the start of the user fields block.
813 *
814 * @since 1.0.0
815 *
816 * @param Charitable_Donation_Form_Interface $form The donation form object.
817 * @return void
818 */
819 function charitable_template_donation_form_login( Charitable_Donation_Form_Interface $form ) {
820
821 $user = $form->get_user();
822
823 if ( $user ) {
824 return;
825 }
826
827 charitable_template( 'donation-form/donor-fields/login-form.php' );
828 }
829
830 endif;
831
832 if ( ! function_exists( 'charitable_template_donation_form_donor_details' ) ) :
833
834 /**
835 * Display the donor's saved details if the user is logged in.
836 *
837 * @since 1.0.0
838 *
839 * @param Charitable_Donation_Form_Interface $form The donation form object.
840 * @return void
841 */
842 function charitable_template_donation_form_donor_details( Charitable_Donation_Form_Interface $form ) {
843 /* Verify that the user is logged in and has all required fields filled out */
844 if ( ! $form->should_hide_user_fields() ) {
845 return;
846 }
847
848 charitable_template( 'donation-form/donor-fields/donor-details.php', array( 'user' => $form->get_user() ) );
849 }
850
851 endif;
852
853 if ( ! function_exists( 'charitable_template_donation_form_donor_fields_hidden_wrapper_start' ) ) :
854
855 /**
856 * If the user is logged in, adds a wrapper around the donor fields that hide them.
857 *
858 * @since 1.0.0
859 *
860 * @param Charitable_Donation_Form_Interface $form The donation form object.
861 * @return void
862 */
863 function charitable_template_donation_form_donor_fields_hidden_wrapper_start( Charitable_Donation_Form_Interface $form ) {
864 /* Verify that the user is logged in and has all required fields filled out */
865 if ( ! $form->should_hide_user_fields() ) {
866 return;
867 }
868
869 charitable_template( 'donation-form/donor-fields/hidden-fields-wrapper-start.php' );
870 }
871
872 endif;
873
874 if ( ! function_exists( 'charitable_template_donation_form_donor_fields_hidden_wrapper_end' ) ) :
875
876 /**
877 * Closes the hidden donor fields wrapper div if the user is logged in.
878 *
879 * @since 1.0.0
880 *
881 * @param Charitable_Donation_Form_Interface $form The donation form object.
882 * @return void
883 */
884 function charitable_template_donation_form_donor_fields_hidden_wrapper_end( Charitable_Donation_Form_Interface $form ) {
885 /* Verify that the user is logged in and has all required fields filled out */
886 if ( ! $form->should_hide_user_fields() ) {
887 return;
888 }
889
890 charitable_template( 'donation-form/donor-fields/hidden-fields-wrapper-end.php' );
891 }
892
893 endif;
894
895 if ( ! function_exists( 'charitable_template_donation_form_current_amount_text' ) ) :
896
897 /**
898 * Display the amount currently selected to donate.
899 *
900 * @since 1.5.0
901 *
902 * @param int|float $amount The current donation amount.
903 * @param string $form_id The current form ID.
904 * @param string $campaign_id The current campaign ID.
905 * @return string
906 */
907 function charitable_template_donation_form_current_amount_text( $amount, $form_id, $campaign_id ) {
908 if ( ! $amount ) {
909 return '';
910 }
911
912 /**
913 * Format the donation amount.
914 *
915 * @since 1.4.14
916 * @since 1.5.0 Third parameter has been changed from an instance of
917 * `Charitable_Donation_Form` to a campaign ID.
918 *
919 * @param string $amount_formatted The formatted amount.
920 * @param int|float $amount The raw amount.
921 * @param int $campaign_id Campaign ID.
922 */
923 $amount_formatted = apply_filters( 'charitable_session_donation_amount_formatted', charitable_format_money( $amount, false, true ), $amount, $campaign_id );
924
925 $content = '<p>';
926 /* translators: %s: donation amount */
927 $content .= sprintf( __( 'Your Donation Amount: %s.', 'charitable' ), '<strong>' . $amount_formatted . '</strong>' );
928 $content .= '&nbsp;<a href="#" class="change-donation" data-charitable-toggle="charitable-donation-options-' . esc_attr( $form_id ) . '">' . __( 'Change', 'charitable' ) . '</a>';
929 $content .= '</p>';
930
931 return $content;
932 }
933
934 endif;
935
936
937
938 // //////////////////////////////
939 // DONATION PROCESSING PAGE
940 // //////////////////////////////
941 if ( ! function_exists( 'charitable_template_donation_processing_content' ) ) :
942
943 /**
944 * Render the content of the donation processing page.
945 *
946 * @since 1.2.0
947 *
948 * @param string $content Default content to be rendered.
949 * @return string
950 */
951 function charitable_template_donation_processing_content( $content ) {
952 if ( ! charitable_is_page( 'donation_processing_page' ) ) {
953 return $content;
954 }
955
956 $donation = charitable_get_current_donation();
957
958 if ( ! $donation ) {
959 return $content;
960 }
961
962 $content = apply_filters( 'charitable_processing_donation_' . $donation->get_gateway(), $content, $donation );
963
964 return $content;
965 }
966
967 endif;
968
969 // //////////////////////////////
970 // ACCOUNT PAGES
971 // //////////////////////////////
972 if ( ! function_exists( 'charitable_template_forgot_password_content' ) ) :
973
974 /**
975 * Render the content of the forgot password page.
976 *
977 * @since 1.4.0
978 *
979 * @param string $content Default content to be rendered.
980 * @return string
981 */
982 function charitable_template_forgot_password_content( $content = '' ) {
983 if ( ! charitable_is_page( 'forgot_password_page' ) ) {
984 return $content;
985 }
986
987 ob_start();
988
989 if ( isset( $_GET['email_sent'] ) ) {
990
991 charitable_template( 'account/forgot-password-sent.php' );
992
993 } else {
994
995 charitable_template(
996 'account/forgot-password.php',
997 array(
998 'form' => new Charitable_Forgot_Password_Form(),
999 )
1000 );
1001
1002 }
1003
1004 $content = ob_get_clean();
1005
1006 return $content;
1007 }
1008
1009 endif;
1010
1011 if ( ! function_exists( 'charitable_template_reset_password_content' ) ) :
1012
1013 /**
1014 * Render the content of the reset password page.
1015 *
1016 * @since 1.4.0
1017 *
1018 * @param string $content Default content to be rendered.
1019 * @return string
1020 */
1021 function charitable_template_reset_password_content( $content = '' ) {
1022 if ( ! charitable_is_page( 'reset_password_page' ) ) {
1023 return $content;
1024 }
1025
1026 ob_start();
1027
1028 charitable_template(
1029 'account/reset-password.php',
1030 array(
1031 'form' => new Charitable_Reset_Password_Form(),
1032 )
1033 );
1034
1035 $content = ob_get_clean();
1036
1037 return $content;
1038 }
1039
1040 endif;
1041
1042 if ( ! function_exists( 'charitable_template_form_login_link' ) ) :
1043
1044 /**
1045 * Display a link to the login form.
1046 *
1047 * @since 1.4.2
1048 *
1049 * @param Charitable_Registration_Form|null $form Instance of `Charitable_Registration_Form`, or
1050 * null in previous versions of Charitable.
1051 * @return void
1052 */
1053 function charitable_template_form_login_link( $form = null ) {
1054 /**
1055 * For backwards compatibility, since previously the
1056 * Form object was not passed to the hook.
1057 */
1058 if ( is_null( $form ) ) {
1059 return;
1060 }
1061
1062 if ( ! $form->get_login_link() ) {
1063 return;
1064 }
1065
1066 printf( '<p>%s</p>', $form->get_login_link() );
1067 }
1068
1069 endif;
1070
1071 // //////////////////////////////
1072 // NOTICES
1073 // //////////////////////////////
1074 if ( ! function_exists( 'charitable_template_notices' ) ) :
1075
1076 /**
1077 * Render any notices.
1078 *
1079 * @since 1.4.0
1080 *
1081 * @param array $notices Optional. Notices to be rendered.
1082 * @return void
1083 */
1084 function charitable_template_notices( $notices = array() ) {
1085 if ( empty( $notices ) ) {
1086 $notices = charitable_get_notices()->get_notices();
1087 }
1088
1089 charitable_template_from_session(
1090 'form-fields/notices.php',
1091 array(
1092 'notices' => $notices,
1093 ),
1094 'notices'
1095 );
1096 }
1097
1098 endif;
1099