Posted By

ginoplusio on 03/06/17


Tagged

wordpress pdf


Versions (?)

Generate all old PDF preview images in WordPress


 / Published in: PHP
 

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

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.

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

Report this snippet  

You need to login to post a comment.