Make WordPress Core

Changeset 48369


Ignore:
Timestamp:
07/07/2020 10:18:25 AM (5 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r48368 r48369  
    25342534        // The (resized) image files would have name and extension, and will be in the uploads dir.
    25352535        if ( $name && $ext && @is_dir( $dir ) && false !== strpos( $dir, $upload_dir['basedir'] ) ) {
    2536             // List of all files and directories contained in $dir.
    2537             $files = @scandir( $dir );
     2536            /**
     2537             * Filters the file list used for calculating a unique filename for a newly added file.
     2538             *
     2539             * Returning an array from the filter will effectively short-circuit retrieval
     2540             * from the filesystem and return the passed value instead.
     2541             *
     2542             * @since 5.5.0
     2543             *
     2544             * @param array|null $files    The list of files to use for filename comparisons.
     2545             *                             Default null (to retrieve the list from the filesystem).
     2546             * @param string     $dir      The directory for the new file.
     2547             * @param string     $filename The proposed filename for the new file.
     2548             */
     2549            $files = apply_filters( 'pre_wp_unique_filename_file_list', null, $dir, $filename );
     2550
     2551            if ( null === $files ) {
     2552                // List of all files and directories contained in $dir.
     2553                $files = @scandir( $dir );
     2554            }
    25382555
    25392556            if ( ! empty( $files ) ) {
Note: See TracChangeset for help on using the changeset viewer.