Skip to content

Commit 165d803

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@59855 602fd350-edb4-49c9-b593-d223f7449a82
1 parent b8f28f9 commit 165d803

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/wp-includes/class-wp-image-editor.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,16 +433,19 @@ protected function get_output_format( $filename = null, $mime_type = null ) {
433433
* Builds an output filename based on current file, and adding proper suffix
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
438439
* @param string $dest_path
439440
* @param string $extension
440441
* @return string filename
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

448451
$dir = pathinfo( $this->file, PATHINFO_DIRNAME );
@@ -462,7 +465,7 @@ public function generate_filename( $suffix = null, $dest_path = null, $extension
462465
}
463466
}
464467

465-
return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}";
468+
return trailingslashit( $dir ) . "{$name}{$suffix}.{$new_ext}";
466469
}
467470

468471
/**

0 commit comments

Comments
 (0)