我想让自定义用户角色” cm”仅在”发布元”框中看到” cm批准”和” cm被拒绝”, ” rm”仅看到” cm批准”, ” rm批准”, ” rm被拒绝”。请看下面的屏幕截图, 谢谢!
#1
我在聚会中与一位WordPress专家交谈后才找到解决方案。当我使用”编辑流程”时, 一切变得很容易。我建议你也安装该工具。
add_filter('ef_custom_status_list', 'custom_by_roles');
function custom_by_roles($custom_statuses){
$current_user = wp_get_current_user();
$permitted_statuses = array();
if ($current_user -> roles[0] == 'cm'){
$permitted_statuses = array(
'cm-approved', 'cm-rejected', 'received'
);
}elseif ($current_user -> roles[0] == 'rm'){
$permitted_statuses = array(
'cm-approved', 'rm-approved', 'rm-rejected'
);
}
foreach($custom_statuses as $key => $custom_status){
if(!in_array($custom_status->slug, $permitted_statuses))
unset($custom_statuses[$key]);
}
return $custom_statuses;
}
评论前必须登录!
注册