Changeset 2617865
- Timestamp:
- 10/21/2021 02:54:56 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
visual-form-builder/trunk/inc/class-list-table.php
r1812215 r2617865 17 17 * @since 3.1.0 18 18 * @var array 19 * @access public20 19 */ 21 20 public $items; … … 26 25 * @since 3.1.0 27 26 * @var array 28 * @access protected29 27 */ 30 28 protected $_args; … … 42 40 * 43 41 * @since 3.1.0 44 * @var object 45 * @access protected 42 * @var WP_Screen 46 43 */ 47 44 protected $screen; … … 52 49 * @since 3.1.0 53 50 * @var array 54 * @access private55 51 */ 56 52 private $_actions; … … 61 57 * @since 3.1.0 62 58 * @var string 63 * @access private64 59 */ 65 60 private $_pagination; … … 70 65 * @since 4.1.0 71 66 * @var array 72 * @access protected73 67 */ 74 68 protected $modes = array(); 75 69 76 70 /** 77 * Stores the value returned by ->get_column_info() 78 * 71 * Stores the value returned by ->get_column_info(). 72 * 73 * @since 4.1.0 79 74 * @var array 80 75 */ … … 82 77 83 78 /** 84 * [protected description] 79 * {@internal Missing Summary} 80 * 85 81 * @var array 86 82 */ … … 88 84 89 85 /** 90 * [protected description] 86 * {@internal Missing Summary} 87 * 91 88 * @var array 92 89 */ 93 protected $compat_methods = array( 'set_pagination_args', 'get_views', 'get_bulk_actions', 'bulk_actions', 94 'row_actions', 'months_dropdown', 'view_switcher', 'comments_bubble', 'get_items_per_page', 'pagination', 95 'get_sortable_columns', 'get_column_info', 'get_table_classes', 'display_tablenav', 'extra_tablenav', 96 'single_row_columns' ); 90 protected $compat_methods = array( 91 'set_pagination_args', 92 'get_views', 93 'get_bulk_actions', 94 'bulk_actions', 95 'row_actions', 96 'months_dropdown', 97 'view_switcher', 98 'comments_bubble', 99 'get_items_per_page', 100 'pagination', 101 'get_sortable_columns', 102 'get_column_info', 103 'get_table_classes', 104 'display_tablenav', 105 'extra_tablenav', 106 'single_row_columns', 107 ); 97 108 98 109 /** … … 103 114 * 104 115 * @since 3.1.0 105 * @access public106 116 * 107 117 * @param array|string $args { … … 113 123 * @type string $singular Singular label for an object being listed, e.g. 'post'. 114 124 * Default empty 115 * @type bool $ajax Whether the list table supports A JAX. This includes loading125 * @type bool $ajax Whether the list table supports Ajax. This includes loading 116 126 * and sorting data, for example. If true, the class will call 117 * the {@see _js_vars()}method in the footer to provide variables118 * to any scripts handling A JAXevents. Default false.127 * the _js_vars() method in the footer to provide variables 128 * to any scripts handling Ajax events. Default false. 119 129 * @type string $screen String containing the hook name used to determine the current 120 130 * screen. If left null, the current screen will be automatically set. … … 123 133 */ 124 134 public function __construct( $args = array() ) { 125 $args = wp_parse_args( $args, array( 126 'plural' => '', 127 'singular' => '', 128 'ajax' => false, 129 'screen' => null, 130 ) ); 135 $args = wp_parse_args( 136 $args, 137 array( 138 'plural' => '', 139 'singular' => '', 140 'ajax' => false, 141 'screen' => null, 142 ) 143 ); 131 144 132 145 $this->screen = convert_to_screen( $args['screen'] ); … … 134 147 add_filter( "manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0 ); 135 148 136 if ( ! $args['plural'] )149 if ( ! $args['plural'] ) { 137 150 $args['plural'] = $this->screen->base; 138 139 $args['plural'] = sanitize_key( $args['plural'] ); 151 } 152 153 $args['plural'] = sanitize_key( $args['plural'] ); 140 154 $args['singular'] = sanitize_key( $args['singular'] ); 141 155 … … 149 163 if ( empty( $this->modes ) ) { 150 164 $this->modes = array( 151 'list' => __( ' List View' ),152 'excerpt' => __( 'Ex cerpt View' )165 'list' => __( 'Compact view' ), 166 'excerpt' => __( 'Extended view' ), 153 167 ); 154 168 } … … 156 170 157 171 /** 158 * Make private properties readable for backward scompatibility.172 * Make private properties readable for backward compatibility. 159 173 * 160 174 * @since 4.0.0 161 * @access public162 175 * 163 176 * @param string $name Property to get. … … 165 178 */ 166 179 public function __get( $name ) { 167 if ( in_array( $name, $this->compat_fields ) ) {180 if ( in_array( $name, $this->compat_fields, true ) ) { 168 181 return $this->$name; 169 182 } … … 171 184 172 185 /** 173 * Make private properties settable for backward scompatibility.186 * Make private properties settable for backward compatibility. 174 187 * 175 188 * @since 4.0.0 176 * @access public177 189 * 178 190 * @param string $name Property to check if set. … … 181 193 */ 182 194 public function __set( $name, $value ) { 183 if ( in_array( $name, $this->compat_fields ) ) {195 if ( in_array( $name, $this->compat_fields, true ) ) { 184 196 return $this->$name = $value; 185 197 } … … 187 199 188 200 /** 189 * Make private properties checkable for backward scompatibility.201 * Make private properties checkable for backward compatibility. 190 202 * 191 203 * @since 4.0.0 192 * @access public193 204 * 194 205 * @param string $name Property to check if set. … … 196 207 */ 197 208 public function __isset( $name ) { 198 if ( in_array( $name, $this->compat_fields ) ) {209 if ( in_array( $name, $this->compat_fields, true ) ) { 199 210 return isset( $this->$name ); 200 211 } … … 202 213 203 214 /** 204 * Make private properties un-settable for backward scompatibility.215 * Make private properties un-settable for backward compatibility. 205 216 * 206 217 * @since 4.0.0 207 * @access public208 218 * 209 219 * @param string $name Property to unset. 210 220 */ 211 221 public function __unset( $name ) { 212 if ( in_array( $name, $this->compat_fields ) ) {222 if ( in_array( $name, $this->compat_fields, true ) ) { 213 223 unset( $this->$name ); 214 224 } … … 216 226 217 227 /** 218 * Make private/protected methods readable for backward scompatibility.228 * Make private/protected methods readable for backward compatibility. 219 229 * 220 230 * @since 4.0.0 221 * @access public 222 * 223 * @param callable $name Method to call. 224 * @param array $arguments Arguments to pass when calling. 231 * 232 * @param string $name Method to call. 233 * @param array $arguments Arguments to pass when calling. 225 234 * @return mixed|bool Return value of the callback, false otherwise. 226 235 */ 227 236 public function __call( $name, $arguments ) { 228 if ( in_array( $name, $this->compat_methods ) ) {229 return call_user_func_array( array( $this, $name ),$arguments );237 if ( in_array( $name, $this->compat_methods, true ) ) { 238 return $this->$name( ...$arguments ); 230 239 } 231 240 return false; … … 236 245 * 237 246 * @since 3.1.0 238 * @access public239 247 * @abstract 240 248 */ 241 249 public function ajax_user_can() { 242 die( 'function WP_List_Table::ajax_user_can() must be over -ridden in a sub-class.' );250 die( 'function WP_List_Table::ajax_user_can() must be overridden in a subclass.' ); 243 251 } 244 252 245 253 /** 246 254 * Prepares the list of items for displaying. 255 * 247 256 * @uses WP_List_Table::set_pagination_args() 248 257 * 249 258 * @since 3.1.0 250 * @access public251 259 * @abstract 252 260 */ 253 261 public function prepare_items() { 254 die( 'function WP_List_Table::prepare_items() must be over -ridden in a sub-class.' );262 die( 'function WP_List_Table::prepare_items() must be overridden in a subclass.' ); 255 263 } 256 264 … … 258 266 * An internal method that sets all the necessary pagination arguments 259 267 * 260 * @param array $args An associative array with information about the pagination 261 * @access protected 268 * @since 3.1.0 262 269 * 263 270 * @param array|string $args Array or string of arguments with information about the pagination. 264 271 */ 265 272 protected function set_pagination_args( $args ) { 266 $args = wp_parse_args( $args, array( 267 'total_items' => 0, 268 'total_pages' => 0, 269 'per_page' => 0, 270 ) ); 271 272 if ( !$args['total_pages'] && $args['per_page'] > 0 ) 273 $args = wp_parse_args( 274 $args, 275 array( 276 'total_items' => 0, 277 'total_pages' => 0, 278 'per_page' => 0, 279 ) 280 ); 281 282 if ( ! $args['total_pages'] && $args['per_page'] > 0 ) { 273 283 $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] ); 284 } 274 285 275 286 // Redirect if page number is invalid and headers are not already sent. … … 286 297 * 287 298 * @since 3.1.0 288 * @access public289 299 * 290 300 * @param string $key Pagination argument to retrieve. Common values include 'total_items', … … 297 307 } 298 308 299 if ( isset( $this->_pagination_args[ $key] ) ) {300 return $this->_pagination_args[ $key];309 if ( isset( $this->_pagination_args[ $key ] ) ) { 310 return $this->_pagination_args[ $key ]; 301 311 } 302 312 } … … 306 316 * 307 317 * @since 3.1.0 308 * @access public309 318 * 310 319 * @return bool 311 320 */ 312 321 public function has_items() { 313 return ! empty( $this->items );322 return ! empty( $this->items ); 314 323 } 315 324 … … 318 327 * 319 328 * @since 3.1.0 320 * @access public321 329 */ 322 330 public function no_items() { … … 325 333 326 334 /** 327 * Display the search box. 328 * 329 * @since 3.1.0 330 * @access public 331 * 332 * @param string $text The search button text 333 * @param string $input_id The search input id 335 * Displays the search box. 336 * 337 * @since 3.1.0 338 * 339 * @param string $text The 'submit' button label. 340 * @param string $input_id ID attribute value for the search input field. 334 341 */ 335 342 public function search_box( $text, $input_id ) { 336 if ( empty( $_REQUEST['s'] ) && ! $this->has_items() )343 if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { 337 344 return; 345 } 338 346 339 347 $input_id = $input_id . '-search-input'; 340 348 341 if ( ! empty( $_REQUEST['orderby'] ) ) 349 if ( ! empty( $_REQUEST['orderby'] ) ) { 342 350 echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; 343 if ( ! empty( $_REQUEST['order'] ) ) 351 } 352 if ( ! empty( $_REQUEST['order'] ) ) { 344 353 echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; 345 if ( ! empty( $_REQUEST['post_mime_type'] ) ) 354 } 355 if ( ! empty( $_REQUEST['post_mime_type'] ) ) { 346 356 echo '<input type="hidden" name="post_mime_type" value="' . esc_attr( $_REQUEST['post_mime_type'] ) . '" />'; 347 if ( ! empty( $_REQUEST['detached'] ) ) 357 } 358 if ( ! empty( $_REQUEST['detached'] ) ) { 348 359 echo '<input type="hidden" name="detached" value="' . esc_attr( $_REQUEST['detached'] ) . '" />'; 349 ?> 360 } 361 ?> 350 362 <p class="search-box"> 351 363 <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php echo $text; ?>:</label> 352 364 <input type="search" id="<?php echo esc_attr( $input_id ); ?>" name="s" value="<?php _admin_search_query(); ?>" /> 353 <?php submit_button( $text, '', '', false, array( 'id' => 'search-submit' ) ); ?>365 <?php submit_button( $text, '', '', false, array( 'id' => 'search-submit' ) ); ?> 354 366 </p> 355 <?php 356 } 357 358 /** 359 * Get an associative array ( id => link ) with the list 360 * of views available on this table. 361 * 362 * @since 3.1.0 363 * @access protected 367 <?php 368 } 369 370 /** 371 * Gets the list of views available on this table. 372 * 373 * The format is an associative array: 374 * - `'id' => 'link'` 375 * 376 * @since 3.1.0 364 377 * 365 378 * @return array … … 370 383 371 384 /** 372 * Display the list of views available on this table. 373 * 374 * @since 3.1.0 375 * @access public 385 * Displays the list of views available on this table. 386 * 387 * @since 3.1.0 376 388 */ 377 389 public function views() { 378 390 $views = $this->get_views(); 379 391 /** 380 * Filter the list of available list table views.392 * Filters the list of available list table views. 381 393 * 382 394 * The dynamic portion of the hook name, `$this->screen->id`, refers 383 * to the ID of the current screen , usually a string.384 * 385 * @since 3. 5.0386 * 387 * @param array$views An array of available list table views.395 * to the ID of the current screen. 396 * 397 * @since 3.1.0 398 * 399 * @param string[] $views An array of available list table views. 388 400 */ 389 401 $views = apply_filters( "views_{$this->screen->id}", $views ); 390 402 391 if ( empty( $views ) ) 403 if ( empty( $views ) ) { 392 404 return; 405 } 393 406 394 407 $this->screen->render_screen_reader_content( 'heading_views' ); … … 399 412 } 400 413 echo implode( " |</li>\n", $views ) . "</li>\n"; 401 echo "</ul>"; 402 } 403 404 /** 405 * Get an associative array ( option_name => option_title ) with the list 406 * of bulk actions available on this table. 407 * 408 * @since 3.1.0 409 * @access protected 414 echo '</ul>'; 415 } 416 417 /** 418 * Retrieves the list of bulk actions available for this table. 419 * 420 * The format is an associative array where each element represents either a top level option value and label, or 421 * an array representing an optgroup and its options. 422 * 423 * For a standard option, the array element key is the field value and the array element value is the field label. 424 * 425 * For an optgroup, the array element key is the label and the array element value is an associative array of 426 * options as above. 427 * 428 * Example: 429 * 430 * [ 431 * 'edit' => 'Edit', 432 * 'delete' => 'Delete', 433 * 'Change State' => [ 434 * 'feature' => 'Featured', 435 * 'sale' => 'On Sale', 436 * ] 437 * ] 438 * 439 * @since 3.1.0 440 * @since 5.6.0 A bulk action can now contain an array of options in order to create an optgroup. 410 441 * 411 442 * @return array … … 416 447 417 448 /** 418 * Display the bulk actions dropdown. 419 * 420 * @since 3.1.0 421 * @access protected 449 * Displays the bulk actions dropdown. 450 * 451 * @since 3.1.0 422 452 * 423 453 * @param string $which The location of the bulk actions: 'top' or 'bottom'. … … 427 457 if ( is_null( $this->_actions ) ) { 428 458 $this->_actions = $this->get_bulk_actions(); 459 429 460 /** 430 * Filters the list table Bulk Actions drop-down.461 * Filters the items in the bulk actions menu of the list table. 431 462 * 432 463 * The dynamic portion of the hook name, `$this->screen->id`, refers 433 * to the ID of the current screen , usually a string.464 * to the ID of the current screen. 434 465 * 435 * This filter can currently only be used to remove bulk actions. 436 * 437 * @since 3.5.0 466 * @since 3.1.0 467 * @since 5.6.0 A bulk action can now contain an array of options in order to create an optgroup. 438 468 * 439 469 * @param array $actions An array of the available bulk actions. 440 470 */ 441 $this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions ); 471 $this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 472 442 473 $two = ''; 443 474 } else { … … 445 476 } 446 477 447 if ( empty( $this->_actions ) ) 478 if ( empty( $this->_actions ) ) { 448 479 return; 480 } 449 481 450 482 echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>'; 451 483 echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">\n"; 452 echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>\n"; 453 454 foreach ( $this->_actions as $name => $title ) { 455 $class = 'edit' === $name ? ' class="hide-if-no-js"' : ''; 456 457 echo "\t" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>\n"; 484 echo '<option value="-1">' . __( 'Bulk actions' ) . "</option>\n"; 485 486 foreach ( $this->_actions as $key => $value ) { 487 if ( is_array( $value ) ) { 488 echo "\t" . '<optgroup label="' . esc_attr( $key ) . '">' . "\n"; 489 490 foreach ( $value as $name => $title ) { 491 $class = ( 'edit' === $name ) ? ' class="hide-if-no-js"' : ''; 492 493 echo "\t\t" . '<option value="' . esc_attr( $name ) . '"' . $class . '>' . $title . "</option>\n"; 494 } 495 echo "\t" . "</optgroup>\n"; 496 } else { 497 $class = ( 'edit' === $key ) ? ' class="hide-if-no-js"' : ''; 498 499 echo "\t" . '<option value="' . esc_attr( $key ) . '"' . $class . '>' . $value . "</option>\n"; 500 } 458 501 } 459 502 … … 465 508 466 509 /** 467 * Get the current action selected from the bulk actions dropdown. 468 * 469 * @since 3.1.0 470 * @access public 471 * 472 * @return string|false The action name or False if no action was selected 510 * Gets the current action selected from the bulk actions dropdown. 511 * 512 * @since 3.1.0 513 * 514 * @return string|false The action name. False if no action was selected. 473 515 */ 474 516 public function current_action() { 475 if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) ) 517 if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) ) { 476 518 return false; 477 478 if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] ) 519 } 520 521 if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] ) { 479 522 return $_REQUEST['action']; 480 481 if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] ) 482 return $_REQUEST['action2']; 523 } 483 524 484 525 return false; … … 486 527 487 528 /** 488 * Generate row actions div 489 * 490 * @since 3.1.0 491 * @access protected 492 * 493 * @param array $actions The list of actions 494 * @param bool $always_visible Whether the actions should be always visible 495 * @return string 529 * Generates the required HTML for a list of row action links. 530 * 531 * @since 3.1.0 532 * 533 * @param string[] $actions An array of action links. 534 * @param bool $always_visible Whether the actions should be always visible. 535 * @return string The HTML for the row actions. 496 536 */ 497 537 protected function row_actions( $actions, $always_visible = false ) { 498 538 $action_count = count( $actions ); 539 540 if ( ! $action_count ) { 541 return ''; 542 } 543 544 $mode = get_user_setting( 'posts_list_mode', 'list' ); 545 546 if ( 'excerpt' === $mode ) { 547 $always_visible = true; 548 } 549 550 $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">'; 551 499 552 $i = 0; 500 553 501 if ( !$action_count )502 return '';503 504 $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';505 554 foreach ( $actions as $action => $link ) { 506 555 ++$i; 507 ( $i == $action_count ) ? $sep = '' : $sep = ' | '; 556 557 $sep = ( $i < $action_count ) ? ' | ' : ''; 558 508 559 $out .= "<span class='$action'>$link$sep</span>"; 509 560 } 561 510 562 $out .= '</div>'; 511 563 … … 516 568 517 569 /** 518 * Display a monthly dropdown for filtering items 519 * 520 * @since 3.1.0 521 * @access protected 522 * 523 * @global wpdb $wpdb 524 * @global WP_Locale $wp_locale 525 * 526 * @param string $post_type 570 * Displays a dropdown for filtering items in the list table by month. 571 * 572 * @since 3.1.0 573 * 574 * @global wpdb $wpdb WordPress database abstraction object. 575 * @global WP_Locale $wp_locale WordPress date and time locale object. 576 * 577 * @param string $post_type The post type. 527 578 */ 528 579 protected function months_dropdown( $post_type ) { … … 541 592 } 542 593 543 $extra_checks = "AND post_status != 'auto-draft'"; 544 if ( ! isset( $_GET['post_status'] ) || 'trash' !== $_GET['post_status'] ) { 545 $extra_checks .= " AND post_status != 'trash'"; 546 } elseif ( isset( $_GET['post_status'] ) ) { 547 $extra_checks = $wpdb->prepare( ' AND post_status = %s', $_GET['post_status'] ); 548 } 549 550 $months = $wpdb->get_results( $wpdb->prepare( " 551 SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month 552 FROM $wpdb->posts 553 WHERE post_type = %s 554 $extra_checks 555 ORDER BY post_date DESC 556 ", $post_type ) ); 594 /** 595 * Filters to short-circuit performing the months dropdown query. 596 * 597 * @since 5.7.0 598 * 599 * @param object[]|false $months 'Months' drop-down results. Default false. 600 * @param string $post_type The post type. 601 */ 602 $months = apply_filters( 'pre_months_dropdown_query', false, $post_type ); 603 604 if ( ! is_array( $months ) ) { 605 $extra_checks = "AND post_status != 'auto-draft'"; 606 if ( ! isset( $_GET['post_status'] ) || 'trash' !== $_GET['post_status'] ) { 607 $extra_checks .= " AND post_status != 'trash'"; 608 } elseif ( isset( $_GET['post_status'] ) ) { 609 $extra_checks = $wpdb->prepare( ' AND post_status = %s', $_GET['post_status'] ); 610 } 611 612 $months = $wpdb->get_results( 613 $wpdb->prepare( 614 " 615 SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month 616 FROM $wpdb->posts 617 WHERE post_type = %s 618 $extra_checks 619 ORDER BY post_date DESC 620 ", 621 $post_type 622 ) 623 ); 624 } 557 625 558 626 /** … … 561 629 * @since 3.7.0 562 630 * 563 * @param object $months The months drop-down query results.564 * @param string $post_type The post type.631 * @param object[] $months Array of the months drop-down query results. 632 * @param string $post_type The post type. 565 633 */ 566 634 $months = apply_filters( 'months_dropdown_results', $months, $post_type ); … … 568 636 $month_count = count( $months ); 569 637 570 if ( ! $month_count || ( 1 == $month_count && 0 == $months[0]->month ) )638 if ( ! $month_count || ( 1 == $month_count && 0 == $months[0]->month ) ) { 571 639 return; 640 } 572 641 573 642 $m = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0; 574 ?>575 <label for="filter-by-date" class="screen-reader-text"><?php _e( 'Filter by date' ); ?></label>643 ?> 644 <label for="filter-by-date" class="screen-reader-text"><?php echo get_post_type_object( $post_type )->labels->filter_by_date; ?></label> 576 645 <select name="m" id="filter-by-date"> 577 646 <option<?php selected( $m, 0 ); ?> value="0"><?php _e( 'All dates' ); ?></option> 578 <?php647 <?php 579 648 foreach ( $months as $arc_row ) { 580 if ( 0 == $arc_row->year ) 649 if ( 0 == $arc_row->year ) { 581 650 continue; 651 } 582 652 583 653 $month = zeroise( $arc_row->month, 2 ); 584 $year = $arc_row->year; 585 586 printf( "<option %s value='%s'>%s</option>\n", 654 $year = $arc_row->year; 655 656 printf( 657 "<option %s value='%s'>%s</option>\n", 587 658 selected( $m, $year . $month, false ), 588 659 esc_attr( $arc_row->year . $month ), 589 /* translators: 1: month name, 2: 4-digit year*/660 /* translators: 1: Month name, 2: 4-digit year. */ 590 661 sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year ) 591 662 ); 592 663 } 593 ?>664 ?> 594 665 </select> 595 <?php 596 } 597 598 /** 599 * Display a view switcher 600 * 601 * @since 3.1.0 602 * @access protected 666 <?php 667 } 668 669 /** 670 * Displays a view switcher. 671 * 672 * @since 3.1.0 603 673 * 604 674 * @param string $current_mode 605 675 */ 606 676 protected function view_switcher( $current_mode ) { 607 ?>677 ?> 608 678 <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" /> 609 679 <div class="view-switch"> 610 <?php 611 foreach ( $this->modes as $mode => $title ) { 612 $classes = array( 'view-' . $mode ); 613 if ( $current_mode === $mode ) 614 $classes[] = 'current'; 615 printf( 616 "<a href='%s' class='%s' id='view-switch-$mode'><span class='screen-reader-text'>%s</span></a>\n", 617 esc_url( add_query_arg( 'mode', $mode ) ), 618 implode( ' ', $classes ), 619 $title 620 ); 680 <?php 681 foreach ( $this->modes as $mode => $title ) { 682 $classes = array( 'view-' . $mode ); 683 $aria_current = ''; 684 685 if ( $current_mode === $mode ) { 686 $classes[] = 'current'; 687 $aria_current = ' aria-current="page"'; 621 688 } 689 690 printf( 691 "<a href='%s' class='%s' id='view-switch-$mode'$aria_current><span class='screen-reader-text'>%s</span></a>\n", 692 esc_url( remove_query_arg( 'attachment-filter', add_query_arg( 'mode', $mode ) ) ), 693 implode( ' ', $classes ), 694 $title 695 ); 696 } 622 697 ?> 623 698 </div> 624 <?php 625 } 626 627 /** 628 * Display a comment count bubble 629 * 630 * @since 3.1.0 631 * @access protected 699 <?php 700 } 701 702 /** 703 * Displays a comment count bubble. 704 * 705 * @since 3.1.0 632 706 * 633 707 * @param int $post_id The post ID. … … 638 712 639 713 $approved_comments_number = number_format_i18n( $approved_comments ); 640 $pending_comments_number = number_format_i18n( $pending_comments ); 641 642 $approved_only_phrase = sprintf( _n( '%s comment', '%s comments', $approved_comments ), $approved_comments_number ); 643 $approved_phrase = sprintf( _n( '%s approved comment', '%s approved comments', $approved_comments ), $approved_comments_number ); 644 $pending_phrase = sprintf( _n( '%s pending comment', '%s pending comments', $pending_comments ), $pending_comments_number ); 645 646 // No comments at all. 714 $pending_comments_number = number_format_i18n( $pending_comments ); 715 716 $approved_only_phrase = sprintf( 717 /* translators: %s: Number of comments. */ 718 _n( '%s comment', '%s comments', $approved_comments ), 719 $approved_comments_number 720 ); 721 722 $approved_phrase = sprintf( 723 /* translators: %s: Number of comments. */ 724 _n( '%s approved comment', '%s approved comments', $approved_comments ), 725 $approved_comments_number 726 ); 727 728 $pending_phrase = sprintf( 729 /* translators: %s: Number of comments. */ 730 _n( '%s pending comment', '%s pending comments', $pending_comments ), 731 $pending_comments_number 732 ); 733 647 734 if ( ! $approved_comments && ! $pending_comments ) { 648 printf( '<span aria-hidden="true">—</span><span class="screen-reader-text">%s</span>', 735 // No comments at all. 736 printf( 737 '<span aria-hidden="true">—</span><span class="screen-reader-text">%s</span>', 649 738 __( 'No comments' ) 650 739 ); 651 // Approved comments have different display depending on some conditions. 740 } elseif ( $approved_comments && 'trash' === get_post_status( $post_id ) ) { 741 // Don't link the comment bubble for a trashed post. 742 printf( 743 '<span class="post-com-count post-com-count-approved"><span class="comment-count-approved" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>', 744 $approved_comments_number, 745 $pending_comments ? $approved_phrase : $approved_only_phrase 746 ); 652 747 } elseif ( $approved_comments ) { 653 printf( '<a href="%s" class="post-com-count post-com-count-approved"><span class="comment-count-approved" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>', 654 esc_url( add_query_arg( array( 'p' => $post_id, 'comment_status' => 'approved' ), admin_url( 'edit-comments.php' ) ) ), 748 // Link the comment bubble to approved comments. 749 printf( 750 '<a href="%s" class="post-com-count post-com-count-approved"><span class="comment-count-approved" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>', 751 esc_url( 752 add_query_arg( 753 array( 754 'p' => $post_id, 755 'comment_status' => 'approved', 756 ), 757 admin_url( 'edit-comments.php' ) 758 ) 759 ), 655 760 $approved_comments_number, 656 761 $pending_comments ? $approved_phrase : $approved_only_phrase 657 762 ); 658 763 } else { 659 printf( '<span class="post-com-count post-com-count-no-comments"><span class="comment-count comment-count-no-comments" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>', 764 // Don't link the comment bubble when there are no approved comments. 765 printf( 766 '<span class="post-com-count post-com-count-no-comments"><span class="comment-count comment-count-no-comments" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>', 660 767 $approved_comments_number, 661 768 $pending_comments ? __( 'No approved comments' ) : __( 'No comments' ) … … 664 771 665 772 if ( $pending_comments ) { 666 printf( '<a href="%s" class="post-com-count post-com-count-pending"><span class="comment-count-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>', 667 esc_url( add_query_arg( array( 'p' => $post_id, 'comment_status' => 'moderated' ), admin_url( 'edit-comments.php' ) ) ), 773 printf( 774 '<a href="%s" class="post-com-count post-com-count-pending"><span class="comment-count-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>', 775 esc_url( 776 add_query_arg( 777 array( 778 'p' => $post_id, 779 'comment_status' => 'moderated', 780 ), 781 admin_url( 'edit-comments.php' ) 782 ) 783 ), 668 784 $pending_comments_number, 669 785 $pending_phrase 670 786 ); 671 787 } else { 672 printf( '<span class="post-com-count post-com-count-pending post-com-count-no-pending"><span class="comment-count comment-count-no-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>', 788 printf( 789 '<span class="post-com-count post-com-count-pending post-com-count-no-pending"><span class="comment-count comment-count-no-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>', 673 790 $pending_comments_number, 674 791 $approved_comments ? __( 'No pending comments' ) : __( 'No comments' ) … … 678 795 679 796 /** 680 * Get the current page number 681 * 682 * @since 3.1.0 683 * @access public 797 * Gets the current page number. 798 * 799 * @since 3.1.0 684 800 * 685 801 * @return int … … 688 804 $pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0; 689 805 690 if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] ) 806 if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] ) { 691 807 $pagenum = $this->_pagination_args['total_pages']; 808 } 692 809 693 810 return max( 1, $pagenum ); … … 695 812 696 813 /** 697 * Get number of items to display on a single page 698 * 699 * @since 3.1.0 700 * @access protected 814 * Gets the number of items to display on a single page. 815 * 816 * @since 3.1.0 701 817 * 702 818 * @param string $option … … 706 822 protected function get_items_per_page( $option, $default = 20 ) { 707 823 $per_page = (int) get_user_option( $option ); 708 if ( empty( $per_page ) || $per_page < 1 ) 824 if ( empty( $per_page ) || $per_page < 1 ) { 709 825 $per_page = $default; 826 } 710 827 711 828 /** 712 829 * Filters the number of items to be displayed on each page of the list table. 713 830 * 714 * The dynamic hook name, $option, refers to the `per_page` option depending 715 * on the type of list table in use. Possible values include: 'edit_comments_per_page', 716 * 'sites_network_per_page', 'site_themes_network_per_page', 'themes_network_per_page', 717 * 'users_network_per_page', 'edit_post_per_page', 'edit_page_per_page', 718 * 'edit_{$post_type}_per_page', etc. 831 * The dynamic hook name, `$option`, refers to the `per_page` option depending 832 * on the type of list table in use. Possible filter names include: 833 * 834 * - `edit_comments_per_page` 835 * - `sites_network_per_page` 836 * - `site_themes_network_per_page` 837 * - `themes_network_per_page'` 838 * - `users_network_per_page` 839 * - `edit_post_per_page` 840 * - `edit_page_per_page'` 841 * - `edit_{$post_type}_per_page` 842 * - `edit_post_tag_per_page` 843 * - `edit_category_per_page` 844 * - `edit_{$taxonomy}_per_page` 845 * - `site_users_network_per_page` 846 * - `users_per_page` 719 847 * 720 848 * @since 2.9.0 … … 726 854 727 855 /** 728 * Display the pagination. 729 * 730 * @since 3.1.0 731 * @access protected 856 * Displays the pagination. 857 * 858 * @since 3.1.0 732 859 * 733 860 * @param string $which … … 738 865 } 739 866 740 $total_items = $this->_pagination_args['total_items'];741 $total_pages = $this->_pagination_args['total_pages'];867 $total_items = $this->_pagination_args['total_items']; 868 $total_pages = $this->_pagination_args['total_pages']; 742 869 $infinite_scroll = false; 743 870 if ( isset( $this->_pagination_args['infinite_scroll'] ) ) { … … 749 876 } 750 877 751 $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>'; 752 753 $current = $this->get_pagenum(); 878 $output = '<span class="displaying-num">' . sprintf( 879 /* translators: %s: Number of items. */ 880 _n( '%s item', '%s items', $total_items ), 881 number_format_i18n( $total_items ) 882 ) . '</span>'; 883 884 $current = $this->get_pagenum(); 754 885 $removable_query_args = wp_removable_query_args(); 755 886 … … 763 894 $total_pages_after = '</span></span>'; 764 895 765 $disable_first = $disable_last = $disable_prev = $disable_next = false; 766 767 if ( $current == 1 ) { 896 $disable_first = false; 897 $disable_last = false; 898 $disable_prev = false; 899 $disable_next = false; 900 901 if ( 1 == $current ) { 768 902 $disable_first = true; 769 $disable_prev = true;770 }771 if ( $current == 2) {903 $disable_prev = true; 904 } 905 if ( 2 == $current ) { 772 906 $disable_first = true; 773 907 } 774 if ( $current == $total_pages) {908 if ( $total_pages == $current ) { 775 909 $disable_last = true; 776 910 $disable_next = true; 777 }778 if ( $ current == $total_pages - 1) {911 } 912 if ( $total_pages - 1 == $current ) { 779 913 $disable_last = true; 780 914 } 781 915 782 916 if ( $disable_first ) { 783 $page_links[] = '<span class="tablenav-pages-navspan " aria-hidden="true">«</span>';917 $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">«</span>'; 784 918 } else { 785 $page_links[] = sprintf( "<a class='first-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>", 919 $page_links[] = sprintf( 920 "<a class='first-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>", 786 921 esc_url( remove_query_arg( 'paged', $current_url ) ), 787 922 __( 'First page' ), … … 791 926 792 927 if ( $disable_prev ) { 793 $page_links[] = '<span class="tablenav-pages-navspan " aria-hidden="true">‹</span>';928 $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">‹</span>'; 794 929 } else { 795 $page_links[] = sprintf( "<a class='prev-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>", 796 esc_url( add_query_arg( 'paged', max( 1, $current-1 ), $current_url ) ), 930 $page_links[] = sprintf( 931 "<a class='prev-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>", 932 esc_url( add_query_arg( 'paged', max( 1, $current - 1 ), $current_url ) ), 797 933 __( 'Previous page' ), 798 934 '‹' … … 804 940 $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">'; 805 941 } else { 806 $html_current_page = sprintf( "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>", 942 $html_current_page = sprintf( 943 "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>", 807 944 '<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>', 808 945 $current, … … 811 948 } 812 949 $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) ); 813 $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after; 950 $page_links[] = $total_pages_before . sprintf( 951 /* translators: 1: Current page, 2: Total pages. */ 952 _x( '%1$s of %2$s', 'paging' ), 953 $html_current_page, 954 $html_total_pages 955 ) . $total_pages_after; 814 956 815 957 if ( $disable_next ) { 816 $page_links[] = '<span class="tablenav-pages-navspan " aria-hidden="true">›</span>';958 $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">›</span>'; 817 959 } else { 818 $page_links[] = sprintf( "<a class='next-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>", 819 esc_url( add_query_arg( 'paged', min( $total_pages, $current+1 ), $current_url ) ), 960 $page_links[] = sprintf( 961 "<a class='next-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>", 962 esc_url( add_query_arg( 'paged', min( $total_pages, $current + 1 ), $current_url ) ), 820 963 __( 'Next page' ), 821 964 '›' … … 824 967 825 968 if ( $disable_last ) { 826 $page_links[] = '<span class="tablenav-pages-navspan " aria-hidden="true">»</span>';969 $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">»</span>'; 827 970 } else { 828 $page_links[] = sprintf( "<a class='last-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>", 971 $page_links[] = sprintf( 972 "<a class='last-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>", 829 973 esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ), 830 974 __( 'Last page' ), … … 837 981 $pagination_links_class .= ' hide-if-js'; 838 982 } 839 $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';983 $output .= "\n<span class='$pagination_links_class'>" . implode( "\n", $page_links ) . '</span>'; 840 984 841 985 if ( $total_pages ) { … … 850 994 851 995 /** 852 * Get a list of columns. The format is: 853 * 'internal-name' => 'Title' 854 * 855 * @since 3.1.0 856 * @access public 996 * Gets a list of columns. 997 * 998 * The format is: 999 * - `'internal-name' => 'Title'` 1000 * 1001 * @since 3.1.0 857 1002 * @abstract 858 1003 * … … 860 1005 */ 861 1006 public function get_columns() { 862 die( 'function WP_List_Table::get_columns() must be over-ridden in a sub-class.' ); 863 } 864 865 /** 866 * Get a list of sortable columns. The format is: 867 * 'internal-name' => 'orderby' 868 * or 869 * 'internal-name' => array( 'orderby', true ) 870 * 871 * The second format will make the initial sorting order be descending 872 * 873 * @since 3.1.0 874 * @access protected 1007 die( 'function WP_List_Table::get_columns() must be overridden in a subclass.' ); 1008 } 1009 1010 /** 1011 * Gets a list of sortable columns. 1012 * 1013 * The format is: 1014 * - `'internal-name' => 'orderby'` 1015 * - `'internal-name' => array( 'orderby', 'asc' )` - The second element sets the initial sorting order. 1016 * - `'internal-name' => array( 'orderby', true )` - The second element makes the initial order descending. 1017 * 1018 * @since 3.1.0 875 1019 * 876 1020 * @return array … … 884 1028 * 885 1029 * @since 4.3.0 886 * @access protected887 1030 * 888 1031 * @return string Name of the default primary column, in this case, an empty string. … … 890 1033 protected function get_default_primary_column_name() { 891 1034 $columns = $this->get_columns(); 892 $column = '';1035 $column = ''; 893 1036 894 1037 if ( empty( $columns ) ) { … … 911 1054 912 1055 /** 913 * Public wrapper for Visual_Form_Builder_List_Table::get_default_primary_column_name().1056 * Public wrapper for WP_List_Table::get_default_primary_column_name(). 914 1057 * 915 1058 * @since 4.4.0 … … 925 1068 * 926 1069 * @since 4.3.0 927 * @access protected928 1070 * 929 1071 * @return string The name of the primary column. … … 933 1075 $default = $this->get_default_primary_column_name(); 934 1076 935 // If the primary column doesn't exist fall back to the936 // f irst non-checkbox column.1077 // If the primary column doesn't exist, 1078 // fall back to the first non-checkbox column. 937 1079 if ( ! isset( $columns[ $default ] ) ) { 938 $default = Visual_Form_Builder_List_Table::get_default_primary_column_name();1080 $default = self::get_default_primary_column_name(); 939 1081 } 940 1082 … … 947 1089 * @param string $context Screen ID for specific list table, e.g. 'plugins'. 948 1090 */ 949 $column = apply_filters( 'list_table_primary_column', $default, $this->screen->id );1091 $column = apply_filters( 'list_table_primary_column', $default, $this->screen->id ); 950 1092 951 1093 if ( empty( $column ) || ! isset( $columns[ $column ] ) ) { … … 957 1099 958 1100 /** 959 * Get a list of all, hidden and sortable columns, with filter applied 960 * 961 * @since 3.1.0 962 * @access protected 1101 * Gets a list of all, hidden, and sortable columns, with filter applied. 1102 * 1103 * @since 3.1.0 963 1104 * 964 1105 * @return array 965 1106 */ 966 1107 protected function get_column_info() { 967 // $_column_headers is already set / cached 1108 // $_column_headers is already set / cached. 968 1109 if ( isset( $this->_column_headers ) && is_array( $this->_column_headers ) ) { 969 // Back-compat for list tables that have been manually setting $_column_headers for horse reasons. 970 // In 4.3, we added a fourth argument for primary column. 1110 /* 1111 * Backward compatibility for `$_column_headers` format prior to WordPress 4.3. 1112 * 1113 * In WordPress 4.3 the primary column name was added as a fourth item in the 1114 * column headers property. This ensures the primary column name is included 1115 * in plugins setting the property directly in the three item format. 1116 */ 971 1117 $column_headers = array( array(), array(), array(), $this->get_primary_column_name() ); 972 1118 foreach ( $this->_column_headers as $key => $value ) { … … 978 1124 979 1125 $columns = get_column_headers( $this->screen ); 980 $hidden = get_hidden_columns( $this->screen );1126 $hidden = get_hidden_columns( $this->screen ); 981 1127 982 1128 $sortable_columns = $this->get_sortable_columns(); … … 985 1131 * 986 1132 * The dynamic portion of the hook name, `$this->screen->id`, refers 987 * to the ID of the current screen , usually a string.988 * 989 * @since 3. 5.01133 * to the ID of the current screen. 1134 * 1135 * @since 3.1.0 990 1136 * 991 1137 * @param array $sortable_columns An array of sortable columns. … … 995 1141 $sortable = array(); 996 1142 foreach ( $_sortable as $id => $data ) { 997 if ( empty( $data ) ) 1143 if ( empty( $data ) ) { 998 1144 continue; 1145 } 999 1146 1000 1147 $data = (array) $data; 1001 if ( ! isset( $data[1] ) )1148 if ( ! isset( $data[1] ) ) { 1002 1149 $data[1] = false; 1003 1004 $sortable[$id] = $data; 1005 } 1006 1007 $primary = $this->get_primary_column_name(); 1150 } 1151 1152 $sortable[ $id ] = $data; 1153 } 1154 1155 $primary = $this->get_primary_column_name(); 1008 1156 $this->_column_headers = array( $columns, $hidden, $sortable, $primary ); 1009 1157 … … 1012 1160 1013 1161 /** 1014 * Return number of visible columns 1015 * 1016 * @since 3.1.0 1017 * @access public 1162 * Returns the number of visible columns. 1163 * 1164 * @since 3.1.0 1018 1165 * 1019 1166 * @return int … … 1021 1168 public function get_column_count() { 1022 1169 list ( $columns, $hidden ) = $this->get_column_info(); 1023 $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );1170 $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) ); 1024 1171 return count( $columns ) - count( $hidden ); 1025 1172 } 1026 1173 1027 1174 /** 1028 * Print column headers, accounting for hidden and sortable columns. 1029 * 1030 * @since 3.1.0 1031 * @access public 1032 * 1033 * @staticvar int $cb_counter 1034 * 1035 * @param bool $with_id Whether to set the id attribute or not 1175 * Prints column headers, accounting for hidden and sortable columns. 1176 * 1177 * @since 3.1.0 1178 * 1179 * @param bool $with_id Whether to set the ID attribute or not 1036 1180 */ 1037 1181 public function print_column_headers( $with_id = true ) { … … 1055 1199 if ( ! empty( $columns['cb'] ) ) { 1056 1200 static $cb_counter = 1; 1057 $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>'1201 $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>' 1058 1202 . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />'; 1059 1203 $cb_counter++; … … 1063 1207 $class = array( 'manage-column', "column-$column_key" ); 1064 1208 1065 if ( in_array( $column_key, $hidden ) ) {1209 if ( in_array( $column_key, $hidden, true ) ) { 1066 1210 $class[] = 'hidden'; 1067 1211 } 1068 1212 1069 if ( 'cb' === $column_key ) 1213 if ( 'cb' === $column_key ) { 1070 1214 $class[] = 'check-column'; 1071 elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) )1215 } elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ), true ) ) { 1072 1216 $class[] = 'num'; 1217 } 1073 1218 1074 1219 if ( $column_key === $primary ) { … … 1076 1221 } 1077 1222 1078 if ( isset( $sortable[ $column_key] ) ) {1079 list( $orderby, $desc_first ) = $sortable[ $column_key];1223 if ( isset( $sortable[ $column_key ] ) ) { 1224 list( $orderby, $desc_first ) = $sortable[ $column_key ]; 1080 1225 1081 1226 if ( $current_orderby === $orderby ) { 1082 1227 $order = 'asc' === $current_order ? 'desc' : 'asc'; 1228 1083 1229 $class[] = 'sorted'; 1084 1230 $class[] = $current_order; 1085 1231 } else { 1086 $order = $desc_first ? 'desc' : 'asc'; 1232 $order = strtolower( $desc_first ); 1233 1234 if ( ! in_array( $order, array( 'desc', 'asc' ), true ) ) { 1235 $order = $desc_first ? 'desc' : 'asc'; 1236 } 1237 1087 1238 $class[] = 'sortable'; 1088 $class[] = $desc_first? 'asc' : 'desc';1239 $class[] = 'desc' === $order ? 'asc' : 'desc'; 1089 1240 } 1090 1241 1091 $column_display_name = '<a href="' . esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>'; 1242 $column_display_name = sprintf( 1243 '<a href="%s"><span>%s</span><span class="sorting-indicator"></span></a>', 1244 esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ), 1245 $column_display_name 1246 ); 1092 1247 } 1093 1248 1094 $tag = ( 'cb' === $column_key ) ? 'td' : 'th';1249 $tag = ( 'cb' === $column_key ) ? 'td' : 'th'; 1095 1250 $scope = ( 'th' === $tag ) ? 'scope="col"' : ''; 1096 $id = $with_id ? "id='$column_key'" : ''; 1097 1098 if ( !empty( $class ) ) 1099 $class = "class='" . join( ' ', $class ) . "'"; 1251 $id = $with_id ? "id='$column_key'" : ''; 1252 1253 if ( ! empty( $class ) ) { 1254 $class = "class='" . implode( ' ', $class ) . "'"; 1255 } 1100 1256 1101 1257 echo "<$tag $scope $id $class>$column_display_name</$tag>"; … … 1104 1260 1105 1261 /** 1106 * Display the table 1107 * 1108 * @since 3.1.0 1109 * @access public 1262 * Displays the table. 1263 * 1264 * @since 3.1.0 1110 1265 */ 1111 1266 public function display() { … … 1115 1270 1116 1271 $this->screen->render_screen_reader_content( 'heading_list' ); 1117 ?>1272 ?> 1118 1273 <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>"> 1119 1274 <thead> … … 1123 1278 </thead> 1124 1279 1125 <tbody id="the-list"<?php 1280 <tbody id="the-list" 1281 <?php 1126 1282 if ( $singular ) { 1127 1283 echo " data-wp-lists='list:$singular'"; 1128 } ?>> 1284 } 1285 ?> 1286 > 1129 1287 <?php $this->display_rows_or_placeholder(); ?> 1130 1288 </tbody> … … 1137 1295 1138 1296 </table> 1139 <?php1297 <?php 1140 1298 $this->display_tablenav( 'bottom' ); 1141 1299 } 1142 1300 1143 1301 /** 1144 * Get a list of CSS classes for the list table table tag. 1145 * 1146 * @since 3.1.0 1147 * @access protected 1148 * 1149 * @return array List of CSS classes for the table tag. 1302 * Gets a list of CSS classes for the WP_List_Table table tag. 1303 * 1304 * @since 3.1.0 1305 * 1306 * @return string[] Array of CSS classes for the table tag. 1150 1307 */ 1151 1308 protected function get_table_classes() { 1152 return array( 'widefat', 'fixed', 'striped', $this->_args['plural'] ); 1153 } 1154 1155 /** 1156 * Generate the table navigation above or below the table 1157 * 1158 * @since 3.1.0 1159 * @access protected 1309 $mode = get_user_setting( 'posts_list_mode', 'list' ); 1310 1311 $mode_class = esc_attr( 'table-view-' . $mode ); 1312 1313 return array( 'widefat', 'fixed', 'striped', $mode_class, $this->_args['plural'] ); 1314 } 1315 1316 /** 1317 * Generates the table navigation above or below the table 1318 * 1319 * @since 3.1.0 1160 1320 * @param string $which 1161 1321 */ … … 1167 1327 <div class="tablenav <?php echo esc_attr( $which ); ?>"> 1168 1328 1169 <?php if ( $this->has_items() ) : ?>1329 <?php if ( $this->has_items() ) : ?> 1170 1330 <div class="alignleft actions bulkactions"> 1171 1331 <?php $this->bulk_actions( $which ); ?> 1172 1332 </div> 1173 <?php endif; 1333 <?php 1334 endif; 1174 1335 $this->extra_tablenav( $which ); 1175 1336 $this->pagination( $which ); 1176 ?>1337 ?> 1177 1338 1178 1339 <br class="clear" /> 1179 1340 </div> 1180 <?php 1181 } 1182 1183 /** 1184 * Extra controls to be displayed between bulk actions and pagination 1185 * 1186 * @since 3.1.0 1187 * @access protected 1341 <?php 1342 } 1343 1344 /** 1345 * Extra controls to be displayed between bulk actions and pagination. 1346 * 1347 * @since 3.1.0 1188 1348 * 1189 1349 * @param string $which … … 1192 1352 1193 1353 /** 1194 * Generate the tbody element for the list table. 1195 * 1196 * @since 3.1.0 1197 * @access public 1354 * Generates the tbody element for the list table. 1355 * 1356 * @since 3.1.0 1198 1357 */ 1199 1358 public function display_rows_or_placeholder() { … … 1208 1367 1209 1368 /** 1210 * Generate the table rows 1211 * 1212 * @since 3.1.0 1213 * @access public 1369 * Generates the table rows. 1370 * 1371 * @since 3.1.0 1214 1372 */ 1215 1373 public function display_rows() { 1216 foreach ( $this->items as $item ) 1374 foreach ( $this->items as $item ) { 1217 1375 $this->single_row( $item ); 1218 }1219 1220 /** 1221 * Generates content for a single row of the table1222 * 1223 * @since 3.1.01224 * @ access public1225 * 1226 * @param object $item The current item1376 } 1377 } 1378 1379 /** 1380 * Generates content for a single row of the table. 1381 * 1382 * @since 3.1.0 1383 * 1384 * @param object|array $item The current item 1227 1385 */ 1228 1386 public function single_row( $item ) { … … 1233 1391 1234 1392 /** 1235 * 1236 * @param object $item 1393 * @param object|array $item 1237 1394 * @param string $column_name 1238 1395 */ … … 1240 1397 1241 1398 /** 1242 * 1243 * @param object $item 1399 * @param object|array $item 1244 1400 */ 1245 1401 protected function column_cb( $item ) {} 1246 1402 1247 1403 /** 1248 * Generates the columns for a single row of the table 1249 * 1250 * @since 3.1.0 1251 * @access protected 1252 * 1253 * @param object $item The current item 1404 * Generates the columns for a single row of the table. 1405 * 1406 * @since 3.1.0 1407 * 1408 * @param object|array $item The current item. 1254 1409 */ 1255 1410 protected function single_row_columns( $item ) { … … 1262 1417 } 1263 1418 1264 if ( in_array( $column_name, $hidden ) ) {1419 if ( in_array( $column_name, $hidden, true ) ) { 1265 1420 $classes .= ' hidden'; 1266 1421 } 1267 1422 1268 1423 // Comments column uses HTML in the display name with screen reader text. 1269 // Instead of using esc_attr(), we strip tags to get closer to a user-friendly string.1270 $data = 'data-colname="' . wp_strip_all_tags( $column_display_name) . '"';1424 // Strip tags to get closer to a user-friendly string. 1425 $data = 'data-colname="' . esc_attr( wp_strip_all_tags( $column_display_name ) ) . '"'; 1271 1426 1272 1427 $attributes = "class='$classes' $data"; … … 1288 1443 echo call_user_func( array( $this, 'column_' . $column_name ), $item ); 1289 1444 echo $this->handle_row_actions( $item, $column_name, $primary ); 1290 echo "</td>";1445 echo '</td>'; 1291 1446 } else { 1292 1447 echo "<td $attributes>"; 1293 1448 echo $this->column_default( $item, $column_name ); 1294 1449 echo $this->handle_row_actions( $item, $column_name, $primary ); 1295 echo "</td>";1450 echo '</td>'; 1296 1451 } 1297 1452 } … … 1302 1457 * 1303 1458 * @since 4.3.0 1304 * @access protected1305 * 1306 * @param object $item The item being acted upon.1307 * @param string $column_name Currentcolumn name.1308 * @ param string $primary Primary column name.1309 * @return string The row actions HTML, or an empty string if the current column isthe primary column.1459 * 1460 * @param object|array $item The item being acted upon. 1461 * @param string $column_name Current column name. 1462 * @param string $primary Primary column name. 1463 * @return string The row actions HTML, or an empty string 1464 * if the current column is not the primary column. 1310 1465 */ 1311 1466 protected function handle_row_actions( $item, $column_name, $primary ) { 1312 1467 return $column_name === $primary ? '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>' : ''; 1313 } 1314 1315 /** 1316 * Handle an incoming ajax request (called from admin-ajax.php) 1317 * 1318 * @since 3.1.0 1319 * @access public 1468 } 1469 1470 /** 1471 * Handles an incoming ajax request (called from admin-ajax.php) 1472 * 1473 * @since 3.1.0 1320 1474 */ 1321 1475 public function ajax_response() { … … 1335 1489 if ( isset( $this->_pagination_args['total_items'] ) ) { 1336 1490 $response['total_items_i18n'] = sprintf( 1491 /* translators: Number of items. */ 1337 1492 _n( '%s item', '%s items', $this->_pagination_args['total_items'] ), 1338 1493 number_format_i18n( $this->_pagination_args['total_items'] ) … … 1340 1495 } 1341 1496 if ( isset( $this->_pagination_args['total_pages'] ) ) { 1342 $response['total_pages'] = $this->_pagination_args['total_pages'];1497 $response['total_pages'] = $this->_pagination_args['total_pages']; 1343 1498 $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] ); 1344 1499 } … … 1348 1503 1349 1504 /** 1350 * Send required variables to JavaScript land1351 * 1352 * @ access public1505 * Sends required variables to JavaScript land. 1506 * 1507 * @since 3.1.0 1353 1508 */ 1354 1509 public function _js_vars() { … … 1358 1513 'id' => $this->screen->id, 1359 1514 'base' => $this->screen->base, 1360 ) 1515 ), 1361 1516 ); 1362 1517
Note: See TracChangeset
for help on using the changeset viewer.