Filter hook 'pre_wp_unique_filename_file_list'

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

View Source

pre_wp_unique_filename_file_list

Filter Hook
Description
Filters the file list used for calculating a unique filename for a newly added file. Returning an array from the filter will effectively short-circuit retrieval from the filesystem and return the passed value instead.

Hook Information

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

Hook Parameters

Type Name Description
array|null $files The list of files to use for filename comparisons. Default null (to retrieve the list from the filesystem).
string $dir The directory for the new file.
string $filename The proposed filename for the new file.

Usage Examples

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

function my_custom_filter($files, $dir, $filename) {
    // Your custom filtering logic here
    return $files;
}

Source Code Context

wp-includes/functions.php:2673 - How this hook is used in WordPress core
<?php
2668  			 * @param array|null $files    The list of files to use for filename comparisons.
2669  			 *                             Default null (to retrieve the list from the filesystem).
2670  			 * @param string     $dir      The directory for the new file.
2671  			 * @param string     $filename The proposed filename for the new file.
2672  			 */
2673  			$files = apply_filters( 'pre_wp_unique_filename_file_list', null, $dir, $filename );
2674  
2675  			if ( null === $files ) {
2676  				// List of all files and directories contained in $dir.
2677  				$files = @scandir( $dir );
2678  			}

PHP Documentation

<?php
/**
			 * Filters the file list used for calculating a unique filename for a newly added file.
			 *
			 * Returning an array from the filter will effectively short-circuit retrieval
			 * from the filesystem and return the passed value instead.
			 *
			 * @since 5.5.0
			 *
			 * @param array|null $files    The list of files to use for filename comparisons.
			 *                             Default null (to retrieve the list from the filesystem).
			 * @param string     $dir      The directory for the new file.
			 * @param string     $filename The proposed filename for the new file.
			 */
Quick Info
  • Hook Type: Filter
  • Parameters: 3
  • File: wp-includes/functions.php
Related Hooks

Related hooks will be displayed here in future updates.