WordPress.org

Make WordPress Core

Changeset 40075


Ignore:
Timestamp:
02/17/2017 09:23:52 PM (15 months ago)
Author:
SergeyBiryukov
Message:

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.

Location:
branches/4.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

  • branches/4.7/src/wp-includes/functions.php

    r39851 r40075  
    20752075            // Check for both lower and upper case extension or image sub-sizes may be overwritten.
    20762076            while ( file_exists($dir . "/$filename") || file_exists($dir . "/$filename2") ) {
    2077                 $new_number = $number + 1;
     2077                $new_number = (int) $number + 1;
    20782078                $filename = str_replace( array( "-$number$ext", "$number$ext" ), "-$new_number$ext", $filename );
    20792079                $filename2 = str_replace( array( "-$number$ext2", "$number$ext2" ), "-$new_number$ext2", $filename2 );
     
    20952095
    20962096        while ( file_exists( $dir . "/$filename" ) ) {
     2097            $new_number = (int) $number + 1;
    20972098            if ( '' == "$number$ext" ) {
    2098                 $filename = "$filename-" . ++$number;
     2099                $filename = "$filename-" . $new_number;
    20992100            } else {
    2100                 $filename = str_replace( array( "-$number$ext", "$number$ext" ), "-" . ++$number . $ext, $filename );
     2101                $filename = str_replace( array( "-$number$ext", "$number$ext" ), "-" . $new_number . $ext, $filename );
    21012102            }
     2103            $number = $new_number;
    21022104        }
    21032105    }
Note: See TracChangeset for help on using the changeset viewer.