PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.14
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.14
1.8.13.1 1.8.13 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 All 212 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.14, at includes/public/charitable-template-functions.php

1,248 lines 31.4 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 // Added in 1.7.0.9 - add filter for custom logic and now controllable by new tab for campaign settings.
175 if ( false === apply_filters( 'charitable_display_template_campaign_percentage_raised', true, $campaign ) ) {
176 return false;
177 }
178
179 charitable_template( 'campaign/summary-percentage-raised.php', array( 'campaign' => $campaign ) );
180
181 return true;
182 }
183
184 endif;
185
186 if ( ! function_exists( 'charitable_template_campaign_donation_summary' ) ) :
187
188 /**
189 * Display campaign goal in summary block.
190 *
191 * @since 1.0.0
192 *
193 * @param Charitable_Campaign $campaign The campaign object.
194 * @return true
195 */
196 function charitable_template_campaign_donation_summary( $campaign ) {
197 charitable_template( 'campaign/summary-donations.php', array( 'campaign' => $campaign ) );
198 return true;
199 }
200
201 endif;
202
203 if ( ! function_exists( 'charitable_template_campaign_donor_count' ) ) :
204
205 /**
206 * Display number of campaign donors in summary block.
207 *
208 * @since 1.0.0
209 *
210 * @param Charitable_Campaign $campaign The campaign object.
211 * @return true
212 */
213 function charitable_template_campaign_donor_count( $campaign ) {
214
215 // Added in 1.7.0.9 - add filter for custom logic and now controllable by new tab for campaign settings.
216 if ( false === apply_filters( 'charitable_display_template_campaign_donor_count', true, $campaign ) ) {
217 return false;
218 }
219
220 charitable_template( 'campaign/summary-donors.php', array( 'campaign' => $campaign ) );
221 return true;
222 }
223
224 endif;
225
226 if ( ! function_exists( 'charitable_template_campaign_time_left' ) ) :
227
228 /**
229 * Display the amount of time left in the campaign in the summary block.
230 *
231 * @since 1.0.0
232 *
233 * @param Charitable_Campaign $campaign The campaign object.
234 * @return boolean True if the template was displayed. False otherwise.
235 */
236 function charitable_template_campaign_time_left( $campaign ) {
237 if ( $campaign->is_endless() ) {
238 return false;
239 }
240
241 // Added in 1.7.0.9 - add filter for custom logic and now controllable by new tab for campaign settings.
242 if ( false === apply_filters( 'charitable_display_template_campaign_time_remaining', true, $campaign ) ) {
243 return false;
244 }
245
246 charitable_template( 'campaign/summary-time-left.php', array( 'campaign' => $campaign ) );
247 return true;
248 }
249
250 endif;
251
252 if ( ! function_exists( 'charitable_template_donate_button' ) ) :
253
254 /**
255 * Display donate button or link in the campaign summary.
256 *
257 * @since 1.0.0
258 *
259 * @param Charitable_Campaign $campaign The campaign object.
260 * @return boolean True if the template was displayed. False otherwise.
261 */
262 function charitable_template_donate_button( $campaign ) {
263 if ( ! $campaign->can_receive_donations() ) {
264 return false;
265 }
266
267 $campaign->donate_button_template();
268
269 return true;
270 }
271
272 endif;
273
274 if ( ! function_exists( 'charitable_template_campaign_summary' ) ) :
275
276 /**
277 * Display campaign summary before rest of campaign content.
278 *
279 * @since 1.0.0
280 *
281 * @param Charitable_Campaign $campaign The campaign object.
282 * @return void
283 */
284 function charitable_template_campaign_summary( $campaign ) {
285 charitable_template( 'campaign/summary.php', array( 'campaign' => $campaign ) );
286 }
287
288 endif;
289
290 if ( ! function_exists( 'charitable_template_campaign_progress_bar' ) ) :
291
292 /**
293 * Output the campaign progress bar.
294 *
295 * @since 1.0.0
296 *
297 * @param Charitable_Campaign $campaign The campaign object.
298 * @return void
299 */
300 function charitable_template_campaign_progress_bar( $campaign ) {
301 charitable_template( 'campaign/progress-bar.php', array( 'campaign' => $campaign ) );
302 }
303
304 endif;
305
306 if ( ! function_exists( 'charitable_template_campaign_donate_button' ) ) :
307
308 /**
309 * Output the campaign donate button.
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_button( $campaign ) {
317 charitable_template( 'campaign/donate-button.php', array( 'campaign' => $campaign ) );
318 }
319
320 endif;
321
322 if ( ! function_exists( 'charitable_template_campaign_donate_link' ) ) :
323
324 /**
325 * Output the campaign donate link.
326 *
327 * @since 1.0.0
328 *
329 * @param Charitable_Campaign $campaign The campaign object.
330 * @return void
331 */
332 function charitable_template_campaign_donate_link( $campaign ) {
333 charitable_template( 'campaign/donate-link.php', array( 'campaign' => $campaign ) );
334 }
335
336 endif;
337
338 if ( ! function_exists( 'charitable_template_campaign_status_tag' ) ) :
339
340 /**
341 * Output the campaign status tag.
342 *
343 * @since 1.0.0
344 *
345 * @param Charitable_Campaign $campaign The campaign object.
346 * @return void
347 */
348 function charitable_template_campaign_status_tag( $campaign ) {
349 charitable_template( 'campaign/status-tag.php', array( 'campaign' => $campaign ) );
350 }
351
352 endif;
353
354 if ( ! function_exists( 'charitable_template_campaign_donation_form_in_page' ) ) :
355
356 /**
357 * Add the donation form straight into the campaign page.
358 *
359 * @since 1.0.0
360 * @since 1.5.0 Function now returns true/false depending
361 * on whether the template is rendered.
362 *
363 * @param Charitable_Campaign $campaign The campaign object.
364 * @return boolean
365 */
366 function charitable_template_campaign_donation_form_in_page( Charitable_Campaign $campaign ) {
367 if ( $campaign->can_receive_donations() && 'same_page' == charitable_get_option( 'donation_form_display', 'separate_page' ) ) {
368 $donation_id = get_query_var( 'donation_id', false );
369
370 /* If a donation ID is included, make sure it belongs to the current user. */
371 if ( $donation_id && ! charitable_user_can_access_donation( $donation_id ) ) {
372 return false;
373 }
374
375 charitable_get_current_donation_form()->render();
376 return true;
377 }
378
379 return false;
380 }
381
382 endif;
383
384 if ( ! function_exists( 'charitable_template_campaign_modal_donation_window' ) ) :
385
386 /**
387 * Adds the modal donation window to a campaign page.
388 *
389 * @since 1.0.0
390 * @since 1.5.0 Function now returns true/false depending
391 * on whether the template is rendered.
392 *
393 * @global WP_Query $wp_query
394 * @return boolean
395 */
396 function charitable_template_campaign_modal_donation_window() {
397 global $wp_query;
398
399 if ( Charitable::CAMPAIGN_POST_TYPE != get_post_type() ) {
400 return false;
401 }
402
403 if ( isset( $wp_query->query_vars['donate'] ) ) {
404 return false;
405 }
406
407 $campaign = charitable_get_current_campaign();
408
409 if ( $campaign->can_receive_donations() && 'modal' == charitable_get_option( 'donation_form_display', 'separate_page' ) ) {
410 charitable_template( 'campaign/donate-modal-window.php', array( 'campaign' => $campaign ) );
411 return true;
412 }
413
414 return false;
415 }
416
417 endif;
418
419 // //////////////////////////////
420 // CAMPAIGN LOOP
421 // //////////////////////////////
422 if ( ! function_exists( 'charitable_template_campaign_loop' ) ) :
423
424 /**
425 * Display the campaign loop.
426 *
427 * This is used instead of the_content filter.
428 *
429 * @since 1.0.0
430 *
431 * @param WP_Query $campaigns Query with campaigns.
432 * @param int $columns Number of columns to use for loop.
433 * @return void
434 */
435 function charitable_template_campaign_loop( $campaigns = false, $columns = 1 ) {
436 if ( ! $campaigns ) {
437 global $wp_query;
438 $campaigns = $wp_query;
439 }
440
441 charitable_template(
442 'campaign-loop.php',
443 array(
444 'campaigns' => $campaigns,
445 'columns' => $columns,
446 )
447 );
448 }
449
450 endif;
451
452 if ( ! function_exists( 'charitable_template_responsive_styles' ) ) :
453
454 /**
455 * Add responsive styles for the campaign loop.
456 *
457 * @since 1.4.0
458 *
459 * @param WP_Query $campaigns The campaigns that will be displayed.
460 * @param array $args The view arguments.
461 * @return void
462 */
463 function charitable_template_responsive_styles( $campaigns, $args ) {
464 if ( ! isset( $args['responsive'] ) || ! $args['responsive'] ) {
465 return;
466 }
467
468 $breakpoint = '768px';
469
470 if ( preg_match( '/[px|em]/', $args['responsive'] ) ) {
471 $breakpoint = $args['responsive'];
472 }
473 ?>
474 <style type="text/css" media="screen">
475 @media only screen and (max-width: <?php echo $breakpoint; ?>) {
476 .campaign-loop.campaign-grid.masonry { -moz-column-count: 1; -webkit-column-count: 1; column-count: 1; }
477 .campaign-loop.campaign-grid .campaign,.campaign-loop.campaign-grid .campaign.hentry { width: 100% !important; }
478 }
479 </style>
480 <?php
481 }
482
483 endif;
484
485 if ( ! function_exists( 'charitable_template_campaign_loop_thumbnail' ) ) :
486
487 /**
488 * Output the campaign thumbnail 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_thumbnail( $campaign ) {
496 charitable_template( 'campaign-loop/thumbnail.php', array( 'campaign' => $campaign ) );
497 }
498
499 endif;
500
501 if ( ! function_exists( 'charitable_template_campaign_loop_donation_stats' ) ) :
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 * @return void
510 */
511 function charitable_template_campaign_loop_donation_stats( $campaign ) {
512 charitable_template( 'campaign-loop/donation-stats.php', array( 'campaign' => $campaign ) );
513 }
514
515 endif;
516
517 if ( ! function_exists( 'charitable_template_campaign_loop_donate_link' ) ) :
518
519 /**
520 * Output the campaign donation status on campaigns displayed within the loop.
521 *
522 * @since 1.0.0
523 *
524 * @param Charitable_Campaign $campaign The campaign object.
525 * @param mixed[] $args Optional arguments.
526 * @return void
527 */
528 function charitable_template_campaign_loop_donate_link( $campaign, $args = array() ) {
529 if ( isset( $args['button'] ) && 'donate' != $args['button'] ) {
530 return;
531 }
532
533 $campaign->donate_button_loop_template();
534 }
535
536 endif;
537
538 if ( ! function_exists( 'charitable_template_campaign_loop_more_link' ) ) :
539
540 /**
541 * Output the read more link on campaigns displayed within the loop.
542 *
543 * @since 1.2.3
544 *
545 * @param Charitable_Campaign $campaign The campaign object.
546 * @param mixed[] $args Optional arguments.
547 * @return void
548 */
549 function charitable_template_campaign_loop_more_link( $campaign, $args = array() ) {
550 if ( ! isset( $args['button'] ) || 'details' !== $args['button'] ) {
551 return;
552 }
553
554 charitable_template( 'campaign-loop/more-link.php', array( 'campaign' => $campaign ) );
555 }
556
557 endif;
558
559 if ( ! function_exists( 'charitable_template_campaign_loop_add_modal' ) ) :
560
561 /**
562 * Checks if the modal option is enabled and hooks the modal template up to wp_footer if it is.
563 *
564 * @since 1.2.3
565 *
566 * @return void
567 */
568 function charitable_template_campaign_loop_add_modal() {
569 if ( 'modal' == charitable_get_option( 'donation_form_display', 'separate_page' ) ) {
570 add_action( 'wp_footer', 'charitable_template_campaign_loop_modal_donation_window' );
571 }
572 }
573
574 endif;
575
576 if ( ! function_exists( 'charitable_template_campaign_loop_modal_donation_window' ) ) :
577
578 /**
579 * Adds the modal donation window to the campaign loop.
580 *
581 * @since 1.2.3
582 *
583 * @return void
584 */
585 function charitable_template_campaign_loop_modal_donation_window() {
586 charitable_template( 'campaign-loop/donate-modal-window.php' );
587 }
588
589 endif;
590
591 /**********************************************/
592 /* DONATION FORM
593 /**********************************************/
594
595 if ( ! function_exists( 'charitable_template_donation_form' ) ) :
596
597 /**
598 * Display a campaign's donation form.
599 *
600 * @since 1.6.55
601 *
602 * @param int $campaign_id The campaign ID.
603 * @param array $args Args to pass to the view.
604 * @return false|void
605 */
606 function charitable_template_donation_form( $campaign_id, $args = array() ) {
607 if ( Charitable::CAMPAIGN_POST_TYPE !== get_post_type( $campaign_id ) ) {
608 return false;
609 }
610
611 if ( ! array_key_exists( 'campaign_id', $args ) ) {
612 $args['campaign_id'] = $campaign_id;
613 }
614
615 if ( ! charitable_campaign_can_receive_donations( $args['campaign_id'] ) ) {
616 return false;
617 }
618
619 $donation_id = get_query_var( 'donation_id', false );
620
621 /* If a donation ID is included, make sure it belongs to the current user. */
622 if ( $donation_id && ! charitable_user_can_access_donation( $donation_id ) ) {
623 return false;
624 }
625
626 if ( ! wp_script_is( 'charitable-script', 'enqueued' ) ) {
627 Charitable_Public::get_instance()->enqueue_donation_form_scripts();
628 }
629
630 $form = charitable_get_campaign( $campaign_id )->get_donation_form();
631
632 /**
633 * Do something before rendering the donation form.
634 *
635 * @since 1.0.0
636 *
637 * @param Charitable_Donation_Form $form The donation form instance.
638 */
639 do_action( 'charitable_donation_form_before', $form );
640
641 $args['form'] = $form;
642 $args['campaign'] = $form->get_campaign();
643
644 charitable_template( 'donation-form/form-donation.php', $args );
645
646 /**
647 * Do something after rendering the donation form.
648 *
649 * @since 1.0.0
650 *
651 * @param Charitable_Donation_Form $form The donation form instance.
652 */
653 do_action( 'charitable_donation_form_after', $form );
654 }
655
656 endif;
657
658 // //////////////////////////////
659 // DONATION RECEIPT
660 // //////////////////////////////
661 if ( ! function_exists( 'charitable_template_donation_receipt_content' ) ) :
662
663 /**
664 * Display the donation form. This is used with the_content filter.
665 *
666 * @since 1.0.0
667 *
668 * @param string $content Page content.
669 * @return string
670 */
671 function charitable_template_donation_receipt_content( $content ) {
672
673 if ( ! in_the_loop() || ! charitable_is_page( 'donation_receipt_page' ) ) {
674 return $content;
675 }
676
677 /* If we are NOT using the automatic option, this is a static page with the shortcode, so don't filter again. */
678 if ( 'auto' != charitable_get_option( 'donation_receipt_page', 'auto' ) ) {
679 return $content;
680 }
681
682 return charitable_template_donation_receipt_output( $content );
683
684 }
685
686 endif;
687
688 if ( ! function_exists( 'charitable_template_donation_receipt_output' ) ) :
689
690 /**
691 * Render the donation receipt. This can be used by the [donation_receipt] shortcode or through `the_content` filter.
692 *
693 * @since 1.0.0
694 * @since 1.5.0 Added $donation argument.
695 *
696 * @param string $content Page content.
697 * @param Charitable_Donation|null $donation Optional. Useful when the donation is not the current donation.
698 * @return string
699 */
700 function charitable_template_donation_receipt_output( $content, $donation = null ) {
701 if ( is_null( $donation ) ) {
702 $donation = charitable_get_current_donation();
703 }
704
705 if ( ! $donation || 'simple' != $donation->get_donation_type() ) {
706 return $content;
707 }
708
709 ob_start();
710
711 if ( ! $donation->is_from_current_user() ) {
712 charitable_template_from_session(
713 'donation-receipt/not-authorized.php',
714 array( 'content' => $content ),
715 'donation_receipt',
716 array( 'donation_id' => $donation->ID )
717 );
718
719 return ob_get_clean();
720 }
721
722 do_action( 'charitable_donation_receipt_page', $donation );
723
724 charitable_template(
725 'content-donation-receipt.php',
726 array(
727 'content' => $content,
728 'donation' => $donation,
729 )
730 );
731
732 $content = ob_get_clean();
733
734 return $content;
735 }
736
737 endif;
738
739 if ( ! function_exists( 'charitable_template_donation_receipt_summary' ) ) :
740
741 /**
742 * Display the donation receipt summary.
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_summary( Charitable_Donation $donation ) {
750 charitable_template( 'donation-receipt/summary.php', array( 'donation' => $donation ) );
751 }
752
753 endif;
754
755 if ( ! function_exists( 'charitable_template_donation_receipt_offline_payment_instructions' ) ) :
756
757 /**
758 * Display the offline payment instructions, if applicable.
759 *
760 * @since 1.0.0
761 *
762 * @param Charitable_Donation $donation The Donation object.
763 * @return void
764 */
765 function charitable_template_donation_receipt_offline_payment_instructions( Charitable_Donation $donation ) {
766 if ( 'offline' != $donation->get_gateway() ) {
767 return;
768 }
769
770 charitable_template( 'donation-receipt/offline-payment-instructions.php', array( 'donation' => $donation ) );
771 }
772
773 endif;
774
775 if ( ! function_exists( 'charitable_template_donation_receipt_details' ) ) :
776
777 /**
778 * Display the donation details.
779 *
780 * @since 1.0.0
781 *
782 * @param Charitable_Donation $donation The Donation object.
783 * @return void
784 */
785 function charitable_template_donation_receipt_details( Charitable_Donation $donation ) {
786 charitable_template( 'donation-receipt/details.php', array( 'donation' => $donation ) );
787 }
788
789
790 endif;
791
792 // //////////////////////////////
793 // DONATION FORM
794 // //////////////////////////////
795 if ( ! function_exists( 'charitable_template_donation_form_content' ) ) :
796
797 /**
798 * Display the donation form. This is used with the_content filter.
799 *
800 * @since 1.0.0
801 *
802 * @param string $content Page content.
803 * @return string
804 */
805 function charitable_template_donation_form_content( $content ) {
806
807 if ( ! charitable_is_main_loop() || ! charitable_is_page( 'campaign_donation_page' ) ) {
808 return $content;
809 }
810
811 if ( 'separate_page' != charitable_get_option( 'donation_form_display', 'separate_page' )
812 && false === get_query_var( 'donate', false ) ) {
813 return $content;
814 }
815
816 ob_start();
817
818 charitable_template( 'content-donation-form.php' );
819
820 return ob_get_clean();
821 }
822
823 endif;
824
825 if ( ! function_exists( 'charitable_template_donation_form_login' ) ) :
826
827 /**
828 * Display a prompt to login at the start of the user fields block.
829 *
830 * @since 1.0.0
831 *
832 * @param Charitable_Donation_Form_Interface $form The donation form object.
833 * @return void
834 */
835 function charitable_template_donation_form_login( Charitable_Donation_Form_Interface $form ) {
836
837 $user = $form->get_user();
838
839 if ( $user ) {
840 return;
841 }
842
843 charitable_template( 'donation-form/donor-fields/login-form.php' );
844 }
845
846 endif;
847
848 if ( ! function_exists( 'charitable_template_donation_form_donor_details' ) ) :
849
850 /**
851 * Display the donor's saved details if the user is logged in.
852 *
853 * @since 1.0.0
854 *
855 * @param Charitable_Donation_Form_Interface $form The donation form object.
856 * @return void
857 */
858 function charitable_template_donation_form_donor_details( Charitable_Donation_Form_Interface $form ) {
859 /* Verify that the user is logged in and has all required fields filled out */
860 if ( ! $form->should_hide_user_fields() ) {
861 return;
862 }
863
864 charitable_template( 'donation-form/donor-fields/donor-details.php', array( 'user' => $form->get_user() ) );
865 }
866
867 endif;
868
869 if ( ! function_exists( 'charitable_template_donation_form_donor_fields_hidden_wrapper_start' ) ) :
870
871 /**
872 * If the user is logged in, adds a wrapper around the donor fields that hide them.
873 *
874 * @since 1.0.0
875 *
876 * @param Charitable_Donation_Form_Interface $form The donation form object.
877 * @return void
878 */
879 function charitable_template_donation_form_donor_fields_hidden_wrapper_start( Charitable_Donation_Form_Interface $form ) {
880 /* Verify that the user is logged in and has all required fields filled out */
881 if ( ! $form->should_hide_user_fields() ) {
882 return;
883 }
884
885 charitable_template( 'donation-form/donor-fields/hidden-fields-wrapper-start.php' );
886 }
887
888 endif;
889
890 if ( ! function_exists( 'charitable_template_donation_form_donor_fields_hidden_wrapper_end' ) ) :
891
892 /**
893 * Closes the hidden donor fields wrapper div if the user is logged in.
894 *
895 * @since 1.0.0
896 *
897 * @param Charitable_Donation_Form_Interface $form The donation form object.
898 * @return void
899 */
900 function charitable_template_donation_form_donor_fields_hidden_wrapper_end( Charitable_Donation_Form_Interface $form ) {
901 /* Verify that the user is logged in and has all required fields filled out */
902 if ( ! $form->should_hide_user_fields() ) {
903 return;
904 }
905
906 charitable_template( 'donation-form/donor-fields/hidden-fields-wrapper-end.php' );
907 }
908
909 endif;
910
911 if ( ! function_exists( 'charitable_template_donation_form_current_amount_text' ) ) :
912
913 /**
914 * Display the amount currently selected to donate.
915 *
916 * @since 1.5.0
917 *
918 * @param int|float $amount The current donation amount.
919 * @param string $form_id The current form ID.
920 * @param string $campaign_id The current campaign ID.
921 * @return string
922 */
923 function charitable_template_donation_form_current_amount_text( $amount, $form_id, $campaign_id ) {
924 if ( ! $amount ) {
925 return '';
926 }
927
928 /**
929 * Format the donation amount.
930 *
931 * @since 1.4.14
932 * @since 1.5.0 Third parameter has been changed from an instance of
933 * `Charitable_Donation_Form` to a campaign ID.
934 *
935 * @param string $amount_formatted The formatted amount.
936 * @param int|float $amount The raw amount.
937 * @param int $campaign_id Campaign ID.
938 */
939 $amount_formatted = apply_filters( 'charitable_session_donation_amount_formatted', charitable_format_money( $amount, false, true ), $amount, $campaign_id );
940
941 $content = '<p>';
942 /* translators: %s: donation amount */
943 $content .= sprintf( __( 'Your Donation Amount: %s.', 'charitable' ), '<strong>' . $amount_formatted . '</strong>' );
944 $content .= '&nbsp;<a href="#" class="change-donation" data-charitable-toggle="charitable-donation-options-' . esc_attr( $form_id ) . '">' . __( 'Change', 'charitable' ) . '</a>';
945 $content .= '</p>';
946
947 return $content;
948 }
949
950 endif;
951
952
953
954 // //////////////////////////////
955 // DONATION PROCESSING PAGE
956 // //////////////////////////////
957 if ( ! function_exists( 'charitable_template_donation_processing_content' ) ) :
958
959 /**
960 * Render the content of the donation processing page.
961 *
962 * @since 1.2.0
963 *
964 * @param string $content Default content to be rendered.
965 * @return string
966 */
967 function charitable_template_donation_processing_content( $content ) {
968 if ( ! charitable_is_page( 'donation_processing_page' ) ) {
969 return $content;
970 }
971
972 $donation = charitable_get_current_donation();
973
974 if ( ! $donation ) {
975 return $content;
976 }
977
978 $content = apply_filters( 'charitable_processing_donation_' . $donation->get_gateway(), $content, $donation );
979
980 return $content;
981 }
982
983 endif;
984
985 // //////////////////////////////
986 // ACCOUNT PAGES
987 // //////////////////////////////
988 if ( ! function_exists( 'charitable_template_forgot_password_content' ) ) :
989
990 /**
991 * Render the content of the forgot password page.
992 *
993 * @since 1.4.0
994 *
995 * @param string $content Default content to be rendered.
996 * @return string
997 */
998 function charitable_template_forgot_password_content( $content = '' ) {
999 if ( ! charitable_is_page( 'forgot_password_page' ) ) {
1000 return $content;
1001 }
1002
1003 ob_start();
1004
1005 if ( isset( $_GET['email_sent'] ) ) {
1006
1007 charitable_template( 'account/forgot-password-sent.php' );
1008
1009 } else {
1010
1011 charitable_template(
1012 'account/forgot-password.php',
1013 array(
1014 'form' => new Charitable_Forgot_Password_Form(),
1015 )
1016 );
1017
1018 }
1019
1020 $content = ob_get_clean();
1021
1022 return $content;
1023 }
1024
1025 endif;
1026
1027 if ( ! function_exists( 'charitable_template_reset_password_content' ) ) :
1028
1029 /**
1030 * Render the content of the reset password page.
1031 *
1032 * @since 1.4.0
1033 *
1034 * @param string $content Default content to be rendered.
1035 * @return string
1036 */
1037 function charitable_template_reset_password_content( $content = '' ) {
1038 if ( ! charitable_is_page( 'reset_password_page' ) ) {
1039 return $content;
1040 }
1041
1042 ob_start();
1043
1044 charitable_template(
1045 'account/reset-password.php',
1046 array(
1047 'form' => new Charitable_Reset_Password_Form(),
1048 )
1049 );
1050
1051 $content = ob_get_clean();
1052
1053 return $content;
1054 }
1055
1056 endif;
1057
1058 if ( ! function_exists( 'charitable_template_form_login_link' ) ) :
1059
1060 /**
1061 * Display a link to the login form.
1062 *
1063 * @since 1.4.2
1064 *
1065 * @param Charitable_Registration_Form|null $form Instance of `Charitable_Registration_Form`, or
1066 * null in previous versions of Charitable.
1067 * @return void
1068 */
1069 function charitable_template_form_login_link( $form = null ) {
1070 /**
1071 * For backwards compatibility, since previously the
1072 * Form object was not passed to the hook.
1073 */
1074 if ( is_null( $form ) ) {
1075 return;
1076 }
1077
1078 if ( ! $form->get_login_link() ) {
1079 return;
1080 }
1081
1082 printf( '<p>%s</p>', $form->get_login_link() );
1083 }
1084
1085 endif;
1086
1087 if ( ! function_exists( 'charitable_maybe_hide_campaign_percentage_raised' ) ) :
1088
1089 /**
1090 * Determine if a campaign setting says to hide this. Return true to show, false to hide.
1091 *
1092 * @since 1.7.0.8
1093 *
1094 * @param boolean $current_value Current value of boolean passed in.
1095 * @return boolean
1096 */
1097 function charitable_maybe_hide_campaign_percentage_raised( $current_value = true, $campaign = false ) {
1098
1099 if ( false === $campaign || 0 === $campaign->get_campaign_id() ) {
1100 return $current_value;
1101 }
1102
1103 $campaign_hide_percent_raised = get_post_meta( $campaign->get_campaign_id(), '_campaign_hide_percent_raised', true );
1104
1105 if ( false === $campaign_hide_percent_raised || empty( $campaign_hide_percent_raised ) ) {
1106 return $current_value;
1107 }
1108
1109 if ( in_array( 'hide_percent_raised', $campaign_hide_percent_raised ) ) {
1110 return false; // hide
1111 }
1112
1113 return $current_value;
1114
1115 }
1116
1117 endif;
1118
1119
1120 if ( ! function_exists( 'charitable_maybe_hide_campaign_donor_count' ) ) :
1121
1122 /**
1123 * Determine if a campaign setting says to hide this. Return true to show, false to hide.
1124 *
1125 * @since 1.7.0.8
1126 *
1127 * @param boolean $current_value Current value of boolean passed in.
1128 * @return boolean
1129 */
1130 function charitable_maybe_hide_campaign_donor_count( $current_value = true, $campaign = false ) {
1131
1132 if ( false === $campaign || 0 === $campaign->get_campaign_id() ) {
1133 return $current_value;
1134 }
1135
1136 $campaign_hide_donor_count = get_post_meta( $campaign->get_campaign_id(), '_campaign_hide_number_of_donors', true );
1137
1138 if ( false === $campaign_hide_donor_count || empty( $campaign_hide_donor_count ) ) {
1139 return $current_value;
1140 }
1141
1142 if ( in_array( 'hide_number_of_donors', $campaign_hide_donor_count ) ) {
1143 return false; // hide
1144 }
1145
1146 return $current_value;
1147
1148 }
1149
1150 endif;
1151
1152
1153 if ( ! function_exists( 'charitable_maybe_hide_campaign_amount_donated' ) ) :
1154
1155 /**
1156 * Determine if a campaign setting says to hide this. Return true to show, false to hide.
1157 *
1158 * @since 1.7.0.8
1159 *
1160 * @param boolean $current_value Current value of boolean passed in.
1161 * @return boolean
1162 */
1163 function charitable_maybe_hide_campaign_amount_donated( $current_value, $campaign, $amount, $goal ) {
1164
1165 if ( false === $campaign || 0 === $campaign->get_campaign_id() ) {
1166 return $current_value;
1167 }
1168
1169 $campaign_hide_amount_donated = get_post_meta( $campaign->get_campaign_id(), '_campaign_hide_amount_donated', true );
1170
1171 if ( false === $campaign_hide_amount_donated || empty( $campaign_hide_amount_donated ) ) {
1172 return $current_value;
1173 }
1174
1175 if ( in_array( 'hide_amount_donated', $campaign_hide_amount_donated ) ) {
1176 return false; // hide
1177 }
1178
1179 return $current_value;
1180
1181 }
1182
1183 endif;
1184
1185
1186 if ( ! function_exists( 'charitable_maybe_hide_campaign_time_remaining' ) ) :
1187
1188 /**
1189 * Determine if a campaign setting says to hide this. Return true to show, false to hide.
1190 *
1191 * @since 1.7.0.8
1192 *
1193 * @param boolean $current_value Current value of boolean passed in.
1194 * @return boolean
1195 */
1196 function charitable_maybe_hide_campaign_time_remaining( $current_value = true, $campaign = false ) {
1197
1198 if ( false === $campaign || 0 === $campaign->get_campaign_id() ) {
1199 return $current_value;
1200 }
1201
1202 $campaign_hide_time_remaining = get_post_meta( $campaign->get_campaign_id(), '_campaign_hide_time_remaining', true );
1203
1204 if ( false === $campaign_hide_time_remaining || empty( $campaign_hide_time_remaining ) ) {
1205 return $current_value;
1206 }
1207
1208 if ( in_array( 'hide_time_remaining', $campaign_hide_time_remaining ) ) {
1209 return false; // hide
1210 }
1211
1212 return $current_value;
1213
1214 }
1215
1216 endif;
1217
1218
1219
1220 // //////////////////////////////
1221 // NOTICES
1222 // //////////////////////////////
1223 if ( ! function_exists( 'charitable_template_notices' ) ) :
1224
1225 /**
1226 * Render any notices.
1227 *
1228 * @since 1.4.0
1229 *
1230 * @param array $notices Optional. Notices to be rendered.
1231 * @return void
1232 */
1233 function charitable_template_notices( $notices = array() ) {
1234 if ( empty( $notices ) ) {
1235 $notices = charitable_get_notices()->get_notices();
1236 }
1237
1238 charitable_template_from_session(
1239 'form-fields/notices.php',
1240 array(
1241 'notices' => $notices,
1242 ),
1243 'notices'
1244 );
1245 }
1246
1247 endif;
1248