diff --git a/src/wp-includes/class-wp-image-editor.php b/src/wp-includes/class-wp-image-editor.php index f9f58fcd50..da7f4082ce 100644 --- a/src/wp-includes/class-wp-image-editor.php +++ b/src/wp-includes/class-wp-image-editor.php @@ -433,6 +433,7 @@ abstract class WP_Image_Editor { * Builds an output filename based on current file, and adding proper suffix * * @since 3.5.0 + * @since 6.8.0 Passing an empty string as $suffix will now omit the suffix from the generated filename. * * @param string $suffix * @param string $dest_path @@ -440,9 +441,11 @@ abstract class WP_Image_Editor { * @return string filename */ public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) { - // $suffix will be appended to the destination filename, just before the extension. - if ( ! $suffix ) { - $suffix = $this->get_suffix(); + // If not empty the $suffix will be appended to the destination filename, just before the extension. + if ( $suffix ) { + $suffix = '-' . $suffix; + } elseif ( '' !== $suffix ) { + $suffix = '-' . $this->get_suffix(); } $dir = pathinfo( $this->file, PATHINFO_DIRNAME ); @@ -462,7 +465,7 @@ abstract class WP_Image_Editor { } } - return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}"; + return trailingslashit( $dir ) . "{$name}{$suffix}.{$new_ext}"; } /**