Plugin Directory

Changeset 2617865


Ignore:
Timestamp:
10/21/2021 02:54:56 PM (4 years ago)
Author:
mmuro
Message:

Update class list wrapper

File:
1 edited

Legend:

Unmodified
Added
Removed
  • visual-form-builder/trunk/inc/class-list-table.php

    r1812215 r2617865  
    1717     * @since 3.1.0
    1818     * @var array
    19      * @access public
    2019     */
    2120    public $items;
     
    2625     * @since 3.1.0
    2726     * @var array
    28      * @access protected
    2927     */
    3028    protected $_args;
     
    4240     *
    4341     * @since 3.1.0
    44      * @var object
    45      * @access protected
     42     * @var WP_Screen
    4643     */
    4744    protected $screen;
     
    5249     * @since 3.1.0
    5350     * @var array
    54      * @access private
    5551     */
    5652    private $_actions;
     
    6157     * @since 3.1.0
    6258     * @var string
    63      * @access private
    6459     */
    6560    private $_pagination;
     
    7065     * @since 4.1.0
    7166     * @var array
    72      * @access protected
    7367     */
    7468    protected $modes = array();
    7569
    7670    /**
    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
    7974     * @var array
    8075     */
     
    8277
    8378    /**
    84      * [protected description]
     79     * {@internal Missing Summary}
     80     *
    8581     * @var array
    8682     */
     
    8884
    8985    /**
    90      * [protected description]
     86     * {@internal Missing Summary}
     87     *
    9188     * @var array
    9289     */
    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    );
    97108
    98109    /**
     
    103114     *
    104115     * @since 3.1.0
    105      * @access public
    106116     *
    107117     * @param array|string $args {
     
    113123     *     @type string $singular Singular label for an object being listed, e.g. 'post'.
    114124     *                            Default empty
    115      *     @type bool   $ajax     Whether the list table supports AJAX. This includes loading
     125     *     @type bool   $ajax     Whether the list table supports Ajax. This includes loading
    116126     *                            and sorting data, for example. If true, the class will call
    117      *                            the {@see _js_vars()} method in the footer to provide variables
    118      *                            to any scripts handling AJAX events. Default false.
     127     *                            the _js_vars() method in the footer to provide variables
     128     *                            to any scripts handling Ajax events. Default false.
    119129     *     @type string $screen   String containing the hook name used to determine the current
    120130     *                            screen. If left null, the current screen will be automatically set.
     
    123133     */
    124134    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        );
    131144
    132145        $this->screen = convert_to_screen( $args['screen'] );
     
    134147        add_filter( "manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0 );
    135148
    136         if ( !$args['plural'] )
     149        if ( ! $args['plural'] ) {
    137150            $args['plural'] = $this->screen->base;
    138 
    139         $args['plural'] = sanitize_key( $args['plural'] );
     151        }
     152
     153        $args['plural']   = sanitize_key( $args['plural'] );
    140154        $args['singular'] = sanitize_key( $args['singular'] );
    141155
     
    149163        if ( empty( $this->modes ) ) {
    150164            $this->modes = array(
    151                 'list'    => __( 'List View' ),
    152                 'excerpt' => __( 'Excerpt View' )
     165                'list'    => __( 'Compact view' ),
     166                'excerpt' => __( 'Extended view' ),
    153167            );
    154168        }
     
    156170
    157171    /**
    158      * Make private properties readable for backwards compatibility.
     172     * Make private properties readable for backward compatibility.
    159173     *
    160174     * @since 4.0.0
    161      * @access public
    162175     *
    163176     * @param string $name Property to get.
     
    165178     */
    166179    public function __get( $name ) {
    167         if ( in_array( $name, $this->compat_fields ) ) {
     180        if ( in_array( $name, $this->compat_fields, true ) ) {
    168181            return $this->$name;
    169182        }
     
    171184
    172185    /**
    173      * Make private properties settable for backwards compatibility.
     186     * Make private properties settable for backward compatibility.
    174187     *
    175188     * @since 4.0.0
    176      * @access public
    177189     *
    178190     * @param string $name  Property to check if set.
     
    181193     */
    182194    public function __set( $name, $value ) {
    183         if ( in_array( $name, $this->compat_fields ) ) {
     195        if ( in_array( $name, $this->compat_fields, true ) ) {
    184196            return $this->$name = $value;
    185197        }
     
    187199
    188200    /**
    189      * Make private properties checkable for backwards compatibility.
     201     * Make private properties checkable for backward compatibility.
    190202     *
    191203     * @since 4.0.0
    192      * @access public
    193204     *
    194205     * @param string $name Property to check if set.
     
    196207     */
    197208    public function __isset( $name ) {
    198         if ( in_array( $name, $this->compat_fields ) ) {
     209        if ( in_array( $name, $this->compat_fields, true ) ) {
    199210            return isset( $this->$name );
    200211        }
     
    202213
    203214    /**
    204      * Make private properties un-settable for backwards compatibility.
     215     * Make private properties un-settable for backward compatibility.
    205216     *
    206217     * @since 4.0.0
    207      * @access public
    208218     *
    209219     * @param string $name Property to unset.
    210220     */
    211221    public function __unset( $name ) {
    212         if ( in_array( $name, $this->compat_fields ) ) {
     222        if ( in_array( $name, $this->compat_fields, true ) ) {
    213223            unset( $this->$name );
    214224        }
     
    216226
    217227    /**
    218      * Make private/protected methods readable for backwards compatibility.
     228     * Make private/protected methods readable for backward compatibility.
    219229     *
    220230     * @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.
    225234     * @return mixed|bool Return value of the callback, false otherwise.
    226235     */
    227236    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 );
    230239        }
    231240        return false;
     
    236245     *
    237246     * @since 3.1.0
    238      * @access public
    239247     * @abstract
    240248     */
    241249    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.' );
    243251    }
    244252
    245253    /**
    246254     * Prepares the list of items for displaying.
     255     *
    247256     * @uses WP_List_Table::set_pagination_args()
    248257     *
    249258     * @since 3.1.0
    250      * @access public
    251259     * @abstract
    252260     */
    253261    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.' );
    255263    }
    256264
     
    258266     * An internal method that sets all the necessary pagination arguments
    259267     *
    260      * @param array $args An associative array with information about the pagination
    261      * @access protected
     268     * @since 3.1.0
    262269     *
    263270     * @param array|string $args Array or string of arguments with information about the pagination.
    264271     */
    265272    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 ) {
    273283            $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] );
     284        }
    274285
    275286        // Redirect if page number is invalid and headers are not already sent.
     
    286297     *
    287298     * @since 3.1.0
    288      * @access public
    289299     *
    290300     * @param string $key Pagination argument to retrieve. Common values include 'total_items',
     
    297307        }
    298308
    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 ];
    301311        }
    302312    }
     
    306316     *
    307317     * @since 3.1.0
    308      * @access public
    309318     *
    310319     * @return bool
    311320     */
    312321    public function has_items() {
    313         return !empty( $this->items );
     322        return ! empty( $this->items );
    314323    }
    315324
     
    318327     *
    319328     * @since 3.1.0
    320      * @access public
    321329     */
    322330    public function no_items() {
     
    325333
    326334    /**
    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.
    334341     */
    335342    public function search_box( $text, $input_id ) {
    336         if ( empty( $_REQUEST['s'] ) && !$this->has_items() )
     343        if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) {
    337344            return;
     345        }
    338346
    339347        $input_id = $input_id . '-search-input';
    340348
    341         if ( ! empty( $_REQUEST['orderby'] ) )
     349        if ( ! empty( $_REQUEST['orderby'] ) ) {
    342350            echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
    343         if ( ! empty( $_REQUEST['order'] ) )
     351        }
     352        if ( ! empty( $_REQUEST['order'] ) ) {
    344353            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'] ) ) {
    346356            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'] ) ) {
    348359            echo '<input type="hidden" name="detached" value="' . esc_attr( $_REQUEST['detached'] ) . '" />';
    349 ?>
     360        }
     361        ?>
    350362<p class="search-box">
    351363    <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php echo $text; ?>:</label>
    352364    <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' ) ); ?>
    354366</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
    364377     *
    365378     * @return array
     
    370383
    371384    /**
    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
    376388     */
    377389    public function views() {
    378390        $views = $this->get_views();
    379391        /**
    380          * Filter the list of available list table views.
     392         * Filters the list of available list table views.
    381393         *
    382394         * 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.0
    386          *
    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.
    388400         */
    389401        $views = apply_filters( "views_{$this->screen->id}", $views );
    390402
    391         if ( empty( $views ) )
     403        if ( empty( $views ) ) {
    392404            return;
     405        }
    393406
    394407        $this->screen->render_screen_reader_content( 'heading_views' );
     
    399412        }
    400413        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.
    410441     *
    411442     * @return array
     
    416447
    417448    /**
    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
    422452     *
    423453     * @param string $which The location of the bulk actions: 'top' or 'bottom'.
     
    427457        if ( is_null( $this->_actions ) ) {
    428458            $this->_actions = $this->get_bulk_actions();
     459
    429460            /**
    430              * Filters the list table Bulk Actions drop-down.
     461             * Filters the items in the bulk actions menu of the list table.
    431462             *
    432463             * 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.
    434465             *
    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.
    438468             *
    439469             * @param array $actions An array of the available bulk actions.
    440470             */
    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
    442473            $two = '';
    443474        } else {
     
    445476        }
    446477
    447         if ( empty( $this->_actions ) )
     478        if ( empty( $this->_actions ) ) {
    448479            return;
     480        }
    449481
    450482        echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
    451483        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            }
    458501        }
    459502
     
    465508
    466509    /**
    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.
    473515     */
    474516    public function current_action() {
    475         if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) )
     517        if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) ) {
    476518            return false;
    477 
    478         if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] )
     519        }
     520
     521        if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] ) {
    479522            return $_REQUEST['action'];
    480 
    481         if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] )
    482             return $_REQUEST['action2'];
     523        }
    483524
    484525        return false;
     
    486527
    487528    /**
    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.
    496536     */
    497537    protected function row_actions( $actions, $always_visible = false ) {
    498538        $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
    499552        $i = 0;
    500553
    501         if ( !$action_count )
    502             return '';
    503 
    504         $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
    505554        foreach ( $actions as $action => $link ) {
    506555            ++$i;
    507             ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
     556
     557            $sep = ( $i < $action_count ) ? ' | ' : '';
     558
    508559            $out .= "<span class='$action'>$link$sep</span>";
    509560        }
     561
    510562        $out .= '</div>';
    511563
     
    516568
    517569    /**
    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.
    527578     */
    528579    protected function months_dropdown( $post_type ) {
     
    541592        }
    542593
    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        }
    557625
    558626        /**
     
    561629         * @since 3.7.0
    562630         *
    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.
    565633         */
    566634        $months = apply_filters( 'months_dropdown_results', $months, $post_type );
     
    568636        $month_count = count( $months );
    569637
    570         if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
     638        if ( ! $month_count || ( 1 == $month_count && 0 == $months[0]->month ) ) {
    571639            return;
     640        }
    572641
    573642        $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>
    576645        <select name="m" id="filter-by-date">
    577646            <option<?php selected( $m, 0 ); ?> value="0"><?php _e( 'All dates' ); ?></option>
    578 <?php
     647        <?php
    579648        foreach ( $months as $arc_row ) {
    580             if ( 0 == $arc_row->year )
     649            if ( 0 == $arc_row->year ) {
    581650                continue;
     651            }
    582652
    583653            $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",
    587658                selected( $m, $year . $month, false ),
    588659                esc_attr( $arc_row->year . $month ),
    589                 /* translators: 1: month name, 2: 4-digit year */
     660                /* translators: 1: Month name, 2: 4-digit year. */
    590661                sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year )
    591662            );
    592663        }
    593 ?>
     664        ?>
    594665        </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
    603673     *
    604674     * @param string $current_mode
    605675     */
    606676    protected function view_switcher( $current_mode ) {
    607 ?>
     677        ?>
    608678        <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" />
    609679        <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"';
    621688            }
     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        }
    622697        ?>
    623698        </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
    632706     *
    633707     * @param int $post_id          The post ID.
     
    638712
    639713        $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
    647734        if ( ! $approved_comments && ! $pending_comments ) {
    648             printf( '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">%s</span>',
     735            // No comments at all.
     736            printf(
     737                '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">%s</span>',
    649738                __( 'No comments' )
    650739            );
    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            );
    652747        } 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                ),
    655760                $approved_comments_number,
    656761                $pending_comments ? $approved_phrase : $approved_only_phrase
    657762            );
    658763        } 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>',
    660767                $approved_comments_number,
    661768                $pending_comments ? __( 'No approved comments' ) : __( 'No comments' )
     
    664771
    665772        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                ),
    668784                $pending_comments_number,
    669785                $pending_phrase
    670786            );
    671787        } 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>',
    673790                $pending_comments_number,
    674791                $approved_comments ? __( 'No pending comments' ) : __( 'No comments' )
     
    678795
    679796    /**
    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
    684800     *
    685801     * @return int
     
    688804        $pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
    689805
    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'] ) {
    691807            $pagenum = $this->_pagination_args['total_pages'];
     808        }
    692809
    693810        return max( 1, $pagenum );
     
    695812
    696813    /**
    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
    701817     *
    702818     * @param string $option
     
    706822    protected function get_items_per_page( $option, $default = 20 ) {
    707823        $per_page = (int) get_user_option( $option );
    708         if ( empty( $per_page ) || $per_page < 1 )
     824        if ( empty( $per_page ) || $per_page < 1 ) {
    709825            $per_page = $default;
     826        }
    710827
    711828        /**
    712829         * Filters the number of items to be displayed on each page of the list table.
    713830         *
    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`
    719847         *
    720848         * @since 2.9.0
     
    726854
    727855    /**
    728      * Display the pagination.
    729      *
    730      * @since 3.1.0
    731      * @access protected
     856     * Displays the pagination.
     857     *
     858     * @since 3.1.0
    732859     *
    733860     * @param string $which
     
    738865        }
    739866
    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'];
    742869        $infinite_scroll = false;
    743870        if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
     
    749876        }
    750877
    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();
    754885        $removable_query_args = wp_removable_query_args();
    755886
     
    763894        $total_pages_after  = '</span></span>';
    764895
    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 ) {
    768902            $disable_first = true;
    769             $disable_prev = true;
    770         }
    771         if ( $current == 2 ) {
     903            $disable_prev  = true;
     904        }
     905        if ( 2 == $current ) {
    772906            $disable_first = true;
    773907        }
    774         if ( $current == $total_pages ) {
     908        if ( $total_pages == $current ) {
    775909            $disable_last = true;
    776910            $disable_next = true;
    777         }
    778         if ( $current == $total_pages - 1 ) {
     911        }
     912        if ( $total_pages - 1 == $current ) {
    779913            $disable_last = true;
    780914        }
    781915
    782916        if ( $disable_first ) {
    783             $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&laquo;</span>';
     917            $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&laquo;</span>';
    784918        } 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>",
    786921                esc_url( remove_query_arg( 'paged', $current_url ) ),
    787922                __( 'First page' ),
     
    791926
    792927        if ( $disable_prev ) {
    793             $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&lsaquo;</span>';
     928            $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&lsaquo;</span>';
    794929        } 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 ) ),
    797933                __( 'Previous page' ),
    798934                '&lsaquo;'
     
    804940            $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
    805941        } 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'>",
    807944                '<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
    808945                $current,
     
    811948        }
    812949        $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;
    814956
    815957        if ( $disable_next ) {
    816             $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&rsaquo;</span>';
     958            $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&rsaquo;</span>';
    817959        } 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 ) ),
    820963                __( 'Next page' ),
    821964                '&rsaquo;'
     
    824967
    825968        if ( $disable_last ) {
    826             $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&raquo;</span>';
     969            $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&raquo;</span>';
    827970        } 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>",
    829973                esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
    830974                __( 'Last page' ),
     
    837981            $pagination_links_class .= ' hide-if-js';
    838982        }
    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>';
    840984
    841985        if ( $total_pages ) {
     
    850994
    851995    /**
    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
    8571002     * @abstract
    8581003     *
     
    8601005     */
    8611006    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
    8751019     *
    8761020     * @return array
     
    8841028     *
    8851029     * @since 4.3.0
    886      * @access protected
    8871030     *
    8881031     * @return string Name of the default primary column, in this case, an empty string.
     
    8901033    protected function get_default_primary_column_name() {
    8911034        $columns = $this->get_columns();
    892         $column = '';
     1035        $column  = '';
    8931036
    8941037        if ( empty( $columns ) ) {
     
    9111054
    9121055    /**
    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().
    9141057     *
    9151058     * @since 4.4.0
     
    9251068     *
    9261069     * @since 4.3.0
    927      * @access protected
    9281070     *
    9291071     * @return string The name of the primary column.
     
    9331075        $default = $this->get_default_primary_column_name();
    9341076
    935         // If the primary column doesn't exist fall back to the
    936         // first non-checkbox column.
     1077        // If the primary column doesn't exist,
     1078        // fall back to the first non-checkbox column.
    9371079        if ( ! isset( $columns[ $default ] ) ) {
    938             $default = Visual_Form_Builder_List_Table::get_default_primary_column_name();
     1080            $default = self::get_default_primary_column_name();
    9391081        }
    9401082
     
    9471089         * @param string $context Screen ID for specific list table, e.g. 'plugins'.
    9481090         */
    949         $column  = apply_filters( 'list_table_primary_column', $default, $this->screen->id );
     1091        $column = apply_filters( 'list_table_primary_column', $default, $this->screen->id );
    9501092
    9511093        if ( empty( $column ) || ! isset( $columns[ $column ] ) ) {
     
    9571099
    9581100    /**
    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
    9631104     *
    9641105     * @return array
    9651106     */
    9661107    protected function get_column_info() {
    967         // $_column_headers is already set / cached
     1108        // $_column_headers is already set / cached.
    9681109        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             */
    9711117            $column_headers = array( array(), array(), array(), $this->get_primary_column_name() );
    9721118            foreach ( $this->_column_headers as $key => $value ) {
     
    9781124
    9791125        $columns = get_column_headers( $this->screen );
    980         $hidden = get_hidden_columns( $this->screen );
     1126        $hidden  = get_hidden_columns( $this->screen );
    9811127
    9821128        $sortable_columns = $this->get_sortable_columns();
     
    9851131         *
    9861132         * 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.0
     1133         * to the ID of the current screen.
     1134         *
     1135         * @since 3.1.0
    9901136         *
    9911137         * @param array $sortable_columns An array of sortable columns.
     
    9951141        $sortable = array();
    9961142        foreach ( $_sortable as $id => $data ) {
    997             if ( empty( $data ) )
     1143            if ( empty( $data ) ) {
    9981144                continue;
     1145            }
    9991146
    10001147            $data = (array) $data;
    1001             if ( !isset( $data[1] ) )
     1148            if ( ! isset( $data[1] ) ) {
    10021149                $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();
    10081156        $this->_column_headers = array( $columns, $hidden, $sortable, $primary );
    10091157
     
    10121160
    10131161    /**
    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
    10181165     *
    10191166     * @return int
     
    10211168    public function get_column_count() {
    10221169        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 ) );
    10241171        return count( $columns ) - count( $hidden );
    10251172    }
    10261173
    10271174    /**
    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
    10361180     */
    10371181    public function print_column_headers( $with_id = true ) {
     
    10551199        if ( ! empty( $columns['cb'] ) ) {
    10561200            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>'
    10581202                . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />';
    10591203            $cb_counter++;
     
    10631207            $class = array( 'manage-column', "column-$column_key" );
    10641208
    1065             if ( in_array( $column_key, $hidden ) ) {
     1209            if ( in_array( $column_key, $hidden, true ) ) {
    10661210                $class[] = 'hidden';
    10671211            }
    10681212
    1069             if ( 'cb' === $column_key )
     1213            if ( 'cb' === $column_key ) {
    10701214                $class[] = 'check-column';
    1071             elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) )
     1215            } elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ), true ) ) {
    10721216                $class[] = 'num';
     1217            }
    10731218
    10741219            if ( $column_key === $primary ) {
     
    10761221            }
    10771222
    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 ];
    10801225
    10811226                if ( $current_orderby === $orderby ) {
    10821227                    $order = 'asc' === $current_order ? 'desc' : 'asc';
     1228
    10831229                    $class[] = 'sorted';
    10841230                    $class[] = $current_order;
    10851231                } 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
    10871238                    $class[] = 'sortable';
    1088                     $class[] = $desc_first ? 'asc' : 'desc';
     1239                    $class[] = 'desc' === $order ? 'asc' : 'desc';
    10891240                }
    10901241
    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                );
    10921247            }
    10931248
    1094             $tag = ( 'cb' === $column_key ) ? 'td' : 'th';
     1249            $tag   = ( 'cb' === $column_key ) ? 'td' : 'th';
    10951250            $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            }
    11001256
    11011257            echo "<$tag $scope $id $class>$column_display_name</$tag>";
     
    11041260
    11051261    /**
    1106      * Display the table
    1107      *
    1108      * @since 3.1.0
    1109      * @access public
     1262     * Displays the table.
     1263     *
     1264     * @since 3.1.0
    11101265     */
    11111266    public function display() {
     
    11151270
    11161271        $this->screen->render_screen_reader_content( 'heading_list' );
    1117 ?>
     1272        ?>
    11181273<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
    11191274    <thead>
     
    11231278    </thead>
    11241279
    1125     <tbody id="the-list"<?php
     1280    <tbody id="the-list"
     1281        <?php
    11261282        if ( $singular ) {
    11271283            echo " data-wp-lists='list:$singular'";
    1128         } ?>>
     1284        }
     1285        ?>
     1286        >
    11291287        <?php $this->display_rows_or_placeholder(); ?>
    11301288    </tbody>
     
    11371295
    11381296</table>
    1139 <?php
     1297        <?php
    11401298        $this->display_tablenav( 'bottom' );
    11411299    }
    11421300
    11431301    /**
    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.
    11501307     */
    11511308    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
    11601320     * @param string $which
    11611321     */
     
    11671327    <div class="tablenav <?php echo esc_attr( $which ); ?>">
    11681328
    1169         <?php if ( $this->has_items() ): ?>
     1329        <?php if ( $this->has_items() ) : ?>
    11701330        <div class="alignleft actions bulkactions">
    11711331            <?php $this->bulk_actions( $which ); ?>
    11721332        </div>
    1173         <?php endif;
     1333            <?php
     1334        endif;
    11741335        $this->extra_tablenav( $which );
    11751336        $this->pagination( $which );
    1176 ?>
     1337        ?>
    11771338
    11781339        <br class="clear" />
    11791340    </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
    11881348     *
    11891349     * @param string $which
     
    11921352
    11931353    /**
    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
    11981357     */
    11991358    public function display_rows_or_placeholder() {
     
    12081367
    12091368    /**
    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
    12141372     */
    12151373    public function display_rows() {
    1216         foreach ( $this->items as $item )
     1374        foreach ( $this->items as $item ) {
    12171375            $this->single_row( $item );
    1218     }
    1219 
    1220     /**
    1221      * Generates content for a single row of the table
    1222      *
    1223      * @since 3.1.0
    1224      * @access public
    1225      *
    1226      * @param object $item The current item
     1376        }
     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
    12271385     */
    12281386    public function single_row( $item ) {
     
    12331391
    12341392    /**
    1235      *
    1236      * @param object $item
     1393     * @param object|array $item
    12371394     * @param string $column_name
    12381395     */
     
    12401397
    12411398    /**
    1242      *
    1243      * @param object $item
     1399     * @param object|array $item
    12441400     */
    12451401    protected function column_cb( $item ) {}
    12461402
    12471403    /**
    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.
    12541409     */
    12551410    protected function single_row_columns( $item ) {
     
    12621417            }
    12631418
    1264             if ( in_array( $column_name, $hidden ) ) {
     1419            if ( in_array( $column_name, $hidden, true ) ) {
    12651420                $classes .= ' hidden';
    12661421            }
    12671422
    12681423            // 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 ) ) . '"';
    12711426
    12721427            $attributes = "class='$classes' $data";
     
    12881443                echo call_user_func( array( $this, 'column_' . $column_name ), $item );
    12891444                echo $this->handle_row_actions( $item, $column_name, $primary );
    1290                 echo "</td>";
     1445                echo '</td>';
    12911446            } else {
    12921447                echo "<td $attributes>";
    12931448                echo $this->column_default( $item, $column_name );
    12941449                echo $this->handle_row_actions( $item, $column_name, $primary );
    1295                 echo "</td>";
     1450                echo '</td>';
    12961451            }
    12971452        }
     
    13021457     *
    13031458     * @since 4.3.0
    1304      * @access protected
    1305      *
    1306      * @param object $item        The item being acted upon.
    1307      * @param string $column_name Current column name.
    1308      * @param string $primary     Primary column name.
    1309      * @return string The row actions HTML, or an empty string if the current column is the 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.
    13101465     */
    13111466    protected function handle_row_actions( $item, $column_name, $primary ) {
    13121467        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
    13201474     */
    13211475    public function ajax_response() {
     
    13351489        if ( isset( $this->_pagination_args['total_items'] ) ) {
    13361490            $response['total_items_i18n'] = sprintf(
     1491                /* translators: Number of items. */
    13371492                _n( '%s item', '%s items', $this->_pagination_args['total_items'] ),
    13381493                number_format_i18n( $this->_pagination_args['total_items'] )
     
    13401495        }
    13411496        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'];
    13431498            $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
    13441499        }
     
    13481503
    13491504    /**
    1350      * Send required variables to JavaScript land
    1351      *
    1352      * @access public
     1505     * Sends required variables to JavaScript land.
     1506     *
     1507     * @since 3.1.0
    13531508     */
    13541509    public function _js_vars() {
     
    13581513                'id'   => $this->screen->id,
    13591514                'base' => $this->screen->base,
    1360             )
     1515            ),
    13611516        );
    13621517
Note: See TracChangeset for help on using the changeset viewer.