mirror of
https://github.com/WordPress/WordPress.git
synced 2025-03-09 07:00:01 +00:00
Upload: Introduce pre_wp_unique_filename_file_list
filter to allow for short-circuiting the scandir()
call in wp_unique_filename()
.
This allows plugins to override the file fetching behavior to provide performance improvements for large directories. Props joehoyle. Fixes #50587. Built from https://develop.svn.wordpress.org/trunk@48369 git-svn-id: http://core.svn.wordpress.org/trunk@48138 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
afa6bb4f1a
commit
82d9974f8c
@ -2533,8 +2533,25 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null )
|
||||
|
||||
// The (resized) image files would have name and extension, and will be in the uploads dir.
|
||||
if ( $name && $ext && @is_dir( $dir ) && false !== strpos( $dir, $upload_dir['basedir'] ) ) {
|
||||
// List of all files and directories contained in $dir.
|
||||
$files = @scandir( $dir );
|
||||
/**
|
||||
* 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.
|
||||
|
@ -13,7 +13,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.5-alpha-48368';
|
||||
$wp_version = '5.5-alpha-48369';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
x
Reference in New Issue
Block a user