【发布时间】:2012-01-03 00:34:11
【问题描述】:
我正在编写一个插件,它创建一个新的 post_type 和一个只能添加/编辑/等新 post_type 的相应角色。一切都按预期工作,但分配了我的自定义角色的用户无法查看仪表板。一旦用户登录,他们立即得到以下错误:
“您没有足够的权限访问此页面。”
但是,登录成功,当用户浏览网站时,自定义帖子上会出现“编辑”链接。该用户甚至可以通过工具栏编辑/添加新的自定义帖子,但只要他/她单击“仪表板”或任何其他未直接链接到自定义 post_type 的链接,他们就会收到上述错误消息。
我认为这意味着我的自定义功能正在发挥作用……但效果太好了(太严格了)。我还想允许基本的“订阅者”权限以及我为自定义 post_type 定义的功能。我已经阅读并重新阅读了有关功能和角色的法典,看来我应该能够通过将'read' => true 添加到我的功能数组中来做我想做的事,但它似乎不起作用。这是我的代码:
add_action('init', 'setup_dictionary_post');
//Register custom post type
function setup_dictionary_post() {
$capabilities = array(
'publish_posts' => 'publish_dictionary_entry',
'edit_posts' => 'edit_dictionary_entry',
'edit_others_posts' => 'edit_others_dictionary_entry',
'delete_posts' => 'delete_dictionary_entry',
'delete_others_posts' => 'delete_others_dictionary_entry',
'read_private_posts' => 'read_private_dictionary_entry',
'edit_post' => 'edit_dictionary_entry',
'delete_post' => 'delete_dictionary_entry',
'read_post' => 'read_dictionary_entry'
);
$labels = array(
'name' => 'Dictionary Entries',
'singular_name' => 'Dictionary Entry',
'menu_name' => 'Dictionary Entries',
'add_new' => 'Add New',
'add_new_item' => 'Add New Dictionary Entry',
'edit' => 'Edit entry',
'edit_item' => 'Edit Dictionary Entry',
'new_item' => 'New Dictionary Entry',
'view' => 'View Dictionary Entry',
'view_item' => 'View Dictionary Entry',
'search_items' => 'Search Dictionary Entries',
'not_found' => 'No Dictionary Entries Found',
'not_found_in_trash' => 'No Dictionary Entries Found in Trash',
'parent' => 'Parent Dictionary Entry',);
register_post_type('dictionary_entry', array(
'label' => 'Dictionary Entries',
'description' => '',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'dictionary_entry',
'capabilities'=>$capabilities,
'hierarchical' => false,
'rewrite' => array('slug' => ''),
'query_var' => true,
'supports' => array('title','comments','revisions','thumbnail','author','page-attributes',),
'labels' => $labels,
)
);
flush_rewrite_rules(false);
/********************** CUSTOM ROLE *****************************/
add_role('dictionary_entry_author', 'Dictionary Helper', array(
'publish_dictionary_entry' => true,
'edit_dictionary_entry' => true,
'edit_others_dictionary_entry' => true,
'delete_dictionary_entry' => true,
'delete_others_dictionary_entry' => true,
'read_private_dictionary_entry' => true,
'edit_dictionary_entry' => true,
'delete_dictionary_entry' => true,
'read_dictionary_entry' => true,
// more standard capabilities here
'read' => true,
));
//I do some other stuff later in this function that isn't important.
//For example, I define a custom taxonomy for the new post_type...
}
我不确定为什么 'read'=>true, 没有达到我想要的效果。我已经阅读了几个教程,并收到了一些从中映射“元功能”的代码,但我没有在我的代码中使用它,因为我不明白它是如何工作的而且它不似乎 是必要的。我可能是错的。
【问题讨论】:
标签: wordpress