Unpleasant bug with attachments
-
We create pages with lots of attached photos as a galleries and then duplicate them to create a shortened version of the page without texts. So every page on our website exists in two versions.
Recently we found out that free space on our hosing is melting much faster than planned.
It turned out that during page cloning Duplicate Post plugin (v3.2) for some reason creates a duplicate for each photo attached to the post. After that WordPress creates resized version of them and our disk now is full of duplicate photos.We have an old version of our website where Duplicated Post plugin has a version 2.6. That version doesn’t have that bug. Pages duplicated and master photos are used on cloned page as expected. Checkbox “Copy attachments” in plugins settings is checked on both versions of our website.
-
Hi,
this is not a bug, it’s the intended behaviour of the “Attachment” options.
As specified in the Settings page and in the documentation, “Copy attachments” should stay unchecked unless you have very special needs.With “Attachments” unchecked, the links in the original text and the references in custom fields are still preserved as you would do by copying a post “by hand” (choosing images already uploaded in the media selector).
Beware that I recommend sticking to version 3.2 instead of reverting to 2.6, because:
- 2.6 has some serious security flaws
- 2.6 has bugs with a number of common plugins (visual composers among others)
- “Attachments” option in 2.6 is buggy, since it creates duplicate media library entries linking to the same physical files, so if you delete one of those clones you can lose the attachment in the original file.
Can you try unchecking it and see if it works for you?
If it doesn’t, can you explain your use case so we can find a solution?Thanks for reporting!
Hello,
Wow, what a quick response! Thank you!
I’ve tried to uncheck the Copy Attachments option and our shortcode
[gallery columns="1" link="none" size="full"]is no longer works on a new cloned page. It shows ‘No items found’ in editor.
As I understand this is happening because there is no more any attached images to display with that shortcode.Is there any way to keep the original attachments while duplicating a page?
-
This reply was modified 9 years ago by
crypto.
What I didn’t understand yet is why ver 2.6 of the plugin didn’t create a duplicate file of the attachments.
Considering your message above it seems that the 2.6 had a bug with not copying the attachments even with that option turned on. Or, alternatively, it had some other way to keep original attachments instead of copying them.-
This reply was modified 9 years ago by
crypto.
Hi @crypto,
sorry for the delay.I’ll try to explain better what’s happening.
Every attachment, in WordPress, is “made” of two parts: a physical file inside (usually) thewp-content/uploadsfolder, and a post of typeattachmentwhich contains the URL of the physical file. This attachment can have a “normal” post (or page, or whatever) as its parent, and thus be “attached” to it. Or it can be without parent, as it happens when you upload an attachment from theMedia Libraryinstead of from within a post edit screen.
When you use a gallery shortcode like that one, WordPress gets all the attachments attached to the current post and uses their physical files, as long as they are images, to display them somehow. If the post doesn’t have any image attached, the gallery is empty.Enter my plugin, which may or may not copy the attachments of a post.
- with versions up to 2.6, when attachments were copied, only the database entries (the posts of type
attachmenthaving the current post has parent) were cloned, but not the physical files. This meant that you could have many attachments linking to the same physical file, which is wrong because deleting an attachment would have deleted the physical file for every other attachment pointing to that.
But it worked with that shortcode, because the new post had its own attachments, distinct from but pointing to the same physical files of the attachments of the original post. - since version 3.0, when attachments are copied, not only the database entries are clone, but also the physical files. It’s as if you are uploading the same images that you uploaded in the original post: so you have the original post and the copy with distinct attachment, pointing to different physical files that happen to be identical, but not the same ones. Obviously it doubles the space used on the server.
If you disable theAttachmentssetting instead, the attachments are not cloned with the post. Usually it’s not big deal as long as images are embedded in the content, or there are hyperlinks pointing to uploaded documents, or you have selected a featured image: that’s because all this things use the ID of the attachments, or the URLs of the physical file, regardless of whether the attachments are attached to the original or to another post, or are un-attached at all.
But it’s a problem with that shortcode because the clone post does not have any attachment, so it shows nothing. Pay attention that if you create a new post by hand, and you copy the content of another post including the shortcode, it doesn’t display anything because the post doesn’t have anything attached.
So I stick to my claim that v3.2 is not buggy in that regard, but behaves exactly how I intended it to, and how I think it’s the expected way.
That said, hoping it’s all clear, what about the solution if you’re using that kind of shortcode?- Reverting to v2.6 could be an easy solution, but as I said it would be an unsafe and buggy one, so I don’t recommend it.
- Turning on the
Attachmentssetting makes that shortcode work, but at the price of duplicating files in the uploads folder, using more hosting space, as you experienced. - Turning off the the
Attachmentssetting, you need to fix the shortcode just as you would have to if you copied the post by hand: creating a gallery by explicitly selecting the images you want it to display, regardless of the post to which they are attached.
Not that if you do it in the original post already, when you copy it you won’t need to edit the gallery since the shortcode would already have the list of images IDs to display, e.g.[gallery ids="4,7,90,330" columns="1" link="none" size="full"]. - Another possible solution would be to add some code to my plugin to edit the gallery shortcodes automatically when cloning a post to add the IDs of the images attached to the original post, instead of doing it by hand as I told above. But it’s not so simple and probably it wouldn’t make it in the next version as I have some other, more general priorities
- There could be some other solutions, tailor-made to your case, which would involve some coding (for example by editing your template).
I suggest you solution 3, which is the most straightforward though it requires to explicitly choose the images for every gallery: it should be what’s already happening when you add a gallery shortcode using the “Add Media” button… How come you don’t have any
idsparameter to your shortcode?Sorry if the reply is to loong, I hope I’ve explained the issue clearly enough and helped you choose the best solution for you…
Thanks for reporting, feel free to write for any doubt or bug or question!
Thank you very much for the time you spent on writing your post – that really helped me understand a process behind the image upload. I thought that every time I insert the same image to the different posts a new attachment is created which is not true.
How come you don’t have any
idsparameter to your shortcode?We have 2 galleries on every page – slider and built-in wordpress gallery with same images for those visitors who want to quickly scroll through all images.
Every gallery contains approx 60 images so we tried to simplify life to our editors by removing the need to select images for galleries twice.
All they had to do is to open slider gallery options and upload all images. That action created attachments that were displayed by wordpress gallery shortcode.Your solution no.3 is now in place. That increased the amount of labor work but slightly so situation is solved, thanks you!
The topic ‘Unpleasant bug with attachments’ is closed to new replies.