[wp-trac] [WordPress Trac] #62385: Improve `WP_Image_Editor::generate_filename()` to support generating filenames without a suffix
WordPress Trac
noreply at wordpress.org
Mon Nov 11 22:01:21 UTC 2024
#62385: Improve `WP_Image_Editor::generate_filename()` to support generating
filenames without a suffix
-------------------------+---------------------
Reporter: azaozz | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 6.8
Component: Media | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
-------------------------+---------------------
Comment (by azaozz):
Thinking that the best solution here would be to accept an empty string
for "no suffix". I.e. a
[https://core.trac.wordpress.org/browser/branches/6.7/src/wp-includes
/class-wp-image-editor.php#L434 patch would be something like]:
{{{
if ( $suffix ) {
$suffix = '-' . $suffix;
} elseif ( '' !== $suffix ) {
$suffix = '-' . $this->get_suffix();
}
}}}
instead of:
{{{
if ( ! $suffix ) {
$suffix = $this->get_suffix();
}
}}}
(And the dash will be removed from the returned value:
`"{$name}{$suffix}.{$new_ext}"`.)
Implementing this will change the behavior of `generate_filename()` a
little bit, but thinking the change will be quite insignificant and as far
as I see won't affect existing plugins. Then the current code that was
added in 6.7 in [59379] can be replaced with `$saved = $editor->save(
$editor->generate_filename( '' ) );`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62385#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list