我已经使用了几个教程,并尝试应用各种“解决方案”,但我仍然无法让自定义角色为自定义类型编辑自己的帖子。
我创造了这个角色,它显示了很好的。。。
function mymodule_create_role() {
add_role( \'resident\', \'New Role\', array(
\'read\' => true, // True allows that capability
\'create_posts\' => false,
\'edit_posts\' => false, // Allows user to edit their own posts
\'publish_posts\'=>false, //Allows the user to publish, otherwise posts stays in draft mode
\'edit_published_posts\'=>false,
\'upload_files\'=>true,
\'delete_published_posts\'=>false,
));
}
我还注册了我的新内容类型,这似乎很好。。。
function register_bulletin_board() {
$labels = array(
\'name\' => _x( \'Bulletin Board\', \'bulletin_board\' ),
\'singular_name\' => _x( \'Bulletin Board\', \'bulletin_board\' ),
\'add_new\' => _x( \'Add New\', \'bulletin_board\' ),
\'add_new_item\' => _x( \'Add New Bulletin Board\', \'bulletin_board\' ),
\'edit_item\' => _x( \'Edit Bulletin Board\', \'bulletin_board\' ),
\'new_item\' => _x( \'New Bulletin Board\', \'bulletin_board\' ),
\'view_item\' => _x( \'View Bulletin Board\', \'bulletin_board\' ),
\'search_items\' => _x( \'Search Bulletin Board\', \'bulletin_board\' ),
\'not_found\' => _x( \'No bulletin board found\', \'bulletin_board\' ),
\'not_found_in_trash\' => _x( \'No bulletin board found in Trash\', \'bulletin_board\' ),
\'parent_item_colon\' => _x( \'Parent Bulletin Board:\', \'bulletin_board\' ),
\'menu_name\' => _x( \'Bulletin Board\', \'bulletin_board\' ),
);
$args = array(
\'labels\' => $labels,
\'hierarchical\' => true,
\'description\' => \'Bulletin board for citizen posts\',
\'supports\' => array( \'title\', \'editor\',\'author\'),
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'menu_icon\' => get_bloginfo(\'template_url\') . \'/images/imagegallery.png\',
\'show_in_nav_menus\' => true,
\'publicly_queryable\' => true,
\'exclude_from_search\' => false,
\'has_archive\' => true,
\'query_var\' => true,
\'can_export\' => true,
\'rewrite\' => true,
\'capabilities\' => array(
\'edit_post\' => \'edit_bulletin_board\',
\'edit_posts\' => \'edit_bulletin_boards\',
\'edit_others_posts\' => \'edit_other_bulletin_board\',
\'publish_posts\' => \'publish_bulletin_board\',
\'read_post\' => \'read_bulletin_board\',
\'read_private_posts\' => \'read_private_bulletin_board\',
\'delete_post\' => \'delete_bulletin_board\'
),
\'map_meta_cap\' => true
);
register_post_type( \'bulletin_board\', $args );
}
最后,我将add\\u cap应用于我的角色,其中包括我的新“常驻”角色。。。
$roles = array(\'administrator\',\'resident\',\'editor\');
// Loop through each role and assign capabilities
foreach($roles as $the_role) {
$admins = get_role( $the_role );
$admins->add_cap( \'can_edit_posts\' );
$admins->add_cap( \'edit_bulletin_board\' );
$admins->add_cap( \'edit_bulletin_boards\' );
$admins->add_cap( \'edit_other_bulletin_board\' );
$admins->add_cap( \'publish_bulletin_board\' );
$admins->add_cap( \'read_bulletin_board\' );
$admins->add_cap( \'read_private_bulletin_board\' );
$admins->add_cap( \'delete_bulletin_board\' );
}
现在,当我以“居民”身份登录时,我可以发布公告栏帖子,但该用户无法编辑或删除。从我所读到的内容来看,这些功能应该通过add\\u cap()绑定到register\\u post\\u type()使用的功能数组,情况似乎就是这样。
我还安装了用户角色编辑器插件,我看到了对公告板编辑的检查,但这似乎仍然没有任何意义。
如有任何建议,将不胜感激。