WordPress.org

Make WordPress Core

Opened 7 months ago

Last modified 12 days ago

#48974 reopened defect (bug)

-1 being added to image uploads with Version 5.3.1 (and 5.4.2)

Reported by: neotrope Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.3.1
Component: Media Keywords:
Focuses: Cc:

Description

Hi, as of the Friday update my image uploads are geting '-1' added to each image

e.g.,
19-1216-iskysoft-christmas19-696x522-1.jpg

19-1216-jla-special-needs-696x522-1.jpg

Change History (18)

#1 @neotrope
7 months ago

Even auto-generated images using an imagemagick script to generate image from first image in post, are doing the same thing for a virgin image file ...

19-1212s2p-EPIC-Mat-Presutti-696x522-1.jpg

#2 @pbiron
7 months ago

  • Keywords close added

Hi @neotrope, welcome to WordPress Trac.

That behavior is indeed new in WP 5.3.1.

You can read more about the reasons behind the change at #42437.

The short explanation is as follows:

  1. WP has long automatically added -1, -2, -3, etc when you upload a file with the same name multiple times (e.g., suppose you uploaded my-image.jpg yesterday, when you upload another file named my-image.jpg tomorrow, WP renames the new file to my-image-1.jpg). It does this for any file type, not just images.
  2. when WP creates the various "sub-sizes" of image files, it has long added the dimensions of the sub-size to the filename, e.g., when creating the default "thumbnail" filesize for my-image.jpg, WP creates my-image-150x150.jpg.
  3. however, because of number 2, prior to the change in WP 5.3.1, if after uploading my-image.jpg, you then uploaded my-image-150x150.jpg that would overwrite the previously created "thumbnail" for my-image.jpg. Similarly, if you first uploaded my-image-150x150.jpg and then later uploaded my-image.jpg the "thumbnail" for my-image.jpg would overwrite the original image my-image-150x150.jpg.

So, this change is to actually protect uploaded image files and WP-generated sub-size image files from overwriting each other.

#3 @neotrope
7 months ago

Hi

well, we need this with a disable option under 'settings . images' or a plugin hook to remove this 'fheature' as it breaks our versioning and also messes with stuff where file names should end with the dimensions for things like pagespeed image rewrites. It makes it problematic on a site with thousands of images when doing backups as now we have local copies without the -1 and then copies with 1. So in a server crash situation or database corruption without backup; we'd be unable to upload our original images to image folder, as all the image links would be permanwntly broken.

So, this is *not* a useful feature for us.

Similarly - as another example, if a customer logo changes, we can upload new image via FTP to over-write; this would not work as our local images will never have -1 added to them.

So, *PLEASE enable some sort of 'turn it off' option, as those of us with large news portals generation large number of images already 'right sized and optimized' -- the -1 causes numerous issued for us.

Thanks.

Filter hook to disable would be fine, if not other option ... I'm sure I'm not the only publisher vs blogger who will have problems with this. :-)

#4 @pbiron
7 months ago

The change in behavior in 5.3.1 is simply extending the filename uniqueness checks that WP has always done to include a check for uploads that contain "dimension-like" filenames.

But if you need to override that behavior, since WP 4.5.0 there has been the wp_unique_filename filter which you can use in a custom plugin.

#5 follow-up: @neotrope
7 months ago

Right - but the filename is unique to begin with and should not be rewritten as the base file being used inside a post for a newspaper with internal versioning and backup merges, where now we would have duplicate versions of every image.

So, having to use a plugin simply to keep the original filename is incredibly stupid.

No CMS should change the names of original intellectual property files -- this is contrary to good behavior. -1 on the primary image should only be done if in fact there were a duplicate, which we have not had since using WP since 2004.

Hopefully dev team members will rethink this as it's now causing problems on 20 news portals for us.

Really really bad and intrusive move.

We don't need custom file names, we need our image file names to remain what we name them.

Sheesh.

#6 follow-up: @neotrope
7 months ago

sample code to disable this new 'feature' would be highly appreciated by anyone viewing this.
TIA.

#7 in reply to: ↑ 5 @pbiron
7 months ago

Replying to neotrope:

Right - but the filename is unique to begin with and should not be rewritten as the base file being used inside a post for a newspaper with internal versioning and backup merges, where now we would have duplicate versions of every image.

