sewpafly / post-thumbnail-editor

Wordpress Plugin to manually edit post thumbnails
http://wordpress.org/extend/plugins/post-thumbnail-editor/
32 stars 18 forks source link

Add file suffix option for CDNs #42

Closed sewpafly closed 11 years ago

sewpafly commented 12 years ago

I have had a bit of problems with the plugin while using it on a site with origin-pull cdn. The generated thumb file name remaining the same as the original, it did not get pulled by the CDN nodes, and instead the old one was still being served. So I looked into the way WP does for the edited images and I am suggesting this small change: adding a suffix to the image or perhaps adding a timestamp.

Thanks and looking forward on your opinion, Mile

/*
 * ================
 * Get the filename
 * ================
 * See image_resize function in wp-includes/media.php to follow the same conventions
 *  - Check if the file exists
 */
function pte_generate_filename( $file, $w, $h ){
        $info   = pathinfo( $file );
        $ext    = $info['extension'];
        $name   = wp_basename( $file, ".$ext" );
        $suffix = "{$w}x{$h}".'-pte'; // or .time()
        //print_r( compact( "file", "info", "ext", "name", "suffix" ) );
        return "{$name}-{$suffix}.{$ext}";
}
sewpafly commented 11 years ago

Fixed @ 3429aba42d254d40c175a709c2e2b5ef0a2d3673