diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 500aa35a0e..4cc62be66d 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -2472,11 +2472,17 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) // Prevent collisions with existing file names that contain dimension-like strings // (whether they are subsizes or originals uploaded prior to #42437). + $upload_dir = wp_get_upload_dir(); // The (resized) image files would have name and extension, and will be in the uploads dir. - if ( @is_dir( $dir ) && $name && $ext ) { - // List of all files and directories contained in $dir (with the "dot" files removed). - $files = array_diff( scandir( $dir ), array( '.', '..' ) ); + if ( $name && $ext && @is_dir( $dir ) && false !== strpos( $dir, $upload_dir['basedir'] ) ) { + // List of all files and directories contained in $dir. + $files = @scandir( $dir ); + + if ( ! empty( $files ) ) { + // Remove "dot" dirs. + $files = array_diff( $files, array( '.', '..' ) ); + } if ( ! empty( $files ) ) { while ( _wp_check_existing_file_names( $filename, $files ) ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 6b69c4910c..86b812d71d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.4-alpha-46964'; +$wp_version = '5.4-alpha-46965'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.