The filename may be unique at the time you upload it (including for the auto-generated sub-sizes that exist at the the time you upload it, but as general purpose software, WP must consider the future...if you were to later change themes to one that defined a sub-size that was 696x522 and then you uploaded an image named 19-1216-iskysoft-christmas19.jpg WP would overwrite the file you originally uploaded as 19-1216-iskysoft-christmas19-696x522.jpg. And while your workflow may prevent that from happening, many WP users do change themes (or activate plugins) define different sub-sizes and then regenerate sub-sizes for existing uploads and were having previously uploaded files overwritten.

So, this change was to solve a problem that real users were having.

So, having to use a plugin simply to keep the original filename is incredibly stupid.

No CMS should change the names of original intellectual property files -- this is contrary to good behavior. -1 on the primary image should only be done if in fact there were a duplicate, which we have not had since using WP since 2004.

As I stated before, WP has (since at least version 2.5.0) sometimes changed the names of original files upon upload to prevent previously (or future) uploaded files from being overwritten.

#8 in reply to: ↑ 6 @pbiron
7 months ago

Replying to neotrope:

sample code to disable this new 'feature' would be highly appreciated by anyone viewing this.
TIA.

<?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).

#9 follow-up: @neotrope
7 months ago

Fantastic. Thanks so much; we have custom theme, using CMS as news publishing platform, not blog posting; and have syndication to other websites, don't use thumbnails, etc. -- this was huge intrusive problem for us; so hopefully an optional toggle on images settings might be considered. I will try this solution, just making custom plugin for it, which is easy-peezie. THANK YOU SO MUCH for the quick fix, I"m about to go on vacation and was not prepared to have to wrangle this issue on 20+ websites where the -1 thing is huge problem for us. THANK YOU!!! :)

And, doh - the one time I didn't read the full changelog. ;-)

#10 in reply to: ↑ 9 @pbiron
7 months ago

  • Resolution set to fixed
  • Status changed from new to closed

Replying to neotrope:

Fantastic. Thanks so much; we have custom theme, using CMS as news publishing platform, not blog posting; and have syndication to other websites, don't use thumbnails, etc. --

By "(we) don't use thumbnails", do you mean have have a plugin that has "unregistered" all sub-sizes? If not, then WP is still creating sub-size files for the built-in defined sub-sizes, even if your theme/content doesn't display them.

this was huge intrusive problem for us; so hopefully an optional toggle on images settings might be considered. I will try this solution, just making custom plugin for it, which is easy-peezie. THANK YOU SO MUCH for the quick fix, I"m about to go on vacation and was not prepared to have to wrangle this issue on 20+ websites where the -1 thing is huge problem for us. THANK YOU!!! :)

Also, just to be clear, the code sample I gave above comes with the usual disclaimer:

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

If you use that code and it causes additional problems then neither myself nor the WordPress project are responsible :-)

I'm going to close this ticket.

#11 @neotrope
7 months ago

Hi, yes; we have been building websites since 1995, using WP since 2004; not newbies. Tons of custom code; not using gutenberg, custom hooks for stuff like 'duplicate post' and custom image usage only "on post" and noplace else. Complex. But this kind of 'out of the blue' thing is kind of bad for our setup. it would be like adding -new-post to end of every post without asking if we needed that. Same idea -actually changing file names we upload is not something one should expect for the original file(s).

THANK YOU. This was a good quick fix for our issue. I'm sure I'm not the only one who will have issue with this, but many likely have not noticed it yet since rolled out Friday. Expect more feedback on this from others on Monday, I'm guessing. But for us, this solved it! #whew :-)

#12 @pbiron
7 months ago

  • Resolution changed from fixed to wontfix

#13 @netweb
6 months ago

  • Milestone Awaiting Review deleted

#14 @SergeyBiryukov
5 months ago

  • Component changed from General to Media
  • Keywords needs-patch close removed

#15 @SergeyBiryukov
5 months ago

#49314 was marked as a duplicate.

#16 @olafeichstaedt
12 days ago

  • Resolution wontfix deleted
  • Status changed from closed to reopened

I stumbled upon this behavior when deploying WP 5.4.2 to the Linux production server. Why "stumbled"? I still develop on XAMPP/Windows (imagick not installed) and this local instance of WP 5.4.2 does not add "-1" and the likes to the name of the uploaded file ... bug or feature?

#17 @olafeichstaedt
12 days ago

... and then there is this: when does the "-1" get added and when not? I just uploaded a bunch of images to the Linux production server and some get the "-1" and some do not. Bug or feature?


#18 @olafeichstaedt
12 days ago

  • Summary changed from -1 being added to image uploads with Version 5.3.1 to -1 being added to image uploads with Version 5.3.1 (and 5.4.2)

... and then some images are present with a whole set of sizes BOTH with and without "-1". That does not seem right. Let me know if I can do anything to reproduce or investigate this issue.

Note: See TracTickets for help on using tickets.