Guest User

Untitled

a guest
Dec 7th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. function replace_uploaded_image($image_data) {
  2. // if there is no large image : return
  3. if (!isset($image_data['sizes']['large'])) return $image_data;
  4.  
  5. // paths to the uploaded image and the large image
  6. $upload_dir = wp_upload_dir();
  7. $uploaded_image_location = $upload_dir['basedir'] . '/' .$image_data['file'];
  8. $large_image_location = $upload_dir['path'] . '/'.$image_data['sizes']['large']['file'];
  9.  
  10. // delete the uploaded image
  11. unlink($uploaded_image_location);
  12.  
  13. // rename the large image
  14. rename($large_image_location,$uploaded_image_location);
  15.  
  16. // update image metadata and return them
  17. $image_data['width'] = $image_data['sizes']['large']['width'];
  18. $image_data['height'] = $image_data['sizes']['large']['height'];
  19. unset($image_data['sizes']['large']);
  20.  
  21. return $image_data;
  22. }
  23. add_filter('wp_generate_attachment_metadata','replace_uploaded_image');
Add Comment
Please, Sign In to add comment