我正在尝试获取使用创建的自定义图像大小add_image_size
返回javascript对象。我知道如何将它们包括在下拉列表中,但我不想/不需要。
当前对象返回数组中的默认值(完整、大、中和缩略图),但不返回任何自定义大小。
下面是我用来设置uploader实例的代码
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();
});