retrieve custom image sizes from media uploader javascript object

thanks to a friend on Twitter, I was able to get this working. Below is the code. function wpse_110060_image_sizes_js( $response, $attachment, $meta ){ $size_array = array( ‘custom_size_one’, ‘custom_size_two’) ; foreach ( $size_array as $size ): if ( isset( $meta[‘sizes’][ $size ] ) ) { $attachment_url = wp_get_attachment_url( $attachment->ID ); $base_url = str_replace( wp_basename( $attachment_url ), … Read more

REST API: Backbone and custom endpoint

It looks like you are trying to send a POST request to the /istermactive endpoint, is that correct? (I think you may want to remove the trailing slash from the endpoint?) I’m not really sure the wp-api client is the right tool for a standard ajax POST, you may want to use jQuery.ajax or use … Read more

Pass media upload value to input field

You can use some thing like this to add as many image as you want with the botton click for example add logos or advertisements etc jQuery(document).ready(function($){ var mediaUploader; /* function to add partner logo */ function display_ad( button, title, btnTxt, inputFieldId, outputDivId,formClass, e){ e.preventDefault(); if (mediaUploader) { mediaUploader.open(); return; } mediaUploader = wp.media.frames.file_frame =wp.media({ … Read more

WordPress 5.5 – ReferenceError: commonL10n is not defined error

This is Trac ticket 51223: commonL10n and other JS globals removed without backwards compatibility In WordPress 5.5, the localized translations under commonL10n were replaced by wp.i18n.__ without deprecation notice or backwards compatibility. Plugins using commonL10n now have JavaScript errors introduced by updating WordPress which can break site functionality. It was fixed in 5.5.1 by adding … Read more

Display attachments by ID in a wp.media frame

You can always filter on the client side: var query = wp.media.query(); query.filterWithIds = function(ids) { return _(this.models.filter(function(c) { return _.contains(ids, c.id); })); }; var res = query.filterWithIds([6,87]); // change these to your IDs res.each(function(v){ console.log( v.toJSON() ); }); Disclaimer: found the beautiful filterWithIds function in this SO question.

wp.customize.bind ready event not fired

Do not put the Customizer ready event handler inside of the jQuery event handler. The Customizer ready will trigger at jQuery ready, so you are adding the event handler too late. Just do: wp.customize.bind(‘ready’, function(){ console.log(‘ready’); }); Your JS needs to be enqueued with customize-controls script as its dependency. Enqueue at the customize_controls_enqueue_scripts action.