WP_Image_Editor::generate_filename( string $suffix = null, string $dest_path = null, string $extension = null ): string
- Since
- 3.5.0, 6.8.0
- Source
wp-includes/class-wp-image-editor.php:443
Builds an output filename based on current file, and adding proper suffix
Parameters
$suffixstringoptional- Default:
null $dest_pathstringoptional- Default:
null $extensionstringoptional- Default:
null
Return
string- filename
Uses · 4
- wp_basename()i18n-friendly version of basename().
- wp_is_stream()Tests if a given path is a stream URL
- trailingslashit()Appends a trailing slash.
- WP_Image_Editor::get_suffix()Builds and returns proper suffix for file based on height and width.
Source
public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) { // 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 ); $ext = pathinfo( $this->file, PATHINFO_EXTENSION ); $name = wp_basename( $this->file, ".$ext" ); $new_ext = strtolower( $extension ? $extension : $ext ); if ( ! is_null( $dest_path ) ) { if ( ! wp_is_stream( $dest_path ) ) { $_dest_path = realpath( $dest_path ); if ( $_dest_path ) { $dir = $_dest_path; } } else { $dir = $dest_path; } } return trailingslashit( $dir ) . "{$name}{$suffix}.{$new_ext}"; }History
Introduced in 3.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
6.8.0
Passing an empty string as $suffix will now omit the suffix from the generated filename.from the docblock
3.5.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-includes/class-wp-image-editor.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.