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