From 1964aec6672f10dadffe34acab9ab5376656127c Mon Sep 17 00:00:00 2001 From: Joe Dolson Date: Sun, 2 Mar 2025 18:53:33 +0000 Subject: [PATCH] Media: Simplify file name generation for image conversions. Use the empty string argument in `$editor->save()` added in [59855] to simplify the code used to prevent image format conversions from getting a suffix appended to their file names. Props joedolson, audrasjb, azaozz. See #62385. Fixes #63003. git-svn-id: https://develop.svn.wordpress.org/trunk@59897 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/image.php | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/wp-admin/includes/image.php b/src/wp-admin/includes/image.php index bb70b27787..9fe2471669 100644 --- a/src/wp-admin/includes/image.php +++ b/src/wp-admin/includes/image.php @@ -339,17 +339,8 @@ function wp_create_image_subsizes( $file, $attachment_id ) { if ( $scale_down ) { $saved = $editor->save( $editor->generate_filename( 'scaled' ) ); } elseif ( $convert ) { - /* - * Generate a new file name for the converted image. - * - * As the image file name will be unique due to the changed file extension, - * it does not need a suffix to be unique. However, the generate_filename method - * does not allow for an empty suffix, so the "-converted" suffix is required to - * be added and subsequently removed. - */ - $converted_file_name = $editor->generate_filename( 'converted' ); - $converted_file_name = preg_replace( '/(-converted\.)([a-z0-9]+)$/i', '.$2', $converted_file_name ); - $saved = $editor->save( $converted_file_name ); + // Pass an empty string to avoid adding a suffix to converted file names. + $saved = $editor->save( $editor->generate_filename( '' ) ); } else { $saved = $editor->save(); }