PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.2.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.2.06
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/helpers/FrmListHelper.php +137 -236 6.27 → 5.2.06 View file →
@@ -7,17 +7,15 @@
7 7 /**
8 8 * The current list of items
9 9 *
10 10 * @since 2.0.18
11 - *
12 11 * @var array
12 + * @access public
13 13 */
14 14 public $items;
15 15
16 16 /**
17 17 * @since 4.07
18 - *
19 - * @var bool|int
20 18 */
21 19 public $total_items = false;
22 20
23 21 /**
@@ -23,10 +21,10 @@
23 21 /**
24 22 * Various information about the current table
25 23 *
26 24 * @since 2.0.18
27 - *
28 25 * @var array
26 + * @access protected
29 27 */
30 28 protected $_args;
31 29
32 30 /**
@@ -32,9 +30,8 @@
32 30 /**
33 31 * Various information needed for displaying the pagination
34 32 *
35 33 * @since 2.0.18
36 - *
37 34 * @var array
38 35 */
39 36 protected $_pagination_args = array();
40 37
@@ -41,10 +38,10 @@
41 38 /**
42 39 * The current screen
43 40 *
44 41 * @since 2.0.18
45 - *
46 - * @var \WP_Screen
42 + * @var object
43 + * @access protected
47 44 */
48 45 protected $screen;
49 46
50 47 /**
@@ -50,10 +47,10 @@
50 47 /**
51 48 * Cached bulk actions
52 49 *
53 50 * @since 2.0.18
54 - *
55 51 * @var array
52 + * @access private
56 53 */
57 54 private $_actions;
58 55
59 56 /**
@@ -59,10 +56,10 @@
59 56 /**
60 57 * Cached pagination output
61 58 *
62 59 * @since 2.0.18
63 - *
64 60 * @var string
61 + * @access private
65 62 */
66 63 private $_pagination;
67 64
68 65 /**
@@ -68,14 +65,15 @@
68 65 /**
69 66 * The view switcher modes.
70 67 *
71 68 * @since 2.0.18
72 - *
73 69 * @var array
70 + * @access protected
74 71 */
75 72 protected $modes = array();
76 73
77 74 /**
75 + *
78 76 * @var array
79 77 */
80 78 protected $params;
81 79
@@ -85,16 +83,10 @@
85 83 * @var array
86 84 */
87 85 protected $_column_headers;
88 86
89 - /**
90 - * @var array
91 - */
92 87 protected $compat_fields = array( '_args', '_pagination_args', 'screen', '_actions', '_pagination' );
93 88
94 - /**
95 - * @var array
96 - */
97 89 protected $compat_methods = array(
98 90 'set_pagination_args',
99 91 'get_views',
100 92 'get_bulk_actions',
@@ -112,12 +104,8 @@
112 104 );
113 105
114 106 /**
115 107 * Construct the table object
116 - *
117 - * @param array $args
118 - *
119 - * @return void
120 108 */
121 109 public function __construct( $args ) {
122 110 $args = wp_parse_args(
123 111 $args,
@@ -149,9 +137,9 @@
149 137 // wp_enqueue_script( 'list-table' );
150 138 add_action( 'admin_footer', array( $this, '_js_vars' ) );
151 139 }
152 140
153 - if ( ! $this->modes ) {
141 + if ( empty( $this->modes ) ) {
154 142 $this->modes = array(
155 143 'list' => __( 'List View', 'formidable' ),
156 144 'excerpt' => __( 'Excerpt View', 'formidable' ),
157 145 );
@@ -177,9 +165,9 @@
177 165 *
178 166 * @uses FrmListHelper::set_pagination_args()
179 167 *
180 168 * @since 2.0.18
181 - *
169 + * @access public
182 170 * @abstract
183 171 */
184 172 public function prepare_items() {
185 173 die( 'function FrmListHelper::prepare_items() must be over-ridden in a sub-class.' );
@@ -186,19 +174,15 @@
186 174 }
187 175
188 176 /**
189 177 * @since 3.0
190 - *
191 - * @param array $args
192 - *
193 - * @return array|string
194 178 */
195 179 protected function get_param( $args ) {
196 180 return FrmAppHelper::get_simple_request(
197 181 array(
198 182 'param' => $args['param'],
199 - 'default' => $args['default'] ?? '',
200 - 'sanitize' => $args['sanitize'] ?? 'sanitize_title',
183 + 'default' => isset( $args['default'] ) ? $args['default'] : '',
184 + 'sanitize' => isset( $args['sanitize'] ) ? $args['sanitize'] : 'sanitize_title',
201 185 'type' => 'request',
202 186 )
203 187 );
204 188 }
@@ -205,9 +189,13 @@
205 189
206 190 /**
207 191 * An internal method that sets all the necessary pagination arguments
208 192 *
209 - * @param array $args An associative array with information about the pagination.
193 + * @param array $args An associative array with information about the pagination
194 + *
195 + * @access protected
196 + *
197 + * @param array|string $args
210 198 */
211 199 protected function set_pagination_args( $args ) {
212 200 $args = wp_parse_args(
213 201 $args,
@@ -234,8 +222,9 @@
234 222 /**
235 223 * Access the pagination args.
236 224 *
237 225 * @since 2.0.18
226 + * @access public
238 227 *
239 228 * @param string $key Pagination argument to retrieve. Common values include 'total_items',
240 229 * 'total_pages', 'per_page', or 'infinite_scroll'.
241 230 *
@@ -241,13 +230,15 @@
241 230 *
242 231 * @return int Number of items that correspond to the given pagination argument.
243 232 */
244 233 public function get_pagination_arg( $key ) {
245 - if ( 'page' === $key ) {
234 + if ( 'page' == $key ) {
246 235 return $this->get_pagenum();
247 236 }
248 237
249 - return $this->_pagination_args[ $key ] ?? null;
238 + if ( isset( $this->_pagination_args[ $key ] ) ) {
239 + return $this->_pagination_args[ $key ];
240 + }
250 241 }
251 242
252 243 /**
253 244 * Whether the table has items to display or not
@@ -252,8 +243,9 @@
252 243 /**
253 244 * Whether the table has items to display or not
254 245 *
255 246 * @since 2.0.18
247 + * @access public
256 248 *
257 249 * @return bool
258 250 */
259 251 public function has_items() {
@@ -263,8 +255,9 @@
263 255 /**
264 256 * Message to be displayed when there are no items
265 257 *
266 258 * @since 2.0.18
259 + * @access public
267 260 */
268 261 public function no_items() {
269 262 esc_html_e( 'No items found.', 'formidable' );
270 263 }
@@ -272,11 +265,12 @@
272 265 /**
273 266 * Display the search box.
274 267 *
275 268 * @since 2.0.18
269 + * @access public
276 270 *
277 - * @param string $text The search button text.
278 - * @param string $input_id The search input id.
271 + * @param string $text The search button text
272 + * @param string $input_id The search input id
279 273 */
280 274 public function search_box( $text, $input_id ) {
281 275 if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) {
282 276 return;
@@ -288,13 +282,8 @@
288 282
289 283 FrmAppHelper::show_search_box( compact( 'text', 'input_id' ) );
290 284 }
291 285
292 - /**
293 - * @param string $param_name
294 - *
295 - * @return void
296 - */
297 286 private function hidden_search_inputs( $param_name ) {
298 287 if ( ! empty( $_REQUEST[ $param_name ] ) ) {
299 288 $value = sanitize_text_field( wp_unslash( $_REQUEST[ $param_name ] ) );
300 289 echo '<input type="hidden" name="' . esc_attr( $param_name ) . '" value="' . esc_attr( $value ) . '" />';
@@ -305,8 +294,9 @@
305 294 * Get an associative array ( id => link ) with the list
306 295 * of views available on this table.
307 296 *
308 297 * @since 2.0.18
298 + * @access protected
309 299 *
310 300 * @return array
311 301 */
312 302 protected function get_views() {
@@ -316,8 +306,9 @@
316 306 /**
317 307 * Display the list of views available on this table.
318 308 *
319 309 * @since 2.0.18
310 + * @access public
320 311 */
321 312 public function views() {
322 313 $views = $this->get_views();
323 314 /**
@@ -331,14 +322,13 @@
331 322 * @param array $views An array of available list table views.
332 323 */
333 324 $views = apply_filters( 'views_' . $this->screen->id, $views );
334 325
335 - if ( ! $views ) {
326 + if ( empty( $views ) ) {
336 327 return;
337 328 }
338 329
339 330 echo "<ul class='subsubsub'>\n";
340 -
341 331 foreach ( $views as $class => $view ) {
342 332 $views[ $class ] = "\t" . '<li class="' . esc_attr( $class ) . '">' . $view;
343 333 }
344 334 echo implode( " |</li>\n", $views ) . "</li>\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
@@ -349,8 +339,9 @@
349 339 * Get an associative array ( option_name => option_title ) with the list
350 340 * of bulk actions available on this table.
351 341 *
352 342 * @since 2.0.18
343 + * @access protected
353 344 *
354 345 * @return array
355 346 */
356 347 protected function get_bulk_actions() {
@@ -360,8 +351,9 @@
360 351 /**
361 352 * Display the bulk actions dropdown.
362 353 *
363 354 * @since 2.0.18
355 + * @access protected
364 356 *
365 357 * @param string $which The location of the bulk actions: 'top' or 'bottom'.
366 358 * This is designated as optional for backwards-compatibility.
367 359 */
@@ -387,23 +379,22 @@
387 379
388 380 $two = '';
389 381 } else {
390 382 $two = '2';
391 - }//end if
383 + }
392 384
393 385 if ( empty( $this->_actions ) ) {
394 386 return;
395 387 }
396 388
397 - echo "<label for='bulk-action-selector-" . esc_attr( $which ) . "' class='screen-reader-text'>" . esc_html__( 'Select bulk action', 'formidable' ) . '</label>';
389 + echo "<label for='bulk-action-selector-" . esc_attr( $which ) . "' class='screen-reader-text'>" . esc_attr__( 'Select bulk action', 'formidable' ) . '</label>';
398 390 echo "<select name='action" . esc_attr( $two ) . "' id='bulk-action-selector-" . esc_attr( $which ) . "'>\n";
399 - echo "<option value='-1' selected='selected'>" . esc_html__( 'Bulk Actions', 'formidable' ) . "</option>\n";
391 + echo "<option value='-1' selected='selected'>" . esc_attr__( 'Bulk Actions', 'formidable' ) . "</option>\n";
400 392
401 393 foreach ( $this->_actions as $name => $title ) {
402 394 $params = array(
403 395 'value' => $name,
404 396 );
405 -
406 397 if ( 'edit' === $name ) {
407 398 $params['class'] = 'hide-if-no-js';
408 399 }
409 400
@@ -417,21 +408,9 @@
417 408 if ( isset( $this->_actions['bulk_delete'] ) ) {
418 409 $verify = $this->confirm_bulk_delete();
419 410
420 411 if ( $verify ) {
421 - $confirm_delete_attributes = array(
422 - 'id' => 'confirm-bulk-delete-' . $which,
423 - 'class' => 'frm-hidden',
424 - 'tabindex' => '-1',
425 - 'aria-hidden' => 'true',
426 - 'href' => 'confirm-bulk-delete',
427 - 'data-loaded-from' => $this->loaded_from(),
428 - 'data-frmverify' => $verify,
429 - 'data-frmverify-btn' => 'frm-button-red',
430 - );
431 -
432 - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
433 - echo '<a ' . FrmAppHelper::array_to_html_params( $confirm_delete_attributes ) . '></a>';
412 + echo "<a id='confirm-bulk-delete-" . esc_attr( $which ) . "' class='frm-hidden' href='confirm-bulk-delete' data-frmcaution='" . esc_html__( 'Heads up', 'formidable' ) . "' data-frmverify='" . esc_attr( $verify ) . "'></a>";
434 413 }
435 414 }
436 415
437 416 submit_button( __( 'Apply', 'formidable' ), 'action', '', false, array( 'id' => "doaction$two" ) );
@@ -448,18 +427,18 @@
448 427 /**
449 428 * Get the current action selected from the bulk actions dropdown.
450 429 *
451 430 * @since 2.0.18
431 + * @access public
452 432 *
453 - * @return false|string The action name or False if no action was selected
433 + * @return string|false The action name or False if no action was selected
454 434 */
455 435 public function current_action() {
456 - if ( ! empty( $_REQUEST['filter_action'] ) ) {
436 + if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) ) {
457 437 return false;
458 438 }
459 439
460 440 $action = $this->get_bulk_action( 'action' );
461 -
462 441 if ( $action === false ) {
463 442 $action = $this->get_bulk_action( 'action2' );
464 443 }
465 444
@@ -465,13 +444,8 @@
465 444
466 445 return $action;
467 446 }
468 447
469 - /**
470 - * @param string $action_name
471 - *
472 - * @return false|string
473 - */
474 448 private function get_bulk_action( $action_name ) {
475 449 $action = false;
476 450 $action_param = $this->get_param(
477 451 array(
@@ -478,10 +452,8 @@
478 452 'param' => $action_name,
479 453 'sanitize' => 'sanitize_text_field',
480 454 )
481 455 );
482 -
483 - // phpcs:ignore Universal.Operators.StrictComparisons
484 456 if ( $action_param && - 1 != $action_param ) {
485 457 $action = $action_param;
486 458 }
487 459
@@ -491,33 +463,35 @@
491 463 /**
492 464 * Generate row actions div
493 465 *
494 466 * @since 2.0.18
467 + * @access protected
495 468 *
496 - * @param array $actions The list of actions.
497 - * @param bool $always_visible Whether the actions should be always visible.
469 + * @param array $actions The list of actions
470 + * @param bool $always_visible Whether the actions should be always visible
498 471 *
499 472 * @return string
500 473 */
501 474 protected function row_actions( $actions, $always_visible = false ) {
502 475 $action_count = count( $actions );
503 - $i = 0;
504 476
477 + $i = 0;
478 +
505 479 if ( ! $action_count ) {
506 480 return '';
507 481 }
508 482
509 483 $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
510 -
511 484 foreach ( $actions as $action => $link ) {
512 - ++$i;
513 - $sep = $i === $action_count ? '' : ' | ';
485 + ++ $i;
486 + ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
514 487 $out .= "<span class='$action'>$link$sep</span>";
515 488 }
489 + $out .= '</div>';
516 490
517 - $out .= '</div>';
491 + $out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details', 'formidable' ) . '</span></button>';
518 492
519 - return $out . ( '<button type="button" class="toggle-row"><span class="screen-reader-text">' . esc_html__( 'Show more details', 'formidable' ) . '</span></button>' );
493 + return $out;
520 494 }
521 495
522 496 /**
523 497 * Display a view switcher
@@ -522,8 +496,9 @@
522 496 /**
523 497 * Display a view switcher
524 498 *
525 499 * @since 2.0.18
500 + * @access protected
526 501 *
527 502 * @param string $current_mode
528 503 */
529 504 protected function view_switcher( $current_mode ) {
@@ -532,10 +507,8 @@
532 507 <div class="view-switch">
533 508 <?php
534 509 foreach ( $this->modes as $mode => $title ) {
535 510 $classes = array( 'view-' . $mode );
536 -
537 - // phpcs:ignore Universal.Operators.StrictComparisons
538 511 if ( $current_mode == $mode ) {
539 512 $classes[] = 'current';
540 513 }
541 514
@@ -554,8 +527,9 @@
554 527 /**
555 528 * Get the current page number
556 529 *
557 530 * @since 2.0.18
531 + * @access public
558 532 *
559 533 * @return int
560 534 */
561 535 public function get_pagenum() {
@@ -571,18 +545,18 @@
571 545 /**
572 546 * Get number of items to display on a single page
573 547 *
574 548 * @since 2.0.18
549 + * @access protected
575 550 *
576 551 * @param string $option
577 - * @param int $default
552 + * @param int $default
578 553 *
579 554 * @return int
580 555 */
581 556 protected function get_items_per_page( $option, $default = 20 ) {
582 557 $per_page = (int) get_user_option( $option );
583 -
584 - if ( ! $per_page || $per_page < 1 ) {
558 + if ( empty( $per_page ) || $per_page < 1 ) {
585 559 $per_page = $default;
586 560 }
587 561
588 562 /**
@@ -604,8 +578,9 @@
604 578 /**
605 579 * Display the pagination.
606 580 *
607 581 * @since 2.0.18
582 + * @access protected
608 583 *
609 584 * @param string $which
610 585 */
611 586 protected function pagination( $which ) {
@@ -615,9 +590,8 @@
615 590
616 591 $total_items = $this->_pagination_args['total_items'];
617 592 $total_pages = $this->_pagination_args['total_pages'];
618 593 $infinite_scroll = false;
619 -
620 594 if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
621 595 $infinite_scroll = $this->_pagination_args['infinite_scroll'];
622 596 }
623 597
@@ -623,14 +597,17 @@
623 597
624 598 /* translators: %s: Number of items */
625 599 $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items, 'formidable' ), number_format_i18n( $total_items ) ) . '</span>';
626 600
627 - $current = $this->get_pagenum();
628 - $page_links = array();
601 + $current = $this->get_pagenum();
602 +
603 + $page_links = array();
604 +
629 605 $total_pages_before = '<span class="paging-input">';
630 606 $total_pages_after = '</span>';
631 - $disable = $this->disabled_pages( $total_pages );
632 607
608 + $disable = $this->disabled_pages( $total_pages );
609 +
633 610 $page_links[] = $this->add_page_link(
634 611 array(
635 612 'page' => 'first',
636 613 'arrow' => '&laquo;',
@@ -647,9 +624,9 @@
647 624 'disabled' => $disable['prev'],
648 625 )
649 626 );
650 627
651 - if ( 'bottom' === $which ) {
628 + if ( 'bottom' == $which ) {
652 629 $html_current_page = $current;
653 630 $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page', 'formidable' ) . '</span><span id="table-paging" class="paging-input">';
654 631 } else {
655 632 $html_current_page = sprintf(
@@ -658,9 +635,8 @@
658 635 $current,
659 636 strlen( $total_pages )
660 637 );
661 638 }
662 -
663 639 $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
664 640
665 641 /* translators: %1$s: Current page number, %2$s: Total pages */
666 642 $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging', 'formidable' ), $html_current_page, $html_total_pages ) . $total_pages_after;
@@ -683,15 +659,13 @@
683 659 )
684 660 );
685 661
686 662 $pagination_links_class = 'pagination-links';
687 -
688 - if ( $infinite_scroll ) {
663 + if ( ! empty( $infinite_scroll ) ) {
689 664 $pagination_links_class = ' hide-if-js';
690 665 }
666 + $output .= "\n" . '<span class="' . esc_attr( $pagination_links_class ) . '">' . join( "\n", $page_links ) . '</span>';
691 667
692 - $output .= "\n" . '<span class="' . esc_attr( $pagination_links_class ) . '">' . implode( "\n", $page_links ) . '</span>';
693 -
694 668 if ( $total_pages ) {
695 669 $page_class = $total_pages < 2 ? ' one-page' : '';
696 670 } else {
697 671 $page_class = ' no-pages';
@@ -700,13 +674,8 @@
700 674
701 675 echo $this->_pagination; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
702 676 }
703 677
704 - /**
705 - * @param int $total_pages
706 - *
707 - * @return array
708 - */
709 678 private function disabled_pages( $total_pages ) {
710 679 $current = $this->get_pagenum();
711 680 $disable = array(
712 681 'first' => false,
@@ -714,21 +683,19 @@
714 683 'prev' => false,
715 684 'next' => false,
716 685 );
717 686
718 - // phpcs:ignore Universal.Operators.StrictComparisons
719 687 if ( $current == 1 ) {
720 688 $disable['first'] = true;
721 689 $disable['prev'] = true;
722 - } elseif ( $current == 2 ) { // phpcs:ignore Universal.Operators.StrictComparisons
690 + } elseif ( $current == 2 ) {
723 691 $disable['first'] = true;
724 692 }
725 693
726 - // phpcs:ignore Universal.Operators.StrictComparisons
727 694 if ( $current == $total_pages ) {
728 695 $disable['last'] = true;
729 696 $disable['next'] = true;
730 - } elseif ( $current == $total_pages - 1 ) { // phpcs:ignore Universal.Operators.StrictComparisons
697 + } elseif ( $current == $total_pages - 1 ) {
731 698 $disable['last'] = true;
732 699 }
733 700
734 701 return $disable;
@@ -733,13 +700,8 @@
733 700
734 701 return $disable;
735 702 }
736 703
737 - /**
738 - * @param string $link
739 - *
740 - * @return string
741 - */
742 704 private function link_label( $link ) {
743 705 $labels = array(
744 706 'first' => __( 'First page', 'formidable' ),
745 707 'last' => __( 'Last page', 'formidable' ),
@@ -751,34 +713,26 @@
751 713 }
752 714
753 715 private function current_url() {
754 716 $current_url = set_url_scheme( 'http://' . FrmAppHelper::get_server_value( 'HTTP_HOST' ) . FrmAppHelper::get_server_value( 'REQUEST_URI' ) );
717 +
755 718 return remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
756 719 }
757 720
758 - /**
759 - * @param array $atts
760 - *
761 - * @return string
762 - */
763 721 private function add_page_link( $atts ) {
764 - return $atts['disabled'] ? $this->add_disabled_link( $atts['arrow'] ) : $this->add_active_link( $atts );
722 + if ( $atts['disabled'] ) {
723 + $link = $this->add_disabled_link( $atts['arrow'] );
724 + } else {
725 + $link = $this->add_active_link( $atts );
726 + }
727 +
728 + return $link;
765 729 }
766 730
767 - /**
768 - * @param string $label
769 - *
770 - * @return string
771 - */
772 731 private function add_disabled_link( $label ) {
773 732 return '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">' . $label . '</span>';
774 733 }
775 734
776 - /**
777 - * @param array $atts
778 - *
779 - * @return string
780 - */
781 735 private function add_active_link( $atts ) {
782 736 $url = esc_url( add_query_arg( 'paged', $atts['number'], $this->current_url() ) );
783 737 $label = $this->link_label( $atts['page'] );
784 738
@@ -799,8 +753,9 @@
799 753 *
800 754 * The second format will make the initial sorting order be descending
801 755 *
802 756 * @since 2.0.18
757 + * @access protected
803 758 *
804 759 * @return array
805 760 */
806 761 protected function get_sortable_columns() {
@@ -810,8 +765,9 @@
810 765 /**
811 766 * Gets the name of the default primary column.
812 767 *
813 768 * @since 4.3.0
769 + * @access protected
814 770 *
815 771 * @return string Name of the default primary column, in this case, an empty string.
816 772 */
817 773 protected function get_default_primary_column_name() {
@@ -835,8 +791,9 @@
835 791 /**
836 792 * Gets the name of the primary column.
837 793 *
838 794 * @since 4.3.0
795 + * @access protected
839 796 *
840 797 * @return string The name of the primary column.
841 798 */
842 799 protected function get_primary_column_name() {
@@ -858,9 +815,9 @@
858 815 * @param string $context Screen ID for specific list table, e.g. 'plugins'.
859 816 */
860 817 $column = apply_filters( 'list_table_primary_column', $default, $this->screen->id );
861 818
862 - if ( ! $column || ! isset( $columns[ $column ] ) ) {
819 + if ( empty( $column ) || ! isset( $columns[ $column ] ) ) {
863 820 $column = $default;
864 821 }
865 822
866 823 return $column;
@@ -869,18 +826,18 @@
869 826 /**
870 827 * Get a list of all, hidden and sortable columns, with filter applied
871 828 *
872 829 * @since 2.0.18
830 + * @access protected
873 831 *
874 832 * @return array
875 833 */
876 834 protected function get_column_info() {
877 835 // $_column_headers is already set / cached
878 - if ( is_array( $this->_column_headers ) ) {
836 + if ( isset( $this->_column_headers ) && is_array( $this->_column_headers ) ) {
879 837 // Back-compat for list tables that have been manually setting $_column_headers for horse reasons.
880 838 // In 4.3, we added a fourth argument for primary column.
881 839 $column_headers = array( array(), array(), array(), $this->get_primary_column_name() );
882 -
883 840 foreach ( $this->_column_headers as $key => $value ) {
884 841 $column_headers[ $key ] = $value;
885 842 }
886 843
@@ -886,10 +843,11 @@
886 843
887 844 return $column_headers;
888 845 }
889 846
890 - $columns = get_column_headers( $this->screen );
891 - $hidden = get_hidden_columns( $this->screen );
847 + $columns = get_column_headers( $this->screen );
848 + $hidden = get_hidden_columns( $this->screen );
849 +
892 850 $sortable_columns = $this->get_sortable_columns();
893 851 /**
894 852 * Filter the list table sortable columns for a specific screen.
895 853 *
@@ -902,9 +860,8 @@
902 860 */
903 861 $_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );
904 862
905 863 $sortable = array();
906 -
907 864 foreach ( $_sortable as $id => $data ) {
908 865 if ( empty( $data ) ) {
909 866 continue;
910 867 }
@@ -909,9 +866,8 @@
909 866 continue;
910 867 }
911 868
912 869 $data = (array) $data;
913 -
914 870 if ( ! isset( $data[1] ) ) {
915 871 $data[1] = false;
916 872 }
917 873
@@ -928,14 +884,15 @@
928 884 /**
929 885 * Return number of visible columns
930 886 *
931 887 * @since 2.0.18
888 + * @access public
932 889 *
933 890 * @return int
934 891 */
935 892 public function get_column_count() {
936 893 list ( $columns, $hidden ) = $this->get_column_info();
937 - $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
894 + $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
938 895
939 896 return count( $columns ) - count( $hidden );
940 897 }
941 898
@@ -942,49 +899,53 @@
942 899 /**
943 900 * Print column headers, accounting for hidden and sortable columns.
944 901 *
945 902 * @since 2.0.18
903 + * @access public
946 904 *
947 905 * @staticvar int $cb_counter
948 906 *
949 - * @param bool $with_id Whether to set the id attribute or not.
950 - *
951 - * @return void
907 + * @param bool $with_id Whether to set the id attribute or not
952 908 */
953 - public function print_column_headers( $with_id = true ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh, Generic.Metrics.CyclomaticComplexity.MaxExceeded, SlevomatCodingStandard.Files.LineLength.LineTooLong
909 + public function print_column_headers( $with_id = true ) {
954 910 list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
955 911
956 - $current_url = set_url_scheme( 'http://' . FrmAppHelper::get_server_value( 'HTTP_HOST' ) . FrmAppHelper::get_server_value( 'REQUEST_URI' ) );
957 - $current_url = remove_query_arg( 'paged', $current_url );
958 - $current_orderby = isset( $_GET['orderby'] ) ? sanitize_text_field( wp_unslash( $_GET['orderby'] ) ) : '';
959 - $current_order = isset( $_GET['order'] ) && 'desc' === $_GET['order'] ? 'desc' : 'asc';
912 + $current_url = set_url_scheme( 'http://' . FrmAppHelper::get_server_value( 'HTTP_HOST' ) . FrmAppHelper::get_server_value( 'REQUEST_URI' ) );
913 + $current_url = remove_query_arg( 'paged', $current_url );
960 914
961 - FrmAppController::apply_saved_sort_preference( $current_orderby, $current_order );
915 + if ( isset( $_GET['orderby'] ) ) {
916 + $current_orderby = sanitize_text_field( wp_unslash( $_GET['orderby'] ) );
917 + } else {
918 + $current_orderby = '';
919 + }
962 920
921 + if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) {
922 + $current_order = 'desc';
923 + } else {
924 + $current_order = 'asc';
925 + }
926 +
963 927 if ( ! empty( $columns['cb'] ) ) {
964 928 static $cb_counter = 1;
965 - $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All', 'formidable' ) . '</label>';
966 - $columns['cb'] .= '<input id="cb-select-all-' . esc_attr( $cb_counter ) . '" type="checkbox" />';
967 - ++$cb_counter;
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 ++;
968 932 }
969 933
970 934 foreach ( $columns as $column_key => $column_display_name ) {
971 - $class = array( 'manage-column', "column-$column_key" );
972 - $aria_sort_attr = '';
973 - $order_text = '';
935 + $class = array( 'manage-column', "column-$column_key" );
974 936
975 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
976 937 if ( in_array( $column_key, $hidden ) ) {
977 938 $class[] = 'hidden';
978 939 }
979 940
980 - if ( 'cb' === $column_key ) {
941 + if ( 'cb' == $column_key ) {
981 942 $class[] = 'check-column';
982 - } elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ), true ) ) {
943 + } elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) ) {
983 944 $class[] = 'num';
984 945 }
985 946
986 - if ( $column_key === $primary || $column_key === 'name' ) {
947 + if ( $column_key === $primary ) {
987 948 $class[] = 'column-primary';
988 949 }
989 950
990 951 if ( isset( $sortable[ $column_key ] ) ) {
@@ -989,19 +950,10 @@
989 950
990 951 if ( isset( $sortable[ $column_key ] ) ) {
991 952 list( $orderby, $desc_first ) = $sortable[ $column_key ];
992 953
993 - // phpcs:ignore Universal.Operators.StrictComparisons
994 954 if ( $current_orderby == $orderby ) {
995 - // The sorted column. The `aria-sort` attribute must be set only on the sorted column.
996 - if ( 'asc' === $current_order ) {
997 - $order = 'desc';
998 - $aria_sort_attr = ' aria-sort="ascending"';
999 - } else {
1000 - $order = 'asc';
1001 - $aria_sort_attr = ' aria-sort="descending"';
1002 - }
1003 -
955 + $order = 'asc' == $current_order ? 'desc' : 'asc';
1004 956 $class[] = 'sorted';
1005 957 $class[] = $current_order;
1006 958 } else {
1007 959 $order = $desc_first ? 'desc' : 'asc';
@@ -1006,41 +958,19 @@
1006 958 } else {
1007 959 $order = $desc_first ? 'desc' : 'asc';
1008 960 $class[] = 'sortable';
1009 961 $class[] = $desc_first ? 'asc' : 'desc';
1010 -
1011 - /* translators: Hidden accessibility text. */
1012 - $asc_text = __( 'Sort ascending.', 'formidable' );
1013 - /* translators: Hidden accessibility text. */
1014 - $desc_text = __( 'Sort descending.', 'formidable' );
1015 - $order_text = 'asc' === $order ? $asc_text : $desc_text;
1016 - }//end if
1017 -
1018 - if ( '' !== $order_text ) {
1019 - $order_text = ' <span class="screen-reader-text">' . $order_text . '</span>';
1020 962 }
1021 963
1022 - $column_display_name = sprintf(
1023 - '<a href="%1$s">' .
1024 - '<span>%2$s</span>' .
1025 - '<span class="sorting-indicators">' .
1026 - '<span class="sorting-indicator asc" aria-hidden="true"></span>' .
1027 - '<span class="sorting-indicator desc" aria-hidden="true"></span>' .
1028 - '</span>' .
1029 - '%3$s' .
1030 - '</a>',
1031 - esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ),
1032 - $column_display_name,
1033 - $order_text
1034 - );
1035 - }//end if
964 + $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 + }
1036 966
1037 - $tag = 'cb' === $column_key ? 'td' : 'th';
1038 - $scope = 'th' === $tag ? 'scope="col"' : '';
967 + $tag = ( 'cb' === $column_key ) ? 'td' : 'th';
968 + $scope = ( 'th' === $tag ) ? 'scope="col"' : '';
1039 969 $id = $with_id ? "id='" . esc_attr( $column_key ) . "'" : '';
1040 970
1041 - if ( $class ) {
1042 - $class = "class='" . esc_attr( implode( ' ', $class ) ) . "'";
971 + if ( ! empty( $class ) ) {
972 + $class = "class='" . esc_attr( join( ' ', $class ) ) . "'";
1043 973 }
1044 974
1045 975 if ( ! $this->has_min_items() && ! $with_id ) {
1046 976 // Hide the labels but show the border.
@@ -1045,10 +975,10 @@
1045 975 if ( ! $this->has_min_items() && ! $with_id ) {
1046 976 // Hide the labels but show the border.
1047 977 $column_display_name = '';
1048 978 }
1049 - echo "<$tag $scope $id $class $aria_sort_attr>$column_display_name</$tag>"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1050 - }//end foreach
979 + echo "<$tag $scope $id $class>$column_display_name</$tag>"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
980 + }
1051 981 }
1052 982
1053 983 /**
1054 984 * Display the table
@@ -1053,26 +983,18 @@
1053 983 /**
1054 984 * Display the table
1055 985 *
1056 986 * @since 2.0.18
1057 - *
1058 - * @param array $args
1059 - *
1060 - * @return void
987 + * @access public
1061 988 */
1062 - public function display( $args = array() ) {
989 + public function display() {
1063 990 $singular = $this->_args['singular'];
1064 991 $tbody_params = array();
1065 -
1066 992 if ( $singular ) {
1067 993 $tbody_params['data-wp-lists'] = 'list:' . $singular;
1068 994 }
1069 995
1070 - if ( $this->should_display( $args, 'display-top-nav' ) ) {
1071 - $this->display_tablenav( 'top' );
1072 - }
1073 - $this->screen->render_screen_reader_content( 'heading_list' );
1074 -
996 + $this->display_tablenav( 'top' );
1075 997 ?>
1076 998 <table class="wp-list-table <?php echo esc_attr( implode( ' ', $this->get_table_classes() ) ); ?>">
1077 999 <?php if ( $this->has_min_items( 1 ) ) { ?>
1078 1000 <thead>
@@ -1085,9 +1007,9 @@
1085 1007 <tbody id="the-list"<?php FrmAppHelper::array_to_html_params( $tbody_params, true ); ?>>
1086 1008 <?php $this->display_rows_or_placeholder(); ?>
1087 1009 </tbody>
1088 1010
1089 - <?php if ( $this->has_min_items( 1 ) && $this->should_display( $args, 'display-bottom-headers' ) ) { ?>
1011 + <?php if ( $this->has_min_items( 1 ) ) { ?>
1090 1012 <tfoot>
1091 1013 <tr>
1092 1014 <?php $this->print_column_headers( false ); ?>
1093 1015 </tr>
@@ -1094,29 +1016,16 @@
1094 1016 </tfoot>
1095 1017 <?php } ?>
1096 1018 </table>
1097 1019 <?php
1098 - if ( $this->should_display( $args, 'display-bottom-nav' ) ) {
1099 - $this->display_tablenav( 'bottom' );
1100 - }
1020 + $this->display_tablenav( 'bottom' );
1101 1021 }
1102 1022
1103 1023 /**
1104 - * Determines if a particular feature or element should be displayed.
1105 - *
1106 - * @param array $args An associative array of arguments.
1107 - * @param string $settings The specific setting key to check within the arguments array.
1108 - *
1109 - * @return bool Returns true if the setting is not set or if it is not false; otherwise, returns false.
1110 - */
1111 - protected function should_display( $args, $settings ) {
1112 - return ! isset( $args[ $settings ] ) || false !== $args[ $settings ];
1113 - }
1114 -
1115 - /**
1116 1024 * Get a list of CSS classes for the list table table tag.
1117 1025 *
1118 1026 * @since 2.0.18
1027 + * @access protected
1119 1028 *
1120 1029 * @return array List of CSS classes for the table tag.
1121 1030 */
1122 1031 protected function get_table_classes() {
@@ -1126,8 +1035,9 @@
1126 1035 /**
1127 1036 * Generate the table navigation above or below the table
1128 1037 *
1129 1038 * @since 2.0.18
1039 + * @access protected
1130 1040 *
1131 1041 * @param string $which
1132 1042 */
1133 1043 protected function display_tablenav( $which ) {
@@ -1132,9 +1042,8 @@
1132 1042 */
1133 1043 protected function display_tablenav( $which ) {
1134 1044 if ( 'top' === $which ) {
1135 1045 wp_nonce_field( 'bulk-' . $this->_args['plural'], '_wpnonce', false );
1136 -
1137 1046 if ( ! $this->has_min_items( 1 ) ) {
1138 1047 // Don't show bulk actions if no items.
1139 1048 return;
1140 1049 }
@@ -1162,12 +1071,8 @@
1162 1071 * Use this to exclude the footer labels and bulk items.
1163 1072 * When close together, it feels like duplicates.
1164 1073 *
1165 1074 * @since 4.07
1166 - *
1167 - * @param int $limit
1168 - *
1169 - * @return bool
1170 1075 */
1171 1076 protected function has_min_items( $limit = 5 ) {
1172 1077 return $this->has_items() && ( $this->total_items === false || $this->total_items >= $limit );
1173 1078 }
@@ -1175,8 +1080,9 @@
1175 1080 /**
1176 1081 * Extra controls to be displayed between bulk actions and pagination
1177 1082 *
1178 1083 * @since 2.0.18
1084 + * @access protected
1179 1085 *
1180 1086 * @param string $which
1181 1087 */
1182 1088 protected function extra_tablenav( $which ) {
@@ -1185,8 +1091,9 @@
1185 1091 /**
1186 1092 * Generate the tbody element for the list table.
1187 1093 *
1188 1094 * @since 2.0.18
1095 + * @access public
1189 1096 */
1190 1097 public function display_rows_or_placeholder() {
1191 1098 if ( $this->has_items() ) {
1192 1099 $this->display_rows();
@@ -1200,10 +1107,11 @@
1200 1107 /**
1201 1108 * Generates content for a single row of the table
1202 1109 *
1203 1110 * @since 2.0.18
1111 + * @access public
1204 1112 *
1205 - * @param object $item The current item.
1113 + * @param object $item The current item
1206 1114 */
1207 1115 public function single_row( $item ) {
1208 1116 echo '<tr>';
1209 1117 $this->single_row_columns( $item );
@@ -1213,10 +1121,11 @@
1213 1121 /**
1214 1122 * Generates the columns for a single row of the table
1215 1123 *
1216 1124 * @since 2.0.18
1125 + * @access protected
1217 1126 *
1218 - * @param object $item The current item.
1127 + * @param object $item The current item
1219 1128 */
1220 1129 protected function single_row_columns( $item ) {
1221 1130 list( $columns, $hidden,, $primary ) = $this->get_column_info();
1222 1131
@@ -1221,14 +1130,12 @@
1221 1130 list( $columns, $hidden,, $primary ) = $this->get_column_info();
1222 1131
1223 1132 foreach ( $columns as $column_name => $column_display_name ) {
1224 1133 $classes = "$column_name column-$column_name";
1225 -
1226 1134 if ( $primary === $column_name ) {
1227 1135 $classes .= ' has-row-actions column-primary';
1228 1136 }
1229 1137
1230 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
1231 1138 if ( in_array( $column_name, $hidden ) ) {
1232 1139 $classes .= ' hidden';
1233 1140 }
1234 1141
@@ -1252,9 +1159,9 @@
1252 1159
1253 1160 echo $this->handle_row_actions( $item, $column_name, $primary ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1254 1161 echo '</td>';
1255 1162 }
1256 - }//end foreach
1163 + }
1257 1164 }
1258 1165
1259 1166 /**
1260 1167 * Generates and display row actions links for the list table.
@@ -1259,8 +1166,9 @@
1259 1166 /**
1260 1167 * Generates and display row actions links for the list table.
1261 1168 *
1262 1169 * @since 4.3.0
1170 + * @access protected
1263 1171 *
1264 1172 * @param object $item The item being acted upon.
1265 1173 * @param string $column_name Current column name.
1266 1174 * @param string $primary Primary column name.
@@ -1267,9 +1175,9 @@
1267 1175 *
1268 1176 * @return string The row actions output. In this case, an empty string.
1269 1177 */
1270 1178 protected function handle_row_actions( $item, $column_name, $primary ) {
1271 - 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
1179 + return $column_name == $primary ? '<button type="button" class="toggle-row"><span class="screen-reader-text">' . esc_html__( 'Show more details', 'formidable' ) . '</span></button>' : '';
1272 1180 }
1273 1181
1274 1182 /**
1275 1183 * Handle an incoming ajax request (called from admin-ajax.php)
@@ -1274,14 +1182,14 @@
1274 1182 /**
1275 1183 * Handle an incoming ajax request (called from admin-ajax.php)
1276 1184 *
1277 1185 * @since 2.0.18
1186 + * @access public
1278 1187 */
1279 1188 public function ajax_response() {
1280 1189 $this->prepare_items();
1281 1190
1282 1191 ob_start();
1283 -
1284 1192 if ( ! empty( $_REQUEST['no_placeholder'] ) ) {
1285 1193 $this->display_rows();
1286 1194 } else {
1287 1195 $this->display_rows_or_placeholder();
@@ -1286,9 +1194,10 @@
1286 1194 } else {
1287 1195 $this->display_rows_or_placeholder();
1288 1196 }
1289 1197
1290 - $rows = ob_get_clean();
1198 + $rows = ob_get_clean();
1199 +
1291 1200 $response = array( 'rows' => $rows );
1292 1201
1293 1202 if ( isset( $this->_pagination_args['total_items'] ) ) {
1294 1203 $response['total_items_i18n'] = sprintf(
@@ -1296,9 +1205,8 @@
1296 1205 _n( '%s item', '%s items', $this->_pagination_args['total_items'], 'formidable' ),
1297 1206 number_format_i18n( $this->_pagination_args['total_items'] )
1298 1207 );
1299 1208 }
1300 -
1301 1209 if ( isset( $this->_pagination_args['total_pages'] ) ) {
1302 1210 $response['total_pages'] = $this->_pagination_args['total_pages'];
1303 1211 $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
1304 1212 }
@@ -1308,9 +1216,9 @@
1308 1216
1309 1217 /**
1310 1218 * Send required variables to JavaScript land
1311 1219 *
1312 - * @return void
1220 + * @access public
1313 1221 */
1314 1222 public function _js_vars() {
1315 1223 $args = array(
1316 1224 'class' => get_class( $this ),
@@ -1320,13 +1228,6 @@
1320 1228 ),
1321 1229 );
1322 1230
1323 1231 printf( "<script type='text/javascript'>list_args = %s;</script>\n", wp_json_encode( $args ) );
1324 - }
1325 -
1326 - /**
1327 - * @return string
1328 - */
1329 - protected function loaded_from() {
1330 - return '';
1331 1232 }
1332 1233 }