Make WordPress Core

Ticket #21453: append.hyphen.wp.unique.filename.21453.diff

File append.hyphen.wp.unique.filename.21453.diff, 1.3 KB (added by mikejolley, 10 years ago)

Patch to append hyphens e.g. IMAGE-1.jpg instead of IMAGE1.jpg

  • wp-includes/functions.php

    diff --git wp-includes/functions.php wp-includes/functions.php
    index aea813b..13aa3b7 100644
    function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) 
    17051705                        // check for both lower and upper case extension or image sub-sizes may be overwritten
    17061706                        while ( file_exists($dir . "/$filename") || file_exists($dir . "/$filename2") ) {
    17071707                                $new_number = $number + 1;
    1708                                 $filename = str_replace( "$number$ext", "$new_number$ext", $filename );
    1709                                 $filename2 = str_replace( "$number$ext2", "$new_number$ext2", $filename2 );
     1708                                $filename = str_replace( array( "-$number$ext", "$number$ext" ), "-$new_number$ext", $filename );
     1709                                $filename2 = str_replace( array( "-$number$ext2", "$number$ext2" ), "-$new_number$ext2", $filename2 );
    17101710                                $number = $new_number;
    17111711                        }
    17121712                        return $filename2;
    function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) 
    17141714
    17151715                while ( file_exists( $dir . "/$filename" ) ) {
    17161716                        if ( '' == "$number$ext" )
    1717                                 $filename = $filename . ++$number . $ext;
    1718                         else
    1719                                 $filename = str_replace( "$number$ext", ++$number . $ext, $filename );
     1717                                $filename = "$filename-" . ++$number;
     1718                        else 
     1719                                $filename = str_replace( array( "-$number$ext", "$number$ext" ), "-" . ++$number . $ext, $filename );
    17201720                }
    17211721        }
    17221722