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