#52326 closed defect (bug) (fixed)
`get_post_status()` is can be incorrect for attachments.
Reported by: | peterwilsoncc | Owned by: | peterwilsoncc |
---|---|---|---|
Milestone: | 5.7 | Priority: | normal |
Severity: | normal | Version: | 2.2 |
Component: | Media | Keywords: | has-unit-tests has-patch has-dev-note |
Focuses: | Cc: |
Description (last modified by )
get_post_status()
can return an incorrect status for attachments in the following circumstances:
- Attachment with
inherit
status fromfuture
post: returns'publish'
, ought to be'future'
- Attachment with status
draft
and no parent: returns'publish'
, ought to be'draft'
(can't be done in admin, only via code) - Attachment with
inherit
status andpost_parent
set to nonexistent post: returnsfalse
, ought to be'publish'
.
I've attached unit tests to demonstrate.
Attachments (1)
Change History (13)
This ticket was mentioned in PR #881 on WordPress/wordpress-develop by peterwilsoncc.
4 years ago
#1
- Keywords has-patch added
#3
@
4 years ago
In PR #881:
- Unit tests
- A valid attachment ID can no longer return
false
as the status - attachment with
inherit
status always inherits parent posts status unless trashed (need to confirm this is correct) - trashed posts return the status immediately prior to the post been trashed using the meta data
- if the meta data is not set/the parent post does not exist the attachment defaults to
publish
. - attachments are now passed through the
get_post_status
filter, they bypassed it before.
#4
@
4 years ago
- Description modified (diff)
- Keywords needs-dev-note added
- Milestone changed from Awaiting Review to 5.7
- Owner set to peterwilsoncc
- Status changed from new to assigned
- Version set to 2.2
Putting this on the milestone as it's going to be helpful for #5272.
Will need a comment in the general dev note (rather than a dedicated one) that the get_post_status
filter now runs for attachments too.
trash
changes were introduced in 4.0.0 but various other bugs have been around since the function was introduced in 2.2.0.
#6
@
4 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
// Attachment permitted statuses: 'inherit', , see wp_insert_post().
Did this list mean to include something other than inherit
? I assume publish
, but wanted to double-check :)
#7
@
4 years ago
@SergeyBiryukov Failed cut and paste when I moved it to the elseif
below. Fix incoming.
#9
follow-up:
↓ 10
@
4 years ago
A valid attachment ID can no longer return false as the status
attachment with inherit status always inherits parent posts status unless trashed (need to confirm this is correct)
if the meta data is not set/the parent post does not exist the attachment defaults to publish
publish
seems like the wrong default for an attachment with no parent. Where is it published? I would suggest draft
in this case.
Is this marked for a dev note? There could be plugins checking for false
.
#10
in reply to:
↑ 9
@
4 years ago
Replying to joyously:
publish
seems like the wrong default for an attachment with no parent. Where is it published? I would suggestdraft
in this case.
For trash
ed parents, attachments have worked like this for a long time (at least as far back as 4.4.0). An attachment uploaded with one post as the parent may be published on another and WP Core offers no protections against using files in the uploads folder.
Is this marked for a dev note? There could be plugins checking for
false
.
Yes, this is marked for a dev note.
#12
@
4 years ago
- Summary changed from `get_post_status()` is can be incrorrect for attachments. to `get_post_status()` is can be incorrect for attachments.
https://core.trac.wordpress.org/ticket/52326