• Resolved Jeff Farthing

    (@jfarthing84)


    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

    (@jfarthing84)

    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.