wppaste
WordPress

apply_filters( 'wp_unique_filename', string $filename, string $ext, string $dir, callable|null $unique_filename_callback, string[] $alt_filenames, int|string $number )

Since
4.5.0, 5.8.1
Filters the result when generating a unique file name.

Compatibility

WordPress
since 5.8.1
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Parameters

$filenamestring
Unique file name.
$extstring
File extension. Example: ".png".
$dirstring
Directory path.
$unique_filename_callbackcallable|null
Callback function that generates the unique file name.
$alt_filenamesstring[]
Array of alternate file names that were checked for collisions.
$numberint|string
The highest number that was used to make the file name unique or an empty string if unused.

Where this hook fires · 1

  • wp-includes/functions.php:2809wp_unique_filename()

Source code

	 * @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 apply_filters( 'wp_unique_filename', $filename, $ext, $dir, $unique_filename_callback, $alt_filenames, $number );} /** * Helper function to test if each of an array of file names could conflict with existing files. * * @since 5.8.1

Changelog

Introduced in 4.5.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

5.8.1
The $alt_filenames and $number parameters were added.from the docblock
4.5.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, 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.