Skip to content

Commit

Permalink
Fix get attachment by filesize in WP Utils Helpers (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
irshadahmad21 authored Aug 6, 2024
1 parent 5192205 commit a825c39
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-bees-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wptelegram": patch
---

Fixed the issue of scaled image being preferred over original image
5 changes: 5 additions & 0 deletions .changeset/tall-pugs-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wpsocio/wp-utils": patch
---

Fixed get attachment by filesize to return original image if within limits
7 changes: 7 additions & 0 deletions packages/php/wp-utils/src/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,13 @@ public static function get_attachment_by_filesize( $id, $filesize, $return = 'ur
return $path;
}

$original_image_path = function_exists( 'wp_get_original_image_path' ) ? wp_get_original_image_path( $id ) : null;

// If the original image is less than the limit.
if ( $original_image_path && is_readable( $original_image_path ) && filesize( $original_image_path ) <= $filesize ) {
return 'url' === $return ? wp_get_original_image_url( $id ) : $original_image_path;
}

$meta = wp_get_attachment_metadata( $id );

// For WP < 6.0.
Expand Down

0 comments on commit a825c39

Please sign in to comment.