Making WordPress.org


Ignore:
Timestamp:
12/06/2023 04:28:05 AM (17 months ago)
Author:
dd32
Message:

Plugin Directory: Reviewer tools: Make the Reviewer column sortable.

Fixes #7147.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/list-table/class-plugin-posts.php

    r12593 r13017  
    88
    99class Plugin_Posts extends \WP_Posts_List_Table {
     10
     11    protected $column_order = [
     12        'cb',
     13        'title',
     14        'author',
     15        'reviewer',
     16        'comments',
     17    ];
     18
     19    /**
     20     * Engage the filters.
     21     */
     22    public function __construct() {
     23        parent::__construct();
     24
     25        add_filter( "manage_{$this->screen->post_type}_posts_columns", [ $this, 'filter_columns' ], 100 );
     26        add_filter( "manage_{$this->screen->id}_sortable_columns", [ $this, 'filter_sortable_columns' ], 100 );
     27    }
     28
     29    /**
     30     * Add the custom columns and set the order.
     31     */
     32    public function filter_columns( $columns ) {
     33        // Rename some columns.
     34        $columns['author']   = __( 'Submitter', 'wporg-plugins' );
     35        $columns['reviewer'] = __( 'Assigned Reviewer', 'wporg-plugins' );
     36        $columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Internal Notes', 'wporg-plugins' ) . '"><span class="screen-reader-text">' . __( 'Internal Notes', 'wporg-plugins' ) . '</span></span>';
     37
     38        // We don't want the stats column.
     39        unset( $columns['stats'] );
     40
     41        $columns = array_merge( array_flip( $this->column_order ), $columns );
     42
     43        return $columns;
     44    }
     45
     46    /**
     47     * The sortable columns.
     48     */
     49    public function filter_sortable_columns( $columns ) {
     50        $columns[ 'reviewer' ] = [ 'assigned_reviewer_time', 'asc' ];
     51
     52        return $columns;
     53    }
    1054
    1155    /**
     
    100144
    101145        return $actions;
    102     }
    103 
    104     /**
    105      *
    106      * @return array
    107      */
    108     public function get_columns() {
    109         $post_type     = $this->screen->post_type;
    110         $posts_columns = array(
    111             'cb'       => '<input type="checkbox" />',
    112             /* translators: manage posts column name */
    113             'title'    => _x( 'Title', 'column name', 'wporg-plugins' ),
    114             'author'   => __( 'Submitter', 'wporg-plugins' ),
    115             'reviewer' => __( 'Assigned Reviewer', 'wporg-plugins' ),
    116         );
    117 
    118         $taxonomies = get_object_taxonomies( $post_type, 'objects' );
    119         $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
    120         $taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type );
    121         $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
    122 
    123         foreach ( $taxonomies as $taxonomy ) {
    124             $column_key                   = 'taxonomy-' . $taxonomy;
    125             $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
    126         }
    127 
    128         $posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Internal Notes', 'wporg-plugins' ) . '"><span class="screen-reader-text">' . __( 'Internal Notes', 'wporg-plugins' ) . '</span></span>';
    129         $posts_columns['date']     = __( 'Date', 'wporg-plugins' );
    130 
    131         /**
    132          * Filter the columns displayed in the Plugins list table.
    133          *
    134          * @param array  $posts_columns An array of column names.
    135          * @param string $post_type     The post type slug.
    136          */
    137         $posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type );
    138 
    139         /**
    140          * Filter the columns displayed in the Plugins list table.
    141          *
    142          * The dynamic portion of the hook name, `$post_type`, refers to the post type slug.
    143          *
    144          * @param array $post_columns An array of column names.
    145          */
    146         return apply_filters( "manage_{$post_type}_posts_columns", $posts_columns );
    147146    }
    148147
Note: See TracChangeset for help on using the changeset viewer.