WordPress.org

Make WordPress Core

Changeset 34256


Ignore:
Timestamp:
09/17/2015 02:29:22 AM (6 years ago)
Author:
wonderboymusic
Message:

Media List Table: remove the counts from the "views" portion of the toolbar, which are inconsistent with grid view. Also reduces complexity and removes potentially expensive count query.

Related to the toolbar view, remove the wp_admin_canonical_url() action in grid mode. Grid views that result from links from the list table view are lenses into the library and need to be indicated as such vs being a full attachment query.

Fixes #29744.

Location:
trunk/src/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-media-list-table.php

    r34163 r34256  
    8585     */
    8686    protected function get_views() {
    87         global $wpdb, $post_mime_types, $avail_post_mime_types;
     87        global $post_mime_types, $avail_post_mime_types;
    8888
    8989        $type_links = array();
    90         $_num_posts = (array) wp_count_attachments();
    91         $_total_posts = array_sum($_num_posts) - $_num_posts['trash'];
    92         $total_orphans = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1" );
    93         $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
    94         $num_posts = array();
    95         foreach ( $matches as $type => $reals ) {
    96             foreach ( $reals as $real ) {
    97                 $num_posts[$type] = ( isset( $num_posts[$type] ) ) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real];
    98             }
    99         }
    100         $selected = empty( $_GET['attachment-filter'] ) ? ' selected="selected"' : '';
    101         $type_links['all'] = "<option value=''$selected>" . sprintf( _nx( 'All (%s)', 'All (%s)', $_total_posts, 'uploaded files' ), number_format_i18n( $_total_posts ) ) . '</option>';
     90
     91        $filter = empty( $_GET['attachment-filter'] ) ? '' : $_GET['attachment-filter'];
     92
     93        $type_links['all'] = sprintf(
     94            '<option value=""%s>%s</option>',
     95            selected( $filter, true, false ),
     96            __( 'All media items' )
     97        );
     98
    10299        foreach ( $post_mime_types as $mime_type => $label ) {
    103             if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
     100            if ( ! wp_match_mime_types( $mime_type, $avail_post_mime_types ) ) {
    104101                continue;
    105 
    106             $selected = '';
    107             if ( !empty( $_GET['attachment-filter'] ) && strpos( $_GET['attachment-filter'], 'post_mime_type:' ) === 0 && wp_match_mime_types( $mime_type, str_replace( 'post_mime_type:', '', $_GET['attachment-filter'] ) ) )
    108                 $selected = ' selected="selected"';
    109             if ( !empty( $num_posts[$mime_type] ) )
    110                 $type_links[$mime_type] = '<option value="post_mime_type:' . esc_attr( $mime_type ) . '"' . $selected . '>' . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</option>';
    111         }
    112         $type_links['detached'] = '<option value="detached"' . ( $this->detached ? ' selected="selected"' : '' ) . '>' . sprintf( _nx( 'Unattached (%s)', 'Unattached (%s)', $total_orphans, 'detached files' ), number_format_i18n( $total_orphans ) ) . '</option>';
    113 
    114         if ( !empty($_num_posts['trash']) )
    115             $type_links['trash'] = '<option value="trash"' . ( (isset($_GET['attachment-filter']) && $_GET['attachment-filter'] == 'trash' ) ? ' selected="selected"' : '') . '>' . sprintf( _nx( 'Trash (%s)', 'Trash (%s)', $_num_posts['trash'], 'uploaded files' ), number_format_i18n( $_num_posts['trash'] ) ) . '</option>';
    116 
     102            }
     103
     104            $selected = selected(
     105                $filter && 0 === strpos( $filter, 'post_mime_type:' ) &&
     106                    wp_match_mime_types( $mime_type, str_replace( 'post_mime_type:', '', $filter ) ),
     107                true,
     108                false   
     109            );
     110
     111            $type_links[$mime_type] = sprintf(
     112                '<option value="post_mime_type:%s"%s>%s</option>',
     113                esc_attr( $mime_type ),
     114                $selected,
     115                $label[0]
     116            );
     117        }
     118        $type_links['detached'] = '<option value="detached"' . ( $this->detached ? ' selected="selected"' : '' ) . '>' . __( 'Unattached' ) . '</option>';
     119
     120        if ( $this->is_trash ) {
     121            $type_links['trash'] = sprintf(
     122                '<option value="trash"%s>%s</option>',
     123                selected( 'trash' === $filter, true, false ),
     124                __( 'Trash' )
     125            );
     126        }
    117127        return $type_links;
    118128    }
     
    373383        <p class="filename">
    374384            <span class="screen-reader-text"><?php _e( 'File name:' ); ?> </span>
    375             <?php 
     385            <?php
    376386            $file = get_attached_file( $post->ID );
    377387            echo wp_basename( $file );
  • trunk/src/wp-admin/upload.php

    r33435 r34256  
    2525    wp_enqueue_script( 'media-grid' );
    2626    wp_enqueue_script( 'media' );
     27
     28    remove_action( 'admin_head', 'wp_admin_canonical_url' );
    2729
    2830    $q = $_GET;
Note: See TracChangeset for help on using the changeset viewer.