← All changes
|
includes/admin/payments/class-payments-table.php
+211
-159
2.3.0
→
4.17.0
View file →
| @@ -9,8 +9,10 @@ | ||
| 9 | 9 | * @since 1.0 |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly. |
| 13 | +use Give\Donations\Models\Donation; | |
| 14 | + | |
| 13 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | 16 | exit; |
| 15 | 17 | } |
| 16 | 18 | |
| @@ -134,13 +136,13 @@ | ||
| 134 | 136 | public function __construct() { |
| 135 | 137 | |
| 136 | 138 | // Set parent defaults. |
| 137 | 139 | 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 | - ) | |
| 140 | + [ | |
| 141 | + 'singular' => 'form', // Singular name of the listed records. | |
| 142 | + 'plural' => 'forms', // Plural name of the listed records. | |
| 143 | + 'ajax' => false, // Does this table support ajax? | |
| 144 | + ] | |
| 143 | 145 | ); |
| 144 | 146 | |
| 145 | 147 | $this->process_bulk_action(); |
| 146 | 148 | $this->get_payment_counts(); |
| @@ -152,15 +154,14 @@ | ||
| 152 | 154 | * |
| 153 | 155 | * @return void |
| 154 | 156 | */ |
| 155 | 157 | public function advanced_filters() { |
| 156 | - $start_date = isset( $_GET['start-date'] ) ? give_clean( $_GET['start-date'] ) : null; | |
| 157 | - $end_date = isset( $_GET['end-date'] ) ? give_clean( $_GET['end-date'] ) : null; | |
| 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 | - $date_format = give_date_format(); | |
| 158 | + $start_date = isset( $_GET['start-date'] ) ? strtotime( give_clean( $_GET['start-date'] ) ) : ''; | |
| 159 | + $end_date = isset( $_GET['end-date'] ) ? strtotime( give_clean( $_GET['end-date'] ) ) : ''; | |
| 160 | + $status = isset( $_GET['status'] ) ? give_clean( $_GET['status'] ) : ''; | |
| 161 | + $donor = isset( $_GET['donor'] ) ? absint( $_GET['donor'] ) : ''; | |
| 162 | + $search = isset( $_GET['s'] ) ? give_clean( $_GET['s'] ) : ''; | |
| 163 | + $form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0; | |
| 163 | 164 | ?> |
| 164 | 165 | <div id="give-payment-filters" class="give-filters"> |
| 165 | 166 | <?php $this->search_box( __( 'Search', 'give' ), 'give-payments' ); ?> |
| 166 | 167 | <div id="give-payment-date-filters"> |
| @@ -165,32 +166,46 @@ | ||
| 165 | 166 | <?php $this->search_box( __( 'Search', 'give' ), 'give-payments' ); ?> |
| 166 | 167 | <div id="give-payment-date-filters"> |
| 167 | 168 | <div class="give-filter give-filter-half"> |
| 168 | 169 | <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' ); ?>" /> | |
| 170 | + class="give-start-date-label"><?php _e( 'Start Date', 'give' ); ?></label> | |
| 171 | + <input type="text" | |
| 172 | + id="start-date" | |
| 173 | + name="start-date" | |
| 174 | + class="give_datepicker" | |
| 175 | + autocomplete="off" | |
| 176 | + value="<?php echo $start_date ? date_i18n( give_date_format(), $start_date ) : ''; ?>" | |
| 177 | + data-standard-date="<?php echo $start_date ? date( 'Y-m-d', $start_date ) : $start_date; ?>" | |
| 178 | + placeholder="<?php _e( 'Start Date', 'give' ); ?>" | |
| 179 | + /> | |
| 172 | 180 | </div> |
| 173 | 181 | <div class="give-filter give-filter-half"> |
| 174 | 182 | <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' ); ?>" /> | |
| 183 | + <input type="text" | |
| 184 | + id="end-date" | |
| 185 | + name="end-date" | |
| 186 | + class="give_datepicker" | |
| 187 | + autocomplete="off" | |
| 188 | + value="<?php echo $end_date ? date_i18n( give_date_format(), $end_date ) : ''; ?>" | |
| 189 | + data-standard-date="<?php echo $end_date ? date( 'Y-m-d', $end_date ) : $end_date; ?>" | |
| 190 | + placeholder="<?php _e( 'End Date', 'give' ); ?>" | |
| 191 | + /> | |
| 177 | 192 | </div> |
| 178 | 193 | </div> |
| 179 | 194 | <div id="give-payment-form-filter" class="give-filter"> |
| 180 | 195 | <label for="give-donation-forms-filter" |
| 181 | - class="give-donation-forms-filter-label"><?php _e( 'Form', 'give' ); ?></label> | |
| 196 | + class="give-donation-forms-filter-label"><?php _e( 'Form', 'give' ); ?></label> | |
| 182 | 197 | <?php |
| 183 | 198 | // Filter Donations by Donation Forms. |
| 184 | 199 | echo Give()->html->forms_dropdown( |
| 185 | - array( | |
| 200 | + [ | |
| 186 | 201 | 'name' => 'form_id', |
| 187 | 202 | 'id' => 'give-donation-forms-filter', |
| 188 | 203 | 'class' => 'give-donation-forms-filter', |
| 189 | 204 | 'selected' => $form_id, // Make sure to have $form_id set to 0, if there is no selection. |
| 190 | 205 | 'chosen' => true, |
| 191 | - 'number' => - 1, | |
| 192 | - ) | |
| 206 | + 'number' => 30, | |
| 207 | + ] | |
| 193 | 208 | ); |
| 194 | 209 | ?> |
| 195 | 210 | </div> |
| 196 | 211 | |
| @@ -201,9 +216,8 @@ | ||
| 201 | 216 | * @since 1.8.18 |
| 202 | 217 | */ |
| 203 | 218 | do_action( 'give_payment_table_advanced_filters' ); |
| 204 | 219 | |
| 205 | - | |
| 206 | 220 | if ( ! empty( $status ) ) { |
| 207 | 221 | echo sprintf( '<input type="hidden" name="status" value="%s"/>', esc_attr( $status ) ); |
| 208 | 222 | } |
| 209 | 223 | |
| @@ -238,12 +252,8 @@ | ||
| 238 | 252 | * |
| 239 | 253 | * @return void |
| 240 | 254 | */ |
| 241 | 255 | public function search_box( $text, $input_id ) { |
| 242 | - if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { | |
| 243 | - return; | |
| 244 | - } | |
| 245 | - | |
| 246 | 256 | $input_id = $input_id . '-search-input'; |
| 247 | 257 | |
| 248 | 258 | if ( ! empty( $_REQUEST['orderby'] ) ) { |
| 249 | 259 | echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
| @@ -262,13 +272,24 @@ | ||
| 262 | 272 | * @since 1.7 |
| 263 | 273 | */ |
| 264 | 274 | do_action( 'give_payment_history_search' ); |
| 265 | 275 | ?> |
| 266 | - <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label> | |
| 267 | - <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>"/> | |
| 268 | - <?php submit_button( $text, 'button', false, false, array( | |
| 269 | - 'ID' => 'search-submit', | |
| 270 | - ) ); ?><br/> | |
| 276 | + <label class="screen-reader-text" for="<?php echo $input_id; ?>"><?php echo $text; ?>:</label> | |
| 277 | + <input type="search" id="<?php echo $input_id; ?>" name="s" | |
| 278 | + value="<?php _admin_search_query(); ?>" | |
| 279 | + placeholder="<?php _e( 'Name, Email, or Donation ID', 'give' ); ?>" /> | |
| 280 | + <?php | |
| 281 | + submit_button( | |
| 282 | + $text, | |
| 283 | + 'button', | |
| 284 | + false, | |
| 285 | + false, | |
| 286 | + [ | |
| 287 | + 'ID' => 'search-submit', | |
| 288 | + ] | |
| 289 | + ); | |
| 290 | + ?> | |
| 291 | + <br /> | |
| 271 | 292 | </div> |
| 272 | 293 | <?php |
| 273 | 294 | } |
| 274 | 295 | |
| @@ -282,51 +303,51 @@ | ||
| 282 | 303 | */ |
| 283 | 304 | public function get_views() { |
| 284 | 305 | |
| 285 | 306 | $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
| 286 | - $views = array(); | |
| 287 | - $tabs = array( | |
| 288 | - 'all' => array( | |
| 307 | + $views = []; | |
| 308 | + $tabs = [ | |
| 309 | + 'all' => [ | |
| 289 | 310 | 'total_count', |
| 290 | 311 | __( 'All', 'give' ), |
| 291 | - ), | |
| 292 | - 'publish' => array( | |
| 312 | + ], | |
| 313 | + 'publish' => [ | |
| 293 | 314 | 'complete_count', |
| 294 | 315 | __( 'Completed', 'give' ), |
| 295 | - ), | |
| 296 | - 'pending' => array( | |
| 316 | + ], | |
| 317 | + 'pending' => [ | |
| 297 | 318 | 'pending_count', |
| 298 | 319 | __( 'Pending', 'give' ), |
| 299 | - ), | |
| 300 | - 'processing' => array( | |
| 320 | + ], | |
| 321 | + 'processing' => [ | |
| 301 | 322 | 'processing_count', |
| 302 | 323 | __( 'Processing', 'give' ), |
| 303 | - ), | |
| 304 | - 'refunded' => array( | |
| 324 | + ], | |
| 325 | + 'refunded' => [ | |
| 305 | 326 | 'refunded_count', |
| 306 | 327 | __( 'Refunded', 'give' ), |
| 307 | - ), | |
| 308 | - 'revoked' => array( | |
| 328 | + ], | |
| 329 | + 'revoked' => [ | |
| 309 | 330 | 'revoked_count', |
| 310 | 331 | __( 'Revoked', 'give' ), |
| 311 | - ), | |
| 312 | - 'failed' => array( | |
| 332 | + ], | |
| 333 | + 'failed' => [ | |
| 313 | 334 | 'failed_count', |
| 314 | 335 | __( 'Failed', 'give' ), |
| 315 | - ), | |
| 316 | - 'cancelled' => array( | |
| 336 | + ], | |
| 337 | + 'cancelled' => [ | |
| 317 | 338 | 'cancelled_count', |
| 318 | 339 | __( 'Cancelled', 'give' ), |
| 319 | - ), | |
| 320 | - 'abandoned' => array( | |
| 340 | + ], | |
| 341 | + 'abandoned' => [ | |
| 321 | 342 | 'abandoned_count', |
| 322 | 343 | __( 'Abandoned', 'give' ), |
| 323 | - ), | |
| 324 | - 'preapproval' => array( | |
| 344 | + ], | |
| 345 | + 'preapproval' => [ | |
| 325 | 346 | 'preapproval_count', |
| 326 | 347 | __( 'Preapproval Pending', 'give' ), |
| 327 | - ), | |
| 328 | - ); | |
| 348 | + ], | |
| 349 | + ]; | |
| 329 | 350 | |
| 330 | 351 | /** |
| 331 | 352 | * Remove Query from Args of the URL that are being pass to Donation Status. |
| 332 | 353 | * |
| @@ -331,9 +352,9 @@ | ||
| 331 | 352 | * Remove Query from Args of the URL that are being pass to Donation Status. |
| 332 | 353 | * |
| 333 | 354 | * @since 1.8.18 |
| 334 | 355 | */ |
| 335 | - $args = (array) apply_filters( 'give_payments_table_status_remove_query_arg', array( 'paged', '_wpnonce', '_wp_http_referer' ) ); | |
| 356 | + $args = (array) apply_filters( 'give_payments_table_status_remove_query_arg', [ 'paged', '_wpnonce', '_wp_http_referer' ] ); | |
| 336 | 357 | |
| 337 | 358 | // Build URL. |
| 338 | 359 | $staus_url = remove_query_arg( $args ); |
| 339 | 360 | |
| @@ -354,10 +375,10 @@ | ||
| 354 | 375 | */ |
| 355 | 376 | if ( 'all' === $key || $key === $current || apply_filters( 'give_payments_table_show_all_status', 0 < $count, $key, $count ) ) { |
| 356 | 377 | |
| 357 | 378 | $staus_url = 'all' === $key ? |
| 358 | - add_query_arg( array( 'status' => false ), $staus_url ) : | |
| 359 | - add_query_arg( array( 'status' => $key ), $staus_url ); | |
| 379 | + add_query_arg( [ 'status' => false ], $staus_url ) : | |
| 380 | + add_query_arg( [ 'status' => $key ], $staus_url ); | |
| 360 | 381 | |
| 361 | 382 | $views[ $key ] = sprintf( |
| 362 | 383 | '<a href="%s"%s>%s <span class="count">(%s)</span></a>', |
| 363 | 384 | esc_url( $staus_url ), |
| @@ -383,20 +404,21 @@ | ||
| 383 | 404 | * Retrieve the table columns |
| 384 | 405 | * |
| 385 | 406 | * @access public |
| 386 | 407 | * @since 1.0 |
| 408 | + * @since 4.3.0 change donation form to campaign | |
| 387 | 409 | * |
| 388 | 410 | * @return array $columns Array of all the list table columns |
| 389 | 411 | */ |
| 390 | 412 | public function get_columns() { |
| 391 | - $columns = array( | |
| 413 | + $columns = [ | |
| 392 | 414 | 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text. |
| 393 | 415 | 'donation' => __( 'Donation', 'give' ), |
| 394 | - 'donation_form' => __( 'Donation Form', 'give' ), | |
| 416 | + 'campaign' => __( 'Campaign', 'give' ), | |
| 395 | 417 | 'status' => __( 'Status', 'give' ), |
| 396 | 418 | 'date' => __( 'Date', 'give' ), |
| 397 | 419 | 'amount' => __( 'Amount', 'give' ), |
| 398 | - ); | |
| 420 | + ]; | |
| 399 | 421 | |
| 400 | 422 | if ( current_user_can( 'view_give_payments' ) ) { |
| 401 | 423 | $columns['details'] = __( 'Details', 'give' ); |
| 402 | 424 | } |
| @@ -412,15 +434,15 @@ | ||
| 412 | 434 | * |
| 413 | 435 | * @return array Array of all the sortable columns |
| 414 | 436 | */ |
| 415 | 437 | public function get_sortable_columns() { |
| 416 | - $columns = array( | |
| 417 | - 'donation' => array( 'ID', true ), | |
| 418 | - 'donation_form' => array( 'donation_form', false ), | |
| 419 | - 'status' => array( 'status', false ), | |
| 420 | - 'amount' => array( 'amount', false ), | |
| 421 | - 'date' => array( 'date', false ), | |
| 422 | - ); | |
| 438 | + $columns = [ | |
| 439 | + 'donation' => [ 'ID', true ], | |
| 440 | + 'campaign ' => [ 'campaign', false ], | |
| 441 | + 'status' => [ 'status', false ], | |
| 442 | + 'amount' => [ 'amount', false ], | |
| 443 | + 'date' => [ 'date', false ], | |
| 444 | + ]; | |
| 423 | 445 | |
| 424 | 446 | return apply_filters( 'give_payments_table_sortable_columns', $columns ); |
| 425 | 447 | } |
| 426 | 448 | |
| @@ -443,8 +465,9 @@ | ||
| 443 | 465 | * @param string $column_name The name of the column. |
| 444 | 466 | * |
| 445 | 467 | * @access public |
| 446 | 468 | * @since 1.0 |
| 469 | + * @since 4.3.0 show campaign name instead of the form name | |
| 447 | 470 | * |
| 448 | 471 | * @return string Column Name |
| 449 | 472 | */ |
| 450 | 473 | public function column_default( $payment, $column_name ) { |
| @@ -453,16 +476,18 @@ | ||
| 453 | 476 | $row_actions = $this->get_row_actions( $payment ); |
| 454 | 477 | $value = ''; |
| 455 | 478 | |
| 456 | 479 | switch ( $column_name ) { |
| 457 | - case 'donation' : | |
| 480 | + case 'donation': | |
| 458 | 481 | $serial_code = Give()->seq_donation_number->get_serial_code( $payment ); |
| 459 | 482 | if ( current_user_can( 'view_give_payments' ) ) { |
| 460 | - $value = Give()->tooltips->render_link( array( | |
| 461 | - 'label' => sprintf( __( 'View Donation %s', 'give' ), $serial_code ), | |
| 462 | - 'tag_content' => $serial_code, | |
| 463 | - 'link' => $single_donation_url, | |
| 464 | - ) ); | |
| 483 | + $value = Give()->tooltips->render_link( | |
| 484 | + [ | |
| 485 | + 'label' => sprintf( __( 'View Donation %s', 'give' ), $serial_code ), | |
| 486 | + 'tag_content' => $serial_code, | |
| 487 | + 'link' => $single_donation_url, | |
| 488 | + ] | |
| 489 | + ); | |
| 465 | 490 | } else { |
| 466 | 491 | $value = $serial_code; |
| 467 | 492 | } |
| 468 | 493 | |
| @@ -480,22 +505,14 @@ | ||
| 480 | 505 | $value = give_donation_amount( $payment, true ); |
| 481 | 506 | $value .= sprintf( '<br><small>%1$s %2$s</small>', __( 'via', 'give' ), give_get_gateway_admin_label( $payment->gateway ) ); |
| 482 | 507 | break; |
| 483 | 508 | |
| 484 | - case 'donation_form': | |
| 485 | - $form_title = empty( $payment->form_title ) ? sprintf( __( 'Untitled (#%s)', 'give' ), $payment->form_id ) : $payment->form_title; | |
| 486 | - $value = '<a href="' . admin_url( 'post.php?post=' . $payment->form_id . '&action=edit' ) . '">' . $form_title . '</a>'; | |
| 487 | - $level = give_get_donation_form_title( | |
| 488 | - $payment, | |
| 489 | - array( | |
| 490 | - 'only_level' => true, | |
| 491 | - ) | |
| 492 | - ); | |
| 509 | + case 'campaign': | |
| 493 | 510 | |
| 494 | - if ( ! empty( $level ) ) { | |
| 495 | - $value .= $level; | |
| 496 | - } | |
| 511 | + $donation = Donation::find($payment->ID); | |
| 497 | 512 | |
| 513 | + $value = '<a href="' . admin_url( 'edit.php?post_type=give_forms&page=give-campaigns&id=' . $donation->campaign->id . '&tab=overview&action=edit' ) . '">' . $donation->campaign->title . '</a>'; | |
| 514 | + | |
| 498 | 515 | break; |
| 499 | 516 | |
| 500 | 517 | case 'date': |
| 501 | 518 | $date = strtotime( $payment->date ); |
| @@ -505,19 +522,20 @@ | ||
| 505 | 522 | case 'status': |
| 506 | 523 | $value = $this->get_payment_status( $payment ); |
| 507 | 524 | break; |
| 508 | 525 | |
| 509 | - | |
| 510 | - case 'details' : | |
| 526 | + case 'details': | |
| 511 | 527 | if ( current_user_can( 'view_give_payments' ) ) { |
| 512 | - $value = Give()->tooltips->render_link( array( | |
| 513 | - 'label' => sprintf( __( 'View Donation #%s', 'give' ), $payment->ID ), | |
| 514 | - 'tag_content' => '<span class="dashicons dashicons-visibility"></span>', | |
| 515 | - 'link' => $single_donation_url, | |
| 516 | - 'attributes' => array( | |
| 517 | - 'class' => 'give-payment-details-link button button-small', | |
| 518 | - ), | |
| 519 | - ) ); | |
| 528 | + $value = Give()->tooltips->render_link( | |
| 529 | + [ | |
| 530 | + 'label' => sprintf( __( 'View Donation #%s', 'give' ), $payment->ID ), | |
| 531 | + 'tag_content' => '<span class="dashicons dashicons-visibility"></span>', | |
| 532 | + 'link' => $single_donation_url, | |
| 533 | + 'attributes' => [ | |
| 534 | + 'class' => 'give-payment-details-link button button-small', | |
| 535 | + ], | |
| 536 | + ] | |
| 537 | + ); | |
| 520 | 538 | |
| 521 | 539 | $value = "<div class=\"give-payment-details-link-wrap\">{$value}</div>"; |
| 522 | 540 | } |
| 523 | 541 | break; |
| @@ -548,15 +566,16 @@ | ||
| 548 | 566 | if ( empty( $email ) ) { |
| 549 | 567 | $email = __( '(unknown)', 'give' ); |
| 550 | 568 | } |
| 551 | 569 | |
| 570 | + $value = Give()->tooltips->render_link( | |
| 571 | + [ | |
| 572 | + 'link' => "mailto:{$email}", | |
| 573 | + 'label' => __( 'Email donor', 'give' ), | |
| 574 | + 'tag_content' => $email, | |
| 575 | + ] | |
| 576 | + ); | |
| 552 | 577 | |
| 553 | - $value = Give()->tooltips->render_link( array( | |
| 554 | - 'link' => "mailto:{$email}", | |
| 555 | - 'label' => __( 'Email donor', 'give' ), | |
| 556 | - 'tag_content' => $email, | |
| 557 | - ) ); | |
| 558 | - | |
| 559 | 578 | return apply_filters( 'give_payments_table_column', $value, $payment->ID, 'email' ); |
| 560 | 579 | } |
| 561 | 580 | |
| 562 | 581 | /** |
| @@ -569,9 +588,9 @@ | ||
| 569 | 588 | * @return array $actions |
| 570 | 589 | */ |
| 571 | 590 | function get_row_actions( $payment ) { |
| 572 | 591 | |
| 573 | - $actions = array(); | |
| 592 | + $actions = []; | |
| 574 | 593 | $email = give_get_payment_user_email( $payment->ID ); |
| 575 | 594 | |
| 576 | 595 | // Add search term string back to base URL. |
| 577 | 596 | $search_terms = ( isset( $_GET['s'] ) ? trim( $_GET['s'] ) : '' ); |
| @@ -581,16 +600,23 @@ | ||
| 581 | 600 | |
| 582 | 601 | if ( give_is_payment_complete( $payment->ID ) && ! empty( $email ) ) { |
| 583 | 602 | |
| 584 | 603 | $actions['email_links'] = sprintf( |
| 585 | - '<a class="resend-single-donation-receipt" href="%1$s" aria-label="%2$s">%3$s</a>', wp_nonce_url( | |
| 586 | - add_query_arg( | |
| 587 | - array( | |
| 588 | - 'give-action' => 'email_links', | |
| 589 | - 'purchase_id' => $payment->ID, | |
| 590 | - ), $this->base_url | |
| 591 | - ), 'give_payment_nonce' | |
| 592 | - ), sprintf( __( 'Resend Donation %s Receipt', 'give' ), $payment->ID ), __( 'Resend Receipt', 'give' ) | |
| 604 | + '<a class="resend-single-donation-receipt" href="%1$s" aria-label="%2$s">%3$s</a>', | |
| 605 | + esc_url( | |
| 606 | + wp_nonce_url( | |
| 607 | + add_query_arg( | |
| 608 | + [ | |
| 609 | + 'give-action' => 'email_links', | |
| 610 | + 'purchase_id' => $payment->ID, | |
| 611 | + ], | |
| 612 | + $this->base_url | |
| 613 | + ), | |
| 614 | + 'give_payment_nonce' | |
| 615 | + ) | |
| 616 | + ), | |
| 617 | + sprintf( __( 'Resend Donation %s Receipt', 'give' ), $payment->ID ), | |
| 618 | + __( 'Resend Receipt', 'give' ) | |
| 593 | 619 | ); |
| 594 | 620 | |
| 595 | 621 | } |
| 596 | 622 | |
| @@ -596,16 +622,22 @@ | ||
| 596 | 622 | |
| 597 | 623 | if ( current_user_can( 'view_give_payments' ) ) { |
| 598 | 624 | $actions['delete'] = sprintf( |
| 599 | 625 | '<a class="delete-single-donation" href="%1$s" aria-label="%2$s">%3$s</a>', |
| 600 | - wp_nonce_url( | |
| 601 | - add_query_arg( | |
| 602 | - array( | |
| 603 | - 'give-action' => 'delete_payment', | |
| 604 | - 'purchase_id' => $payment->ID, | |
| 605 | - ), $this->base_url | |
| 606 | - ), 'give_donation_nonce' | |
| 607 | - ), sprintf( __( 'Delete Donation %s', 'give' ), $payment->ID ), __( 'Delete', 'give' ) | |
| 626 | + esc_url( | |
| 627 | + wp_nonce_url( | |
| 628 | + add_query_arg( | |
| 629 | + [ | |
| 630 | + 'give-action' => 'delete_payment', | |
| 631 | + 'purchase_id' => $payment->ID, | |
| 632 | + ], | |
| 633 | + $this->base_url | |
| 634 | + ), | |
| 635 | + 'give_donation_nonce' | |
| 636 | + ) | |
| 637 | + ), | |
| 638 | + sprintf( __( 'Delete Donation %s', 'give' ), $payment->ID ), | |
| 639 | + __( 'Delete', 'give' ) | |
| 608 | 640 | ); |
| 609 | 641 | } |
| 610 | 642 | |
| 611 | 643 | return apply_filters( 'give_payment_row_actions', $actions, $payment ); |
| @@ -629,17 +661,18 @@ | ||
| 629 | 661 | give_get_payment_status( $payment, true ) |
| 630 | 662 | ); |
| 631 | 663 | |
| 632 | 664 | if ( $payment->mode == 'test' ) { |
| 633 | - $value .= Give()->tooltips->render_span( array( | |
| 634 | - 'label' => __( 'This donation was made in test mode.', 'give' ), | |
| 635 | - 'tag_content' => __( 'Test', 'give' ), | |
| 636 | - 'attributes' => array( | |
| 637 | - 'class' => 'give-item-label give-item-label-orange give-test-mode-transactions-label', | |
| 638 | - ), | |
| 665 | + $value .= Give()->tooltips->render_span( | |
| 666 | + [ | |
| 667 | + 'label' => __( 'This donation was made in test mode.', 'give' ), | |
| 668 | + 'tag_content' => __( 'Test', 'give' ), | |
| 669 | + 'attributes' => [ | |
| 670 | + 'class' => 'give-item-label give-item-label-orange give-test-mode-transactions-label', | |
| 671 | + ], | |
| 639 | 672 | |
| 640 | - | |
| 641 | - ) ); | |
| 673 | + ] | |
| 674 | + ); | |
| 642 | 675 | } |
| 643 | 676 | |
| 644 | 677 | if ( true === $payment->import && true === (bool) apply_filters( 'give_payment_show_importer_label', false ) ) { |
| 645 | 678 | $value .= sprintf( |
| @@ -711,9 +744,14 @@ | ||
| 711 | 744 | $value .= ')'; |
| 712 | 745 | } |
| 713 | 746 | } else { |
| 714 | 747 | $email = give_get_payment_user_email( $payment->ID ); |
| 715 | - $value .= '<a href="' . esc_url( admin_url( "edit.php?post_type=give_forms&page=give-payment-history&s=$email" ) ) . '">' . __( '(donor missing)', 'give' ) . '</a>'; | |
| 748 | + $value .= sprintf( | |
| 749 | + '<a href="%1$s">%2$s (%3$s)</a>', | |
| 750 | + esc_url( admin_url( "edit.php?post_type=give_forms&page=give-payment-history&s=$email" ) ), | |
| 751 | + give_get_donor_name_by( $payment->ID, 'donation' ), | |
| 752 | + esc_html__( 'donor missing', 'give' ) | |
| 753 | + ); | |
| 716 | 754 | } |
| 717 | 755 | |
| 718 | 756 | return apply_filters( 'give_payments_table_column', $value, $payment->ID, 'donor' ); |
| 719 | 757 | } |
| @@ -726,9 +764,9 @@ | ||
| 726 | 764 | * |
| 727 | 765 | * @return array $actions Array of the bulk actions |
| 728 | 766 | */ |
| 729 | 767 | public function get_bulk_actions() { |
| 730 | - $actions = array( | |
| 768 | + $actions = [ | |
| 731 | 769 | 'delete' => __( 'Delete', 'give' ), |
| 732 | 770 | 'set-status-publish' => __( 'Set To Completed', 'give' ), |
| 733 | 771 | 'set-status-pending' => __( 'Set To Pending', 'give' ), |
| 734 | 772 | 'set-status-processing' => __( 'Set To Processing', 'give' ), |
| @@ -738,9 +776,9 @@ | ||
| 738 | 776 | 'set-status-cancelled' => __( 'Set To Cancelled', 'give' ), |
| 739 | 777 | 'set-status-abandoned' => __( 'Set To Abandoned', 'give' ), |
| 740 | 778 | 'set-status-preapproval' => __( 'Set To Preapproval', 'give' ), |
| 741 | 779 | 'resend-receipt' => __( 'Resend Email Receipts', 'give' ), |
| 742 | - ); | |
| 780 | + ]; | |
| 743 | 781 | |
| 744 | 782 | return apply_filters( 'give_payments_table_bulk_actions', $actions ); |
| 745 | 783 | } |
| 746 | 784 | |
| @@ -746,31 +784,42 @@ | ||
| 746 | 784 | |
| 747 | 785 | /** |
| 748 | 786 | * Process the bulk actions |
| 749 | 787 | * |
| 788 | + * @since 2.25.2 Add nonce check for bulk action. | |
| 789 | + * @since 1.0 | |
| 790 | + * | |
| 750 | 791 | * @access public |
| 751 | - * @since 1.0 | |
| 752 | 792 | * |
| 753 | 793 | * @return void |
| 754 | 794 | */ |
| 755 | - public function process_bulk_action() { | |
| 756 | - $ids = isset( $_GET['payment'] ) ? $_GET['payment'] : false; | |
| 757 | - $action = $this->current_action(); | |
| 795 | + public function process_bulk_action() | |
| 796 | + { | |
| 797 | + $ids = isset($_GET['payment']) ? $_GET['payment'] : false; | |
| 798 | + $action = $this->current_action(); | |
| 758 | 799 | |
| 759 | - if ( ! is_array( $ids ) ) { | |
| 760 | - $ids = array( $ids ); | |
| 761 | - } | |
| 800 | + if ( ! is_array($ids)) { | |
| 801 | + $ids = [$ids]; | |
| 802 | + } | |
| 762 | 803 | |
| 763 | - if ( empty( $action ) ) { | |
| 764 | - return; | |
| 765 | - } | |
| 804 | + if ( | |
| 805 | + empty($action) || | |
| 806 | + ! current_user_can('edit_give_payments') | |
| 807 | + ) { | |
| 808 | + return; | |
| 809 | + } | |
| 766 | 810 | |
| 767 | - foreach ( $ids as $id ) { | |
| 811 | + give_validate_nonce($_GET['_wpnonce'] ?? '', 'bulk-forms'); | |
| 768 | 812 | |
| 813 | + foreach ($ids as $id) { | |
| 769 | 814 | // Detect when a bulk action is being triggered. |
| 770 | 815 | switch ( $this->current_action() ) { |
| 771 | 816 | |
| 772 | 817 | case 'delete': |
| 818 | + if ( ! current_user_can( 'delete_give_payments' ) ) { | |
| 819 | + return; | |
| 820 | + } | |
| 821 | + | |
| 773 | 822 | give_delete_donation( $id ); |
| 774 | 823 | break; |
| 775 | 824 | |
| 776 | 825 | case 'set-status-publish': |
| @@ -840,9 +889,9 @@ | ||
| 840 | 889 | * @return object |
| 841 | 890 | */ |
| 842 | 891 | public function get_payment_counts() { |
| 843 | 892 | |
| 844 | - $args = array(); | |
| 893 | + $args = []; | |
| 845 | 894 | |
| 846 | 895 | if ( isset( $_GET['user'] ) ) { |
| 847 | 896 | $args['user'] = urldecode( $_GET['user'] ); |
| 848 | 897 | } elseif ( isset( $_GET['donor'] ) ) { |
| @@ -894,26 +943,29 @@ | ||
| 894 | 943 | * |
| 895 | 944 | * @return array objects in array containing all the data for the payments |
| 896 | 945 | */ |
| 897 | 946 | public function payments_data() { |
| 898 | - | |
| 899 | 947 | $per_page = $this->per_page; |
| 900 | 948 | $orderby = isset( $_GET['orderby'] ) ? urldecode( $_GET['orderby'] ) : 'ID'; |
| 901 | - $order = isset( $_GET['order'] ) ? $_GET['order'] : 'DESC'; | |
| 902 | - $user = isset( $_GET['user'] ) ? $_GET['user'] : null; | |
| 903 | - $donor = isset( $_GET['donor'] ) ? $_GET['donor'] : null; | |
| 904 | - $status = isset( $_GET['status'] ) ? $_GET['status'] : give_get_payment_status_keys(); | |
| 905 | - $meta_key = isset( $_GET['meta_key'] ) ? $_GET['meta_key'] : null; | |
| 906 | - $year = isset( $_GET['year'] ) ? $_GET['year'] : null; | |
| 907 | - $month = isset( $_GET['m'] ) ? $_GET['m'] : null; | |
| 908 | - $day = isset( $_GET['day'] ) ? $_GET['day'] : null; | |
| 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; | |
| 909 | 957 | $search = isset( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : null; |
| 910 | - $start_date = isset( $_GET['start-date'] ) ? sanitize_text_field( $_GET['start-date'] ) : null; | |
| 911 | - $end_date = isset( $_GET['end-date'] ) ? sanitize_text_field( $_GET['end-date'] ) : $start_date; | |
| 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' ) ); | |
| 912 | 964 | $form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : null; |
| 913 | 965 | $gateway = ! empty( $_GET['gateway'] ) ? give_clean( $_GET['gateway'] ) : null; |
| 914 | 966 | |
| 915 | - $args = array( | |
| 967 | + $args = [ | |
| 916 | 968 | 'output' => 'payments', |
| 917 | 969 | 'number' => $per_page, |
| 918 | 970 | 'page' => isset( $_GET['paged'] ) ? $_GET['paged'] : null, |
| 919 | 971 | 'orderby' => $orderby, |
| @@ -929,9 +981,9 @@ | ||
| 929 | 981 | 'start_date' => $start_date, |
| 930 | 982 | 'gateway' => $gateway, |
| 931 | 983 | 'end_date' => $end_date, |
| 932 | 984 | 'give_forms' => $form_id, |
| 933 | - ); | |
| 985 | + ]; | |
| 934 | 986 | |
| 935 | 987 | if ( is_string( $search ) && false !== strpos( $search, 'txn:' ) ) { |
| 936 | 988 | $args['search_in_notes'] = true; |
| 937 | 989 | $args['s'] = trim( str_replace( 'txn:', '', $args['s'] ) ); |
| @@ -964,17 +1016,17 @@ | ||
| 964 | 1016 | * @return void |
| 965 | 1017 | */ |
| 966 | 1018 | public function prepare_items() { |
| 967 | 1019 | |
| 968 | - wp_reset_vars( array( 'action', 'payment', 'orderby', 'order', 's' ) ); | |
| 1020 | + wp_reset_vars( [ 'action', 'payment', 'orderby', 'order', 's' ] ); | |
| 969 | 1021 | |
| 970 | 1022 | $columns = $this->get_columns(); |
| 971 | - $hidden = array(); // No hidden columns. | |
| 1023 | + $hidden = []; // No hidden columns. | |
| 972 | 1024 | $sortable = $this->get_sortable_columns(); |
| 973 | 1025 | $data = $this->payments_data(); |
| 974 | 1026 | $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
| 975 | 1027 | |
| 976 | - $this->_column_headers = array( $columns, $hidden, $sortable ); | |
| 1028 | + $this->_column_headers = [ $columns, $hidden, $sortable ]; | |
| 977 | 1029 | |
| 978 | 1030 | switch ( $status ) { |
| 979 | 1031 | case 'publish': |
| 980 | 1032 | $total_items = $this->complete_count; |
| @@ -1022,9 +1074,9 @@ | ||
| 1022 | 1074 | */ |
| 1023 | 1075 | $total_items = (int) apply_filters( 'give_payment_table_pagination_total_count', $total_items, $this ); |
| 1024 | 1076 | |
| 1025 | 1077 | $this->set_pagination_args( |
| 1026 | - array( | |
| 1078 | + [ | |
| 1027 | 1079 | 'total_items' => $total_items, |
| 1028 | 1080 | // We have to calculate the total number of items. |
| 1029 | 1081 | 'per_page' => $this->per_page, |
| 1030 | 1082 | // We have to determine how many items to show on a page. |
| @@ -1029,8 +1081,8 @@ | ||
| 1029 | 1081 | 'per_page' => $this->per_page, |
| 1030 | 1082 | // We have to determine how many items to show on a page. |
| 1031 | 1083 | 'total_pages' => ceil( $total_items / $this->per_page ), |
| 1032 | 1084 | // We have to calculate the total number of pages. |
| 1033 | - ) | |
| 1085 | + ] | |
| 1034 | 1086 | ); |
| 1035 | 1087 | } |
| 1036 | 1088 | } |