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 +136 -242 6.28 → 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,13 +281,8 @@
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 286 if ( ! empty( $_REQUEST[ $param_name ] ) ) {
309 287 $value = sanitize_text_field( wp_unslash( $_REQUEST[ $param_name ] ) );
310 288 echo '<input type="hidden" name="' . esc_attr( $param_name ) . '" value="' . esc_attr( $value ) . '" />';
@@ -315,8 +293,9 @@
315 293 * Get an associative array ( id => link ) with the list
316 294 * of views available on this table.
317 295 *
318 296 * @since 2.0.18
297 + * @access protected
319 298 *
320 299 * @return array
321 300 */
322 301 protected function get_views() {
@@ -326,8 +305,9 @@
326 305 /**
327 306 * Display the list of views available on this table.
328 307 *
329 308 * @since 2.0.18
309 + * @access public
330 310 */
331 311 public function views() {
332 312 $views = $this->get_views();
333 313 /**
@@ -341,14 +321,13 @@
341 321 * @param array $views An array of available list table views.
342 322 */
343 323 $views = apply_filters( 'views_' . $this->screen->id, $views );
344 324
345 - if ( ! $views ) {
325 + if ( empty( $views ) ) {
346 326 return;
347 327 }
348 328
349 329 echo "<ul class='subsubsub'>\n";
350 -
351 330 foreach ( $views as $class => $view ) {
352 331 $views[ $class ] = "\t" . '<li class="' . esc_attr( $class ) . '">' . $view;
353 332 }
354 333 echo implode( " |</li>\n", $views ) . "</li>\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
@@ -359,8 +338,9 @@
359 338 * Get an associative array ( option_name => option_title ) with the list
360 339 * of bulk actions available on this table.
361 340 *
362 341 * @since 2.0.18
342 + * @access protected
363 343 *
364 344 * @return array
365 345 */
366 346 protected function get_bulk_actions() {
@@ -370,8 +350,9 @@
370 350 /**
371 351 * Display the bulk actions dropdown.
372 352 *
373 353 * @since 2.0.18
354 + * @access protected
374 355 *
375 356 * @param string $which The location of the bulk actions: 'top' or 'bottom'.
376 357 * This is designated as optional for backwards-compatibility.
377 358 */
@@ -403,17 +384,16 @@
403 384 if ( empty( $this->_actions ) ) {
404 385 return;
405 386 }
406 387
407 - 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>';
408 389 echo "<select name='action" . esc_attr( $two ) . "' id='bulk-action-selector-" . esc_attr( $which ) . "'>\n";
409 - 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";
410 391
411 392 foreach ( $this->_actions as $name => $title ) {
412 393 $params = array(
413 394 'value' => $name,
414 395 );
415 -
416 396 if ( 'edit' === $name ) {
417 397 $params['class'] = 'hide-if-no-js';
418 398 }
419 399
@@ -427,21 +407,9 @@
427 407 if ( isset( $this->_actions['bulk_delete'] ) ) {
428 408 $verify = $this->confirm_bulk_delete();
429 409
430 410 if ( $verify ) {
431 - $confirm_delete_attributes = array(
432 - 'id' => 'confirm-bulk-delete-' . $which,
433 - 'class' => 'frm-hidden',
434 - 'tabindex' => '-1',
435 - 'aria-hidden' => 'true',
436 - 'href' => 'confirm-bulk-delete',
437 - 'data-loaded-from' => $this->loaded_from(),
438 - 'data-frmverify' => $verify,
439 - 'data-frmverify-btn' => 'frm-button-red',
440 - );
441 -
442 - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
443 - 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>";
444 412 }
445 413 }
446 414
447 415 submit_button( __( 'Apply', 'formidable' ), 'action', '', false, array( 'id' => "doaction$two" ) );
@@ -458,26 +426,25 @@
458 426 /**
459 427 * Get the current action selected from the bulk actions dropdown.
460 428 *
461 429 * @since 2.0.18
430 + * @access public
462 431 *
463 - * @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
464 433 */
465 434 public function current_action() {
466 - if ( ! empty( $_REQUEST['filter_action'] ) ) {
435 + if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) ) {
467 436 return false;
468 437 }
469 438
470 439 $action = $this->get_bulk_action( 'action' );
440 + if ( $action === false ) {
441 + $action = $this->get_bulk_action( 'action2' );
442 + }
471 443
472 - return $action === false ? $this->get_bulk_action( 'action2' ) : $action;
444 + return $action;
473 445 }
474 446
475 - /**
476 - * @param string $action_name
477 - *
478 - * @return false|string
479 - */
480 447 private function get_bulk_action( $action_name ) {
481 448 $action = false;
482 449 $action_param = $this->get_param(
483 450 array(
@@ -484,12 +451,10 @@
484 451 'param' => $action_name,
485 452 'sanitize' => 'sanitize_text_field',
486 453 )
487 454 );
488 -
489 - // phpcs:ignore Universal.Operators.StrictComparisons
490 455 if ( $action_param && - 1 != $action_param ) {
491 - return $action_param;
456 + $action = $action_param;
492 457 }
493 458
494 459 return $action;
495 460 }
@@ -497,8 +462,9 @@
497 462 /**
498 463 * Generate row actions div
499 464 *
500 465 * @since 2.0.18
466 + * @access protected
501 467 *
502 468 * @param array $actions The list of actions.
503 469 * @param bool $always_visible Whether the actions should be always visible.
504 470 *
@@ -506,24 +472,25 @@
506 472 */
507 473 protected function row_actions( $actions, $always_visible = false ) {
508 474 $action_count = count( $actions );
509 475
476 + $i = 0;
477 +
510 478 if ( ! $action_count ) {
511 479 return '';
512 480 }
513 481
514 - $i = 0;
515 482 $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
516 -
517 483 foreach ( $actions as $action => $link ) {
518 - ++$i;
519 - $sep = $i === $action_count ? '' : ' | ';
484 + ++ $i;
485 + ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
520 486 $out .= "<span class='$action'>$link$sep</span>";
521 487 }
488 + $out .= '</div>';
522 489
523 - $out .= '</div>';
490 + $out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details', 'formidable' ) . '</span></button>';
524 491
525 - return $out . ( '<button type="button" class="toggle-row"><span class="screen-reader-text">' . esc_html__( 'Show more details', 'formidable' ) . '</span></button>' );
492 + return $out;
526 493 }
527 494
528 495 /**
529 496 * Display a view switcher
@@ -528,13 +495,13 @@
528 495 /**
529 496 * Display a view switcher
530 497 *
531 498 * @since 2.0.18
499 + * @access protected
532 500 *
533 501 * @param string $current_mode
534 502 */
535 503 protected function view_switcher( $current_mode ) {
536 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
537 504 ?>
538 505 <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>"/>
539 506 <div class="view-switch">
540 507 <?php
@@ -539,10 +506,8 @@
539 506 <div class="view-switch">
540 507 <?php
541 508 foreach ( $this->modes as $mode => $title ) {
542 509 $classes = array( 'view-' . $mode );
543 -
544 - // phpcs:ignore Universal.Operators.StrictComparisons
545 510 if ( $current_mode == $mode ) {
546 511 $classes[] = 'current';
547 512 }
548 513
@@ -555,9 +520,8 @@
555 520 }
556 521 ?>
557 522 </div>
558 523 <?php
559 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
560 524 }
561 525
562 526 /**
563 527 * Get the current page number
@@ -562,8 +526,9 @@
562 526 /**
563 527 * Get the current page number
564 528 *
565 529 * @since 2.0.18
530 + * @access public
566 531 *
567 532 * @return int
568 533 */
569 534 public function get_pagenum() {
@@ -579,8 +544,9 @@
579 544 /**
580 545 * Get number of items to display on a single page
581 546 *
582 547 * @since 2.0.18
548 + * @access protected
583 549 *
584 550 * @param string $option
585 551 * @param int $default
586 552 *
@@ -587,10 +553,9 @@
587 553 * @return int
588 554 */
589 555 protected function get_items_per_page( $option, $default = 20 ) {
590 556 $per_page = (int) get_user_option( $option );
591 -
592 - if ( ! $per_page || $per_page < 1 ) {
557 + if ( empty( $per_page ) || $per_page < 1 ) {
593 558 $per_page = $default;
594 559 }
595 560
596 561 /**
@@ -612,8 +577,9 @@
612 577 /**
613 578 * Display the pagination.
614 579 *
615 580 * @since 2.0.18
581 + * @access protected
616 582 *
617 583 * @param string $which
618 584 */
619 585 protected function pagination( $which ) {
@@ -623,9 +589,8 @@
623 589
624 590 $total_items = $this->_pagination_args['total_items'];
625 591 $total_pages = $this->_pagination_args['total_pages'];
626 592 $infinite_scroll = false;
627 -
628 593 if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
629 594 $infinite_scroll = $this->_pagination_args['infinite_scroll'];
630 595 }
631 596
@@ -631,14 +596,17 @@
631 596
632 597 /* translators: %s: Number of items */
633 598 $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items, 'formidable' ), number_format_i18n( $total_items ) ) . '</span>';
634 599
635 - $current = $this->get_pagenum();
636 - $page_links = array();
600 + $current = $this->get_pagenum();
601 +
602 + $page_links = array();
603 +
637 604 $total_pages_before = '<span class="paging-input">';
638 605 $total_pages_after = '</span>';
639 - $disable = $this->disabled_pages( $total_pages );
640 606
607 + $disable = $this->disabled_pages( $total_pages );
608 +
641 609 $page_links[] = $this->add_page_link(
642 610 array(
643 611 'page' => 'first',
644 612 'arrow' => '&laquo;',
@@ -655,20 +623,19 @@
655 623 'disabled' => $disable['prev'],
656 624 )
657 625 );
658 626
659 - if ( 'bottom' === $which ) {
627 + if ( 'bottom' == $which ) {
660 628 $html_current_page = $current;
661 - $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">';
662 630 } else {
663 631 $html_current_page = sprintf(
664 632 "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' />",
665 - '<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>',
666 634 $current,
667 635 strlen( $total_pages )
668 636 );
669 637 }
670 -
671 638 $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
672 639
673 640 /* translators: %1$s: Current page number, %2$s: Total pages */
674 641 $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging', 'formidable' ), $html_current_page, $html_total_pages ) . $total_pages_after;
@@ -691,15 +658,13 @@
691 658 )
692 659 );
693 660
694 661 $pagination_links_class = 'pagination-links';
695 -
696 - if ( $infinite_scroll ) {
662 + if ( ! empty( $infinite_scroll ) ) {
697 663 $pagination_links_class = ' hide-if-js';
698 664 }
665 + $output .= "\n" . '<span class="' . esc_attr( $pagination_links_class ) . '">' . join( "\n", $page_links ) . '</span>';
699 666
700 - $output .= "\n" . '<span class="' . esc_attr( $pagination_links_class ) . '">' . implode( "\n", $page_links ) . '</span>';
701 -
702 667 if ( $total_pages ) {
703 668 $page_class = $total_pages < 2 ? ' one-page' : '';
704 669 } else {
705 670 $page_class = ' no-pages';
@@ -708,13 +673,8 @@
708 673
709 674 echo $this->_pagination; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
710 675 }
711 676
712 - /**
713 - * @param int $total_pages
714 - *
715 - * @return array
716 - */
717 677 private function disabled_pages( $total_pages ) {
718 678 $current = $this->get_pagenum();
719 679 $disable = array(
720 680 'first' => false,
@@ -722,21 +682,19 @@
722 682 'prev' => false,
723 683 'next' => false,
724 684 );
725 685
726 - // phpcs:ignore Universal.Operators.StrictComparisons
727 686 if ( $current == 1 ) {
728 687 $disable['first'] = true;
729 688 $disable['prev'] = true;
730 - } elseif ( $current == 2 ) { // phpcs:ignore Universal.Operators.StrictComparisons
689 + } elseif ( $current == 2 ) {
731 690 $disable['first'] = true;
732 691 }
733 692
734 - // phpcs:ignore Universal.Operators.StrictComparisons
735 693 if ( $current == $total_pages ) {
736 694 $disable['last'] = true;
737 695 $disable['next'] = true;
738 - } elseif ( $current == $total_pages - 1 ) { // phpcs:ignore Universal.Operators.StrictComparisons
696 + } elseif ( $current == $total_pages - 1 ) {
739 697 $disable['last'] = true;
740 698 }
741 699
742 700 return $disable;
@@ -741,13 +699,8 @@
741 699
742 700 return $disable;
743 701 }
744 702
745 - /**
746 - * @param string $link
747 - *
748 - * @return string
749 - */
750 703 private function link_label( $link ) {
751 704 $labels = array(
752 705 'first' => __( 'First page', 'formidable' ),
753 706 'last' => __( 'Last page', 'formidable' ),
@@ -759,34 +712,26 @@
759 712 }
760 713
761 714 private function current_url() {
762 715 $current_url = set_url_scheme( 'http://' . FrmAppHelper::get_server_value( 'HTTP_HOST' ) . FrmAppHelper::get_server_value( 'REQUEST_URI' ) );
716 +
763 717 return remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
764 718 }
765 719
766 - /**
767 - * @param array $atts
768 - *
769 - * @return string
770 - */
771 720 private function add_page_link( $atts ) {
772 - 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;
773 728 }
774 729
775 - /**
776 - * @param string $label
777 - *
778 - * @return string
779 - */
780 730 private function add_disabled_link( $label ) {
781 731 return '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">' . $label . '</span>';
782 732 }
783 733
784 - /**
785 - * @param array $atts
786 - *
787 - * @return string
788 - */
789 734 private function add_active_link( $atts ) {
790 735 $url = esc_url( add_query_arg( 'paged', $atts['number'], $this->current_url() ) );
791 736 $label = $this->link_label( $atts['page'] );
792 737
@@ -807,8 +752,9 @@
807 752 *
808 753 * The second format will make the initial sorting order be descending
809 754 *
810 755 * @since 2.0.18
756 + * @access protected
811 757 *
812 758 * @return array
813 759 */
814 760 protected function get_sortable_columns() {
@@ -818,8 +764,9 @@
818 764 /**
819 765 * Gets the name of the default primary column.
820 766 *
821 767 * @since 4.3.0
768 + * @access protected
822 769 *
823 770 * @return string Name of the default primary column, in this case, an empty string.
824 771 */
825 772 protected function get_default_primary_column_name() {
@@ -826,9 +773,9 @@
826 773 $columns = $this->get_columns();
827 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.
777 + // so let's fall back to the first non-checkbox column.
831 778 foreach ( $columns as $col => $column_name ) {
832 779 if ( 'cb' === $col ) {
833 780 continue;
834 781 }
@@ -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
@@ -894,10 +842,11 @@
894 842
895 843 return $column_headers;
896 844 }
897 845
898 - $columns = get_column_headers( $this->screen );
899 - $hidden = get_hidden_columns( $this->screen );
846 + $columns = get_column_headers( $this->screen );
847 + $hidden = get_hidden_columns( $this->screen );
848 +
900 849 $sortable_columns = $this->get_sortable_columns();
901 850 /**
902 851 * Filter the list table sortable columns for a specific screen.
903 852 *
@@ -910,16 +859,14 @@
910 859 */
911 860 $_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );
912 861
913 862 $sortable = array();
914 -
915 863 foreach ( $_sortable as $id => $data ) {
916 - if ( ! $data ) {
864 + if ( empty( $data ) ) {
917 865 continue;
918 866 }
919 867
920 868 $data = (array) $data;
921 -
922 869 if ( ! isset( $data[1] ) ) {
923 870 $data[1] = false;
924 871 }
925 872
@@ -936,14 +883,15 @@
936 883 /**
937 884 * Return number of visible columns
938 885 *
939 886 * @since 2.0.18
887 + * @access public
940 888 *
941 889 * @return int
942 890 */
943 891 public function get_column_count() {
944 892 list ( $columns, $hidden ) = $this->get_column_info();
945 - $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
893 + $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
946 894
947 895 return count( $columns ) - count( $hidden );
948 896 }
949 897
@@ -950,45 +898,49 @@
950 898 /**
951 899 * Print column headers, accounting for hidden and sortable columns.
952 900 *
953 901 * @since 2.0.18
902 + * @access public
954 903 *
955 904 * @staticvar int $cb_counter
956 905 *
957 906 * @param bool $with_id Whether to set the id attribute or not.
958 - *
959 - * @return void
960 907 */
961 - 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 ) {
962 909 list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
963 910
964 - $current_url = set_url_scheme( 'http://' . FrmAppHelper::get_server_value( 'HTTP_HOST' ) . FrmAppHelper::get_server_value( 'REQUEST_URI' ) );
965 - $current_url = remove_query_arg( 'paged', $current_url );
966 - $current_orderby = isset( $_GET['orderby'] ) ? sanitize_text_field( wp_unslash( $_GET['orderby'] ) ) : '';
967 - $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 );
968 913
969 - 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 + }
970 919
920 + if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) {
921 + $current_order = 'desc';
922 + } else {
923 + $current_order = 'asc';
924 + }
925 +
971 926 if ( ! empty( $columns['cb'] ) ) {
972 927 static $cb_counter = 1;
973 - $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . esc_html__( 'Select All', 'formidable' ) . '</label>';
974 - $columns['cb'] .= '<input id="cb-select-all-' . esc_attr( $cb_counter ) . '" type="checkbox" />';
975 - ++$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 ++;
976 931 }
977 932
978 933 foreach ( $columns as $column_key => $column_display_name ) {
979 - $class = array( 'manage-column', "column-$column_key" );
980 - $aria_sort_attr = '';
981 - $order_text = '';
934 + $class = array( 'manage-column', "column-$column_key" );
982 935
983 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
984 936 if ( in_array( $column_key, $hidden ) ) {
985 937 $class[] = 'hidden';
986 938 }
987 939
988 - if ( 'cb' === $column_key ) {
940 + if ( 'cb' == $column_key ) {
989 941 $class[] = 'check-column';
990 - } elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ), true ) ) {
942 + } elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) ) {
991 943 $class[] = 'num';
992 944 }
993 945
994 946 if ( $column_key === $primary || $column_key === 'name' ) {
@@ -997,19 +949,10 @@
997 949
998 950 if ( isset( $sortable[ $column_key ] ) ) {
999 951 list( $orderby, $desc_first ) = $sortable[ $column_key ];
1000 952
1001 - // phpcs:ignore Universal.Operators.StrictComparisons
1002 953 if ( $current_orderby == $orderby ) {
1003 - // The sorted column. The `aria-sort` attribute must be set only on the sorted column.
1004 - if ( 'asc' === $current_order ) {
1005 - $order = 'desc';
1006 - $aria_sort_attr = ' aria-sort="ascending"';
1007 - } else {
1008 - $order = 'asc';
1009 - $aria_sort_attr = ' aria-sort="descending"';
1010 - }
1011 -
954 + $order = 'asc' == $current_order ? 'desc' : 'asc';
1012 955 $class[] = 'sorted';
1013 956 $class[] = $current_order;
1014 957 } else {
1015 958 $order = $desc_first ? 'desc' : 'asc';
@@ -1014,41 +957,19 @@
1014 957 } else {
1015 958 $order = $desc_first ? 'desc' : 'asc';
1016 959 $class[] = 'sortable';
1017 960 $class[] = $desc_first ? 'asc' : 'desc';
1018 -
1019 - /* translators: Hidden accessibility text. */
1020 - $asc_text = __( 'Sort ascending.', 'formidable' );
1021 - /* translators: Hidden accessibility text. */
1022 - $desc_text = __( 'Sort descending.', 'formidable' );
1023 - $order_text = 'asc' === $order ? $asc_text : $desc_text;
1024 - }//end if
1025 -
1026 - if ( '' !== $order_text ) {
1027 - $order_text = ' <span class="screen-reader-text">' . $order_text . '</span>';
1028 961 }
1029 962
1030 - $column_display_name = sprintf(
1031 - '<a href="%1$s">' .
1032 - '<span>%2$s</span>' .
1033 - '<span class="sorting-indicators">' .
1034 - '<span class="sorting-indicator asc" aria-hidden="true"></span>' .
1035 - '<span class="sorting-indicator desc" aria-hidden="true"></span>' .
1036 - '</span>' .
1037 - '%3$s' .
1038 - '</a>',
1039 - esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ),
1040 - $column_display_name,
1041 - $order_text
1042 - );
1043 - }//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 + }
1044 965
1045 - $tag = 'cb' === $column_key ? 'td' : 'th';
1046 - $scope = 'th' === $tag ? 'scope="col"' : '';
966 + $tag = ( 'cb' === $column_key ) ? 'td' : 'th';
967 + $scope = ( 'th' === $tag ) ? 'scope="col"' : '';
1047 968 $id = $with_id ? "id='" . esc_attr( $column_key ) . "'" : '';
1048 969
1049 - if ( $class ) {
1050 - $class = "class='" . esc_attr( implode( ' ', $class ) ) . "'";
970 + if ( ! empty( $class ) ) {
971 + $class = "class='" . esc_attr( join( ' ', $class ) ) . "'";
1051 972 }
1052 973
1053 974 if ( ! $this->has_min_items() && ! $with_id ) {
1054 975 // Hide the labels but show the border.
@@ -1053,9 +974,9 @@
1053 974 if ( ! $this->has_min_items() && ! $with_id ) {
1054 975 // Hide the labels but show the border.
1055 976 $column_display_name = '';
1056 977 }
1057 - 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
1058 979 }//end foreach
1059 980 }
1060 981
1061 982 /**
@@ -1061,27 +982,18 @@
1061 982 /**
1062 983 * Display the table
1063 984 *
1064 985 * @since 2.0.18
1065 - *
1066 - * @param array $args
1067 - *
1068 - * @return void
986 + * @access public
1069 987 */
1070 - public function display( $args = array() ) {
988 + public function display() {
1071 989 $singular = $this->_args['singular'];
1072 990 $tbody_params = array();
1073 -
1074 991 if ( $singular ) {
1075 992 $tbody_params['data-wp-lists'] = 'list:' . $singular;
1076 993 }
1077 994
1078 - if ( $this->should_display( $args, 'display-top-nav' ) ) {
1079 - $this->display_tablenav( 'top' );
1080 - }
1081 - $this->screen->render_screen_reader_content( 'heading_list' );
1082 -
1083 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
995 + $this->display_tablenav( 'top' );
1084 996 ?>
1085 997 <table class="wp-list-table <?php echo esc_attr( implode( ' ', $this->get_table_classes() ) ); ?>">
1086 998 <?php if ( $this->has_min_items( 1 ) ) { ?>
1087 999 <thead>
@@ -1094,9 +1006,9 @@
1094 1006 <tbody id="the-list"<?php FrmAppHelper::array_to_html_params( $tbody_params, true ); ?>>
1095 1007 <?php $this->display_rows_or_placeholder(); ?>
1096 1008 </tbody>
1097 1009
1098 - <?php if ( $this->has_min_items( 1 ) && $this->should_display( $args, 'display-bottom-headers' ) ) { ?>
1010 + <?php if ( $this->has_min_items( 1 ) ) { ?>
1099 1011 <tfoot>
1100 1012 <tr>
1101 1013 <?php $this->print_column_headers( false ); ?>
1102 1014 </tr>
@@ -1103,31 +1015,16 @@
1103 1015 </tfoot>
1104 1016 <?php } ?>
1105 1017 </table>
1106 1018 <?php
1107 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1108 -
1109 - if ( $this->should_display( $args, 'display-bottom-nav' ) ) {
1110 - $this->display_tablenav( 'bottom' );
1111 - }
1019 + $this->display_tablenav( 'bottom' );
1112 1020 }
1113 1021
1114 1022 /**
1115 - * Determines if a particular feature or element should be displayed.
1116 - *
1117 - * @param array $args An associative array of arguments.
1118 - * @param string $settings The specific setting key to check within the arguments array.
1119 - *
1120 - * @return bool Returns true if the setting is not set or if it is not false; otherwise, returns false.
1121 - */
1122 - protected function should_display( $args, $settings ) {
1123 - return ! isset( $args[ $settings ] ) || false !== $args[ $settings ];
1124 - }
1125 -
1126 - /**
1127 1023 * Get a list of CSS classes for the list table table tag.
1128 1024 *
1129 1025 * @since 2.0.18
1026 + * @access protected
1130 1027 *
1131 1028 * @return array List of CSS classes for the table tag.
1132 1029 */
1133 1030 protected function get_table_classes() {
@@ -1137,8 +1034,9 @@
1137 1034 /**
1138 1035 * Generate the table navigation above or below the table
1139 1036 *
1140 1037 * @since 2.0.18
1038 + * @access protected
1141 1039 *
1142 1040 * @param string $which
1143 1041 */
1144 1042 protected function display_tablenav( $which ) {
@@ -1143,18 +1041,16 @@
1143 1041 */
1144 1042 protected function display_tablenav( $which ) {
1145 1043 if ( 'top' === $which ) {
1146 1044 wp_nonce_field( 'bulk-' . $this->_args['plural'], '_wpnonce', false );
1147 -
1148 1045 if ( ! $this->has_min_items( 1 ) ) {
1149 1046 // Don't show bulk actions if no items.
1150 1047 return;
1151 1048 }
1152 1049 } elseif ( ! $this->has_min_items() ) {
1153 - // 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.
1154 1051 return;
1155 1052 }
1156 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1157 1053 ?>
1158 1054 <div class="tablenav <?php echo esc_attr( $which ); ?>">
1159 1055
1160 1056 <div class="alignleft actions bulkactions">
@@ -1167,9 +1063,8 @@
1167 1063
1168 1064 <br class="clear"/>
1169 1065 </div>
1170 1066 <?php
1171 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1172 1067 }
1173 1068
1174 1069 /**
1175 1070 * Use this to exclude the footer labels and bulk items.
@@ -1175,12 +1070,8 @@
1175 1070 * Use this to exclude the footer labels and bulk items.
1176 1071 * When close together, it feels like duplicates.
1177 1072 *
1178 1073 * @since 4.07
1179 - *
1180 - * @param int $limit
1181 - *
1182 - * @return bool
1183 1074 */
1184 1075 protected function has_min_items( $limit = 5 ) {
1185 1076 return $this->has_items() && ( $this->total_items === false || $this->total_items >= $limit );
1186 1077 }
@@ -1188,8 +1079,9 @@
1188 1079 /**
1189 1080 * Extra controls to be displayed between bulk actions and pagination
1190 1081 *
1191 1082 * @since 2.0.18
1083 + * @access protected
1192 1084 *
1193 1085 * @param string $which
1194 1086 */
1195 1087 protected function extra_tablenav( $which ) {
@@ -1198,8 +1090,9 @@
1198 1090 /**
1199 1091 * Generate the tbody element for the list table.
1200 1092 *
1201 1093 * @since 2.0.18
1094 + * @access public
1202 1095 */
1203 1096 public function display_rows_or_placeholder() {
1204 1097 if ( $this->has_items() ) {
1205 1098 $this->display_rows();
@@ -1213,8 +1106,9 @@
1213 1106 /**
1214 1107 * Generates content for a single row of the table
1215 1108 *
1216 1109 * @since 2.0.18
1110 + * @access public
1217 1111 *
1218 1112 * @param object $item The current item.
1219 1113 */
1220 1114 public function single_row( $item ) {
@@ -1226,8 +1120,9 @@
1226 1120 /**
1227 1121 * Generates the columns for a single row of the table
1228 1122 *
1229 1123 * @since 2.0.18
1124 + * @access protected
1230 1125 *
1231 1126 * @param object $item The current item.
1232 1127 */
1233 1128 protected function single_row_columns( $item ) {
@@ -1234,14 +1129,12 @@
1234 1129 list( $columns, $hidden,, $primary ) = $this->get_column_info();
1235 1130
1236 1131 foreach ( $columns as $column_name => $column_display_name ) {
1237 1132 $classes = "$column_name column-$column_name";
1238 -
1239 1133 if ( $primary === $column_name ) {
1240 1134 $classes .= ' has-row-actions column-primary';
1241 1135 }
1242 1136
1243 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
1244 1137 if ( in_array( $column_name, $hidden ) ) {
1245 1138 $classes .= ' hidden';
1246 1139 }
1247 1140
@@ -1272,8 +1165,9 @@
1272 1165 /**
1273 1166 * Generates and display row actions links for the list table.
1274 1167 *
1275 1168 * @since 4.3.0
1169 + * @access protected
1276 1170 *
1277 1171 * @param object $item The item being acted upon.
1278 1172 * @param string $column_name Current column name.
1279 1173 * @param string $primary Primary column name.
@@ -1280,9 +1174,9 @@
1280 1174 *
1281 1175 * @return string The row actions output. In this case, an empty string.
1282 1176 */
1283 1177 protected function handle_row_actions( $item, $column_name, $primary ) {
1284 - 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>' : '';
1285 1179 }
1286 1180
1287 1181 /**
1288 1182 * Handle an incoming ajax request (called from admin-ajax.php)
@@ -1287,14 +1181,14 @@
1287 1181 /**
1288 1182 * Handle an incoming ajax request (called from admin-ajax.php)
1289 1183 *
1290 1184 * @since 2.0.18
1185 + * @access public
1291 1186 */
1292 1187 public function ajax_response() {
1293 1188 $this->prepare_items();
1294 1189
1295 1190 ob_start();
1296 -
1297 1191 if ( ! empty( $_REQUEST['no_placeholder'] ) ) {
1298 1192 $this->display_rows();
1299 1193 } else {
1300 1194 $this->display_rows_or_placeholder();
@@ -1299,9 +1193,10 @@
1299 1193 } else {
1300 1194 $this->display_rows_or_placeholder();
1301 1195 }
1302 1196
1303 - $rows = ob_get_clean();
1197 + $rows = ob_get_clean();
1198 +
1304 1199 $response = array( 'rows' => $rows );
1305 1200
1306 1201 if ( isset( $this->_pagination_args['total_items'] ) ) {
1307 1202 $response['total_items_i18n'] = sprintf(
@@ -1309,9 +1204,8 @@
1309 1204 _n( '%s item', '%s items', $this->_pagination_args['total_items'], 'formidable' ),
1310 1205 number_format_i18n( $this->_pagination_args['total_items'] )
1311 1206 );
1312 1207 }
1313 -
1314 1208 if ( isset( $this->_pagination_args['total_pages'] ) ) {
1315 1209 $response['total_pages'] = $this->_pagination_args['total_pages'];
1316 1210 $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
1317 1211 }
@@ -1321,9 +1215,9 @@
1321 1215
1322 1216 /**
1323 1217 * Send required variables to JavaScript land
1324 1218 *
1325 - * @return void
1219 + * @access public
1326 1220 */
1327 1221 public function _js_vars() {
1328 1222 $args = array(
1329 1223 'class' => get_class( $this ),