Return to Snippet

Revision: 71742
at March 6, 2017 21:24 by ginoplusio


Initial Code
include 'wp-load.php';
include 'wp-admin/includes/image.php';
     
if ( !current_user_can( 'edit_others_pages' )) die("Not authorized.");
$attachments = $wpdb->get_results("select * from wp_posts where post_mime_type='application/pdf'");
if ($attachments) {
    foreach ($attachments as $attachment) {
        $filename = str_replace("http://".$_SERVER['HTTP_HOST'], $_SERVER['DOCUMENT_ROOT'], $attachment->guid);
        echo $filename."<br/>\n";
        $metadata = wp_generate_attachment_metadata($attachment->ID, $filename);
        wp_update_attachment_metadata($attachment->ID, $metadata);
    }
}

Initial URL
http://www.barattalo.it/wordpress/fix-pdf-preview-images-wordpress-4-7/

Initial Description
From WordPress 4.7 when you upload a PDF it generates jpg previews. All pdf will remain without previews, or you can use this script to generate previews.

Initial Title
Generate all old PDF preview images in WordPress

Initial Tags
wordpress

Initial Language
PHP