PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.11.3
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.11.3
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 / shortcodes / class-charitable-donors-shortcode.php

class-charitable-donors-shortcode.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.11.3, at includes/shortcodes/class-charitable-donors-shortcode.php

176 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Donors shortcode class.
4 *
5 * @package Charitable/Shortcodes/Donors
6 * @author David Bisset
7 * @copyright Copyright (c) 2023, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.5.0
10 * @version 1.5.7
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 if ( ! class_exists( 'Charitable_Donors_Shortcode' ) ) :
19
20 /**
21 * Charitable_Donors_Shortcode class.
22 *
23 * @since 1.5.0
24 */
25 class Charitable_Donors_Shortcode {
26
27 /**
28 * Display the shortcode output. This is the callback method for the donors shortcode.
29 *
30 * @since 1.5.0
31 *
32 * @param array $atts The user-defined shortcode attributes.
33 * @return string
34 */
35 public static function display( $atts ) {
36 $default = array(
37 'number' => 10,
38 'orderby' => 'date',
39 'order' => 'DESC',
40 'campaign' => 0,
41 'distinct_donors' => 0,
42 'orientation' => 'horizontal',
43 'show_name' => 1,
44 'show_location' => 0,
45 'show_amount' => 1,
46 'show_avatar' => 1,
47 'hide_if_no_donors' => 0,
48 'campaign_categories' => '',
49 'builder_preview' => false, // added in 1.8.0
50 );
51
52 $args = shortcode_atts( $default, $atts, 'charitable_donors' );
53
54 if ( '' !== $args['campaign_categories'] ) {
55 $campaign_categories = str_replace( ', ', ',', $args['campaign_categories'] );
56 $campaign_categories = explode( ',', $args['campaign_categories'] );
57 $cat_args = [
58 'post_type' => 'campaign',
59 'posts_per_page' => -1,
60 'fields' => 'ids',
61 'tax_query' => [
62 [
63 'taxonomy' => 'campaign_category',
64 'field' => 'slug',
65 'terms' => $campaign_categories,
66 ],
67 ],
68 ];
69 $query = new WP_Query( $cat_args );
70 if ( ! empty( $query->posts ) ) {
71 $args['campaign'] = $query->posts;
72 }
73 }
74 $args['donors'] = self::get_donors( $args );
75
76 /**
77 * Replace the default template with your own.
78 *
79 * If you replace the template with your own, it needs to be an instance of Charitable_Template.
80 *
81 * @since 1.5.0
82 *
83 * @param false|Charitable_Template The template. If false (the default), we will use our own template.
84 * @param array $args All the parsed arguments.
85 * @return false|Charitable_Template
86 */
87 $template = apply_filters( 'charitable_donors_shortcode_template', false, $args );
88
89 /* Fall back to default Charitable_Template if no template returned or if template was not object of 'Charitable_Template' class. */
90 if ( ! is_object( $template ) || ! is_a( $template, 'Charitable_Template' ) ) {
91 $template = new Charitable_Template( 'donor-loop.php', false );
92 }
93
94 if ( ! $template->template_file_exists() ) {
95 return false;
96 }
97
98 /**
99 * Modify the view arguments that are passed to the donors template.
100 *
101 * @since 1.5.0
102 *
103 * @param array $view_args The arguments to pass.
104 * @param array $args All the parsed arguments.
105 * @return array
106 */
107 $view_args = apply_filters(
108 'charitable_donors_shortcode_view_args',
109 charitable_array_subset(
110 $args,
111 array(
112 'donors',
113 'number',
114 'orderby',
115 'order',
116 'campaign',
117 'orientation',
118 'distinct_donors',
119 'show_name',
120 'show_location',
121 'show_amount',
122 'show_avatar',
123 'hide_if_no_donors',
124 'builder_preview'
125 )
126 ),
127 $args
128 );
129
130 $template->set_view_args( $view_args );
131
132 ob_start();
133
134 $template->render();
135
136 /**
137 * Customize the output of the shortcode.
138 *
139 * @since 1.5.0
140 *
141 * @param string $content The content to be displayed.
142 * @param array $args All the parsed arguments.
143 * @return string
144 */
145 return apply_filters( 'charitable_donors_shortcode', ob_get_clean(), $args );
146 }
147
148 /**
149 * Return donors to display in the donors shortcode.
150 *
151 * @since 1.5.0
152 *
153 * @param array $args The query arguments to be used to retrieve donors.
154 * @return Charitable_Donor_Query
155 */
156 public static function get_donors( $args ) {
157 /**
158 * Filter the arguments passed to Charitable_Donor_Query.
159 *
160 * @since 1.5.0
161 *
162 * @param array $query_args The arguments to be passed to Charitable_Donor_Query::__construct.
163 * @param array $args All the parsed arguments.
164 * @return array
165 */
166 $query_args = apply_filters( 'charitable_donors_shortcode_donor_query_args',
167 charitable_array_subset( $args, array( 'number', 'orderby', 'order', 'campaign', 'distinct_donors' ) ),
168 $args
169 );
170
171 return new Charitable_Donor_Query( $query_args );
172 }
173 }
174
175 endif;
176