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/queries/class-charitable-donations-query.php +52 -22 1.6.8 → 1.8.13 View file →
@@ -2,13 +2,13 @@
2 2 /**
3 3 * A helper class to retrieve Donations.
4 4 *
5 5 * @package Charitable/Classes/Charitable_Donations_Query
6 - * @author Eric Daams
7 - * @copyright Copyright (c) 2019, 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.4.0
10 - * @version 1.6.8
10 + * @version 1.6.54
11 11 */
12 12
13 13 // Exit if accessed directly.
14 14 if ( ! defined( 'ABSPATH' ) ) {
@@ -27,8 +27,9 @@
27 27 /**
28 28 * Create class object.
29 29 *
30 30 * @since 1.4.0
31 + * @since 1.7.0.9
31 32 *
32 33 * @param array $args Arguments used in query.
33 34 */
34 35 public function __construct( $args = array() ) {
@@ -48,8 +49,10 @@
48 49 // Only get donations for a specific campaign.
49 50 'campaign' => 0,
50 51 // Only get donations by a specific donor.
51 52 'donor_id' => 0,
53 + // Only get donations by a specific donor email.
54 + 'donor_email' => false,
52 55 // Only get donations by a specific user.
53 56 'user_id' => 0,
54 57 // Donation plan is essentially post_parent.
55 58 'donation_plan' => 0,
@@ -56,8 +59,10 @@
56 59 // Filter donations by date.
57 60 'date_query' => array(),
58 61 // Filter donations by meta.
59 62 'meta_query' => array(),
63 + // Return only the IDs passed.
64 + 'donation_ids' => array(),
60 65 );
61 66
62 67 $this->args = wp_parse_args( $args, $defaults );
63 68
@@ -92,9 +97,8 @@
92 97 * When the currency uses commas for decimals and periods for thousands,
93 98 * the amount returned from the database needs to be sanitized.
94 99 */
95 100 if ( $currency_helper->is_comma_decimal() ) {
96 -
97 101 foreach ( $records as $i => $row ) {
98 102 $records[ $i ]->amount = $currency_helper->sanitize_database_amount( $row->amount );
99 103 }
100 104 }
@@ -102,8 +106,26 @@
102 106 return $records;
103 107 }
104 108
105 109 /**
110 + * Run the IDs query, returning the results.
111 + *
112 + * @global WPDB $wpdb
113 + *
114 + * @since 1.6.54
115 + *
116 + * @return array
117 + */
118 + public function run_query_ids() {
119 + global $wpdb;
120 +
121 + $sql = "SELECT {$this->fields()} {$this->from()} {$this->join()} {$this->where()} {$this->groupby()} {$this->orderby()} {$this->order()} {$this->limit()} {$this->offset()};";
122 +
123 + // phpcs:ignore PluginCheck.Security.DirectDB.UnescapedDBParameter -- get_prepared_sql() internally calls $wpdb->prepare() which properly escapes the SQL.
124 + return $wpdb->get_col( $this->get_prepared_sql( $sql ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.NotPrepared,PluginCheck.Security.DirectDB.UnescapedDBParameter
125 + }
126 +
127 + /**
106 128 * Set up fields query argument.
107 129 *
108 130 * @since 1.4.0
109 131 *
@@ -147,8 +169,9 @@
147 169 /**
148 170 * Remove any hooks that have been attached by the class to prevent contaminating other queries.
149 171 *
150 172 * @since 1.4.0
173 + * @version 1.7.0.9
151 174 *
152 175 * @return void
153 176 */
154 177 public function unhook_callbacks() {
@@ -154,17 +177,20 @@
154 177 public function unhook_callbacks() {
155 178 remove_action( 'charitable_pre_query', array( $this, 'setup_fields' ) );
156 179 remove_filter( 'charitable_query_fields', array( $this, 'donation_fields' ), 4 );
157 180 remove_filter( 'charitable_query_fields', array( $this, 'donation_calc_fields' ), 5 );
158 - remove_filter( 'charitable_query_join', array( $this, 'join_campaign_donations_table_on_donation' ), 5 );
159 - remove_filter( 'charitable_query_join', array( $this, 'join_meta' ), 6 );
160 - remove_filter( 'charitable_query_where', array( $this, 'where_donation_plan_is_in' ), 4 );
161 - remove_filter( 'charitable_query_where', array( $this, 'where_status_is_in' ), 5 );
162 - remove_filter( 'charitable_query_where', array( $this, 'where_campaign_is_in' ), 6 );
163 - remove_filter( 'charitable_query_where', array( $this, 'where_donor_id_is_in' ), 7 );
164 - remove_filter( 'charitable_query_where', array( $this, 'where_user_id_is_in' ), 8 );
165 - remove_filter( 'charitable_query_where', array( $this, 'where_date' ), 9 );
166 - remove_filter( 'charitable_query_where', array( $this, 'where_meta' ), 10 );
181 + remove_filter( 'charitable_query_join', array( $this, 'join_campaign_donations_table_on_donation' ), 4 );
182 + remove_filter( 'charitable_query_join', array( $this, 'join_campaign_donors_table_on_donation' ), 6 );
183 + remove_filter( 'charitable_query_join', array( $this, 'join_meta' ), 7 );
184 + remove_filter( 'charitable_query_where', array( $this, 'where_donation_plan_is_in' ), 8 );
185 + remove_filter( 'charitable_query_where', array( $this, 'where_status_is_in' ), 9 );
186 + remove_filter( 'charitable_query_where', array( $this, 'where_campaign_is_in' ), 10 );
187 + remove_filter( 'charitable_query_where', array( $this, 'where_donor_id_is_in' ), 11 );
188 + remove_filter( 'charitable_query_where', array( $this, 'where_donor_email_is_in' ), 12 );
189 + remove_filter( 'charitable_query_where', array( $this, 'where_user_id_is_in' ), 13 );
190 + remove_filter( 'charitable_query_where', array( $this, 'where_donation_id_is_in' ), 14 );
191 + remove_filter( 'charitable_query_where', array( $this, 'where_date' ), 15 );
192 + remove_filter( 'charitable_query_where', array( $this, 'where_meta' ), 16 );
167 193 remove_action( 'charitable_pre_query', array( $this, 'setup_orderby' ) );
168 194 remove_filter( 'charitable_query_orderby', array( $this, 'orderby_date' ) );
169 195 remove_filter( 'charitable_query_orderby', array( $this, 'orderby_donation_amount' ) );
170 196 remove_filter( 'charitable_query_groupby', array( $this, 'groupby_donation_id' ) );
@@ -174,8 +200,9 @@
174 200 /**
175 201 * Set up callbacks for WP_Query filters.
176 202 *
177 203 * @since 1.4.0
204 + * @version 1.7.0.9
178 205 *
179 206 * @return void
180 207 */
181 208 protected function prepare_query() {
@@ -180,17 +207,20 @@
180 207 */
181 208 protected function prepare_query() {
182 209 add_action( 'charitable_pre_query', array( $this, 'setup_fields' ) );
183 210 add_action( 'charitable_pre_query', array( $this, 'setup_orderby' ) );
184 - add_filter( 'charitable_query_join', array( $this, 'join_campaign_donations_table_on_donation' ), 5 );
185 - add_filter( 'charitable_query_join', array( $this, 'join_meta' ), 6 );
186 - add_filter( 'charitable_query_where', array( $this, 'where_donation_plan_is_in' ), 4 );
187 - add_filter( 'charitable_query_where', array( $this, 'where_status_is_in' ), 5 );
188 - add_filter( 'charitable_query_where', array( $this, 'where_campaign_is_in' ), 6 );
189 - add_filter( 'charitable_query_where', array( $this, 'where_donor_id_is_in' ), 7 );
190 - add_filter( 'charitable_query_where', array( $this, 'where_user_id_is_in' ), 8 );
191 - add_filter( 'charitable_query_where', array( $this, 'where_date' ), 9 );
192 - add_filter( 'charitable_query_where', array( $this, 'where_meta' ), 10 );
211 + add_filter( 'charitable_query_join', array( $this, 'join_campaign_donations_table_on_donation' ), 4 );
212 + add_filter( 'charitable_query_join', array( $this, 'join_campaign_donors_table_on_donation' ), 6 );
213 + add_filter( 'charitable_query_join', array( $this, 'join_meta' ), 7 );
214 + add_filter( 'charitable_query_where', array( $this, 'where_donation_plan_is_in' ), 8 );
215 + add_filter( 'charitable_query_where', array( $this, 'where_status_is_in' ), 9 );
216 + add_filter( 'charitable_query_where', array( $this, 'where_campaign_is_in' ), 10 );
217 + add_filter( 'charitable_query_where', array( $this, 'where_donor_id_is_in' ), 11 );
218 + add_filter( 'charitable_query_where', array( $this, 'where_donor_email_is_in' ), 12 );
219 + add_filter( 'charitable_query_where', array( $this, 'where_user_id_is_in' ), 13 );
220 + add_filter( 'charitable_query_where', array( $this, 'where_donation_id_is_in' ), 14 );
221 + add_filter( 'charitable_query_where', array( $this, 'where_date' ), 15 );
222 + add_filter( 'charitable_query_where', array( $this, 'where_meta' ), 16 );
193 223 add_filter( 'charitable_query_groupby', array( $this, 'groupby_donation_id' ) );
194 224 add_action( 'charitable_post_query', array( $this, 'unhook_callbacks' ) );
195 225 }
196 226 }