PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.7.5
GiveWP – Donation Plugin and Fundraising Platform v2.7.5
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 7 years ago class-batch-export.php 6 years ago class-core-settings-export.php 7 years ago class-export-earnings.php 6 years ago class-export.php 6 years ago class-give-export-donations.php 6 years ago export-actions.php 6 years ago export-functions.php 6 years ago give-export-donations-exporter.php 6 years ago give-export-donations-functions.php 6 years ago pdf-reports.php 6 years ago
give-export-donations-functions.php
584 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 = array();
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 = array(
30 'give_forms' => array( $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 array(
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, array() ) );
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'][] = array(
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'][] = array(
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 2.1
233 */
234 function give_export_donation_standard_fields() {
235 ?>
236 <tr>
237 <td scope="row" class="row-title">
238 <label><?php _e( 'Standard Columns:', 'give' ); ?></label>
239 </td>
240 <td>
241 <div class="give-clearfix">
242 <ul class="give-export-option">
243 <li class="give-export-option-fields give-export-option-payment-fields">
244 <ul class="give-export-option-payment-fields-ul">
245
246 <li class="give-export-option-label give-export-option-donation-label">
247 <span>
248 <?php _e( 'Donation Payment Fields', 'give' ); ?>
249 </span>
250 </li>
251
252 <li class="give-export-option-start">
253 <label for="give-export-donation-id">
254 <input type="checkbox" checked
255 name="give_give_donations_export_option[donation_id]"
256 id="give-export-donation-id"><?php _e( 'Donation ID', 'give' ); ?>
257 </label>
258 </li>
259
260 <?php
261 if ( give_is_setting_enabled( give_get_option( 'sequential-ordering_status', 'disabled' ) ) ) {
262 ?>
263 <li>
264 <label for="give-export-seq-id">
265 <input type="checkbox" checked
266 name="give_give_donations_export_option[seq_id]"
267 id="give-export-seq-id"><?php _e( 'Donation Number', 'give' ); ?>
268 </label>
269 </li>
270 <?php
271 }
272 ?>
273
274 <li>
275 <label for="give-export-donation-sum">
276 <input type="checkbox" checked
277 name="give_give_donations_export_option[donation_total]"
278 id="give-export-donation-sum"><?php _e( 'Donation Total', 'give' ); ?>
279 </label>
280 </li>
281
282 <li>
283 <label for="give-export-donation-currency_code">
284 <input type="checkbox" checked
285 name="give_give_donations_export_option[currency_code]"
286 id="give-export-donation-currency_code"><?php _e( 'Currency Code', 'give' ); ?>
287 </label>
288 </li>
289
290 <li>
291 <label for="give-export-donation-currency_symbol">
292 <input type="checkbox" checked
293 name="give_give_donations_export_option[currency_symbol]"
294 id="give-export-donation-currency_symbol"><?php _e( 'Currency Symbol', 'give' ); ?>
295 </label>
296 </li>
297
298 <li>
299 <label for="give-export-donation-status">
300 <input type="checkbox" checked
301 name="give_give_donations_export_option[donation_status]"
302 id="give-export-donation-status"><?php _e( 'Donation Status', 'give' ); ?>
303 </label>
304 </li>
305
306 <li>
307 <label for="give-export-donation-date">
308 <input type="checkbox" checked
309 name="give_give_donations_export_option[donation_date]"
310 id="give-export-donation-date"><?php _e( 'Donation Date', 'give' ); ?>
311 </label>
312 </li>
313
314 <li>
315 <label for="give-export-donation-time">
316 <input type="checkbox" checked
317 name="give_give_donations_export_option[donation_time]"
318 id="give-export-donation-time"><?php _e( 'Donation Time', 'give' ); ?>
319 </label>
320 </li>
321
322 <li>
323 <label for="give-export-payment-gateway">
324 <input type="checkbox" checked
325 name="give_give_donations_export_option[payment_gateway]"
326 id="give-export-payment-gateway"><?php _e( 'Payment Gateway', 'give' ); ?>
327 </label>
328 </li>
329
330 <li>
331 <label for="give-export-payment-mode">
332 <input type="checkbox" checked
333 name="give_give_donations_export_option[payment_mode]"
334 id="give-export-payment-mode"><?php _e( 'Payment Mode', 'give' ); ?>
335 </label>
336 </li>
337
338 <li>
339 <label for="give-export-donation-note-private">
340 <input type="checkbox"
341 name="give_give_donations_export_option[donation_note_private]"
342 id="give-export-donation-note-private"><?php _e( 'Donation Note (private)', 'give' ); ?>
343 </label>
344 </li>
345
346 <li>
347 <label for="give-export-donation-note-to-donor">
348 <input type="checkbox"
349 name="give_give_donations_export_option[donation_note_to_donor]"
350 id="give-export-donation-note-to-donor"><?php _e( 'Donation Note (to donor)', 'give' ); ?>
351 </label>
352 </li>
353
354 <?php
355 /*
356 * Action to add extra columns in standard payment fields
357 *
358 * @since 2.1
359 */
360 do_action( 'give_export_donation_standard_payment_fields' );
361 ?>
362 </ul>
363 </li>
364
365 <li class="give-export-option-fields give-export-option-form-fields">
366 <ul class="give-export-option-form-fields-ul">
367
368 <li class="give-export-option-label give-export-option-Form-label">
369 <span>
370 <?php _e( 'Donation Form Fields', 'give' ); ?>
371 </span>
372 </li>
373
374
375 <li class="give-export-option-start">
376 <label for="give-export-donation-form-id">
377 <input type="checkbox" checked
378 name="give_give_donations_export_option[form_id]"
379 id="give-export-donation-form-id"><?php _e( 'Donation Form ID', 'give' ); ?>
380 </label>
381 </li>
382
383 <li>
384 <label for="give-export-donation-form-title">
385 <input type="checkbox" checked
386 name="give_give_donations_export_option[form_title]"
387 id="give-export-donation-form-title"><?php _e( 'Donation Form Title', 'give' ); ?>
388 </label>
389 </li>
390
391 <li>
392 <label for="give-export-donation-form-level-id">
393 <input type="checkbox" checked
394 name="give_give_donations_export_option[form_level_id]"
395 id="give-export-donation-form-level-id"><?php _e( 'Donation Form Level ID', 'give' ); ?>
396 </label>
397 </li>
398
399 <li>
400 <label for="give-export-donation-form-level-title">
401 <input type="checkbox" checked
402 name="give_give_donations_export_option[form_level_title]"
403 id="give-export-donation-form-level-title"><?php _e( 'Donation Form Level Title', 'give' ); ?>
404 </label>
405 </li>
406
407 <?php
408 /*
409 * Action to add extra columns in standard form fields
410 *
411 * @since 2.1
412 */
413 do_action( 'give_export_donation_standard_form_fields' );
414 ?>
415 </ul>
416 </li>
417
418 <li class="give-export-option-fields give-export-option-donor-fields">
419 <ul class="give-export-option-donor-fields-ul">
420
421 <li class="give-export-option-label give-export-option-donor-label">
422 <span>
423 <?php _e( 'Donor Fields', 'give' ); ?>
424 </span>
425 </li>
426
427 <li class="give-export-option-start">
428 <label for="give-export-title-prefix">
429 <input type="checkbox" checked
430 name="give_give_donations_export_option[title_prefix]"
431 id="give-export-title-prefix"><?php esc_html_e( 'Donor\'s Title Prefix', 'give' ); ?>
432 </label>
433 </li>
434
435 <li class="give-export-option-start">
436 <label for="give-export-first-name">
437 <input type="checkbox" checked
438 name="give_give_donations_export_option[first_name]"
439 id="give-export-first-name"><?php _e( 'Donor\'s First Name', 'give' ); ?>
440 </label>
441 </li>
442
443 <li>
444 <label for="give-export-last-name">
445 <input type="checkbox" checked
446 name="give_give_donations_export_option[last_name]"
447 id="give-export-last-name"><?php _e( 'Donor\'s Last Name', 'give' ); ?>
448 </label>
449 </li>
450
451 <li>
452 <label for="give-export-email">
453 <input type="checkbox" checked
454 name="give_give_donations_export_option[email]"
455 id="give-export-email"><?php _e( 'Donor\'s Email', 'give' ); ?>
456 </label>
457 </li>
458
459 <li>
460 <label for="give-export-company">
461 <input type="checkbox" checked
462 name="give_give_donations_export_option[company]"
463 id="give-export-company"><?php _e( 'Company Name', 'give' ); ?>
464 </label>
465 </li>
466
467 <li>
468 <label for="give-export-address">
469 <input type="checkbox" checked
470 name="give_give_donations_export_option[address]"
471 id="give-export-address"><?php _e( 'Donor\'s Billing Address', 'give' ); ?>
472 </label>
473 </li>
474
475 <li>
476 <label for="give-export-comment">
477 <input type="checkbox" checked
478 name="give_give_donations_export_option[comment]"
479 id="give-export-comment"><?php _e( 'Donor\'s Comment', 'give' ); ?>
480 </label>
481 </li>
482
483 <li>
484 <label for="give-export-userid">
485 <input type="checkbox" checked
486 name="give_give_donations_export_option[userid]"
487 id="give-export-userid"><?php _e( 'User ID', 'give' ); ?>
488 </label>
489 </li>
490
491 <li>
492 <label for="give-export-donorid">
493 <input type="checkbox" checked
494 name="give_give_donations_export_option[donorid]"
495 id="give-export-donorid"><?php _e( 'Donor ID', 'give' ); ?>
496 </label>
497 </li>
498
499 <li>
500 <label for="give-export-donor-ip">
501 <input type="checkbox" checked
502 name="give_give_donations_export_option[donor_ip]"
503 id="give-export-donor-ip"><?php _e( 'Donor IP Address', 'give' ); ?>
504 </label>
505 </li>
506
507 <?php
508 /*
509 * Action to add extra columns in standard donor fields
510 *
511 * @since 2.1
512 */
513 do_action( 'give_export_donation_standard_donor_fields' );
514 ?>
515 </ul>
516 </li>
517
518 <?php
519 /**
520 * Action to add custom export column.
521 *
522 * @since 2.1.4
523 */
524 do_action( 'give_export_donation_add_custom_column' );
525 ?>
526 </ul>
527 </div>
528 </td>
529 </tr>
530 <?php
531 }
532
533 add_action( 'give_export_donation_fields', 'give_export_donation_standard_fields', 10 );
534
535 /**
536 * Add Donation Custom fields in export donation page
537 *
538 * @since 2.1
539 */
540 function give_export_donation_custom_fields() {
541 ?>
542 <tr
543 class="give-hidden give-export-donations-hide give-export-donations-standard-fields">
544 <td scope="row" class="row-title">
545 <label><?php _e( 'Custom Field Columns:', 'give' ); ?></label>
546 </td>
547 <td class="give-field-wrap">
548 <div class="give-clearfix">
549 <ul class="give-export-option-ul"></ul>
550 <p class="give-field-description"><?php _e( 'The following fields may have been created by custom code, or another plugin.', 'give' ); ?></p>
551 </div>
552 </td>
553 </tr>
554 <?php
555 }
556
557 add_action( 'give_export_donation_fields', 'give_export_donation_custom_fields', 30 );
558
559
560 /**
561 * Add Donation hidden fields in export donation page
562 *
563 * @since 2.1
564 */
565 function give_export_donation_hidden_fields() {
566 ?>
567
568 <tr class="give-hidden give-export-donations-hide give-export-donations-hidden-fields">
569 <td scope="row" class="row-title">
570 <label><?php _e( 'Hidden Custom Field Columns:', 'give' ); ?></label>
571 </td>
572 <td class="give-field-wrap">
573 <div class="give-clearfix">
574 <ul class="give-export-option-ul"></ul>
575 <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 you may contain data you would like to export.', 'give' ); ?></p>
576 </div>
577 </td>
578 </tr>
579 <?php
580 }
581
582 add_action( 'give_export_donation_fields', 'give_export_donation_hidden_fields', 40 );
583
584