| @@ -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 | |
| @@ -41,10 +37,9 @@ | ||
| 41 | 37 | /** |
| 42 | 38 | * The current screen |
| 43 | 39 | * |
| 44 | 40 | * @since 2.0.18 |
| 45 | - * | |
| 46 | - * @var \WP_Screen | |
| 41 | + * @var object | |
| 47 | 42 | */ |
| 48 | 43 | protected $screen; |
| 49 | 44 | |
| 50 | 45 | /** |
| @@ -50,9 +45,8 @@ | ||
| 50 | 45 | /** |
| 51 | 46 | * Cached bulk actions |
| 52 | 47 | * |
| 53 | 48 | * @since 2.0.18 |
| 54 | - * | |
| 55 | 49 | * @var array |
| 56 | 50 | */ |
| 57 | 51 | private $_actions; |
| 58 | 52 | |
| @@ -59,9 +53,8 @@ | ||
| 59 | 53 | /** |
| 60 | 54 | * Cached pagination output |
| 61 | 55 | * |
| 62 | 56 | * @since 2.0.18 |
| 63 | - * | |
| 64 | 57 | * @var string |
| 65 | 58 | */ |
| 66 | 59 | private $_pagination; |
| 67 | 60 | |
| @@ -68,9 +61,8 @@ | ||
| 68 | 61 | /** |
| 69 | 62 | * The view switcher modes. |
| 70 | 63 | * |
| 71 | 64 | * @since 2.0.18 |
| 72 | - * | |
| 73 | 65 | * @var array |
| 74 | 66 | */ |
| 75 | 67 | protected $modes = array(); |
| 76 | 68 | |
| @@ -85,16 +77,10 @@ | ||
| 85 | 77 | * @var array |
| 86 | 78 | */ |
| 87 | 79 | protected $_column_headers; |
| 88 | 80 | |
| 89 | - /** | |
| 90 | - * @var array | |
| 91 | - */ | |
| 92 | 81 | protected $compat_fields = array( '_args', '_pagination_args', 'screen', '_actions', '_pagination' ); |
| 93 | 82 | |
| 94 | - /** | |
| 95 | - * @var array | |
| 96 | - */ | |
| 97 | 83 | protected $compat_methods = array( |
| 98 | 84 | 'set_pagination_args', |
| 99 | 85 | 'get_views', |
| 100 | 86 | 'get_bulk_actions', |
| @@ -112,12 +98,8 @@ | ||
| 112 | 98 | ); |
| 113 | 99 | |
| 114 | 100 | /** |
| 115 | 101 | * Construct the table object |
| 116 | - * | |
| 117 | - * @param array $args | |
| 118 | - * | |
| 119 | - * @return void | |
| 120 | 102 | */ |
| 121 | 103 | public function __construct( $args ) { |
| 122 | 104 | $args = wp_parse_args( |
| 123 | 105 | $args, |
| @@ -177,9 +159,8 @@ | ||
| 177 | 159 | * |
| 178 | 160 | * @uses FrmListHelper::set_pagination_args() |
| 179 | 161 | * |
| 180 | 162 | * @since 2.0.18 |
| 181 | - * | |
| 182 | 163 | * @abstract |
| 183 | 164 | */ |
| 184 | 165 | public function prepare_items() { |
| 185 | 166 | die( 'function FrmListHelper::prepare_items() must be over-ridden in a sub-class.' ); |
| @@ -186,19 +167,15 @@ | ||
| 186 | 167 | } |
| 187 | 168 | |
| 188 | 169 | /** |
| 189 | 170 | * @since 3.0 |
| 190 | - * | |
| 191 | - * @param array $args | |
| 192 | - * | |
| 193 | - * @return array|string | |
| 194 | 171 | */ |
| 195 | 172 | protected function get_param( $args ) { |
| 196 | 173 | return FrmAppHelper::get_simple_request( |
| 197 | 174 | array( |
| 198 | 175 | 'param' => $args['param'], |
| 199 | - 'default' => $args['default'] ?? '', | |
| 200 | - 'sanitize' => $args['sanitize'] ?? 'sanitize_title', | |
| 176 | + 'default' => isset( $args['default'] ) ? $args['default'] : '', | |
| 177 | + 'sanitize' => isset( $args['sanitize'] ) ? $args['sanitize'] : 'sanitize_title', | |
| 201 | 178 | 'type' => 'request', |
| 202 | 179 | ) |
| 203 | 180 | ); |
| 204 | 181 | } |
| @@ -290,13 +267,8 @@ | ||
| 290 | 267 | |
| 291 | 268 | FrmAppHelper::show_search_box( compact( 'text', 'input_id' ) ); |
| 292 | 269 | } |
| 293 | 270 | |
| 294 | - /** | |
| 295 | - * @param string $param_name | |
| 296 | - * | |
| 297 | - * @return void | |
| 298 | - */ | |
| 299 | 271 | private function hidden_search_inputs( $param_name ) { |
| 300 | 272 | if ( ! empty( $_REQUEST[ $param_name ] ) ) { |
| 301 | 273 | $value = sanitize_text_field( wp_unslash( $_REQUEST[ $param_name ] ) ); |
| 302 | 274 | echo '<input type="hidden" name="' . esc_attr( $param_name ) . '" value="' . esc_attr( $value ) . '" />'; |
| @@ -338,9 +310,8 @@ | ||
| 338 | 310 | return; |
| 339 | 311 | } |
| 340 | 312 | |
| 341 | 313 | echo "<ul class='subsubsub'>\n"; |
| 342 | - | |
| 343 | 314 | foreach ( $views as $class => $view ) { |
| 344 | 315 | $views[ $class ] = "\t" . '<li class="' . esc_attr( $class ) . '">' . $view; |
| 345 | 316 | } |
| 346 | 317 | echo implode( " |</li>\n", $views ) . "</li>\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| @@ -403,9 +374,8 @@ | ||
| 403 | 374 | foreach ( $this->_actions as $name => $title ) { |
| 404 | 375 | $params = array( |
| 405 | 376 | 'value' => $name, |
| 406 | 377 | ); |
| 407 | - | |
| 408 | 378 | if ( 'edit' === $name ) { |
| 409 | 379 | $params['class'] = 'hide-if-no-js'; |
| 410 | 380 | } |
| 411 | 381 | |
| @@ -419,21 +389,9 @@ | ||
| 419 | 389 | if ( isset( $this->_actions['bulk_delete'] ) ) { |
| 420 | 390 | $verify = $this->confirm_bulk_delete(); |
| 421 | 391 | |
| 422 | 392 | if ( $verify ) { |
| 423 | - $confirm_delete_attributes = array( | |
| 424 | - 'id' => 'confirm-bulk-delete-' . $which, | |
| 425 | - 'class' => 'frm-hidden', | |
| 426 | - 'tabindex' => '-1', | |
| 427 | - 'aria-hidden' => 'true', | |
| 428 | - 'href' => 'confirm-bulk-delete', | |
| 429 | - 'data-loaded-from' => $this->loaded_from(), | |
| 430 | - 'data-frmverify' => $verify, | |
| 431 | - 'data-frmverify-btn' => 'frm-button-red', | |
| 432 | - ); | |
| 433 | - | |
| 434 | - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 435 | - echo '<a ' . FrmAppHelper::array_to_html_params( $confirm_delete_attributes ) . '></a>'; | |
| 393 | + 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>"; | |
| 436 | 394 | } |
| 437 | 395 | } |
| 438 | 396 | |
| 439 | 397 | submit_button( __( 'Apply', 'formidable' ), 'action', '', false, array( 'id' => "doaction$two" ) ); |
| @@ -459,9 +417,8 @@ | ||
| 459 | 417 | return false; |
| 460 | 418 | } |
| 461 | 419 | |
| 462 | 420 | $action = $this->get_bulk_action( 'action' ); |
| 463 | - | |
| 464 | 421 | if ( $action === false ) { |
| 465 | 422 | $action = $this->get_bulk_action( 'action2' ); |
| 466 | 423 | } |
| 467 | 424 | |
| @@ -467,13 +424,8 @@ | ||
| 467 | 424 | |
| 468 | 425 | return $action; |
| 469 | 426 | } |
| 470 | 427 | |
| 471 | - /** | |
| 472 | - * @param string $action_name | |
| 473 | - * | |
| 474 | - * @return false|string | |
| 475 | - */ | |
| 476 | 428 | private function get_bulk_action( $action_name ) { |
| 477 | 429 | $action = false; |
| 478 | 430 | $action_param = $this->get_param( |
| 479 | 431 | array( |
| @@ -480,9 +432,8 @@ | ||
| 480 | 432 | 'param' => $action_name, |
| 481 | 433 | 'sanitize' => 'sanitize_text_field', |
| 482 | 434 | ) |
| 483 | 435 | ); |
| 484 | - | |
| 485 | 436 | if ( $action_param && - 1 != $action_param ) { |
| 486 | 437 | $action = $action_param; |
| 487 | 438 | } |
| 488 | 439 | |
| @@ -508,15 +459,13 @@ | ||
| 508 | 459 | return ''; |
| 509 | 460 | } |
| 510 | 461 | |
| 511 | 462 | $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">'; |
| 512 | - | |
| 513 | 463 | foreach ( $actions as $action => $link ) { |
| 514 | 464 | ++$i; |
| 515 | - $sep = $i === $action_count ? '' : ' | '; | |
| 465 | + $sep = $i == $action_count ? '' : ' | '; | |
| 516 | 466 | $out .= "<span class='$action'>$link$sep</span>"; |
| 517 | 467 | } |
| 518 | - | |
| 519 | 468 | $out .= '</div>'; |
| 520 | 469 | |
| 521 | 470 | $out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details', 'formidable' ) . '</span></button>'; |
| 522 | 471 | |
| @@ -536,9 +485,8 @@ | ||
| 536 | 485 | <div class="view-switch"> |
| 537 | 486 | <?php |
| 538 | 487 | foreach ( $this->modes as $mode => $title ) { |
| 539 | 488 | $classes = array( 'view-' . $mode ); |
| 540 | - | |
| 541 | 489 | if ( $current_mode == $mode ) { |
| 542 | 490 | $classes[] = 'current'; |
| 543 | 491 | } |
| 544 | 492 | |
| @@ -582,9 +530,8 @@ | ||
| 582 | 530 | * @return int |
| 583 | 531 | */ |
| 584 | 532 | protected function get_items_per_page( $option, $default = 20 ) { |
| 585 | 533 | $per_page = (int) get_user_option( $option ); |
| 586 | - | |
| 587 | 534 | if ( empty( $per_page ) || $per_page < 1 ) { |
| 588 | 535 | $per_page = $default; |
| 589 | 536 | } |
| 590 | 537 | |
| @@ -618,9 +565,8 @@ | ||
| 618 | 565 | |
| 619 | 566 | $total_items = $this->_pagination_args['total_items']; |
| 620 | 567 | $total_pages = $this->_pagination_args['total_pages']; |
| 621 | 568 | $infinite_scroll = false; |
| 622 | - | |
| 623 | 569 | if ( isset( $this->_pagination_args['infinite_scroll'] ) ) { |
| 624 | 570 | $infinite_scroll = $this->_pagination_args['infinite_scroll']; |
| 625 | 571 | } |
| 626 | 572 | |
| @@ -664,9 +610,8 @@ | ||
| 664 | 610 | $current, |
| 665 | 611 | strlen( $total_pages ) |
| 666 | 612 | ); |
| 667 | 613 | } |
| 668 | - | |
| 669 | 614 | $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) ); |
| 670 | 615 | |
| 671 | 616 | /* translators: %1$s: Current page number, %2$s: Total pages */ |
| 672 | 617 | $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging', 'formidable' ), $html_current_page, $html_total_pages ) . $total_pages_after; |
| @@ -689,13 +634,11 @@ | ||
| 689 | 634 | ) |
| 690 | 635 | ); |
| 691 | 636 | |
| 692 | 637 | $pagination_links_class = 'pagination-links'; |
| 693 | - | |
| 694 | 638 | if ( ! empty( $infinite_scroll ) ) { |
| 695 | 639 | $pagination_links_class = ' hide-if-js'; |
| 696 | 640 | } |
| 697 | - | |
| 698 | 641 | $output .= "\n" . '<span class="' . esc_attr( $pagination_links_class ) . '">' . implode( "\n", $page_links ) . '</span>'; |
| 699 | 642 | |
| 700 | 643 | if ( $total_pages ) { |
| 701 | 644 | $page_class = $total_pages < 2 ? ' one-page' : ''; |
| @@ -706,13 +649,8 @@ | ||
| 706 | 649 | |
| 707 | 650 | echo $this->_pagination; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 708 | 651 | } |
| 709 | 652 | |
| 710 | - /** | |
| 711 | - * @param int $total_pages | |
| 712 | - * | |
| 713 | - * @return array | |
| 714 | - */ | |
| 715 | 653 | private function disabled_pages( $total_pages ) { |
| 716 | 654 | $current = $this->get_pagenum(); |
| 717 | 655 | $disable = array( |
| 718 | 656 | 'first' => false, |
| @@ -737,13 +675,8 @@ | ||
| 737 | 675 | |
| 738 | 676 | return $disable; |
| 739 | 677 | } |
| 740 | 678 | |
| 741 | - /** | |
| 742 | - * @param string $link | |
| 743 | - * | |
| 744 | - * @return string | |
| 745 | - */ | |
| 746 | 679 | private function link_label( $link ) { |
| 747 | 680 | $labels = array( |
| 748 | 681 | 'first' => __( 'First page', 'formidable' ), |
| 749 | 682 | 'last' => __( 'Last page', 'formidable' ), |
| @@ -759,13 +692,8 @@ | ||
| 759 | 692 | |
| 760 | 693 | return remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url ); |
| 761 | 694 | } |
| 762 | 695 | |
| 763 | - /** | |
| 764 | - * @param array $atts | |
| 765 | - * | |
| 766 | - * @return string | |
| 767 | - */ | |
| 768 | 696 | private function add_page_link( $atts ) { |
| 769 | 697 | if ( $atts['disabled'] ) { |
| 770 | 698 | $link = $this->add_disabled_link( $atts['arrow'] ); |
| 771 | 699 | } else { |
| @@ -774,22 +702,12 @@ | ||
| 774 | 702 | |
| 775 | 703 | return $link; |
| 776 | 704 | } |
| 777 | 705 | |
| 778 | - /** | |
| 779 | - * @param string $label | |
| 780 | - * | |
| 781 | - * @return string | |
| 782 | - */ | |
| 783 | 706 | private function add_disabled_link( $label ) { |
| 784 | 707 | return '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">' . $label . '</span>'; |
| 785 | 708 | } |
| 786 | 709 | |
| 787 | - /** | |
| 788 | - * @param array $atts | |
| 789 | - * | |
| 790 | - * @return string | |
| 791 | - */ | |
| 792 | 710 | private function add_active_link( $atts ) { |
| 793 | 711 | $url = esc_url( add_query_arg( 'paged', $atts['number'], $this->current_url() ) ); |
| 794 | 712 | $label = $this->link_label( $atts['page'] ); |
| 795 | 713 | |
| @@ -889,9 +807,8 @@ | ||
| 889 | 807 | if ( is_array( $this->_column_headers ) ) { |
| 890 | 808 | // Back-compat for list tables that have been manually setting $_column_headers for horse reasons. |
| 891 | 809 | // In 4.3, we added a fourth argument for primary column. |
| 892 | 810 | $column_headers = array( array(), array(), array(), $this->get_primary_column_name() ); |
| 893 | - | |
| 894 | 811 | foreach ( $this->_column_headers as $key => $value ) { |
| 895 | 812 | $column_headers[ $key ] = $value; |
| 896 | 813 | } |
| 897 | 814 | |
| @@ -914,9 +831,8 @@ | ||
| 914 | 831 | */ |
| 915 | 832 | $_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns ); |
| 916 | 833 | |
| 917 | 834 | $sortable = array(); |
| 918 | - | |
| 919 | 835 | foreach ( $_sortable as $id => $data ) { |
| 920 | 836 | if ( empty( $data ) ) { |
| 921 | 837 | continue; |
| 922 | 838 | } |
| @@ -921,9 +837,8 @@ | ||
| 921 | 837 | continue; |
| 922 | 838 | } |
| 923 | 839 | |
| 924 | 840 | $data = (array) $data; |
| 925 | - | |
| 926 | 841 | if ( ! isset( $data[1] ) ) { |
| 927 | 842 | $data[1] = false; |
| 928 | 843 | } |
| 929 | 844 | |
| @@ -958,9 +873,8 @@ | ||
| 958 | 873 | * |
| 959 | 874 | * @staticvar int $cb_counter |
| 960 | 875 | * |
| 961 | 876 | * @param bool $with_id Whether to set the id attribute or not. |
| 962 | - * | |
| 963 | 877 | * @return void |
| 964 | 878 | */ |
| 965 | 879 | public function print_column_headers( $with_id = true ) { |
| 966 | 880 | list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); |
| @@ -979,10 +893,8 @@ | ||
| 979 | 893 | } else { |
| 980 | 894 | $current_order = 'asc'; |
| 981 | 895 | } |
| 982 | 896 | |
| 983 | - FrmAppController::apply_saved_sort_preference( $current_orderby, $current_order ); | |
| 984 | - | |
| 985 | 897 | if ( ! empty( $columns['cb'] ) ) { |
| 986 | 898 | static $cb_counter = 1; |
| 987 | 899 | $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All', 'formidable' ) . '</label>'; |
| 988 | 900 | $columns['cb'] .= '<input id="cb-select-all-' . esc_attr( $cb_counter ) . '" type="checkbox" />'; |
| @@ -1073,21 +985,16 @@ | ||
| 1073 | 985 | /** |
| 1074 | 986 | * Display the table |
| 1075 | 987 | * |
| 1076 | 988 | * @since 2.0.18 |
| 1077 | - * | |
| 1078 | 989 | * @param array $args |
| 1079 | - * | |
| 1080 | - * @return void | |
| 1081 | 990 | */ |
| 1082 | 991 | public function display( $args = array() ) { |
| 1083 | 992 | $singular = $this->_args['singular']; |
| 1084 | 993 | $tbody_params = array(); |
| 1085 | - | |
| 1086 | 994 | if ( $singular ) { |
| 1087 | 995 | $tbody_params['data-wp-lists'] = 'list:' . $singular; |
| 1088 | 996 | } |
| 1089 | - | |
| 1090 | 997 | if ( $this->should_display( $args, 'display-top-nav' ) ) { |
| 1091 | 998 | $this->display_tablenav( 'top' ); |
| 1092 | 999 | } |
| 1093 | 1000 | $this->screen->render_screen_reader_content( 'heading_list' ); |
| @@ -1152,9 +1059,8 @@ | ||
| 1152 | 1059 | */ |
| 1153 | 1060 | protected function display_tablenav( $which ) { |
| 1154 | 1061 | if ( 'top' === $which ) { |
| 1155 | 1062 | wp_nonce_field( 'bulk-' . $this->_args['plural'], '_wpnonce', false ); |
| 1156 | - | |
| 1157 | 1063 | if ( ! $this->has_min_items( 1 ) ) { |
| 1158 | 1064 | // Don't show bulk actions if no items. |
| 1159 | 1065 | return; |
| 1160 | 1066 | } |
| @@ -1182,12 +1088,8 @@ | ||
| 1182 | 1088 | * Use this to exclude the footer labels and bulk items. |
| 1183 | 1089 | * When close together, it feels like duplicates. |
| 1184 | 1090 | * |
| 1185 | 1091 | * @since 4.07 |
| 1186 | - * | |
| 1187 | - * @param int $limit | |
| 1188 | - * | |
| 1189 | - * @return bool | |
| 1190 | 1092 | */ |
| 1191 | 1093 | protected function has_min_items( $limit = 5 ) { |
| 1192 | 1094 | return $this->has_items() && ( $this->total_items === false || $this->total_items >= $limit ); |
| 1193 | 1095 | } |
| @@ -1241,9 +1143,8 @@ | ||
| 1241 | 1143 | list( $columns, $hidden,, $primary ) = $this->get_column_info(); |
| 1242 | 1144 | |
| 1243 | 1145 | foreach ( $columns as $column_name => $column_display_name ) { |
| 1244 | 1146 | $classes = "$column_name column-$column_name"; |
| 1245 | - | |
| 1246 | 1147 | if ( $primary === $column_name ) { |
| 1247 | 1148 | $classes .= ' has-row-actions column-primary'; |
| 1248 | 1149 | } |
| 1249 | 1150 | |
| @@ -1298,9 +1199,8 @@ | ||
| 1298 | 1199 | public function ajax_response() { |
| 1299 | 1200 | $this->prepare_items(); |
| 1300 | 1201 | |
| 1301 | 1202 | ob_start(); |
| 1302 | - | |
| 1303 | 1203 | if ( ! empty( $_REQUEST['no_placeholder'] ) ) { |
| 1304 | 1204 | $this->display_rows(); |
| 1305 | 1205 | } else { |
| 1306 | 1206 | $this->display_rows_or_placeholder(); |
| @@ -1316,9 +1216,8 @@ | ||
| 1316 | 1216 | _n( '%s item', '%s items', $this->_pagination_args['total_items'], 'formidable' ), |
| 1317 | 1217 | number_format_i18n( $this->_pagination_args['total_items'] ) |
| 1318 | 1218 | ); |
| 1319 | 1219 | } |
| 1320 | - | |
| 1321 | 1220 | if ( isset( $this->_pagination_args['total_pages'] ) ) { |
| 1322 | 1221 | $response['total_pages'] = $this->_pagination_args['total_pages']; |
| 1323 | 1222 | $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] ); |
| 1324 | 1223 | } |