Filter hook 'image_editor_output_format'
in WP Core File wp-includes/functions.php at line 2710
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.
Occurrences
Filename |
Line Number |
wp-includes/functions.php |
2710 |
wp-includes/class-wp-image-editor.php |
388 |
wp-includes/media.php |
4064 |
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. $files = apply_filters( 'pre_wp_unique_filename_file_list', null, $dir, $filename ); if ( null === $files ) { // List of all files and directories contained in $dir. $files = @scandir( $dir ); } if ( ! empty( $files ) ) { // Remove "dot" dirs. $files = array_diff( $files, array( '.', '..' ) ); } if ( ! empty( $files ) ) { $count = count( $files ); /* Ensure this never goes into infinite loop as it uses pathinfo() and regex in the check, but string replacement for the changes. $i = 0; while ( $i <= $count && _wp_check_existing_file_names( $filename, $files ) ) { $new_number = (int) $number + 1; // If $ext is uppercase it was replaced with the lowercase version after the previous loop. $filename = str_replace( array( "-{$number}{$lc_ext}", "{$number}{$lc_ext}" ), "-{$new_number}{$lc_ext}", $filename ); $number = $new_number; ++$i; } } } /* Check if an image will be converted after uploading or some existing image sub-size file names may conflict when regenerated. If yes, ensure the new file name will be unique and will produce unique sub-sizes. |
PHP Doc
/**
* 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.
*/
$files = apply_filters( 'pre_wp_unique_filename_file_list', null, $dir, $filename );
if ( null === $files ) {
// List of all files and directories contained in $dir.
$files = @scandir( $dir );
}
if ( ! empty( $files ) ) {
// Remove "dot" dirs.
$files = array_diff( $files, array( '.', '..' ) );
}
if ( ! empty( $files ) ) {
$count = count( $files );
/*
* Ensure this never goes into infinite loop as it uses pathinfo() and regex in the check,
* but string replacement for the changes.
*/
$i = 0;
while ( $i <= $count && _wp_check_existing_file_names( $filename, $files ) ) {
$new_number = (int) $number + 1;
// If $ext is uppercase it was replaced with the lowercase version after the previous loop.
$filename = str_replace(
array( "-{$number}{$lc_ext}", "{$number}{$lc_ext}" ),
"-{$new_number}{$lc_ext}",
$filename
);
$number = $new_number;
++$i;
}
}
}
/*
* Check if an image will be converted after uploading or some existing image sub-size file names may conflict
* when regenerated. If yes, ensure the new file name will be unique and will produce unique sub-sizes.
*/