Make WordPress Core


Ignore:
Timestamp:
05/29/2015 02:40:52 AM (11 years ago)
Author:
helen
Message:

List tables: introduce the concept of a "primary" column.

This becomes the column that contains the row actions, and allows for a more flexibility, particularly with custom post types and list tables. To (re)define the primary column, use the list_table_primary_column filter, which receives the column name and the screen ID as arguments.

props stephdau, DaveAl, jesin.
see #25408.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-plugins-list-table.php

    r32642 r32644  
    569569                );
    570570
    571                 list( $columns, $hidden ) = $this->get_column_info();
     571                list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
     572
     573                $extra_class = ' has-row-actions column-primary';
    572574
    573575                foreach ( $columns as $column_name => $column_display_name ) {
    574576                        $style = '';
    575                         if ( in_array( $column_name, $hidden ) )
     577                        if ( in_array( $column_name, $hidden ) ) {
    576578                                $style = ' style="display:none;"';
     579                        }
    577580
    578581                        switch ( $column_name ) {
    … …  
    581584                                        break;
    582585                                case 'name':
    583                                         echo "<td class='plugin-title'$style><strong>$plugin_name</strong>";
    584                                         echo $this->row_actions( $actions, true );
     586                                        if ( $primary === $column_name || ! isset( $columns[ $primary ] ) ) {
     587                                                echo "<td class='plugin-title $extra_class'$style><strong>$plugin_name</strong>";
     588                                                echo $this->row_actions( $actions, true );
     589                                        } else {
     590                                                echo "<td class='plugin-title'$style><strong>$plugin_name</strong>";
     591                                        }
    585592                                        echo "</td>";
    586593                                        break;
    587594                                case 'description':
    588                                         echo "<td class='column-description desc'$style>
     595                                        $classes = 'column-description desc';
     596                                        if ( $primary === $column_name ) {
     597                                                $classes .= " $extra_class";
     598                                        }
     599
     600                                        echo "<td class='$classes'$style>
    589601                                                <div class='plugin-description'>$description</div>
    590602                                                <div class='$class second plugin-version-author-uri'>";
    … …  
    633645                                        echo implode( ' | ', $plugin_meta );
    634646
     647                                        if ( $primary === $column_name ) {
     648                                                echo $this->row_actions( $actions, true );
     649                                        }
    635650                                        echo "</div></td>";
    636651                                        break;
    637652                                default:
    638                                         echo "<td class='$column_name column-$column_name'$style>";
     653                                        $classes = "$column_name column-$column_name$class";
     654                                        if ( $primary === $column_name ) {
     655                                                $classes .= " $extra_class";
     656                                        }
     657
     658                                        echo "<td class='$classes'$style>";
    639659
    640660                                        /**
    … …  
    648668                                         */
    649669                                        do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data );
     670
     671                                        if ( $primary === $column_name ) {
     672                                                echo $this->row_actions( $actions, true );
     673                                        }
    650674                                        echo "</td>";
    651675                        }
    … …  
    683707                do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $status );
    684708        }
     709
     710        /**
     711         * Get name of default primary column for this specific list table.
     712         *
     713         * @since 4.3.0
     714         * @access protected
     715         *
     716         * @return string
     717         */
     718        protected function get_default_primary_column_name() {
     719                return 'plugin';
     720        }
    685721}
Note: See TracChangeset for help on using the changeset viewer.