Created
March 30, 2021 07:49
-
-
Save victormattosvm/a82738594f758f373414c43a80058320 to your computer and use it in GitHub Desktop.
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
<?php | |
/* | |
* CAUTION! | |
* This code will delete all generated thumbnails. Useful if you want to regenerate. | |
* Don't forget to regenerate thumbnails with wp-cli or any plugin. | |
*/ | |
add_action( 'init', 'remove_all_thumbnails' ); | |
function remove_all_thumbnails(){ | |
$attachments = get_posts( array( | |
'post_type' => 'attachment', | |
'posts_per_page' => -1, | |
) ); | |
foreach ($attachments as $attach){ | |
$filePath = get_attached_file($attach->ID); | |
$ext = pathinfo($filePath, PATHINFO_EXTENSION); | |
$dirname = pathinfo($filePath, PATHINFO_DIRNAME); | |
$filename = basename($filePath,".".$ext); | |
foreach (glob("{$dirname}/{$filename}-*") as $delete_file) { | |
unlink($delete_file); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment