Media: Dynamically generate attachment filters using get_post_mime_types().

Moves `get_post_mime_types()` from `wp-admin/includes/post.php` to `wp-includes/post.php`.

fixes #22514, see #21390.


git-svn-id: http://core.svn.wordpress.org/trunk@22743 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Daryl Koopersmith 2012-11-21 10:18:59 +00:00
parent 51f2e14b46
commit 5b11aea8f5
5 changed files with 81 additions and 63 deletions

View File

@ -875,23 +875,6 @@ function wp_edit_posts_query( $q = false ) {
return $avail_post_stati;
}
/**
* Get default post mime types
*
* @since 2.9.0
*
* @return array
*/
function get_post_mime_types() {
$post_mime_types = array( // array( adj, noun )
'image' => array(__('Images'), __('Manage Images'), _n_noop('Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>')),
'audio' => array(__('Audio'), __('Manage Audio'), _n_noop('Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>')),
'video' => array(__('Video'), __('Manage Video'), _n_noop('Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>')),
);
return apply_filters('post_mime_types', $post_mime_types);
}
/**
* {@internal Missing Short Description}}
*

View File

@ -671,6 +671,9 @@ window.wp = window.wp || {};
// Generate the query `args` object.
// Correct any differing property names.
_.each( props, function( value, prop ) {
if ( _.isNull( value ) )
return;
args[ Query.propmap[ prop ] || prop ] = value;
});

View File

@ -2766,54 +2766,74 @@
change: 'change'
},
filters: (function() {
var filters = {};
_.each( media.view.settings.mimeTypes || {}, function( text, key ) {
filters[ key ] = {
text: text,
props: {
type: key,
parent: null
}
};
});
filters.all = {
text: l10n.allMediaItems,
props: {
type: null,
parent: null
},
priority: 10
};
filters.uploaded = {
text: l10n.uploadedToThisPost,
props: {
type: null,
parent: media.view.settings.postId
},
priority: 20
};
return filters;
}()),
initialize: function() {
var els;
els = _.map({
all: 'allMediaItems',
uploaded: 'uploadedToThisPost',
image: 'images',
audio: 'audio',
video: 'videos'
}, function( text, value ) {
return this.make( 'option', { value: value }, l10n[ text ] );
}, this );
this.$el.html( els );
// Build `<option>` elements.
this.$el.html( _.chain( this.filters ).map( function( filter, value ) {
return {
el: this.make( 'option', { value: value }, filter.text ),
priority: filter.priority || 50
};
}, this ).sortBy('priority').pluck('el').value() );
this.model.on( 'change', this.select, this );
this.select();
},
change: function( event ) {
var model = this.model,
value = this.el.value,
type;
var filter = this.filters[ this.el.value ];
if ( 'all' === value || 'uploaded' === value )
model.unset('type');
else if ( 'image' === value || 'audio' === value || 'video' === value )
model.set( 'type', value );
if ( 'uploaded' === value )
model.set( 'parent', media.view.settings.postId );
else
model.unset('parent');
if ( filter )
this.model.set( filter.props );
},
select: function() {
var model = this.model,
value = 'all',
type = model.get('type'),
value = 'all';
parent = model.get('parent'),
props = {
parent: _.isUndefined( parent ) ? null : parent,
type: _.isUndefined( type ) ? null : type
};
if ( model.get('parent') === media.view.settings.postId )
value = 'uploaded';
else if ( 'image' === type )
value = 'image';
else if ( 'audio' === type )
value = 'audio';
else if ( 'video' === type )
value = 'video';
_.find( this.filters, function( filter, key ) {
if ( _.isEqual( filter.props, props ) )
return value = key;
});
this.$el.val( value );
}

View File

@ -1322,10 +1322,9 @@ function wp_enqueue_media( $args = array() ) {
unset( $tabs['type'], $tabs['type_url'], $tabs['gallery'], $tabs['library'] );
$settings = array(
'tabs' => $tabs,
'tabUrl' => add_query_arg( array(
'chromeless' => true
), admin_url('media-upload.php') ),
'tabs' => $tabs,
'tabUrl' => add_query_arg( array( 'chromeless' => true ), admin_url('media-upload.php') ),
'mimeTypes' => wp_list_pluck( get_post_mime_types(), 0 ),
);
$post = null;
@ -1354,16 +1353,12 @@ function wp_enqueue_media( $args = array() ) {
'uploadMoreFiles' => __( 'Upload more files' ),
// Library
'mediaLibraryTitle' => __( 'Media Library' ),
'createNewGallery' => __( 'Create a new gallery' ),
'insertIntoPost' => $hier ? __( 'Insert into page' ) : __( 'Insert into post' ),
'returnToLibrary' => __( '&#8592; Return to library' ),
'mediaLibraryTitle' => __( 'Media Library' ),
'createNewGallery' => __( 'Create a new gallery' ),
'returnToLibrary' => __( '&#8592; Return to library' ),
'allMediaItems' => __( 'All media items' ),
'insertIntoPost' => $hier ? __( 'Insert into page' ) : __( 'Insert into post' ),
'uploadedToThisPost' => $hier ? __( 'Uploaded to this page' ) : __( 'Uploaded to this post' ),
'images' => __( 'Images' ),
'audio' => __( 'Audio' ),
'videos' => __( 'Videos' ),
// Embed
'embedFromUrlTitle' => __( 'Embed From URL' ),

View File

@ -2179,6 +2179,23 @@ function wp_count_attachments( $mime_type = '' ) {
return (object) $stats;
}
/**
* Get default post mime types
*
* @since 2.9.0
*
* @return array
*/
function get_post_mime_types() {
$post_mime_types = array( // array( adj, noun )
'image' => array(__('Images'), __('Manage Images'), _n_noop('Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>')),
'audio' => array(__('Audio'), __('Manage Audio'), _n_noop('Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>')),
'video' => array(__('Video'), __('Manage Video'), _n_noop('Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>')),
);
return apply_filters('post_mime_types', $post_mime_types);
}
/**
* Check a MIME-Type against a list.
*