wp_unique_filename

Filters the result when generating a unique file name.

Description

apply_filters( 'wp_unique_filename', (string) $filename2, (string) $ext, (string) $dir, (string) $unique_filename_callback ); 

Parameters (4)

0. $filename2 (string)
Unique file name.
1. $ext (string)
File extension, eg. .png..
2. $dir (string)
Directory path.
3. $unique_filename_callback (string)
Callback function that generates the unique file name.

Usage

To run the hook, copy the example below.
  1. $filename2 = apply_filters( 'wp_unique_filename', $filename2, $ext, $dir, $unique_filename_callback ); 
  2.  
  3. if ( !empty( $filename2 ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the wp_unique_filename callback 
  2. function filter_wp_unique_filename( $filename2, $ext, $dir, $unique_filename_callback ) { 
  3. // make filter magic happen here... 
  4. return $filename2
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'wp_unique_filename', 'filter_wp_unique_filename', 10, 4 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'wp_unique_filename', 'filter_wp_unique_filename', 10, 4 ); 

Defined (2)

The filter is defined in the following location(s).

/wp-includes/functions.php  
  1. return apply_filters( 'wp_unique_filename', $filename2, $ext, $dir, $unique_filename_callback ); 
  1. return apply_filters( 'wp_unique_filename', $filename2, $ext, $dir, $unique_filename_callback );