Skip to content

Instantly share code, notes, and snippets.

@PatelUtkarsh
Created February 19, 2020 13:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatelUtkarsh/fddfc320af3e7fa5b3c745eaaf1c568f to your computer and use it in GitHub Desktop.
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.
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