PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.7.4
GiveWP – Donation Plugin and Fundraising Platform v2.7.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 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
1078 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 .= sprintf(
749 '<a href="%1$s">%2$s (%3$s)</a>',
750 esc_url( admin_url( "edit.php?post_type=give_forms&page=give-payment-history&s=$email" ) ),
751 give_get_donor_name_by( $payment->ID, 'donation' ),
752 esc_html__( 'donor missing', 'give' )
753 );
754 }
755
756 return apply_filters( 'give_payments_table_column', $value, $payment->ID, 'donor' );
757 }
758
759 /**
760 * Retrieve the bulk actions
761 *
762 * @access public
763 * @since 1.0
764 *
765 * @return array $actions Array of the bulk actions
766 */
767 public function get_bulk_actions() {
768 $actions = array(
769 'delete' => __( 'Delete', 'give' ),
770 'set-status-publish' => __( 'Set To Completed', 'give' ),
771 'set-status-pending' => __( 'Set To Pending', 'give' ),
772 'set-status-processing' => __( 'Set To Processing', 'give' ),
773 'set-status-refunded' => __( 'Set To Refunded', 'give' ),
774 'set-status-revoked' => __( 'Set To Revoked', 'give' ),
775 'set-status-failed' => __( 'Set To Failed', 'give' ),
776 'set-status-cancelled' => __( 'Set To Cancelled', 'give' ),
777 'set-status-abandoned' => __( 'Set To Abandoned', 'give' ),
778 'set-status-preapproval' => __( 'Set To Preapproval', 'give' ),
779 'resend-receipt' => __( 'Resend Email Receipts', 'give' ),
780 );
781
782 return apply_filters( 'give_payments_table_bulk_actions', $actions );
783 }
784
785 /**
786 * Process the bulk actions
787 *
788 * @access public
789 * @since 1.0
790 *
791 * @return void
792 */
793 public function process_bulk_action() {
794 $ids = isset( $_GET['payment'] ) ? $_GET['payment'] : false;
795 $action = $this->current_action();
796
797 if ( ! is_array( $ids ) ) {
798 $ids = array( $ids );
799 }
800
801 if ( empty( $action ) ) {
802 return;
803 }
804
805 foreach ( $ids as $id ) {
806
807 // Detect when a bulk action is being triggered.
808 switch ( $this->current_action() ) {
809
810 case 'delete':
811 give_delete_donation( $id );
812 break;
813
814 case 'set-status-publish':
815 give_update_payment_status( $id, 'publish' );
816 break;
817
818 case 'set-status-pending':
819 give_update_payment_status( $id, 'pending' );
820 break;
821
822 case 'set-status-processing':
823 give_update_payment_status( $id, 'processing' );
824 break;
825
826 case 'set-status-refunded':
827 give_update_payment_status( $id, 'refunded' );
828 break;
829 case 'set-status-revoked':
830 give_update_payment_status( $id, 'revoked' );
831 break;
832
833 case 'set-status-failed':
834 give_update_payment_status( $id, 'failed' );
835 break;
836
837 case 'set-status-cancelled':
838 give_update_payment_status( $id, 'cancelled' );
839 break;
840
841 case 'set-status-abandoned':
842 give_update_payment_status( $id, 'abandoned' );
843 break;
844
845 case 'set-status-preapproval':
846 give_update_payment_status( $id, 'preapproval' );
847 break;
848
849 case 'resend-receipt':
850 /**
851 * Fire the action
852 *
853 * @since 2.0
854 */
855 do_action( 'give_donation-receipt_email_notification', $id );
856 break;
857 }// End switch().
858
859 /**
860 * Fires after triggering bulk action on payments table.
861 *
862 * @param int $id The ID of the payment.
863 * @param string $current_action The action that is being triggered.
864 *
865 * @since 1.7
866 */
867 do_action( 'give_payments_table_do_bulk_action', $id, $this->current_action() );
868 }// End foreach().
869
870 }
871
872 /**
873 * Retrieve the payment counts
874 *
875 * @access public
876 * @since 1.0
877 *
878 * @return object
879 */
880 public function get_payment_counts() {
881
882 $args = array();
883
884 if ( isset( $_GET['user'] ) ) {
885 $args['user'] = urldecode( $_GET['user'] );
886 } elseif ( isset( $_GET['donor'] ) ) {
887 $args['donor'] = absint( $_GET['donor'] );
888 } elseif ( isset( $_GET['s'] ) ) {
889 $is_user = strpos( $_GET['s'], strtolower( 'user:' ) ) !== false;
890 if ( $is_user ) {
891 $args['user'] = absint( trim( str_replace( 'user:', '', strtolower( $_GET['s'] ) ) ) );
892 unset( $args['s'] );
893 } else {
894 $args['s'] = sanitize_text_field( $_GET['s'] );
895 }
896 }
897
898 if ( ! empty( $_GET['start-date'] ) ) {
899 $args['start-date'] = urldecode( $_GET['start-date'] );
900 }
901
902 if ( ! empty( $_GET['end-date'] ) ) {
903 $args['end-date'] = urldecode( $_GET['end-date'] );
904 }
905
906 $args['form_id'] = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : null;
907 $args['gateway'] = ! empty( $_GET['gateway'] ) ? give_clean( $_GET['gateway'] ) : null;
908
909 $payment_count = give_count_payments( $args );
910 $this->complete_count = $payment_count->publish;
911 $this->pending_count = $payment_count->pending;
912 $this->processing_count = $payment_count->processing;
913 $this->refunded_count = $payment_count->refunded;
914 $this->failed_count = $payment_count->failed;
915 $this->revoked_count = $payment_count->revoked;
916 $this->cancelled_count = $payment_count->cancelled;
917 $this->abandoned_count = $payment_count->abandoned;
918 $this->preapproval_count = $payment_count->preapproval;
919
920 foreach ( $payment_count as $count ) {
921 $this->total_count += $count;
922 }
923
924 return $payment_count;
925 }
926
927 /**
928 * Retrieve all the data for all the payments.
929 *
930 * @access public
931 * @since 1.0
932 *
933 * @return array objects in array containing all the data for the payments
934 */
935 public function payments_data() {
936 $per_page = $this->per_page;
937 $orderby = isset( $_GET['orderby'] ) ? urldecode( $_GET['orderby'] ) : 'ID';
938 $order = isset( $_GET['order'] ) ? $_GET['order'] : 'DESC';
939 $user = isset( $_GET['user'] ) ? $_GET['user'] : null;
940 $donor = isset( $_GET['donor'] ) ? $_GET['donor'] : null;
941 $status = isset( $_GET['status'] ) ? $_GET['status'] : give_get_payment_status_keys();
942 $meta_key = isset( $_GET['meta_key'] ) ? $_GET['meta_key'] : null;
943 $year = isset( $_GET['year'] ) ? $_GET['year'] : null;
944 $month = isset( $_GET['m'] ) ? $_GET['m'] : null;
945 $day = isset( $_GET['day'] ) ? $_GET['day'] : null;
946 $search = isset( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : null;
947 $start_date = ! empty( $_GET['start-date'] )
948 ? give_clean( $_GET['start-date'] )
949 : date( 'Y-m-d', 0 );
950 $end_date = ! empty( $_GET['end-date'] )
951 ? give_clean( $_GET['end-date'] )
952 : date( 'Y-m-d', current_time( 'timestamp' ) );
953 $form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : null;
954 $gateway = ! empty( $_GET['gateway'] ) ? give_clean( $_GET['gateway'] ) : null;
955
956 $args = array(
957 'output' => 'payments',
958 'number' => $per_page,
959 'page' => isset( $_GET['paged'] ) ? $_GET['paged'] : null,
960 'orderby' => $orderby,
961 'order' => $order,
962 'user' => $user,
963 'donor' => $donor,
964 'status' => $status,
965 'meta_key' => $meta_key,
966 'year' => $year,
967 'month' => $month,
968 'day' => $day,
969 's' => $search,
970 'start_date' => $start_date,
971 'gateway' => $gateway,
972 'end_date' => $end_date,
973 'give_forms' => $form_id,
974 );
975
976 if ( is_string( $search ) && false !== strpos( $search, 'txn:' ) ) {
977 $args['search_in_notes'] = true;
978 $args['s'] = trim( str_replace( 'txn:', '', $args['s'] ) );
979 }
980
981 /**
982 * Filter to modify payment table argument.
983 *
984 * @since 1.8.18
985 */
986 $args = (array) apply_filters( 'give_payment_table_payments_query', $args );
987
988 $p_query = new Give_Payments_Query( $args );
989
990 return $p_query->get_payments();
991
992 }
993
994 /**
995 * Setup the final data for the table
996 *
997 * @access public
998 * @since 1.0
999 * @uses Give_Payment_History_Table::get_columns()
1000 * @uses Give_Payment_History_Table::get_sortable_columns()
1001 * @uses Give_Payment_History_Table::payments_data()
1002 * @uses WP_List_Table::get_pagenum()
1003 * @uses WP_List_Table::set_pagination_args()
1004 *
1005 * @return void
1006 */
1007 public function prepare_items() {
1008
1009 wp_reset_vars( array( 'action', 'payment', 'orderby', 'order', 's' ) );
1010
1011 $columns = $this->get_columns();
1012 $hidden = array(); // No hidden columns.
1013 $sortable = $this->get_sortable_columns();
1014 $data = $this->payments_data();
1015 $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any';
1016
1017 $this->_column_headers = array( $columns, $hidden, $sortable );
1018
1019 switch ( $status ) {
1020 case 'publish':
1021 $total_items = $this->complete_count;
1022 break;
1023 case 'pending':
1024 $total_items = $this->pending_count;
1025 break;
1026 case 'processing':
1027 $total_items = $this->processing_count;
1028 break;
1029 case 'refunded':
1030 $total_items = $this->refunded_count;
1031 break;
1032 case 'failed':
1033 $total_items = $this->failed_count;
1034 break;
1035 case 'revoked':
1036 $total_items = $this->revoked_count;
1037 break;
1038 case 'cancelled':
1039 $total_items = $this->cancelled_count;
1040 break;
1041 case 'abandoned':
1042 $total_items = $this->abandoned_count;
1043 break;
1044 case 'preapproval':
1045 $total_items = $this->preapproval_count;
1046 break;
1047 case 'any':
1048 $total_items = $this->total_count;
1049 break;
1050 default:
1051 // Retrieve the count of the non-default-Give status.
1052 $count = wp_count_posts( 'give_payment' );
1053 $total_items = isset( $count->{$status} ) ? $count->{$status} : 0;
1054 break;
1055 }
1056
1057 $this->items = $data;
1058
1059 /**
1060 * Filter to modify total count of the pagination.
1061 *
1062 * @since 1.8.19
1063 */
1064 $total_items = (int) apply_filters( 'give_payment_table_pagination_total_count', $total_items, $this );
1065
1066 $this->set_pagination_args(
1067 array(
1068 'total_items' => $total_items,
1069 // We have to calculate the total number of items.
1070 'per_page' => $this->per_page,
1071 // We have to determine how many items to show on a page.
1072 'total_pages' => ceil( $total_items / $this->per_page ),
1073 // We have to calculate the total number of pages.
1074 )
1075 );
1076 }
1077 }
1078