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 | |
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>'; |
| 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 | ); |
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 | | |
| 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 | } |