Filesystem API: Add a filter to wp_unique_filename().

Props SergeyBiryukov, MikeHansenMe, johnbillion, swissspidy.
Fixes #19121.

git-svn-id: https://develop.svn.wordpress.org/trunk@36310 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler 2016-01-15 09:38:30 +00:00
parent 44db9bccf4
commit 053733f8c0

View File

@ -2003,7 +2003,18 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null )
$filename2 = str_replace( array( "-$number$ext2", "$number$ext2" ), "-$new_number$ext2", $filename2 );
$number = $new_number;
}
return $filename2;
/**
* Filter the result when generating a unique file name.
*
* @since 4.5.0
*
* @param string $filename Unique file name.
* @param string $ext File extension, eg. ".png".
* @param string $dir Directory path.
* @param callable|null $unique_filename_callback Callback function that generates the unique file name.
*/
return apply_filters( 'wp_unique_filename', $filename2, $ext, $dir, $unique_filename_callback );
}
while ( file_exists( $dir . "/$filename" ) ) {
@ -2015,7 +2026,8 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null )
}
}
return $filename;
/** This filter is documented in wp-includes/functions.php */
return apply_filters( 'wp_unique_filename', $filename, $ext, $dir, $unique_filename_callback );
}
/**