[wp-trac] [WordPress Trac] #48974: -1 being added to image uploads with Version 5.3.1

WordPress Trac noreply at wordpress.org
Sat Dec 14 21:55:03 UTC 2019


#48974: -1 being added to image uploads with Version 5.3.1
-------------------------------+------------------------------
 Reporter:  neotrope           |       Owner:  (none)
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  General            |     Version:  5.3.1
 Severity:  normal             |  Resolution:
 Keywords:  needs-patch close  |     Focuses:
-------------------------------+------------------------------

Comment (by pbiron):

 Replying to [comment:6 neotrope]:
 > sample code to disable this new 'feature' would be highly appreciated by
 anyone viewing this.
 > TIA.
 {{{#!php
 <?php
 add_filter( 'wp_unique_filename', 'my_ununique_filename', 10, 4 );

 function my_ununique_filename( $filename, $ext, $dir,
 $unique_filename_callback ) {
         $esc_ext = preg_quote( $ext );

         if ( 1 === preg_match( "/\d+x\d+-\d{$esc_ext}\$/", $filename ) ) {
                 if ( ! file_exists( "{$dir}/{$filename}" ) ) {
                         $filename = preg_replace( "/-\d{$esc_ext}\$/",
 $ext, $filename );
                 }
         }

         return $filename;
 }
 }}}

 This would mostly return to the pre-5.3.1 behavior.  I say "mostly"
 because, in 5.3, if you were to have the above code in a plugin and
 uploaded `19-1216-iskysoft-christmas19-696x522.jpg` and then uploaded it
 again, the code would cause the 2nd file to overwrite the 1st one...which
 would be different that the 5.3 behavior (since WP <= 5.3 would have added
 -1 to prevent that overwrite).

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48974#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list