在我的代码中,我有一个自定义的帖子类型job.我创建了一个名为job manager.Now的角色,我想为职务manager.Only授予添加、编辑、删除职务的权限他可以访问职务帖子type.hoe w来实现这一点...
我尝试通过以下代码创建作业经理角色
function add_job_manager_role(){
add_role(
'job_manager',
'Job Manager',
array(
'read' => true,
'edit_posts' => false,
'delete_posts' => false,
'publish_posts' => false,
'upload_files' => true
)
);
}
add_action( 'admin_init', 'add_job_manager_role', 4 ); 如何授予作业经理添加、删除、编辑自定义帖子类型作业的权限
任何帮助都非常感谢提前.Thanks ...
发布于 2019-09-16 17:09:29
当您添加角色时,您还必须添加功能,如下所示:
/**
add CPT capabilites to Role
*/
add_action('admin_init','o99_add_role_caps',999);
function o99_add_role_caps() {
$role = get_role('my_role'); // ex. job_manager
$role->add_cap( 'read_my_CPT');
$role->add_cap( 'edit_my_CPT' );
$role->add_cap( 'edit_my_CPT' );
$role->add_cap( 'edit_other_my_CPT' );
$role->add_cap( 'edit_published_my_CPT' );
$role->add_cap( 'publish_my_CPT' );
$role->add_cap( 'read_private_my_CPT' );
$role->add_cap( 'delete_my_CPT' );
}当然,当您在创建或修改功能参数时,my_CPT是您的自定义帖子类型,您所做的事情如下:
function change_capabilities_of_CPT( $args, $post_type ){
// Do not filter any other post type
if ( 'my_CPT' !== $post_type ) { // my_CPT == Custom Post Type == 'job' or other
// if other post_types return original arguments
return $args;
}
// This is the important part of the capabilities
/// which you can also do on creation ( and not by filtering like in this example )
// Change the capabilities of my_CPT post_type
$args['capabilities'] = array(
'edit_post' => 'edit_my_CPT',
'edit_posts' => 'edit_my_CPT',
'edit_others_posts' => 'edit_other_my_CPT',
'publish_posts' => 'publish_my_CPT',
'read_post' => 'read_my_CPT ',
'read_private_posts' => 'read_private_my_CPT',
'delete_post' => 'delete_my_CPT'
);
// Return the new arguments
return $args;
}编辑我
有关详细信息,请访问:
为了能够控制CPT,每个操作都涉及其他几个capabilities。
例如,为了publish_my_CPT和为了编辑,你需要edit_my_CPT && edit_other_my_CPT && read_my_CPT && read_private_my_CPT等等。请查看capabilities in the Codex,通过发布的代码,您可以将_my_CPT (例如- _job或其他任何CPT )添加到这些功能中,从而使您能够获得所需的结果。
https://stackoverflow.com/questions/57952159
复制相似问题