PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 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 All 256 releases
← All changes | includes/admin/tools/export/give-export-donations-functions.php +148 -120 2.3.2 → 4.17.0 View file →
@@ -4,45 +4,48 @@
4 4 */
5 5
6 6
7 7 /**
8 - * AJAX
8 + * Return of meta keys for a donation form.
9 9 *
10 10 * @see http://wordpress.stackexchange.com/questions/58834/echo-all-meta-keys-of-a-custom-post-type
11 - *
12 - * @return string
13 11 */
14 12 function give_export_donations_get_custom_fields() {
13 + global $wpdb;
15 14
16 - global $wpdb;
17 - $post_type = 'give_payment';
18 - $responses = array();
15 + if ( ! current_user_can( 'export_give_reports' ) ) {
16 + wp_send_json_error();
17 + }
18 +
19 + $post_type = 'give_payment';
20 + $responses = [];
19 21 $donationmeta_table_key = Give()->payment_meta->get_meta_type() . '_id';
20 22
21 - $form_id = isset( $_POST['form_id'] ) ? intval( $_POST['form_id'] ) : '';
23 + $form_id = isset( $_POST['form_id'] ) ? absint( $_POST['form_id'] ) : '';
22 24
23 25 if ( empty( $form_id ) ) {
24 - return false;
26 + wp_send_json_error();
25 27 }
26 28
27 - $args = array(
28 - 'give_forms' => array( $form_id ),
29 + $args = [
30 + 'give_forms' => [ $form_id ],
29 31 'posts_per_page' => - 1,
30 32 'fields' => 'ids',
31 - );
33 + ];
34 +
32 35 $donation_list = implode( ',', (array) give_get_payments( $args ) );
33 36
34 37 $query_and = sprintf(
35 - "AND $wpdb->posts.ID IN (%s)
36 - AND $wpdb->donationmeta.meta_key != ''
38 + "AND $wpdb->posts.ID IN (%s)
39 + AND $wpdb->donationmeta.meta_key != ''
37 40 AND $wpdb->donationmeta.meta_key NOT RegExp '(^[_0-9].+$)'",
38 41 $donation_list
39 42 );
40 43
41 44 $query = "
42 - SELECT DISTINCT($wpdb->donationmeta.meta_key)
43 - FROM $wpdb->posts
44 - LEFT JOIN $wpdb->donationmeta
45 + SELECT DISTINCT($wpdb->donationmeta.meta_key)
46 + FROM $wpdb->posts
47 + LEFT JOIN $wpdb->donationmeta
45 48 ON $wpdb->posts.ID = {$wpdb->donationmeta}.{$donationmeta_table_key}
46 49 WHERE $wpdb->posts.post_type = '%s'
47 50 " . $query_and;
48 51
@@ -52,65 +55,66 @@
52 55 $responses['standard_fields'] = array_values( $meta_keys );
53 56 }
54 57
55 58 $query_and = sprintf(
56 - "AND $wpdb->posts.ID IN (%s)
57 - AND $wpdb->donationmeta.meta_key != ''
59 + "AND $wpdb->posts.ID IN (%s)
60 + AND $wpdb->donationmeta.meta_key != ''
58 61 AND $wpdb->donationmeta.meta_key NOT RegExp '^[^_]'",
59 62 $donation_list
60 63 );
61 64
62 65 $query = "
63 - SELECT DISTINCT($wpdb->donationmeta.meta_key)
64 - FROM $wpdb->posts
65 - LEFT JOIN $wpdb->donationmeta
66 - ON $wpdb->posts.ID = {$wpdb->donationmeta}.{$donationmeta_table_key}
66 + SELECT DISTINCT($wpdb->donationmeta.meta_key)
67 + FROM $wpdb->posts
68 + LEFT JOIN $wpdb->donationmeta
69 + ON $wpdb->posts.ID = {$wpdb->donationmeta}.{$donationmeta_table_key}
67 70 WHERE $wpdb->posts.post_type = '%s'
68 71 " . $query_and;
69 72
70 - $hidden_meta_keys = $wpdb->get_col( $wpdb->prepare( $query, $post_type ) );
73 + $hidden_meta_keys = $wpdb->get_col( $wpdb->prepare( $query, $post_type ) );
71 74
72 75 /**
73 76 * Filter to modify hidden keys that are going to be ignore when displaying the hidden keys
74 77 *
75 - * @since 2.1
76 - *
77 78 * @param array $ignore_hidden_keys Hidden keys that are going to be ignore
78 - * @param array $form_id Donation form id
79 + * @param array $form_id Donation form id
79 80 *
80 81 * @return array $ignore_hidden_keys Hidden keys that are going to be ignore
82 + * @since 2.1
81 83 */
82 - $ignore_hidden_keys = apply_filters( 'give_export_donations_ignore_hidden_keys', array(
83 - '_give_payment_meta',
84 - '_give_payment_gateway',
85 - '_give_payment_mode',
86 - '_give_payment_form_title',
87 - '_give_payment_form_id',
88 - '_give_payment_price_id',
89 - '_give_payment_user_id',
90 - '_give_payment_user_email',
91 - '_give_payment_user_ip',
92 - '_give_payment_customer_id',
93 - '_give_payment_total',
94 - '_give_completed_date',
95 - '_give_donation_company',
96 - '_give_donor_billing_first_name',
97 - '_give_donor_billing_last_name',
98 - '_give_payment_donor_email',
99 - '_give_payment_donor_id',
100 - '_give_payment_date',
101 - '_give_donor_billing_address1',
102 - '_give_donor_billing_address2',
103 - '_give_donor_billing_city',
104 - '_give_donor_billing_zip',
105 - '_give_donor_billing_state',
106 - '_give_donor_billing_country',
107 - '_give_payment_import',
108 - '_give_payment_currency',
109 - '_give_payment_import_id',
110 - '_give_payment_donor_ip',
111 - '_give_payment_donor_title_prefix',
112 - ),
84 + $ignore_hidden_keys = apply_filters(
85 + 'give_export_donations_ignore_hidden_keys',
86 + [
87 + '_give_payment_meta',
88 + '_give_payment_gateway',
89 + '_give_payment_mode',
90 + '_give_payment_form_title',
91 + '_give_payment_form_id',
92 + '_give_payment_price_id',
93 + '_give_payment_user_id',
94 + '_give_payment_user_email',
95 + '_give_payment_user_ip',
96 + '_give_payment_customer_id',
97 + '_give_payment_total',
98 + '_give_completed_date',
99 + '_give_donation_company',
100 + '_give_donor_billing_first_name',
101 + '_give_donor_billing_last_name',
102 + '_give_payment_donor_email',
103 + '_give_payment_donor_id',
104 + '_give_payment_date',
105 + '_give_donor_billing_address1',
106 + '_give_donor_billing_address2',
107 + '_give_donor_billing_city',
108 + '_give_donor_billing_zip',
109 + '_give_donor_billing_state',
110 + '_give_donor_billing_country',
111 + '_give_payment_import',
112 + '_give_payment_currency',
113 + '_give_payment_import_id',
114 + '_give_payment_donor_ip',
115 + '_give_payment_donor_title_prefix',
116 + ],
113 117 $form_id
114 118 );
115 119
116 120 // Unset ignored hidden keys.
@@ -126,14 +130,13 @@
126 130
127 131 /**
128 132 * Filter to modify custom fields when select donation forms,
129 133 *
130 - * @since 2.1
131 - *
132 134 * @param array $responses Contain all the fields that need to be display when donation form is display
133 - * @param int $form_id Donation Form ID
135 + * @param int $form_id Donation Form ID
134 136 *
135 137 * @return array $responses
138 + * @since 2.1
136 139 */
137 140 wp_send_json( (array) apply_filters( 'give_export_donations_get_custom_fields', $responses, $form_id ) );
138 141
139 142 }
@@ -188,35 +191,35 @@
188 191 if ( empty( $_POST['fields'] ) ) {
189 192 return $args;
190 193 }
191 194
192 - $fields = isset( $_POST['fields'] ) ? $_POST['fields'] : null;
193 - parse_str( $fields );
195 + $fields = isset( $_POST['fields'] ) ? $_POST['fields'] : '';
196 + $fields = array_map( 'give_clean', wp_parse_args( $fields, [] ) );
194 197
195 - if ( ! empty( $give_forms_categories ) || ! empty( $give_forms_tags ) ) {
196 - $args['posts_per_page'] = -1;
198 + if ( ! empty( $fields['give_forms_categories'] ) || ! empty( $fields['give_forms_tags'] ) ) {
199 + $args['posts_per_page'] = - 1;
197 200 }
198 201
199 - if ( ! empty( $give_forms_categories ) && ! empty( $give_forms_tags ) ) {
202 + if ( ! empty( $fields['give_forms_categories'] ) && ! empty( $fields['give_forms_tags'] ) ) {
200 203 $args['tax_query']['relation'] = 'AND';
201 204 }
202 205
203 - if ( ! empty( $give_forms_categories ) ) {
204 - $args['tax_query'][] = array(
206 + if ( ! empty( $fields['give_forms_categories'] ) ) {
207 + $args['tax_query'][] = [
205 208 'taxonomy' => 'give_forms_category',
206 209 'field' => 'term_id',
207 - 'terms' => $give_forms_categories,
210 + 'terms' => $fields['give_forms_categories'],
208 211 'operator' => 'AND',
209 - );
212 + ];
210 213 }
211 214
212 - if ( ! empty( $give_forms_tags ) ) {
213 - $args['tax_query'][] = array(
215 + if ( ! empty( $fields['give_forms_tags'] ) ) {
216 + $args['tax_query'][] = [
214 217 'taxonomy' => 'give_forms_tag',
215 218 'field' => 'term_id',
216 - 'terms' => $give_forms_tags,
219 + 'terms' => $fields['give_forms_tags'],
217 220 'operator' => 'AND',
218 - );
221 + ];
219 222 }
220 223
221 224 return $args;
222 225 }
@@ -225,8 +228,9 @@
225 228
226 229 /**
227 230 * Add Donation standard fields in export donation page
228 231 *
232 + * @since 3.12.1 add Donor Phone Number to donor fields.
229 233 * @since 2.1
230 234 */
231 235 function give_export_donation_standard_fields() {
232 236 ?>
@@ -248,10 +252,10 @@
248 252
249 253 <li class="give-export-option-start">
250 254 <label for="give-export-donation-id">
251 255 <input type="checkbox" checked
252 - name="give_give_donations_export_option[donation_id]"
253 - id="give-export-donation-id"><?php _e( 'Donation ID', 'give' ); ?>
256 + name="give_give_donations_export_option[donation_id]"
257 + id="give-export-donation-id"><?php _e( 'Donation ID', 'give' ); ?>
254 258 </label>
255 259 </li>
256 260
257 261 <?php
@@ -259,10 +263,10 @@
259 263 ?>
260 264 <li>
261 265 <label for="give-export-seq-id">
262 266 <input type="checkbox" checked
263 - name="give_give_donations_export_option[seq_id]"
264 - id="give-export-seq-id"><?php _e( 'Donation Number', 'give' ); ?>
267 + name="give_give_donations_export_option[seq_id]"
268 + id="give-export-seq-id"><?php _e( 'Donation Number', 'give' ); ?>
265 269 </label>
266 270 </li>
267 271 <?php
268 272 }
@@ -270,10 +274,10 @@
270 274
271 275 <li>
272 276 <label for="give-export-donation-sum">
273 277 <input type="checkbox" checked
274 - name="give_give_donations_export_option[donation_total]"
275 - id="give-export-donation-sum"><?php _e( 'Donation Total', 'give' ); ?>
278 + name="give_give_donations_export_option[donation_total]"
279 + id="give-export-donation-sum"><?php _e( 'Donation Total', 'give' ); ?>
276 280 </label>
277 281 </li>
278 282
279 283 <li>
@@ -278,10 +282,10 @@
278 282
279 283 <li>
280 284 <label for="give-export-donation-currency_code">
281 285 <input type="checkbox" checked
282 - name="give_give_donations_export_option[currency_code]"
283 - id="give-export-donation-currency_code"><?php _e( 'Currency Code', 'give' ); ?>
286 + name="give_give_donations_export_option[currency_code]"
287 + id="give-export-donation-currency_code"><?php _e( 'Currency Code', 'give' ); ?>
284 288 </label>
285 289 </li>
286 290
287 291 <li>
@@ -286,10 +290,10 @@
286 290
287 291 <li>
288 292 <label for="give-export-donation-currency_symbol">
289 293 <input type="checkbox" checked
290 - name="give_give_donations_export_option[currency_symbol]"
291 - id="give-export-donation-currency_symbol"><?php _e( 'Currency Symbol', 'give' ); ?>
294 + name="give_give_donations_export_option[currency_symbol]"
295 + id="give-export-donation-currency_symbol"><?php _e( 'Currency Symbol', 'give' ); ?>
292 296 </label>
293 297 </li>
294 298
295 299 <li>
@@ -294,10 +298,10 @@
294 298
295 299 <li>
296 300 <label for="give-export-donation-status">
297 301 <input type="checkbox" checked
298 - name="give_give_donations_export_option[donation_status]"
299 - id="give-export-donation-status"><?php _e( 'Donation Status', 'give' ); ?>
302 + name="give_give_donations_export_option[donation_status]"
303 + id="give-export-donation-status"><?php _e( 'Donation Status', 'give' ); ?>
300 304 </label>
301 305 </li>
302 306
303 307 <li>
@@ -302,10 +306,10 @@
302 306
303 307 <li>
304 308 <label for="give-export-donation-date">
305 309 <input type="checkbox" checked
306 - name="give_give_donations_export_option[donation_date]"
307 - id="give-export-donation-date"><?php _e( 'Donation Date', 'give' ); ?>
310 + name="give_give_donations_export_option[donation_date]"
311 + id="give-export-donation-date"><?php _e( 'Donation Date', 'give' ); ?>
308 312 </label>
309 313 </li>
310 314
311 315 <li>
@@ -310,10 +314,10 @@
310 314
311 315 <li>
312 316 <label for="give-export-donation-time">
313 317 <input type="checkbox" checked
314 - name="give_give_donations_export_option[donation_time]"
315 - id="give-export-donation-time"><?php _e( 'Donation Time', 'give' ); ?>
318 + name="give_give_donations_export_option[donation_time]"
319 + id="give-export-donation-time"><?php _e( 'Donation Time', 'give' ); ?>
316 320 </label>
317 321 </li>
318 322
319 323 <li>
@@ -318,10 +322,10 @@
318 322
319 323 <li>
320 324 <label for="give-export-payment-gateway">
321 325 <input type="checkbox" checked
322 - name="give_give_donations_export_option[payment_gateway]"
323 - id="give-export-payment-gateway"><?php _e( 'Payment Gateway', 'give' ); ?>
326 + name="give_give_donations_export_option[payment_gateway]"
327 + id="give-export-payment-gateway"><?php _e( 'Payment Gateway', 'give' ); ?>
324 328 </label>
325 329 </li>
326 330
327 331 <li>
@@ -326,13 +330,29 @@
326 330
327 331 <li>
328 332 <label for="give-export-payment-mode">
329 333 <input type="checkbox" checked
330 - name="give_give_donations_export_option[payment_mode]"
331 - id="give-export-payment-mode"><?php _e( 'Payment Mode', 'give' ); ?>
334 + name="give_give_donations_export_option[payment_mode]"
335 + id="give-export-payment-mode"><?php _e( 'Payment Mode', 'give' ); ?>
332 336 </label>
333 337 </li>
334 338
339 + <li>
340 + <label for="give-export-donation-note-private">
341 + <input type="checkbox"
342 + name="give_give_donations_export_option[donation_note_private]"
343 + id="give-export-donation-note-private"><?php _e( 'Donation Note (private)', 'give' ); ?>
344 + </label>
345 + </li>
346 +
347 + <li>
348 + <label for="give-export-donation-note-to-donor">
349 + <input type="checkbox"
350 + name="give_give_donations_export_option[donation_note_to_donor]"
351 + id="give-export-donation-note-to-donor"><?php _e( 'Donation Note (to donor)', 'give' ); ?>
352 + </label>
353 + </li>
354 +
335 355 <?php
336 356 /*
337 357 * Action to add extra columns in standard payment fields
338 358 *
@@ -355,10 +375,10 @@
355 375
356 376 <li class="give-export-option-start">
357 377 <label for="give-export-donation-form-id">
358 378 <input type="checkbox" checked
359 - name="give_give_donations_export_option[form_id]"
360 - id="give-export-donation-form-id"><?php _e( 'Donation Form ID', 'give' ); ?>
379 + name="give_give_donations_export_option[form_id]"
380 + id="give-export-donation-form-id"><?php _e( 'Donation Form ID', 'give' ); ?>
361 381 </label>
362 382 </li>
363 383
364 384 <li>
@@ -363,10 +383,10 @@
363 383
364 384 <li>
365 385 <label for="give-export-donation-form-title">
366 386 <input type="checkbox" checked
367 - name="give_give_donations_export_option[form_title]"
368 - id="give-export-donation-form-title"><?php _e( 'Donation Form Title', 'give' ); ?>
387 + name="give_give_donations_export_option[form_title]"
388 + id="give-export-donation-form-title"><?php _e( 'Donation Form Title', 'give' ); ?>
369 389 </label>
370 390 </li>
371 391
372 392 <li>
@@ -371,10 +391,10 @@
371 391
372 392 <li>
373 393 <label for="give-export-donation-form-level-id">
374 394 <input type="checkbox" checked
375 - name="give_give_donations_export_option[form_level_id]"
376 - id="give-export-donation-form-level-id"><?php _e( 'Donation Form Level ID', 'give' ); ?>
395 + name="give_give_donations_export_option[form_level_id]"
396 + id="give-export-donation-form-level-id"><?php _e( 'Donation Form Level ID', 'give' ); ?>
377 397 </label>
378 398 </li>
379 399
380 400 <li>
@@ -379,10 +399,10 @@
379 399
380 400 <li>
381 401 <label for="give-export-donation-form-level-title">
382 402 <input type="checkbox" checked
383 - name="give_give_donations_export_option[form_level_title]"
384 - id="give-export-donation-form-level-title"><?php _e( 'Donation Form Level Title', 'give' ); ?>
403 + name="give_give_donations_export_option[form_level_title]"
404 + id="give-export-donation-form-level-title"><?php _e( 'Donation Form Level Title', 'give' ); ?>
385 405 </label>
386 406 </li>
387 407
388 408 <?php
@@ -415,10 +435,10 @@
415 435
416 436 <li class="give-export-option-start">
417 437 <label for="give-export-first-name">
418 438 <input type="checkbox" checked
419 - name="give_give_donations_export_option[first_name]"
420 - id="give-export-first-name"><?php _e( 'Donor\'s First Name', 'give' ); ?>
439 + name="give_give_donations_export_option[first_name]"
440 + id="give-export-first-name"><?php _e( 'Donor\'s First Name', 'give' ); ?>
421 441 </label>
422 442 </li>
423 443
424 444 <li>
@@ -423,10 +443,10 @@
423 443
424 444 <li>
425 445 <label for="give-export-last-name">
426 446 <input type="checkbox" checked
427 - name="give_give_donations_export_option[last_name]"
428 - id="give-export-last-name"><?php _e( 'Donor\'s Last Name', 'give' ); ?>
447 + name="give_give_donations_export_option[last_name]"
448 + id="give-export-last-name"><?php _e( 'Donor\'s Last Name', 'give' ); ?>
429 449 </label>
430 450 </li>
431 451
432 452 <li>
@@ -431,10 +451,10 @@
431 451
432 452 <li>
433 453 <label for="give-export-email">
434 454 <input type="checkbox" checked
435 - name="give_give_donations_export_option[email]"
436 - id="give-export-email"><?php _e( 'Donor\'s Email', 'give' ); ?>
455 + name="give_give_donations_export_option[email]"
456 + id="give-export-email"><?php _e( 'Donor\'s Email', 'give' ); ?>
437 457 </label>
438 458 </li>
439 459
440 460 <li>
@@ -439,10 +459,10 @@
439 459
440 460 <li>
441 461 <label for="give-export-company">
442 462 <input type="checkbox" checked
443 - name="give_give_donations_export_option[company]"
444 - id="give-export-company"><?php _e( 'Company Name', 'give' ); ?>
463 + name="give_give_donations_export_option[company]"
464 + id="give-export-company"><?php _e( 'Company Name', 'give' ); ?>
445 465 </label>
446 466 </li>
447 467
448 468 <li>
@@ -447,18 +467,26 @@
447 467
448 468 <li>
449 469 <label for="give-export-address">
450 470 <input type="checkbox" checked
451 - name="give_give_donations_export_option[address]"
452 - id="give-export-address"><?php _e( 'Donor\'s Billing Address', 'give' ); ?>
471 + name="give_give_donations_export_option[address]"
472 + id="give-export-address"><?php _e( 'Donor\'s Billing Address', 'give' ); ?>
453 473 </label>
454 474 </li>
455 475
476 + <li>
477 + <label for="give-export-phone">
478 + <input type="checkbox" checked
479 + name="give_give_donations_export_option[phone]"
480 + id="give-export-address"><?php _e( 'Donor\'s Phone Number', 'give' ); ?>
481 + </label>
482 + </li>
483 +
456 484 <li>
457 485 <label for="give-export-comment">
458 486 <input type="checkbox" checked
459 - name="give_give_donations_export_option[comment]"
460 - id="give-export-comment"><?php _e( 'Donor\'s Comment', 'give' ); ?>
487 + name="give_give_donations_export_option[comment]"
488 + id="give-export-comment"><?php _e( 'Donor\'s Comment', 'give' ); ?>
461 489 </label>
462 490 </li>
463 491
464 492 <li>
@@ -463,10 +491,10 @@
463 491
464 492 <li>
465 493 <label for="give-export-userid">
466 494 <input type="checkbox" checked
467 - name="give_give_donations_export_option[userid]"
468 - id="give-export-userid"><?php _e( 'User ID', 'give' ); ?>
495 + name="give_give_donations_export_option[userid]"
496 + id="give-export-userid"><?php _e( 'User ID', 'give' ); ?>
469 497 </label>
470 498 </li>
471 499
472 500 <li>
@@ -471,10 +499,10 @@
471 499
472 500 <li>
473 501 <label for="give-export-donorid">
474 502 <input type="checkbox" checked
475 - name="give_give_donations_export_option[donorid]"
476 - id="give-export-donorid"><?php _e( 'Donor ID', 'give' ); ?>
503 + name="give_give_donations_export_option[donorid]"
504 + id="give-export-donorid"><?php _e( 'Donor ID', 'give' ); ?>
477 505 </label>
478 506 </li>
479 507
480 508 <li>
@@ -479,10 +507,10 @@
479 507
480 508 <li>
481 509 <label for="give-export-donor-ip">
482 510 <input type="checkbox" checked
483 - name="give_give_donations_export_option[donor_ip]"
484 - id="give-export-donor-ip"><?php _e( 'Donor IP Address', 'give' ); ?>
511 + name="give_give_donations_export_option[donor_ip]"
512 + id="give-export-donor-ip"><?php _e( 'Donor IP Address', 'give' ); ?>
485 513 </label>
486 514 </li>
487 515
488 516 <?php
@@ -552,9 +580,9 @@
552 580 </td>
553 581 <td class="give-field-wrap">
554 582 <div class="give-clearfix">
555 583 <ul class="give-export-option-ul"></ul>
556 - <p class="give-field-description"><?php _e( 'The following hidden custom fields contain data created by Give Core, a Give Add-on, another plugin, etc.<br/>Hidden fields are generally used for programming logic, but you may contain data you would like to export.', 'give' ); ?></p>
584 + <p class="give-field-description"><?php _e( 'The following hidden custom fields contain data created by GiveWP Core, a GiveWP Add-on, another plugin, etc.<br/>Hidden fields are generally used for programming logic, but may contain data you would like to export.', 'give' ); ?></p>
557 585 </div>
558 586 </td>
559 587 </tr>
560 588 <?php