PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 3.19.4
GiveWP – Donation Plugin and Fundraising Platform v3.19.4
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 3 years ago class-payments-table.php 2 years ago payments-history.php 4 years ago view-payment-details.php 2 years ago
class-payments-table.php
1089 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 [
139 'singular' => 'form', // Singular name of the listed records.
140 'plural' => 'forms', // 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 [
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 [
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 = [];
306 $tabs = [
307 'all' => [
308 'total_count',
309 __( 'All', 'give' ),
310 ],
311 'publish' => [
312 'complete_count',
313 __( 'Completed', 'give' ),
314 ],
315 'pending' => [
316 'pending_count',
317 __( 'Pending', 'give' ),
318 ],
319 'processing' => [
320 'processing_count',
321 __( 'Processing', 'give' ),
322 ],
323 'refunded' => [
324 'refunded_count',
325 __( 'Refunded', 'give' ),
326 ],
327 'revoked' => [
328 'revoked_count',
329 __( 'Revoked', 'give' ),
330 ],
331 'failed' => [
332 'failed_count',
333 __( 'Failed', 'give' ),
334 ],
335 'cancelled' => [
336 'cancelled_count',
337 __( 'Cancelled', 'give' ),
338 ],
339 'abandoned' => [
340 'abandoned_count',
341 __( 'Abandoned', 'give' ),
342 ],
343 'preapproval' => [
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', [ '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( [ 'status' => false ], $staus_url ) :
378 add_query_arg( [ '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 = [
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 = [
436 'donation' => [ 'ID', true ],
437 'donation_form' => [ 'donation_form', false ],
438 'status' => [ 'status', false ],
439 'amount' => [ 'amount', false ],
440 'date' => [ '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 [
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 [
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 [
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' => [
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 [
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 = [];
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 esc_url(
610 wp_nonce_url(
611 add_query_arg(
612 [
613 'give-action' => 'email_links',
614 'purchase_id' => $payment->ID,
615 ],
616 $this->base_url
617 ),
618 'give_payment_nonce'
619 )
620 ),
621 sprintf( __( 'Resend Donation %s Receipt', 'give' ), $payment->ID ),
622 __( 'Resend Receipt', 'give' )
623 );
624
625 }
626
627 if ( current_user_can( 'view_give_payments' ) ) {
628 $actions['delete'] = sprintf(
629 '<a class="delete-single-donation" href="%1$s" aria-label="%2$s">%3$s</a>',
630 esc_url(
631 wp_nonce_url(
632 add_query_arg(
633 [
634 'give-action' => 'delete_payment',
635 'purchase_id' => $payment->ID,
636 ],
637 $this->base_url
638 ),
639 'give_donation_nonce'
640 )
641 ),
642 sprintf( __( 'Delete Donation %s', 'give' ), $payment->ID ),
643 __( 'Delete', 'give' )
644 );
645 }
646
647 return apply_filters( 'give_payment_row_actions', $actions, $payment );
648 }
649
650
651 /**
652 * Get payment status html.
653 *
654 * @since 1.0
655 * @access public
656 *
657 * @param Give_Payment $payment Contains all the data of the payment.
658 *
659 * @return string Data shown in the Email column
660 */
661 function get_payment_status( $payment ) {
662 $value = sprintf(
663 '<div class="give-donation-status status-%1$s"><span class="give-donation-status-icon"></span>&nbsp;%2$s</div>',
664 $payment->status,
665 give_get_payment_status( $payment, true )
666 );
667
668 if ( $payment->mode == 'test' ) {
669 $value .= Give()->tooltips->render_span(
670 [
671 'label' => __( 'This donation was made in test mode.', 'give' ),
672 'tag_content' => __( 'Test', 'give' ),
673 'attributes' => [
674 'class' => 'give-item-label give-item-label-orange give-test-mode-transactions-label',
675 ],
676
677 ]
678 );
679 }
680
681 if ( true === $payment->import && true === (bool) apply_filters( 'give_payment_show_importer_label', false ) ) {
682 $value .= sprintf(
683 '&nbsp;<span class="give-item-label give-item-label-orange give-test-mode-transactions-label" data-tooltip="%1$s">%2$s</span>',
684 __( 'This donation was imported.', 'give' ),
685 __( 'Import', 'give' )
686 );
687 }
688
689 return $value;
690 }
691
692 /**
693 * Get checkbox html.
694 *
695 * @param object $payment Contains all the data for the checkbox column.
696 *
697 * @access public
698 * @since 1.0
699 *
700 * @return string Displays a checkbox.
701 */
702 public function column_cb( $payment ) {
703 return sprintf( '<input type="checkbox" name="%1$s[]" value="%2$s" />', 'payment', $payment->ID );
704 }
705
706 /**
707 * Get payment ID html.
708 *
709 * @param object $payment Contains all the data for the checkbox column.
710 *
711 * @access public
712 * @since 1.0
713 *
714 * @return string Displays a checkbox.
715 */
716 public function get_payment_id( $payment ) {
717 return '<span class="give-payment-id">' . give_get_payment_number( $payment->ID ) . '</span>';
718 }
719
720 /**
721 * Get donor html.
722 *
723 * @param object $payment Contains all the data of the payment.
724 *
725 * @access public
726 * @since 1.0
727 *
728 * @return string Data shown in the User column
729 */
730 public function get_donor( $payment ) {
731
732 $donor_id = give_get_payment_donor_id( $payment->ID );
733 $donor_billing_name = give_get_donor_name_by( $payment->ID, 'donation' );
734 $donor_name = give_get_donor_name_by( $donor_id, 'donor' );
735
736 $value = '';
737 if ( ! empty( $donor_id ) ) {
738
739 // Check whether the donor name and WP_User name is same or not.
740 if ( sanitize_title( $donor_billing_name ) !== sanitize_title( $donor_name ) ) {
741 $value .= $donor_billing_name . ' (';
742 }
743
744 $value .= '<a href="' . esc_url( admin_url( "edit.php?post_type=give_forms&page=give-donors&view=overview&id=$donor_id" ) ) . '">' . $donor_name . '</a>';
745
746 // Check whether the donor name and WP_User name is same or not.
747 if ( sanitize_title( $donor_billing_name ) != sanitize_title( $donor_name ) ) {
748 $value .= ')';
749 }
750 } else {
751 $email = give_get_payment_user_email( $payment->ID );
752 $value .= sprintf(
753 '<a href="%1$s">%2$s (%3$s)</a>',
754 esc_url( admin_url( "edit.php?post_type=give_forms&page=give-payment-history&s=$email" ) ),
755 give_get_donor_name_by( $payment->ID, 'donation' ),
756 esc_html__( 'donor missing', 'give' )
757 );
758 }
759
760 return apply_filters( 'give_payments_table_column', $value, $payment->ID, 'donor' );
761 }
762
763 /**
764 * Retrieve the bulk actions
765 *
766 * @access public
767 * @since 1.0
768 *
769 * @return array $actions Array of the bulk actions
770 */
771 public function get_bulk_actions() {
772 $actions = [
773 'delete' => __( 'Delete', 'give' ),
774 'set-status-publish' => __( 'Set To Completed', 'give' ),
775 'set-status-pending' => __( 'Set To Pending', 'give' ),
776 'set-status-processing' => __( 'Set To Processing', 'give' ),
777 'set-status-refunded' => __( 'Set To Refunded', 'give' ),
778 'set-status-revoked' => __( 'Set To Revoked', 'give' ),
779 'set-status-failed' => __( 'Set To Failed', 'give' ),
780 'set-status-cancelled' => __( 'Set To Cancelled', 'give' ),
781 'set-status-abandoned' => __( 'Set To Abandoned', 'give' ),
782 'set-status-preapproval' => __( 'Set To Preapproval', 'give' ),
783 'resend-receipt' => __( 'Resend Email Receipts', 'give' ),
784 ];
785
786 return apply_filters( 'give_payments_table_bulk_actions', $actions );
787 }
788
789 /**
790 * Process the bulk actions
791 *
792 * @since 2.25.2 Add nonce check for bulk action.
793 * @since 1.0
794 *
795 * @access public
796 *
797 * @return void
798 */
799 public function process_bulk_action()
800 {
801 $ids = isset($_GET['payment']) ? $_GET['payment'] : false;
802 $action = $this->current_action();
803
804 if ( ! is_array($ids)) {
805 $ids = [$ids];
806 }
807
808 if (
809 empty($action) ||
810 ! current_user_can('edit_give_payments')
811 ) {
812 return;
813 }
814
815 give_validate_nonce($_GET['_wpnonce'] ?? '', 'bulk-forms');
816
817 foreach ($ids as $id) {
818 // Detect when a bulk action is being triggered.
819 switch ( $this->current_action() ) {
820
821 case 'delete':
822 give_delete_donation( $id );
823 break;
824
825 case 'set-status-publish':
826 give_update_payment_status( $id, 'publish' );
827 break;
828
829 case 'set-status-pending':
830 give_update_payment_status( $id, 'pending' );
831 break;
832
833 case 'set-status-processing':
834 give_update_payment_status( $id, 'processing' );
835 break;
836
837 case 'set-status-refunded':
838 give_update_payment_status( $id, 'refunded' );
839 break;
840 case 'set-status-revoked':
841 give_update_payment_status( $id, 'revoked' );
842 break;
843
844 case 'set-status-failed':
845 give_update_payment_status( $id, 'failed' );
846 break;
847
848 case 'set-status-cancelled':
849 give_update_payment_status( $id, 'cancelled' );
850 break;
851
852 case 'set-status-abandoned':
853 give_update_payment_status( $id, 'abandoned' );
854 break;
855
856 case 'set-status-preapproval':
857 give_update_payment_status( $id, 'preapproval' );
858 break;
859
860 case 'resend-receipt':
861 /**
862 * Fire the action
863 *
864 * @since 2.0
865 */
866 do_action( 'give_donation-receipt_email_notification', $id );
867 break;
868 }// End switch().
869
870 /**
871 * Fires after triggering bulk action on payments table.
872 *
873 * @param int $id The ID of the payment.
874 * @param string $current_action The action that is being triggered.
875 *
876 * @since 1.7
877 */
878 do_action( 'give_payments_table_do_bulk_action', $id, $this->current_action() );
879 }// End foreach().
880
881 }
882
883 /**
884 * Retrieve the payment counts
885 *
886 * @access public
887 * @since 1.0
888 *
889 * @return object
890 */
891 public function get_payment_counts() {
892
893 $args = [];
894
895 if ( isset( $_GET['user'] ) ) {
896 $args['user'] = urldecode( $_GET['user'] );
897 } elseif ( isset( $_GET['donor'] ) ) {
898 $args['donor'] = absint( $_GET['donor'] );
899 } elseif ( isset( $_GET['s'] ) ) {
900 $is_user = strpos( $_GET['s'], strtolower( 'user:' ) ) !== false;
901 if ( $is_user ) {
902 $args['user'] = absint( trim( str_replace( 'user:', '', strtolower( $_GET['s'] ) ) ) );
903 unset( $args['s'] );
904 } else {
905 $args['s'] = sanitize_text_field( $_GET['s'] );
906 }
907 }
908
909 if ( ! empty( $_GET['start-date'] ) ) {
910 $args['start-date'] = urldecode( $_GET['start-date'] );
911 }
912
913 if ( ! empty( $_GET['end-date'] ) ) {
914 $args['end-date'] = urldecode( $_GET['end-date'] );
915 }
916
917 $args['form_id'] = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : null;
918 $args['gateway'] = ! empty( $_GET['gateway'] ) ? give_clean( $_GET['gateway'] ) : null;
919
920 $payment_count = give_count_payments( $args );
921 $this->complete_count = $payment_count->publish;
922 $this->pending_count = $payment_count->pending;
923 $this->processing_count = $payment_count->processing;
924 $this->refunded_count = $payment_count->refunded;
925 $this->failed_count = $payment_count->failed;
926 $this->revoked_count = $payment_count->revoked;
927 $this->cancelled_count = $payment_count->cancelled;
928 $this->abandoned_count = $payment_count->abandoned;
929 $this->preapproval_count = $payment_count->preapproval;
930
931 foreach ( $payment_count as $count ) {
932 $this->total_count += $count;
933 }
934
935 return $payment_count;
936 }
937
938 /**
939 * Retrieve all the data for all the payments.
940 *
941 * @access public
942 * @since 1.0
943 *
944 * @return array objects in array containing all the data for the payments
945 */
946 public function payments_data() {
947 $per_page = $this->per_page;
948 $orderby = isset( $_GET['orderby'] ) ? urldecode( $_GET['orderby'] ) : 'ID';
949 $order = isset( $_GET['order'] ) ? give_clean( $_GET['order'] ) : 'DESC';
950 $user = isset( $_GET['user'] ) ? absint( $_GET['user'] ) : null;
951 $donor = isset( $_GET['donor'] ) ? absint( $_GET['donor'] ) : null;
952 $status = isset( $_GET['status'] ) ? give_clean( $_GET['status'] ) : give_get_payment_status_keys();
953 $meta_key = isset( $_GET['meta_key'] ) ? give_clean( $_GET['meta_key'] ) : null;
954 $year = isset( $_GET['year'] ) ? give_clean( $_GET['year'] ) : null;
955 $month = isset( $_GET['m'] ) ? give_clean( $_GET['m'] ) : null;
956 $day = isset( $_GET['day'] ) ? give_clean( $_GET['day'] ) : null;
957 $search = isset( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : null;
958 $start_date = ! empty( $_GET['start-date'] )
959 ? give_clean( $_GET['start-date'] )
960 : date( 'Y-m-d', 0 );
961 $end_date = ! empty( $_GET['end-date'] )
962 ? give_clean( $_GET['end-date'] )
963 : date( 'Y-m-d', current_time( 'timestamp' ) );
964 $form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : null;
965 $gateway = ! empty( $_GET['gateway'] ) ? give_clean( $_GET['gateway'] ) : null;
966
967 $args = [
968 'output' => 'payments',
969 'number' => $per_page,
970 'page' => isset( $_GET['paged'] ) ? $_GET['paged'] : null,
971 'orderby' => $orderby,
972 'order' => $order,
973 'user' => $user,
974 'donor' => $donor,
975 'status' => $status,
976 'meta_key' => $meta_key,
977 'year' => $year,
978 'month' => $month,
979 'day' => $day,
980 's' => $search,
981 'start_date' => $start_date,
982 'gateway' => $gateway,
983 'end_date' => $end_date,
984 'give_forms' => $form_id,
985 ];
986
987 if ( is_string( $search ) && false !== strpos( $search, 'txn:' ) ) {
988 $args['search_in_notes'] = true;
989 $args['s'] = trim( str_replace( 'txn:', '', $args['s'] ) );
990 }
991
992 /**
993 * Filter to modify payment table argument.
994 *
995 * @since 1.8.18
996 */
997 $args = (array) apply_filters( 'give_payment_table_payments_query', $args );
998
999 $p_query = new Give_Payments_Query( $args );
1000
1001 return $p_query->get_payments();
1002
1003 }
1004
1005 /**
1006 * Setup the final data for the table
1007 *
1008 * @access public
1009 * @since 1.0
1010 * @uses Give_Payment_History_Table::get_columns()
1011 * @uses Give_Payment_History_Table::get_sortable_columns()
1012 * @uses Give_Payment_History_Table::payments_data()
1013 * @uses WP_List_Table::get_pagenum()
1014 * @uses WP_List_Table::set_pagination_args()
1015 *
1016 * @return void
1017 */
1018 public function prepare_items() {
1019
1020 wp_reset_vars( [ 'action', 'payment', 'orderby', 'order', 's' ] );
1021
1022 $columns = $this->get_columns();
1023 $hidden = []; // No hidden columns.
1024 $sortable = $this->get_sortable_columns();
1025 $data = $this->payments_data();
1026 $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any';
1027
1028 $this->_column_headers = [ $columns, $hidden, $sortable ];
1029
1030 switch ( $status ) {
1031 case 'publish':
1032 $total_items = $this->complete_count;
1033 break;
1034 case 'pending':
1035 $total_items = $this->pending_count;
1036 break;
1037 case 'processing':
1038 $total_items = $this->processing_count;
1039 break;
1040 case 'refunded':
1041 $total_items = $this->refunded_count;
1042 break;
1043 case 'failed':
1044 $total_items = $this->failed_count;
1045 break;
1046 case 'revoked':
1047 $total_items = $this->revoked_count;
1048 break;
1049 case 'cancelled':
1050 $total_items = $this->cancelled_count;
1051 break;
1052 case 'abandoned':
1053 $total_items = $this->abandoned_count;
1054 break;
1055 case 'preapproval':
1056 $total_items = $this->preapproval_count;
1057 break;
1058 case 'any':
1059 $total_items = $this->total_count;
1060 break;
1061 default:
1062 // Retrieve the count of the non-default-Give status.
1063 $count = wp_count_posts( 'give_payment' );
1064 $total_items = isset( $count->{$status} ) ? $count->{$status} : 0;
1065 break;
1066 }
1067
1068 $this->items = $data;
1069
1070 /**
1071 * Filter to modify total count of the pagination.
1072 *
1073 * @since 1.8.19
1074 */
1075 $total_items = (int) apply_filters( 'give_payment_table_pagination_total_count', $total_items, $this );
1076
1077 $this->set_pagination_args(
1078 [
1079 'total_items' => $total_items,
1080 // We have to calculate the total number of items.
1081 'per_page' => $this->per_page,
1082 // We have to determine how many items to show on a page.
1083 'total_pages' => ceil( $total_items / $this->per_page ),
1084 // We have to calculate the total number of pages.
1085 ]
1086 );
1087 }
1088 }
1089