Make WordPress Core

Opened 14 years ago

Closed 10 years ago

#14639 closed defect (bug) (fixed)

Posts in the Trash drag attachment pages down with them

Reported by: markel's profile markel Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.0 Priority: normal
Severity: normal Version: 3.0.1
Component: Media Keywords: has-patch
Focuses: Cc:

Description

If you have an attachment linked to a post, then move the post to the Trash, the attachment page results in a 404.

Steps to reproduce:

  1. Create a new post with at least one image attached to it (just add it to the post).
  2. Publish the post.
  3. Check both the attachment URL (it will be a "child" of the post to which it is attached) and the post URL.
  4. Move the post to the Trash.
  5. Try to "View" the attachment either by going through the Media Library or by refreshing the attachment URL. WordPress will display a 404 message.

Deleting the post permanently can cause the attachment permalink to work again, both with the page parent in the slug and without that information in the form http://sitename.com/attachmentname/ .

Attachments (1)

14639.diff (743 bytes) - added by ericlewis 10 years ago.

Download all attachments as: .zip

Change History (13)

#1 @markel
14 years ago

  • Cc ryan@… added

#2 @westi
14 years ago

  • Cc westi added

Attachments inherit post status from the post they are attached too so they should behave as if they were no longer published which is what is happening here.

Why would you expect otherwise?

#3 @markel
14 years ago

Point taken.

I'll argue then instead that the permalink should also result in a 404 when the post has been permanently deleted.

#4 @helenyhou
12 years ago

#22761 was marked as a duplicate.

#5 @helen
12 years ago

#23013 was marked as a duplicate.

#6 @nmoinvaz
12 years ago

If you plan on leaving it that way so that posts that are trashed take down all the attachments with-it then the user interface shouldn't allow users create galleries with attachments from other posts.

#7 @knutsp
12 years ago

  • Cc knut@… added

#8 follow-up: @mindctrl
11 years ago

  • Cc dailyrants@… added

This affects other posts too, not just the original post to which a media item is attached.

For example, if you add the same image to two posts, and set it to link to the attachment page in both posts, it breaks the link in the second post when the first post is deleted or set as a draft.

It's kinda tricky. On the one hand, you might want a media item's visibility linked to the post it is attached to. On the other, it pretty much messes with the concept of a central media library. When a media item is "attached" to something, it's no longer a neutral object available for use everywhere without conditions. If it's simply referenced and not attached, its usable everywhere and its permalink is tied to itself instead of another object.

To the point made by the OP about what happens when the original post is emptied from the trash, it's just weird that the permalink of the attachment begins to work again and still lives at a location attached to the original post slug. site.com/deleted-post-title/attachment. That just seems wrong.

Any "solution" to this seems equally annoying from a UI perspective, as one would need to declare that an item is either attached to another object or is a global asset to be referenced as a unique independent asset.

One that comes to mind, but isn't obvious without people discovering it through trial and error, is that if an item is uploaded by Media > Add New, it is an independent object forever. If it is ever inserted into a post via the "Add Media" button later, it remains independent and is only accessed via the HTML code that gets inserted into the post. If it's initially inserted into a post via the "Add Media" button in the post editor screen, it becomes tied to that object as it currently does.

I'm very likely overlooking something here, but the current situation seems far less than ideal. Does anyone else have any insight here?

Last edited 11 years ago by mindctrl (previous) (diff)

#9 in reply to: ↑ 8 @SergeyBiryukov
11 years ago

Replying to mindctrl:

To the point made by the OP about what happens when the original post is emptied from the trash, it's just weird that the permalink of the attachment begins to work again and still lives at a location attached to the original post slug. site.com/deleted-post-title/attachment. That just seems wrong.

Actually, once the post is deleted, the attachment permalink in Media Library changes to numeric form (e.g. http://trunk.wordpress/?attachment_id=5186). The old permalink, however, still continues to work. It should probably redirect to the new one.

#10 follow-up: @azaozz
10 years ago

  • Milestone changed from Awaiting Review to 4.0

Ran into this again. Somewhat more common user case:

  • Create new post, upload couple of images and publish it.
  • Trash it.
  • Create another post, add a gallery that includes the above images and publish it.
  • In that gallery the above images are linked to non-existing pages (404).

Not sure what is the best behavior here. Perhaps when moving a post to the trash all attachments have to be "unattached" from it. Doesn't make sense to "trash" the attachment pages when the attached files are still accessible.

Then we can add some special meta to keep track of them and re-attach in case the post is restored, and the attachments haven't been attached elsewhere.

Moving to 4.0 for consideration.

@ericlewis
10 years ago

#11 in reply to: ↑ 10 @ericlewis
10 years ago

  • Keywords has-patch added

Replying to azaozz:

Perhaps when moving a post to the trash all attachments have to be "unattached" from it. Doesn't make sense to "trash" the attachment pages when the attached files are still accessible.

It seems that an attachment's post status inherits from its post parent ([17999]). I think that's weird. An attachment should be private if its post parent is private? An attachment should be trashed if its post parent is trashed?

A conservative effort in attachment:14639.diff changes the post status for attachments to respect the post's pre-trash post status.

Last edited 10 years ago by SergeyBiryukov (previous) (diff)

#12 @wonderboymusic
10 years ago

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

In 28791:

Posts in the Trash should not drag attachment pages down with them.

Props ericlewis.
Fixes #14639.

Note: See TracTickets for help on using tickets.