Skip to content

Instantly share code, notes, and snippets.

@nickdaugherty
Last active December 15, 2015 10:49
Show Gist options
  • Save nickdaugherty/5248786 to your computer and use it in GitHub Desktop.
Save nickdaugherty/5248786 to your computer and use it in GitHub Desktop.
Forces only images uploaded to the post to be available for Featured Images
(function($){
if ( ! window.wp || ! wp.media ) {
return;
}
wp.media.view.AttachmentsBrowser = wp.media.view.AttachmentsBrowser.extend({
createUploader: function(){
this.$el.remove( '.uploader-inline' ).append( '<div class="uploader-inline"><h3>No Items Found.</h3></div>' );
}
});
$(function(){
wp.media.featuredImage.frame().on( 'open', function(){
$el = wp.media.featuredImage.frame().$el;
limit_to_uploaded_only( $el );
});
var workflow = wp.media.editor.get( 'content' );
if ( ! workflow )
workflow = wp.media.editor.add( 'content' );
workflow.on( 'open', function(){
limit_to_uploaded_only( workflow.$el );
});
workflow.state().on( 'activate', function(){
limit_to_uploaded_only( workflow.$el );
});
function limit_to_uploaded_only( $el ) {
var upload_tab = $el.find( '.media-router .media-menu-item:eq(0)' );
// If upload tab hasn't been removed already, remove it
if ( ! upload_tab.hasClass( 'removed') ) {
upload_tab
.css( { display: 'none' } )
.addClass( 'removed' );
}
$el.find( 'select.attachment-filters option[value!="uploaded"]' ).remove();
$el.find( 'select.attachment-filters').val( 'uploaded' ).trigger( 'change' );
// Remove the inline uploader, if present
if ( $el.find( '.attachments .attachment' ).size() ) {
$el.find( '.attachments-browser' ).remove( '.uploader-inline' ).append( '<div class="uploader-inline"><h3>No Items Found.</h3></div>' );
}
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment