Make WordPress Core

Changeset 59855


Ignore:
Timestamp:
02/21/2025 08:23:34 PM (20 months ago)
Author:
joedolson
Message:

Media: Support generating filenames without a suffix.

Add support handling an empty string in the $suffix parameter that allows a file name to be generated with no suffix added. This makes it possible to avoid adding irrelevant suffixes in cases like converting image formats.

Props azaozz, debarghyabanerjee, joedolson.
See #62359.
Fixes #62385.

File:
1 edited

Legend:

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

    r59473 r59855  
    434434         *
    435435         * @since 3.5.0
     436         * @since 6.8.0 Passing an empty string as $suffix will now omit the suffix from the generated filename.
    436437         *
    437438         * @param string $suffix
    … …  
    441442         */
    442443        public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) {
    443                 // $suffix will be appended to the destination filename, just before the extension.
    444                 if ( ! $suffix ) {
    445                         $suffix = $this->get_suffix();
     444                // If not empty the $suffix will be appended to the destination filename, just before the extension.
     445                if ( $suffix ) {
     446                        $suffix = '-' . $suffix;
     447                } elseif ( '' !== $suffix ) {
     448                        $suffix = '-' . $this->get_suffix();
    446449                }
    447450
    … …  
    463466                }
    464467
    465                 return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}";
     468                return trailingslashit( $dir ) . "{$name}{$suffix}.{$new_ext}";
    466469        }
    467470
Note: See TracChangeset for help on using the changeset viewer.