Skip to content

Commit

Permalink
Remove check for wp_get_image_mime()
Browse files Browse the repository at this point in the history
I tried to call get_post() as late as possible, for better performance. But then I saw that wp_get_attachment_url() calls get_post() anyways, so it doesn’t really matter. By moving get_post() further to the top, we can use the post_mime_type property of the attachment instead fo the wp_get_image_mime() function. This seems to work better, because it doesn’t have to use the URL of the image, but a local file path. Using the URL could lead to an error with SSL certificates on localhost.
  • Loading branch information
gchtr committed Mar 9, 2018
1 parent e0dc4c7 commit d03849f
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions lib/Timmy.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public function get_image_sizes_for_ui() {
* the image is an intermediate size. False on failure.
*/
public function filter_image_downsize( $return = false, $attachment_id, $size ) {
// Timber needs the file src as an URL. Checks if ID belongs to an attachment.
// Timber needs the file src as an URL. Also checks if ID belongs to an attachment.
$file_src = wp_get_attachment_url( $attachment_id );

if ( ! $file_src ) {
Expand All @@ -246,7 +246,8 @@ public function filter_image_downsize( $return = false, $attachment_id, $size )
? filter_var( $_POST['action'], FILTER_SANITIZE_STRING )
: false;

$mime_type = wp_get_image_mime( $file_src );
$attachment = get_post( $attachment_id );
$mime_type = $attachment->post_mime_type;

// Bail out if mime type can’t be determined.
if ( ! $mime_type ) {
Expand All @@ -268,17 +269,17 @@ public function filter_image_downsize( $return = false, $attachment_id, $size )
*
* @since 0.13.0
*
* @param bool $ignore Whether to ignore an image size. Default false.
* @param string $mime_type The mime type of the image.
* @param string $size The requested image size.
* @param int $attachment_id The attachment post ID.
* @param string $file_src The file src URL.
* @param bool $ignore Whether to ignore an image size. Default false.
* @param string $mime_type The mime type of the image.
* @param string $size The requested image size.
* @param int $attachment The attachment post.
* @param string $file_src The file src URL.
*/
$ignore = apply_filters( 'timmy/resize/ignore',
$ignore,
$mime_type,
$size,
$attachment_id,
$attachment,
$file_src
);

Expand Down Expand Up @@ -370,8 +371,6 @@ public function filter_image_downsize( $return = false, $attachment_id, $size )
return array( $file_src, 0, 0, false );
}

$attachment = get_post( $attachment_id );

// Sort out which image size we need to take from our own image configuration
if ( ! is_array( $size ) && isset( $img_sizes[ $size ] ) ) {
$img_size = $img_sizes[ $size ];
Expand Down

0 comments on commit d03849f

Please sign in to comment.