这就是我所做的,我没有授予订阅者所有这些权限,而是将所有订阅者升级为贡献者。
我将自定义帖子类型的功能更改为:
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'boat' ),
'capability_type' => 'post',
'capabilities' => array(
'publish_posts' => 'edit_posts',//contributor can edit
'edit_others_posts' => 'update_core',//administrator can see other
'delete_posts' => 'update_core',//administrator can see other
'delete_others_posts' => 'update_core',//administrator can see other
'read_private_posts' => 'update_core',//administrator can see other
'edit_post' => 'edit_posts',//contributor can edit
'delete_post' => 'update_core',//administrator can see other
'read_post' => 'edit_posts',//contributor can edit
),
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title','revision' )
);
register_post_type("boat", $args);
然后我添加了一些我在不同网页上找到的自定义功能:
这个隐藏了我不想让投稿人看到的菜单
来源:来源 1
和:来源 2
function remove_menus(){
$author = wp_get_current_user();
if(isset($author->roles[0])){
$current_role = $author->roles[0];
}else{
$current_role = 'no_role';
}
if($current_role == 'contributor'){
remove_menu_page( 'index.php' ); //Dashboard
remove_menu_page( 'edit.php' ); //Posts
remove_menu_page( 'upload.php' ); //Media
remove_menu_page( 'tools.php' ); //Tools
remove_menu_page( 'edit-comments.php' ); //Comments
remove_menu_page( 'edit.php?post_type=my_other_custom_post_type_I_want_to_hide' );
}
}
add_action( 'admin_menu', 'remove_menus' );
然后我限制投稿人使用:来自:source 3
add_action( 'load-edit.php', 'posts_for_current_contributor' );
function posts_for_current_contributor() {
global $user_ID;
if ( current_user_can( 'contributor' ) ) {
if ( ! isset( $_GET['author'] ) ) {
wp_redirect( add_query_arg( 'author', $user_ID ) );
exit;
}
}
}
最后我允许贡献者上传文件 : from source 4
add_action('admin_init', 'allow_contributor_uploads');
function allow_contributor_uploads() {
$contributor = get_role('contributor');
$contributor->add_cap('upload_files');
}
由于我使用ACF(高级自定义字段)制作的自定义帖子类型中有一堆自定义字段,因此我将媒体上传限制为仅本地帖子,因此我的投稿人无法使用其他人的媒体。
我希望这会对某人有所帮助!:)