Support » Plugin: Auto Post Thumbnail » Fix for bug when URL has no image extension

  • I noticed that the plugin stopped working when a feed started using a CDN service which strips extensions. A fix for this is to inspect the EXIF data instead of relying on the file extension.

    Here’s the fix:

    371     // Get the file type. Must to use it as a post thumbnail.
    372     //$wp_filetype = wp_check_filetype( $filename, $mimes );
    373 $image_type = exif_imagetype($new_file);
    374 
    375 switch($image_type) {
    376         case IMAGETYPE_GIF:
    377                 $wp_filetype['type'] = 'image/gif';
    378                 $wp_filetype['ext'] = 'gif';
    379                 break;
    380         case IMAGETYPE_JPEG:
    381                 $wp_filetype['type'] = 'image/jpeg';
    382                 $wp_filetype['ext'] = 'jpeg';
    383                 break;
    384         case IMAGETYPE_PNG:
    385                 $wp_filetype['type'] = 'image/png';
    386                 $wp_filetype['ext'] = 'png';
    387                 break;
    388 }
    389 
    390     extract( $wp_filetype );
    

    You can modify this code to set $type and $ext and ignore the extract command. Actually, $ext is not used, so that can be ignored as well.

  • The topic ‘Fix for bug when URL has no image extension’ is closed to new replies.