Run script after clicking Set Featured Image in Media

I would like to run some script to get the featured image's width and height after the user clicked 'Use Featured Image' button and use the data retrieved within the Post Edit screen. Is there such hook available for use in JavaScript? Otherwise, do you have other suggestions to achieve this?

Thanks for helping!

Edit : If there isn't any hook, I tried using the code below but clicking 'Set Featured Image' wouldn't trigger the event, presumably because it's a modal pop-up? Any ideas?

jQuery("#set-post-thumbnail").on("click", function(){
    alert('clicked');

    jQuery(document).on("click", '.media-button-select', function(){
        alert('clicked button');
    })
})  

Topic media-modal thickbox media Wordpress

Category Web


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.