Created
February 19, 2020 13:25
-
-
Save PatelUtkarsh/fddfc320af3e7fa5b3c745eaaf1c568f to your computer and use it in GitHub Desktop.
Refresh WordPress media library images - useful when editors are uploading image via 3rd party tool using REST API - Example: Mediawires so editor do not need to reload page to get new images on existing article.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery( document ).ready( function () { | |
// Refresh media library each time on click of add media. | |
if ( wp.media ) { | |
wp.media.view.Modal.prototype.on( 'open', function () { | |
if ( wp.media.frame.content.get() !== null ) { | |
// this forces a refresh of the content. | |
wp.media.frame.content.get().collection._requery( true ); | |
} | |
} ); | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment