PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
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
← All changes | includes/shortcodes/class-charitable-donors-shortcode.php +81 -39 1.6.7 → 1.8.13 View file →
@@ -2,10 +2,10 @@
2 2 /**
3 3 * Donors shortcode class.
4 4 *
5 5 * @package Charitable/Shortcodes/Donors
6 - * @author Eric Daams
7 - * @copyright Copyright (c) 2018, Studio 164a
6 + * @author David Bisset
7 + * @copyright Copyright (c) 2023, WP Charitable LLC
8 8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 9 * @since 1.5.0
10 10 * @version 1.5.7
11 11 */
@@ -10,9 +10,11 @@
10 10 * @version 1.5.7
11 11 */
12 12
13 13 // Exit if accessed directly.
14 -if ( ! defined( 'ABSPATH' ) ) { exit; }
14 +if ( ! defined( 'ABSPATH' ) ) {
15 + exit;
16 +}
15 17
16 18 if ( ! class_exists( 'Charitable_Donors_Shortcode' ) ) :
17 19
18 20 /**
@@ -31,22 +33,54 @@
31 33 * @return string
32 34 */
33 35 public static function display( $atts ) {
34 36 $default = array(
35 - 'number' => 10,
36 - 'orderby' => 'date',
37 - 'order' => 'DESC',
38 - 'campaign' => 0,
37 + 'number' => 10,
38 + 'orderby' => 'date',
39 + 'order' => 'DESC',
40 + 'campaign' => 0,
39 41 'distinct_donors' => 0,
40 - 'orientation' => 'horizontal',
41 - 'show_name' => 1,
42 - 'show_location' => 0,
43 - 'show_amount' => 1,
44 - 'show_avatar' => 1,
45 - 'hide_if_no_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
46 50 );
47 51
48 - $args = shortcode_atts( $default, $atts, 'charitable_donors' );
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 + }
49 83 $args['donors'] = self::get_donors( $args );
50 84
51 85 /**
52 86 * Replace the default template with your own.
@@ -52,14 +86,14 @@
52 86 * Replace the default template with your own.
53 87 *
54 88 * If you replace the template with your own, it needs to be an instance of Charitable_Template.
55 89 *
56 - * @since 1.5.0
90 + * @since 1.5.0
57 91 *
58 - * @param false|Charitable_Template The template. If false (the default), we will use our own template.
59 - * @param array $args All the parsed arguments.
60 - * @return false|Charitable_Template
61 - */
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 + */
62 96 $template = apply_filters( 'charitable_donors_shortcode_template', false, $args );
63 97
64 98 /* Fall back to default Charitable_Template if no template returned or if template was not object of 'Charitable_Template' class. */
65 99 if ( ! is_object( $template ) || ! is_a( $template, 'Charitable_Template' ) ) {
@@ -76,24 +110,32 @@
76 110 * @since 1.5.0
77 111 *
78 112 * @param array $view_args The arguments to pass.
79 113 * @param array $args All the parsed arguments.
80 - * @return array
81 - */
82 - $view_args = apply_filters( 'charitable_donors_shortcode_view_args', charitable_array_subset( $args, array(
83 - 'donors',
84 - 'number',
85 - 'orderby',
86 - 'order',
87 - 'campaign',
88 - 'orientation',
89 - 'distinct_donors',
90 - 'show_name',
91 - 'show_location',
92 - 'show_amount',
93 - 'show_avatar',
94 - 'hide_if_no_donors',
95 - ) ), $args );
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 + );
96 138
97 139 $template->set_view_args( $view_args );
98 140
99 141 ob_start();
@@ -106,10 +148,10 @@
106 148 * @since 1.5.0
107 149 *
108 150 * @param string $content The content to be displayed.
109 151 * @param array $args All the parsed arguments.
110 - * @return string
111 - */
152 + * @return string
153 + */
112 154 return apply_filters( 'charitable_donors_shortcode', ob_get_clean(), $args );
113 155 }
114 156
115 157 /**
@@ -127,10 +169,10 @@
127 169 * @since 1.5.0
128 170 *
129 171 * @param array $query_args The arguments to be passed to Charitable_Donor_Query::__construct.
130 172 * @param array $args All the parsed arguments.
131 - * @return array
132 - */
173 + * @return array
174 + */
133 175 $query_args = apply_filters( 'charitable_donors_shortcode_donor_query_args',
134 176 charitable_array_subset( $args, array( 'number', 'orderby', 'order', 'campaign', 'distinct_donors' ) ),
135 177 $args
136 178 );