Last active
February 20, 2017 06:46
-
-
Save mdunham/2992b215b1bb6b446bf370e80ffac229 to your computer and use it in GitHub Desktop.
This is was a quick little console script I wrote to help me regenerate the thumbnails of only the posts or in this case products specified.
This file contains 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
// HTML: add the tag: <iframe id="f" src="" width="900" height="600"></iframe> | |
// Then run the following in the console: | |
var | |
// Array of wp_posts ID's that need their thumbnails regenerated | |
ids = ["328921", "326496", "322847", "21967", "16180", "16173"], | |
// Prevent handling the onload event at the wrong time | |
loaded = false, | |
// Begin editting a new product | |
run = function (id) { | |
loaded = false; | |
document.querySelector('#f').setAttribute('src', 'https://yourwebsite.com/wp-admin/post.php?post=' + id + '&action=edit'); | |
}; | |
// The product has loaded begin the regen. | |
document.querySelector('#f').onload = function () { | |
if (loaded) | |
return true; | |
loaded = true; | |
// Click Regnerate Photos | |
document.getElementById('f').contentWindow.document.getElementById('sis_featured_regenerate').click(); | |
// If there are more ID's left to go then wait for the regen to finish first | |
if (ids.length) { | |
console.log(ids.length + ' more to go'); | |
var chk = function () { | |
// If this is blank then the rengeration is not complete | |
if (document.getElementById('f').contentWindow.document.querySelector('div.sis_message').innerText === '') { | |
setTimeout(chk, 500); | |
} else { | |
// Products thumbnails have regenerated run the next id | |
run(ids.pop()); | |
} | |
}; | |
// Check to see if the regeneration has completed | |
setTimeout(chk, 500); | |
} | |
}; | |
// Init | |
run(ids.pop()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment