PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.6.1
GiveWP – Donation Plugin and Fundraising Platform v2.6.1
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 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 / payments / class-payments-table.php
give / includes / admin / payments Last commit date
actions.php 6 years ago class-payments-table.php 6 years ago payments-history.php 6 years ago view-payment-details.php 6 years ago
class-payments-table.php
1073 lines
1 <?php
2 /**
3 * Payment History Table Class
4 *
5 * @package Give
6 * @subpackage Admin/Payments
7 * @copyright Copyright (c) 2016, Give
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 // Load WP_List_Table if not loaded.
18 if ( ! class_exists( 'WP_List_Table' ) ) {
19 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
20 }
21
22 /**
23 * Give_Payment_History_Table Class
24 *
25 * Renders the Payment History table on the Payment History page
26 *
27 * @since 1.0
28 */
29 class Give_Payment_History_Table extends WP_List_Table {
30
31 /**
32 * Number of results to show per page
33 *
34 * @var string
35 * @since 1.0
36 */
37 public $per_page = 30;
38
39 /**
40 * URL of this page
41 *
42 * @var string
43 * @since 1.0.1
44 */
45 public $base_url;
46
47 /**
48 * Total number of payments
49 *
50 * @var int
51 * @since 1.0
52 */
53 public $total_count;
54
55 /**
56 * Total number of complete payments
57 *
58 * @var int
59 * @since 1.0
60 */
61 public $complete_count;
62
63 /**
64 * Total number of pending payments
65 *
66 * @var int
67 * @since 1.0
68 */
69 public $pending_count;
70
71 /**
72 * Total number of processing payments
73 *
74 * @var int
75 * @since 1.8.9
76 */
77 public $processing_count;
78
79 /**
80 * Total number of refunded payments
81 *
82 * @var int
83 * @since 1.0
84 */
85 public $refunded_count;
86
87 /**
88 * Total number of failed payments
89 *
90 * @var int
91 * @since 1.0
92 */
93 public $failed_count;
94
95 /**
96 * Total number of revoked payments
97 *
98 * @var int
99 * @since 1.0
100 */
101 public $revoked_count;
102
103 /**
104 * Total number of cancelled payments
105 *
106 * @var int
107 * @since 1.4
108 */
109 public $cancelled_count;
110
111 /**
112 * Total number of abandoned payments
113 *
114 * @var int
115 * @since 1.6
116 */
117 public $abandoned_count;
118
119 /**
120 * Total number of pre-approved payments
121 *
122 * @var int
123 * @since 1.8.13
124 */
125 public $preapproval_count;
126
127 /**
128 * Get things started.
129 *
130 * @since 1.0
131 * @uses Give_Payment_History_Table::get_payment_counts()
132 * @see WP_List_Table::__construct()
133 */
134 public function __construct() {
135
136 // Set parent defaults.
137 parent::__construct(
138 array(
139 'singular' => give_get_forms_label_singular(), // Singular name of the listed records.
140 'plural' => give_get_forms_label_plural(), // Plural name of the listed records.
141 'ajax' => false, // Does this table support ajax?
142 )
143 );
144
145 $this->process_bulk_action();
146 $this->get_payment_counts();
147 $this->base_url = admin_url( 'edit.php?post_type=give_forms&page=give-payment-history' );
148 }
149
150 /**
151 * Add donation search filter.
152 *
153 * @return void
154 */
155 public function advanced_filters() {
156 $start_date = isset( $_GET['start-date'] ) ? strtotime( give_clean( $_GET['start-date'] ) ) : '';
157 $end_date = isset( $_GET['end-date'] ) ? strtotime( give_clean( $_GET['end-date'] ) ) : '';
158 $status = isset( $_GET['status'] ) ? give_clean( $_GET['status'] ) : '';
159 $donor = isset( $_GET['donor'] ) ? absint( $_GET['donor'] ) : '';
160 $search = isset( $_GET['s'] ) ? give_clean( $_GET['s'] ) : '';
161 $form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0;
162 ?>
163 <div id="give-payment-filters" class="give-filters">
164 <?php $this->search_box( __( 'Search', 'give' ), 'give-payments' ); ?>
165 <div id="give-payment-date-filters">
166 <div class="give-filter give-filter-half">
167 <label for="start-date"
168 class="give-start-date-label"><?php _e( 'Start Date', 'give' ); ?></label>
169 <input type="text"
170 id="start-date"
171 name="start-date"
172 class="give_datepicker"
173 autocomplete="off"
174 value="<?php echo $start_date ? date_i18n( give_date_format(), $start_date ) : ''; ?>"
175 data-standard-date="<?php echo $start_date ? date( 'Y-m-d', $start_date ) : $start_date; ?>"
176 placeholder="<?php _e( 'Start Date', 'give' ); ?>"
177 />
178 </div>
179 <div class="give-filter give-filter-half">
180 <label for="end-date" class="give-end-date-label"><?php _e( 'End Date', 'give' ); ?></label>
181 <input type="text"
182 id="end-date"
183 name="end-date"
184 class="give_datepicker"
185 autocomplete="off"
186 value="<?php echo $end_date ? date_i18n( give_date_format(), $end_date ) : ''; ?>"
187 data-standard-date="<?php echo $end_date ? date( 'Y-m-d', $end_date ) : $end_date; ?>"
188 placeholder="<?php _e( 'End Date', 'give' ); ?>"
189 />
190 </div>
191 </div>
192 <div id="give-payment-form-filter" class="give-filter">
193 <label for="give-donation-forms-filter"
194 class="give-donation-forms-filter-label"><?php _e( 'Form', 'give' ); ?></label>
195 <?php
196 // Filter Donations by Donation Forms.
197 echo Give()->html->forms_dropdown(
198 array(
199 'name' => 'form_id',
200 'id' => 'give-donation-forms-filter',
201 'class' => 'give-donation-forms-filter',
202 'selected' => $form_id, // Make sure to have $form_id set to 0, if there is no selection.
203 'chosen' => true,
204 'number' => 30,
205 )
206 );
207 ?>
208 </div>
209
210 <?php
211 /**
212 * Action to add hidden fields and HTML in Payment search.
213 *
214 * @since 1.8.18
215 */
216 do_action( 'give_payment_table_advanced_filters' );
217
218 if ( ! empty( $status ) ) {
219 echo sprintf( '<input type="hidden" name="status" value="%s"/>', esc_attr( $status ) );
220 }
221
222 if ( ! empty( $donor ) ) {
223 echo sprintf( '<input type="hidden" name="donor" value="%s"/>', absint( $donor ) );
224 }
225 ?>
226
227 <div class="give-filter">
228 <?php submit_button( __( 'Apply', 'give' ), 'secondary', '', false ); ?>
229 <?php
230 // Clear active filters button.
231 if ( ! empty( $start_date ) || ! empty( $end_date ) || ! empty( $donor ) || ! empty( $search ) || ! empty( $status ) || ! empty( $form_id ) ) :
232 ?>
233 <a href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-payment-history' ); ?>"
234 class="button give-clear-filters-button"><?php _e( 'Clear Filters', 'give' ); ?></a>
235 <?php endif; ?>
236 </div>
237 </div>
238
239 <?php
240 }
241
242 /**
243 * Show the search field
244 *
245 * @param string $text Label for the search box.
246 * @param string $input_id ID of the search box.
247 *
248 * @since 1.0
249 * @access public
250 *
251 * @return void
252 */
253 public function search_box( $text, $input_id ) {
254 $input_id = $input_id . '-search-input';
255
256 if ( ! empty( $_REQUEST['orderby'] ) ) {
257 echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
258 }
259 if ( ! empty( $_REQUEST['order'] ) ) {
260 echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
261 }
262 ?>
263 <div class="give-filter give-filter-search" role="search">
264 <?php
265 /**
266 * Fires in the payment history search box.
267 *
268 * Allows you to add new elements before the search box.
269 *
270 * @since 1.7
271 */
272 do_action( 'give_payment_history_search' );
273 ?>
274 <label class="screen-reader-text" for="<?php echo $input_id; ?>"><?php echo $text; ?>:</label>
275 <input type="search" id="<?php echo $input_id; ?>" name="s"
276 value="<?php _admin_search_query(); ?>"
277 placeholder="<?php _e( 'Name, Email, or Donation ID', 'give' ); ?>" />
278 <?php
279 submit_button(
280 $text,
281 'button',
282 false,
283 false,
284 array(
285 'ID' => 'search-submit',
286 )
287 );
288 ?>
289 <br />
290 </div>
291 <?php
292 }
293
294 /**
295 * Retrieve the view types
296 *
297 * @access public
298 * @since 1.0
299 *
300 * @return array $views All the views available
301 */
302 public function get_views() {
303
304 $current = isset( $_GET['status'] ) ? $_GET['status'] : '';
305 $views = array();
306 $tabs = array(
307 'all' => array(
308 'total_count',
309 __( 'All', 'give' ),
310 ),
311 'publish' => array(
312 'complete_count',
313 __( 'Completed', 'give' ),
314 ),
315 'pending' => array(
316 'pending_count',
317 __( 'Pending', 'give' ),
318 ),
319 'processing' => array(
320 'processing_count',
321 __( 'Processing', 'give' ),
322 ),
323 'refunded' => array(
324 'refunded_count',
325 __( 'Refunded', 'give' ),
326 ),
327 'revoked' => array(
328 'revoked_count',
329 __( 'Revoked', 'give' ),
330 ),
331 'failed' => array(
332 'failed_count',
333 __( 'Failed', 'give' ),
334 ),
335 'cancelled' => array(
336 'cancelled_count',
337 __( 'Cancelled', 'give' ),
338 ),
339 'abandoned' => array(
340 'abandoned_count',
341 __( 'Abandoned', 'give' ),
342 ),
343 'preapproval' => array(
344 'preapproval_count',
345 __( 'Preapproval Pending', 'give' ),
346 ),
347 );
348
349 /**
350 * Remove Query from Args of the URL that are being pass to Donation Status.
351 *
352 * @since 1.8.18
353 */
354 $args = (array) apply_filters( 'give_payments_table_status_remove_query_arg', array( 'paged', '_wpnonce', '_wp_http_referer' ) );
355
356 // Build URL.
357 $staus_url = remove_query_arg( $args );
358
359 foreach ( $tabs as $key => $tab ) {
360 $count_key = $tab[0];
361 $name = $tab[1];
362 $count = $this->$count_key;
363
364 /**
365 * Filter can be used to show all the status inside the donation tabs.
366 *
367 * Filter can be used to show all the status inside the donation submenu tabs return true to show all the tab.
368 *
369 * @param string $key Current view tab value.
370 * @param int $count Number of donation inside the tab.
371 *
372 * @since 1.8.12
373 */
374 if ( 'all' === $key || $key === $current || apply_filters( 'give_payments_table_show_all_status', 0 < $count, $key, $count ) ) {
375
376 $staus_url = 'all' === $key ?
377 add_query_arg( array( 'status' => false ), $staus_url ) :
378 add_query_arg( array( 'status' => $key ), $staus_url );
379
380 $views[ $key ] = sprintf(
381 '<a href="%s"%s>%s&nbsp;<span class="count">(%s)</span></a>',
382 esc_url( $staus_url ),
383 ( ( 'all' === $key && empty( $current ) ) ) ? ' class="current"' : ( $current == $key ? 'class="current"' : '' ),
384 $name,
385 $count
386 );
387 }
388 }
389
390 /**
391 * Filter the donation listing page views.
392 *
393 * @since 1.0
394 *
395 * @param array $views
396 * @param Give_Payment_History_Table
397 */
398 return apply_filters( 'give_payments_table_views', $views, $this );
399 }
400
401 /**
402 * Retrieve the table columns
403 *
404 * @access public
405 * @since 1.0
406 *
407 * @return array $columns Array of all the list table columns
408 */
409 public function get_columns() {
410 $columns = array(
411 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text.
412 'donation' => __( 'Donation', 'give' ),
413 'donation_form' => __( 'Donation Form', 'give' ),
414 'status' => __( 'Status', 'give' ),
415 'date' => __( 'Date', 'give' ),
416 'amount' => __( 'Amount', 'give' ),
417 );
418
419 if ( current_user_can( 'view_give_payments' ) ) {
420 $columns['details'] = __( 'Details', 'give' );
421 }
422
423 return apply_filters( 'give_payments_table_columns', $columns );
424 }
425
426 /**
427 * Retrieve the table's sortable columns
428 *
429 * @access public
430 * @since 1.0
431 *
432 * @return array Array of all the sortable columns
433 */
434 public function get_sortable_columns() {
435 $columns = array(
436 'donation' => array( 'ID', true ),
437 'donation_form' => array( 'donation_form', false ),
438 'status' => array( 'status', false ),
439 'amount' => array( 'amount', false ),
440 'date' => array( 'date', false ),
441 );
442
443 return apply_filters( 'give_payments_table_sortable_columns', $columns );
444 }
445
446 /**
447 * Gets the name of the primary column.
448 *
449 * @since 1.5
450 * @access protected
451 *
452 * @return string Name of the primary column.
453 */
454 protected function get_primary_column_name() {
455 return 'donation';
456 }
457
458 /**
459 * This function renders most of the columns in the list table.
460 *
461 * @param Give_Payment $payment Payment ID.
462 * @param string $column_name The name of the column.
463 *
464 * @access public
465 * @since 1.0
466 *
467 * @return string Column Name
468 */
469 public function column_default( $payment, $column_name ) {
470
471 $single_donation_url = esc_url( add_query_arg( 'id', $payment->ID, admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details' ) ) );
472 $row_actions = $this->get_row_actions( $payment );
473 $value = '';
474
475 switch ( $column_name ) {
476 case 'donation':
477 $serial_code = Give()->seq_donation_number->get_serial_code( $payment );
478 if ( current_user_can( 'view_give_payments' ) ) {
479 $value = Give()->tooltips->render_link(
480 array(
481 'label' => sprintf( __( 'View Donation %s', 'give' ), $serial_code ),
482 'tag_content' => $serial_code,
483 'link' => $single_donation_url,
484 )
485 );
486 } else {
487 $value = $serial_code;
488 }
489
490 $value .= sprintf(
491 '&nbsp;%1$s&nbsp;%2$s<br>',
492 __( 'by', 'give' ),
493 $this->get_donor( $payment )
494 );
495
496 $value .= $this->get_donor_email( $payment );
497 $value .= $this->row_actions( $row_actions );
498 break;
499
500 case 'amount':
501 $value = give_donation_amount( $payment, true );
502 $value .= sprintf( '<br><small>%1$s %2$s</small>', __( 'via', 'give' ), give_get_gateway_admin_label( $payment->gateway ) );
503 break;
504
505 case 'donation_form':
506 $form_title = empty( $payment->form_title ) ? sprintf( __( 'Untitled (#%s)', 'give' ), $payment->form_id ) : $payment->form_title;
507 $value = '<a href="' . admin_url( 'post.php?post=' . $payment->form_id . '&action=edit' ) . '">' . $form_title . '</a>';
508 $level = give_get_donation_form_title(
509 $payment,
510 array(
511 'only_level' => true,
512 )
513 );
514
515 if ( ! empty( $level ) ) {
516 $value .= $level;
517 }
518
519 break;
520
521 case 'date':
522 $date = strtotime( $payment->date );
523 $value = date_i18n( give_date_format(), $date );
524 break;
525
526 case 'status':
527 $value = $this->get_payment_status( $payment );
528 break;
529
530 case 'details':
531 if ( current_user_can( 'view_give_payments' ) ) {
532 $value = Give()->tooltips->render_link(
533 array(
534 'label' => sprintf( __( 'View Donation #%s', 'give' ), $payment->ID ),
535 'tag_content' => '<span class="dashicons dashicons-visibility"></span>',
536 'link' => $single_donation_url,
537 'attributes' => array(
538 'class' => 'give-payment-details-link button button-small',
539 ),
540 )
541 );
542
543 $value = "<div class=\"give-payment-details-link-wrap\">{$value}</div>";
544 }
545 break;
546
547 default:
548 $value = isset( $payment->$column_name ) ? $payment->$column_name : '';
549 break;
550
551 }// End switch().
552
553 return apply_filters( 'give_payments_table_column', $value, $payment->ID, $column_name );
554 }
555
556 /**
557 * Get donor email html.
558 *
559 * @param object $payment Contains all the data of the payment.
560 *
561 * @access public
562 * @since 1.0
563 *
564 * @return string Data shown in the Email column
565 */
566 public function get_donor_email( $payment ) {
567
568 $email = give_get_payment_user_email( $payment->ID );
569
570 if ( empty( $email ) ) {
571 $email = __( '(unknown)', 'give' );
572 }
573
574 $value = Give()->tooltips->render_link(
575 array(
576 'link' => "mailto:{$email}",
577 'label' => __( 'Email donor', 'give' ),
578 'tag_content' => $email,
579 )
580 );
581
582 return apply_filters( 'give_payments_table_column', $value, $payment->ID, 'email' );
583 }
584
585 /**
586 * Get Row Actions
587 *
588 * @param object $payment Payment Data.
589 *
590 * @since 1.6
591 *
592 * @return array $actions
593 */
594 function get_row_actions( $payment ) {
595
596 $actions = array();
597 $email = give_get_payment_user_email( $payment->ID );
598
599 // Add search term string back to base URL.
600 $search_terms = ( isset( $_GET['s'] ) ? trim( $_GET['s'] ) : '' );
601 if ( ! empty( $search_terms ) ) {
602 $this->base_url = add_query_arg( 's', $search_terms, $this->base_url );
603 }
604
605 if ( give_is_payment_complete( $payment->ID ) && ! empty( $email ) ) {
606
607 $actions['email_links'] = sprintf(
608 '<a class="resend-single-donation-receipt" href="%1$s" aria-label="%2$s">%3$s</a>',
609 wp_nonce_url(
610 add_query_arg(
611 array(
612 'give-action' => 'email_links',
613 'purchase_id' => $payment->ID,
614 ),
615 $this->base_url
616 ),
617 'give_payment_nonce'
618 ),
619 sprintf( __( 'Resend Donation %s Receipt', 'give' ), $payment->ID ),
620 __( 'Resend Receipt', 'give' )
621 );
622
623 }
624
625 if ( current_user_can( 'view_give_payments' ) ) {
626 $actions['delete'] = sprintf(
627 '<a class="delete-single-donation" href="%1$s" aria-label="%2$s">%3$s</a>',
628 wp_nonce_url(
629 add_query_arg(
630 array(
631 'give-action' => 'delete_payment',
632 'purchase_id' => $payment->ID,
633 ),
634 $this->base_url
635 ),
636 'give_donation_nonce'
637 ),
638 sprintf( __( 'Delete Donation %s', 'give' ), $payment->ID ),
639 __( 'Delete', 'give' )
640 );
641 }
642
643 return apply_filters( 'give_payment_row_actions', $actions, $payment );
644 }
645
646
647 /**
648 * Get payment status html.
649 *
650 * @since 1.0
651 * @access public
652 *
653 * @param Give_Payment $payment Contains all the data of the payment.
654 *
655 * @return string Data shown in the Email column
656 */
657 function get_payment_status( $payment ) {
658 $value = sprintf(
659 '<div class="give-donation-status status-%1$s"><span class="give-donation-status-icon"></span>&nbsp;%2$s</div>',
660 $payment->status,
661 give_get_payment_status( $payment, true )
662 );
663
664 if ( $payment->mode == 'test' ) {
665 $value .= Give()->tooltips->render_span(
666 array(
667 'label' => __( 'This donation was made in test mode.', 'give' ),
668 'tag_content' => __( 'Test', 'give' ),
669 'attributes' => array(
670 'class' => 'give-item-label give-item-label-orange give-test-mode-transactions-label',
671 ),
672
673 )
674 );
675 }
676
677 if ( true === $payment->import && true === (bool) apply_filters( 'give_payment_show_importer_label', false ) ) {
678 $value .= sprintf(
679 '&nbsp;<span class="give-item-label give-item-label-orange give-test-mode-transactions-label" data-tooltip="%1$s">%2$s</span>',
680 __( 'This donation was imported.', 'give' ),
681 __( 'Import', 'give' )
682 );
683 }
684
685 return $value;
686 }
687
688 /**
689 * Get checkbox html.
690 *
691 * @param object $payment Contains all the data for the checkbox column.
692 *
693 * @access public
694 * @since 1.0
695 *
696 * @return string Displays a checkbox.
697 */
698 public function column_cb( $payment ) {
699 return sprintf( '<input type="checkbox" name="%1$s[]" value="%2$s" />', 'payment', $payment->ID );
700 }
701
702 /**
703 * Get payment ID html.
704 *
705 * @param object $payment Contains all the data for the checkbox column.
706 *
707 * @access public
708 * @since 1.0
709 *
710 * @return string Displays a checkbox.
711 */
712 public function get_payment_id( $payment ) {
713 return '<span class="give-payment-id">' . give_get_payment_number( $payment->ID ) . '</span>';
714 }
715
716 /**
717 * Get donor html.
718 *
719 * @param object $payment Contains all the data of the payment.
720 *
721 * @access public
722 * @since 1.0
723 *
724 * @return string Data shown in the User column
725 */
726 public function get_donor( $payment ) {
727
728 $donor_id = give_get_payment_donor_id( $payment->ID );
729 $donor_billing_name = give_get_donor_name_by( $payment->ID, 'donation' );
730 $donor_name = give_get_donor_name_by( $donor_id, 'donor' );
731
732 $value = '';
733 if ( ! empty( $donor_id ) ) {
734
735 // Check whether the donor name and WP_User name is same or not.
736 if ( sanitize_title( $donor_billing_name ) !== sanitize_title( $donor_name ) ) {
737 $value .= $donor_billing_name . ' (';
738 }
739
740 $value .= '<a href="' . esc_url( admin_url( "edit.php?post_type=give_forms&page=give-donors&view=overview&id=$donor_id" ) ) . '">' . $donor_name . '</a>';
741
742 // Check whether the donor name and WP_User name is same or not.
743 if ( sanitize_title( $donor_billing_name ) != sanitize_title( $donor_name ) ) {
744 $value .= ')';
745 }
746 } else {
747 $email = give_get_payment_user_email( $payment->ID );
748 $value .= '<a href="' . esc_url( admin_url( "edit.php?post_type=give_forms&page=give-payment-history&s=$email" ) ) . '">' . __( '(donor missing)', 'give' ) . '</a>';
749 }
750
751 return apply_filters( 'give_payments_table_column', $value, $payment->ID, 'donor' );
752 }
753
754 /**
755 * Retrieve the bulk actions
756 *
757 * @access public
758 * @since 1.0
759 *
760 * @return array $actions Array of the bulk actions
761 */
762 public function get_bulk_actions() {
763 $actions = array(
764 'delete' => __( 'Delete', 'give' ),
765 'set-status-publish' => __( 'Set To Completed', 'give' ),
766 'set-status-pending' => __( 'Set To Pending', 'give' ),
767 'set-status-processing' => __( 'Set To Processing', 'give' ),
768 'set-status-refunded' => __( 'Set To Refunded', 'give' ),
769 'set-status-revoked' => __( 'Set To Revoked', 'give' ),
770 'set-status-failed' => __( 'Set To Failed', 'give' ),
771 'set-status-cancelled' => __( 'Set To Cancelled', 'give' ),
772 'set-status-abandoned' => __( 'Set To Abandoned', 'give' ),
773 'set-status-preapproval' => __( 'Set To Preapproval', 'give' ),
774 'resend-receipt' => __( 'Resend Email Receipts', 'give' ),
775 );
776
777 return apply_filters( 'give_payments_table_bulk_actions', $actions );
778 }
779
780 /**
781 * Process the bulk actions
782 *
783 * @access public
784 * @since 1.0
785 *
786 * @return void
787 */
788 public function process_bulk_action() {
789 $ids = isset( $_GET['payment'] ) ? $_GET['payment'] : false;
790 $action = $this->current_action();
791
792 if ( ! is_array( $ids ) ) {
793 $ids = array( $ids );
794 }
795
796 if ( empty( $action ) ) {
797 return;
798 }
799
800 foreach ( $ids as $id ) {
801
802 // Detect when a bulk action is being triggered.
803 switch ( $this->current_action() ) {
804
805 case 'delete':
806 give_delete_donation( $id );
807 break;
808
809 case 'set-status-publish':
810 give_update_payment_status( $id, 'publish' );
811 break;
812
813 case 'set-status-pending':
814 give_update_payment_status( $id, 'pending' );
815 break;
816
817 case 'set-status-processing':
818 give_update_payment_status( $id, 'processing' );
819 break;
820
821 case 'set-status-refunded':
822 give_update_payment_status( $id, 'refunded' );
823 break;
824 case 'set-status-revoked':
825 give_update_payment_status( $id, 'revoked' );
826 break;
827
828 case 'set-status-failed':
829 give_update_payment_status( $id, 'failed' );
830 break;
831
832 case 'set-status-cancelled':
833 give_update_payment_status( $id, 'cancelled' );
834 break;
835
836 case 'set-status-abandoned':
837 give_update_payment_status( $id, 'abandoned' );
838 break;
839
840 case 'set-status-preapproval':
841 give_update_payment_status( $id, 'preapproval' );
842 break;
843
844 case 'resend-receipt':
845 /**
846 * Fire the action
847 *
848 * @since 2.0
849 */
850 do_action( 'give_donation-receipt_email_notification', $id );
851 break;
852 }// End switch().
853
854 /**
855 * Fires after triggering bulk action on payments table.
856 *
857 * @param int $id The ID of the payment.
858 * @param string $current_action The action that is being triggered.
859 *
860 * @since 1.7
861 */
862 do_action( 'give_payments_table_do_bulk_action', $id, $this->current_action() );
863 }// End foreach().
864
865 }
866
867 /**
868 * Retrieve the payment counts
869 *
870 * @access public
871 * @since 1.0
872 *
873 * @return object
874 */
875 public function get_payment_counts() {
876
877 $args = array();
878
879 if ( isset( $_GET['user'] ) ) {
880 $args['user'] = urldecode( $_GET['user'] );
881 } elseif ( isset( $_GET['donor'] ) ) {
882 $args['donor'] = absint( $_GET['donor'] );
883 } elseif ( isset( $_GET['s'] ) ) {
884 $is_user = strpos( $_GET['s'], strtolower( 'user:' ) ) !== false;
885 if ( $is_user ) {
886 $args['user'] = absint( trim( str_replace( 'user:', '', strtolower( $_GET['s'] ) ) ) );
887 unset( $args['s'] );
888 } else {
889 $args['s'] = sanitize_text_field( $_GET['s'] );
890 }
891 }
892
893 if ( ! empty( $_GET['start-date'] ) ) {
894 $args['start-date'] = urldecode( $_GET['start-date'] );
895 }
896
897 if ( ! empty( $_GET['end-date'] ) ) {
898 $args['end-date'] = urldecode( $_GET['end-date'] );
899 }
900
901 $args['form_id'] = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : null;
902 $args['gateway'] = ! empty( $_GET['gateway'] ) ? give_clean( $_GET['gateway'] ) : null;
903
904 $payment_count = give_count_payments( $args );
905 $this->complete_count = $payment_count->publish;
906 $this->pending_count = $payment_count->pending;
907 $this->processing_count = $payment_count->processing;
908 $this->refunded_count = $payment_count->refunded;
909 $this->failed_count = $payment_count->failed;
910 $this->revoked_count = $payment_count->revoked;
911 $this->cancelled_count = $payment_count->cancelled;
912 $this->abandoned_count = $payment_count->abandoned;
913 $this->preapproval_count = $payment_count->preapproval;
914
915 foreach ( $payment_count as $count ) {
916 $this->total_count += $count;
917 }
918
919 return $payment_count;
920 }
921
922 /**
923 * Retrieve all the data for all the payments.
924 *
925 * @access public
926 * @since 1.0
927 *
928 * @return array objects in array containing all the data for the payments
929 */
930 public function payments_data() {
931 $per_page = $this->per_page;
932 $orderby = isset( $_GET['orderby'] ) ? urldecode( $_GET['orderby'] ) : 'ID';
933 $order = isset( $_GET['order'] ) ? $_GET['order'] : 'DESC';
934 $user = isset( $_GET['user'] ) ? $_GET['user'] : null;
935 $donor = isset( $_GET['donor'] ) ? $_GET['donor'] : null;
936 $status = isset( $_GET['status'] ) ? $_GET['status'] : give_get_payment_status_keys();
937 $meta_key = isset( $_GET['meta_key'] ) ? $_GET['meta_key'] : null;
938 $year = isset( $_GET['year'] ) ? $_GET['year'] : null;
939 $month = isset( $_GET['m'] ) ? $_GET['m'] : null;
940 $day = isset( $_GET['day'] ) ? $_GET['day'] : null;
941 $search = isset( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : null;
942 $start_date = ! empty( $_GET['start-date'] )
943 ? give_clean( $_GET['start-date'] )
944 : date( 'Y-m-d', 0 );
945 $end_date = ! empty( $_GET['end-date'] )
946 ? give_clean( $_GET['end-date'] )
947 : date( 'Y-m-d', current_time( 'timestamp' ) );
948 $form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : null;
949 $gateway = ! empty( $_GET['gateway'] ) ? give_clean( $_GET['gateway'] ) : null;
950
951 $args = array(
952 'output' => 'payments',
953 'number' => $per_page,
954 'page' => isset( $_GET['paged'] ) ? $_GET['paged'] : null,
955 'orderby' => $orderby,
956 'order' => $order,
957 'user' => $user,
958 'donor' => $donor,
959 'status' => $status,
960 'meta_key' => $meta_key,
961 'year' => $year,
962 'month' => $month,
963 'day' => $day,
964 's' => $search,
965 'start_date' => $start_date,
966 'gateway' => $gateway,
967 'end_date' => $end_date,
968 'give_forms' => $form_id,
969 );
970
971 if ( is_string( $search ) && false !== strpos( $search, 'txn:' ) ) {
972 $args['search_in_notes'] = true;
973 $args['s'] = trim( str_replace( 'txn:', '', $args['s'] ) );
974 }
975
976 /**
977 * Filter to modify payment table argument.
978 *
979 * @since 1.8.18
980 */
981 $args = (array) apply_filters( 'give_payment_table_payments_query', $args );
982
983 $p_query = new Give_Payments_Query( $args );
984
985 return $p_query->get_payments();
986
987 }
988
989 /**
990 * Setup the final data for the table
991 *
992 * @access public
993 * @since 1.0
994 * @uses Give_Payment_History_Table::get_columns()
995 * @uses Give_Payment_History_Table::get_sortable_columns()
996 * @uses Give_Payment_History_Table::payments_data()
997 * @uses WP_List_Table::get_pagenum()
998 * @uses WP_List_Table::set_pagination_args()
999 *
1000 * @return void
1001 */
1002 public function prepare_items() {
1003
1004 wp_reset_vars( array( 'action', 'payment', 'orderby', 'order', 's' ) );
1005
1006 $columns = $this->get_columns();
1007 $hidden = array(); // No hidden columns.
1008 $sortable = $this->get_sortable_columns();
1009 $data = $this->payments_data();
1010 $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any';
1011
1012 $this->_column_headers = array( $columns, $hidden, $sortable );
1013
1014 switch ( $status ) {
1015 case 'publish':
1016 $total_items = $this->complete_count;
1017 break;
1018 case 'pending':
1019 $total_items = $this->pending_count;
1020 break;
1021 case 'processing':
1022 $total_items = $this->processing_count;
1023 break;
1024 case 'refunded':
1025 $total_items = $this->refunded_count;
1026 break;
1027 case 'failed':
1028 $total_items = $this->failed_count;
1029 break;
1030 case 'revoked':
1031 $total_items = $this->revoked_count;
1032 break;
1033 case 'cancelled':
1034 $total_items = $this->cancelled_count;
1035 break;
1036 case 'abandoned':
1037 $total_items = $this->abandoned_count;
1038 break;
1039 case 'preapproval':
1040 $total_items = $this->preapproval_count;
1041 break;
1042 case 'any':
1043 $total_items = $this->total_count;
1044 break;
1045 default:
1046 // Retrieve the count of the non-default-Give status.
1047 $count = wp_count_posts( 'give_payment' );
1048 $total_items = isset( $count->{$status} ) ? $count->{$status} : 0;
1049 break;
1050 }
1051
1052 $this->items = $data;
1053
1054 /**
1055 * Filter to modify total count of the pagination.
1056 *
1057 * @since 1.8.19
1058 */
1059 $total_items = (int) apply_filters( 'give_payment_table_pagination_total_count', $total_items, $this );
1060
1061 $this->set_pagination_args(
1062 array(
1063 'total_items' => $total_items,
1064 // We have to calculate the total number of items.
1065 'per_page' => $this->per_page,
1066 // We have to determine how many items to show on a page.
1067 'total_pages' => ceil( $total_items / $this->per_page ),
1068 // We have to calculate the total number of pages.
1069 )
1070 );
1071 }
1072 }
1073