WP_Image_Editor::generate_filename
Builds an output filename based on current file, and adding proper suffix
Метод класса: WP_Image_Editor{}
Хуков нет.
Возвращает
Строку. filename
Использование
$WP_Image_Editor = new WP_Image_Editor(); $WP_Image_Editor->generate_filename( $suffix, $dest_path, $extension );
- $suffix(строка)
- .
По умолчанию:null - $dest_path(строка)
- .
По умолчанию:null - $extension(строка)
- .
По умолчанию:null
Список изменений
| С версии 3.5.0 | Введена. |
| С версии 6.8.0 | Passing an empty string as $suffix will now omit the suffix from the generated filename. |
Код WP_Image_Editor::generate_filename() WP Image Editor::generate filename WP 6.9.1
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}";
}