我创建了一个自定义帖子类型,并为其提供了以下功能:
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 );
}
我也检查过了
$GLOBALS[\'wp_post_types\'][\'team_page\']
为了确保他们都在那里,一切似乎都正常:
[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
)
所以我猜我的问题在于错误地分配了这些功能,我很喜欢:
$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\');
我以为这就是问题所在,但当我
print_r(get_role( \'administrator\' ));
我得到:
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
)
)
这个名单大大缩短了。
不管怎样,它还是不起作用。我无法以管理员身份访问我的自定义帖子类型,除非我将功能类型改回“页面”或“帖子”