PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.2.1
GiveWP – Donation Plugin and Fundraising Platform v2.2.1
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 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / donors / class-give-donor-wall.php
give / includes / donors Last commit date
actions.php 7 years ago backward-compatibility.php 8 years ago class-give-donor-stats.php 7 years ago class-give-donor-wall.php 7 years ago class-give-donors-query.php 7 years ago frontend-donor-functions.php 7 years ago
class-give-donor-wall.php
351 lines
1 <?php
2 /**
3 * Donors Gravatars
4 *
5 * @package Give
6 * @subpackage Classes/Give_Donors_Gravatars
7 * @copyright Copyright (c) 2016, WordImpress
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17
18 /**
19 * Give_Donor_Wall Class
20 *
21 * This class handles donors.
22 *
23 * @since 2.2.0
24 */
25 class Give_Donor_Wall {
26 /**
27 * Instance.
28 *
29 * @since 2.2.0
30 * @access private
31 * @var Give_Donor_Wall
32 */
33 static private $instance;
34
35 /**
36 * Singleton pattern.
37 *
38 * @since 2.2.0
39 * @access private
40 */
41 private function __construct() {
42 }
43
44
45 /**
46 * Get instance.
47 *
48 * @since 2.2.0
49 * @access public
50 * @return Give_Donor_Wall
51 */
52 public static function get_instance() {
53 if ( null === static::$instance ) {
54 self::$instance = new static();
55
56 self::$instance->setup_actions();
57 }
58
59 return self::$instance;
60 }
61
62 /**
63 * Setup the default hooks and actions
64 *
65 * @since 2.2.0
66 *
67 * @return void
68 */
69 public function setup_actions() {
70
71 add_shortcode( 'give_donor_wall', array( $this, 'render_shortcode' ) );
72
73 add_action( 'wp_ajax_give_get_donor_comments', array( $this, 'ajax_handler' ) );
74 add_action( 'wp_ajax_nopriv_give_get_donor_comments', array( $this, 'ajax_handler' ) );
75
76 }
77
78
79 /**
80 * Displays donors in a grid layout.
81 *
82 * @since 2.2.0
83 *
84 * @param array $atts {
85 * Optional. Attributes of the donor wall shortcode.
86 *
87 * @type int $donors_per_page Number of donors per page. Default '20'.
88 * @type int $form_id The donation form to filter donors by. Default is all forms (no filter).
89 * @type bool $paged Whether to paginate donors. Default 'true'.
90 * @type string $ids A comma-separated list of donor IDs to display. Default empty.
91 * @type string $columns Maximum columns to display. Default 'best-fit'.
92 * Accepts 'best-fit', '1', '2', '3', '4'.
93 * @type bool $show_avatar Whether to display the donor's gravatar image if available. Default 'true'.
94 * @type bool $show_name Whether to display the donor's full name, first and last. Default 'true'.
95 * @type bool $show_total Whether to display the donor's donation amount. Default 'true'.
96 * @type bool $show_time Whether to display date of the last donation. Default 'true'.
97 * @type bool $show_comments Whether to display the donor's comment if they left one. Default 'true'.
98 * @type int $comment_length The number of words to display for the comments before a "Read more" field
99 * displays. Default '20'.
100 * @type string $readmore_text Link label for modal in which donor can read full comment.
101 * @type string $loadmore_text Button label which will load more donor comments.
102 * @type int $avatar_size Avatar image size in pixels without the "px". Default "60"
103 * @type string $orderby The order in which you want the donors to appear. Accepts "donation_amount", "donation_count",
104 * if donor donated same value for orderby attribute then they will short by created date (fallback)
105 * @type string $order The order in which you want the donors to appear. Accepts "ASC". "DESC".
106 *
107 * }
108 * @return string|bool The markup of the form grid or false.
109 */
110 public function render_shortcode( $atts ) {
111
112 $give_settings = give_get_settings();
113
114 $atts = $this->parse_atts( $atts );
115 $donor_query = $this->get_donor_query_atts( $atts );
116 $donors = $this->get_donors( $donor_query );
117 $html = '';
118
119 if ( $donors ) {
120
121 ob_start();
122
123 foreach ( $donors as $donor ) {
124 // Give/templates/shortcode-donor-wall.php.
125 give_get_template( 'shortcode-donor-wall', array( $donor, $give_settings, $atts ) );
126 }
127
128 $html = ob_get_clean();
129
130 // Return only donor html.
131 if (
132 isset( $atts['only_donor_html'] )
133 && wp_doing_ajax()
134 && $atts['only_donor_html']
135 ) {
136 return $html;
137 }
138 }
139
140 $next_donor_query = $donor_query;
141 $next_donor_query['paged'] = $next_donor_query['paged'] + 1;
142 $next_donor_query['fields'] = 'id';
143
144 $more_btn_html = '';
145 if ( $this->get_donors( $next_donor_query ) ) {
146 $more_btn_html = sprintf(
147 '<button class="give-donor__load_more give-button-with-loader" data-shortcode="%1$s"><span class="give-loading-animation"></span>%2$s</button>',
148 rawurlencode( http_build_query( $atts ) ),
149 $atts['loadmore_text']
150 );
151 }
152
153 $html = $html
154 ? sprintf(
155 '<div class="give-wrap give-grid-ie-utility"><div class="give-grid give-grid--%1$s">%2$s</div>%3$s</div>',
156 esc_attr( $atts['columns'] ),
157 $html,
158 $more_btn_html
159 )
160 : '';
161
162 return $html;
163 }
164
165 /**
166 * Parse shortcode attributes
167 *
168 * @since 2.2.0
169 * @access public
170 *
171 * @param array $atts Shortcode attributes.
172 *
173 * @return array
174 */
175 public function parse_atts( $atts ) {
176 $atts = shortcode_atts(
177 array(
178 'donors_per_page' => 20,
179 'form_id' => 0,
180 'paged' => 1,
181 'ids' => '',
182 'columns' => 'best-fit',
183 'show_avatar' => true,
184 'show_name' => true,
185 'show_total' => true,
186 'show_time' => true,
187 'show_comments' => true,
188 'comment_length' => 20,
189 'only_comments' => true,
190 'readmore_text' => esc_html__( 'Read More', 'give' ),
191 'loadmore_text' => esc_html__( 'Load More', 'give' ),
192 'avatar_size' => 60,
193 'orderby' => 'donation_count',
194 'order' => 'DESC',
195 'hide_empty' => true,
196 'only_donor_html' => false, // Only for internal use.
197 ), $atts
198 );
199
200 // Validate integer attributes.
201 $atts['donors_per_page'] = absint( $atts['donors_per_page'] );
202
203 // Validate boolean attributes.
204 $boolean_attributes = array(
205 'show_avatar',
206 'show_name',
207 'show_total',
208 'show_time',
209 'show_comments',
210 'show_comments',
211 'hide_empty',
212 'only_comments',
213 'only_donor_html',
214 );
215
216 foreach ( $boolean_attributes as $att ) {
217 // Convert numeric to boolean.
218 // It will prevent condition check against boolean value.
219 if ( is_numeric( $atts[ $att ] ) ) {
220 $atts[ $att ] = (bool) $atts[ $att ];
221 }
222
223 $atts[ $att ] = filter_var( $atts[ $att ], FILTER_VALIDATE_BOOLEAN );
224 }
225
226 return $atts;
227 }
228
229 /**
230 * Get donor query from shortcode attribiutes
231 *
232 * @since 2.2.0
233 * @access public
234 *
235 * @param array $atts Shortcode attributes.
236 *
237 * @return array
238 */
239 public function get_donor_query_atts( $atts ) {
240 // Set default form query args.
241 $donor_args = array(
242 'number' => $atts['donors_per_page'],
243 'paged' => $atts['paged'],
244 'orderby' => $atts['orderby'],
245 'order' => $atts['order'],
246 );
247
248 // Hide donors with zero donation amount.
249 if ( $atts['hide_empty'] ) {
250 $donor_args['donation_amount'] = array(
251 'compare' => '>=',
252 'amount' => 1,
253 );
254 }
255
256 // Show donor who donated to specific form.
257 if ( $atts['form_id'] ) {
258 $donor_args['give_forms'] = $atts['form_id'];
259 }
260
261 // Show donor by id.
262 if ( $atts['ids'] ) {
263 $donor_args['donor'] = $atts['ids'];
264 }
265
266 // Replace donation with purchase because donor table has that prefix in column name.
267 $donor_args['orderby'] = str_replace(
268 array( 'donation', 'amount' ), array(
269 'purchase',
270 'value',
271 ), $atts['orderby']
272 );
273
274 // Add fallback orderby.
275 $donor_args['orderby'] = array(
276 $donor_args['orderby'] => $donor_args['order'],
277 'date_created' => 'DESC',
278 );
279
280 unset( $donor_args['order'] );
281
282 // Set payment query.
283 // @codingStandardsIgnoreStart
284 if ( true === $atts['only_comments'] ) {
285 $donor_args['meta_query'] = array(
286 array(
287 'key' => '_give_has_comment',
288 'value' => '1',
289 ),
290 );
291 }
292 // @codingStandardsIgnoreEnd
293
294 return $donor_args;
295 }
296
297 /**
298 * Get donors
299 *
300 * @since 2.2.0
301 * @access public
302 *
303 * @param array $donor_query Dorno query.
304 *
305 * @return array
306 */
307 public function get_donors( $donor_query ) {
308 $donor_query = new Give_Donors_Query( $donor_query );
309 $donors = $donor_query->get_donors();
310
311 return $donors;
312 }
313
314
315 /**
316 * Ajax handler
317 *
318 * @since 2.2.0
319 * @access public
320 */
321 public function ajax_handler() {
322 $shortcode_atts = wp_parse_args( give_clean( rawurldecode( $_POST['data'] ) ) ); // @codingStandardsIgnoreLine
323
324 // Get next page donor comments.
325 $shortcode_atts['paged'] = $shortcode_atts['paged'] + 1;
326 $shortcode_atts['only_donor_html'] = true;
327
328 $donors_comment_html = $this->render_shortcode( $shortcode_atts );
329
330 // Check if donor comment remaining.
331 $donor_query = $this->get_donor_query_atts( $shortcode_atts );
332 $donor_query['paged'] = $donor_query['paged'] + 1;
333 $donor_query['fields'] = 'id';
334 $has_donors = $this->get_donors( $donor_query ) ? 1 : 0;
335
336 // Remove internal shortcode param.
337 unset( $shortcode_atts['only_donor_html'] );
338
339 wp_send_json(
340 array(
341 'shortcode' => rawurlencode( http_build_query( $shortcode_atts ) ),
342 'html' => $donors_comment_html,
343 'remaining' => $has_donors,
344 )
345 );
346 }
347 }
348
349 // Initialize shortcode.
350 Give_Donor_Wall::get_instance();
351