W3cubDocs

/WordPress

WP_Image_Editor::generate_filename( string $suffix = null, string $dest_path = null, string $extension = null )

Builds an output filename based on current file, and adding proper suffix

Description

Parameters

$suffix

(string) (Optional)

Default value: null

$dest_path

(string) (Optional)

Default value: null

$extension

(string) (Optional)

Default value: null

Return

(string) filename

Source

File: wp-includes/class-wp-image-editor.php

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();
		}

		$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 ) && $_dest_path = realpath( $dest_path ) ) {
			$dir = $_dest_path;
		}

		return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}";
	}

Changelog

Version Description
3.5.0 Introduced.

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_image_editor/generate_filename