This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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'] ) ? give_clean( $_GET['start-date'] ) : null; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
157 | $end_date = isset( $_GET['end-date'] ) ? give_clean( $_GET['end-date'] ) : null; |
||
0 ignored issues
–
show
|
|||
158 | $status = isset( $_GET['status'] ) ? give_clean( $_GET['status'] ) : ''; |
||
0 ignored issues
–
show
|
|||
159 | $donor = isset( $_GET['donor'] ) ? absint( $_GET['donor'] ) : ''; |
||
0 ignored issues
–
show
|
|||
160 | $search = isset( $_GET['s'] ) ? give_clean( $_GET['s'] ) : ''; |
||
0 ignored issues
–
show
|
|||
161 | $form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0; |
||
0 ignored issues
–
show
|
|||
162 | $date_format = give_date_format(); |
||
0 ignored issues
–
show
$date_format is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
163 | ?> |
||
164 | <div id="give-payment-filters" class="give-filters"> |
||
165 | <?php $this->search_box( __( 'Search', 'give' ), 'give-payments' ); ?> |
||
166 | <div id="give-payment-date-filters"> |
||
167 | <div class="give-filter give-filter-half"> |
||
168 | <label for="start-date" |
||
169 | class="give-start-date-label"><?php _e( 'Start Date', 'give' ); ?></label> |
||
170 | <input type="text" id="start-date" name="start-date" class="give_datepicker" autocomplete="off" |
||
171 | value="<?php printf( esc_attr( $start_date ) ); ?>" placeholder="<?php _e( 'Start Date', 'give' ); ?>" /> |
||
172 | </div> |
||
173 | <div class="give-filter give-filter-half"> |
||
174 | <label for="end-date" class="give-end-date-label"><?php _e( 'End Date', 'give' ); ?></label> |
||
175 | <input type="text" id="end-date" name="end-date" class="give_datepicker" autocomplete="off" |
||
176 | value="<?php printf( esc_attr( $end_date ) ); ?>" placeholder="<?php _e( 'End Date', 'give' ); ?>" /> |
||
177 | </div> |
||
178 | </div> |
||
179 | <div id="give-payment-form-filter" class="give-filter"> |
||
180 | <label for="give-donation-forms-filter" |
||
181 | class="give-donation-forms-filter-label"><?php _e( 'Form', 'give' ); ?></label> |
||
182 | <?php |
||
183 | // Filter Donations by Donation Forms. |
||
184 | echo Give()->html->forms_dropdown( |
||
0 ignored issues
–
show
|
|||
185 | array( |
||
186 | 'name' => 'form_id', |
||
187 | 'id' => 'give-donation-forms-filter', |
||
188 | 'class' => 'give-donation-forms-filter', |
||
189 | 'selected' => $form_id, // Make sure to have $form_id set to 0, if there is no selection. |
||
190 | 'chosen' => true, |
||
191 | 'number' => 30, |
||
192 | ) |
||
193 | ); |
||
194 | ?> |
||
195 | </div> |
||
196 | |||
197 | <?php |
||
198 | /** |
||
199 | * Action to add hidden fields and HTML in Payment search. |
||
200 | * |
||
201 | * @since 1.8.18 |
||
202 | */ |
||
203 | do_action( 'give_payment_table_advanced_filters' ); |
||
204 | |||
0 ignored issues
–
show
|
|||
205 | |||
206 | if ( ! empty( $status ) ) { |
||
207 | echo sprintf( '<input type="hidden" name="status" value="%s"/>', esc_attr( $status ) ); |
||
0 ignored issues
–
show
|
|||
208 | } |
||
209 | |||
210 | if ( ! empty( $donor ) ) { |
||
211 | echo sprintf( '<input type="hidden" name="donor" value="%s"/>', absint( $donor ) ); |
||
0 ignored issues
–
show
|
|||
212 | } |
||
213 | ?> |
||
214 | |||
215 | <div class="give-filter"> |
||
216 | <?php submit_button( __( 'Apply', 'give' ), 'secondary', '', false ); ?> |
||
217 | <?php |
||
218 | // Clear active filters button. |
||
219 | View Code Duplication | if ( ! empty( $start_date ) || ! empty( $end_date ) || ! empty( $donor ) || ! empty( $search ) || ! empty( $status ) || ! empty( $form_id ) ) : |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
220 | ?> |
||
221 | <a href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-payment-history' ); ?>" |
||
0 ignored issues
–
show
|
|||
222 | class="button give-clear-filters-button"><?php _e( 'Clear Filters', 'give' ); ?></a> |
||
223 | <?php endif; ?> |
||
224 | </div> |
||
225 | </div> |
||
226 | |||
227 | <?php |
||
228 | } |
||
229 | |||
230 | /** |
||
231 | * Show the search field |
||
232 | * |
||
233 | * @param string $text Label for the search box. |
||
234 | * @param string $input_id ID of the search box. |
||
235 | * |
||
236 | * @since 1.0 |
||
237 | * @access public |
||
238 | * |
||
239 | * @return void |
||
240 | */ |
||
241 | public function search_box( $text, $input_id ) { |
||
242 | $input_id = $input_id . '-search-input'; |
||
243 | |||
244 | if ( ! empty( $_REQUEST['orderby'] ) ) { |
||
0 ignored issues
–
show
|
|||
245 | echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
||
0 ignored issues
–
show
|
|||
246 | } |
||
247 | if ( ! empty( $_REQUEST['order'] ) ) { |
||
0 ignored issues
–
show
|
|||
248 | echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
||
0 ignored issues
–
show
|
|||
249 | } |
||
250 | ?> |
||
251 | <div class="give-filter give-filter-search" role="search"> |
||
252 | <?php |
||
253 | /** |
||
254 | * Fires in the payment history search box. |
||
255 | * |
||
256 | * Allows you to add new elements before the search box. |
||
257 | * |
||
258 | * @since 1.7 |
||
259 | */ |
||
260 | do_action( 'give_payment_history_search' ); |
||
261 | ?> |
||
262 | <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label> |
||
0 ignored issues
–
show
|
|||
263 | <input type="search" id="<?php echo $input_id ?>" name="s" |
||
0 ignored issues
–
show
|
|||
264 | value="<?php _admin_search_query(); ?>" |
||
265 | placeholder="<?php _e( 'Name, Email, or Donation ID', 'give' ); ?>" /> |
||
266 | <?php submit_button( $text, 'button', false, false, array( |
||
267 | 'ID' => 'search-submit', |
||
268 | ) ); ?><br /> |
||
269 | </div> |
||
270 | <?php |
||
271 | } |
||
272 | |||
273 | /** |
||
274 | * Retrieve the view types |
||
275 | * |
||
276 | * @access public |
||
277 | * @since 1.0 |
||
278 | * |
||
279 | * @return array $views All the views available |
||
280 | */ |
||
281 | public function get_views() { |
||
282 | |||
283 | $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
||
0 ignored issues
–
show
|
|||
284 | $views = array(); |
||
285 | $tabs = array( |
||
286 | 'all' => array( |
||
287 | 'total_count', |
||
288 | __( 'All', 'give' ), |
||
289 | ), |
||
290 | 'publish' => array( |
||
291 | 'complete_count', |
||
292 | __( 'Completed', 'give' ), |
||
293 | ), |
||
294 | 'pending' => array( |
||
295 | 'pending_count', |
||
296 | __( 'Pending', 'give' ), |
||
297 | ), |
||
298 | 'processing' => array( |
||
299 | 'processing_count', |
||
300 | __( 'Processing', 'give' ), |
||
301 | ), |
||
302 | 'refunded' => array( |
||
303 | 'refunded_count', |
||
304 | __( 'Refunded', 'give' ), |
||
305 | ), |
||
306 | 'revoked' => array( |
||
307 | 'revoked_count', |
||
308 | __( 'Revoked', 'give' ), |
||
309 | ), |
||
310 | 'failed' => array( |
||
311 | 'failed_count', |
||
312 | __( 'Failed', 'give' ), |
||
313 | ), |
||
314 | 'cancelled' => array( |
||
315 | 'cancelled_count', |
||
316 | __( 'Cancelled', 'give' ), |
||
317 | ), |
||
318 | 'abandoned' => array( |
||
319 | 'abandoned_count', |
||
320 | __( 'Abandoned', 'give' ), |
||
321 | ), |
||
322 | 'preapproval' => array( |
||
323 | 'preapproval_count', |
||
324 | __( 'Preapproval Pending', 'give' ), |
||
325 | ), |
||
326 | ); |
||
327 | |||
328 | /** |
||
329 | * Remove Query from Args of the URL that are being pass to Donation Status. |
||
330 | * |
||
331 | * @since 1.8.18 |
||
332 | */ |
||
333 | $args = (array) apply_filters( 'give_payments_table_status_remove_query_arg', array( 'paged', '_wpnonce', '_wp_http_referer' ) ); |
||
334 | |||
335 | // Build URL. |
||
336 | $staus_url = remove_query_arg( $args ); |
||
337 | |||
338 | foreach ( $tabs as $key => $tab ) { |
||
339 | $count_key = $tab[0]; |
||
340 | $name = $tab[1]; |
||
341 | $count = $this->$count_key; |
||
342 | |||
343 | /** |
||
344 | * Filter can be used to show all the status inside the donation tabs. |
||
345 | * |
||
346 | * Filter can be used to show all the status inside the donation submenu tabs return true to show all the tab. |
||
347 | * |
||
348 | * @param string $key Current view tab value. |
||
349 | * @param int $count Number of donation inside the tab. |
||
350 | * |
||
351 | * @since 1.8.12 |
||
352 | */ |
||
353 | if ( 'all' === $key || $key === $current || apply_filters( 'give_payments_table_show_all_status', 0 < $count, $key, $count ) ) { |
||
354 | |||
355 | $staus_url = 'all' === $key ? |
||
356 | add_query_arg( array( 'status' => false ), $staus_url ) : |
||
357 | add_query_arg( array( 'status' => $key ), $staus_url ); |
||
358 | |||
359 | $views[ $key ] = sprintf( |
||
360 | '<a href="%s"%s>%s <span class="count">(%s)</span></a>', |
||
361 | esc_url( $staus_url ), |
||
362 | ( ( 'all' === $key && empty( $current ) ) ) ? ' class="current"' : ( $current == $key ? 'class="current"' : '' ), |
||
363 | $name, |
||
364 | $count |
||
365 | ); |
||
366 | } |
||
367 | } |
||
368 | |||
369 | /** |
||
370 | * Filter the donation listing page views. |
||
371 | * |
||
372 | * @since 1.0 |
||
373 | * |
||
374 | * @param array $views |
||
375 | * @param Give_Payment_History_Table |
||
376 | */ |
||
377 | return apply_filters( 'give_payments_table_views', $views, $this ); |
||
378 | } |
||
379 | |||
380 | /** |
||
381 | * Retrieve the table columns |
||
382 | * |
||
383 | * @access public |
||
384 | * @since 1.0 |
||
385 | * |
||
386 | * @return array $columns Array of all the list table columns |
||
387 | */ |
||
388 | public function get_columns() { |
||
389 | $columns = array( |
||
390 | 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text. |
||
391 | 'donation' => __( 'Donation', 'give' ), |
||
392 | 'donation_form' => __( 'Donation Form', 'give' ), |
||
393 | 'status' => __( 'Status', 'give' ), |
||
394 | 'date' => __( 'Date', 'give' ), |
||
395 | 'amount' => __( 'Amount', 'give' ), |
||
396 | ); |
||
397 | |||
398 | if ( current_user_can( 'view_give_payments' ) ) { |
||
399 | $columns['details'] = __( 'Details', 'give' ); |
||
400 | } |
||
401 | |||
402 | return apply_filters( 'give_payments_table_columns', $columns ); |
||
403 | } |
||
404 | |||
405 | /** |
||
406 | * Retrieve the table's sortable columns |
||
407 | * |
||
408 | * @access public |
||
409 | * @since 1.0 |
||
410 | * |
||
411 | * @return array Array of all the sortable columns |
||
412 | */ |
||
413 | public function get_sortable_columns() { |
||
414 | $columns = array( |
||
415 | 'donation' => array( 'ID', true ), |
||
416 | 'donation_form' => array( 'donation_form', false ), |
||
417 | 'status' => array( 'status', false ), |
||
418 | 'amount' => array( 'amount', false ), |
||
419 | 'date' => array( 'date', false ), |
||
420 | ); |
||
421 | |||
422 | return apply_filters( 'give_payments_table_sortable_columns', $columns ); |
||
423 | } |
||
424 | |||
425 | /** |
||
426 | * Gets the name of the primary column. |
||
427 | * |
||
428 | * @since 1.5 |
||
429 | * @access protected |
||
430 | * |
||
431 | * @return string Name of the primary column. |
||
432 | */ |
||
433 | protected function get_primary_column_name() { |
||
434 | return 'donation'; |
||
435 | } |
||
436 | |||
437 | /** |
||
438 | * This function renders most of the columns in the list table. |
||
439 | * |
||
440 | * @param Give_Payment $payment Payment ID. |
||
441 | * @param string $column_name The name of the column. |
||
442 | * |
||
443 | * @access public |
||
444 | * @since 1.0 |
||
445 | * |
||
446 | * @return string Column Name |
||
447 | */ |
||
448 | public function column_default( $payment, $column_name ) { |
||
449 | |||
450 | $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' ) ) ); |
||
451 | $row_actions = $this->get_row_actions( $payment ); |
||
452 | $value = ''; |
||
453 | |||
454 | switch ( $column_name ) { |
||
455 | case 'donation' : |
||
456 | $serial_code = Give()->seq_donation_number->get_serial_code( $payment ); |
||
457 | if ( current_user_can( 'view_give_payments' ) ) { |
||
458 | $value = Give()->tooltips->render_link( array( |
||
459 | 'label' => sprintf( __( 'View Donation %s', 'give' ), $serial_code ), |
||
460 | 'tag_content' => $serial_code, |
||
461 | 'link' => $single_donation_url, |
||
462 | ) ); |
||
463 | } else { |
||
464 | $value = $serial_code; |
||
465 | } |
||
466 | |||
467 | $value .= sprintf( |
||
468 | ' %1$s %2$s<br>', |
||
469 | __( 'by', 'give' ), |
||
470 | $this->get_donor( $payment ) |
||
471 | ); |
||
472 | |||
473 | $value .= $this->get_donor_email( $payment ); |
||
474 | $value .= $this->row_actions( $row_actions ); |
||
475 | break; |
||
476 | |||
477 | case 'amount': |
||
478 | $value = give_donation_amount( $payment, true ); |
||
479 | $value .= sprintf( '<br><small>%1$s %2$s</small>', __( 'via', 'give' ), give_get_gateway_admin_label( $payment->gateway ) ); |
||
480 | break; |
||
481 | |||
482 | case 'donation_form': |
||
483 | $form_title = empty( $payment->form_title ) ? sprintf( __( 'Untitled (#%s)', 'give' ), $payment->form_id ) : $payment->form_title; |
||
484 | $value = '<a href="' . admin_url( 'post.php?post=' . $payment->form_id . '&action=edit' ) . '">' . $form_title . '</a>'; |
||
485 | $level = give_get_donation_form_title( |
||
486 | $payment, |
||
487 | array( |
||
488 | 'only_level' => true, |
||
489 | ) |
||
490 | ); |
||
491 | |||
492 | if ( ! empty( $level ) ) { |
||
493 | $value .= $level; |
||
494 | } |
||
495 | |||
496 | break; |
||
497 | |||
498 | case 'date': |
||
499 | $date = strtotime( $payment->date ); |
||
500 | $value = date_i18n( give_date_format(), $date ); |
||
501 | break; |
||
502 | |||
503 | case 'status': |
||
504 | $value = $this->get_payment_status( $payment ); |
||
505 | break; |
||
506 | |||
0 ignored issues
–
show
|
|||
507 | |||
508 | case 'details' : |
||
509 | if ( current_user_can( 'view_give_payments' ) ) { |
||
510 | $value = Give()->tooltips->render_link( array( |
||
511 | 'label' => sprintf( __( 'View Donation #%s', 'give' ), $payment->ID ), |
||
512 | 'tag_content' => '<span class="dashicons dashicons-visibility"></span>', |
||
513 | 'link' => $single_donation_url, |
||
514 | 'attributes' => array( |
||
515 | 'class' => 'give-payment-details-link button button-small', |
||
516 | ), |
||
517 | ) ); |
||
518 | |||
519 | $value = "<div class=\"give-payment-details-link-wrap\">{$value}</div>"; |
||
520 | } |
||
521 | break; |
||
522 | |||
523 | default: |
||
524 | $value = isset( $payment->$column_name ) ? $payment->$column_name : ''; |
||
525 | break; |
||
526 | |||
527 | }// End switch(). |
||
528 | |||
529 | return apply_filters( 'give_payments_table_column', $value, $payment->ID, $column_name ); |
||
530 | } |
||
531 | |||
532 | /** |
||
533 | * Get donor email html. |
||
534 | * |
||
535 | * @param object $payment Contains all the data of the payment. |
||
536 | * |
||
537 | * @access public |
||
538 | * @since 1.0 |
||
539 | * |
||
540 | * @return string Data shown in the Email column |
||
541 | */ |
||
542 | public function get_donor_email( $payment ) { |
||
543 | |||
544 | $email = give_get_payment_user_email( $payment->ID ); |
||
545 | |||
546 | if ( empty( $email ) ) { |
||
547 | $email = __( '(unknown)', 'give' ); |
||
548 | } |
||
549 | |||
0 ignored issues
–
show
|
|||
550 | |||
551 | $value = Give()->tooltips->render_link( array( |
||
552 | 'link' => "mailto:{$email}", |
||
553 | 'label' => __( 'Email donor', 'give' ), |
||
554 | 'tag_content' => $email, |
||
555 | ) ); |
||
556 | |||
557 | return apply_filters( 'give_payments_table_column', $value, $payment->ID, 'email' ); |
||
558 | } |
||
559 | |||
560 | /** |
||
561 | * Get Row Actions |
||
562 | * |
||
563 | * @param object $payment Payment Data. |
||
564 | * |
||
565 | * @since 1.6 |
||
566 | * |
||
567 | * @return array $actions |
||
568 | */ |
||
569 | function get_row_actions( $payment ) { |
||
0 ignored issues
–
show
|
|||
570 | |||
571 | $actions = array(); |
||
572 | $email = give_get_payment_user_email( $payment->ID ); |
||
573 | |||
574 | // Add search term string back to base URL. |
||
575 | $search_terms = ( isset( $_GET['s'] ) ? trim( $_GET['s'] ) : '' ); |
||
0 ignored issues
–
show
|
|||
576 | if ( ! empty( $search_terms ) ) { |
||
577 | $this->base_url = add_query_arg( 's', $search_terms, $this->base_url ); |
||
578 | } |
||
579 | |||
580 | View Code Duplication | if ( give_is_payment_complete( $payment->ID ) && ! empty( $email ) ) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
581 | |||
582 | $actions['email_links'] = sprintf( |
||
583 | '<a class="resend-single-donation-receipt" href="%1$s" aria-label="%2$s">%3$s</a>', wp_nonce_url( |
||
584 | add_query_arg( |
||
0 ignored issues
–
show
|
|||
585 | array( |
||
586 | 'give-action' => 'email_links', |
||
587 | 'purchase_id' => $payment->ID, |
||
588 | ), $this->base_url |
||
589 | ), 'give_payment_nonce' |
||
0 ignored issues
–
show
|
|||
590 | ), sprintf( __( 'Resend Donation %s Receipt', 'give' ), $payment->ID ), __( 'Resend Receipt', 'give' ) |
||
0 ignored issues
–
show
|
|||
591 | ); |
||
592 | |||
593 | } |
||
594 | |||
595 | View Code Duplication | if ( current_user_can( 'view_give_payments' ) ) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
596 | $actions['delete'] = sprintf( |
||
597 | '<a class="delete-single-donation" href="%1$s" aria-label="%2$s">%3$s</a>', |
||
598 | wp_nonce_url( |
||
599 | add_query_arg( |
||
600 | array( |
||
601 | 'give-action' => 'delete_payment', |
||
602 | 'purchase_id' => $payment->ID, |
||
603 | ), $this->base_url |
||
604 | ), 'give_donation_nonce' |
||
605 | ), sprintf( __( 'Delete Donation %s', 'give' ), $payment->ID ), __( 'Delete', 'give' ) |
||
606 | ); |
||
607 | } |
||
608 | |||
609 | return apply_filters( 'give_payment_row_actions', $actions, $payment ); |
||
610 | } |
||
611 | |||
612 | |||
613 | /** |
||
614 | * Get payment status html. |
||
615 | * |
||
616 | * @since 1.0 |
||
617 | * @access public |
||
618 | * |
||
619 | * @param Give_Payment $payment Contains all the data of the payment. |
||
620 | * |
||
621 | * @return string Data shown in the Email column |
||
622 | */ |
||
623 | function get_payment_status( $payment ) { |
||
0 ignored issues
–
show
|
|||
624 | $value = sprintf( |
||
625 | '<div class="give-donation-status status-%1$s"><span class="give-donation-status-icon"></span> %2$s</div>', |
||
626 | $payment->status, |
||
627 | give_get_payment_status( $payment, true ) |
||
628 | ); |
||
629 | |||
630 | if ( $payment->mode == 'test' ) { |
||
0 ignored issues
–
show
|
|||
631 | $value .= Give()->tooltips->render_span( array( |
||
632 | 'label' => __( 'This donation was made in test mode.', 'give' ), |
||
633 | 'tag_content' => __( 'Test', 'give' ), |
||
634 | 'attributes' => array( |
||
635 | 'class' => 'give-item-label give-item-label-orange give-test-mode-transactions-label', |
||
636 | ), |
||
637 | |||
0 ignored issues
–
show
|
|||
638 | |||
639 | ) ); |
||
640 | } |
||
641 | |||
642 | if ( true === $payment->import && true === (bool) apply_filters( 'give_payment_show_importer_label', false ) ) { |
||
643 | $value .= sprintf( |
||
644 | ' <span class="give-item-label give-item-label-orange give-test-mode-transactions-label" data-tooltip="%1$s">%2$s</span>', |
||
645 | __( 'This donation was imported.', 'give' ), |
||
646 | __( 'Import', 'give' ) |
||
647 | ); |
||
648 | } |
||
649 | |||
650 | return $value; |
||
651 | } |
||
652 | |||
653 | /** |
||
654 | * Get checkbox html. |
||
655 | * |
||
656 | * @param object $payment Contains all the data for the checkbox column. |
||
657 | * |
||
658 | * @access public |
||
659 | * @since 1.0 |
||
660 | * |
||
661 | * @return string Displays a checkbox. |
||
662 | */ |
||
663 | public function column_cb( $payment ) { |
||
664 | return sprintf( '<input type="checkbox" name="%1$s[]" value="%2$s" />', 'payment', $payment->ID ); |
||
665 | } |
||
666 | |||
667 | /** |
||
668 | * Get payment ID html. |
||
669 | * |
||
670 | * @param object $payment Contains all the data for the checkbox column. |
||
671 | * |
||
672 | * @access public |
||
673 | * @since 1.0 |
||
674 | * |
||
675 | * @return string Displays a checkbox. |
||
676 | */ |
||
677 | public function get_payment_id( $payment ) { |
||
678 | return '<span class="give-payment-id">' . give_get_payment_number( $payment->ID ) . '</span>'; |
||
679 | } |
||
680 | |||
681 | /** |
||
682 | * Get donor html. |
||
683 | * |
||
684 | * @param object $payment Contains all the data of the payment. |
||
685 | * |
||
686 | * @access public |
||
687 | * @since 1.0 |
||
688 | * |
||
689 | * @return string Data shown in the User column |
||
690 | */ |
||
691 | public function get_donor( $payment ) { |
||
692 | |||
693 | $donor_id = give_get_payment_donor_id( $payment->ID ); |
||
694 | $donor_billing_name = give_get_donor_name_by( $payment->ID, 'donation' ); |
||
695 | $donor_name = give_get_donor_name_by( $donor_id, 'donor' ); |
||
696 | |||
697 | $value = ''; |
||
698 | if ( ! empty( $donor_id ) ) { |
||
699 | |||
700 | // Check whether the donor name and WP_User name is same or not. |
||
701 | if ( sanitize_title( $donor_billing_name ) !== sanitize_title( $donor_name ) ) { |
||
702 | $value .= $donor_billing_name . ' ('; |
||
703 | } |
||
704 | |||
705 | $value .= '<a href="' . esc_url( admin_url( "edit.php?post_type=give_forms&page=give-donors&view=overview&id=$donor_id" ) ) . '">' . $donor_name . '</a>'; |
||
706 | |||
707 | // Check whether the donor name and WP_User name is same or not. |
||
708 | if ( sanitize_title( $donor_billing_name ) != sanitize_title( $donor_name ) ) { |
||
709 | $value .= ')'; |
||
710 | } |
||
711 | } else { |
||
712 | $email = give_get_payment_user_email( $payment->ID ); |
||
713 | $value .= '<a href="' . esc_url( admin_url( "edit.php?post_type=give_forms&page=give-payment-history&s=$email" ) ) . '">' . __( '(donor missing)', 'give' ) . '</a>'; |
||
714 | } |
||
715 | |||
716 | return apply_filters( 'give_payments_table_column', $value, $payment->ID, 'donor' ); |
||
717 | } |
||
718 | |||
719 | /** |
||
720 | * Retrieve the bulk actions |
||
721 | * |
||
722 | * @access public |
||
723 | * @since 1.0 |
||
724 | * |
||
725 | * @return array $actions Array of the bulk actions |
||
726 | */ |
||
727 | public function get_bulk_actions() { |
||
728 | $actions = array( |
||
729 | 'delete' => __( 'Delete', 'give' ), |
||
730 | 'set-status-publish' => __( 'Set To Completed', 'give' ), |
||
731 | 'set-status-pending' => __( 'Set To Pending', 'give' ), |
||
732 | 'set-status-processing' => __( 'Set To Processing', 'give' ), |
||
733 | 'set-status-refunded' => __( 'Set To Refunded', 'give' ), |
||
734 | 'set-status-revoked' => __( 'Set To Revoked', 'give' ), |
||
735 | 'set-status-failed' => __( 'Set To Failed', 'give' ), |
||
736 | 'set-status-cancelled' => __( 'Set To Cancelled', 'give' ), |
||
737 | 'set-status-abandoned' => __( 'Set To Abandoned', 'give' ), |
||
738 | 'set-status-preapproval' => __( 'Set To Preapproval', 'give' ), |
||
739 | 'resend-receipt' => __( 'Resend Email Receipts', 'give' ), |
||
740 | ); |
||
741 | |||
742 | return apply_filters( 'give_payments_table_bulk_actions', $actions ); |
||
743 | } |
||
744 | |||
745 | /** |
||
746 | * Process the bulk actions |
||
747 | * |
||
748 | * @access public |
||
749 | * @since 1.0 |
||
750 | * |
||
751 | * @return void |
||
752 | */ |
||
753 | public function process_bulk_action() { |
||
754 | $ids = isset( $_GET['payment'] ) ? $_GET['payment'] : false; |
||
0 ignored issues
–
show
|
|||
755 | $action = $this->current_action(); |
||
756 | |||
757 | if ( ! is_array( $ids ) ) { |
||
758 | $ids = array( $ids ); |
||
759 | } |
||
760 | |||
761 | if ( empty( $action ) ) { |
||
762 | return; |
||
763 | } |
||
764 | |||
765 | foreach ( $ids as $id ) { |
||
766 | |||
767 | // Detect when a bulk action is being triggered. |
||
768 | switch ( $this->current_action() ) { |
||
769 | |||
770 | case 'delete': |
||
771 | give_delete_donation( $id ); |
||
772 | break; |
||
773 | |||
774 | case 'set-status-publish': |
||
775 | give_update_payment_status( $id, 'publish' ); |
||
776 | break; |
||
777 | |||
778 | case 'set-status-pending': |
||
779 | give_update_payment_status( $id, 'pending' ); |
||
780 | break; |
||
781 | |||
782 | case 'set-status-processing': |
||
783 | give_update_payment_status( $id, 'processing' ); |
||
784 | break; |
||
785 | |||
786 | case 'set-status-refunded': |
||
787 | give_update_payment_status( $id, 'refunded' ); |
||
788 | break; |
||
789 | case 'set-status-revoked': |
||
790 | give_update_payment_status( $id, 'revoked' ); |
||
791 | break; |
||
792 | |||
793 | case 'set-status-failed': |
||
794 | give_update_payment_status( $id, 'failed' ); |
||
795 | break; |
||
796 | |||
797 | case 'set-status-cancelled': |
||
798 | give_update_payment_status( $id, 'cancelled' ); |
||
799 | break; |
||
800 | |||
801 | case 'set-status-abandoned': |
||
802 | give_update_payment_status( $id, 'abandoned' ); |
||
803 | break; |
||
804 | |||
805 | case 'set-status-preapproval': |
||
806 | give_update_payment_status( $id, 'preapproval' ); |
||
807 | break; |
||
808 | |||
809 | case 'resend-receipt': |
||
810 | /** |
||
811 | * Fire the action |
||
812 | * |
||
813 | * @since 2.0 |
||
814 | */ |
||
815 | do_action( 'give_donation-receipt_email_notification', $id ); |
||
816 | break; |
||
817 | }// End switch(). |
||
818 | |||
819 | /** |
||
820 | * Fires after triggering bulk action on payments table. |
||
821 | * |
||
822 | * @param int $id The ID of the payment. |
||
823 | * @param string $current_action The action that is being triggered. |
||
824 | * |
||
825 | * @since 1.7 |
||
826 | */ |
||
827 | do_action( 'give_payments_table_do_bulk_action', $id, $this->current_action() ); |
||
828 | }// End foreach(). |
||
829 | |||
830 | } |
||
831 | |||
832 | /** |
||
833 | * Retrieve the payment counts |
||
834 | * |
||
835 | * @access public |
||
836 | * @since 1.0 |
||
837 | * |
||
838 | * @return object |
||
839 | */ |
||
840 | public function get_payment_counts() { |
||
841 | |||
842 | $args = array(); |
||
843 | |||
844 | if ( isset( $_GET['user'] ) ) { |
||
845 | $args['user'] = urldecode( $_GET['user'] ); |
||
0 ignored issues
–
show
|
|||
846 | } elseif ( isset( $_GET['donor'] ) ) { |
||
847 | $args['donor'] = absint( $_GET['donor'] ); |
||
0 ignored issues
–
show
|
|||
848 | } elseif ( isset( $_GET['s'] ) ) { |
||
849 | $is_user = strpos( $_GET['s'], strtolower( 'user:' ) ) !== false; |
||
0 ignored issues
–
show
|
|||
850 | if ( $is_user ) { |
||
851 | $args['user'] = absint( trim( str_replace( 'user:', '', strtolower( $_GET['s'] ) ) ) ); |
||
0 ignored issues
–
show
|
|||
852 | unset( $args['s'] ); |
||
853 | } else { |
||
854 | $args['s'] = sanitize_text_field( $_GET['s'] ); |
||
0 ignored issues
–
show
|
|||
855 | } |
||
856 | } |
||
857 | |||
858 | if ( ! empty( $_GET['start-date'] ) ) { |
||
859 | $args['start-date'] = urldecode( $_GET['start-date'] ); |
||
0 ignored issues
–
show
|
|||
860 | } |
||
861 | |||
862 | if ( ! empty( $_GET['end-date'] ) ) { |
||
863 | $args['end-date'] = urldecode( $_GET['end-date'] ); |
||
0 ignored issues
–
show
|
|||
864 | } |
||
865 | |||
866 | $args['form_id'] = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : null; |
||
0 ignored issues
–
show
|
|||
867 | $args['gateway'] = ! empty( $_GET['gateway'] ) ? give_clean( $_GET['gateway'] ) : null; |
||
0 ignored issues
–
show
|
|||
868 | |||
869 | $payment_count = give_count_payments( $args ); |
||
870 | $this->complete_count = $payment_count->publish; |
||
871 | $this->pending_count = $payment_count->pending; |
||
872 | $this->processing_count = $payment_count->processing; |
||
873 | $this->refunded_count = $payment_count->refunded; |
||
874 | $this->failed_count = $payment_count->failed; |
||
875 | $this->revoked_count = $payment_count->revoked; |
||
876 | $this->cancelled_count = $payment_count->cancelled; |
||
877 | $this->abandoned_count = $payment_count->abandoned; |
||
878 | $this->preapproval_count = $payment_count->preapproval; |
||
879 | |||
880 | foreach ( $payment_count as $count ) { |
||
881 | $this->total_count += $count; |
||
882 | } |
||
883 | |||
884 | return $payment_count; |
||
885 | } |
||
886 | |||
887 | /** |
||
888 | * Retrieve all the data for all the payments. |
||
889 | * |
||
890 | * @access public |
||
891 | * @since 1.0 |
||
892 | * |
||
893 | * @return array objects in array containing all the data for the payments |
||
894 | */ |
||
895 | public function payments_data() { |
||
896 | $per_page = $this->per_page; |
||
897 | $orderby = isset( $_GET['orderby'] ) ? urldecode( $_GET['orderby'] ) : 'ID'; |
||
0 ignored issues
–
show
|
|||
898 | $order = isset( $_GET['order'] ) ? $_GET['order'] : 'DESC'; |
||
0 ignored issues
–
show
|
|||
899 | $user = isset( $_GET['user'] ) ? $_GET['user'] : null; |
||
0 ignored issues
–
show
|
|||
900 | $donor = isset( $_GET['donor'] ) ? $_GET['donor'] : null; |
||
0 ignored issues
–
show
|
|||
901 | $status = isset( $_GET['status'] ) ? $_GET['status'] : give_get_payment_status_keys(); |
||
0 ignored issues
–
show
|
|||
902 | $meta_key = isset( $_GET['meta_key'] ) ? $_GET['meta_key'] : null; |
||
0 ignored issues
–
show
|
|||
903 | $year = isset( $_GET['year'] ) ? $_GET['year'] : null; |
||
0 ignored issues
–
show
|
|||
904 | $month = isset( $_GET['m'] ) ? $_GET['m'] : null; |
||
0 ignored issues
–
show
|
|||
905 | $day = isset( $_GET['day'] ) ? $_GET['day'] : null; |
||
0 ignored issues
–
show
|
|||
906 | $search = isset( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : null; |
||
0 ignored issues
–
show
|
|||
907 | $start_date = ! empty ( $_GET['start-date'] ) ? sanitize_text_field( $_GET['start-date'] ) : date( give_date_format(), 0 ); |
||
0 ignored issues
–
show
|
|||
908 | $end_date = ! empty( $_GET['end-date'] ) |
||
0 ignored issues
–
show
|
|||
909 | ? sanitize_text_field( $_GET['end-date'] ) |
||
0 ignored issues
–
show
|
|||
910 | : date( give_date_format(), current_time( 'timestamp' ) ); |
||
911 | $form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : null; |
||
0 ignored issues
–
show
|
|||
912 | $gateway = ! empty( $_GET['gateway'] ) ? give_clean( $_GET['gateway'] ) : null; |
||
0 ignored issues
–
show
|
|||
913 | |||
914 | $args = array( |
||
915 | 'output' => 'payments', |
||
916 | 'number' => $per_page, |
||
917 | 'page' => isset( $_GET['paged'] ) ? $_GET['paged'] : null, |
||
0 ignored issues
–
show
|
|||
918 | 'orderby' => $orderby, |
||
919 | 'order' => $order, |
||
920 | 'user' => $user, |
||
921 | 'donor' => $donor, |
||
922 | 'status' => $status, |
||
923 | 'meta_key' => $meta_key, |
||
0 ignored issues
–
show
|
|||
924 | 'year' => $year, |
||
925 | 'month' => $month, |
||
926 | 'day' => $day, |
||
927 | 's' => $search, |
||
928 | 'start_date' => $start_date, |
||
929 | 'gateway' => $gateway, |
||
930 | 'end_date' => $end_date, |
||
931 | 'give_forms' => $form_id, |
||
932 | ); |
||
933 | |||
934 | if ( is_string( $search ) && false !== strpos( $search, 'txn:' ) ) { |
||
935 | $args['search_in_notes'] = true; |
||
936 | $args['s'] = trim( str_replace( 'txn:', '', $args['s'] ) ); |
||
937 | } |
||
938 | |||
939 | /** |
||
940 | * Filter to modify payment table argument. |
||
941 | * |
||
942 | * @since 1.8.18 |
||
943 | */ |
||
944 | $args = (array) apply_filters( 'give_payment_table_payments_query', $args ); |
||
945 | |||
946 | $p_query = new Give_Payments_Query( $args ); |
||
947 | |||
948 | return $p_query->get_payments(); |
||
949 | |||
950 | } |
||
951 | |||
952 | /** |
||
953 | * Setup the final data for the table |
||
954 | * |
||
955 | * @access public |
||
956 | * @since 1.0 |
||
957 | * @uses Give_Payment_History_Table::get_columns() |
||
958 | * @uses Give_Payment_History_Table::get_sortable_columns() |
||
959 | * @uses Give_Payment_History_Table::payments_data() |
||
960 | * @uses WP_List_Table::get_pagenum() |
||
961 | * @uses WP_List_Table::set_pagination_args() |
||
962 | * |
||
963 | * @return void |
||
964 | */ |
||
965 | public function prepare_items() { |
||
966 | |||
967 | wp_reset_vars( array( 'action', 'payment', 'orderby', 'order', 's' ) ); |
||
968 | |||
969 | $columns = $this->get_columns(); |
||
970 | $hidden = array(); // No hidden columns. |
||
971 | $sortable = $this->get_sortable_columns(); |
||
972 | $data = $this->payments_data(); |
||
973 | $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
||
0 ignored issues
–
show
|
|||
974 | |||
975 | $this->_column_headers = array( $columns, $hidden, $sortable ); |
||
976 | |||
977 | switch ( $status ) { |
||
978 | case 'publish': |
||
979 | $total_items = $this->complete_count; |
||
980 | break; |
||
981 | case 'pending': |
||
982 | $total_items = $this->pending_count; |
||
983 | break; |
||
984 | case 'processing': |
||
985 | $total_items = $this->processing_count; |
||
986 | break; |
||
987 | case 'refunded': |
||
988 | $total_items = $this->refunded_count; |
||
989 | break; |
||
990 | case 'failed': |
||
991 | $total_items = $this->failed_count; |
||
992 | break; |
||
993 | case 'revoked': |
||
994 | $total_items = $this->revoked_count; |
||
995 | break; |
||
996 | case 'cancelled': |
||
997 | $total_items = $this->cancelled_count; |
||
998 | break; |
||
999 | case 'abandoned': |
||
1000 | $total_items = $this->abandoned_count; |
||
1001 | break; |
||
1002 | case 'preapproval': |
||
1003 | $total_items = $this->preapproval_count; |
||
1004 | break; |
||
1005 | case 'any': |
||
1006 | $total_items = $this->total_count; |
||
1007 | break; |
||
1008 | default: |
||
1009 | // Retrieve the count of the non-default-Give status. |
||
1010 | $count = wp_count_posts( 'give_payment' ); |
||
1011 | $total_items = isset( $count->{$status} ) ? $count->{$status} : 0; |
||
1012 | break; |
||
1013 | } |
||
1014 | |||
1015 | $this->items = $data; |
||
1016 | |||
1017 | /** |
||
1018 | * Filter to modify total count of the pagination. |
||
1019 | * |
||
1020 | * @since 1.8.19 |
||
1021 | */ |
||
1022 | $total_items = (int) apply_filters( 'give_payment_table_pagination_total_count', $total_items, $this ); |
||
1023 | |||
1024 | $this->set_pagination_args( |
||
1025 | array( |
||
1026 | 'total_items' => $total_items, |
||
1027 | // We have to calculate the total number of items. |
||
1028 | 'per_page' => $this->per_page, |
||
1029 | // We have to determine how many items to show on a page. |
||
1030 | 'total_pages' => ceil( $total_items / $this->per_page ), |
||
1031 | // We have to calculate the total number of pages. |
||
1032 | ) |
||
1033 | ); |
||
1034 | } |
||
1035 | } |
||
1036 |