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. Built from https://develop.svn.wordpress.org/trunk@59855 git-svn-id: http://core.svn.wordpress.org/trunk@59197 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -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}";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.8-alpha-59854';
|
||||
$wp_version = '6.8-alpha-59855';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
||||
Reference in New Issue
Block a user