Make WordPress Core


Ignore:
Timestamp:
03/02/2025 06:53:33 PM (18 months ago)
Author:
joedolson
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/image.php

    r59845 r59897  
    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();
Note: See TracChangeset for help on using the changeset viewer.