Bind event on Media gallery elements WordPress

(function ($) { “use strict”; $(function () { var button = $(‘.upload-image’); button.click(function (e) { e.preventDefault(); // If the media frame already exists, reopen it. if (file_frame) { file_frame.open(); return; } var btn = $(this), media = wp.media; // Create the media frame. var file_frame = media.frames.file_frame = media({ title: jQuery(this).data(‘uploader_title’), button: { text: jQuery(this).data(‘uploader_button_text’) … Read more

Best approach when modifying the Media Manager

This is my go to snippet for things like this. <?php add_action(‘print_media_templates’, function(){ // define your backbone template; // the “tmpl-” prefix is required, // and your input field should have a data-setting attribute // matching the shortcode name ?> <script type=”text/html” id=”tmpl-my-custom-gallery-setting”> <label class=”setting”> <span><?php _e(‘My setting’); ?></span> <select data-setting=”my_custom_attr”> <option value=”foo”> Foo </option> … Read more

Rendering the uploaded file in a wp.media object

I presume you’ve fixed this already but (in a blatant attempt to snaffle the bounty and) as mentioned in the comments there’s a simple fix, in your myplugin_meta_box_callback() function change the line $mime_types = array( ‘application/pdf’ ); to $mime_types=”application/pdf”; The library.type option to wp.media expects a string (which can be comma-separated with additional types) not … Read more

WordPress 3.5 Media Manager – add a button

This block of code will add a button right next to the “Insert into post” one. When clicked, it will send selected images to WP editor, each wrapped inside your template HTML: var wpMediaFramePost = wp.media.view.MediaFrame.Post; wp.media.view.MediaFrame.Post = wpMediaFramePost.extend( { mainInsertToolbar: function( view ) { “use strict”; wpMediaFramePost.prototype.mainInsertToolbar.call(this, view); var controller = this; this.selectionStatusToolbar( view … Read more

ThickBox replacement

For what it’s worth, I have integrated the new media uploader in a plugin which allows the admin to select or upload media from the standard media dialog instead of having to copy/paste URLs, and it seems to work well. I posted an answer here that might be what you’re looking for. Tom McFarlin has … Read more

How to trigger a refresh in the media modal

You can checkout this link https://codex.wordpress.org/Javascript_Reference/wp.media jQuery(function($){ // Set all variables to be used in scope var frame, metaBox = $(‘#meta-box-id.postbox’), // Your meta box id here addImgLink = metaBox.find(‘.upload-custom-img’), delImgLink = metaBox.find( ‘.delete-custom-img’), imgContainer = metaBox.find( ‘.custom-img-container’), imgIdInput = metaBox.find( ‘.custom-img-id’ ); // ADD IMAGE LINK addImgLink.on( ‘click’, function( event ){ event.preventDefault(); // If … Read more

Add filter function in media modal box

The wonderful world of Backbone.js and WP (of which I know barely anything). I think the problem is you are just calling the same default media.view, instead I believe you need to initialize a new one. For example: /** * Replace the media-toolbar with our own */ var myDrop = media.view.AttachmentsBrowser; media.view.AttachmentsBrowser = media.view.AttachmentsBrowser.extend({ createToolbar: … Read more