PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / trunk
GiveWP – Donation Plugin and Fundraising Platform vtrunk
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 / admin / tools / export / give-export-donations-functions.php
give / includes / admin / tools / export Last commit date
class-batch-export-donors.php 5 years ago class-batch-export.php 4 years ago class-core-settings-export.php 7 years ago class-export-earnings.php 3 years ago class-export.php 3 years ago class-give-export-donations.php 5 years ago export-actions.php 3 years ago export-functions.php 2 years ago give-export-donations-exporter.php 1 year ago give-export-donations-functions.php 2 years ago pdf-reports.php 1 year ago
give-export-donations-functions.php
593 lines
1 <?php
2 /**
3 * Give Export Donations Functions
4 */
5
6
7 /**
8 * Return of meta keys for a donation form.
9 *
10 * @see http://wordpress.stackexchange.com/questions/58834/echo-all-meta-keys-of-a-custom-post-type
11 */
12 function give_export_donations_get_custom_fields() {
13 global $wpdb;
14
15 if ( ! current_user_can( 'export_give_reports' ) ) {
16 wp_send_json_error();
17 }
18
19 $post_type = 'give_payment';
20 $responses = [];
21 $donationmeta_table_key = Give()->payment_meta->get_meta_type() . '_id';
22
23 $form_id = isset( $_POST['form_id'] ) ? absint( $_POST['form_id'] ) : '';
24
25 if ( empty( $form_id ) ) {
26 wp_send_json_error();
27 }
28
29 $args = [
30 'give_forms' => [ $form_id ],
31 'posts_per_page' => - 1,
32 'fields' => 'ids',
33 ];
34
35 $donation_list = implode( ',', (array) give_get_payments( $args ) );
36
37 $query_and = sprintf(
38 "AND $wpdb->posts.ID IN (%s)
39 AND $wpdb->donationmeta.meta_key != ''
40 AND $wpdb->donationmeta.meta_key NOT RegExp '(^[_0-9].+$)'",
41 $donation_list
42 );
43
44 $query = "
45 SELECT DISTINCT($wpdb->donationmeta.meta_key)
46 FROM $wpdb->posts
47 LEFT JOIN $wpdb->donationmeta
48 ON $wpdb->posts.ID = {$wpdb->donationmeta}.{$donationmeta_table_key}
49 WHERE $wpdb->posts.post_type = '%s'
50 " . $query_and;
51
52 $meta_keys = $wpdb->get_col( $wpdb->prepare( $query, $post_type ) );
53
54 if ( ! empty( $meta_keys ) ) {
55 $responses['standard_fields'] = array_values( $meta_keys );
56 }
57
58 $query_and = sprintf(
59 "AND $wpdb->posts.ID IN (%s)
60 AND $wpdb->donationmeta.meta_key != ''
61 AND $wpdb->donationmeta.meta_key NOT RegExp '^[^_]'",
62 $donation_list
63 );
64
65 $query = "
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}
70 WHERE $wpdb->posts.post_type = '%s'
71 " . $query_and;
72
73 $hidden_meta_keys = $wpdb->get_col( $wpdb->prepare( $query, $post_type ) );
74
75 /**
76 * Filter to modify hidden keys that are going to be ignore when displaying the hidden keys
77 *
78 * @param array $ignore_hidden_keys Hidden keys that are going to be ignore
79 * @param array $form_id Donation form id
80 *
81 * @return array $ignore_hidden_keys Hidden keys that are going to be ignore
82 * @since 2.1
83 */
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 ],
117 $form_id
118 );
119
120 // Unset ignored hidden keys.
121 foreach ( $ignore_hidden_keys as $key ) {
122 if ( ( $key = array_search( $key, $hidden_meta_keys ) ) !== false ) {
123 unset( $hidden_meta_keys[ $key ] );
124 }
125 }
126
127 if ( ! empty( $hidden_meta_keys ) ) {
128 $responses['hidden_fields'] = array_values( $hidden_meta_keys );
129 }
130
131 /**
132 * Filter to modify custom fields when select donation forms,
133 *
134 * @param array $responses Contain all the fields that need to be display when donation form is display
135 * @param int $form_id Donation Form ID
136 *
137 * @return array $responses
138 * @since 2.1
139 */
140 wp_send_json( (array) apply_filters( 'give_export_donations_get_custom_fields', $responses, $form_id ) );
141
142 }
143
144 add_action( 'wp_ajax_give_export_donations_get_custom_fields', 'give_export_donations_get_custom_fields' );
145
146 /**
147 * Register the payments batch exporter
148 *
149 * @since 1.0
150 */
151 function give_register_export_donations_batch_export() {
152 add_action( 'give_batch_export_class_include', 'give_export_donations_include_export_class', 10, 1 );
153 }
154
155 add_action( 'give_register_batch_exporter', 'give_register_export_donations_batch_export', 10 );
156
157
158 /**
159 * Includes the Give Export Donations Custom Exporter Class.
160 *
161 * @param $class Give_Export_Donations_CSV
162 */
163 function give_export_donations_include_export_class( $class ) {
164 if ( 'Give_Export_Donations_CSV' === $class ) {
165 require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/export/give-export-donations-exporter.php';
166 }
167 }
168
169
170 /**
171 * Create column key.
172 *
173 * @param $string
174 *
175 * @return string
176 */
177 function give_export_donations_create_column_key( $string ) {
178 return sanitize_key( str_replace( ' ', '_', $string ) );
179 }
180
181 /**
182 * Filter to modify donation search form when search through AJAX
183 *
184 * @since 2.1
185 *
186 * @param $args
187 *
188 * @return array
189 */
190 function give_export_donation_form_search_args( $args ) {
191 if ( empty( $_POST['fields'] ) ) {
192 return $args;
193 }
194
195 $fields = isset( $_POST['fields'] ) ? $_POST['fields'] : '';
196 $fields = array_map( 'give_clean', wp_parse_args( $fields, [] ) );
197
198 if ( ! empty( $fields['give_forms_categories'] ) || ! empty( $fields['give_forms_tags'] ) ) {
199 $args['posts_per_page'] = - 1;
200 }
201
202 if ( ! empty( $fields['give_forms_categories'] ) && ! empty( $fields['give_forms_tags'] ) ) {
203 $args['tax_query']['relation'] = 'AND';
204 }
205
206 if ( ! empty( $fields['give_forms_categories'] ) ) {
207 $args['tax_query'][] = [
208 'taxonomy' => 'give_forms_category',
209 'field' => 'term_id',
210 'terms' => $fields['give_forms_categories'],
211 'operator' => 'AND',
212 ];
213 }
214
215 if ( ! empty( $fields['give_forms_tags'] ) ) {
216 $args['tax_query'][] = [
217 'taxonomy' => 'give_forms_tag',
218 'field' => 'term_id',
219 'terms' => $fields['give_forms_tags'],
220 'operator' => 'AND',
221 ];
222 }
223
224 return $args;
225 }
226
227 add_filter( 'give_ajax_form_search_args', 'give_export_donation_form_search_args' );
228
229 /**
230 * Add Donation standard fields in export donation page
231 *
232 * @since 3.12.1 add Donor Phone Number to donor fields.
233 * @since 2.1
234 */
235 function give_export_donation_standard_fields() {
236 ?>
237 <tr>
238 <td scope="row" class="row-title">
239 <label><?php _e( 'Standard Columns:', 'give' ); ?></label>
240 </td>
241 <td>
242 <div class="give-clearfix">
243 <ul class="give-export-option">
244 <li class="give-export-option-fields give-export-option-payment-fields">
245 <ul class="give-export-option-payment-fields-ul">
246
247 <li class="give-export-option-label give-export-option-donation-label">
248 <span>
249 <?php _e( 'Donation Payment Fields', 'give' ); ?>
250 </span>
251 </li>
252
253 <li class="give-export-option-start">
254 <label for="give-export-donation-id">
255 <input type="checkbox" checked
256 name="give_give_donations_export_option[donation_id]"
257 id="give-export-donation-id"><?php _e( 'Donation ID', 'give' ); ?>
258 </label>
259 </li>
260
261 <?php
262 if ( give_is_setting_enabled( give_get_option( 'sequential-ordering_status', 'disabled' ) ) ) {
263 ?>
264 <li>
265 <label for="give-export-seq-id">
266 <input type="checkbox" checked
267 name="give_give_donations_export_option[seq_id]"
268 id="give-export-seq-id"><?php _e( 'Donation Number', 'give' ); ?>
269 </label>
270 </li>
271 <?php
272 }
273 ?>
274
275 <li>
276 <label for="give-export-donation-sum">
277 <input type="checkbox" checked
278 name="give_give_donations_export_option[donation_total]"
279 id="give-export-donation-sum"><?php _e( 'Donation Total', 'give' ); ?>
280 </label>
281 </li>
282
283 <li>
284 <label for="give-export-donation-currency_code">
285 <input type="checkbox" checked
286 name="give_give_donations_export_option[currency_code]"
287 id="give-export-donation-currency_code"><?php _e( 'Currency Code', 'give' ); ?>
288 </label>
289 </li>
290
291 <li>
292 <label for="give-export-donation-currency_symbol">
293 <input type="checkbox" checked
294 name="give_give_donations_export_option[currency_symbol]"
295 id="give-export-donation-currency_symbol"><?php _e( 'Currency Symbol', 'give' ); ?>
296 </label>
297 </li>
298
299 <li>
300 <label for="give-export-donation-status">
301 <input type="checkbox" checked
302 name="give_give_donations_export_option[donation_status]"
303 id="give-export-donation-status"><?php _e( 'Donation Status', 'give' ); ?>
304 </label>
305 </li>
306
307 <li>
308 <label for="give-export-donation-date">
309 <input type="checkbox" checked
310 name="give_give_donations_export_option[donation_date]"
311 id="give-export-donation-date"><?php _e( 'Donation Date', 'give' ); ?>
312 </label>
313 </li>
314
315 <li>
316 <label for="give-export-donation-time">
317 <input type="checkbox" checked
318 name="give_give_donations_export_option[donation_time]"
319 id="give-export-donation-time"><?php _e( 'Donation Time', 'give' ); ?>
320 </label>
321 </li>
322
323 <li>
324 <label for="give-export-payment-gateway">
325 <input type="checkbox" checked
326 name="give_give_donations_export_option[payment_gateway]"
327 id="give-export-payment-gateway"><?php _e( 'Payment Gateway', 'give' ); ?>
328 </label>
329 </li>
330
331 <li>
332 <label for="give-export-payment-mode">
333 <input type="checkbox" checked
334 name="give_give_donations_export_option[payment_mode]"
335 id="give-export-payment-mode"><?php _e( 'Payment Mode', 'give' ); ?>
336 </label>
337 </li>
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
355 <?php
356 /*
357 * Action to add extra columns in standard payment fields
358 *
359 * @since 2.1
360 */
361 do_action( 'give_export_donation_standard_payment_fields' );
362 ?>
363 </ul>
364 </li>
365
366 <li class="give-export-option-fields give-export-option-form-fields">
367 <ul class="give-export-option-form-fields-ul">
368
369 <li class="give-export-option-label give-export-option-Form-label">
370 <span>
371 <?php _e( 'Donation Form Fields', 'give' ); ?>
372 </span>
373 </li>
374
375
376 <li class="give-export-option-start">
377 <label for="give-export-donation-form-id">
378 <input type="checkbox" checked
379 name="give_give_donations_export_option[form_id]"
380 id="give-export-donation-form-id"><?php _e( 'Donation Form ID', 'give' ); ?>
381 </label>
382 </li>
383
384 <li>
385 <label for="give-export-donation-form-title">
386 <input type="checkbox" checked
387 name="give_give_donations_export_option[form_title]"
388 id="give-export-donation-form-title"><?php _e( 'Donation Form Title', 'give' ); ?>
389 </label>
390 </li>
391
392 <li>
393 <label for="give-export-donation-form-level-id">
394 <input type="checkbox" checked
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' ); ?>
397 </label>
398 </li>
399
400 <li>
401 <label for="give-export-donation-form-level-title">
402 <input type="checkbox" checked
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' ); ?>
405 </label>
406 </li>
407
408 <?php
409 /*
410 * Action to add extra columns in standard form fields
411 *
412 * @since 2.1
413 */
414 do_action( 'give_export_donation_standard_form_fields' );
415 ?>
416 </ul>
417 </li>
418
419 <li class="give-export-option-fields give-export-option-donor-fields">
420 <ul class="give-export-option-donor-fields-ul">
421
422 <li class="give-export-option-label give-export-option-donor-label">
423 <span>
424 <?php _e( 'Donor Fields', 'give' ); ?>
425 </span>
426 </li>
427
428 <li class="give-export-option-start">
429 <label for="give-export-title-prefix">
430 <input type="checkbox" checked
431 name="give_give_donations_export_option[title_prefix]"
432 id="give-export-title-prefix"><?php esc_html_e( 'Donor\'s Title Prefix', 'give' ); ?>
433 </label>
434 </li>
435
436 <li class="give-export-option-start">
437 <label for="give-export-first-name">
438 <input type="checkbox" checked
439 name="give_give_donations_export_option[first_name]"
440 id="give-export-first-name"><?php _e( 'Donor\'s First Name', 'give' ); ?>
441 </label>
442 </li>
443
444 <li>
445 <label for="give-export-last-name">
446 <input type="checkbox" checked
447 name="give_give_donations_export_option[last_name]"
448 id="give-export-last-name"><?php _e( 'Donor\'s Last Name', 'give' ); ?>
449 </label>
450 </li>
451
452 <li>
453 <label for="give-export-email">
454 <input type="checkbox" checked
455 name="give_give_donations_export_option[email]"
456 id="give-export-email"><?php _e( 'Donor\'s Email', 'give' ); ?>
457 </label>
458 </li>
459
460 <li>
461 <label for="give-export-company">
462 <input type="checkbox" checked
463 name="give_give_donations_export_option[company]"
464 id="give-export-company"><?php _e( 'Company Name', 'give' ); ?>
465 </label>
466 </li>
467
468 <li>
469 <label for="give-export-address">
470 <input type="checkbox" checked
471 name="give_give_donations_export_option[address]"
472 id="give-export-address"><?php _e( 'Donor\'s Billing Address', 'give' ); ?>
473 </label>
474 </li>
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
484 <li>
485 <label for="give-export-comment">
486 <input type="checkbox" checked
487 name="give_give_donations_export_option[comment]"
488 id="give-export-comment"><?php _e( 'Donor\'s Comment', 'give' ); ?>
489 </label>
490 </li>
491
492 <li>
493 <label for="give-export-userid">
494 <input type="checkbox" checked
495 name="give_give_donations_export_option[userid]"
496 id="give-export-userid"><?php _e( 'User ID', 'give' ); ?>
497 </label>
498 </li>
499
500 <li>
501 <label for="give-export-donorid">
502 <input type="checkbox" checked
503 name="give_give_donations_export_option[donorid]"
504 id="give-export-donorid"><?php _e( 'Donor ID', 'give' ); ?>
505 </label>
506 </li>
507
508 <li>
509 <label for="give-export-donor-ip">
510 <input type="checkbox" checked
511 name="give_give_donations_export_option[donor_ip]"
512 id="give-export-donor-ip"><?php _e( 'Donor IP Address', 'give' ); ?>
513 </label>
514 </li>
515
516 <?php
517 /*
518 * Action to add extra columns in standard donor fields
519 *
520 * @since 2.1
521 */
522 do_action( 'give_export_donation_standard_donor_fields' );
523 ?>
524 </ul>
525 </li>
526
527 <?php
528 /**
529 * Action to add custom export column.
530 *
531 * @since 2.1.4
532 */
533 do_action( 'give_export_donation_add_custom_column' );
534 ?>
535 </ul>
536 </div>
537 </td>
538 </tr>
539 <?php
540 }
541
542 add_action( 'give_export_donation_fields', 'give_export_donation_standard_fields', 10 );
543
544 /**
545 * Add Donation Custom fields in export donation page
546 *
547 * @since 2.1
548 */
549 function give_export_donation_custom_fields() {
550 ?>
551 <tr
552 class="give-hidden give-export-donations-hide give-export-donations-standard-fields">
553 <td scope="row" class="row-title">
554 <label><?php _e( 'Custom Field Columns:', 'give' ); ?></label>
555 </td>
556 <td class="give-field-wrap">
557 <div class="give-clearfix">
558 <ul class="give-export-option-ul"></ul>
559 <p class="give-field-description"><?php _e( 'The following fields may have been created by custom code, or another plugin.', 'give' ); ?></p>
560 </div>
561 </td>
562 </tr>
563 <?php
564 }
565
566 add_action( 'give_export_donation_fields', 'give_export_donation_custom_fields', 30 );
567
568
569 /**
570 * Add Donation hidden fields in export donation page
571 *
572 * @since 2.1
573 */
574 function give_export_donation_hidden_fields() {
575 ?>
576
577 <tr class="give-hidden give-export-donations-hide give-export-donations-hidden-fields">
578 <td scope="row" class="row-title">
579 <label><?php _e( 'Hidden Custom Field Columns:', 'give' ); ?></label>
580 </td>
581 <td class="give-field-wrap">
582 <div class="give-clearfix">
583 <ul class="give-export-option-ul"></ul>
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>
585 </div>
586 </td>
587 </tr>
588 <?php
589 }
590
591 add_action( 'give_export_donation_fields', 'give_export_donation_hidden_fields', 40 );
592
593