Make WordPress Core


Ignore:
Timestamp:
05/29/2015 02:40:52 AM (10 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-list-table.php

    r32642 r32644  
    796796
    797797    /**
     798     * Get name of default primary column
     799     *
     800     * @since 4.3.0
     801     * @access protected
     802     *
     803     * @return string
     804     */
     805    protected function get_default_primary_column_name() {
     806        return '';
     807    }
     808
     809    /**
     810     * Get name of primary column.
     811     *
     812     * @since 4.3.0
     813     * @access protected
     814     *
     815     * @return string Filtered name of primary column
     816     */
     817    protected function get_primary_column_name() {
     818        $columns = $this->get_columns();
     819        $default = $this->get_default_primary_column_name();
     820        /**
     821         * Filter the name of the primary column for the current list table, with context as argument (eg: 'plugins').
     822         *
     823         * @since 4.3.0
     824         *
     825         * @param string $default Column name default for the specific list table (eg: 'name')
     826         * @param string $context Screen ID for specific list table (eg: 'plugins')
     827         */
     828        $column  = apply_filters( 'list_table_primary_column', $default, $this->screen->id );
     829
     830        if ( empty( $column ) || ! isset( $columns[ $column ] ) ) {
     831            $column = $default;
     832        }
     833
     834        return $column;
     835    }
     836
     837    /**
    798838     * Get a list of all, hidden and sortable columns, with filter applied
    799839     *
     
    835875        }
    836876
    837         $this->_column_headers = array( $columns, $hidden, $sortable );
     877        $primary = $this->get_primary_column_name();
     878        $this->_column_headers = array( $columns, $hidden, $sortable, $primary );
    838879
    839880        return $this->_column_headers;
     
    10631104     */
    10641105    protected function single_row_columns( $item ) {
    1065         list( $columns, $hidden ) = $this->get_column_info();
     1106        list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
    10661107
    10671108        foreach ( $columns as $column_name => $column_display_name ) {
    1068             $class = "class='$column_name column-$column_name'";
     1109            $classes = "$column_name column-$column_name";
     1110            if ( $primary === $column_name ) {
     1111                $classes .= ' has-row-actions column-primary';
     1112            }
    10691113
    10701114            $style = '';
    1071             if ( in_array( $column_name, $hidden ) )
     1115            if ( in_array( $column_name, $hidden ) ) {
    10721116                $style = ' style="display:none;"';
    1073 
    1074             $attributes = "$class$style";
     1117            }
     1118
     1119            $attributes = "class='$classes'$style";
    10751120
    10761121            if ( 'cb' == $column_name ) {
     
    10821127                echo "<td $attributes>";
    10831128                echo call_user_func( array( $this, 'column_' . $column_name ), $item );
     1129                echo $this->handle_row_actions( $item, $column_name, $primary );
    10841130                echo "</td>";
    10851131            }
     
    10871133                echo "<td $attributes>";
    10881134                echo $this->column_default( $item, $column_name );
     1135                echo $this->handle_row_actions( $item, $column_name, $primary );
    10891136                echo "</td>";
    10901137            }
    10911138        }
    10921139    }
     1140
     1141    /**
     1142     * Generate and display row actions links
     1143     *
     1144     * @since 4.3.0
     1145     * @access protected
     1146     *
     1147     * @param object $item Item being acted upon
     1148     * @param string $column_name Current column name
     1149     * @param string $primary Primary column name
     1150     *
     1151     * @return string
     1152     */
     1153    protected function handle_row_actions( $item, $column_name, $primary ) {
     1154        return '';
     1155    }
    10931156
    10941157    /**
Note: See TracChangeset for help on using the changeset viewer.