Hi,
You can use fr_thumbnails_folder_image_sizes_get_image_sizes_path filter to change the base thumbnail path. Then use fr_thumbnails_folder_image_sizes_get_image_size_url filter to change the thumbnail URL.
Hi!
Thank you so much for your quick response. This is the code I have added, but it doesn’t seem to be working. Can you help me with what I’m doing wrong?
function fr_thumbnails_new_thumbnail_path() {
$new_fr_path = 'https://staging.ibiweb.org/wp-content/uploads/thumbnails/';
return $new_fr_path;
}
add_filter( 'fr_thumbnails_folder_image_sizes_get_image_sizes_path', 'fr_thumbnails_new_thumbnail_path' );
function fr_thumbnails_new_thumbnail_url() {
$new_fr_url = 'https://staging.ibiweb.org/wp-content/uploads/thumbnails/';
return $new_fr_url;
}
add_filter( 'fr_thumbnails_folder_image_sizes_get_image_size_url', 'fr_thumbnails_new_thumbnail_url' );
Thank you so much!
Kari
fr_thumbnails_folder_image_sizes_get_image_sizes_path should return the base thumbnail path on your server. And fr_thumbnails_folder_image_sizes_get_image_size_url should return the URL of the thumbnail image.
/**
* Change the base thumbnail path.
*/
add_filter('fr_thumbnails_folder_image_sizes_get_image_sizes_path', function($base_path) {
$base_path = WP_CONTENT_DIR . '/uploads/thumbnails';
return $base_path;
});
/**
* Change a thumbnail URL.
*/
add_filter('fr_thumbnails_folder_image_sizes_get_image_size_url', function($thumbnail_url, $id, $size) {
$base_path = WP_CONTENT_DIR . '/uploads/thumbnails';
$base_url = WP_CONTENT_URL . '/uploads/thumbnails';
$image_size = image_get_intermediate_size($id, $size);
$thumbnail_url = str_replace($base_path, $base_url, $image_size['path']);
return $thumbnail_url;
}, 10, 3);
Hi! Thank you SO much for your help! That is working perfectly with one exception. It is not working for PDF documents. I see you are checking if it is an image with this code:
// Skip if not an image.
if (!wp_attachment_is_image($id)) {
return $downsize;
}
I’m assuming that’s why it’s not working for PDF documents. Is there any way I can have this work for PDF documents, maybe specify an array of valid file extensions? Thank you so much for your help!
Thanks,
Kari
This plugin only moves thumbnail images. Anything else is left untouched, including PDF.
You will have to do it in the code where you are altering the upload path.
Got it. I’m actually talking about the thumbnails that are created for the PDFs, not the PDF itself. Those are the thumbnails that I need to use and set as a featured image while keeping the PDF in a protected folder. By default, WordPress now creates thumbnails for PDF uploads and I’d love to be able to use them. Right now I have changed the upload path for my ACF field to go to the /s2member-files/ folder and the automatically generated thumbnails are also going there. The idea was to move those thumbnails (but not the PDF) to another folder using your plugin. It is working when I upload a .jpg file to the protected area using my ACF field. The thumbnails are successfully moved to the new location /uploads/thumbnails/s2-member-files. But when I upload a PDF to the protected area, the thumbnails are not moved to the new location. I’m assuming it’s because you’re checking if the file is an image (and .pdf doesn’t pass that test) so the thumbnails are disregarded. Is there a way that we can include .pdf as part of that test so we can get the thumbnails?
Thanks so much for your help,
Kari
Please download and try this version of the plugin. Before installing, please unzip and rename the folder to fr-thumbnails-folder.
Hi!
THANK YOU so much for working on this for me. It is working for all thumbnail sizes except for the primary thumbnail. By default, that file is named filename-pdf.jpg (with no size indication after it). So, for instance:
PDF file uploaded:
Test-20.pdf
Thumbs:
Test-20-pdf.jpg (primary)
Test-20-pdf-150×150.jpg
Test-20-pdf-300×169.jpg
Test-20-pdf-800×450.jpg and so on.
Is there a way to also include that primary file? I’m not sure how that’s different than the other thumbnails and why it wasn’t included in your move?
Thanks,
Kari
I’m sorry, I can’t help you with that. The primary image is not included because WordPress treats it like an original image, not a thumbnail.
Got it. That makes sense. Thank you so much for your help on this and for spending time updating the plugin to work with PDF thumbnails. Your plugin is working great and doing exactly what I need!