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:
parent
51f2e14b46
commit
5b11aea8f5
|
@ -875,23 +875,6 @@ function wp_edit_posts_query( $q = false ) {
|
||||||
return $avail_post_stati;
|
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}}
|
* {@internal Missing Short Description}}
|
||||||
*
|
*
|
||||||
|
|
|
@ -671,6 +671,9 @@ window.wp = window.wp || {};
|
||||||
// Generate the query `args` object.
|
// Generate the query `args` object.
|
||||||
// Correct any differing property names.
|
// Correct any differing property names.
|
||||||
_.each( props, function( value, prop ) {
|
_.each( props, function( value, prop ) {
|
||||||
|
if ( _.isNull( value ) )
|
||||||
|
return;
|
||||||
|
|
||||||
args[ Query.propmap[ prop ] || prop ] = value;
|
args[ Query.propmap[ prop ] || prop ] = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -2766,54 +2766,74 @@
|
||||||
change: 'change'
|
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() {
|
initialize: function() {
|
||||||
var els;
|
// Build `<option>` elements.
|
||||||
|
this.$el.html( _.chain( this.filters ).map( function( filter, value ) {
|
||||||
els = _.map({
|
return {
|
||||||
all: 'allMediaItems',
|
el: this.make( 'option', { value: value }, filter.text ),
|
||||||
uploaded: 'uploadedToThisPost',
|
priority: filter.priority || 50
|
||||||
image: 'images',
|
};
|
||||||
audio: 'audio',
|
}, this ).sortBy('priority').pluck('el').value() );
|
||||||
video: 'videos'
|
|
||||||
}, function( text, value ) {
|
|
||||||
return this.make( 'option', { value: value }, l10n[ text ] );
|
|
||||||
}, this );
|
|
||||||
|
|
||||||
this.$el.html( els );
|
|
||||||
|
|
||||||
this.model.on( 'change', this.select, this );
|
this.model.on( 'change', this.select, this );
|
||||||
this.select();
|
this.select();
|
||||||
},
|
},
|
||||||
|
|
||||||
change: function( event ) {
|
change: function( event ) {
|
||||||
var model = this.model,
|
var filter = this.filters[ this.el.value ];
|
||||||
value = this.el.value,
|
|
||||||
type;
|
|
||||||
|
|
||||||
if ( 'all' === value || 'uploaded' === value )
|
if ( filter )
|
||||||
model.unset('type');
|
this.model.set( filter.props );
|
||||||
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');
|
|
||||||
},
|
},
|
||||||
|
|
||||||
select: function() {
|
select: function() {
|
||||||
var model = this.model,
|
var model = this.model,
|
||||||
|
value = 'all',
|
||||||
type = model.get('type'),
|
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 )
|
_.find( this.filters, function( filter, key ) {
|
||||||
value = 'uploaded';
|
if ( _.isEqual( filter.props, props ) )
|
||||||
else if ( 'image' === type )
|
return value = key;
|
||||||
value = 'image';
|
});
|
||||||
else if ( 'audio' === type )
|
|
||||||
value = 'audio';
|
|
||||||
else if ( 'video' === type )
|
|
||||||
value = 'video';
|
|
||||||
|
|
||||||
this.$el.val( value );
|
this.$el.val( value );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1322,10 +1322,9 @@ function wp_enqueue_media( $args = array() ) {
|
||||||
unset( $tabs['type'], $tabs['type_url'], $tabs['gallery'], $tabs['library'] );
|
unset( $tabs['type'], $tabs['type_url'], $tabs['gallery'], $tabs['library'] );
|
||||||
|
|
||||||
$settings = array(
|
$settings = array(
|
||||||
'tabs' => $tabs,
|
'tabs' => $tabs,
|
||||||
'tabUrl' => add_query_arg( array(
|
'tabUrl' => add_query_arg( array( 'chromeless' => true ), admin_url('media-upload.php') ),
|
||||||
'chromeless' => true
|
'mimeTypes' => wp_list_pluck( get_post_mime_types(), 0 ),
|
||||||
), admin_url('media-upload.php') ),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$post = null;
|
$post = null;
|
||||||
|
@ -1354,16 +1353,12 @@ function wp_enqueue_media( $args = array() ) {
|
||||||
'uploadMoreFiles' => __( 'Upload more files' ),
|
'uploadMoreFiles' => __( 'Upload more files' ),
|
||||||
|
|
||||||
// Library
|
// Library
|
||||||
'mediaLibraryTitle' => __( 'Media Library' ),
|
'mediaLibraryTitle' => __( 'Media Library' ),
|
||||||
'createNewGallery' => __( 'Create a new gallery' ),
|
'createNewGallery' => __( 'Create a new gallery' ),
|
||||||
'insertIntoPost' => $hier ? __( 'Insert into page' ) : __( 'Insert into post' ),
|
'returnToLibrary' => __( '← Return to library' ),
|
||||||
'returnToLibrary' => __( '← Return to library' ),
|
|
||||||
|
|
||||||
'allMediaItems' => __( 'All media items' ),
|
'allMediaItems' => __( 'All media items' ),
|
||||||
|
'insertIntoPost' => $hier ? __( 'Insert into page' ) : __( 'Insert into post' ),
|
||||||
'uploadedToThisPost' => $hier ? __( 'Uploaded to this page' ) : __( 'Uploaded to this post' ),
|
'uploadedToThisPost' => $hier ? __( 'Uploaded to this page' ) : __( 'Uploaded to this post' ),
|
||||||
'images' => __( 'Images' ),
|
|
||||||
'audio' => __( 'Audio' ),
|
|
||||||
'videos' => __( 'Videos' ),
|
|
||||||
|
|
||||||
// Embed
|
// Embed
|
||||||
'embedFromUrlTitle' => __( 'Embed From URL' ),
|
'embedFromUrlTitle' => __( 'Embed From URL' ),
|
||||||
|
|
|
@ -2179,6 +2179,23 @@ function wp_count_attachments( $mime_type = '' ) {
|
||||||
return (object) $stats;
|
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.
|
* Check a MIME-Type against a list.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue