Run script after clicking Set Featured Image in Media

I think what you need is (function(){ var featuredImage = wp.media.featuredImage.frame(); featuredImage.on(‘select’, function(){ var attachment = featuredImage.state().get(‘selection’).first().toJSON(); console.log(attachment); }); })(); The attachment object should have height and width properties.

Filter medias from the Media Uploader (wp.media) modal with a post meta

Simplest part is to filter attachment list. Use this code add_filter(‘ajax_query_attachments_args’, function($args) { $args[‘meta_query’] = array( array( ‘key’ => ‘my_image_meta’, ‘value’ => $some_value, ‘compare’ => ‘=’ ) ); return $args; }); However this code will filter all media library queries. You may want to pass some additional parameter from wp.media. This answer may be helpful.

Open the attachment details modal

Unfortunately the logic of the attachment details isn’t made to be used standalone – it requires the grid that opens it. You can however use the get_media_item( attachment_id ) method to receive the HTML of the form for modifying images: https://developer.wordpress.org/reference/functions/get_media_item/

Adding fields to the media uploader with jquery listeners

From Blackbone.js website: render is the core function that your view should override, in order to populate its element (this.el), with the appropriate HTML. The convention is for render to always return this. So, I have modified the code a little bit to add jQuery change listener. function add_gallery_type_option(){ ?> <script type=”text/html” id=”tmpl-my-custom-gallery-setting”> <label class=”setting”> … Read more

How to set additional parameter in wp.media?

I’ve been searching for this answer too and found it using this answer. You just need to add a property to the library object: var wpMedia = wp.media.frames.file_frame = wp.media({ ‘library’: { type: ‘image’, custom_var: ‘webhead’ }, ‘multiple’: true }); Then in PHP you can see the custom variable in the ajax_query_attachments_args hook like so: … Read more

How to extend Media Library (WP 4.4)

It’s not a tab but you might be able to get started with an upload button. Check out pre-upload-ui and some actions that follow. Namely pre-plupload-upload-ui and post-upload-ui. This will add a couple buttons to the ‘Upload Files‘ tab and to ‘Media > Add New‘. BUTTONS add_action( ‘pre-plupload-upload-ui’, ‘wpse_20160202_pre_plupload_upload_ui’ ); add_action( ‘post-upload-ui’, ‘wpse_20160202_post_upload_ui’ ); function … Read more

Modify the array of selected images in media modal

I’m able to do the following in media modal: var selection = wp.media.frame.state().get(‘selection’); // get selected collection attachment = wp.media.attachment(id); // get attachment with id attachment.fetch(); selection.add(attachment); // add attachment to selection collection There should be .remove() method or something similar.

Modify Custom Field in Media Library using JavaScript

One way to do it (which is probably evil) is to select the control by adding a block of javascript using the tr field of $form_fields: function set_image_data( $form_fields, $post ) { $form_fields[‘text_color’] = array( ‘label’ => ‘Text Color’, ‘input’ => ‘text’, ‘value’ => get_post_meta( $post->ID, ‘_text_color’, true ) ); ob_start(); ?> <script type=”text/javascript”> jQuery(‘[name$=”[text_color]”]’).myColorPicker(); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)