using user_has_cap filter

View: New views
4 Messages — Rating Filter:   Alert me  

using user_has_cap filter

by Steve Taylor-15 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: using user_has_cap filter

by Andrew Nacin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

http://phpxref.ftwr.co.uk/wordpress/wp-includes/capabilities.php.source.html#l697


> $caps is ????
>

The capability being asked for. If it's a meta capability, map_meta_cap
first determines the primitive capability.

$args are the extra arguments - post ID, etc. But what is $args[0], what is
> $args[1], etc. ????
>

It depends on the capability being asked for, so you can determine the
specific situation for which the capability is being requested. The post ID
will be passed by current_user_can if, say, the check is whether the user
can edit or delete a post. But it wouldn't be passed if the check is whether
the user can switch themes.
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: using user_has_cap filter

by John Blackbourn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

$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
'delete_users'.

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].

HTH!

John.

2009/10/27 Steve Taylor <steve@...>:

> 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@...
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: using user_has_cap filter

by Steve Taylor-15 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

John, many thanks, that was exactly what I needed.

Steve


2009/10/27 John Blackbourn <johnbillion+wp@...>:

> $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
> 'delete_users'.
>
> 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].
>
> HTH!
>
> John.
>
> 2009/10/27 Steve Taylor <steve@...>:
>> 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@...
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers@...
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers