A method to force open the Media Manager UI when directly uploading in the editor

Question

I am trying to find a way to force open the Media Manager UI after uploading an image (or simply use the Media Manager rather than the Upload button, if easier).

The reason for this approach is that I have added some custom validation code in the default wp.media.frame to validate some image metadata (credits) and allowing an upload/insert only if this field contains data. This works as long as the editor uses the Media Manager’s upload tab is used to upload an image (since it auto-opens the library tab with the uploaded image preselected). But if the editor simply uploads the image using the Uploader button, then the media manager never opens and the validation never occurs, leading to potential images without credit metadata.

I understand that the wp.Uploader object handles the upload. I have tried to link to various events (success, reset, complete ) but none fire when used in the js. eg.

    wp.Uploader.queue.on('init', function() {
        console.log('Upload init!');
    });
    wp.Uploader.queue.on('progress', function() {
        console.log('Upload progress!');
    });
    wp.Uploader.queue.on('success', function() {
        console.log('Upload success!');
    });
    wp.Uploader.queue.on('complete', function() {
        console.log('Upload complete!');
    });
    wp.Uploader.queue.on('FileUploaded', function() {
        console.log('Upload FileUploaded!');
    });
    wp.Uploader.queue.on('reset', function() {
        console.log('Upload reset!');
    });

Is the above possible? It can be the default behaviour for all upload events. A last resort could be to hack the css and hide the upload button fully but that seems clunky at he least.

enter image description here

Thanks!

0
kujain 4 months 0 Answers 11 views 0

Leave an answer