允许编辑查看/修改自定义帖子类型

时间:2018-11-29 作者:bones

我创建了三种新的自定义帖子类型,它们对我的管理员用户都很好。具有编辑器角色的用户可以在管理中查看菜单项,但当他们单击其中一项时,会显示:

对不起,不允许您访问此页面

这让我抓狂,知道我错过了什么吗?

// The custom function MUST be hooked to the init action hook
add_action( \'init\', \'handbook_noodles_post_type\', 0 );

// A custom function that calls register_post_type
function handbook_noodles_post_type()
{
    // Set various pieces of text, $labels is used inside the $args array
    $labels = array(
        \'name\' => \'Noodles\\\'s Handbook\',
        \'singular_name\' => \'Noodles\\\'s Page\',
        \'add_new\' => __( \'Add New Page\' ),
        \'add_new_item\' => \'Add New Page\',
        \'edit_item\' => \'Edit Page\',
    );

    // Set various pieces of information about the post type
    $args = array(
        \'labels\' => $labels,
        \'description\' => \'Noodles\\\'s Handbook Pages\',
        \'public\' => true,
        \'exclude_from_search\' => true,
        \'query_var\' => false,
        \'show_in_menu\' => \'employee_handbook.php\',
        \'supports\' => array(\'title\', \'editor\', \'page-attributes\'),
        \'hierarchical\' => true,
        \'has_archive\' => true,
        \'capability_type\' => \'post\',
        \'map_meta_cap\' => true
    );

    register_post_type( \'noodles-handbook\', $args );
}

1 个回复
SO网友:Dave S

我怀疑问题不在于注册帖子类型,而在于创建菜单页时。

调用add\\u submenu\\u page()时,请确保$capability参数正确。在您的情况下,您需要“edit\\u posts”:

$capability = \'edit_posts\';
add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug );

结束

相关推荐