From 16142a461e9b69e9629d36b79e67406177e2e1ef Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 15 Jan 2016 09:39:26 +0000 Subject: [PATCH] Filesystem API: Add a filter to `wp_unique_filename()`. Props SergeyBiryukov, MikeHansenMe, johnbillion, swissspidy. Fixes #19121. Built from https://develop.svn.wordpress.org/trunk@36310 git-svn-id: http://core.svn.wordpress.org/trunk@36277 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 16 ++++++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index db38c6d65d..3525712071 100644 --- a/wp-includes/functions.php +++ b/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 ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 1761d3fff6..1f747fb00c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.5-alpha-36309'; +$wp_version = '4.5-alpha-36310'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.