Created
August 27, 2013 08:35
-
-
Save jrobinsonc/6351115 to your computer and use it in GitHub Desktop.
Regenerate thumbnails in WordPress.
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 | |
function regenerateThumbnails() | |
{ | |
global $wpdb; | |
$images = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'image/%'"); | |
foreach ($images as $image) | |
{ | |
$id = $image->ID; | |
$fullsizepath = get_attached_file($id); | |
if (false === $fullsizepath || !file_exists($fullsizepath)) | |
return; | |
require_once(ABSPATH . 'wp-admin/includes/image.php'); | |
if (wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $fullsizepath))) | |
return true; | |
else | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment