[wp-hackers] Capabilities and all that

John Blackbourn johnbillion+wp at gmail.com
Mon Jul 23 15:22:52 UTC 2012


On 23 July 2012 15:48, Simon Wheatley <simon at sweetinteraction.com> wrote:
> I was hoping for a neat way of using map_meta_cap or similar to allow anyone with a *_posts(s) type cap to carry that cap over to the *_video(s) caps.
>
> Any tips, or do I have to add all the *_video(s) caps to all the roles in the site I want to have them.

Take a look at my User Switching plugin [1]. It uses the
'user_has_cap' and 'map_meta_cap' filters for adding capabilities on
the fly and I've documented it well because it can be hard to get your
head around.

I would use *_video as your CPT's meta capability, assign these
capabilities to your Video Editor role when you add the custom role,
and then filter the capabilities for all your other roles so you don't
need to touch them. Something along the lines of:

if ( ( 'edit_video' == $args[0] ) and !isset( $caps['edit_video'] ) )
  $caps['edit_video'] = user_can( $args[1], 'edit_posts' );

John

[1] http://wordpress.org/extend/plugins/user-switching/


More information about the wp-hackers mailing list