PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0
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 +168 -273 6.275.0 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 );
@@ -167,9 +155,9 @@
167 155 }
168 156
169 157 public function display_rows() {
170 158 foreach ( $this->items as $item ) {
171 - echo "\n\t", $this->single_row( $item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
159 + echo "\n\t", $this->single_row( $item ); // WPCS: XSS ok.
172 160 }
173 161 }
174 162
175 163 /**
@@ -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,18 +322,17 @@
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 - echo implode( " |</li>\n", $views ) . "</li>\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
334 + echo implode( " |</li>\n", $views ) . "</li>\n"; // WPCS: XSS ok.
345 335 echo '</ul>';
346 336 }
347 337
348 338 /**
@@ -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,30 +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 - $params = array(
403 - 'value' => $name,
404 - );
394 + $class = 'edit' == $name ? ' class="hide-if-no-js"' : '';
405 395
406 - if ( 'edit' === $name ) {
407 - $params['class'] = 'hide-if-no-js';
408 - }
409 -
410 - echo "\t<option ";
411 - FrmAppHelper::array_to_html_params( $params, true );
412 - echo '>' . esc_html( $title ) . '</option>' . "\n";
396 + echo "\t<option value='" . esc_attr( $name ) . "'$class>" . esc_html( $title ) . "</option>\n"; // WPCS: XSS ok.
413 397 }
414 398
415 399 echo "</select>\n";
416 400
@@ -417,21 +401,9 @@
417 401 if ( isset( $this->_actions['bulk_delete'] ) ) {
418 402 $verify = $this->confirm_bulk_delete();
419 403
420 404 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>';
405 + 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 406 }
435 407 }
436 408
437 409 submit_button( __( 'Apply', 'formidable' ), 'action', '', false, array( 'id' => "doaction$two" ) );
@@ -448,18 +420,18 @@
448 420 /**
449 421 * Get the current action selected from the bulk actions dropdown.
450 422 *
451 423 * @since 2.0.18
424 + * @access public
452 425 *
453 - * @return false|string The action name or False if no action was selected
426 + * @return string|false The action name or False if no action was selected
454 427 */
455 428 public function current_action() {
456 - if ( ! empty( $_REQUEST['filter_action'] ) ) {
429 + if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) ) {
457 430 return false;
458 431 }
459 432
460 433 $action = $this->get_bulk_action( 'action' );
461 -
462 434 if ( $action === false ) {
463 435 $action = $this->get_bulk_action( 'action2' );
464 436 }
465 437
@@ -465,23 +437,16 @@
465 437
466 438 return $action;
467 439 }
468 440
469 - /**
470 - * @param string $action_name
471 - *
472 - * @return false|string
473 - */
474 - private function get_bulk_action( $action_name ) {
441 + private static function get_bulk_action( $action_name ) {
475 442 $action = false;
476 - $action_param = $this->get_param(
443 + $action_param = self::get_param(
477 444 array(
478 445 'param' => $action_name,
479 446 'sanitize' => 'sanitize_text_field',
480 447 )
481 448 );
482 -
483 - // phpcs:ignore Universal.Operators.StrictComparisons
484 449 if ( $action_param && - 1 != $action_param ) {
485 450 $action = $action_param;
486 451 }
487 452
@@ -491,33 +456,35 @@
491 456 /**
492 457 * Generate row actions div
493 458 *
494 459 * @since 2.0.18
460 + * @access protected
495 461 *
496 - * @param array $actions The list of actions.
497 - * @param bool $always_visible Whether the actions should be always visible.
462 + * @param array $actions The list of actions
463 + * @param bool $always_visible Whether the actions should be always visible
498 464 *
499 465 * @return string
500 466 */
501 467 protected function row_actions( $actions, $always_visible = false ) {
502 468 $action_count = count( $actions );
503 - $i = 0;
504 469
470 + $i = 0;
471 +
505 472 if ( ! $action_count ) {
506 473 return '';
507 474 }
508 475
509 476 $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
510 -
511 477 foreach ( $actions as $action => $link ) {
512 - ++$i;
513 - $sep = $i === $action_count ? '' : ' | ';
478 + ++ $i;
479 + ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
514 480 $out .= "<span class='$action'>$link$sep</span>";
515 481 }
482 + $out .= '</div>';
516 483
517 - $out .= '</div>';
484 + $out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details', 'formidable' ) . '</span></button>';
518 485
519 - return $out . ( '<button type="button" class="toggle-row"><span class="screen-reader-text">' . esc_html__( 'Show more details', 'formidable' ) . '</span></button>' );
486 + return $out;
520 487 }
521 488
522 489 /**
523 490 * Display a view switcher
@@ -522,8 +489,9 @@
522 489 /**
523 490 * Display a view switcher
524 491 *
525 492 * @since 2.0.18
493 + * @access protected
526 494 *
527 495 * @param string $current_mode
528 496 */
529 497 protected function view_switcher( $current_mode ) {
@@ -532,10 +500,8 @@
532 500 <div class="view-switch">
533 501 <?php
534 502 foreach ( $this->modes as $mode => $title ) {
535 503 $classes = array( 'view-' . $mode );
536 -
537 - // phpcs:ignore Universal.Operators.StrictComparisons
538 504 if ( $current_mode == $mode ) {
539 505 $classes[] = 'current';
540 506 }
541 507
@@ -554,8 +520,9 @@
554 520 /**
555 521 * Get the current page number
556 522 *
557 523 * @since 2.0.18
524 + * @access public
558 525 *
559 526 * @return int
560 527 */
561 528 public function get_pagenum() {
@@ -571,18 +538,18 @@
571 538 /**
572 539 * Get number of items to display on a single page
573 540 *
574 541 * @since 2.0.18
542 + * @access protected
575 543 *
576 544 * @param string $option
577 - * @param int $default
545 + * @param int $default
578 546 *
579 547 * @return int
580 548 */
581 549 protected function get_items_per_page( $option, $default = 20 ) {
582 550 $per_page = (int) get_user_option( $option );
583 -
584 - if ( ! $per_page || $per_page < 1 ) {
551 + if ( empty( $per_page ) || $per_page < 1 ) {
585 552 $per_page = $default;
586 553 }
587 554
588 555 /**
@@ -604,8 +571,9 @@
604 571 /**
605 572 * Display the pagination.
606 573 *
607 574 * @since 2.0.18
575 + * @access protected
608 576 *
609 577 * @param string $which
610 578 */
611 579 protected function pagination( $which ) {
@@ -615,9 +583,8 @@
615 583
616 584 $total_items = $this->_pagination_args['total_items'];
617 585 $total_pages = $this->_pagination_args['total_pages'];
618 586 $infinite_scroll = false;
619 -
620 587 if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
621 588 $infinite_scroll = $this->_pagination_args['infinite_scroll'];
622 589 }
623 590
@@ -623,14 +590,17 @@
623 590
624 591 /* translators: %s: Number of items */
625 592 $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items, 'formidable' ), number_format_i18n( $total_items ) ) . '</span>';
626 593
627 - $current = $this->get_pagenum();
628 - $page_links = array();
594 + $current = $this->get_pagenum();
595 +
596 + $page_links = array();
597 +
629 598 $total_pages_before = '<span class="paging-input">';
630 599 $total_pages_after = '</span>';
631 - $disable = $this->disabled_pages( $total_pages );
632 600
601 + $disable = $this->disabled_pages( $total_pages );
602 +
633 603 $page_links[] = $this->add_page_link(
634 604 array(
635 605 'page' => 'first',
636 606 'arrow' => '&laquo;',
@@ -647,9 +617,9 @@
647 617 'disabled' => $disable['prev'],
648 618 )
649 619 );
650 620
651 - if ( 'bottom' === $which ) {
621 + if ( 'bottom' == $which ) {
652 622 $html_current_page = $current;
653 623 $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page', 'formidable' ) . '</span><span id="table-paging" class="paging-input">';
654 624 } else {
655 625 $html_current_page = sprintf(
@@ -658,9 +628,8 @@
658 628 $current,
659 629 strlen( $total_pages )
660 630 );
661 631 }
662 -
663 632 $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
664 633
665 634 /* translators: %1$s: Current page number, %2$s: Total pages */
666 635 $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 +652,13 @@
683 652 )
684 653 );
685 654
686 655 $pagination_links_class = 'pagination-links';
687 -
688 - if ( $infinite_scroll ) {
656 + if ( ! empty( $infinite_scroll ) ) {
689 657 $pagination_links_class = ' hide-if-js';
690 658 }
659 + $output .= "\n" . '<span class="' . esc_attr( $pagination_links_class ) . '">' . join( "\n", $page_links ) . '</span>';
691 660
692 - $output .= "\n" . '<span class="' . esc_attr( $pagination_links_class ) . '">' . implode( "\n", $page_links ) . '</span>';
693 -
694 661 if ( $total_pages ) {
695 662 $page_class = $total_pages < 2 ? ' one-page' : '';
696 663 } else {
697 664 $page_class = ' no-pages';
@@ -697,16 +664,11 @@
697 664 $page_class = ' no-pages';
698 665 }
699 666 $this->_pagination = "<div class='tablenav-pages" . esc_attr( $page_class ) . "'>$output</div>";
700 667
701 - echo $this->_pagination; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
668 + echo $this->_pagination; // WPCS: XSS ok.
702 669 }
703 670
704 - /**
705 - * @param int $total_pages
706 - *
707 - * @return array
708 - */
709 671 private function disabled_pages( $total_pages ) {
710 672 $current = $this->get_pagenum();
711 673 $disable = array(
712 674 'first' => false,
@@ -714,21 +676,19 @@
714 676 'prev' => false,
715 677 'next' => false,
716 678 );
717 679
718 - // phpcs:ignore Universal.Operators.StrictComparisons
719 680 if ( $current == 1 ) {
720 681 $disable['first'] = true;
721 682 $disable['prev'] = true;
722 - } elseif ( $current == 2 ) { // phpcs:ignore Universal.Operators.StrictComparisons
683 + } elseif ( $current == 2 ) {
723 684 $disable['first'] = true;
724 685 }
725 686
726 - // phpcs:ignore Universal.Operators.StrictComparisons
727 687 if ( $current == $total_pages ) {
728 688 $disable['last'] = true;
729 689 $disable['next'] = true;
730 - } elseif ( $current == $total_pages - 1 ) { // phpcs:ignore Universal.Operators.StrictComparisons
690 + } elseif ( $current == $total_pages - 1 ) {
731 691 $disable['last'] = true;
732 692 }
733 693
734 694 return $disable;
@@ -733,13 +693,8 @@
733 693
734 694 return $disable;
735 695 }
736 696
737 - /**
738 - * @param string $link
739 - *
740 - * @return string
741 - */
742 697 private function link_label( $link ) {
743 698 $labels = array(
744 699 'first' => __( 'First page', 'formidable' ),
745 700 'last' => __( 'Last page', 'formidable' ),
@@ -751,34 +706,26 @@
751 706 }
752 707
753 708 private function current_url() {
754 709 $current_url = set_url_scheme( 'http://' . FrmAppHelper::get_server_value( 'HTTP_HOST' ) . FrmAppHelper::get_server_value( 'REQUEST_URI' ) );
710 +
755 711 return remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
756 712 }
757 713
758 - /**
759 - * @param array $atts
760 - *
761 - * @return string
762 - */
763 714 private function add_page_link( $atts ) {
764 - return $atts['disabled'] ? $this->add_disabled_link( $atts['arrow'] ) : $this->add_active_link( $atts );
715 + if ( $atts['disabled'] ) {
716 + $link = $this->add_disabled_link( $atts['arrow'] );
717 + } else {
718 + $link = $this->add_active_link( $atts );
719 + }
720 +
721 + return $link;
765 722 }
766 723
767 - /**
768 - * @param string $label
769 - *
770 - * @return string
771 - */
772 724 private function add_disabled_link( $label ) {
773 725 return '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">' . $label . '</span>';
774 726 }
775 727
776 - /**
777 - * @param array $atts
778 - *
779 - * @return string
780 - */
781 728 private function add_active_link( $atts ) {
782 729 $url = esc_url( add_query_arg( 'paged', $atts['number'], $this->current_url() ) );
783 730 $label = $this->link_label( $atts['page'] );
784 731
@@ -799,8 +746,9 @@
799 746 *
800 747 * The second format will make the initial sorting order be descending
801 748 *
802 749 * @since 2.0.18
750 + * @access protected
803 751 *
804 752 * @return array
805 753 */
806 754 protected function get_sortable_columns() {
@@ -810,8 +758,9 @@
810 758 /**
811 759 * Gets the name of the default primary column.
812 760 *
813 761 * @since 4.3.0
762 + * @access protected
814 763 *
815 764 * @return string Name of the default primary column, in this case, an empty string.
816 765 */
817 766 protected function get_default_primary_column_name() {
@@ -835,8 +784,9 @@
835 784 /**
836 785 * Gets the name of the primary column.
837 786 *
838 787 * @since 4.3.0
788 + * @access protected
839 789 *
840 790 * @return string The name of the primary column.
841 791 */
842 792 protected function get_primary_column_name() {
@@ -858,9 +808,9 @@
858 808 * @param string $context Screen ID for specific list table, e.g. 'plugins'.
859 809 */
860 810 $column = apply_filters( 'list_table_primary_column', $default, $this->screen->id );
861 811
862 - if ( ! $column || ! isset( $columns[ $column ] ) ) {
812 + if ( empty( $column ) || ! isset( $columns[ $column ] ) ) {
863 813 $column = $default;
864 814 }
865 815
866 816 return $column;
@@ -869,18 +819,18 @@
869 819 /**
870 820 * Get a list of all, hidden and sortable columns, with filter applied
871 821 *
872 822 * @since 2.0.18
823 + * @access protected
873 824 *
874 825 * @return array
875 826 */
876 827 protected function get_column_info() {
877 828 // $_column_headers is already set / cached
878 - if ( is_array( $this->_column_headers ) ) {
829 + if ( isset( $this->_column_headers ) && is_array( $this->_column_headers ) ) {
879 830 // Back-compat for list tables that have been manually setting $_column_headers for horse reasons.
880 831 // In 4.3, we added a fourth argument for primary column.
881 832 $column_headers = array( array(), array(), array(), $this->get_primary_column_name() );
882 -
883 833 foreach ( $this->_column_headers as $key => $value ) {
884 834 $column_headers[ $key ] = $value;
885 835 }
886 836
@@ -886,10 +836,11 @@
886 836
887 837 return $column_headers;
888 838 }
889 839
890 - $columns = get_column_headers( $this->screen );
891 - $hidden = get_hidden_columns( $this->screen );
840 + $columns = get_column_headers( $this->screen );
841 + $hidden = get_hidden_columns( $this->screen );
842 +
892 843 $sortable_columns = $this->get_sortable_columns();
893 844 /**
894 845 * Filter the list table sortable columns for a specific screen.
895 846 *
@@ -902,9 +853,8 @@
902 853 */
903 854 $_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );
904 855
905 856 $sortable = array();
906 -
907 857 foreach ( $_sortable as $id => $data ) {
908 858 if ( empty( $data ) ) {
909 859 continue;
910 860 }
@@ -909,9 +859,8 @@
909 859 continue;
910 860 }
911 861
912 862 $data = (array) $data;
913 -
914 863 if ( ! isset( $data[1] ) ) {
915 864 $data[1] = false;
916 865 }
917 866
@@ -928,14 +877,15 @@
928 877 /**
929 878 * Return number of visible columns
930 879 *
931 880 * @since 2.0.18
881 + * @access public
932 882 *
933 883 * @return int
934 884 */
935 885 public function get_column_count() {
936 886 list ( $columns, $hidden ) = $this->get_column_info();
937 - $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
887 + $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
938 888
939 889 return count( $columns ) - count( $hidden );
940 890 }
941 891
@@ -942,49 +892,53 @@
942 892 /**
943 893 * Print column headers, accounting for hidden and sortable columns.
944 894 *
945 895 * @since 2.0.18
896 + * @access public
946 897 *
947 898 * @staticvar int $cb_counter
948 899 *
949 - * @param bool $with_id Whether to set the id attribute or not.
950 - *
951 - * @return void
900 + * @param bool $with_id Whether to set the id attribute or not
952 901 */
953 - public function print_column_headers( $with_id = true ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh, Generic.Metrics.CyclomaticComplexity.MaxExceeded, SlevomatCodingStandard.Files.LineLength.LineTooLong
902 + public function print_column_headers( $with_id = true ) {
954 903 list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
955 904
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';
905 + $current_url = set_url_scheme( 'http://' . FrmAppHelper::get_server_value( 'HTTP_HOST' ) . FrmAppHelper::get_server_value( 'REQUEST_URI' ) );
906 + $current_url = remove_query_arg( 'paged', $current_url );
960 907
961 - FrmAppController::apply_saved_sort_preference( $current_orderby, $current_order );
908 + if ( isset( $_GET['orderby'] ) ) {
909 + $current_orderby = sanitize_text_field( wp_unslash( $_GET['orderby'] ) );
910 + } else {
911 + $current_orderby = '';
912 + }
962 913
914 + if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) {
915 + $current_order = 'desc';
916 + } else {
917 + $current_order = 'asc';
918 + }
919 +
963 920 if ( ! empty( $columns['cb'] ) ) {
964 921 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;
922 + $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All', 'formidable' ) . '</label>';
923 + $columns['cb'] .= '<input id="cb-select-all-' . esc_attr( $cb_counter ) . '" type="checkbox" />';
924 + $cb_counter ++;
968 925 }
969 926
970 927 foreach ( $columns as $column_key => $column_display_name ) {
971 - $class = array( 'manage-column', "column-$column_key" );
972 - $aria_sort_attr = '';
973 - $order_text = '';
928 + $class = array( 'manage-column', "column-$column_key" );
974 929
975 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
976 930 if ( in_array( $column_key, $hidden ) ) {
977 931 $class[] = 'hidden';
978 932 }
979 933
980 - if ( 'cb' === $column_key ) {
934 + if ( 'cb' == $column_key ) {
981 935 $class[] = 'check-column';
982 - } elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ), true ) ) {
936 + } elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) ) {
983 937 $class[] = 'num';
984 938 }
985 939
986 - if ( $column_key === $primary || $column_key === 'name' ) {
940 + if ( $column_key === $primary ) {
987 941 $class[] = 'column-primary';
988 942 }
989 943
990 944 if ( isset( $sortable[ $column_key ] ) ) {
@@ -989,19 +943,10 @@
989 943
990 944 if ( isset( $sortable[ $column_key ] ) ) {
991 945 list( $orderby, $desc_first ) = $sortable[ $column_key ];
992 946
993 - // phpcs:ignore Universal.Operators.StrictComparisons
994 947 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 -
948 + $order = 'asc' == $current_order ? 'desc' : 'asc';
1004 949 $class[] = 'sorted';
1005 950 $class[] = $current_order;
1006 951 } else {
1007 952 $order = $desc_first ? 'desc' : 'asc';
@@ -1006,41 +951,19 @@
1006 951 } else {
1007 952 $order = $desc_first ? 'desc' : 'asc';
1008 953 $class[] = 'sortable';
1009 954 $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 955 }
1021 956
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
957 + $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>';
958 + }
1036 959
1037 - $tag = 'cb' === $column_key ? 'td' : 'th';
1038 - $scope = 'th' === $tag ? 'scope="col"' : '';
960 + $tag = ( 'cb' === $column_key ) ? 'td' : 'th';
961 + $scope = ( 'th' === $tag ) ? 'scope="col"' : '';
1039 962 $id = $with_id ? "id='" . esc_attr( $column_key ) . "'" : '';
1040 963
1041 - if ( $class ) {
1042 - $class = "class='" . esc_attr( implode( ' ', $class ) ) . "'";
964 + if ( ! empty( $class ) ) {
965 + $class = "class='" . esc_attr( join( ' ', $class ) ) . "'";
1043 966 }
1044 967
1045 968 if ( ! $this->has_min_items() && ! $with_id ) {
1046 969 // Hide the labels but show the border.
@@ -1045,10 +968,10 @@
1045 968 if ( ! $this->has_min_items() && ! $with_id ) {
1046 969 // Hide the labels but show the border.
1047 970 $column_display_name = '';
1048 971 }
1049 - echo "<$tag $scope $id $class $aria_sort_attr>$column_display_name</$tag>"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1050 - }//end foreach
972 + echo "<$tag $scope $id $class>$column_display_name</$tag>"; // WPCS: XSS ok.
973 + }
1051 974 }
1052 975
1053 976 /**
1054 977 * Display the table
@@ -1053,26 +976,14 @@
1053 976 /**
1054 977 * Display the table
1055 978 *
1056 979 * @since 2.0.18
1057 - *
1058 - * @param array $args
1059 - *
1060 - * @return void
980 + * @access public
1061 981 */
1062 - public function display( $args = array() ) {
1063 - $singular = $this->_args['singular'];
1064 - $tbody_params = array();
982 + public function display() {
983 + $singular = $this->_args['singular'];
1065 984
1066 - if ( $singular ) {
1067 - $tbody_params['data-wp-lists'] = 'list:' . $singular;
1068 - }
1069 -
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 -
985 + $this->display_tablenav( 'top' );
1075 986 ?>
1076 987 <table class="wp-list-table <?php echo esc_attr( implode( ' ', $this->get_table_classes() ) ); ?>">
1077 988 <?php if ( $this->has_min_items( 1 ) ) { ?>
1078 989 <thead>
@@ -1081,13 +992,13 @@
1081 992 </tr>
1082 993 </thead>
1083 994 <?php } ?>
1084 995
1085 - <tbody id="the-list"<?php FrmAppHelper::array_to_html_params( $tbody_params, true ); ?>>
996 + <tbody id="the-list"<?php echo( $singular ? " data-wp-lists='list:" . esc_attr( $singular ) . "'" : '' ); // WPCS: XSS ok. ?>>
1086 997 <?php $this->display_rows_or_placeholder(); ?>
1087 998 </tbody>
1088 999
1089 - <?php if ( $this->has_min_items( 1 ) && $this->should_display( $args, 'display-bottom-headers' ) ) { ?>
1000 + <?php if ( $this->has_min_items( 1 ) ) { ?>
1090 1001 <tfoot>
1091 1002 <tr>
1092 1003 <?php $this->print_column_headers( false ); ?>
1093 1004 </tr>
@@ -1094,29 +1005,16 @@
1094 1005 </tfoot>
1095 1006 <?php } ?>
1096 1007 </table>
1097 1008 <?php
1098 - if ( $this->should_display( $args, 'display-bottom-nav' ) ) {
1099 - $this->display_tablenav( 'bottom' );
1100 - }
1009 + $this->display_tablenav( 'bottom' );
1101 1010 }
1102 1011
1103 1012 /**
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 1013 * Get a list of CSS classes for the list table table tag.
1117 1014 *
1118 1015 * @since 2.0.18
1016 + * @access protected
1119 1017 *
1120 1018 * @return array List of CSS classes for the table tag.
1121 1019 */
1122 1020 protected function get_table_classes() {
@@ -1126,15 +1024,15 @@
1126 1024 /**
1127 1025 * Generate the table navigation above or below the table
1128 1026 *
1129 1027 * @since 2.0.18
1028 + * @access protected
1130 1029 *
1131 1030 * @param string $which
1132 1031 */
1133 1032 protected function display_tablenav( $which ) {
1134 - if ( 'top' === $which ) {
1033 + if ( 'top' == $which ) {
1135 1034 wp_nonce_field( 'bulk-' . $this->_args['plural'], '_wpnonce', false );
1136 -
1137 1035 if ( ! $this->has_min_items( 1 ) ) {
1138 1036 // Don't show bulk actions if no items.
1139 1037 return;
1140 1038 }
@@ -1162,12 +1060,8 @@
1162 1060 * Use this to exclude the footer labels and bulk items.
1163 1061 * When close together, it feels like duplicates.
1164 1062 *
1165 1063 * @since 4.07
1166 - *
1167 - * @param int $limit
1168 - *
1169 - * @return bool
1170 1064 */
1171 1065 protected function has_min_items( $limit = 5 ) {
1172 1066 return $this->has_items() && ( $this->total_items === false || $this->total_items >= $limit );
1173 1067 }
@@ -1175,8 +1069,9 @@
1175 1069 /**
1176 1070 * Extra controls to be displayed between bulk actions and pagination
1177 1071 *
1178 1072 * @since 2.0.18
1073 + * @access protected
1179 1074 *
1180 1075 * @param string $which
1181 1076 */
1182 1077 protected function extra_tablenav( $which ) {
@@ -1185,8 +1080,9 @@
1185 1080 /**
1186 1081 * Generate the tbody element for the list table.
1187 1082 *
1188 1083 * @since 2.0.18
1084 + * @access public
1189 1085 */
1190 1086 public function display_rows_or_placeholder() {
1191 1087 if ( $this->has_items() ) {
1192 1088 $this->display_rows();
@@ -1200,10 +1096,11 @@
1200 1096 /**
1201 1097 * Generates content for a single row of the table
1202 1098 *
1203 1099 * @since 2.0.18
1100 + * @access public
1204 1101 *
1205 - * @param object $item The current item.
1102 + * @param object $item The current item
1206 1103 */
1207 1104 public function single_row( $item ) {
1208 1105 echo '<tr>';
1209 1106 $this->single_row_columns( $item );
@@ -1213,10 +1110,11 @@
1213 1110 /**
1214 1111 * Generates the columns for a single row of the table
1215 1112 *
1216 1113 * @since 2.0.18
1114 + * @access protected
1217 1115 *
1218 - * @param object $item The current item.
1116 + * @param object $item The current item
1219 1117 */
1220 1118 protected function single_row_columns( $item ) {
1221 1119 list( $columns, $hidden,, $primary ) = $this->get_column_info();
1222 1120
@@ -1221,40 +1119,43 @@
1221 1119 list( $columns, $hidden,, $primary ) = $this->get_column_info();
1222 1120
1223 1121 foreach ( $columns as $column_name => $column_display_name ) {
1224 1122 $classes = "$column_name column-$column_name";
1225 -
1226 1123 if ( $primary === $column_name ) {
1227 1124 $classes .= ' has-row-actions column-primary';
1228 1125 }
1229 1126
1230 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
1231 1127 if ( in_array( $column_name, $hidden ) ) {
1232 1128 $classes .= ' hidden';
1233 1129 }
1234 1130
1235 - $params = array(
1236 - 'class' => $classes,
1237 - // Comments column uses HTML in the display name with screen reader text.
1238 - // Instead of using esc_attr(), we strip tags to get closer to a user-friendly string.
1239 - 'data-colname' => $column_display_name,
1240 - );
1131 + // Comments column uses HTML in the display name with screen reader text.
1132 + // Instead of using esc_attr(), we strip tags to get closer to a user-friendly string.
1133 + $data = 'data-colname="' . esc_attr( $column_display_name ) . '"';
1241 1134
1242 - if ( 'cb' === $column_name ) {
1135 + $attributes = 'class="' . esc_attr( $classes ) . '" ' . $data;
1136 +
1137 + if ( 'cb' == $column_name ) {
1243 1138 echo '<th scope="row" class="check-column"></th>';
1139 + } elseif ( method_exists( $this, '_column_' . $column_name ) ) {
1140 + echo call_user_func( // WPCS: XSS ok.
1141 + array( $this, '_column_' . $column_name ),
1142 + $item,
1143 + $classes,
1144 + $data,
1145 + $primary
1146 + );
1147 + } elseif ( method_exists( $this, 'column_' . $column_name ) ) {
1148 + echo "<td $attributes>"; // WPCS: XSS ok.
1149 + echo call_user_func( array( $this, 'column_' . $column_name ), $item ); // WPCS: XSS ok.
1150 + echo $this->handle_row_actions( $item, $column_name, $primary ); // WPCS: XSS ok.
1151 + echo '</td>';
1244 1152 } else {
1245 - echo '<td ';
1246 - FrmAppHelper::array_to_html_params( $params, true );
1247 - echo '>';
1248 -
1249 - if ( method_exists( $this, 'column_' . $column_name ) ) {
1250 - echo call_user_func( array( $this, 'column_' . $column_name ), $item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1251 - }
1252 -
1253 - echo $this->handle_row_actions( $item, $column_name, $primary ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1153 + echo "<td $attributes>"; // WPCS: XSS ok.
1154 + echo $this->handle_row_actions( $item, $column_name, $primary ); // WPCS: XSS ok.
1254 1155 echo '</td>';
1255 1156 }
1256 - }//end foreach
1157 + }
1257 1158 }
1258 1159
1259 1160 /**
1260 1161 * Generates and display row actions links for the list table.
@@ -1259,8 +1160,9 @@
1259 1160 /**
1260 1161 * Generates and display row actions links for the list table.
1261 1162 *
1262 1163 * @since 4.3.0
1164 + * @access protected
1263 1165 *
1264 1166 * @param object $item The item being acted upon.
1265 1167 * @param string $column_name Current column name.
1266 1168 * @param string $primary Primary column name.
@@ -1267,9 +1169,9 @@
1267 1169 *
1268 1170 * @return string The row actions output. In this case, an empty string.
1269 1171 */
1270 1172 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
1173 + return $column_name == $primary ? '<button type="button" class="toggle-row"><span class="screen-reader-text">' . esc_html__( 'Show more details', 'formidable' ) . '</span></button>' : '';
1272 1174 }
1273 1175
1274 1176 /**
1275 1177 * Handle an incoming ajax request (called from admin-ajax.php)
@@ -1274,14 +1176,14 @@
1274 1176 /**
1275 1177 * Handle an incoming ajax request (called from admin-ajax.php)
1276 1178 *
1277 1179 * @since 2.0.18
1180 + * @access public
1278 1181 */
1279 1182 public function ajax_response() {
1280 1183 $this->prepare_items();
1281 1184
1282 1185 ob_start();
1283 -
1284 1186 if ( ! empty( $_REQUEST['no_placeholder'] ) ) {
1285 1187 $this->display_rows();
1286 1188 } else {
1287 1189 $this->display_rows_or_placeholder();
@@ -1286,9 +1188,10 @@
1286 1188 } else {
1287 1189 $this->display_rows_or_placeholder();
1288 1190 }
1289 1191
1290 - $rows = ob_get_clean();
1192 + $rows = ob_get_clean();
1193 +
1291 1194 $response = array( 'rows' => $rows );
1292 1195
1293 1196 if ( isset( $this->_pagination_args['total_items'] ) ) {
1294 1197 $response['total_items_i18n'] = sprintf(
@@ -1296,9 +1199,8 @@
1296 1199 _n( '%s item', '%s items', $this->_pagination_args['total_items'], 'formidable' ),
1297 1200 number_format_i18n( $this->_pagination_args['total_items'] )
1298 1201 );
1299 1202 }
1300 -
1301 1203 if ( isset( $this->_pagination_args['total_pages'] ) ) {
1302 1204 $response['total_pages'] = $this->_pagination_args['total_pages'];
1303 1205 $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
1304 1206 }
@@ -1308,9 +1210,9 @@
1308 1210
1309 1211 /**
1310 1212 * Send required variables to JavaScript land
1311 1213 *
1312 - * @return void
1214 + * @access public
1313 1215 */
1314 1216 public function _js_vars() {
1315 1217 $args = array(
1316 1218 'class' => get_class( $this ),
@@ -1320,13 +1222,6 @@
1320 1222 ),
1321 1223 );
1322 1224
1323 1225 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 1226 }
1332 1227 }