PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 4.16.6.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.6.1
4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 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 10 months ago backward-compatibility.php 10 months ago class-give-donor-stats.php 6 years ago class-give-donor-wall.php 8 months ago class-give-donors-query.php 6 months ago frontend-donor-functions.php 3 years ago
class-give-donor-wall.php
675 lines
1 <?php
2 /**
3 * Donor Wall
4 *
5 * @package Give
6 * @subpackage Classes/Give_Donor_Wall
7 * @copyright Copyright (c) 2020, GiveWP
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 // Exit if accessed directly.
13 use Give\Donations\ValueObjects\DonationMetaKeys;
14
15 if (!defined('ABSPATH')) {
16 exit;
17 }
18
19
20 /**
21 * Give_Donor_Wall Class
22 *
23 * This class handles donors.
24 *
25 * @since 2.2.0
26 */
27 class Give_Donor_Wall {
28
29 /**
30 * Instance.
31 *
32 * @since 2.2.0
33 * @access private
34 * @var Give_Donor_Wall
35 */
36 private static $instance;
37
38 /**
39 * Singleton pattern.
40 *
41 * @since 2.2.0
42 * @access private
43 */
44 private function __construct() {
45 }
46
47
48 /**
49 * Get instance.
50 *
51 * @since 2.2.0
52 * @access public
53 * @return Give_Donor_Wall
54 */
55 public static function get_instance() {
56 if ( null === static::$instance ) {
57 self::$instance = new static();
58
59 self::$instance->setup_actions();
60 }
61
62 return self::$instance;
63 }
64
65 /**
66 * Setup the default hooks and actions
67 *
68 * @since 2.2.0
69 *
70 * @return void
71 */
72 public function setup_actions() {
73
74 add_shortcode( 'give_donor_wall', [ $this, 'render_shortcode' ] );
75
76 add_action( 'wp_ajax_give_get_donor_comments', [ $this, 'ajax_handler' ] );
77 add_action( 'wp_ajax_nopriv_give_get_donor_comments', [ $this, 'ajax_handler' ] );
78
79 }
80
81
82 /**
83 * Displays donors in a grid layout.
84 *
85 * @since 4.13.2 add strip_shortcodes to the html output
86 * @since 4.3.1 remove redundant _give_redirect_form_id() function.
87 * @since 3.7.0 Sanitize attributes
88 * @since 2.27.0 Moved AJAX nonce verification to ajax_handler method.
89 * @since 2.2.0
90 *
91 * @param array $atts {
92 * Optional. Attributes of the donor wall shortcode.
93 *
94 * @type int $donors_per_page Number of donors per page. Default '20'.
95 * @type int $form_id The donation form to filter donors by. Default is all forms (no filter).
96 * @type bool $paged Whether to paginate donors. Default 'true'.
97 * @type string $ids A comma-separated list of donor IDs to display. Default empty.
98 * @type string $columns Maximum columns to display. Default 'best-fit'.
99 * Accepts 'best-fit', '1', '2', '3', '4'.
100 * @type bool $show_avatar Whether to display the donor's gravatar image if available. Default 'true'.
101 * @type bool $show_name Whether to display the donor's full name, first and last. Default 'true'.
102 * @type bool $show_company_name Whether to display the donor's company name. Default 'false'.
103 * @type bool $show_total Whether to display the donor's donation amount. Default 'true'.
104 * @type bool $show_comments Whether to display the donor's comment if they left one. Default 'true'.
105 * @type int $comment_length The number of words to display for the comments before a "Read more" field
106 * @type int $only_comments Whether to display the donors only with comment. Default 'false'.
107 * @type bool $show_time Whether to display date of the last donation. Default 'true'.
108 *
109 * @type string $readmore_text Link label for modal in which donor can read full comment.
110 * @type string $loadmore_text Button label which will load more donor comments.
111 * @type int $avatar_size Avatar image size in pixels without the "px". Default "75"
112 * @type string $orderby The order in which you want the donations to appear.
113 * Currently we are using this attribute internally and, it will sort donations by created date.
114 * @type string $order The order in which you want the donors to appear. Accepts "ASC". "DESC".
115 *
116 * }
117 * @return string|bool The markup of the form grid or false.
118 */
119 public function render_shortcode( $atts ) {
120 $atts = give_clean($atts);
121
122 $give_settings = give_get_settings();
123
124 $atts = $this->parse_atts( $atts );
125
126 $donations = $this->get_donation_data( $atts );
127 $html = '';
128
129 if ( $donations ) {
130
131 ob_start();
132
133 foreach ( $donations as $donation ) {
134 $donor = new Give_Donor($donation['_give_payment_donor_id']);
135 // Give/templates/shortcode-donor-wall.php.
136 give_get_template(
137 'shortcode-donor-wall',
138 [
139 $donation,
140 $give_settings,
141 $atts,
142 $donor
143 ]
144 );
145 }
146
147 $html = ob_get_clean();
148
149 // Strip shortcodes to prevent execution of user-supplied shortcode syntax.
150 $html = strip_shortcodes($html);
151
152 // Return only donor html.
153 if (
154 isset( $atts['only_donor_html'] )
155 && wp_doing_ajax()
156 && $atts['only_donor_html']
157 ) {
158 return $html;
159 }
160 }
161
162 $temp_atts = $atts;
163 $temp_atts['paged'] = $atts['paged'] + 1;
164
165 $more_btn_html = sprintf(
166 '<input type="hidden" class="give-donor-wall-shortcode-attrs" data-shortcode="%s" data-nonce="%s">',
167 rawurlencode( http_build_query( $atts ) ),
168 wp_create_nonce( 'givewp-donor-wall-more' )
169 );
170
171 if ( $this->has_donations( $temp_atts ) ) {
172 $more_btn_html .= sprintf(
173 '<button class="give-donor__load_more give-button-with-loader"><span class="give-loading-animation"></span>%1$s</button>',
174 $atts['loadmore_text']
175 );
176 }
177
178 $html = $html
179 ? sprintf(
180 '<div class="give-wrap give-grid-ie-utility"><div class="give-grid give-grid--%1$s">%2$s</div>%3$s</div>',
181 esc_attr( $atts['columns'] ),
182 $html,
183 $more_btn_html
184 )
185 : '';
186
187 return $html;
188 }
189
190 /**
191 * Parse shortcode attributes
192 *
193 * @since 2.30.0
194 * @since 2.2.0
195 * @access public
196 *
197 * @param array $atts Shortcode attributes.
198 *
199 * @return array
200 */
201 public function parse_atts( $atts ) {
202 $atts = shortcode_atts(
203 [
204 'donors_per_page' => 12,
205 'form_id' => 0,
206 'paged' => 1,
207 'ids' => '',
208 'cats' => '',
209 'tags' => '',
210 'columns' => '3',
211 'anonymous' => true,
212 'show_avatar' => true,
213 'show_name' => true,
214 'show_company_name' => false,
215 'show_form' => false,
216 'show_total' => true,
217 'show_comments' => true,
218 'show_tributes' => true,
219 'comment_length' => 140,
220 'only_comments' => false,
221 'readmore_text' => esc_html__( 'Read more', 'give' ),
222 'loadmore_text' => esc_html__( 'Load more', 'give' ),
223 'avatar_size' => 75,
224 'color' => "#219653",
225 'orderby' => 'post_date',
226 'order' => 'DESC',
227 'hide_empty' => true, // Deprecated in 2.3.0
228 'only_donor_html' => false, // Only for internal use.,
229 'show_time' => true,
230 ],
231 $atts,
232 'give_donor_wall'
233 );
234
235 // Validate boolean attributes.
236 $boolean_attributes = [
237 'anonymous',
238 'show_avatar',
239 'show_name',
240 'show_company_name',
241 'show_total',
242 'show_comments',
243 'show_tributes',
244 'hide_empty',
245 'only_comments',
246 'only_donor_html',
247 'show_time'
248 ];
249
250 foreach ( $boolean_attributes as $att ) {
251 // Convert numeric to boolean.
252 // It will prevent condition check against boolean value.
253 if ( is_numeric( $atts[ $att ] ) ) {
254 $atts[ $att ] = (bool) $atts[ $att ];
255 }
256
257 $atts[ $att ] = filter_var( $atts[ $att ], FILTER_VALIDATE_BOOLEAN );
258 }
259
260 // Validate numeric attributes.
261 $numeric_attributes = [
262 'donors_per_page',
263 'paged',
264 'comment_length',
265 'avatar_size',
266 ];
267
268 foreach ( $numeric_attributes as $att ) {
269 // It will prevent condition check against numeric value.
270 $atts[ $att ] = absint( $atts[ $att ] );
271 }
272
273 // Validate comma separated numeric attributes and keep original data format ( comma separated string).
274 if ( ! empty( $atts['ids'] ) ) {
275 $atts['ids'] = implode( ',', $this->split_string($atts['ids'], 'absint') );
276 }
277
278 // Validate Form IDs
279 if ( ! empty( $atts['form_id'] ) ) {
280 $atts['form_id'] = implode( ',', $this->split_string($atts['form_id'], 'absint') );
281 }
282
283 // Donation form categories
284 if ( ! empty( $atts['cats'] ) ) {
285 $atts['cats'] = $this->split_string($atts['cats']);
286 }
287
288 // Donation form tags
289 if ( ! empty( $atts['tags'] ) ) {
290 $atts['tags'] = $this->split_string($atts['tags']);
291 }
292
293 return $atts;
294 }
295
296 /**
297 * Get donors
298 *
299 * @since 2.2.0
300 * @access public
301 *
302 * @param array $donor_query Donor query.
303 *
304 * @return array
305 */
306 public function get_donors( $donor_query ) {
307 $donor_query = new Give_Donors_Query( $donor_query );
308
309 return $donor_query->get_donors();
310 }
311
312
313 /**
314 * This function should return donor comment for ajax request.
315 *
316 * @since 2.27.0 Check nonce for AJAX request to prevent scrapping, see https://github.com/impress-org/givewp/issues/6374.
317 * @since 2.2.0
318 * @access public
319 */
320 public function ajax_handler() {
321 $shortcode_atts = array_map( 'give_clean', wp_parse_args( rawurldecode( $_POST['data'] ) ) ); // @codingStandardsIgnoreLine
322
323 // Get next page donor comments.
324 $shortcode_atts['paged'] = $shortcode_atts['paged'] + 1;
325 $shortcode_atts['only_donor_html'] = true;
326
327 check_ajax_referer( 'givewp-donor-wall-more', 'nonce' );
328
329 $donors_comment_html = $this->render_shortcode( $shortcode_atts );
330
331 // Check if donor comment remaining.
332 $temp_atts = $shortcode_atts;
333 $temp_atts['paged'] = $shortcode_atts['paged'] + 1;
334 $has_donors = $this->has_donations( $temp_atts ) ? 1 : 0;
335
336 // Remove internal shortcode param.
337 unset( $shortcode_atts['only_donor_html'] );
338
339 wp_send_json(
340 [
341 'shortcode' => rawurlencode( http_build_query( $shortcode_atts ) ),
342 'html' => $donors_comment_html,
343 'remaining' => $has_donors,
344 ]
345 );
346 }
347
348 /**
349 * Get query params
350 *
351 * @since 2.24.1
352 * @since 2.3.0
353 *
354 * @param array $atts
355 *
356 * @return array
357 */
358 private function get_query_param( $atts = [] ) {
359 $valid_order = [ 'ASC', 'DESC' ];
360 $valid_orderby = [ 'post_date', 'donation_amount' ];
361
362 $query_atts = [];
363
364 $query_atts['order'] = in_array( $atts['order'], $valid_order ) ? $atts['order'] : 'DESC';
365 $query_atts['orderby'] = in_array( $atts['orderby'], $valid_orderby ) ? $atts['orderby'] : 'post_date';
366 $query_atts['limit'] = absint( $atts['donors_per_page'] );
367 $query_atts['offset'] = absint( $atts['donors_per_page'] * ( $atts['paged'] - 1 ) );
368 $query_atts['form_id'] = implode( '\',\'', array_map( 'absint', explode( ',', $atts['form_id'] ) ) );
369 $query_atts['ids'] = implode( '\',\'', array_map( 'absint', explode( ',', $atts['ids'] ) ) );
370 $query_atts['cats'] = $atts['cats'];
371 $query_atts['tags'] = $atts['tags'];
372 $query_atts['only_comments'] = ( true === $atts['only_comments'] );
373 $query_atts['anonymous'] = ( true === $atts['anonymous'] );
374
375
376
377 return $query_atts;
378 }
379
380 /**
381 * Get donation data.
382 *
383 * @since 2.27.0 Change to read comment from donations meta table
384 * @since 2.3.0
385 *
386 * @param array $atts
387 *
388 * @return array
389 */
390 private function get_donation_data( $atts = [] ) {
391 global $wpdb;
392
393 // Bailout if donation does not exist.
394 if ( ! ( $donation_ids = $this->get_donations( $atts ) ) ) {
395 return [];
396 }
397
398 $donation_ids = ! empty( $donation_ids )
399 ? '\'' . implode( '\',\'', $donation_ids ) . '\''
400 : '';
401
402 // Backward compatibility
403 $donation_id_col = Give()->payment_meta->get_meta_type() . '_id';
404
405 $sql = "SELECT m1.*, p1.post_date as donation_date FROM {$wpdb->donationmeta} as m1
406 INNER JOIN {$wpdb->posts} as p1 ON (m1.{$donation_id_col}=p1.ID)
407 WHERE m1.{$donation_id_col} IN ( {$donation_ids} )
408 ORDER BY FIELD( p1.ID, {$donation_ids} )
409 ";
410
411 $results = (array) $wpdb->get_results( $sql );
412
413 if ( ! empty( $results ) ) {
414 $temp = [];
415
416 /* @var stdClass $result */
417 foreach ( $results as $result ) {
418 $temp[ $result->{$donation_id_col} ][ $result->meta_key ] = maybe_unserialize( $result->meta_value );
419
420 // Set donation date.
421 if ( empty( $temp[ $result->{$donation_id_col} ]['donation_date'] ) ) {
422 $temp[ $result->{$donation_id_col} ]['donation_date'] = $result->donation_date;
423 }
424 }
425
426 if ( ! empty( $temp ) ) {
427 foreach ( $temp as $donation_id => $donation_data ) {
428 $temp[ $donation_id ]['donation_id'] = $donation_id;
429
430 $temp[ $donation_id ]['name_initial'] = give_get_name_initial(
431 [
432 'firstname' => $donation_data['_give_donor_billing_first_name'],
433 'lastname' => $donation_data['_give_donor_billing_last_name'],
434 ]
435 );
436
437 $temp[$donation_id]['donor_comment'] = give_get_payment_meta(
438 $donation_id,
439 DonationMetaKeys::COMMENT
440 );
441 }
442 }
443
444 $results = ! empty( $temp ) ? $temp : [];
445 }
446
447 return $results;
448 }
449
450 /**
451 * Get donation list for specific query
452 *
453 * @since 3.17.2 fix - filter by only_comments attr
454 * @since 2.3.0
455 *
456 * @param array $atts
457 *
458 * @return array
459 */
460 private function get_donations( $atts = [] ) {
461 global $wpdb;
462
463 // Backward compatibility
464 $donation_id_col = Give()->payment_meta->get_meta_type() . '_id';
465
466 $query_params = $this->get_query_param( $atts );
467
468 $sql = "SELECT p1.ID FROM {$wpdb->posts} as p1";
469 $where = " WHERE p1.post_status IN ('publish') AND p1.post_type = 'give_payment'";
470
471 // exclude donation with zero amount from result.
472 $sql .= " INNER JOIN {$wpdb->donationmeta} as m1 ON (p1.ID = m1.{$donation_id_col})";
473 $where .= " AND m1.meta_key='_give_payment_total' AND m1.meta_value>0";
474
475 if ( $query_params['form_id'] ) {
476 $sql .= " INNER JOIN {$wpdb->donationmeta} as m2 ON (p1.ID = m2.{$donation_id_col})";
477 $where .= " AND m2.meta_key='_give_payment_form_id' AND m2.meta_value IN ('{$query_params['form_id']}')";
478 }
479
480 // Get donations only from specific donors.
481 if ( $query_params['ids'] ) {
482 $sql .= " INNER JOIN {$wpdb->donationmeta} as m3 ON (p1.ID = m3.{$donation_id_col})";
483 $where .= " AND m3.meta_key='_give_payment_donor_id' AND m3.meta_value IN ('{$query_params['ids']}')";
484 }
485
486 // exclude donations which does not has donor comment.
487 if ( $query_params['only_comments'] ) {
488 $sql .= " INNER JOIN {$wpdb->donationmeta} as m4 ON (p1.ID = m4.{$donation_id_col})";
489 $where .= " AND m4.meta_key='_give_donation_comment'";
490 }
491
492 // exclude anonymous donation form query based on query parameters.
493 if (
494 ! $query_params['anonymous']
495 || $query_params['only_comments']
496 ) {
497 $where .= " AND p1.ID NOT IN ( SELECT DISTINCT({$donation_id_col}) FROM {$wpdb->donationmeta} WHERE meta_key='_give_anonymous_donation' AND meta_value='1')";
498 }
499
500 // Handle Taxonomy
501 $args = [
502 'post_type' => 'give_forms',
503 'posts_per_page' => -1,
504 'fields' => 'ids',
505 'tax_query' => [],
506 ];
507
508 // Categories
509 if ( is_array($atts['cats'])) {
510 $args['tax_query']['conditions'] = ['relation' => 'OR'];
511
512 foreach ($atts['cats'] as $category) {
513 $args['tax_query']['conditions'][] = [
514 'operator' => 'IN',
515 'taxonomy' => 'give_forms_category',
516 'field' => 'slug',
517 'terms' => $category,
518 ];
519 }
520 }
521
522 // Tags
523 if ( is_array($atts['tags'])) {
524 if (empty($args['tax_query'])) {
525 $args['tax_query']['conditions'] = ['relation' => 'OR'];
526 }
527
528 foreach($atts['tags'] as $tag) {
529 $args['tax_query']['conditions'][] = [
530 'operator' => 'IN',
531 'taxonomy' => 'give_forms_tag',
532 'field' => 'slug',
533 'terms' => $tag,
534 ];
535 }
536 }
537
538 if ( ! empty( $args['tax_query'] ) ) {
539 $query = new WP_Query( $args );
540
541 if ( ! empty($query->posts) ) {
542 $form_ids = implode("','", $query->posts );
543 $sql .= " INNER JOIN {$wpdb->donationmeta} as m4 ON (p1.ID = m4.{$donation_id_col})";
544 $where .= " AND m4.meta_key='_give_payment_form_id' AND m4.meta_value IN ('{$form_ids}')";
545 }
546 }
547
548 // order by query based on parameter.
549 if ( 'donation_amount' === $query_params['orderby'] ) {
550 $order = " ORDER BY m1.meta_value+0 {$query_params['order']}";
551 } else {
552 $order = " ORDER BY p1.{$query_params['orderby']} {$query_params['order']}, p1.ID {$query_params['order']}";
553 }
554
555 $limit = " LIMIT {$query_params['limit']}";
556 $offset = " OFFSET {$query_params['offset']}";
557
558 $sql .= $where . $order . $limit . $offset;
559
560 return $wpdb->get_col( $sql );
561 }
562
563 /**
564 * Get donor comments
565 *
566 * @since 2.3.0
567 *
568 * @param array $donations_data
569 *
570 * @return array
571 */
572 private function get_donor_comments( $donations_data = [] ) {
573 global $wpdb;
574 $comments = [];
575
576 // Bailout.
577 if ( empty( $donations_data ) ) {
578 return $comments;
579 }
580
581 // Backward compatibility.
582 if (
583 ! give_has_upgrade_completed( 'v230_move_donor_note' )
584 || ! give_has_upgrade_completed( 'v230_move_donation_note' )
585 ) {
586 foreach ( $donations_data as $id => $data ) {
587 $comment = give_get_donor_donation_comment( $id, $data['_give_payment_donor_id'] );
588 $comments[ $id ] = ! empty( $comment ) ? $comment->comment_content : '';
589 }
590
591 return $comments;
592 }
593
594 $sql = "SELECT c1.comment_parent as donation_id, c1.comment_content as comment FROM {$wpdb->give_comments} as c1";
595 $sql .= " INNER JOIN {$wpdb->give_commentmeta} as cm1 ON (c1.comment_ID=cm1.give_comment_id)";
596 $where = [];
597
598 foreach ( $donations_data as $id => $data ) {
599 // Do not fetch comment for anonymous donation.
600 if ( ! empty( $data['_give_anonymous_donation'] ) ) {
601 continue;
602 }
603
604 $where[] = "(c1.comment_parent={$id} AND cm1.meta_key='_give_donor_id' AND cm1.meta_value={$data['_give_payment_donor_id']})";
605 }
606
607 $where = ' WHERE ' . implode( ' OR ', $where );
608 $where .= " AND c1.comment_type='donor_donation'";
609
610 $sql = $sql . $where;
611
612 $comments = (array) $wpdb->get_results( $sql );
613
614 if ( ! empty( $comments ) ) {
615 $comments = array_combine(
616 wp_list_pluck( $comments, 'donation_id' ),
617 wp_list_pluck( $comments, 'comment' )
618 );
619 }
620
621 return $comments;
622 }
623
624 /**
625 * Check if donation exist or not for specific query
626 *
627 * @since 2.3.0
628 *
629 * @param array $atts
630 *
631 * @return bool
632 */
633 private function has_donations( $atts = [] ) {
634 return (bool) $this->get_donations( $atts );
635 }
636
637 /**
638 * @since 2.20.0
639 *
640 * @param string $string
641 * @param null|callable $filter
642 * @param string $separator
643 *
644 * @return array
645 */
646 private function split_string($string, $filter = null, $separator = ',') {
647 if ( false === strpos( $string, $separator ) ) {
648 $string = trim( $string );
649
650 if (is_callable($filter)) {
651 $string = $filter($string);
652 }
653
654 return [$string];
655 }
656
657 return array_filter(
658 array_map(
659 static function( $value ) use ($filter) {
660 $value = trim( $value );
661
662 if (is_callable($filter)) {
663 return $filter($value);
664 }
665 return $value;
666 },
667 explode( $separator, $string )
668 )
669 );
670 }
671 }
672
673 // Initialize shortcode.
674 Give_Donor_Wall::get_instance();
675