Hello @fanaticweb
When a post is set to Draft status, URL for attachments are not longer available for users without capabilites to see Draft posts. So WordPress returns a 404 error for those users. Basically is the same that happens to the post URL, attachments tied to a post depends on the post availability.
The same (but for different reasons) would happen to a deleted attachment, if you delete it the URL no longer exists in WordPress, therefore WordPress will return a 404 error like it does for any other deleted content.
Attachment Pages Redirect will redirect only the URL for single existing attachments for which the user trying to access them has enough capabilities, because the plugin can run only once WordPress is ready to provide access to the page.
It’s different if you delete the post. When a post is deleted without deleting the attached files, the attachments become “orphant”, they’re no longer tied to a post so they’re not ruled by the post status. So their URL would be valid and Attachment Pages Redirect would be able to redirect them to the WordPress home page.
I hope the above is clear enough, let me know if you need any further clarification.
Hi Samuel,
Thank you so much for the detailed and elaborate feedback, and I’m glad you mentioned the last case scenario given I have a similar case ongoing as we speak, here’s a breakdown:
P.S.: APR plugin was NOT activated yet
1. Post expired and switched automatically to Draft status (domain.com/custom-taxonomy-category/post-name-slug)
2. Admin deleted all attached images and reassigned Draft post to Admin (Post still exists offline to Admin only)
At this point, when doing a search for any of the previous media files (domain.com/wp-content/uploads/2020/08/image-file.jpg), I’m getting the 404 Not Found, so far it’s normal behavior.
Should I delete that post completely in order for APR to redirect the orphan images to the Homepage or is it too late now since the plugin was installed and activated AFTER the Post and images were removed?
I have another active plugin that was custom made to Redirect expired/deleted posts to the Homepage but unfortunately it doesn’t redirect the attached images of those expired posts.
Thank you and again looking forward for your feedback.
-
This reply was modified 5 years, 4 months ago by
Fanaticweb.
You’re welcome @fanaticweb
2. Admin deleted all attached images and reassigned Draft post to Admin (Post still exists offline to Admin only)
Should I delete that post completely in order for APR to redirect the orphan images to the Homepage or is it too late now since the plugin was installed and activated AFTER the Post and images were removed?
As explained in my previous message, as you deleted the images there’s nothing to redirect. They don’t exists anymore and therefore their attachments pages are gone too. So WordPress will return 404 for them without a chance to do any other thing.
So it’s not a matter of when the plugin was activated, that doesn’t affect to the plugin functionality, simply redirecting deleted images is not a feature of the plugin, the plugin needs an existing attachment page to do its job.
Understood, it all comes down to the images existence, so once the image is deleted, the plugin cannot intervene, but wouldn’t that justify the role of the plugin after all? Or is there a rational reason why you didn’t code it that way?
I’m thinking that in most cases, the images are deleted, be it by the Admin or other editing role users of the site, and that’s where the missing link kicks in.