Making WordPress.org


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

Plugin Directory: Reviewer Tools: Introduce a ZIP & lines-of-code column to the posts table.

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

    r13017 r13021  
    1414        'author',
    1515        'reviewer',
     16        'zip',
     17        'loc',
    1618        'comments',
    1719    ];
     
    3537        $columns['reviewer'] = __( 'Assigned Reviewer', 'wporg-plugins' );
    3638        $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>';
     39        $columns['zip']      = 'Latest Zip';
     40        $columns['loc']      = 'Lines of PHP Code';
    3741
    3842        // We don't want the stats column.
     
    4953    public function filter_sortable_columns( $columns ) {
    5054        $columns[ 'reviewer' ] = [ 'assigned_reviewer_time', 'asc' ];
     55        $columns[ 'zip' ]      = [ '_submitted_zip_size', 'asc' ];
     56        $columns[ 'loc' ]      = [ '_submitted_zip_loc', 'asc' ];
    5157
    5258        return $columns;
     
    654660        }
    655661    }
     662
     663    public function column_zip( $post ) {
     664        if ( ! in_array( $post->post_status, [ 'new', 'pending', 'approved' ] ) ) {
     665            echo '-';
     666            return;
     667        }
     668
     669        $attachments = get_posts( [
     670            'post_parent'    => $post->ID,
     671            'post_type'      => 'attachment',
     672            'post_mime_type' => 'application/zip',
     673            'posts_per_page' => 1,
     674            'orderby'        => 'post_date',
     675            'order'          => 'DESC',
     676        ] )[0];
     677
     678        foreach ( get_attached_media( 'application/zip', $post ) as $zip_file ) {
     679            $zip_size = size_format( filesize( get_attached_file( $zip_file->ID ) ), 1 );
     680
     681            $url  = wp_get_attachment_url( $zip_file->ID );
     682            $name = basename( $url );
     683            $name = explode( '_', $name, 3 )[2];
     684
     685            printf(
     686                '<a href="%1$s">%2$s</a><br>%3$s</li>',
     687                esc_url( $url ),
     688                esc_html( $name ),
     689                esc_html( $zip_size )
     690            );
     691        }
     692    }
     693
     694    public function column_loc( $post ) {
     695        echo number_format_i18n( $post->_submitted_zip_loc );
     696    }
    656697}
Note: See TracChangeset for help on using the changeset viewer.