I am attempting to get the custom image sizes that I’ve created using add_image_size
to return in the javascript object. I know how to include them in the dropdown, but I don’t want / need that.
The current object returns the defaults (full, large, medium, and thumbnail) in an array, but none of the custom sizes.
Here is the code I am using to set the uploader instance
jQuery('input.guide-logo-upload').on('click', function( event ){
event.preventDefault();
// If the media frame already exists, reopen it.
if ( file_frame ) {
file_frame.open();
return;
}
// Create the media frame.
file_frame = wp.media.frames.file_frame = wp.media({
title: jQuery( this ).data( 'uploader_title' ),
button: {
text: jQuery( this ).data( 'uploader_button_text' )
},
multiple: false // force single file
});
// run the callback when selected
file_frame.on( 'select', function() {
// make sure to only deal with the first item
attachment = file_frame.state().get('selection').first().toJSON();
// WHERE ARE MY CUSTOM SIZES
console.log(attachment);
// Populate the field with the URL and show a preview below it
jQuery('input#g-logo').val( attachment.url );
jQuery('input#g-logo-id').val( attachment.id );
jQuery('p.logo-description').after( '<img class="logo-display logo-140" src="' + attachment.sizes.thumbnail.url + '">' );
jQuery('p.logo-description').after( '<img class="logo-display logo-350" src="' + attachment.sizes.medium.url + '">' );
});
// Finally, open the modal
file_frame.open();
});
thanks to a friend on Twitter, I was able to get this working. Below is the code.
note: the array and foreach are only necessary because I have two separate ones I needed to include. if there is only 1 to include, that can be removed.