| @@ -13,13 +13,8 @@ | ||
| 13 | 13 | */ |
| 14 | 14 | public $items; |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * @since 4.07 | |
| 18 | - */ | |
| 19 | - public $total_items = false; | |
| 20 | - | |
| 21 | - /** | |
| 22 | 17 | * Various information about the current table |
| 23 | 18 | * |
| 24 | 19 | * @since 2.0.18 |
| 25 | 20 | * @var array |
| @@ -71,12 +66,12 @@ | ||
| 71 | 66 | */ |
| 72 | 67 | protected $modes = array(); |
| 73 | 68 | |
| 74 | 69 | /** |
| 75 | - * | |
| 76 | - * @var array | |
| 77 | - */ | |
| 78 | - protected $params; | |
| 70 | + * | |
| 71 | + * @var array | |
| 72 | + */ | |
| 73 | + protected $params; | |
| 79 | 74 | |
| 80 | 75 | /** |
| 81 | 76 | * Stores the value returned by ->get_column_info() |
| 82 | 77 | * |
| @@ -85,37 +80,22 @@ | ||
| 85 | 80 | protected $_column_headers; |
| 86 | 81 | |
| 87 | 82 | protected $compat_fields = array( '_args', '_pagination_args', 'screen', '_actions', '_pagination' ); |
| 88 | 83 | |
| 89 | - protected $compat_methods = array( | |
| 90 | - 'set_pagination_args', | |
| 91 | - 'get_views', | |
| 92 | - 'get_bulk_actions', | |
| 93 | - 'bulk_actions', | |
| 94 | - 'row_actions', | |
| 95 | - 'view_switcher', | |
| 96 | - 'get_items_per_page', | |
| 97 | - 'pagination', | |
| 98 | - 'get_sortable_columns', | |
| 99 | - 'get_column_info', | |
| 100 | - 'get_table_classes', | |
| 101 | - 'display_tablenav', | |
| 102 | - 'extra_tablenav', | |
| 103 | - 'single_row_columns', | |
| 104 | - ); | |
| 84 | + protected $compat_methods = array( 'set_pagination_args', 'get_views', 'get_bulk_actions', 'bulk_actions', 'row_actions', 'view_switcher', 'get_items_per_page', 'pagination', 'get_sortable_columns', 'get_column_info', 'get_table_classes', 'display_tablenav', 'extra_tablenav', 'single_row_columns' ); | |
| 105 | 85 | |
| 106 | 86 | /** |
| 107 | - * Construct the table object | |
| 108 | - */ | |
| 87 | + * Construct the table object | |
| 88 | + */ | |
| 109 | 89 | public function __construct( $args ) { |
| 110 | 90 | $args = wp_parse_args( |
| 111 | 91 | $args, |
| 112 | 92 | array( |
| 113 | - 'params' => array(), | |
| 114 | - 'plural' => '', | |
| 93 | + 'params' => array(), | |
| 94 | + 'plural' => '', | |
| 115 | 95 | 'singular' => '', |
| 116 | - 'ajax' => false, | |
| 117 | - 'screen' => null, | |
| 96 | + 'ajax' => false, | |
| 97 | + 'screen' => null, | |
| 118 | 98 | ) |
| 119 | 99 | ); |
| 120 | 100 | |
| 121 | 101 | $this->params = $args['params']; |
| @@ -127,9 +107,9 @@ | ||
| 127 | 107 | if ( ! $args['plural'] ) { |
| 128 | 108 | $args['plural'] = $this->screen->base; |
| 129 | 109 | } |
| 130 | 110 | |
| 131 | - $args['plural'] = sanitize_key( $args['plural'] ); | |
| 111 | + $args['plural'] = sanitize_key( $args['plural'] ); | |
| 132 | 112 | $args['singular'] = sanitize_key( $args['singular'] ); |
| 133 | 113 | |
| 134 | 114 | $this->_args = $args; |
| 135 | 115 | |
| @@ -155,9 +135,9 @@ | ||
| 155 | 135 | } |
| 156 | 136 | |
| 157 | 137 | public function display_rows() { |
| 158 | 138 | foreach ( $this->items as $item ) { |
| 159 | - echo "\n\t", $this->single_row( $item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 139 | + echo "\n\t", $this->single_row( $item ); // WPCS: XSS ok. | |
| 160 | 140 | } |
| 161 | 141 | } |
| 162 | 142 | |
| 163 | 143 | /** |
| @@ -190,9 +170,8 @@ | ||
| 190 | 170 | /** |
| 191 | 171 | * An internal method that sets all the necessary pagination arguments |
| 192 | 172 | * |
| 193 | 173 | * @param array $args An associative array with information about the pagination |
| 194 | - * | |
| 195 | 174 | * @access protected |
| 196 | 175 | * |
| 197 | 176 | * @param array|string $args |
| 198 | 177 | */ |
| @@ -201,9 +180,9 @@ | ||
| 201 | 180 | $args, |
| 202 | 181 | array( |
| 203 | 182 | 'total_items' => 0, |
| 204 | 183 | 'total_pages' => 0, |
| 205 | - 'per_page' => 0, | |
| 184 | + 'per_page' => 0, | |
| 206 | 185 | ) |
| 207 | 186 | ); |
| 208 | 187 | |
| 209 | 188 | if ( ! $args['total_pages'] && $args['per_page'] > 0 ) { |
| @@ -210,9 +189,9 @@ | ||
| 210 | 189 | $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] ); |
| 211 | 190 | } |
| 212 | 191 | |
| 213 | 192 | // Redirect if page number is invalid and headers are not already sent. |
| 214 | - if ( ! headers_sent() && ! wp_doing_ajax() && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) { | |
| 193 | + if ( ! headers_sent() && ! FrmAppHelper::wp_doing_ajax() && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) { | |
| 215 | 194 | wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) ); |
| 216 | 195 | exit; |
| 217 | 196 | } |
| 218 | 197 | |
| @@ -226,9 +205,8 @@ | ||
| 226 | 205 | * @access public |
| 227 | 206 | * |
| 228 | 207 | * @param string $key Pagination argument to retrieve. Common values include 'total_items', |
| 229 | 208 | * 'total_pages', 'per_page', or 'infinite_scroll'. |
| 230 | - * | |
| 231 | 209 | * @return int Number of items that correspond to the given pagination argument. |
| 232 | 210 | */ |
| 233 | 211 | public function get_pagination_arg( $key ) { |
| 234 | 212 | if ( 'page' == $key ) { |
| @@ -279,15 +257,14 @@ | ||
| 279 | 257 | foreach ( array( 'orderby', 'order' ) as $search_params ) { |
| 280 | 258 | $this->hidden_search_inputs( $search_params ); |
| 281 | 259 | } |
| 282 | 260 | |
| 283 | - FrmAppHelper::show_search_box( compact( 'text', 'input_id' ) ); | |
| 261 | + FrmAppHelper::show_search_box( $text, $input_id ); | |
| 284 | 262 | } |
| 285 | 263 | |
| 286 | 264 | private function hidden_search_inputs( $param_name ) { |
| 287 | 265 | if ( ! empty( $_REQUEST[ $param_name ] ) ) { |
| 288 | - $value = sanitize_text_field( wp_unslash( $_REQUEST[ $param_name ] ) ); | |
| 289 | - echo '<input type="hidden" name="' . esc_attr( $param_name ) . '" value="' . esc_attr( $value ) . '" />'; | |
| 266 | + echo '<input type="hidden" name="' . esc_attr( $param_name ) . '" value="' . esc_attr( $_REQUEST[ $param_name ] ) . '" />'; | |
| 290 | 267 | } |
| 291 | 268 | } |
| 292 | 269 | |
| 293 | 270 | /** |
| @@ -330,9 +307,9 @@ | ||
| 330 | 307 | echo "<ul class='subsubsub'>\n"; |
| 331 | 308 | foreach ( $views as $class => $view ) { |
| 332 | 309 | $views[ $class ] = "\t" . '<li class="' . esc_attr( $class ) . '">' . $view; |
| 333 | 310 | } |
| 334 | - echo implode( " |</li>\n", $views ) . "</li>\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 311 | + echo implode( " |</li>\n", $views ) . "</li>\n"; // WPCS: XSS ok. | |
| 335 | 312 | echo '</ul>'; |
| 336 | 313 | } |
| 337 | 314 | |
| 338 | 315 | /** |
| @@ -375,9 +352,8 @@ | ||
| 375 | 352 | * @param array $actions An array of the available bulk actions. |
| 376 | 353 | */ |
| 377 | 354 | $this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions ); |
| 378 | 355 | $this->_actions = array_intersect_assoc( $this->_actions, $no_new_actions ); |
| 379 | - | |
| 380 | 356 | $two = ''; |
| 381 | 357 | } else { |
| 382 | 358 | $two = '2'; |
| 383 | 359 | } |
| @@ -390,42 +366,20 @@ | ||
| 390 | 366 | echo "<select name='action" . esc_attr( $two ) . "' id='bulk-action-selector-" . esc_attr( $which ) . "'>\n"; |
| 391 | 367 | echo "<option value='-1' selected='selected'>" . esc_attr__( 'Bulk Actions', 'formidable' ) . "</option>\n"; |
| 392 | 368 | |
| 393 | 369 | foreach ( $this->_actions as $name => $title ) { |
| 394 | - $params = array( | |
| 395 | - 'value' => $name, | |
| 396 | - ); | |
| 397 | - if ( 'edit' === $name ) { | |
| 398 | - $params['class'] = 'hide-if-no-js'; | |
| 399 | - } | |
| 370 | + $class = 'edit' == $name ? ' class="hide-if-no-js"' : ''; | |
| 400 | 371 | |
| 401 | - echo "\t<option "; | |
| 402 | - FrmAppHelper::array_to_html_params( $params, true ); | |
| 403 | - echo '>' . esc_html( $title ) . '</option>' . "\n"; | |
| 372 | + echo "\t<option value='" . esc_attr( $name ) . "'$class>" . esc_html( $title ) . "</option>\n"; // WPCS: XSS ok. | |
| 404 | 373 | } |
| 405 | 374 | |
| 406 | 375 | echo "</select>\n"; |
| 407 | 376 | |
| 408 | - if ( isset( $this->_actions['bulk_delete'] ) ) { | |
| 409 | - $verify = $this->confirm_bulk_delete(); | |
| 410 | - | |
| 411 | - if ( $verify ) { | |
| 412 | - 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>"; | |
| 413 | - } | |
| 414 | - } | |
| 415 | - | |
| 416 | 377 | submit_button( __( 'Apply', 'formidable' ), 'action', '', false, array( 'id' => "doaction$two" ) ); |
| 417 | 378 | echo "\n"; |
| 418 | 379 | } |
| 419 | 380 | |
| 420 | 381 | /** |
| 421 | - * @return string if empty there will be no confirmation pop up | |
| 422 | - */ | |
| 423 | - protected function confirm_bulk_delete() { | |
| 424 | - return ''; | |
| 425 | - } | |
| 426 | - | |
| 427 | - /** | |
| 428 | 382 | * Get the current action selected from the bulk actions dropdown. |
| 429 | 383 | * |
| 430 | 384 | * @since 2.0.18 |
| 431 | 385 | * @access public |
| @@ -444,20 +398,19 @@ | ||
| 444 | 398 | |
| 445 | 399 | return $action; |
| 446 | 400 | } |
| 447 | 401 | |
| 448 | - private function get_bulk_action( $action_name ) { | |
| 449 | - $action = false; | |
| 450 | - $action_param = $this->get_param( | |
| 402 | + private static function get_bulk_action( $action_name ) { | |
| 403 | + $action = false; | |
| 404 | + $action_param = self::get_param( | |
| 451 | 405 | array( |
| 452 | - 'param' => $action_name, | |
| 406 | + 'param' => $action_name, | |
| 453 | 407 | 'sanitize' => 'sanitize_text_field', |
| 454 | 408 | ) |
| 455 | 409 | ); |
| 456 | - if ( $action_param && - 1 != $action_param ) { | |
| 410 | + if ( $action_param && -1 != $action_param ) { | |
| 457 | 411 | $action = $action_param; |
| 458 | 412 | } |
| 459 | - | |
| 460 | 413 | return $action; |
| 461 | 414 | } |
| 462 | 415 | |
| 463 | 416 | /** |
| @@ -467,14 +420,12 @@ | ||
| 467 | 420 | * @access protected |
| 468 | 421 | * |
| 469 | 422 | * @param array $actions The list of actions |
| 470 | 423 | * @param bool $always_visible Whether the actions should be always visible |
| 471 | - * | |
| 472 | 424 | * @return string |
| 473 | 425 | */ |
| 474 | 426 | protected function row_actions( $actions, $always_visible = false ) { |
| 475 | 427 | $action_count = count( $actions ); |
| 476 | - | |
| 477 | 428 | $i = 0; |
| 478 | 429 | |
| 479 | 430 | if ( ! $action_count ) { |
| 480 | 431 | return ''; |
| @@ -481,9 +432,9 @@ | ||
| 481 | 432 | } |
| 482 | 433 | |
| 483 | 434 | $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">'; |
| 484 | 435 | foreach ( $actions as $action => $link ) { |
| 485 | - ++ $i; | |
| 436 | + ++$i; | |
| 486 | 437 | ( $i == $action_count ) ? $sep = '' : $sep = ' | '; |
| 487 | 438 | $out .= "<span class='$action'>$link$sep</span>"; |
| 488 | 439 | } |
| 489 | 440 | $out .= '</div>'; |
| @@ -501,12 +452,12 @@ | ||
| 501 | 452 | * |
| 502 | 453 | * @param string $current_mode |
| 503 | 454 | */ |
| 504 | 455 | protected function view_switcher( $current_mode ) { |
| 505 | - ?> | |
| 506 | - <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>"/> | |
| 456 | +?> | |
| 457 | + <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" /> | |
| 507 | 458 | <div class="view-switch"> |
| 508 | - <?php | |
| 459 | +<?php | |
| 509 | 460 | foreach ( $this->modes as $mode => $title ) { |
| 510 | 461 | $classes = array( 'view-' . $mode ); |
| 511 | 462 | if ( $current_mode == $mode ) { |
| 512 | 463 | $classes[] = 'current'; |
| @@ -518,11 +469,11 @@ | ||
| 518 | 469 | esc_attr( implode( ' ', $classes ) ), |
| 519 | 470 | esc_html( $title ) |
| 520 | 471 | ); |
| 521 | 472 | } |
| 522 | - ?> | |
| 473 | + ?> | |
| 523 | 474 | </div> |
| 524 | - <?php | |
| 475 | +<?php | |
| 525 | 476 | } |
| 526 | 477 | |
| 527 | 478 | /** |
| 528 | 479 | * Get the current page number |
| @@ -548,10 +499,9 @@ | ||
| 548 | 499 | * @since 2.0.18 |
| 549 | 500 | * @access protected |
| 550 | 501 | * |
| 551 | 502 | * @param string $option |
| 552 | - * @param int $default | |
| 553 | - * | |
| 503 | + * @param int $default | |
| 554 | 504 | * @return int |
| 555 | 505 | */ |
| 556 | 506 | protected function get_items_per_page( $option, $default = 20 ) { |
| 557 | 507 | $per_page = (int) get_user_option( $option ); |
| @@ -587,16 +537,15 @@ | ||
| 587 | 537 | if ( empty( $this->_pagination_args ) ) { |
| 588 | 538 | return; |
| 589 | 539 | } |
| 590 | 540 | |
| 591 | - $total_items = $this->_pagination_args['total_items']; | |
| 592 | - $total_pages = $this->_pagination_args['total_pages']; | |
| 541 | + $total_items = $this->_pagination_args['total_items']; | |
| 542 | + $total_pages = $this->_pagination_args['total_pages']; | |
| 593 | 543 | $infinite_scroll = false; |
| 594 | 544 | if ( isset( $this->_pagination_args['infinite_scroll'] ) ) { |
| 595 | 545 | $infinite_scroll = $this->_pagination_args['infinite_scroll']; |
| 596 | 546 | } |
| 597 | 547 | |
| 598 | - /* translators: %s: Number of items */ | |
| 599 | 548 | $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items, 'formidable' ), number_format_i18n( $total_items ) ) . '</span>'; |
| 600 | 549 | |
| 601 | 550 | $current = $this->get_pagenum(); |
| 602 | 551 | |
| @@ -636,10 +585,8 @@ | ||
| 636 | 585 | strlen( $total_pages ) |
| 637 | 586 | ); |
| 638 | 587 | } |
| 639 | 588 | $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) ); |
| 640 | - | |
| 641 | - /* translators: %1$s: Current page number, %2$s: Total pages */ | |
| 642 | 589 | $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging', 'formidable' ), $html_current_page, $html_total_pages ) . $total_pages_after; |
| 643 | 590 | |
| 644 | 591 | $page_links[] = $this->add_page_link( |
| 645 | 592 | array( |
| @@ -671,9 +618,9 @@ | ||
| 671 | 618 | $page_class = ' no-pages'; |
| 672 | 619 | } |
| 673 | 620 | $this->_pagination = "<div class='tablenav-pages" . esc_attr( $page_class ) . "'>$output</div>"; |
| 674 | 621 | |
| 675 | - echo $this->_pagination; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 622 | + echo $this->_pagination; // WPCS: XSS ok. | |
| 676 | 623 | } |
| 677 | 624 | |
| 678 | 625 | private function disabled_pages( $total_pages ) { |
| 679 | 626 | $current = $this->get_pagenum(); |
| @@ -683,19 +630,19 @@ | ||
| 683 | 630 | 'prev' => false, |
| 684 | 631 | 'next' => false, |
| 685 | 632 | ); |
| 686 | 633 | |
| 687 | - if ( $current == 1 ) { | |
| 634 | + if ( $current == 1 ) { | |
| 688 | 635 | $disable['first'] = true; |
| 689 | 636 | $disable['prev'] = true; |
| 690 | - } elseif ( $current == 2 ) { | |
| 637 | + } elseif ( $current == 2 ) { | |
| 691 | 638 | $disable['first'] = true; |
| 692 | 639 | } |
| 693 | 640 | |
| 694 | - if ( $current == $total_pages ) { | |
| 641 | + if ( $current == $total_pages ) { | |
| 695 | 642 | $disable['last'] = true; |
| 696 | 643 | $disable['next'] = true; |
| 697 | - } elseif ( $current == $total_pages - 1 ) { | |
| 644 | + } elseif ( $current == $total_pages - 1 ) { | |
| 698 | 645 | $disable['last'] = true; |
| 699 | 646 | } |
| 700 | 647 | |
| 701 | 648 | return $disable; |
| @@ -707,9 +654,8 @@ | ||
| 707 | 654 | 'last' => __( 'Last page', 'formidable' ), |
| 708 | 655 | 'prev' => __( 'Previous page', 'formidable' ), |
| 709 | 656 | 'next' => __( 'Next page', 'formidable' ), |
| 710 | 657 | ); |
| 711 | - | |
| 712 | 658 | return $labels[ $link ]; |
| 713 | 659 | } |
| 714 | 660 | |
| 715 | 661 | private function current_url() { |
| @@ -723,9 +669,8 @@ | ||
| 723 | 669 | $link = $this->add_disabled_link( $atts['arrow'] ); |
| 724 | 670 | } else { |
| 725 | 671 | $link = $this->add_active_link( $atts ); |
| 726 | 672 | } |
| 727 | - | |
| 728 | 673 | return $link; |
| 729 | 674 | } |
| 730 | 675 | |
| 731 | 676 | private function add_disabled_link( $label ) { |
| @@ -732,11 +677,10 @@ | ||
| 732 | 677 | return '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">' . $label . '</span>'; |
| 733 | 678 | } |
| 734 | 679 | |
| 735 | 680 | private function add_active_link( $atts ) { |
| 736 | - $url = esc_url( add_query_arg( 'paged', $atts['number'], $this->current_url() ) ); | |
| 681 | + $url = esc_url( add_query_arg( 'paged', $atts['number'], $this->current_url() ) ); | |
| 737 | 682 | $label = $this->link_label( $atts['page'] ); |
| 738 | - | |
| 739 | 683 | return sprintf( |
| 740 | 684 | "<a class='button %s-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>", |
| 741 | 685 | $atts['page'], |
| 742 | 686 | $url, |
| @@ -771,9 +715,9 @@ | ||
| 771 | 715 | * @return string Name of the default primary column, in this case, an empty string. |
| 772 | 716 | */ |
| 773 | 717 | protected function get_default_primary_column_name() { |
| 774 | 718 | $columns = $this->get_columns(); |
| 775 | - $column = ''; | |
| 719 | + $column = ''; | |
| 776 | 720 | |
| 777 | 721 | // We need a primary defined so responsive views show something, |
| 778 | 722 | // so let's fall back to the first non-checkbox column. |
| 779 | 723 | foreach ( $columns as $col => $column_name ) { |
| @@ -813,9 +757,9 @@ | ||
| 813 | 757 | * |
| 814 | 758 | * @param string $default Column name default for the specific list table, e.g. 'name'. |
| 815 | 759 | * @param string $context Screen ID for specific list table, e.g. 'plugins'. |
| 816 | 760 | */ |
| 817 | - $column = apply_filters( 'list_table_primary_column', $default, $this->screen->id ); | |
| 761 | + $column = apply_filters( 'list_table_primary_column', $default, $this->screen->id ); | |
| 818 | 762 | |
| 819 | 763 | if ( empty( $column ) || ! isset( $columns[ $column ] ) ) { |
| 820 | 764 | $column = $default; |
| 821 | 765 | } |
| @@ -844,9 +788,9 @@ | ||
| 844 | 788 | return $column_headers; |
| 845 | 789 | } |
| 846 | 790 | |
| 847 | 791 | $columns = get_column_headers( $this->screen ); |
| 848 | - $hidden = get_hidden_columns( $this->screen ); | |
| 792 | + $hidden = get_hidden_columns( $this->screen ); | |
| 849 | 793 | |
| 850 | 794 | $sortable_columns = $this->get_sortable_columns(); |
| 851 | 795 | /** |
| 852 | 796 | * Filter the list table sortable columns for a specific screen. |
| @@ -874,9 +818,8 @@ | ||
| 874 | 818 | $sortable[ $id ] = $data; |
| 875 | 819 | } |
| 876 | 820 | |
| 877 | 821 | $primary = $this->get_primary_column_name(); |
| 878 | - | |
| 879 | 822 | $this->_column_headers = array( $columns, $hidden, $sortable, $primary ); |
| 880 | 823 | |
| 881 | 824 | return $this->_column_headers; |
| 882 | 825 | } |
| @@ -891,9 +834,8 @@ | ||
| 891 | 834 | */ |
| 892 | 835 | public function get_column_count() { |
| 893 | 836 | list ( $columns, $hidden ) = $this->get_column_info(); |
| 894 | 837 | $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) ); |
| 895 | - | |
| 896 | 838 | return count( $columns ) - count( $hidden ); |
| 897 | 839 | } |
| 898 | 840 | |
| 899 | 841 | /** |
| @@ -912,9 +854,9 @@ | ||
| 912 | 854 | $current_url = set_url_scheme( 'http://' . FrmAppHelper::get_server_value( 'HTTP_HOST' ) . FrmAppHelper::get_server_value( 'REQUEST_URI' ) ); |
| 913 | 855 | $current_url = remove_query_arg( 'paged', $current_url ); |
| 914 | 856 | |
| 915 | 857 | if ( isset( $_GET['orderby'] ) ) { |
| 916 | - $current_orderby = sanitize_text_field( wp_unslash( $_GET['orderby'] ) ); | |
| 858 | + $current_orderby = sanitize_text_field( $_GET['orderby'] ); | |
| 917 | 859 | } else { |
| 918 | 860 | $current_orderby = ''; |
| 919 | 861 | } |
| 920 | 862 | |
| @@ -925,11 +867,11 @@ | ||
| 925 | 867 | } |
| 926 | 868 | |
| 927 | 869 | if ( ! empty( $columns['cb'] ) ) { |
| 928 | 870 | static $cb_counter = 1; |
| 929 | - $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All', 'formidable' ) . '</label>'; | |
| 930 | - $columns['cb'] .= '<input id="cb-select-all-' . esc_attr( $cb_counter ) . '" type="checkbox" />'; | |
| 931 | - $cb_counter ++; | |
| 871 | + $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All', 'formidable' ) . '</label>' | |
| 872 | + . '<input id="cb-select-all-' . esc_attr( $cb_counter ) . '" type="checkbox" />'; | |
| 873 | + $cb_counter++; | |
| 932 | 874 | } |
| 933 | 875 | |
| 934 | 876 | foreach ( $columns as $column_key => $column_display_name ) { |
| 935 | 877 | $class = array( 'manage-column', "column-$column_key" ); |
| @@ -939,13 +881,13 @@ | ||
| 939 | 881 | } |
| 940 | 882 | |
| 941 | 883 | if ( 'cb' == $column_key ) { |
| 942 | 884 | $class[] = 'check-column'; |
| 943 | - } elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) ) { | |
| 885 | + } else if ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) ) { | |
| 944 | 886 | $class[] = 'num'; |
| 945 | 887 | } |
| 946 | 888 | |
| 947 | - if ( $column_key === $primary || $column_key === 'name' ) { | |
| 889 | + if ( $column_key === $primary ) { | |
| 948 | 890 | $class[] = 'column-primary'; |
| 949 | 891 | } |
| 950 | 892 | |
| 951 | 893 | if ( isset( $sortable[ $column_key ] ) ) { |
| @@ -951,13 +893,13 @@ | ||
| 951 | 893 | if ( isset( $sortable[ $column_key ] ) ) { |
| 952 | 894 | list( $orderby, $desc_first ) = $sortable[ $column_key ]; |
| 953 | 895 | |
| 954 | 896 | if ( $current_orderby == $orderby ) { |
| 955 | - $order = 'asc' == $current_order ? 'desc' : 'asc'; | |
| 897 | + $order = 'asc' == $current_order ? 'desc' : 'asc'; | |
| 956 | 898 | $class[] = 'sorted'; |
| 957 | 899 | $class[] = $current_order; |
| 958 | 900 | } else { |
| 959 | - $order = $desc_first ? 'desc' : 'asc'; | |
| 901 | + $order = $desc_first ? 'desc' : 'asc'; | |
| 960 | 902 | $class[] = 'sortable'; |
| 961 | 903 | $class[] = $desc_first ? 'asc' : 'desc'; |
| 962 | 904 | } |
| 963 | 905 | |
| @@ -963,21 +905,17 @@ | ||
| 963 | 905 | |
| 964 | 906 | $column_display_name = '<a href="' . esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ) . '"><span>' . esc_html( $column_display_name ) . '</span><span class="sorting-indicator"></span></a>'; |
| 965 | 907 | } |
| 966 | 908 | |
| 967 | - $tag = ( 'cb' === $column_key ) ? 'td' : 'th'; | |
| 909 | + $tag = ( 'cb' === $column_key ) ? 'td' : 'th'; | |
| 968 | 910 | $scope = ( 'th' === $tag ) ? 'scope="col"' : ''; |
| 969 | - $id = $with_id ? "id='" . esc_attr( $column_key ) . "'" : ''; | |
| 911 | + $id = $with_id ? "id='" . esc_attr( $column_key ) . "'" : ''; | |
| 970 | 912 | |
| 971 | 913 | if ( ! empty( $class ) ) { |
| 972 | 914 | $class = "class='" . esc_attr( join( ' ', $class ) ) . "'"; |
| 973 | 915 | } |
| 974 | 916 | |
| 975 | - if ( ! $this->has_min_items() && ! $with_id ) { | |
| 976 | - // Hide the labels but show the border. | |
| 977 | - $column_display_name = ''; | |
| 978 | - } | |
| 979 | - echo "<$tag $scope $id $class>$column_display_name</$tag>"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 917 | + echo "<$tag $scope $id $class>$column_display_name</$tag>"; // WPCS: XSS ok. | |
| 980 | 918 | } |
| 981 | 919 | } |
| 982 | 920 | |
| 983 | 921 | /** |
| @@ -986,38 +924,31 @@ | ||
| 986 | 924 | * @since 2.0.18 |
| 987 | 925 | * @access public |
| 988 | 926 | */ |
| 989 | 927 | public function display() { |
| 990 | - $singular = $this->_args['singular']; | |
| 991 | - $tbody_params = array(); | |
| 992 | - if ( $singular ) { | |
| 993 | - $tbody_params['data-wp-lists'] = 'list:' . $singular; | |
| 994 | - } | |
| 928 | + $singular = $this->_args['singular']; | |
| 995 | 929 | |
| 996 | 930 | $this->display_tablenav( 'top' ); |
| 997 | - ?> | |
| 998 | - <table class="wp-list-table <?php echo esc_attr( implode( ' ', $this->get_table_classes() ) ); ?>"> | |
| 999 | - <?php if ( $this->has_min_items( 1 ) ) { ?> | |
| 1000 | - <thead> | |
| 1001 | - <tr> | |
| 1002 | - <?php $this->print_column_headers(); ?> | |
| 1003 | - </tr> | |
| 1004 | - </thead> | |
| 1005 | - <?php } ?> | |
| 931 | +?> | |
| 932 | +<table class="wp-list-table <?php echo esc_attr( implode( ' ', $this->get_table_classes() ) ); ?>"> | |
| 933 | + <thead> | |
| 934 | + <tr> | |
| 935 | + <?php $this->print_column_headers(); ?> | |
| 936 | + </tr> | |
| 937 | + </thead> | |
| 1006 | 938 | |
| 1007 | - <tbody id="the-list"<?php FrmAppHelper::array_to_html_params( $tbody_params, true ); ?>> | |
| 1008 | - <?php $this->display_rows_or_placeholder(); ?> | |
| 1009 | - </tbody> | |
| 939 | + <tbody id="the-list"<?php echo ( $singular ? " data-wp-lists='list:" . esc_attr( $singular ) . "'" : '' ); // WPCS: XSS ok. ?>> | |
| 940 | + <?php $this->display_rows_or_placeholder(); ?> | |
| 941 | + </tbody> | |
| 1010 | 942 | |
| 1011 | - <?php if ( $this->has_min_items( 1 ) ) { ?> | |
| 1012 | - <tfoot> | |
| 1013 | - <tr> | |
| 1014 | - <?php $this->print_column_headers( false ); ?> | |
| 1015 | - </tr> | |
| 1016 | - </tfoot> | |
| 1017 | - <?php } ?> | |
| 1018 | - </table> | |
| 1019 | - <?php | |
| 943 | + <tfoot> | |
| 944 | + <tr> | |
| 945 | + <?php $this->print_column_headers( false ); ?> | |
| 946 | + </tr> | |
| 947 | + </tfoot> | |
| 948 | + | |
| 949 | +</table> | |
| 950 | +<?php | |
| 1020 | 951 | $this->display_tablenav( 'bottom' ); |
| 1021 | 952 | } |
| 1022 | 953 | |
| 1023 | 954 | /** |
| @@ -1036,46 +967,28 @@ | ||
| 1036 | 967 | * Generate the table navigation above or below the table |
| 1037 | 968 | * |
| 1038 | 969 | * @since 2.0.18 |
| 1039 | 970 | * @access protected |
| 1040 | - * | |
| 1041 | 971 | * @param string $which |
| 1042 | 972 | */ |
| 1043 | 973 | protected function display_tablenav( $which ) { |
| 1044 | - if ( 'top' === $which ) { | |
| 1045 | - wp_nonce_field( 'bulk-' . $this->_args['plural'], '_wpnonce', false ); | |
| 1046 | - if ( ! $this->has_min_items( 1 ) ) { | |
| 1047 | - // Don't show bulk actions if no items. | |
| 1048 | - return; | |
| 1049 | - } | |
| 1050 | - } elseif ( ! $this->has_min_items() ) { | |
| 1051 | - // don't show the bulk actions when there aren't many rows. | |
| 1052 | - return; | |
| 974 | + if ( 'top' == $which ) { | |
| 975 | + wp_nonce_field( 'bulk-' . $this->_args['plural'] ); | |
| 1053 | 976 | } |
| 1054 | - ?> | |
| 1055 | - <div class="tablenav <?php echo esc_attr( $which ); ?>"> | |
| 977 | +?> | |
| 978 | + <div class="tablenav <?php echo esc_attr( $which ); ?>"> | |
| 1056 | 979 | |
| 1057 | - <div class="alignleft actions bulkactions"> | |
| 1058 | - <?php $this->bulk_actions( $which ); ?> | |
| 1059 | - </div> | |
| 1060 | - <?php | |
| 1061 | - $this->extra_tablenav( $which ); | |
| 1062 | - $this->pagination( $which ); | |
| 1063 | - ?> | |
| 1064 | - | |
| 1065 | - <br class="clear"/> | |
| 980 | + <div class="alignleft actions bulkactions"> | |
| 981 | + <?php $this->bulk_actions( $which ); ?> | |
| 1066 | 982 | </div> |
| 1067 | - <?php | |
| 1068 | - } | |
| 983 | +<?php | |
| 984 | + $this->extra_tablenav( $which ); | |
| 985 | + $this->pagination( $which ); | |
| 986 | +?> | |
| 1069 | 987 | |
| 1070 | - /** | |
| 1071 | - * Use this to exclude the footer labels and bulk items. | |
| 1072 | - * When close together, it feels like duplicates. | |
| 1073 | - * | |
| 1074 | - * @since 4.07 | |
| 1075 | - */ | |
| 1076 | - protected function has_min_items( $limit = 5 ) { | |
| 1077 | - return $this->has_items() && ( $this->total_items === false || $this->total_items >= $limit ); | |
| 988 | + <br class="clear" /> | |
| 989 | + </div> | |
| 990 | +<?php | |
| 1078 | 991 | } |
| 1079 | 992 | |
| 1080 | 993 | /** |
| 1081 | 994 | * Extra controls to be displayed between bulk actions and pagination |
| @@ -1084,10 +997,9 @@ | ||
| 1084 | 997 | * @access protected |
| 1085 | 998 | * |
| 1086 | 999 | * @param string $which |
| 1087 | 1000 | */ |
| 1088 | - protected function extra_tablenav( $which ) { | |
| 1089 | - } | |
| 1001 | + protected function extra_tablenav( $which ) {} | |
| 1090 | 1002 | |
| 1091 | 1003 | /** |
| 1092 | 1004 | * Generate the tbody element for the list table. |
| 1093 | 1005 | * |
| @@ -1126,9 +1038,9 @@ | ||
| 1126 | 1038 | * |
| 1127 | 1039 | * @param object $item The current item |
| 1128 | 1040 | */ |
| 1129 | 1041 | protected function single_row_columns( $item ) { |
| 1130 | - list( $columns, $hidden,, $primary ) = $this->get_column_info(); | |
| 1042 | + list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); | |
| 1131 | 1043 | |
| 1132 | 1044 | foreach ( $columns as $column_name => $column_display_name ) { |
| 1133 | 1045 | $classes = "$column_name column-$column_name"; |
| 1134 | 1046 | if ( $primary === $column_name ) { |
| @@ -1138,27 +1050,32 @@ | ||
| 1138 | 1050 | if ( in_array( $column_name, $hidden ) ) { |
| 1139 | 1051 | $classes .= ' hidden'; |
| 1140 | 1052 | } |
| 1141 | 1053 | |
| 1142 | - $params = array( | |
| 1143 | - 'class' => $classes, | |
| 1144 | - // Comments column uses HTML in the display name with screen reader text. | |
| 1145 | - // Instead of using esc_attr(), we strip tags to get closer to a user-friendly string. | |
| 1146 | - 'data-colname' => $column_display_name, | |
| 1147 | - ); | |
| 1054 | + // Comments column uses HTML in the display name with screen reader text. | |
| 1055 | + // Instead of using esc_attr(), we strip tags to get closer to a user-friendly string. | |
| 1056 | + $data = 'data-colname="' . esc_attr( $column_display_name ) . '"'; | |
| 1148 | 1057 | |
| 1149 | - if ( 'cb' === $column_name ) { | |
| 1058 | + $attributes = 'class="' . esc_attr( $classes ) . '" ' . $data; | |
| 1059 | + | |
| 1060 | + if ( 'cb' == $column_name ) { | |
| 1150 | 1061 | echo '<th scope="row" class="check-column"></th>'; |
| 1062 | + } elseif ( method_exists( $this, '_column_' . $column_name ) ) { | |
| 1063 | + echo call_user_func( // WPCS: XSS ok. | |
| 1064 | + array( $this, '_column_' . $column_name ), | |
| 1065 | + $item, | |
| 1066 | + $classes, | |
| 1067 | + $data, | |
| 1068 | + $primary | |
| 1069 | + ); | |
| 1070 | + } elseif ( method_exists( $this, 'column_' . $column_name ) ) { | |
| 1071 | + echo "<td $attributes>"; // WPCS: XSS ok. | |
| 1072 | + echo call_user_func( array( $this, 'column_' . $column_name ), $item ); // WPCS: XSS ok. | |
| 1073 | + echo $this->handle_row_actions( $item, $column_name, $primary ); // WPCS: XSS ok. | |
| 1074 | + echo '</td>'; | |
| 1151 | 1075 | } else { |
| 1152 | - echo '<td '; | |
| 1153 | - FrmAppHelper::array_to_html_params( $params, true ); | |
| 1154 | - echo '>'; | |
| 1155 | - | |
| 1156 | - if ( method_exists( $this, 'column_' . $column_name ) ) { | |
| 1157 | - echo call_user_func( array( $this, 'column_' . $column_name ), $item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1158 | - } | |
| 1159 | - | |
| 1160 | - echo $this->handle_row_actions( $item, $column_name, $primary ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1076 | + echo "<td $attributes>"; // WPCS: XSS ok. | |
| 1077 | + echo $this->handle_row_actions( $item, $column_name, $primary ); // WPCS: XSS ok. | |
| 1161 | 1078 | echo '</td>'; |
| 1162 | 1079 | } |
| 1163 | 1080 | } |
| 1164 | 1081 | } |
| @@ -1168,17 +1085,16 @@ | ||
| 1168 | 1085 | * |
| 1169 | 1086 | * @since 4.3.0 |
| 1170 | 1087 | * @access protected |
| 1171 | 1088 | * |
| 1172 | - * @param object $item The item being acted upon. | |
| 1089 | + * @param object $item The item being acted upon. | |
| 1173 | 1090 | * @param string $column_name Current column name. |
| 1174 | - * @param string $primary Primary column name. | |
| 1175 | - * | |
| 1091 | + * @param string $primary Primary column name. | |
| 1176 | 1092 | * @return string The row actions output. In this case, an empty string. |
| 1177 | 1093 | */ |
| 1178 | 1094 | protected function handle_row_actions( $item, $column_name, $primary ) { |
| 1179 | 1095 | return $column_name == $primary ? '<button type="button" class="toggle-row"><span class="screen-reader-text">' . esc_html__( 'Show more details', 'formidable' ) . '</span></button>' : ''; |
| 1180 | - } | |
| 1096 | + } | |
| 1181 | 1097 | |
| 1182 | 1098 | /** |
| 1183 | 1099 | * Handle an incoming ajax request (called from admin-ajax.php) |
| 1184 | 1100 | * |
| @@ -1200,15 +1116,14 @@ | ||
| 1200 | 1116 | $response = array( 'rows' => $rows ); |
| 1201 | 1117 | |
| 1202 | 1118 | if ( isset( $this->_pagination_args['total_items'] ) ) { |
| 1203 | 1119 | $response['total_items_i18n'] = sprintf( |
| 1204 | - /* translators: %s: Number of items */ | |
| 1205 | 1120 | _n( '%s item', '%s items', $this->_pagination_args['total_items'], 'formidable' ), |
| 1206 | 1121 | number_format_i18n( $this->_pagination_args['total_items'] ) |
| 1207 | 1122 | ); |
| 1208 | 1123 | } |
| 1209 | 1124 | if ( isset( $this->_pagination_args['total_pages'] ) ) { |
| 1210 | - $response['total_pages'] = $this->_pagination_args['total_pages']; | |
| 1125 | + $response['total_pages'] = $this->_pagination_args['total_pages']; | |
| 1211 | 1126 | $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] ); |
| 1212 | 1127 | } |
| 1213 | 1128 | |
| 1214 | 1129 | die( wp_json_encode( $response ) ); |
| @@ -1228,13 +1143,6 @@ | ||
| 1228 | 1143 | ), |
| 1229 | 1144 | ); |
| 1230 | 1145 | |
| 1231 | 1146 | printf( "<script type='text/javascript'>list_args = %s;</script>\n", wp_json_encode( $args ) ); |
| 1232 | - } | |
| 1233 | - | |
| 1234 | - /** | |
| 1235 | - * @return string | |
| 1236 | - */ | |
| 1237 | - protected function loaded_from() { | |
| 1238 | - return ''; | |
| 1239 | 1147 | } |
| 1240 | 1148 | } |