[wp-hackers] Looking for the role-capability to set for add_submenu_page

Paul paul at codehooligans.com
Fri Aug 27 23:28:08 UTC 2010


I would suggest since you are setting up your own post type then go ahead and define your own user capability role. Then use one of the role manager plugins to select who can access the menu based on your defined role. Im my opinion this is cleaner since you are not tied to the build in WordPress user capabilities. 

So how is this done? Quite easily. From digging into this a few weeks ago I think there are 4 basic actions checked within post type term screen. These actions are 'manage', 'edit', 'delete' and 'assign. For your own post type just pick strings like 'myposttype_manage_terms', 'mediatags_edit_terms', 'mediatags_delete_terms', 'mediatags_assign_terms'. Replace 'myposttype' with something specific to your post type. 

In plugin examples I've reviewed the developer sets these up as a define in a main config file something like:

define( 'MYPOSTTYPE_MANAGE_TERMS_CAP', 'myposttype_manage_terms' );
define( 'MYPOSTTYPE_EDIT_TERMS_CAP', 'myposttype_edit_terms' );
define( 'MYPOSTTYPE_DELETE_TERMS_CAP', 'myposttype_delete_terms' );
define( 'MYPOSTTYPE_ASSIGN_TERMS_CAP', 	'myposttype_assign_terms' );

Then when you setup your post_type you just pass in the defines to the function as an array like:

$default_caps				= array();
$default_caps['manage_terms'] 	= MYPOSTTYPE_MANAGE_TERMS_CAP;
$default_caps['edit_terms'] 		= MYPOSTTYPE_EDIT_TERMS_CAP;
$default_caps['delete_terms'] 	= MYPOSTTYPE_DELETE_TERMS_CAP;
$default_caps['assign_terms'] 	= MYPOSTTYPE_ASSIGN_TERMS_CAP;

register_taxonomy(my_post_type, 'post', array(
    'hierarchical' => false,
    'labels' 		=> $labels,
	'show_ui' 		=> false,
    'query_var' 	=> false,
    'rewrite' 		=> false,
	'capabilities' 	=> $default_caps	// Set the capabilities to your custom array
));

Two excellent Role Cap manager plugins:

Members by Justin Tadlock
http://justintadlock.com/archives/2009/09/17/members-wordpress-plugin

Role Manager by Thomas Schneider
http://www.im-web-gefunden.de/wordpress-plugins/role-manager/







On Aug 27, 2010, at 7:03 PM, Philip M. Hofer (Frumph) wrote:

> Looking for the role to set for add_submenu_page, if the user is set to 'contributor' i want them to have access to the post-types and do what they need to do and I verify it and publish it for them.
> 
> I'm thinking 'edit_posts' ... but i'm just not sure, the http://codex.wordpress.org/Roles_and_Capabilities page really doesn't sort of explain to (me) what each of the roles abilities (by default) are
> 
> 
> - Phil
> _______________________________________________
> 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