Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/js/media/views/attachment-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,20 @@ AttachmentFilters = wp.media.View.extend(/** @lends wp.media.view.AttachmentFilt

// Build `<option>` elements.
this.$el.html( _.chain( this.filters ).map( function( filter, value ) {
// Potentially add an icon to the option.
var filterText = filter.text;
if ( filter.props.icon ) {
filterText = '<span class="dashicons dashicons-' + filter.props.icon + '"></span> ' + filter.text;
}
return {
el: $( '<option></option>' ).val( value ).html( filter.text )[0],
el: $( '<option></option>' ).val( value ).html( filterText )[0],
priority: filter.priority || 50
};
}, this ).sortBy('priority').pluck('el').value() );

// Prepend the selectedelement.
this.$el.prepend( '<button><selectedcontent></selectedcontent></button>' );

this.listenTo( this.model, 'change', this.select );
this.select();
},
Expand Down
54 changes: 30 additions & 24 deletions src/js/media/views/attachment-filters/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,27 @@ All = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attachment
filters[ key ] = {
text: text,
props: {
status: null,
type: key,
status: null,
type: key,
uploadedTo: null,
orderby: 'date',
order: 'DESC',
author: null
}
orderby: 'date',
order: 'DESC',
author: null,
icon: wp.media.view.settings.mimeIcons[key] || false
},
};
});

filters.all = {
text: l10n.allMediaItems,
props: {
status: null,
type: null,
status: null,
type: null,
uploadedTo: null,
orderby: 'date',
order: 'DESC',
author: null
orderby: 'date',
order: 'DESC',
author: null,
icon: 'format-gallery'
},
priority: 10
};
Expand All @@ -48,12 +50,13 @@ All = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attachment
filters.uploaded = {
text: l10n.uploadedToThisPost,
props: {
status: null,
type: null,
status: null,
type: null,
uploadedTo: wp.media.view.settings.post.id,
orderby: 'menuOrder',
order: 'ASC',
author: null
orderby: 'menuOrder',
order: 'ASC',
author: null,
icon: 'upload'
},
priority: 20
};
Expand All @@ -67,7 +70,8 @@ All = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attachment
type: null,
orderby: 'menuOrder',
order: 'ASC',
author: null
author: null,
icon: 'no'
},
priority: 50
};
Expand All @@ -76,12 +80,13 @@ All = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attachment
filters.mine = {
text: l10n.mine,
props: {
status: null,
type: null,
uploadedTo: null,
orderby: 'date',
order: 'DESC',
author: uid
status: null,
type: null,
uploadedTo: null,
orderby: 'date',
order: 'DESC',
author: uid,
icon: 'admin-users'
},
priority: 50
};
Expand All @@ -98,7 +103,8 @@ All = wp.media.view.AttachmentFilters.extend(/** @lends wp.media.view.Attachment
type: null,
orderby: 'date',
order: 'DESC',
author: null
author: null,
icon: 'trash'
},
priority: 50
};
Expand Down
16 changes: 16 additions & 0 deletions src/wp-admin/css/media.css
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,22 @@ border color while dragging a file over the uploader drop area */

.post-type-attachment .wp-filter select {
margin: 0 6px 0 0;
appearance: base-select;
}

.post-type-attachment .wp-filter select::picker(select) {
appearance: base-select;
}

.post-type-attachment .wp-filter select selectedcontent,
.media-modal-content .media-frame select.attachment-filters selectedcontent {
display: flex;
align-items: center;
gap: .5ch;
}

.post-type-attachment .wp-filter select::picker-icon {
display: none;
}

/* Match the spacing the grid view toolbar gets from
Expand Down
19 changes: 14 additions & 5 deletions src/wp-admin/includes/class-wp-media-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ protected function get_views() {
$filter = empty( $_GET['attachment-filter'] ) ? '' : $_GET['attachment-filter'];

$type_links['all'] = sprintf(
'<option value=""%s>%s</option>',
'<option value=""%s>%s%s</option>',
selected( $filter, true, false ),
'<span class="dashicons dashicons-format-gallery"></span> ',
__( 'All media items' )
);

Expand All @@ -170,26 +171,31 @@ protected function get_views() {
false
);

$dashicon = ! empty( $label[3] ) ? "<span class='dashicons dashicons-$label[3]'></span> " : '';

$type_links[ $mime_type ] = sprintf(
'<option value="post_mime_type:%s"%s>%s</option>',
'<option value="post_mime_type:%s"%s>%s%s</option>',
esc_attr( $mime_type ),
$selected,
$dashicon,
$label[0]
);
}

$type_links['detached'] = '<option value="detached"' . ( $this->detached ? ' selected="selected"' : '' ) . '>' . _x( 'Unattached', 'media items' ) . '</option>';
$type_links['detached'] = '<option value="detached"' . ( $this->detached ? ' selected="selected"' : '' ) . '><span class="dashicons dashicons-no"></span> ' . _x( 'Unattached', 'media items' ) . '</option>';

$type_links['mine'] = sprintf(
'<option value="mine"%s>%s</option>',
'<option value="mine"%s>%s%s</option>',
selected( 'mine' === $filter, true, false ),
'<span class="dashicons dashicons-admin-users"></span> ',
_x( 'Mine', 'media items' )
);

if ( $this->is_trash || ( defined( 'MEDIA_TRASH' ) && MEDIA_TRASH ) ) {
$type_links['trash'] = sprintf(
'<option value="trash"%s>%s</option>',
'<option value="trash"%s>%s%s</option>',
selected( 'trash' === $filter, true, false ),
'<span class="dashicons dashicons-trash"></span> ',
_x( 'Trash', 'attachment filter' )
);
}
Expand Down Expand Up @@ -316,6 +322,9 @@ public function views() {
?>
</label>
<select class="attachment-filters" name="attachment-filter" id="attachment-filter">
<button>
<selectedcontent></selectedcontent>
</button>
<?php
if ( ! empty( $views ) ) {
foreach ( $views as $class => $view ) {
Expand Down
1 change: 1 addition & 0 deletions src/wp-includes/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -5088,6 +5088,7 @@ function wp_enqueue_media( $args = array() ) {
'tabs' => $tabs,
'tabUrl' => add_query_arg( array( 'chromeless' => true ), admin_url( 'media-upload.php' ) ),
'mimeTypes' => wp_list_pluck( get_post_mime_types(), 0 ),
'mimeIcons' => wp_list_pluck( get_post_mime_types(), 3, 0 ),
/** This filter is documented in wp-admin/includes/media.php */
'captions' => ! apply_filters( 'disable_captions', '' ),
'nonce' => array(
Expand Down
9 changes: 8 additions & 1 deletion src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -3754,7 +3754,8 @@ function wp_count_attachments( $mime_type = '' ) {
* Gets default post mime types.
*
* @since 2.9.0
* @since 5.3.0 Added the 'Documents', 'Spreadsheets', and 'Archives' mime type groups.
* @since 5.3.0 Added the 'Documents', 'Spreadsheets', and 'Archives' mime type groups.
* @since n.e.x.t. Added dashicon strings for each mime type.
*
* @return array<string, array{0: string, 1: string, 2: array}> List of post mime types, keyed by mime type group
* or by a comma-separated list of mime types. Each
Expand Down Expand Up @@ -3784,6 +3785,7 @@ function get_post_mime_types() {
'Image <span class="count">(%s)</span>',
'Images <span class="count">(%s)</span>'
),
'format-image',
),
'audio' => array(
_x( 'Audio', 'file type group' ),
Expand All @@ -3793,6 +3795,7 @@ function get_post_mime_types() {
'Audio <span class="count">(%s)</span>',
'Audio <span class="count">(%s)</span>'
),
'format-audio',
),
'video' => array(
_x( 'Video', 'file type group' ),
Expand All @@ -3802,6 +3805,7 @@ function get_post_mime_types() {
'Video <span class="count">(%s)</span>',
'Video <span class="count">(%s)</span>'
),
'format-video',
),
'document' => array(
__( 'Documents' ),
Expand All @@ -3811,6 +3815,7 @@ function get_post_mime_types() {
'Document <span class="count">(%s)</span>',
'Documents <span class="count">(%s)</span>'
),
'media-document',
),
'spreadsheet' => array(
__( 'Spreadsheets' ),
Expand All @@ -3820,6 +3825,7 @@ function get_post_mime_types() {
'Spreadsheet <span class="count">(%s)</span>',
'Spreadsheets <span class="count">(%s)</span>'
),
'media-spreadsheet',
),
'archive' => array(
_x( 'Archives', 'file type group' ),
Expand All @@ -3829,6 +3835,7 @@ function get_post_mime_types() {
'Archive <span class="count">(%s)</span>',
'Archives <span class="count">(%s)</span>'
),
'archive',
),
);

Expand Down
Loading