I’m writing a plugin which creates a custom post_type. I’d also like the plugin to create a custom role which can only add/edit/delete the new post_type. I’ve tried several plugins (Role Scoper, Advanced Access manager) and they allow me to redefine or create new roles, but they don’t allow me to assign capabilities specific to the new post_type. For example, I want to allow the ability to add/edit my new post_type but NOT normal posts/pages.
From what I’ve read, I can add new roles with the add_role() function. One of the parameters of this function is an array of “capabilities” which appear to be defined here. I think what I need is to be able to add my capabilities that are specific to MY post_type. Is this possible?
Capabilities for Custom Post Types
The function
register_post_type()takes a$capabilitiesarray as one of its (optional) arguments.It could look like so:
where “ypt” stands for “your post type”.
Thereafter you could add a new role to your WordPress that has these exact capabilities (and possibly some more of the standard WordPress capabilities):
The latter can be done using plugins though, check out the Members plugin by Justin Tadlock, for instance.
Thorough Example
To give you a more concrete example: