I created a custom post type and gave it the following capabilities:
add_action( 'init', 'create_team_page_post_type' );
function create_team_page_post_type() {
$args = array(
'labels' => team_page_post_type_labels( 'Team Page' ),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => array('team', 'teams'),
'capabilities' => array(
'publish_pages' => 'publish_teams',
'edit_pages' => 'edit_teams',
'edit_page' => 'edit_team',
'edit_others_pages' => 'edit_others_teams',
'delete_pages' => 'delete_teams',
'delete_page' => 'delete_team',
'delete_others_pages' => 'delete_others_teams',
'manage_pages' => 'manage_teams',
'read_private_pages' => 'read_private_teams',
'read_page' => 'read_team'
),
'map_meta_cap'=> true,
'has_archive' => true,
'hierarchical' => true,
'menu_position' => null,
'supports' => array('title',
'author',
'editor',
'thumbnail',
)
);
register_post_type( 'team_page', $args );
}
I also checked $GLOBALS['wp_post_types']['team_page']
to make sure they were all there and everything seems to be behaving as it should:
[cap] => stdClass Object
(
[edit_post] => edit_team
[read_post] => read_team
[delete_post] => delete_team
[edit_posts] => edit_teams
[edit_others_posts] => edit_others_teams
[publish_posts] => publish_teams
[read_private_posts] => read_private_teams
[read] => read
[delete_posts] => delete_teams
[delete_private_posts] => delete_private_teams
[delete_published_posts] => delete_published_teams
[delete_others_posts] => delete_others_teams
[edit_private_posts] => edit_private_teams
[edit_published_posts] => edit_published_teams
[create_posts] => edit_teams
)
So I'm guessing my problem lies in incorrectly assigning these capabilities which I did like so:
$role_object = get_role( 'administrator' );
$role_object->add_cap( 'publish_teams');
$role_object->add_cap( 'edit_teams');
$role_object->add_cap( 'edit_team');
$role_object->add_cap( 'edit_others_teams');
$role_object->add_cap( 'delete_teams');
$role_object->add_cap( 'delete_team');
$role_object->add_cap( 'delete_others_teams');
$role_object->add_cap( 'manage_teams');
$role_object->add_cap( 'read_private_teams');
$role_object->add_cap( 'read_team');
I thought that was the problem but when I print_r(get_role( 'administrator' ));
I get:
WP_Role Object
(
[name] => administrator
[capabilities] => Array
(
[manage-teams] => 1
[edit-teams] => 1
[edit_others_teams] => 1
[delete_teams] => 1
[edit-team] => 1
[delete_others_teams] => 1
[delete_team] => 1
[read_private_teams] => 1
[read_team] => 1
[manage_teams] => 1
)
)
That list is shortened considerably.
Anyway it still doesn't work. I cannot access my custom post type as admin unless I change the capability type back to "page" or "post."