Cannot figure this out: user_has_cap

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Cannot figure this out: user_has_cap

Dino Termini
Hi list,

For the life of me, I can't figure this out. I want to prevent my
authors to edit a bunch of pages on my website.

Aside from using pre_get_posts to change wp_query, I'd also tweak
current_user_can "on the fly" and remove "edit_pages" from the user's
capabilities, if the ID is in my blacklist.

So I created a plugin with the following code:

function tweak_edit_page_capability( $allcaps, $caps, $args ) {
     file_put_contents( '/file/somewhere', 'it works!', FILE_APPEND );
     return $allcaps;
}
add_filter( 'user_has_cap', 'tweak_edit_page_capability', 10, 3 );

However the function is not called! What am I doing wrong? I've
deactivated all plugins and reset the theme, but nothing helps!

Dino.
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Cannot figure this out: user_has_cap

John Blackbourn
Are you logged in as a super admin on multisite? The user_has_cap filter
doesn't get called in that situation.

My User Switching plugin has a nice bit of documentation with its callback
functions for this filter and the corresponding map_meta_cap filter, which
may help you. See here and here:

https://github.com/johnbillion/user-switching/blob/0.8.8/user-switching.php#L36-L37
https://github.com/johnbillion/user-switching/blob/0.8.8/user-switching.php#L533-L576

John


On 2 June 2014 17:26, Dino Termini <[hidden email]> wrote:

> Hi list,
>
> For the life of me, I can't figure this out. I want to prevent my authors
> to edit a bunch of pages on my website.
>
> Aside from using pre_get_posts to change wp_query, I'd also tweak
> current_user_can "on the fly" and remove "edit_pages" from the user's
> capabilities, if the ID is in my blacklist.
>
> So I created a plugin with the following code:
>
> function tweak_edit_page_capability( $allcaps, $caps, $args ) {
>     file_put_contents( '/file/somewhere', 'it works!', FILE_APPEND );
>     return $allcaps;
> }
> add_filter( 'user_has_cap', 'tweak_edit_page_capability', 10, 3 );
>
> However the function is not called! What am I doing wrong? I've
> deactivated all plugins and reset the theme, but nothing helps!
>
> Dino.
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Cannot figure this out: user_has_cap

Dino Termini
THANK YOU!!! :) I was indeed logged in as a super admin on mu :/

On 6/2/14, 12:52 PM, John Blackbourn wrote:

> Are you logged in as a super admin on multisite? The user_has_cap filter
> doesn't get called in that situation.
>
> My User Switching plugin has a nice bit of documentation with its callback
> functions for this filter and the corresponding map_meta_cap filter, which
> may help you. See here and here:
>
> https://github.com/johnbillion/user-switching/blob/0.8.8/user-switching.php#L36-L37
> https://github.com/johnbillion/user-switching/blob/0.8.8/user-switching.php#L533-L576
>
> John
>
>
> On 2 June 2014 17:26, Dino Termini <[hidden email]> wrote:
>
>> Hi list,
>>
>> For the life of me, I can't figure this out. I want to prevent my authors
>> to edit a bunch of pages on my website.
>>
>> Aside from using pre_get_posts to change wp_query, I'd also tweak
>> current_user_can "on the fly" and remove "edit_pages" from the user's
>> capabilities, if the ID is in my blacklist.
>>
>> So I created a plugin with the following code:
>>
>> function tweak_edit_page_capability( $allcaps, $caps, $args ) {
>>      file_put_contents( '/file/somewhere', 'it works!', FILE_APPEND );
>>      return $allcaps;
>> }
>> add_filter( 'user_has_cap', 'tweak_edit_page_capability', 10, 3 );
>>
>> However the function is not called! What am I doing wrong? I've
>> deactivated all plugins and reset the theme, but nothing helps!
>>
>> Dino.
>> _______________________________________________
>> wp-hackers mailing list
>> [hidden email]
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers

_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers