[wp-hackers] Mapping meta caps only to attachments and unpublished posts

William Davis will.davis at gmail.com
Thu Jan 13 18:17:08 UTC 2011


Ah, so could I say $caps=delete_attachments and then give users that  
capability?

William P. Davis
will.davis at gmail.com
207.660.5342
http://twitter.com/williampd
http://www.wpdavis.com



On Jan 13, 2011, at 1:14 PM, Andrew Nacin wrote:

> On Thu, Jan 13, 2011 at 1:00 PM, William Davis  
> <will.davis at gmail.com> wrote:
>
>> I'm trying to allow users to only delete unpublished posts and  
>> attachments.
>> I removed their meta cap to delete posts and am trying to add it back
>> selectively with the code below, but am not having any luck. Any  
>> help would
>> be much appreciated.
>>
>> if ( 'delete_post' == $cap ) {
>>               $post = get_post( $args[0] );
>>               $post_type = $post->post_type;
>>               if( $post_type == 'attachment' ) {
>>                       $post_type = get_post_type_object( $post- 
>> >post_type
>> );
>>                       $caps[] = 'delete_post';
>>               }
>> }
>>
>
> You need to map to the primitive cap via map_meta_cap. Thus, $caps[] =
> 'delete_posts' rather than 'delete_post'.
>
> Keep in mind you're not actually modifying the user's capability  
> here --
> you're simply saying that the user needs to have delete_posts whenever
> delete_post is checked for an attachment.
>
> Nacin
> _______________________________________________
> 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