| @@ -7,8 +7,9 @@ | ||
| 7 | 7 | /** |
| 8 | 8 | * The current list of items |
| 9 | 9 | * |
| 10 | 10 | * @since 2.0.18 |
| 11 | + * | |
| 11 | 12 | * @var array |
| 12 | 13 | */ |
| 13 | 14 | public $items; |
| 14 | 15 | |
| @@ -13,8 +14,9 @@ | ||
| 13 | 14 | public $items; |
| 14 | 15 | |
| 15 | 16 | /** |
| 16 | 17 | * @since 4.07 |
| 18 | + * | |
| 17 | 19 | * @var bool|int |
| 18 | 20 | */ |
| 19 | 21 | public $total_items = false; |
| 20 | 22 | |
| @@ -21,8 +23,9 @@ | ||
| 21 | 23 | /** |
| 22 | 24 | * Various information about the current table |
| 23 | 25 | * |
| 24 | 26 | * @since 2.0.18 |
| 27 | + * | |
| 25 | 28 | * @var array |
| 26 | 29 | */ |
| 27 | 30 | protected $_args; |
| 28 | 31 | |
| @@ -29,8 +32,9 @@ | ||
| 29 | 32 | /** |
| 30 | 33 | * Various information needed for displaying the pagination |
| 31 | 34 | * |
| 32 | 35 | * @since 2.0.18 |
| 36 | + * | |
| 33 | 37 | * @var array |
| 34 | 38 | */ |
| 35 | 39 | protected $_pagination_args = array(); |
| 36 | 40 | |
| @@ -46,8 +50,9 @@ | ||
| 46 | 50 | /** |
| 47 | 51 | * Cached bulk actions |
| 48 | 52 | * |
| 49 | 53 | * @since 2.0.18 |
| 54 | + * | |
| 50 | 55 | * @var array |
| 51 | 56 | */ |
| 52 | 57 | private $_actions; |
| 53 | 58 | |
| @@ -54,8 +59,9 @@ | ||
| 54 | 59 | /** |
| 55 | 60 | * Cached pagination output |
| 56 | 61 | * |
| 57 | 62 | * @since 2.0.18 |
| 63 | + * | |
| 58 | 64 | * @var string |
| 59 | 65 | */ |
| 60 | 66 | private $_pagination; |
| 61 | 67 | |
| @@ -62,8 +68,9 @@ | ||
| 62 | 68 | /** |
| 63 | 69 | * The view switcher modes. |
| 64 | 70 | * |
| 65 | 71 | * @since 2.0.18 |
| 72 | + * | |
| 66 | 73 | * @var array |
| 67 | 74 | */ |
| 68 | 75 | protected $modes = array(); |
| 69 | 76 | |
| @@ -78,10 +85,16 @@ | ||
| 78 | 85 | * @var array |
| 79 | 86 | */ |
| 80 | 87 | protected $_column_headers; |
| 81 | 88 | |
| 89 | + /** | |
| 90 | + * @var array | |
| 91 | + */ | |
| 82 | 92 | protected $compat_fields = array( '_args', '_pagination_args', 'screen', '_actions', '_pagination' ); |
| 83 | 93 | |
| 94 | + /** | |
| 95 | + * @var array | |
| 96 | + */ | |
| 84 | 97 | protected $compat_methods = array( |
| 85 | 98 | 'set_pagination_args', |
| 86 | 99 | 'get_views', |
| 87 | 100 | 'get_bulk_actions', |
| @@ -99,8 +112,12 @@ | ||
| 99 | 112 | ); |
| 100 | 113 | |
| 101 | 114 | /** |
| 102 | 115 | * Construct the table object |
| 116 | + * | |
| 117 | + * @param array $args | |
| 118 | + * | |
| 119 | + * @return void | |
| 103 | 120 | */ |
| 104 | 121 | public function __construct( $args ) { |
| 105 | 122 | $args = wp_parse_args( |
| 106 | 123 | $args, |
| @@ -132,9 +149,9 @@ | ||
| 132 | 149 | // wp_enqueue_script( 'list-table' ); |
| 133 | 150 | add_action( 'admin_footer', array( $this, '_js_vars' ) ); |
| 134 | 151 | } |
| 135 | 152 | |
| 136 | - if ( empty( $this->modes ) ) { | |
| 153 | + if ( ! $this->modes ) { | |
| 137 | 154 | $this->modes = array( |
| 138 | 155 | 'list' => __( 'List View', 'formidable' ), |
| 139 | 156 | 'excerpt' => __( 'Excerpt View', 'formidable' ), |
| 140 | 157 | ); |
| @@ -144,8 +161,11 @@ | ||
| 144 | 161 | public function ajax_user_can() { |
| 145 | 162 | return current_user_can( 'administrator' ); |
| 146 | 163 | } |
| 147 | 164 | |
| 165 | + /** | |
| 166 | + * @return array | |
| 167 | + */ | |
| 148 | 168 | public function get_columns() { |
| 149 | 169 | return array(); |
| 150 | 170 | } |
| 151 | 171 | |
| @@ -160,8 +180,9 @@ | ||
| 160 | 180 | * |
| 161 | 181 | * @uses FrmListHelper::set_pagination_args() |
| 162 | 182 | * |
| 163 | 183 | * @since 2.0.18 |
| 184 | + * | |
| 164 | 185 | * @abstract |
| 165 | 186 | */ |
| 166 | 187 | public function prepare_items() { |
| 167 | 188 | die( 'function FrmListHelper::prepare_items() must be over-ridden in a sub-class.' ); |
| @@ -168,8 +189,12 @@ | ||
| 168 | 189 | } |
| 169 | 190 | |
| 170 | 191 | /** |
| 171 | 192 | * @since 3.0 |
| 193 | + * | |
| 194 | + * @param array $args | |
| 195 | + * | |
| 196 | + * @return array|string | |
| 172 | 197 | */ |
| 173 | 198 | protected function get_param( $args ) { |
| 174 | 199 | return FrmAppHelper::get_simple_request( |
| 175 | 200 | array( |
| @@ -200,10 +225,17 @@ | ||
| 200 | 225 | $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] ); |
| 201 | 226 | } |
| 202 | 227 | |
| 203 | 228 | // Redirect if page number is invalid and headers are not already sent. |
| 204 | - if ( ! headers_sent() && ! wp_doing_ajax() && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) { | |
| 205 | - wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) ); | |
| 229 | + if ( ! wp_doing_ajax() && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) { | |
| 230 | + $url = add_query_arg( 'paged', $args['total_pages'] ); | |
| 231 | + | |
| 232 | + if ( headers_sent() ) { | |
| 233 | + FrmAppHelper::js_redirect( $url, true ); | |
| 234 | + exit; | |
| 235 | + } | |
| 236 | + | |
| 237 | + wp_safe_redirect( $url ); | |
| 206 | 238 | exit; |
| 207 | 239 | } |
| 208 | 240 | |
| 209 | 241 | $this->_pagination_args = $args; |
| @@ -219,15 +251,13 @@ | ||
| 219 | 251 | * |
| 220 | 252 | * @return int Number of items that correspond to the given pagination argument. |
| 221 | 253 | */ |
| 222 | 254 | public function get_pagination_arg( $key ) { |
| 223 | - if ( 'page' == $key ) { | |
| 255 | + if ( 'page' === $key ) { | |
| 224 | 256 | return $this->get_pagenum(); |
| 225 | 257 | } |
| 226 | 258 | |
| 227 | - if ( isset( $this->_pagination_args[ $key ] ) ) { | |
| 228 | - return $this->_pagination_args[ $key ]; | |
| 229 | - } | |
| 259 | + return $this->_pagination_args[ $key ] ?? null; | |
| 230 | 260 | } |
| 231 | 261 | |
| 232 | 262 | /** |
| 233 | 263 | * Whether the table has items to display or not |
| @@ -268,13 +298,20 @@ | ||
| 268 | 298 | |
| 269 | 299 | FrmAppHelper::show_search_box( compact( 'text', 'input_id' ) ); |
| 270 | 300 | } |
| 271 | 301 | |
| 302 | + /** | |
| 303 | + * @param string $param_name | |
| 304 | + * | |
| 305 | + * @return void | |
| 306 | + */ | |
| 272 | 307 | private function hidden_search_inputs( $param_name ) { |
| 273 | - if ( ! empty( $_REQUEST[ $param_name ] ) ) { | |
| 274 | - $value = sanitize_text_field( wp_unslash( $_REQUEST[ $param_name ] ) ); | |
| 275 | - echo '<input type="hidden" name="' . esc_attr( $param_name ) . '" value="' . esc_attr( $value ) . '" />'; | |
| 308 | + if ( empty( $_REQUEST[ $param_name ] ) ) { | |
| 309 | + return; | |
| 276 | 310 | } |
| 311 | + | |
| 312 | + $value = sanitize_text_field( wp_unslash( $_REQUEST[ $param_name ] ) ); | |
| 313 | + echo '<input type="hidden" name="' . esc_attr( $param_name ) . '" value="' . esc_attr( $value ) . '" />'; | |
| 277 | 314 | } |
| 278 | 315 | |
| 279 | 316 | /** |
| 280 | 317 | * Get an associative array ( id => link ) with the list |
| @@ -306,13 +343,14 @@ | ||
| 306 | 343 | * @param array $views An array of available list table views. |
| 307 | 344 | */ |
| 308 | 345 | $views = apply_filters( 'views_' . $this->screen->id, $views ); |
| 309 | 346 | |
| 310 | - if ( empty( $views ) ) { | |
| 347 | + if ( ! $views ) { | |
| 311 | 348 | return; |
| 312 | 349 | } |
| 313 | 350 | |
| 314 | 351 | echo "<ul class='subsubsub'>\n"; |
| 352 | + | |
| 315 | 353 | foreach ( $views as $class => $view ) { |
| 316 | 354 | $views[ $class ] = "\t" . '<li class="' . esc_attr( $class ) . '">' . $view; |
| 317 | 355 | } |
| 318 | 356 | echo implode( " |</li>\n", $views ) . "</li>\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| @@ -363,9 +401,9 @@ | ||
| 363 | 401 | } else { |
| 364 | 402 | $two = '2'; |
| 365 | 403 | }//end if |
| 366 | 404 | |
| 367 | - if ( empty( $this->_actions ) ) { | |
| 405 | + if ( ! $this->_actions ) { | |
| 368 | 406 | return; |
| 369 | 407 | } |
| 370 | 408 | |
| 371 | 409 | echo "<label for='bulk-action-selector-" . esc_attr( $which ) . "' class='screen-reader-text'>" . esc_html__( 'Select bulk action', 'formidable' ) . '</label>'; |
| @@ -375,8 +413,9 @@ | ||
| 375 | 413 | foreach ( $this->_actions as $name => $title ) { |
| 376 | 414 | $params = array( |
| 377 | 415 | 'value' => $name, |
| 378 | 416 | ); |
| 417 | + | |
| 379 | 418 | if ( 'edit' === $name ) { |
| 380 | 419 | $params['class'] = 'hide-if-no-js'; |
| 381 | 420 | } |
| 382 | 421 | |
| @@ -430,15 +469,17 @@ | ||
| 430 | 469 | return false; |
| 431 | 470 | } |
| 432 | 471 | |
| 433 | 472 | $action = $this->get_bulk_action( 'action' ); |
| 434 | - if ( $action === false ) { | |
| 435 | - $action = $this->get_bulk_action( 'action2' ); | |
| 436 | - } | |
| 437 | 473 | |
| 438 | - return $action; | |
| 474 | + return $action === false ? $this->get_bulk_action( 'action2' ) : $action; | |
| 439 | 475 | } |
| 440 | 476 | |
| 477 | + /** | |
| 478 | + * @param string $action_name | |
| 479 | + * | |
| 480 | + * @return false|string | |
| 481 | + */ | |
| 441 | 482 | private function get_bulk_action( $action_name ) { |
| 442 | 483 | $action = false; |
| 443 | 484 | $action_param = $this->get_param( |
| 444 | 485 | array( |
| @@ -445,10 +486,12 @@ | ||
| 445 | 486 | 'param' => $action_name, |
| 446 | 487 | 'sanitize' => 'sanitize_text_field', |
| 447 | 488 | ) |
| 448 | 489 | ); |
| 490 | + | |
| 491 | + // phpcs:ignore Universal.Operators.StrictComparisons | |
| 449 | 492 | if ( $action_param && - 1 != $action_param ) { |
| 450 | - $action = $action_param; | |
| 493 | + return $action_param; | |
| 451 | 494 | } |
| 452 | 495 | |
| 453 | 496 | return $action; |
| 454 | 497 | } |
| @@ -465,25 +508,24 @@ | ||
| 465 | 508 | */ |
| 466 | 509 | protected function row_actions( $actions, $always_visible = false ) { |
| 467 | 510 | $action_count = count( $actions ); |
| 468 | 511 | |
| 469 | - $i = 0; | |
| 470 | - | |
| 471 | 512 | if ( ! $action_count ) { |
| 472 | 513 | return ''; |
| 473 | 514 | } |
| 474 | 515 | |
| 516 | + $i = 0; | |
| 475 | 517 | $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">'; |
| 518 | + | |
| 476 | 519 | foreach ( $actions as $action => $link ) { |
| 477 | 520 | ++$i; |
| 478 | - $sep = $i == $action_count ? '' : ' | '; | |
| 521 | + $sep = $i === $action_count ? '' : ' | '; | |
| 479 | 522 | $out .= "<span class='$action'>$link$sep</span>"; |
| 480 | 523 | } |
| 524 | + | |
| 481 | 525 | $out .= '</div>'; |
| 482 | 526 | |
| 483 | - $out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details', 'formidable' ) . '</span></button>'; | |
| 484 | - | |
| 485 | - return $out; | |
| 527 | + return $out . ( '<button type="button" class="toggle-row"><span class="screen-reader-text">' . esc_html__( 'Show more details', 'formidable' ) . '</span></button>' ); | |
| 486 | 528 | } |
| 487 | 529 | |
| 488 | 530 | /** |
| 489 | 531 | * Display a view switcher |
| @@ -492,8 +534,9 @@ | ||
| 492 | 534 | * |
| 493 | 535 | * @param string $current_mode |
| 494 | 536 | */ |
| 495 | 537 | protected function view_switcher( $current_mode ) { |
| 538 | + // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 496 | 539 | ?> |
| 497 | 540 | <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>"/> |
| 498 | 541 | <div class="view-switch"> |
| 499 | 542 | <?php |
| @@ -498,9 +541,10 @@ | ||
| 498 | 541 | <div class="view-switch"> |
| 499 | 542 | <?php |
| 500 | 543 | foreach ( $this->modes as $mode => $title ) { |
| 501 | 544 | $classes = array( 'view-' . $mode ); |
| 502 | - if ( $current_mode == $mode ) { | |
| 545 | + | |
| 546 | + if ( $current_mode === $mode ) { | |
| 503 | 547 | $classes[] = 'current'; |
| 504 | 548 | } |
| 505 | 549 | |
| 506 | 550 | printf( |
| @@ -512,8 +556,9 @@ | ||
| 512 | 556 | } |
| 513 | 557 | ?> |
| 514 | 558 | </div> |
| 515 | 559 | <?php |
| 560 | + // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 516 | 561 | } |
| 517 | 562 | |
| 518 | 563 | /** |
| 519 | 564 | * Get the current page number |
| @@ -543,9 +588,10 @@ | ||
| 543 | 588 | * @return int |
| 544 | 589 | */ |
| 545 | 590 | protected function get_items_per_page( $option, $default = 20 ) { |
| 546 | 591 | $per_page = (int) get_user_option( $option ); |
| 547 | - if ( empty( $per_page ) || $per_page < 1 ) { | |
| 592 | + | |
| 593 | + if ( ! $per_page || $per_page < 1 ) { | |
| 548 | 594 | $per_page = $default; |
| 549 | 595 | } |
| 550 | 596 | |
| 551 | 597 | /** |
| @@ -571,9 +617,9 @@ | ||
| 571 | 617 | * |
| 572 | 618 | * @param string $which |
| 573 | 619 | */ |
| 574 | 620 | protected function pagination( $which ) { |
| 575 | - if ( empty( $this->_pagination_args ) ) { | |
| 621 | + if ( ! $this->_pagination_args ) { | |
| 576 | 622 | return; |
| 577 | 623 | } |
| 578 | 624 | |
| 579 | 625 | $total_items = $this->_pagination_args['total_items']; |
| @@ -578,8 +624,9 @@ | ||
| 578 | 624 | |
| 579 | 625 | $total_items = $this->_pagination_args['total_items']; |
| 580 | 626 | $total_pages = $this->_pagination_args['total_pages']; |
| 581 | 627 | $infinite_scroll = false; |
| 628 | + | |
| 582 | 629 | if ( isset( $this->_pagination_args['infinite_scroll'] ) ) { |
| 583 | 630 | $infinite_scroll = $this->_pagination_args['infinite_scroll']; |
| 584 | 631 | } |
| 585 | 632 | |
| @@ -585,17 +632,14 @@ | ||
| 585 | 632 | |
| 586 | 633 | /* translators: %s: Number of items */ |
| 587 | 634 | $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items, 'formidable' ), number_format_i18n( $total_items ) ) . '</span>'; |
| 588 | 635 | |
| 589 | - $current = $this->get_pagenum(); | |
| 590 | - | |
| 591 | - $page_links = array(); | |
| 592 | - | |
| 636 | + $current = $this->get_pagenum(); | |
| 637 | + $page_links = array(); | |
| 593 | 638 | $total_pages_before = '<span class="paging-input">'; |
| 594 | 639 | $total_pages_after = '</span>'; |
| 640 | + $disable = $this->disabled_pages( $total_pages ); | |
| 595 | 641 | |
| 596 | - $disable = $this->disabled_pages( $total_pages ); | |
| 597 | - | |
| 598 | 642 | $page_links[] = $this->add_page_link( |
| 599 | 643 | array( |
| 600 | 644 | 'page' => 'first', |
| 601 | 645 | 'arrow' => '«', |
| @@ -612,19 +656,20 @@ | ||
| 612 | 656 | 'disabled' => $disable['prev'], |
| 613 | 657 | ) |
| 614 | 658 | ); |
| 615 | 659 | |
| 616 | - if ( 'bottom' == $which ) { | |
| 660 | + if ( 'bottom' === $which ) { | |
| 617 | 661 | $html_current_page = $current; |
| 618 | - $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page', 'formidable' ) . '</span><span id="table-paging" class="paging-input">'; | |
| 662 | + $total_pages_before = '<span class="screen-reader-text">' . esc_html__( 'Current Page', 'formidable' ) . '</span><span id="table-paging" class="paging-input">'; | |
| 619 | 663 | } else { |
| 620 | 664 | $html_current_page = sprintf( |
| 621 | 665 | "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' />", |
| 622 | - '<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page', 'formidable' ) . '</label>', | |
| 666 | + '<label for="current-page-selector" class="screen-reader-text">' . esc_html__( 'Current Page', 'formidable' ) . '</label>', | |
| 623 | 667 | $current, |
| 624 | 668 | strlen( $total_pages ) |
| 625 | 669 | ); |
| 626 | 670 | } |
| 671 | + | |
| 627 | 672 | $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) ); |
| 628 | 673 | |
| 629 | 674 | /* translators: %1$s: Current page number, %2$s: Total pages */ |
| 630 | 675 | $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging', 'formidable' ), $html_current_page, $html_total_pages ) . $total_pages_after; |
| @@ -647,11 +692,13 @@ | ||
| 647 | 692 | ) |
| 648 | 693 | ); |
| 649 | 694 | |
| 650 | 695 | $pagination_links_class = 'pagination-links'; |
| 651 | - if ( ! empty( $infinite_scroll ) ) { | |
| 696 | + | |
| 697 | + if ( $infinite_scroll ) { | |
| 652 | 698 | $pagination_links_class = ' hide-if-js'; |
| 653 | 699 | } |
| 700 | + | |
| 654 | 701 | $output .= "\n" . '<span class="' . esc_attr( $pagination_links_class ) . '">' . implode( "\n", $page_links ) . '</span>'; |
| 655 | 702 | |
| 656 | 703 | if ( $total_pages ) { |
| 657 | 704 | $page_class = $total_pages < 2 ? ' one-page' : ''; |
| @@ -662,8 +709,13 @@ | ||
| 662 | 709 | |
| 663 | 710 | echo $this->_pagination; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 664 | 711 | } |
| 665 | 712 | |
| 713 | + /** | |
| 714 | + * @param int $total_pages | |
| 715 | + * | |
| 716 | + * @return array | |
| 717 | + */ | |
| 666 | 718 | private function disabled_pages( $total_pages ) { |
| 667 | 719 | $current = $this->get_pagenum(); |
| 668 | 720 | $disable = array( |
| 669 | 721 | 'first' => false, |
| @@ -671,19 +723,21 @@ | ||
| 671 | 723 | 'prev' => false, |
| 672 | 724 | 'next' => false, |
| 673 | 725 | ); |
| 674 | 726 | |
| 727 | + // phpcs:ignore Universal.Operators.StrictComparisons | |
| 675 | 728 | if ( $current == 1 ) { |
| 676 | 729 | $disable['first'] = true; |
| 677 | 730 | $disable['prev'] = true; |
| 678 | - } elseif ( $current == 2 ) { | |
| 731 | + } elseif ( $current == 2 ) { // phpcs:ignore Universal.Operators.StrictComparisons | |
| 679 | 732 | $disable['first'] = true; |
| 680 | 733 | } |
| 681 | 734 | |
| 735 | + // phpcs:ignore Universal.Operators.StrictComparisons | |
| 682 | 736 | if ( $current == $total_pages ) { |
| 683 | 737 | $disable['last'] = true; |
| 684 | 738 | $disable['next'] = true; |
| 685 | - } elseif ( $current == $total_pages - 1 ) { | |
| 739 | + } elseif ( $current == $total_pages - 1 ) { // phpcs:ignore Universal.Operators.StrictComparisons | |
| 686 | 740 | $disable['last'] = true; |
| 687 | 741 | } |
| 688 | 742 | |
| 689 | 743 | return $disable; |
| @@ -688,8 +742,13 @@ | ||
| 688 | 742 | |
| 689 | 743 | return $disable; |
| 690 | 744 | } |
| 691 | 745 | |
| 746 | + /** | |
| 747 | + * @param string $link | |
| 748 | + * | |
| 749 | + * @return string | |
| 750 | + */ | |
| 692 | 751 | private function link_label( $link ) { |
| 693 | 752 | $labels = array( |
| 694 | 753 | 'first' => __( 'First page', 'formidable' ), |
| 695 | 754 | 'last' => __( 'Last page', 'formidable' ), |
| @@ -701,26 +760,34 @@ | ||
| 701 | 760 | } |
| 702 | 761 | |
| 703 | 762 | private function current_url() { |
| 704 | 763 | $current_url = set_url_scheme( 'http://' . FrmAppHelper::get_server_value( 'HTTP_HOST' ) . FrmAppHelper::get_server_value( 'REQUEST_URI' ) ); |
| 705 | - | |
| 706 | 764 | return remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url ); |
| 707 | 765 | } |
| 708 | 766 | |
| 767 | + /** | |
| 768 | + * @param array $atts | |
| 769 | + * | |
| 770 | + * @return string | |
| 771 | + */ | |
| 709 | 772 | private function add_page_link( $atts ) { |
| 710 | - if ( $atts['disabled'] ) { | |
| 711 | - $link = $this->add_disabled_link( $atts['arrow'] ); | |
| 712 | - } else { | |
| 713 | - $link = $this->add_active_link( $atts ); | |
| 714 | - } | |
| 715 | - | |
| 716 | - return $link; | |
| 773 | + return $atts['disabled'] ? $this->add_disabled_link( $atts['arrow'] ) : $this->add_active_link( $atts ); | |
| 717 | 774 | } |
| 718 | 775 | |
| 776 | + /** | |
| 777 | + * @param string $label | |
| 778 | + * | |
| 779 | + * @return string | |
| 780 | + */ | |
| 719 | 781 | private function add_disabled_link( $label ) { |
| 720 | 782 | return '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">' . $label . '</span>'; |
| 721 | 783 | } |
| 722 | 784 | |
| 785 | + /** | |
| 786 | + * @param array $atts | |
| 787 | + * | |
| 788 | + * @return string | |
| 789 | + */ | |
| 723 | 790 | private function add_active_link( $atts ) { |
| 724 | 791 | $url = esc_url( add_query_arg( 'paged', $atts['number'], $this->current_url() ) ); |
| 725 | 792 | $label = $this->link_label( $atts['page'] ); |
| 726 | 793 | |
| @@ -756,14 +823,13 @@ | ||
| 756 | 823 | * |
| 757 | 824 | * @return string Name of the default primary column, in this case, an empty string. |
| 758 | 825 | */ |
| 759 | 826 | protected function get_default_primary_column_name() { |
| 760 | - $columns = $this->get_columns(); | |
| 761 | - $column = ''; | |
| 827 | + $column = ''; | |
| 762 | 828 | |
| 763 | 829 | // We need a primary defined so responsive views show something, |
| 764 | - // so let's fall back to the first non-checkbox column. | |
| 765 | - foreach ( $columns as $col => $column_name ) { | |
| 830 | + // So let's fall back to the first non-checkbox column. | |
| 831 | + foreach ( $this->get_columns() as $col => $column_name ) { | |
| 766 | 832 | if ( 'cb' === $col ) { |
| 767 | 833 | continue; |
| 768 | 834 | } |
| 769 | 835 | |
| @@ -785,9 +851,9 @@ | ||
| 785 | 851 | $columns = $this->get_columns(); |
| 786 | 852 | $default = $this->get_default_primary_column_name(); |
| 787 | 853 | |
| 788 | 854 | // If the primary column doesn't exist fall back to the |
| 789 | - // first non-checkbox column. | |
| 855 | + // First non-checkbox column. | |
| 790 | 856 | if ( ! isset( $columns[ $default ] ) ) { |
| 791 | 857 | $default = self::get_default_primary_column_name(); |
| 792 | 858 | } |
| 793 | 859 | |
| @@ -800,10 +866,10 @@ | ||
| 800 | 866 | * @param string $context Screen ID for specific list table, e.g. 'plugins'. |
| 801 | 867 | */ |
| 802 | 868 | $column = apply_filters( 'list_table_primary_column', $default, $this->screen->id ); |
| 803 | 869 | |
| 804 | - if ( empty( $column ) || ! isset( $columns[ $column ] ) ) { | |
| 805 | - $column = $default; | |
| 870 | + if ( ! $column || ! isset( $columns[ $column ] ) ) { | |
| 871 | + return $default; | |
| 806 | 872 | } |
| 807 | 873 | |
| 808 | 874 | return $column; |
| 809 | 875 | } |
| @@ -820,8 +886,9 @@ | ||
| 820 | 886 | if ( is_array( $this->_column_headers ) ) { |
| 821 | 887 | // Back-compat for list tables that have been manually setting $_column_headers for horse reasons. |
| 822 | 888 | // In 4.3, we added a fourth argument for primary column. |
| 823 | 889 | $column_headers = array( array(), array(), array(), $this->get_primary_column_name() ); |
| 890 | + | |
| 824 | 891 | foreach ( $this->_column_headers as $key => $value ) { |
| 825 | 892 | $column_headers[ $key ] = $value; |
| 826 | 893 | } |
| 827 | 894 | |
| @@ -829,10 +896,8 @@ | ||
| 829 | 896 | } |
| 830 | 897 | |
| 831 | 898 | $columns = get_column_headers( $this->screen ); |
| 832 | 899 | $hidden = get_hidden_columns( $this->screen ); |
| 833 | - | |
| 834 | - $sortable_columns = $this->get_sortable_columns(); | |
| 835 | 900 | /** |
| 836 | 901 | * Filter the list table sortable columns for a specific screen. |
| 837 | 902 | * |
| 838 | 903 | * The dynamic portion of the hook name, `$this->screen->id`, refers |
| @@ -841,17 +906,19 @@ | ||
| 841 | 906 | * @since 3.5.0 |
| 842 | 907 | * |
| 843 | 908 | * @param array $sortable_columns An array of sortable columns. |
| 844 | 909 | */ |
| 845 | - $_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns ); | |
| 910 | + $_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $this->get_sortable_columns() ); | |
| 846 | 911 | |
| 847 | 912 | $sortable = array(); |
| 913 | + | |
| 848 | 914 | foreach ( $_sortable as $id => $data ) { |
| 849 | - if ( empty( $data ) ) { | |
| 915 | + if ( ! $data ) { | |
| 850 | 916 | continue; |
| 851 | 917 | } |
| 852 | 918 | |
| 853 | 919 | $data = (array) $data; |
| 920 | + | |
| 854 | 921 | if ( ! isset( $data[1] ) ) { |
| 855 | 922 | $data[1] = false; |
| 856 | 923 | } |
| 857 | 924 | |
| @@ -886,33 +953,24 @@ | ||
| 886 | 953 | * |
| 887 | 954 | * @staticvar int $cb_counter |
| 888 | 955 | * |
| 889 | 956 | * @param bool $with_id Whether to set the id attribute or not. |
| 957 | + * | |
| 890 | 958 | * @return void |
| 891 | 959 | */ |
| 892 | - public function print_column_headers( $with_id = true ) { | |
| 960 | + public function print_column_headers( $with_id = true ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh, Generic.Metrics.CyclomaticComplexity.MaxExceeded, SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 893 | 961 | list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); |
| 894 | 962 | |
| 895 | - $current_url = set_url_scheme( 'http://' . FrmAppHelper::get_server_value( 'HTTP_HOST' ) . FrmAppHelper::get_server_value( 'REQUEST_URI' ) ); | |
| 896 | - $current_url = remove_query_arg( 'paged', $current_url ); | |
| 963 | + $current_url = set_url_scheme( 'http://' . FrmAppHelper::get_server_value( 'HTTP_HOST' ) . FrmAppHelper::get_server_value( 'REQUEST_URI' ) ); | |
| 964 | + $current_url = remove_query_arg( 'paged', $current_url ); | |
| 965 | + $current_orderby = isset( $_GET['orderby'] ) ? sanitize_text_field( wp_unslash( $_GET['orderby'] ) ) : ''; | |
| 966 | + $current_order = isset( $_GET['order'] ) && 'desc' === $_GET['order'] ? 'desc' : 'asc'; | |
| 897 | 967 | |
| 898 | - if ( isset( $_GET['orderby'] ) ) { | |
| 899 | - $current_orderby = sanitize_text_field( wp_unslash( $_GET['orderby'] ) ); | |
| 900 | - } else { | |
| 901 | - $current_orderby = ''; | |
| 902 | - } | |
| 903 | - | |
| 904 | - if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) { | |
| 905 | - $current_order = 'desc'; | |
| 906 | - } else { | |
| 907 | - $current_order = 'asc'; | |
| 908 | - } | |
| 909 | - | |
| 910 | 968 | FrmAppController::apply_saved_sort_preference( $current_orderby, $current_order ); |
| 911 | 969 | |
| 912 | 970 | if ( ! empty( $columns['cb'] ) ) { |
| 913 | 971 | static $cb_counter = 1; |
| 914 | - $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All', 'formidable' ) . '</label>'; | |
| 972 | + $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . esc_html__( 'Select All', 'formidable' ) . '</label>'; | |
| 915 | 973 | $columns['cb'] .= '<input id="cb-select-all-' . esc_attr( $cb_counter ) . '" type="checkbox" />'; |
| 916 | 974 | ++$cb_counter; |
| 917 | 975 | } |
| 918 | 976 | |
| @@ -920,8 +978,9 @@ | ||
| 920 | 978 | $class = array( 'manage-column', "column-$column_key" ); |
| 921 | 979 | $aria_sort_attr = ''; |
| 922 | 980 | $order_text = ''; |
| 923 | 981 | |
| 982 | + // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict | |
| 924 | 983 | if ( in_array( $column_key, $hidden ) ) { |
| 925 | 984 | $class[] = 'hidden'; |
| 926 | 985 | } |
| 927 | 986 | |
| @@ -937,8 +996,9 @@ | ||
| 937 | 996 | |
| 938 | 997 | if ( isset( $sortable[ $column_key ] ) ) { |
| 939 | 998 | list( $orderby, $desc_first ) = $sortable[ $column_key ]; |
| 940 | 999 | |
| 1000 | + // phpcs:ignore Universal.Operators.StrictComparisons | |
| 941 | 1001 | if ( $current_orderby == $orderby ) { |
| 942 | 1002 | // The sorted column. The `aria-sort` attribute must be set only on the sorted column. |
| 943 | 1003 | if ( 'asc' === $current_order ) { |
| 944 | 1004 | $order = 'desc'; |
| @@ -984,9 +1044,9 @@ | ||
| 984 | 1044 | $tag = 'cb' === $column_key ? 'td' : 'th'; |
| 985 | 1045 | $scope = 'th' === $tag ? 'scope="col"' : ''; |
| 986 | 1046 | $id = $with_id ? "id='" . esc_attr( $column_key ) . "'" : ''; |
| 987 | 1047 | |
| 988 | - if ( ! empty( $class ) ) { | |
| 1048 | + if ( $class ) { | |
| 989 | 1049 | $class = "class='" . esc_attr( implode( ' ', $class ) ) . "'"; |
| 990 | 1050 | } |
| 991 | 1051 | |
| 992 | 1052 | if ( ! $this->has_min_items() && ! $with_id ) { |
| @@ -1000,21 +1060,27 @@ | ||
| 1000 | 1060 | /** |
| 1001 | 1061 | * Display the table |
| 1002 | 1062 | * |
| 1003 | 1063 | * @since 2.0.18 |
| 1064 | + * | |
| 1004 | 1065 | * @param array $args |
| 1066 | + * | |
| 1067 | + * @return void | |
| 1005 | 1068 | */ |
| 1006 | 1069 | public function display( $args = array() ) { |
| 1007 | 1070 | $singular = $this->_args['singular']; |
| 1008 | 1071 | $tbody_params = array(); |
| 1072 | + | |
| 1009 | 1073 | if ( $singular ) { |
| 1010 | 1074 | $tbody_params['data-wp-lists'] = 'list:' . $singular; |
| 1011 | 1075 | } |
| 1076 | + | |
| 1012 | 1077 | if ( $this->should_display( $args, 'display-top-nav' ) ) { |
| 1013 | 1078 | $this->display_tablenav( 'top' ); |
| 1014 | 1079 | } |
| 1015 | 1080 | $this->screen->render_screen_reader_content( 'heading_list' ); |
| 1016 | 1081 | |
| 1082 | + // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 1017 | 1083 | ?> |
| 1018 | 1084 | <table class="wp-list-table <?php echo esc_attr( implode( ' ', $this->get_table_classes() ) ); ?>"> |
| 1019 | 1085 | <?php if ( $this->has_min_items( 1 ) ) { ?> |
| 1020 | 1086 | <thead> |
| @@ -1036,8 +1102,10 @@ | ||
| 1036 | 1102 | </tfoot> |
| 1037 | 1103 | <?php } ?> |
| 1038 | 1104 | </table> |
| 1039 | 1105 | <?php |
| 1106 | + // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 1107 | + | |
| 1040 | 1108 | if ( $this->should_display( $args, 'display-bottom-nav' ) ) { |
| 1041 | 1109 | $this->display_tablenav( 'bottom' ); |
| 1042 | 1110 | } |
| 1043 | 1111 | } |
| @@ -1074,16 +1142,18 @@ | ||
| 1074 | 1142 | */ |
| 1075 | 1143 | protected function display_tablenav( $which ) { |
| 1076 | 1144 | if ( 'top' === $which ) { |
| 1077 | 1145 | wp_nonce_field( 'bulk-' . $this->_args['plural'], '_wpnonce', false ); |
| 1146 | + | |
| 1078 | 1147 | if ( ! $this->has_min_items( 1 ) ) { |
| 1079 | 1148 | // Don't show bulk actions if no items. |
| 1080 | 1149 | return; |
| 1081 | 1150 | } |
| 1082 | 1151 | } elseif ( ! $this->has_min_items() ) { |
| 1083 | - // don't show the bulk actions when there aren't many rows. | |
| 1152 | + // Don't show the bulk actions when there aren't many rows. | |
| 1084 | 1153 | return; |
| 1085 | 1154 | } |
| 1155 | + // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 1086 | 1156 | ?> |
| 1087 | 1157 | <div class="tablenav <?php echo esc_attr( $which ); ?>"> |
| 1088 | 1158 | |
| 1089 | 1159 | <div class="alignleft actions bulkactions"> |
| @@ -1096,8 +1166,9 @@ | ||
| 1096 | 1166 | |
| 1097 | 1167 | <br class="clear"/> |
| 1098 | 1168 | </div> |
| 1099 | 1169 | <?php |
| 1170 | + // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 1100 | 1171 | } |
| 1101 | 1172 | |
| 1102 | 1173 | /** |
| 1103 | 1174 | * Use this to exclude the footer labels and bulk items. |
| @@ -1103,8 +1174,12 @@ | ||
| 1103 | 1174 | * Use this to exclude the footer labels and bulk items. |
| 1104 | 1175 | * When close together, it feels like duplicates. |
| 1105 | 1176 | * |
| 1106 | 1177 | * @since 4.07 |
| 1178 | + * | |
| 1179 | + * @param int $limit | |
| 1180 | + * | |
| 1181 | + * @return bool | |
| 1107 | 1182 | */ |
| 1108 | 1183 | protected function has_min_items( $limit = 5 ) { |
| 1109 | 1184 | return $this->has_items() && ( $this->total_items === false || $this->total_items >= $limit ); |
| 1110 | 1185 | } |
| @@ -1138,9 +1213,9 @@ | ||
| 1138 | 1213 | * Generates content for a single row of the table |
| 1139 | 1214 | * |
| 1140 | 1215 | * @since 2.0.18 |
| 1141 | 1216 | * |
| 1142 | - * @param object $item The current item. | |
| 1217 | + * @param stdClass $item The current item. | |
| 1143 | 1218 | */ |
| 1144 | 1219 | public function single_row( $item ) { |
| 1145 | 1220 | echo '<tr>'; |
| 1146 | 1221 | $this->single_row_columns( $item ); |
| @@ -1158,12 +1233,14 @@ | ||
| 1158 | 1233 | list( $columns, $hidden,, $primary ) = $this->get_column_info(); |
| 1159 | 1234 | |
| 1160 | 1235 | foreach ( $columns as $column_name => $column_display_name ) { |
| 1161 | 1236 | $classes = "$column_name column-$column_name"; |
| 1237 | + | |
| 1162 | 1238 | if ( $primary === $column_name ) { |
| 1163 | 1239 | $classes .= ' has-row-actions column-primary'; |
| 1164 | 1240 | } |
| 1165 | 1241 | |
| 1242 | + // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict | |
| 1166 | 1243 | if ( in_array( $column_name, $hidden ) ) { |
| 1167 | 1244 | $classes .= ' hidden'; |
| 1168 | 1245 | } |
| 1169 | 1246 | |
| @@ -1202,9 +1279,9 @@ | ||
| 1202 | 1279 | * |
| 1203 | 1280 | * @return string The row actions output. In this case, an empty string. |
| 1204 | 1281 | */ |
| 1205 | 1282 | protected function handle_row_actions( $item, $column_name, $primary ) { |
| 1206 | - return $column_name == $primary ? '<button type="button" class="toggle-row"><span class="screen-reader-text">' . esc_html__( 'Show more details', 'formidable' ) . '</span></button>' : ''; | |
| 1283 | + return $column_name == $primary ? '<button type="button" class="toggle-row"><span class="screen-reader-text">' . esc_html__( 'Show more details', 'formidable' ) . '</span></button>' : ''; // phpcs:ignore Universal.Operators.StrictComparisons, SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 1207 | 1284 | } |
| 1208 | 1285 | |
| 1209 | 1286 | /** |
| 1210 | 1287 | * Handle an incoming ajax request (called from admin-ajax.php) |
| @@ -1214,8 +1291,9 @@ | ||
| 1214 | 1291 | public function ajax_response() { |
| 1215 | 1292 | $this->prepare_items(); |
| 1216 | 1293 | |
| 1217 | 1294 | ob_start(); |
| 1295 | + | |
| 1218 | 1296 | if ( ! empty( $_REQUEST['no_placeholder'] ) ) { |
| 1219 | 1297 | $this->display_rows(); |
| 1220 | 1298 | } else { |
| 1221 | 1299 | $this->display_rows_or_placeholder(); |
| @@ -1220,10 +1298,9 @@ | ||
| 1220 | 1298 | } else { |
| 1221 | 1299 | $this->display_rows_or_placeholder(); |
| 1222 | 1300 | } |
| 1223 | 1301 | |
| 1224 | - $rows = ob_get_clean(); | |
| 1225 | - | |
| 1302 | + $rows = ob_get_clean(); | |
| 1226 | 1303 | $response = array( 'rows' => $rows ); |
| 1227 | 1304 | |
| 1228 | 1305 | if ( isset( $this->_pagination_args['total_items'] ) ) { |
| 1229 | 1306 | $response['total_items_i18n'] = sprintf( |
| @@ -1231,8 +1308,9 @@ | ||
| 1231 | 1308 | _n( '%s item', '%s items', $this->_pagination_args['total_items'], 'formidable' ), |
| 1232 | 1309 | number_format_i18n( $this->_pagination_args['total_items'] ) |
| 1233 | 1310 | ); |
| 1234 | 1311 | } |
| 1312 | + | |
| 1235 | 1313 | if ( isset( $this->_pagination_args['total_pages'] ) ) { |
| 1236 | 1314 | $response['total_pages'] = $this->_pagination_args['total_pages']; |
| 1237 | 1315 | $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] ); |
| 1238 | 1316 | } |