我想让自定义用户角色'cm'只能看到'cm approved'和'cm rejected',而'rm'只会在发布元中看到'cm approved','rm approved','rm rejected'框。 请参阅下面的截图,谢谢!
答案 0 :(得分: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;
}