Reputation: 94
I'm working on a plugin which will store the main images and thumbnails on a cloud storage system. I've used the wp_get_attachment_url filter to change the destination of the main url, but the attachments then use the same modified path as the main url, which I don't want, as each one needs to be a unique link.
I've tried using the wp_get_attachment_thumb_url to achieve the same result for the thumbs but it never fires at all.
//This works
add_filter( 'wp_get_attachment_url', array( $this, 'wp_get_attachment_url' ), 9, 2 );
//This doesn't
add_filter( 'wp_get_attachment_thumb_url', array( $this, 'wp_get_attachment_thumb_url' ), 20, 2 );
Any suggestions - or have people seen this behaviour?
Upvotes: 0
Views: 601
Reputation: 392
Had the same issue, the wp_get_attachment_thumb_url filter wasn't firing. We had set custom image sizes. if you look at the function code for wp_get_attachment_thumb_url, you will see that it calls image_downsize mid way through the function, and if that function returns an array of sizes it takes the first one to use as the thumbnail and returns it.
So rather than going down in the code block to call the filter you are looking at, it just returns the first result of the image_downsize filter. So I ended up adding a filter for "image_downsize" instead giving it a priority of 1
add_filter( 'image_downsize', function($short_circuit, $attachment_id, $size){
# code to get thumb url here ...
$thumb_url = ...
return array($thumb_url);
}, 1, 2 );
Upvotes: 1