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