Making WordPress.org

Changeset 13034


Ignore:
Timestamp:
12/08/2023 04:07:07 AM (9 months ago)
Author:
dd32
Message:

Plugin Directory: Reviewer tools: More consistent UI for the extra columns, and hide irrelevant columns for non-pending views.

See #7285.

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

    r13033 r13034  
    2727        add_filter( "manage_{$this->screen->post_type}_posts_columns", [ $this, 'filter_columns' ], 100 );
    2828        add_filter( "manage_{$this->screen->id}_sortable_columns", [ $this, 'filter_sortable_columns' ], 100 );
     29        add_filter( 'hidden_columns', [ $this, 'filter_hidden_columns' ], 100, 3 );
    2930    }
    3031
     
    5556        $columns[ 'zip' ]      = [ '_submitted_zip_size', 'asc' ];
    5657        $columns[ 'loc' ]      = [ '_submitted_zip_loc', 'asc' ];
     58
     59        return $columns;
     60    }
     61
     62    /**
     63     * Hide some fields by default.
     64     */
     65    public function filter_hidden_columns( $columns, $screen, $use_defaults ) {
     66        if ( $screen->id !== $this->screen->id ) {
     67            return $columns;
     68        }
     69
     70        // Hide certain columns on default / published views.
     71        if (
     72            in_array( $_REQUEST['post_status'] ?? 'all', [ 'all', 'publish', 'disabled', 'closed' ] ) &&
     73            empty( $_REQUEST['author'] ) &&
     74            empty( $_REQUEST['reviewer'] )
     75        ) {
     76            $columns[] = 'reviewer';
     77            $columns[] = 'zip';
     78            $columns[] = 'loc';
     79        }
    5780
    5881        return $columns;
     
    668691                )
    669692            );
     693        } else {
     694            echo '-';
    670695        }
    671696    }
    672697
    673698    public function column_zip( $post ) {
    674         if ( ! in_array( $post->post_status, [ 'new', 'pending', 'approved' ] ) ) {
     699        $media = get_attached_media( 'application/zip', $post );
     700
     701        if ( ! $media || ! in_array( $post->post_status, [ 'new', 'pending', 'approved' ] ) ) {
    675702            echo '-';
    676703            return;
    677704        }
    678705
    679         foreach ( get_attached_media( 'application/zip', $post ) as $zip_file ) {
     706        foreach ( $media as $zip_file ) {
    680707            $zip_size = size_format( filesize( get_attached_file( $zip_file->ID ) ), 1 );
    681708
     
    694721
    695722    public function column_loc( $post ) {
    696         echo number_format_i18n( $post->_submitted_zip_loc );
     723        if ( ! in_array( $post->post_status, [ 'new', 'pending', 'approved' ] ) ) {
     724            echo '-';
     725            return;
     726        }
     727
     728        echo number_format_i18n( (int) $post->_submitted_zip_loc ) ?: '-';
    697729    }
    698730}
Note: See TracChangeset for help on using the changeset viewer.