Filter hook 'wp_unique_filename'

in WP Core File wp-includes/functions.php at line 2797

View Source

wp_unique_filename

Filter Hook
Description
Filters the result when generating a unique file name.

Hook Information

File Location wp-includes/functions.php View on GitHub
Hook Type Filter
Line Number 2797

Hook Parameters

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

Usage Examples

Basic Usage
<?php
// Hook into wp_unique_filename
add_filter('wp_unique_filename', 'my_custom_filter', 10, 6);

function my_custom_filter($filename, $ext, $dir, $unique_filename_callback, $alt_filenames, $number) {
    // Your custom filtering logic here
    return $filename;
}

Source Code Context

wp-includes/functions.php:2797 - How this hook is used in WordPress core
<?php
2792  	 * @param callable|null $unique_filename_callback Callback function that generates the unique file name.
2793  	 * @param string[]      $alt_filenames            Array of alternate file names that were checked for collisions.
2794  	 * @param int|string    $number                   The highest number that was used to make the file name unique
2795  	 *                                                or an empty string if unused.
2796  	 */
2797  	return apply_filters( 'wp_unique_filename', $filename, $ext, $dir, $unique_filename_callback, $alt_filenames, $number );
2798  }
2799  
2800  /**
2801   * Helper function to test if each of an array of file names could conflict with existing files.
2802   *

PHP Documentation

<?php
/**
	 * Filters the result when generating a unique file name.
	 *
	 * @since 4.5.0
	 * @since 5.8.1 The `$alt_filenames` and `$number` parameters were added.
	 *
	 * @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.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 6
  • File: wp-includes/functions.php
Related Hooks

Related hooks will be displayed here in future updates.