Media: In `wp_unique_filename()`, use explicit type casting when incrementing `$number`.

This prevents the "non-numeric value encountered" warning in PHP 7.1, caused by trying to increment an empty string on the first loop iteration.

Props drrobotnik for initial patch.
Merges [40039] to the 4.7 branch.
Fixes #39774.
Built from https://develop.svn.wordpress.org/branches/4.7@40075


git-svn-id: http://core.svn.wordpress.org/branches/4.7@40012 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2017-02-17 21:24:35 +00:00
parent 297220b740
commit c884f781e1
2 changed files with 6 additions and 4 deletions

View File

@ -2074,7 +2074,7 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null )
// Check for both lower and upper case extension or image sub-sizes may be overwritten. // Check for both lower and upper case extension or image sub-sizes may be overwritten.
while ( file_exists($dir . "/$filename") || file_exists($dir . "/$filename2") ) { while ( file_exists($dir . "/$filename") || file_exists($dir . "/$filename2") ) {
$new_number = $number + 1; $new_number = (int) $number + 1;
$filename = str_replace( array( "-$number$ext", "$number$ext" ), "-$new_number$ext", $filename ); $filename = str_replace( array( "-$number$ext", "$number$ext" ), "-$new_number$ext", $filename );
$filename2 = str_replace( array( "-$number$ext2", "$number$ext2" ), "-$new_number$ext2", $filename2 ); $filename2 = str_replace( array( "-$number$ext2", "$number$ext2" ), "-$new_number$ext2", $filename2 );
$number = $new_number; $number = $new_number;
@ -2094,11 +2094,13 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null )
} }
while ( file_exists( $dir . "/$filename" ) ) { while ( file_exists( $dir . "/$filename" ) ) {
$new_number = (int) $number + 1;
if ( '' == "$number$ext" ) { if ( '' == "$number$ext" ) {
$filename = "$filename-" . ++$number; $filename = "$filename-" . $new_number;
} else { } else {
$filename = str_replace( array( "-$number$ext", "$number$ext" ), "-" . ++$number . $ext, $filename ); $filename = str_replace( array( "-$number$ext", "$number$ext" ), "-" . $new_number . $ext, $filename );
} }
$number = $new_number;
} }
} }

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.7.3-alpha-40071'; $wp_version = '4.7.3-alpha-40075';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.