Title: Bug in code
Last modified: May 19, 2017

---

# Bug in code

 *  Resolved [Jeff Farthing](https://wordpress.org/support/users/jfarthing84/)
 * (@jfarthing84)
 * [9 years ago](https://wordpress.org/support/topic/bug-in-code-3/)
 * In the function `apt_generate_post_thumb`, you have the following code:
 *     ```
       //Fix for checking file extensions
       $exts = explode(".",$filename);
       if (count($exts)>2)return null;
       $allowed=get_allowed_mime_types();
       $ext=pathinfo($new_file,PATHINFO_EXTENSION);
       if(!array_key_exists($ext,$allowed))return null;
       ```
   
 * You check if, for instance, `jpg` exists as a key in the array retrieved from`
   get_allowed_mime_types`. The problem is, it doesn’t. The key for the JPEG MIME
   type is `jpg|jpeg|jpe`. Thus, your plugin thinks `jpg` is not supported.
 * Additionally, a few lines later, you do this:
 *     ```
       // Get the file type. Must to use it as a post thumbnail.
       $wp_filetype = wp_check_filetype( $filename, $mimes );
   
       extract( $wp_filetype );
   
       // No file type! No point to proceed further
       if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) ) {
           return null;
       }
       ```
   
 * The function `wp_check_filetype` checks if the extension is valid AND allowed.
   The difference is, it does it properly. You should replace the former broken 
   code with the latter:
 *     ```
       // Get the file type. Must to use it as a post thumbnail.
       $wp_filetype = wp_check_filetype( $filename );
   
       extract( $wp_filetype );
   
       // No file type! No point to proceed further
       if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) ) {
           return null;
       }
   
       file_put_contents($new_file, $file_data);
   
       // Set correct file permissions
       $stat = stat( dirname( $new_file ));
       $perms = $stat['mode'] & 0000666;
       @ chmod( $new_file, $perms );
   
       // Compute the URL
       $url = $uploads['url'] . "/$filename";
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [Jeff Farthing](https://wordpress.org/support/users/jfarthing84/)
 * (@jfarthing84)
 * [8 years, 12 months ago](https://wordpress.org/support/topic/bug-in-code-3/#post-9222074)
 * In case anyone else runs into this problem and doesn’t want to mess around with
   the plugin’s code, here’s a workaround:
 *     ```
       function split_combined_mimes_for_apt( $mime_types ) {
       	foreach ( $mime_types as $regex => $mime_type ) {
       		if ( false !== strpos( $regex, '|' ) ) {
       			$keys = explode( '|', $regex );
       			foreach ( $keys as $key ) {
       				$mime_types[ $key ] = $mime_type;
       			}
       		}
       	}
       	return $mime_types;
       } );
       add_filter( 'mime_types', 'split_combined_mimes_for_apt' );
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Bug in code’ is closed to new replies.

 * ![](https://ps.w.org/auto-post-thumbnail/assets/icon-256x256.gif?rev=3469511)
 * [Auto Featured Image (Auto Post Thumbnail)](https://wordpress.org/plugins/auto-post-thumbnail/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/auto-post-thumbnail/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/auto-post-thumbnail/)
 * [Active Topics](https://wordpress.org/support/plugin/auto-post-thumbnail/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/auto-post-thumbnail/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/auto-post-thumbnail/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [Jeff Farthing](https://wordpress.org/support/users/jfarthing84/)
 * Last activity: [8 years, 12 months ago](https://wordpress.org/support/topic/bug-in-code-3/#post-9222074)
 * Status: resolved