BACKGROUND
I have created a must-use plugin where I keep general functions. Like register_post_type().
Here I've created several Custom Post Types. With the help of several really good posts, I managed to get a grip of Capability for Custom Post Types (I think).
//////////////// // // Create Custom Post Types // //////////////// add_action( 'init', 'create_post_type' ); function create_post_type() { register_post_type( 'pms', array( 'labels' => array( 'name' => __( 'Personal Mission Statements' ), 'singular_name' => __( 'Personal Mission Statement' ) ), 'public' => true, 'has_archive' => true, 'menu_position' => 2, 'menu_icon' => 'dashicons-heart', 'capability_type' => array('pms','pmss'), 'map_meta_cap' => true, 'supports' => array( 'title', 'editor', 'author' ) ) ); flush_rewrite_rules(); } //////////////// // // Create Custom Roles // //////////////// ///////// //Add new roles //////// //Can't create new post and only edit their own $capabilities_employee = array ( 'edit_others_pages' => true, 'edit_others_posts' => true, 'edit_pages' => true, 'edit_posts' => true, 'edit_private_posts' => true, 'edit_published_posts' => true, 'list_users' => true, 'manage_categories' => true, 'publish_posts' => true, 'read' => true, 'upload_files' => true, 'manage_categories' => true, ); //Create additional Roles function add_roles () { add_role( 'employee', 'Employee', $capabilities_employee ); } add_action( 'admin_init', 'add_roles'); //////// //Specify Capabilities Custom Post Types //////// //Add capabilities to the other Post Types (need added). //The remove a capabilities it is NOT enough to remove the line, you need to add remove_cap() function add_theme_caps() { // gets the candidate role $employees = get_role( 'employee' ); $employees->add_cap( 'read' ); $employees->add_cap( 'edit_pms' ); $employees->add_cap( 'read_pms' ); $employees->add_cap( 'edit_pmss' ); $employees->add_cap( 'publish_pmss' ); $employees->add_cap( 'edit_published_pmss' ); } add_action( 'admin_init', 'add_theme_caps'); PROBLEM Before editing a Custom Post 'pms' I check for current_user_can('edit_pms')
1) Default role 'editor' returns TRUE 2) Custom role 'employee' (above) returns FALSE
Is use $GLOBALS['wp_post_types'] to debug capability on the 'pms' Custom Post Type and get_userdata() to debug capability for the a user with the employee role. They both come out with the right capabilities.
QUESTION Any idea way (2) above returns FALSE?
SOURCES
https://codex.wordpress.org/Function_Reference/register_post_type http://justintadlock.com/archives/2010/07/10/meta-capabilities-for-custom-post-types
$GLOBALS['wp_post_types']is a good way to debug capabilities?