Skip to content

Commit 1964aec

Browse files
committed
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
1 parent 3e56dfc commit 1964aec

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

src/wp-admin/includes/image.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -339,17 +339,8 @@ function wp_create_image_subsizes( $file, $attachment_id ) {
339339
if ( $scale_down ) {
340340
$saved = $editor->save( $editor->generate_filename( 'scaled' ) );
341341
} elseif ( $convert ) {
342-
/*
343-
* Generate a new file name for the converted image.
344-
*
345-
* As the image file name will be unique due to the changed file extension,
346-
* it does not need a suffix to be unique. However, the generate_filename method
347-
* does not allow for an empty suffix, so the "-converted" suffix is required to
348-
* be added and subsequently removed.
349-
*/
350-
$converted_file_name = $editor->generate_filename( 'converted' );
351-
$converted_file_name = preg_replace( '/(-converted\.)([a-z0-9]+)$/i', '.$2', $converted_file_name );
352-
$saved = $editor->save( $converted_file_name );
342+
// Pass an empty string to avoid adding a suffix to converted file names.
343+
$saved = $editor->save( $editor->generate_filename( '' ) );
353344
} else {
354345
$saved = $editor->save();
355346
}

0 commit comments

Comments
 (0)