[wp-hackers] Passing arguments to current_user_can() function

Andrew Nacin wp at andrewnacin.com
Fri May 27 15:26:21 UTC 2011

On Fri, May 27, 2011 at 9:25 AM, Dion Hulse (dd32) <wordpress at dd32.id.au>wrote:

> You need to check against the Custom Post Types permission, which may or
> may
> not, have the same format as the edit posts caps.
> Off the top of my head (You''ll have to check the object
> references/functions)
> $post_obj = get_post_type_object( $post->post_type );
> if ( current_user_can( $post_obj->caps->edit_post ) ) { .... }
> if you dump out the object and look at the caps array, you should be able
> to
> figure it out

Dion is correct, but it's ->cap, rather than ->caps. And edit_post is a meta
cap, not a primitive cap, so you'd need to also pass the post ID so
WordPress can check what actual capabilities are required.

$post_type_object = get_post_type_object( $post->post_type );
if ( current_user_can( $post_type_object->cap->edit_post, $post->ID ) ) {
... }

More information about the wp-hackers mailing list