Skip to content

Commit c0b392f

Browse files
Address feedback for new function
1 parent 04a2e5a commit c0b392f

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

plugins/webp-uploads/helper.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,19 @@ function webp_uploads_get_mime_type_image( int $attachment_id, string $src, stri
479479
*
480480
* @since n.e.x.t
481481
*
482-
* @param string $file The path to the file.
483482
* @param int $attachment_id The attachment ID.
483+
* @param string $file Optional. The path to the file.
484484
* @return string The MIME type of the file, or an empty string if not found.
485485
*/
486-
function webp_uploads_get_file_mime_type( string $file, int $attachment_id ): string {
486+
function webp_uploads_get_attachment_file_mime_type( int $attachment_id, string $file = '' ): string {
487+
if ( '' === $file ) {
488+
$file = get_attached_file( $attachment_id, true );
489+
// File does not exist.
490+
if ( false === $file || ! file_exists( $file ) ) {
491+
return '';
492+
}
493+
}
494+
487495
/*
488496
* We need to get the MIME type ideally from the file, as WordPress Core may have already altered it.
489497
* The post MIME type is typically not updated during that process.

plugins/webp-uploads/hooks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function webp_uploads_create_sources_property( array $metadata, int $attachment_
5858
return $metadata;
5959
}
6060

61-
$mime_type = webp_uploads_get_file_mime_type( $file, $attachment_id );
61+
$mime_type = webp_uploads_get_attachment_file_mime_type( $attachment_id, $file );
6262
if ( '' === $mime_type ) {
6363
return $metadata;
6464
}

plugins/webp-uploads/picture-element.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@ function webp_uploads_wrap_image_in_picture( string $image, string $context, int
2323
return $image;
2424
}
2525

26-
$file = get_attached_file( $attachment_id, true );
27-
// File does not exist.
28-
if ( false === $file || ! file_exists( $file ) ) {
29-
return $image;
30-
}
31-
32-
$original_file_mime_type = webp_uploads_get_file_mime_type( $file, $attachment_id );
26+
$original_file_mime_type = webp_uploads_get_attachment_file_mime_type( $attachment_id );
3327
if ( '' === $original_file_mime_type ) {
3428
return $image;
3529
}

0 commit comments

Comments
 (0)