ravinderk /
Give
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 | * Get things started. |
||
| 121 | * |
||
| 122 | * @since 1.0 |
||
| 123 | * @uses Give_Payment_History_Table::get_payment_counts() |
||
| 124 | * @see WP_List_Table::__construct() |
||
| 125 | */ |
||
| 126 | public function __construct() { |
||
| 127 | |||
| 128 | // Set parent defaults. |
||
| 129 | parent::__construct( array( |
||
| 130 | 'singular' => give_get_forms_label_singular(), // Singular name of the listed records. |
||
| 131 | 'plural' => give_get_forms_label_plural(), // Plural name of the listed records. |
||
| 132 | 'ajax' => false, // Does this table support ajax? |
||
| 133 | ) ); |
||
| 134 | |||
| 135 | $this->process_bulk_action(); |
||
| 136 | $this->get_payment_counts(); |
||
| 137 | $this->base_url = admin_url( 'edit.php?post_type=give_forms&page=give-payment-history' ); |
||
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Add donation search filter. |
||
| 142 | * |
||
| 143 | * @return void |
||
| 144 | */ |
||
| 145 | public function advanced_filters() { |
||
| 146 | $start_date = isset( $_GET['start-date'] ) ? sanitize_text_field( $_GET['start-date'] ) : null; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 147 | $end_date = isset( $_GET['end-date'] ) ? sanitize_text_field( $_GET['end-date'] ) : null; |
||
|
0 ignored issues
–
show
|
|||
| 148 | $status = isset( $_GET['status'] ) ? sanitize_text_field( $_GET['status'] ) : ''; |
||
|
0 ignored issues
–
show
|
|||
| 149 | $donor = isset( $_GET['donor'] ) ? sanitize_text_field( $_GET['donor'] ) : ''; |
||
|
0 ignored issues
–
show
|
|||
| 150 | $search = isset( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
||
|
0 ignored issues
–
show
|
|||
| 151 | $form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0; |
||
|
0 ignored issues
–
show
|
|||
| 152 | ?> |
||
| 153 | <div id="give-payment-filters" class="give-filters"> |
||
| 154 | <?php $this->search_box( esc_html__( 'Search', 'give' ), 'give-payments' ); ?> |
||
| 155 | <div id="give-payment-date-filters"> |
||
| 156 | <div class="give-filter give-filter-half"> |
||
| 157 | <label for="start-date" |
||
| 158 | class="give-start-date-label"><?php esc_html_e( 'Start Date', 'give' ); ?></label> |
||
| 159 | <input type="text" id="start-date" name="start-date" class="give_datepicker" |
||
| 160 | value="<?php echo $start_date; ?>" placeholder="mm/dd/yyyy" /> |
||
|
0 ignored issues
–
show
|
|||
| 161 | </div> |
||
| 162 | <div class="give-filter give-filter-half"> |
||
| 163 | <label for="end-date" class="give-end-date-label"><?php esc_html_e( 'End Date', 'give' ); ?></label> |
||
| 164 | <input type="text" id="end-date" name="end-date" class="give_datepicker" |
||
| 165 | value="<?php echo $end_date; ?>" placeholder="mm/dd/yyyy" /> |
||
|
0 ignored issues
–
show
|
|||
| 166 | </div> |
||
| 167 | </div> |
||
| 168 | <div id="give-payment-form-filter" class="give-filter"> |
||
| 169 | <label for="give-donation-forms-filter" |
||
| 170 | class="give-donation-forms-filter-label"><?php esc_html_e( 'Form', 'give' ); ?></label> |
||
| 171 | <?php |
||
| 172 | // Filter Donations by Donation Forms. |
||
| 173 | echo Give()->html->forms_dropdown( array( |
||
|
0 ignored issues
–
show
|
|||
| 174 | 'name' => 'form_id', |
||
| 175 | 'id' => 'give-donation-forms-filter', |
||
| 176 | 'class' => 'give-donation-forms-filter', |
||
| 177 | 'selected' => $form_id, // Make sure to have $form_id set to 0, if there is no selection. |
||
| 178 | 'chosen' => true, |
||
| 179 | 'number' => - 1, |
||
| 180 | ) ); |
||
| 181 | ?> |
||
| 182 | </div> |
||
| 183 | |||
| 184 | <?php if ( ! empty( $status ) ) : ?> |
||
| 185 | <input type="hidden" name="status" value="<?php echo esc_attr( $status ); ?>" /> |
||
| 186 | <?php endif; ?> |
||
| 187 | |||
| 188 | <div class="give-filter"> |
||
| 189 | <?php submit_button( __( 'Apply', 'give' ), 'secondary', '', false ); ?> |
||
| 190 | <?php |
||
| 191 | // Clear active filters button. |
||
| 192 | if ( ! empty( $start_date ) || ! empty( $end_date ) || ! empty( $donor ) || ! empty( $search ) || ! empty( $status ) || ! empty( $form_id ) ) : ?> |
||
| 193 | <a href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-payment-history' ); ?>" |
||
|
0 ignored issues
–
show
|
|||
| 194 | class="button give-clear-filters-button"><?php esc_html_e( 'Clear Filters', 'give' ); ?></a> |
||
| 195 | <?php endif; ?> |
||
| 196 | </div> |
||
| 197 | </div> |
||
| 198 | |||
| 199 | <?php |
||
| 200 | } |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Show the search field |
||
| 204 | * |
||
| 205 | * @since 1.0 |
||
| 206 | * @access public |
||
| 207 | * |
||
| 208 | * @param string $text Label for the search box |
||
| 209 | * @param string $input_id ID of the search box |
||
| 210 | * |
||
| 211 | * @return void |
||
| 212 | */ |
||
| 213 | public function search_box( $text, $input_id ) { |
||
| 214 | if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
||
|
0 ignored issues
–
show
|
|||
| 215 | return; |
||
| 216 | } |
||
| 217 | |||
| 218 | $input_id = $input_id . '-search-input'; |
||
| 219 | |||
| 220 | if ( ! empty( $_REQUEST['orderby'] ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 221 | echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
||
|
0 ignored issues
–
show
|
|||
| 222 | } |
||
| 223 | if ( ! empty( $_REQUEST['order'] ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 224 | echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
||
|
0 ignored issues
–
show
|
|||
| 225 | } |
||
| 226 | ?> |
||
| 227 | <div class="give-filter give-filter-search" role="search"> |
||
| 228 | <?php |
||
| 229 | /** |
||
| 230 | * Fires in the payment history search box. |
||
| 231 | * |
||
| 232 | * Allows you to add new elements before the search box. |
||
| 233 | * |
||
| 234 | * @since 1.7 |
||
| 235 | */ |
||
| 236 | do_action( 'give_payment_history_search' ); |
||
| 237 | ?> |
||
| 238 | <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label> |
||
|
0 ignored issues
–
show
|
|||
| 239 | <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" /> |
||
|
0 ignored issues
–
show
|
|||
| 240 | <?php submit_button( $text, 'button', false, false, array( |
||
| 241 | 'ID' => 'search-submit', |
||
| 242 | ) ); ?><br /> |
||
| 243 | </div> |
||
| 244 | <?php |
||
| 245 | } |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Retrieve the view types |
||
| 249 | * |
||
| 250 | * @access public |
||
| 251 | * @since 1.0 |
||
| 252 | * @return array $views All the views available |
||
| 253 | */ |
||
| 254 | public function get_views() { |
||
| 255 | |||
| 256 | $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
||
|
0 ignored issues
–
show
|
|||
| 257 | $views = array(); |
||
| 258 | $tabs = array( |
||
| 259 | 'all' => array( |
||
| 260 | 'total_count', |
||
| 261 | esc_html__( 'All', 'give' ), |
||
| 262 | ), |
||
| 263 | 'publish' => array( |
||
| 264 | 'complete_count', |
||
| 265 | esc_html__( 'Completed', 'give' ), |
||
| 266 | ), |
||
| 267 | 'pending' => array( |
||
| 268 | 'pending_count', |
||
| 269 | esc_html__( 'Pending', 'give' ), |
||
| 270 | ), |
||
| 271 | 'processing' => array( |
||
| 272 | 'processing_count', |
||
| 273 | esc_html__( 'Processing', 'give' ), |
||
| 274 | ), |
||
| 275 | 'refunded' => array( |
||
| 276 | 'refunded_count', |
||
| 277 | esc_html__( 'Refunded', 'give' ), |
||
| 278 | ), |
||
| 279 | 'revoked' => array( |
||
| 280 | 'revoked_count', |
||
| 281 | esc_html__( 'Revoked', 'give' ), |
||
| 282 | ), |
||
| 283 | 'failed' => array( |
||
| 284 | 'failed_count', |
||
| 285 | esc_html__( 'Failed', 'give' ), |
||
| 286 | ), |
||
| 287 | 'cancelled' => array( |
||
| 288 | 'cancelled_count', |
||
| 289 | esc_html__( 'Cancelled', 'give' ), |
||
| 290 | ), |
||
| 291 | 'abandoned' => array( |
||
| 292 | 'abandoned_count', |
||
| 293 | esc_html__( 'Abandoned', 'give' ), |
||
| 294 | ), |
||
| 295 | ); |
||
| 296 | |||
| 297 | foreach ( $tabs as $key => $tab ) { |
||
| 298 | $count_key = $tab[0]; |
||
| 299 | $name = $tab[1]; |
||
| 300 | $count = $this->$count_key; |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Filter can be used to show all the status inside the donation tabs. |
||
| 304 | * |
||
| 305 | * Filter can be used to show all the status inside the donation submenu tabs return true to show all the tab. |
||
| 306 | * |
||
| 307 | * @since 1.8.12 |
||
| 308 | * |
||
| 309 | * @param string $key Current view tab value. |
||
| 310 | * @param int $count Number of donation inside the tab. |
||
| 311 | */ |
||
| 312 | if ( 'all' === $key || $key === $current || apply_filters( 'give_payments_table_show_all_status', 0 < $count, $key, $count ) ) { |
||
| 313 | |||
| 314 | $views[ $key ] = sprintf( |
||
| 315 | '<a href="%s" %s >%s <span class="count">(%s)</span></a>', |
||
| 316 | esc_url( ( 'all' === (string) $key ) ? remove_query_arg( array( 'status', 'paged' ) ) : add_query_arg( array( 'status' => $key, 'paged' => false ) ) ), |
||
| 317 | ( ( 'all' === $key && empty( $current ) ) ) ? 'class="current"' : ( $current == $key ) ? 'class="current"' : '', |
||
| 318 | $name, |
||
| 319 | $count |
||
| 320 | ); |
||
| 321 | } |
||
| 322 | } |
||
| 323 | |||
| 324 | return apply_filters( 'give_payments_table_views', $views ); |
||
| 325 | } |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Retrieve the table columns |
||
| 329 | * |
||
| 330 | * @access public |
||
| 331 | * @since 1.0 |
||
| 332 | * @return array $columns Array of all the list table columns |
||
| 333 | */ |
||
| 334 | public function get_columns() { |
||
| 335 | $columns = array( |
||
| 336 | 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text. |
||
| 337 | 'donation' => esc_html__( 'Donation', 'give' ), |
||
| 338 | 'donation_form' => esc_html__( 'Donation Form', 'give' ), |
||
| 339 | 'status' => esc_html__( 'Status', 'give' ), |
||
| 340 | 'date' => esc_html__( 'Date', 'give' ), |
||
| 341 | 'amount' => esc_html__( 'Amount', 'give' ), |
||
| 342 | 'details' => esc_html__( 'Details', 'give' ), |
||
| 343 | ); |
||
| 344 | |||
| 345 | return apply_filters( 'give_payments_table_columns', $columns ); |
||
| 346 | } |
||
| 347 | |||
| 348 | /** |
||
| 349 | * Retrieve the table's sortable columns |
||
| 350 | * |
||
| 351 | * @access public |
||
| 352 | * @since 1.0 |
||
| 353 | * @return array Array of all the sortable columns |
||
| 354 | */ |
||
| 355 | public function get_sortable_columns() { |
||
| 356 | $columns = array( |
||
| 357 | 'donation' => array( 'ID', true ), |
||
| 358 | 'donation_form' => array( 'donation_form', false ), |
||
| 359 | 'status' => array( 'status', false ), |
||
| 360 | 'amount' => array( 'amount', false ), |
||
| 361 | 'date' => array( 'date', false ), |
||
| 362 | ); |
||
| 363 | |||
| 364 | return apply_filters( 'give_payments_table_sortable_columns', $columns ); |
||
| 365 | } |
||
| 366 | |||
| 367 | /** |
||
| 368 | * Gets the name of the primary column. |
||
| 369 | * |
||
| 370 | * @since 1.5 |
||
| 371 | * @access protected |
||
| 372 | * |
||
| 373 | * @return string Name of the primary column. |
||
| 374 | */ |
||
| 375 | protected function get_primary_column_name() { |
||
| 376 | return 'donation'; |
||
| 377 | } |
||
| 378 | |||
| 379 | /** |
||
| 380 | * This function renders most of the columns in the list table. |
||
| 381 | * |
||
| 382 | * @access public |
||
| 383 | * @since 1.0 |
||
| 384 | * |
||
| 385 | * @param Give_Payment $payment Payment ID. |
||
| 386 | * @param string $column_name The name of the column |
||
| 387 | * |
||
| 388 | * @return string Column Name |
||
| 389 | */ |
||
| 390 | public function column_default( $payment, $column_name ) { |
||
| 391 | |||
| 392 | $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' ) ) ); |
||
| 393 | $row_actions = $this->get_row_actions( $payment ); |
||
| 394 | |||
| 395 | switch ( $column_name ) { |
||
| 396 | case 'donation' : |
||
| 397 | $value = sprintf( '<a href="%1$s" data-tooltip="%2$s">#%3$s</a> %4$s %5$s<br>', $single_donation_url, sprintf( esc_attr__( 'View Donation #%s', 'give' ), $payment->ID ), $payment->ID, esc_html__( 'by', 'give' ), $this->get_donor( $payment ) ); |
||
| 398 | $value .= $this->get_donor_email( $payment ); |
||
| 399 | $value .= $this->row_actions( $row_actions ); |
||
| 400 | break; |
||
| 401 | |||
| 402 | case 'amount' : |
||
| 403 | $amount = ! empty( $payment->total ) ? $payment->total : 0; |
||
| 404 | $value = give_currency_filter( give_format_amount( $amount, array( 'sanitize' => false ) ), give_get_payment_currency_code( $payment->ID ) ); |
||
| 405 | $value .= sprintf( '<br><small>%1$s %2$s</small>', __( 'via', 'give' ), give_get_gateway_admin_label( $payment->gateway ) ); |
||
| 406 | break; |
||
| 407 | |||
| 408 | case 'donation_form' : |
||
| 409 | $form_title = empty( $payment->form_title ) ? sprintf( __( 'Untitled (#%s)', 'give' ), $payment->form_id ) : $payment->form_title; |
||
| 410 | $value = '<a href="' . admin_url( 'post.php?post=' . $payment->form_id . '&action=edit' ) . '">' . $form_title . '</a>'; |
||
| 411 | $level = give_get_payment_form_title( $payment->meta, true ); |
||
| 412 | |||
| 413 | if ( ! empty( $level ) ) { |
||
| 414 | $value .= $level; |
||
| 415 | } |
||
| 416 | |||
| 417 | break; |
||
| 418 | |||
| 419 | case 'date' : |
||
| 420 | $date = strtotime( $payment->date ); |
||
| 421 | $value = date_i18n( give_date_format(), $date ); |
||
| 422 | break; |
||
| 423 | |||
| 424 | case 'status' : |
||
| 425 | $value = $this->get_payment_status( $payment ); |
||
| 426 | break; |
||
| 427 | |||
| 428 | case 'details' : |
||
| 429 | $value = sprintf( '<div class="give-payment-details-link-wrap"><a href="%1$s" class="give-payment-details-link button button-small" data-tooltip="%2$s" aria-label="%2$s"><span class="dashicons dashicons-visibility"></span></a></div>', $single_donation_url, sprintf( esc_attr__( 'View Donation #%s', 'give' ), $payment->ID ) ); |
||
| 430 | break; |
||
| 431 | |||
| 432 | default: |
||
| 433 | $value = isset( $payment->$column_name ) ? $payment->$column_name : ''; |
||
| 434 | break; |
||
| 435 | |||
| 436 | }// End switch(). |
||
| 437 | |||
| 438 | return apply_filters( 'give_payments_table_column', $value, $payment->ID, $column_name ); |
||
| 439 | } |
||
| 440 | |||
| 441 | /** |
||
| 442 | * Get donor email html. |
||
| 443 | * |
||
| 444 | * @access public |
||
| 445 | * @since 1.0 |
||
| 446 | * |
||
| 447 | * @param Give_Payment $payment Contains all the data of the payment |
||
| 448 | * |
||
| 449 | * @return string Data shown in the Email column |
||
| 450 | */ |
||
| 451 | public function get_donor_email( $payment ) { |
||
| 452 | |||
| 453 | $email = give_get_payment_user_email( $payment->ID ); |
||
| 454 | |||
| 455 | if ( empty( $email ) ) { |
||
| 456 | $email = esc_html__( '(unknown)', 'give' ); |
||
| 457 | } |
||
| 458 | |||
| 459 | $value = '<a href="mailto:' . $email . '" data-tooltip="' . esc_attr__( 'Email donor', 'give' ) . '">' . $email . '</a>'; |
||
| 460 | |||
| 461 | return apply_filters( 'give_payments_table_column', $value, $payment->ID, 'email' ); |
||
| 462 | } |
||
| 463 | |||
| 464 | /** |
||
| 465 | * Get Row Actions |
||
| 466 | * |
||
| 467 | * @since 1.6 |
||
| 468 | * |
||
| 469 | * @param Give_Payment $payment |
||
| 470 | * |
||
| 471 | * @return array $actions |
||
| 472 | */ |
||
| 473 | function get_row_actions( $payment ) { |
||
| 474 | |||
| 475 | $actions = array(); |
||
| 476 | $email = give_get_payment_user_email( $payment->ID ); |
||
| 477 | |||
| 478 | // Add search term string back to base URL. |
||
| 479 | $search_terms = ( isset( $_GET['s'] ) ? trim( $_GET['s'] ) : '' ); |
||
|
0 ignored issues
–
show
|
|||
| 480 | if ( ! empty( $search_terms ) ) { |
||
| 481 | $this->base_url = add_query_arg( 's', $search_terms, $this->base_url ); |
||
| 482 | } |
||
| 483 | |||
| 484 | if ( give_is_payment_complete( $payment->ID ) && ! empty( $email ) ) { |
||
| 485 | |||
| 486 | $actions['email_links'] = sprintf( '<a class="resend-single-donation-receipt" href="%1$s" aria-label="%2$s">%3$s</a>', wp_nonce_url( add_query_arg( array( |
||
| 487 | 'give-action' => 'email_links', |
||
| 488 | 'purchase_id' => $payment->ID, |
||
| 489 | ), $this->base_url ), 'give_payment_nonce' ), sprintf( esc_attr__( 'Resend Donation %s Receipt', 'give' ), $payment->ID ), esc_html__( 'Resend Receipt', 'give' ) ); |
||
| 490 | |||
| 491 | } |
||
| 492 | |||
| 493 | $actions['delete'] = sprintf( '<a class="delete-single-donation" href="%1$s" aria-label="%2$s">%3$s</a>', wp_nonce_url( add_query_arg( array( |
||
| 494 | 'give-action' => 'delete_payment', |
||
| 495 | 'purchase_id' => $payment->ID, |
||
| 496 | ), $this->base_url ), 'give_donation_nonce' ), sprintf( esc_attr__( 'Delete Donation %s', 'give' ), $payment->ID ), esc_html__( 'Delete', 'give' ) ); |
||
| 497 | |||
| 498 | return apply_filters( 'give_payment_row_actions', $actions, $payment ); |
||
| 499 | } |
||
| 500 | |||
| 501 | |||
| 502 | /** |
||
| 503 | * Get payment status html. |
||
| 504 | * |
||
| 505 | * @access public |
||
| 506 | * @since 1.0 |
||
| 507 | * |
||
| 508 | * @param Give_Payment $payment Contains all the data of the payment |
||
| 509 | * |
||
| 510 | * @return string Data shown in the Email column |
||
| 511 | */ |
||
| 512 | function get_payment_status( $payment ) { |
||
| 513 | $value = '<div class="give-donation-status status-' . sanitize_title( give_get_payment_status( $payment, true ) ) . '"><span class="give-donation-status-icon"></span> ' . give_get_payment_status( $payment, true ) . '</div>'; |
||
| 514 | View Code Duplication | if ( $payment->mode == 'test' ) { |
|
|
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. Loading history...
|
|||
| 515 | $value .= ' <span class="give-item-label give-item-label-orange give-test-mode-transactions-label" data-tooltip="' . esc_attr__( 'This donation was made in test mode.', 'give' ) . '">' . esc_html__( 'Test', 'give' ) . '</span>'; |
||
| 516 | } |
||
| 517 | |||
| 518 | return $value; |
||
| 519 | } |
||
| 520 | |||
| 521 | /** |
||
| 522 | * Get checkbox html. |
||
| 523 | * |
||
| 524 | * @access public |
||
| 525 | * @since 1.0 |
||
| 526 | * |
||
| 527 | * @param Give_Payment $payment Contains all the data for the checkbox column. |
||
| 528 | * |
||
| 529 | * @return string Displays a checkbox. |
||
| 530 | */ |
||
| 531 | public function column_cb( $payment ) { |
||
| 532 | return sprintf( '<input type="checkbox" name="%1$s[]" value="%2$s" />', 'payment', $payment->ID ); |
||
| 533 | } |
||
| 534 | |||
| 535 | /** |
||
| 536 | * Get payment ID html. |
||
| 537 | * |
||
| 538 | * @access public |
||
| 539 | * @since 1.0 |
||
| 540 | * |
||
| 541 | * @param Give_Payment $payment Contains all the data for the checkbox column. |
||
| 542 | * |
||
| 543 | * @return string Displays a checkbox. |
||
| 544 | */ |
||
| 545 | public function get_payment_id( $payment ) { |
||
| 546 | return '<span class="give-payment-id">' . give_get_payment_number( $payment->ID ) . '</span>'; |
||
| 547 | } |
||
| 548 | |||
| 549 | /** |
||
| 550 | * Get donor html. |
||
| 551 | * |
||
| 552 | * @access public |
||
| 553 | * @since 1.0 |
||
| 554 | * |
||
| 555 | * @param Give_Payment $payment Contains all the data of the payment |
||
| 556 | * |
||
| 557 | * @return string Data shown in the User column |
||
| 558 | */ |
||
| 559 | public function get_donor( $payment ) { |
||
| 560 | |||
| 561 | $donor_id = give_get_payment_donor_id( $payment->ID ); |
||
| 562 | $donor_billing_name = give_get_donor_name_by( $payment->ID, 'donation' ); |
||
| 563 | $donor_name = give_get_donor_name_by( $donor_id, 'donor' ); |
||
| 564 | |||
| 565 | $value = ''; |
||
| 566 | if ( ! empty( $donor_id ) ) { |
||
| 567 | |||
| 568 | // Check whether the donor name and WP_User name is same or not. |
||
| 569 | if ( sanitize_title( $donor_billing_name ) != sanitize_title( $donor_name ) ) { |
||
| 570 | $value .= $donor_billing_name . ' ('; |
||
| 571 | } |
||
| 572 | |||
| 573 | $value .= '<a href="' . esc_url( admin_url( "edit.php?post_type=give_forms&page=give-donors&view=overview&id=$donor_id" ) ) . '">' . $donor_name . '</a>'; |
||
| 574 | |||
| 575 | // Check whether the donor name and WP_User name is same or not. |
||
| 576 | if ( sanitize_title( $donor_billing_name ) != sanitize_title( $donor_name ) ) { |
||
| 577 | $value .= ')'; |
||
| 578 | } |
||
| 579 | } else { |
||
| 580 | $email = give_get_payment_user_email( $payment->ID ); |
||
| 581 | $value .= '<a href="' . esc_url( admin_url( "edit.php?post_type=give_forms&page=give-payment-history&s=$email" ) ) . '">' . esc_html__( '(donor missing)', 'give' ) . '</a>'; |
||
| 582 | } |
||
| 583 | |||
| 584 | return apply_filters( 'give_payments_table_column', $value, $payment->ID, 'donor' ); |
||
| 585 | } |
||
| 586 | |||
| 587 | /** |
||
| 588 | * Retrieve the bulk actions |
||
| 589 | * |
||
| 590 | * @access public |
||
| 591 | * @since 1.0 |
||
| 592 | * @return array $actions Array of the bulk actions |
||
| 593 | */ |
||
| 594 | public function get_bulk_actions() { |
||
| 595 | $actions = array( |
||
| 596 | 'delete' => __( 'Delete', 'give' ), |
||
| 597 | 'set-status-publish' => __( 'Set To Completed', 'give' ), |
||
| 598 | 'set-status-pending' => __( 'Set To Pending', 'give' ), |
||
| 599 | 'set-status-processing' => __( 'Set To Processing', 'give' ), |
||
| 600 | 'set-status-refunded' => __( 'Set To Refunded', 'give' ), |
||
| 601 | 'set-status-revoked' => __( 'Set To Revoked', 'give' ), |
||
| 602 | 'set-status-failed' => __( 'Set To Failed', 'give' ), |
||
| 603 | 'set-status-cancelled' => __( 'Set To Cancelled', 'give' ), |
||
| 604 | 'set-status-abandoned' => __( 'Set To Abandoned', 'give' ), |
||
| 605 | 'set-status-preapproval' => __( 'Set To Preapproval', 'give' ), |
||
| 606 | 'resend-receipt' => __( 'Resend Email Receipts', 'give' ), |
||
| 607 | ); |
||
| 608 | |||
| 609 | return apply_filters( 'give_payments_table_bulk_actions', $actions ); |
||
| 610 | } |
||
| 611 | |||
| 612 | /** |
||
| 613 | * Process the bulk actions |
||
| 614 | * |
||
| 615 | * @access public |
||
| 616 | * @since 1.0 |
||
| 617 | * @return void |
||
| 618 | */ |
||
| 619 | public function process_bulk_action() { |
||
| 620 | $ids = isset( $_GET['payment'] ) ? $_GET['payment'] : false; |
||
|
0 ignored issues
–
show
|
|||
| 621 | $action = $this->current_action(); |
||
| 622 | |||
| 623 | if ( ! is_array( $ids ) ) { |
||
| 624 | $ids = array( $ids ); |
||
| 625 | } |
||
| 626 | |||
| 627 | if ( empty( $action ) ) { |
||
| 628 | return; |
||
| 629 | } |
||
| 630 | |||
| 631 | foreach ( $ids as $id ) { |
||
| 632 | |||
| 633 | // Detect when a bulk action is being triggered. |
||
| 634 | switch ( $this->current_action() ) { |
||
| 635 | |||
| 636 | case'delete': |
||
| 637 | give_delete_donation( $id ); |
||
| 638 | break; |
||
| 639 | |||
| 640 | case 'set-status-publish': |
||
| 641 | give_update_payment_status( $id, 'publish' ); |
||
| 642 | break; |
||
| 643 | |||
| 644 | case 'set-status-pending': |
||
| 645 | give_update_payment_status( $id, 'pending' ); |
||
| 646 | break; |
||
| 647 | |||
| 648 | case 'set-status-processing': |
||
| 649 | give_update_payment_status( $id, 'processing' ); |
||
| 650 | break; |
||
| 651 | |||
| 652 | case 'set-status-refunded': |
||
| 653 | give_update_payment_status( $id, 'refunded' ); |
||
| 654 | break; |
||
| 655 | case 'set-status-revoked': |
||
| 656 | give_update_payment_status( $id, 'revoked' ); |
||
| 657 | break; |
||
| 658 | |||
| 659 | case 'set-status-failed': |
||
| 660 | give_update_payment_status( $id, 'failed' ); |
||
| 661 | break; |
||
| 662 | |||
| 663 | case 'set-status-cancelled': |
||
| 664 | give_update_payment_status( $id, 'cancelled' ); |
||
| 665 | break; |
||
| 666 | |||
| 667 | case 'set-status-abandoned': |
||
| 668 | give_update_payment_status( $id, 'abandoned' ); |
||
| 669 | break; |
||
| 670 | |||
| 671 | case 'set-status-preapproval': |
||
| 672 | give_update_payment_status( $id, 'preapproval' ); |
||
| 673 | break; |
||
| 674 | |||
| 675 | case 'resend-receipt': |
||
| 676 | give_email_donation_receipt( $id, false ); |
||
| 677 | break; |
||
| 678 | }// End switch(). |
||
| 679 | |||
| 680 | /** |
||
| 681 | * Fires after triggering bulk action on payments table. |
||
| 682 | * |
||
| 683 | * @since 1.7 |
||
| 684 | * |
||
| 685 | * @param int $id The ID of the payment. |
||
| 686 | * @param string $current_action The action that is being triggered. |
||
| 687 | */ |
||
| 688 | do_action( 'give_payments_table_do_bulk_action', $id, $this->current_action() ); |
||
| 689 | }// End foreach(). |
||
| 690 | |||
| 691 | } |
||
| 692 | |||
| 693 | /** |
||
| 694 | * Retrieve the payment counts |
||
| 695 | * |
||
| 696 | * @access public |
||
| 697 | * @since 1.0 |
||
| 698 | * @return void |
||
| 699 | */ |
||
| 700 | public function get_payment_counts() { |
||
| 701 | |||
| 702 | $args = array(); |
||
| 703 | |||
| 704 | if ( isset( $_GET['user'] ) ) { |
||
| 705 | $args['user'] = urldecode( $_GET['user'] ); |
||
|
0 ignored issues
–
show
|
|||
| 706 | } elseif ( isset( $_GET['donor'] ) ) { |
||
| 707 | $args['donor'] = absint( $_GET['donor'] ); |
||
|
0 ignored issues
–
show
|
|||
| 708 | } elseif ( isset( $_GET['s'] ) ) { |
||
| 709 | $is_user = strpos( $_GET['s'], strtolower( 'user:' ) ) !== false; |
||
|
0 ignored issues
–
show
|
|||
| 710 | if ( $is_user ) { |
||
| 711 | $args['user'] = absint( trim( str_replace( 'user:', '', strtolower( $_GET['s'] ) ) ) ); |
||
|
0 ignored issues
–
show
|
|||
| 712 | unset( $args['s'] ); |
||
| 713 | } else { |
||
| 714 | $args['s'] = sanitize_text_field( $_GET['s'] ); |
||
|
0 ignored issues
–
show
|
|||
| 715 | } |
||
| 716 | } |
||
| 717 | |||
| 718 | if ( ! empty( $_GET['start-date'] ) ) { |
||
| 719 | $args['start-date'] = urldecode( $_GET['start-date'] ); |
||
|
0 ignored issues
–
show
|
|||
| 720 | } |
||
| 721 | |||
| 722 | if ( ! empty( $_GET['end-date'] ) ) { |
||
| 723 | $args['end-date'] = urldecode( $_GET['end-date'] ); |
||
|
0 ignored issues
–
show
|
|||
| 724 | } |
||
| 725 | |||
| 726 | $args['form_id'] = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : null; |
||
|
0 ignored issues
–
show
|
|||
| 727 | |||
| 728 | $payment_count = give_count_payments( $args ); |
||
| 729 | $this->complete_count = $payment_count->publish; |
||
| 730 | $this->pending_count = $payment_count->pending; |
||
| 731 | $this->processing_count = $payment_count->processing; |
||
| 732 | $this->refunded_count = $payment_count->refunded; |
||
| 733 | $this->failed_count = $payment_count->failed; |
||
| 734 | $this->revoked_count = $payment_count->revoked; |
||
| 735 | $this->cancelled_count = $payment_count->cancelled; |
||
| 736 | $this->abandoned_count = $payment_count->abandoned; |
||
| 737 | |||
| 738 | foreach ( $payment_count as $count ) { |
||
| 739 | $this->total_count += $count; |
||
| 740 | } |
||
| 741 | } |
||
| 742 | |||
| 743 | /** |
||
| 744 | * Retrieve all the data for all the payments. |
||
| 745 | * |
||
| 746 | * @access public |
||
| 747 | * @since 1.0 |
||
| 748 | * @return array objects in array containing all the data for the payments |
||
| 749 | */ |
||
| 750 | public function payments_data() { |
||
| 751 | |||
| 752 | $per_page = $this->per_page; |
||
| 753 | $orderby = isset( $_GET['orderby'] ) ? urldecode( $_GET['orderby'] ) : 'ID'; |
||
|
0 ignored issues
–
show
|
|||
| 754 | $order = isset( $_GET['order'] ) ? $_GET['order'] : 'DESC'; |
||
|
0 ignored issues
–
show
|
|||
| 755 | $user = isset( $_GET['user'] ) ? $_GET['user'] : null; |
||
|
0 ignored issues
–
show
|
|||
| 756 | $donor = isset( $_GET['donor'] ) ? $_GET['donor'] : null; |
||
|
0 ignored issues
–
show
|
|||
| 757 | $status = isset( $_GET['status'] ) ? $_GET['status'] : give_get_payment_status_keys(); |
||
|
0 ignored issues
–
show
|
|||
| 758 | $meta_key = isset( $_GET['meta_key'] ) ? $_GET['meta_key'] : null; |
||
|
0 ignored issues
–
show
|
|||
| 759 | $year = isset( $_GET['year'] ) ? $_GET['year'] : null; |
||
|
0 ignored issues
–
show
|
|||
| 760 | $month = isset( $_GET['m'] ) ? $_GET['m'] : null; |
||
|
0 ignored issues
–
show
|
|||
| 761 | $day = isset( $_GET['day'] ) ? $_GET['day'] : null; |
||
|
0 ignored issues
–
show
|
|||
| 762 | $search = isset( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : null; |
||
|
0 ignored issues
–
show
|
|||
| 763 | $start_date = isset( $_GET['start-date'] ) ? sanitize_text_field( $_GET['start-date'] ) : null; |
||
|
0 ignored issues
–
show
|
|||
| 764 | $end_date = isset( $_GET['end-date'] ) ? sanitize_text_field( $_GET['end-date'] ) : $start_date; |
||
|
0 ignored issues
–
show
|
|||
| 765 | $form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : null; |
||
|
0 ignored issues
–
show
|
|||
| 766 | |||
| 767 | if ( ! empty( $search ) ) { |
||
| 768 | $status = 'any'; // Force all payment statuses when searching. |
||
| 769 | } |
||
| 770 | |||
| 771 | $args = array( |
||
| 772 | 'output' => 'payments', |
||
| 773 | 'number' => $per_page, |
||
| 774 | 'page' => isset( $_GET['paged'] ) ? $_GET['paged'] : null, |
||
|
0 ignored issues
–
show
|
|||
| 775 | 'orderby' => $orderby, |
||
| 776 | 'order' => $order, |
||
| 777 | 'user' => $user, |
||
| 778 | 'donor' => $donor, |
||
| 779 | 'status' => $status, |
||
| 780 | 'meta_key' => $meta_key, |
||
|
0 ignored issues
–
show
|
|||
| 781 | 'year' => $year, |
||
| 782 | 'month' => $month, |
||
| 783 | 'day' => $day, |
||
| 784 | 's' => $search, |
||
| 785 | 'start_date' => $start_date, |
||
| 786 | 'end_date' => $end_date, |
||
| 787 | 'give_forms' => $form_id, |
||
| 788 | ); |
||
| 789 | |||
| 790 | if ( is_string( $search ) && false !== strpos( $search, 'txn:' ) ) { |
||
| 791 | $args['search_in_notes'] = true; |
||
| 792 | $args['s'] = trim( str_replace( 'txn:', '', $args['s'] ) ); |
||
| 793 | } |
||
| 794 | |||
| 795 | $p_query = new Give_Payments_Query( $args ); |
||
| 796 | |||
| 797 | return $p_query->get_payments(); |
||
| 798 | |||
| 799 | } |
||
| 800 | |||
| 801 | /** |
||
| 802 | * Setup the final data for the table |
||
| 803 | * |
||
| 804 | * @access public |
||
| 805 | * @since 1.0 |
||
| 806 | * @uses Give_Payment_History_Table::get_columns() |
||
| 807 | * @uses Give_Payment_History_Table::get_sortable_columns() |
||
| 808 | * @uses Give_Payment_History_Table::payments_data() |
||
| 809 | * @uses WP_List_Table::get_pagenum() |
||
| 810 | * @uses WP_List_Table::set_pagination_args() |
||
| 811 | * @return void |
||
| 812 | */ |
||
| 813 | public function prepare_items() { |
||
| 814 | |||
| 815 | wp_reset_vars( array( 'action', 'payment', 'orderby', 'order', 's' ) ); |
||
| 816 | |||
| 817 | $columns = $this->get_columns(); |
||
| 818 | $hidden = array(); // No hidden columns. |
||
| 819 | $sortable = $this->get_sortable_columns(); |
||
| 820 | $data = $this->payments_data(); |
||
| 821 | $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
||
|
0 ignored issues
–
show
|
|||
| 822 | |||
| 823 | $this->_column_headers = array( $columns, $hidden, $sortable ); |
||
| 824 | |||
| 825 | switch ( $status ) { |
||
| 826 | case 'publish': |
||
| 827 | $total_items = $this->complete_count; |
||
| 828 | break; |
||
| 829 | case 'pending': |
||
| 830 | $total_items = $this->pending_count; |
||
| 831 | break; |
||
| 832 | case 'processing': |
||
| 833 | $total_items = $this->processing_count; |
||
| 834 | break; |
||
| 835 | case 'refunded': |
||
| 836 | $total_items = $this->refunded_count; |
||
| 837 | break; |
||
| 838 | case 'failed': |
||
| 839 | $total_items = $this->failed_count; |
||
| 840 | break; |
||
| 841 | case 'revoked': |
||
| 842 | $total_items = $this->revoked_count; |
||
| 843 | break; |
||
| 844 | case 'cancelled': |
||
| 845 | $total_items = $this->cancelled_count; |
||
| 846 | break; |
||
| 847 | case 'abandoned': |
||
| 848 | $total_items = $this->abandoned_count; |
||
| 849 | break; |
||
| 850 | case 'any': |
||
| 851 | $total_items = $this->total_count; |
||
| 852 | break; |
||
| 853 | default: |
||
| 854 | // Retrieve the count of the non-default-Give status. |
||
| 855 | $count = wp_count_posts( 'give_payment' ); |
||
| 856 | $total_items = isset( $count->{$status} ) ? $count->{$status} : 0; |
||
| 857 | break; |
||
| 858 | } |
||
| 859 | |||
| 860 | $this->items = $data; |
||
| 861 | |||
| 862 | $this->set_pagination_args( array( |
||
| 863 | 'total_items' => $total_items, |
||
| 864 | // We have to calculate the total number of items. |
||
| 865 | 'per_page' => $this->per_page, |
||
| 866 | // We have to determine how many items to show on a page. |
||
| 867 | 'total_pages' => ceil( $total_items / $this->per_page ), |
||
| 868 | // We have to calculate the total number of pages. |
||
| 869 | ) ); |
||
| 870 | } |
||
| 871 | } |
||
| 872 |