Last active
March 5, 2018 00:27
-
-
Save ivanhoe011/1cea8d5f176d73e2fd5f to your computer and use it in GitHub Desktop.
Resize all thumbs in WP
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
<?php | |
/** | |
* Resize all thumbs in WP when thumbnail settings are updated | |
*/ | |
function update_thumbnails() { | |
set_time_limit(0); // can help if lot of images | |
$attachments = get_children( array('post_type' => 'attachment', 'post_mime_type' => 'image') ); | |
if ( !$attachments ) | |
return; | |
foreach ( $attachments as $id => $attachment ) { | |
$imagedata = wp_get_attachment_metadata($id); | |
$thumbnail = dirname($imagedata['file']) . '/' . $imagedata['sizes']['thumbnail']['file']; | |
if ( file_exists($thumbnail) ) | |
@unlink($thumbnail); | |
wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $imagedata['file'])); | |
} | |
} | |
add_action('update_option_thumbnail_size_w', 'update_thumbnails'); | |
add_action('update_option_thumbnail_size_h', 'update_thumbnails'); | |
add_action('update_option_thumbnail_crop', 'update_thumbnails'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment