Making WordPress.org

Changeset 13017


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

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

Fixes #7147.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin
Files:
2 edited

Legend:

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

    r12756 r13017  
    3030        add_filter( 'dashboard_glance_items', array( $this, 'plugin_glance_items' ) );
    3131
     32        add_filter( 'query_vars', array( $this, 'query_vars' ) );
    3233        add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
    3334
     
    190191
    191192    /**
     193     * Filter the query vars used in wp-admin.
     194     */
     195    public function query_vars( $query_vars ) {
     196        $query_vars[] = 'reviewer';
     197
     198        return $query_vars;
     199    }
     200
     201    /**
    192202     * Filter the query in wp-admin to list only plugins relevant to the current user.
    193203     *
     
    215225
    216226        // Filter by reviewer.
    217         if ( ! empty( $_REQUEST['reviewer'] ) ) {
     227        if ( isset( $query->query['reviewer'] ) && strlen( $query->query['reviewer'] ) ) {
    218228            $meta_query = $query->get( 'meta_query' ) ?: [];
    219             $meta_query[] = [
     229            $meta_query['assigned_reviewer'] = [
    220230                'key'   => 'assigned_reviewer',
    221                 'value' => intval( $_GET['reviewer'] ),
     231                'value' => intval( $query->query['reviewer'] ),
     232                'type'  => 'unsigned',
     233            ];
     234
     235            // Query for no assignee.
     236            if ( ! $meta_query['assigned_reviewer']['value'] ) {
     237                $meta_query['assigned_reviewer']['compare'] = 'NOT EXISTS';
     238            }
     239
     240            $query->set( 'meta_query', $meta_query );
     241        }
     242
     243        if ( 'assigned_reviewer_time' === $query->query['orderby'] ?? '' ) {
     244            $meta_query = $query->get( 'meta_query' ) ?: [];
     245
     246            $meta_query['assigned_reviewer_time'] = [
     247                'key'     => 'assigned_reviewer_time',
     248                'type'    => 'unsigned',
    222249            ];
    223250
  • 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.