wp_unique_filename filter-hookWP 4.5.0

Filters the result when generating a unique file name.

Usage

add_filter( 'wp_unique_filename', 'wp_kama_unique_filename_filter', 10, 6 );

/**
 * Function for `wp_unique_filename` filter-hook.
 * 
 * @param string        $filename                 Unique file name.
 * @param string        $ext                      File extension. Example: ".png".
 * @param string        $dir                      Directory path.
 * @param callable|null $unique_filename_callback Callback function that generates the unique file name.
 * @param string[]      $alt_filenames            Array of alternate file names that were checked for collisions.
 * @param int|string    $number                   The highest number that was used to make the file name unique or an empty string if unused.
 *
 * @return string
 */
function wp_kama_unique_filename_filter( $filename, $ext, $dir, $unique_filename_callback, $alt_filenames, $number ){

	// filter...
	return $filename;
}
$filename(string)
Unique file name.
$ext(string)
File extension. Example: ".png".
$dir(string)
Directory path.
$unique_filename_callback(callable|null)
Callback function that generates the unique file name.
$alt_filenames(string[])
Array of alternate file names that were checked for collisions.
$number(int|string)
The highest number that was used to make the file name unique or an empty string if unused.

Changelog

Since 4.5.0 Introduced.
Since 5.8.1 The $alt_filenames and $number parameters were added.

Where the hook is called

wp_unique_filename()
wp_unique_filename
wp-includes/functions.php 2765
return apply_filters( 'wp_unique_filename', $filename, $ext, $dir, $unique_filename_callback, $alt_filenames, $number );

Where the hook is used in WordPress

Usage not found.