Make WordPress Core

Opened 9 years ago

Last modified 4 years ago

#26365 new defect (bug)

map_meta_cap() should use parent post status when post has a post status of inherit

Reported by: methnen's profile methnen Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.8
Component: Role/Capability Keywords: has-patch needs-unit-tests
Focuses: Cc:

Description (last modified by SergeyBiryukov)

When a post has a status of inherit map_meta_cap() fails to use the parent's status and so logic that uses the status to determine the mapping doesn't behave as expected.

For example read_post() will often fail when it should pass. Similarly for delete_post() and edit_post().

This has recently caused a variety of difficulties in a project I've been working on where we have a custom post type that uses the inherit post status on children so authors only need to manage the post status of the main parent post.

The fix is two parts. One a fix to get_post_status() that causes it to check the parent status so it'll work backwards to the first post that has a valid (not 'inherit') post status.

The second is a fix to map_meta_cap() that checks for a post status of inherit on the post object and then uses get_post_status() on the post_parent id value.

A couple related/similar issues:
#23458 (these patches would fix the root issue)
#17668 (fixed)

Attachments (5)

capabilities.diff (1.3 KB) - added by methnen 9 years ago.
map_meta_cap_fix
post.diff (511 bytes) - added by methnen 9 years ago.
get_post_status_fix
capabilities.2.diff (1.2 KB) - added by methnen 8 years ago.
Updated capabilities patch.
post.2.diff (405 bytes) - added by methnen 8 years ago.
Updated post patch.
26365.diff (1.6 KB) - added by stevenkword 8 years ago.

Download all attachments as: .zip

Change History (18)

@methnen
9 years ago

map_meta_cap_fix

@methnen
9 years ago

get_post_status_fix

#1 @misterbisson
9 years ago

  • Keywords has-patch added

+1 one this. I'm biased because we need this to resolve the bugs named above. We make extensive use of custom post types with inherit status on a number of gigaom.com properties.

#2 @misterbisson
9 years ago

  • Keywords needs-patch 2nd-opinion added; has-patch removed

#3 @misterbisson
9 years ago

  • Keywords needs-patch removed

#4 @misterbisson
9 years ago

  • Keywords has-patch added

#5 @SergeyBiryukov
9 years ago

  • Description modified (diff)

#6 @antpb
8 years ago

  • Keywords needs-refresh added

Attempted to push out the patch but it's been open for 2 years and failed on the apply. Needs a refresh.

#7 @antpb
8 years ago

  • Keywords needs-patch added; has-patch removed

#8 @methnen
8 years ago

@antpb I'll get updated patches in sometime today. Glad to see this getting some attention.

@methnen
8 years ago

Updated capabilities patch.

@methnen
8 years ago

Updated post patch.

#9 @methnen
8 years ago

Updated patches are now attached.

@stevenkword
8 years ago

#10 @stevenkword
8 years ago

26365.diff simply combines to previous solution into a single diff.

#11 @johnbillion
8 years ago

  • Keywords has-patch needs-unit-tests added; 2nd-opinion needs-refresh needs-patch removed

This needs unit test coverage.

#12 @stevenkword
8 years ago

Note 26365.diff will collide with the solution proposed in #23458, which was milestoned for 4.3.

Last edited 8 years ago by stevenkword (previous) (diff)

#13 @methnen
8 years ago

@stevenkword I'm fairly sure that's only the case in the second post.php patch.

map_meta_cap does not ever call on get_post_status and thus still needs to be fixed in order to properly support 'inherit' on custom post types.

Note: See TracTickets for help on using tickets.