From 053733f8c01edd1881c33ca917a3c0f48a1af6cb Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 15 Jan 2016 09:38:30 +0000 Subject: [PATCH] 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 --- src/wp-includes/functions.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index db38c6d65d..3525712071 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -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 ); } /**