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

185 lines 4.9 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 /**
55 * The order attribute is interpolated into the ORDER BY clause of the
56 * donor query, so restrict it to a valid sort direction before it is
57 * passed any further.
58 *
59 * @since 1.8.12.2
60 */
61 $args['order'] = charitable_validate_sort_direction( $args['order'] );
62
63 if ( '' !== $args['campaign_categories'] ) {
64 $campaign_categories = str_replace( ', ', ',', $args['campaign_categories'] );
65 $campaign_categories = explode( ',', $args['campaign_categories'] );
66 $cat_args = [
67 'post_type' => 'campaign',
68 'posts_per_page' => -1,
69 'fields' => 'ids',
70 'tax_query' => [
71 [
72 'taxonomy' => 'campaign_category',
73 'field' => 'slug',
74 'terms' => $campaign_categories,
75 ],
76 ],
77 ];
78 $query = new WP_Query( $cat_args );
79 if ( ! empty( $query->posts ) ) {
80 $args['campaign'] = $query->posts;
81 }
82 }
83 $args['donors'] = self::get_donors( $args );
84
85 /**
86 * Replace the default template with your own.
87 *
88 * If you replace the template with your own, it needs to be an instance of Charitable_Template.
89 *
90 * @since 1.5.0
91 *
92 * @param false|Charitable_Template The template. If false (the default), we will use our own template.
93 * @param array $args All the parsed arguments.
94 * @return false|Charitable_Template
95 */
96 $template = apply_filters( 'charitable_donors_shortcode_template', false, $args );
97
98 /* Fall back to default Charitable_Template if no template returned or if template was not object of 'Charitable_Template' class. */
99 if ( ! is_object( $template ) || ! is_a( $template, 'Charitable_Template' ) ) {
100 $template = new Charitable_Template( 'donor-loop.php', false );
101 }
102
103 if ( ! $template->template_file_exists() ) {
104 return false;
105 }
106
107 /**
108 * Modify the view arguments that are passed to the donors template.
109 *
110 * @since 1.5.0
111 *
112 * @param array $view_args The arguments to pass.
113 * @param array $args All the parsed arguments.
114 * @return array
115 */
116 $view_args = apply_filters(
117 'charitable_donors_shortcode_view_args',
118 charitable_array_subset(
119 $args,
120 array(
121 'donors',
122 'number',
123 'orderby',
124 'order',
125 'campaign',
126 'orientation',
127 'distinct_donors',
128 'show_name',
129 'show_location',
130 'show_amount',
131 'show_avatar',
132 'hide_if_no_donors',
133 'builder_preview'
134 )
135 ),
136 $args
137 );
138
139 $template->set_view_args( $view_args );
140
141 ob_start();
142
143 $template->render();
144
145 /**
146 * Customize the output of the shortcode.
147 *
148 * @since 1.5.0
149 *
150 * @param string $content The content to be displayed.
151 * @param array $args All the parsed arguments.
152 * @return string
153 */
154 return apply_filters( 'charitable_donors_shortcode', ob_get_clean(), $args );
155 }
156
157 /**
158 * Return donors to display in the donors shortcode.
159 *
160 * @since 1.5.0
161 *
162 * @param array $args The query arguments to be used to retrieve donors.
163 * @return Charitable_Donor_Query
164 */
165 public static function get_donors( $args ) {
166 /**
167 * Filter the arguments passed to Charitable_Donor_Query.
168 *
169 * @since 1.5.0
170 *
171 * @param array $query_args The arguments to be passed to Charitable_Donor_Query::__construct.
172 * @param array $args All the parsed arguments.
173 * @return array
174 */
175 $query_args = apply_filters( 'charitable_donors_shortcode_donor_query_args',
176 charitable_array_subset( $args, array( 'number', 'orderby', 'order', 'campaign', 'distinct_donors' ) ),
177 $args
178 );
179
180 return new Charitable_Donor_Query( $query_args );
181 }
182 }
183
184 endif;
185