[wp-hackers] using user_has_cap filter

John Blackbourn johnbillion+wp at gmail.com
Tue Oct 27 15:18:50 UTC 2009

$caps is an array containing the actual required capability (or
capabilities) for the current action. The best way to explain this is
by examples.

If you call current_user_can('delete_user',2) then the required
capability is delete_users not delete_user. $caps will contain

If you call current_user_can('edit_post',4) and post 4 doesn't belong
to you then $caps will contain several elements such as 'edit_posts',
'edit_others_posts' and maybe more depending on the post status.

In the two plugins I've written that filter user_has_cap, I've found
no need to use $caps at all so don't worry about it too much. Take a
look at map_meta_cap() which is in wp-includes/capabilities.php for
more info.

$args[0] is the required capability for the current_user_can() call.
Eg. current_user_can('edit_posts') will mean $args[0] is 'edit_posts'.

$args[1] is the current user ID.

$args[2] will be the value of the optional second parameter in
current_user_can(). Eg current_user_can('edit_post',5) will give us
'5' in $args[2].



2009/10/27 Steve Taylor <steve at sltaylor.co.uk>:
> I'm almost there with comprehending the user_has_cap filter, but I
> just need some clarification. If I add a filter like this:
> add_filter( 'user_has_cap', 'my_has_cap', 0, 3 );
> And then this is my callback function:
> function lockDeletion( $allcaps, $caps, $args ) {
>    [whatever]
> }
> As far as I can tell:
> $allcaps is an array with capabilities for keys and boolean values
> $caps is ????
> $args are the extra arguments - post ID, etc. But what is $args[0],
> what is $args[1], etc. ????
> thanks,
> Steve Taylor
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list