#23226 closed defect (bug) (fixed)
Always use meta caps directly instead of going through the post_type_object->caps array
Reported by: | markjaquith | Owned by: | nacin |
---|---|---|---|
Milestone: | 3.6 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Role/Capability | Keywords: | has-patch needs-testing |
Focuses: | Cc: |
Description
When using post-related meta caps in core, we should use their meta cap name instead of manually digging into the post object looking for the cap.
e.g.
Do this:
if ( ! current_user_can( 'edit_post', $post_id ) ) { // ... }
Instead of this:
$post_type = get_post_type_object( get_post_type( $post_id ) ); if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) { // ... }
Our meta caps resolve custom caps for the meta caps (if someone has been foolish enough to use them), and we should be consistent about doing it that way so people know that's the right way to do it.
Attachments (2)
Change History (11)
#2
follow-up:
↓ 3
@
12 years ago
To clarify: that's the correct way, even if register_post_type() has 'map_meta_cap' => false
, right?
#3
in reply to:
↑ 2
@
12 years ago
Replying to scribu:
To clarify: that's the correct way, even if register_post_type() has
'map_meta_cap' => false
, right?
Right. Our post-related meta caps all have this block of code:
if ( ! $post_type->map_meta_cap ) { $caps[] = $post_type->cap->$cap;
So it essentially does that digging for us.
#4
@
12 years ago
- Keywords has-patch needs-testing added
- Owner set to markjaquith
- Status changed from new to accepted
First swing. Passes existing unit tests. Where possible, I removed the associated get_post_type_object()
call — that is, if it was only being used in the cap check. I could probably use a double-check where that happened.
#5
@
12 years ago
- Owner changed from markjaquith to nacin
- Status changed from accepted to assigned
Assigning to nacin for review, as map_meta_cap
is near and dear to him.
#7
@
12 years ago
Found a couple more in query.php, fixed in 23226.2.diff
I've been meaning to do this for a while as a first step to cleaning up meta capabilities for post types. +1.