我在我的functions.php文件中的WordPress中创建了新用户role (Manager)
。这是我的代码,但不起作用。管理员仅阅读帖子,无法编辑和删除。怎么了?
谢谢。
function ui_new_role() {
//add the new user role
add_role(
'manager',
'Manager',
array(
'edit_' => true,
'read_' => true,
'delete_' => true,
'edit_s' => true,
'edit_others_s' => true,
'publish_s' => true,
'read_private_s' => true,
'delete_s' => true,
'delete_private_s' => true,
'delete_published_s' => true,
'delete_others_s' => true,
'edit_private_s' => true,
'edit_published_s' => true,
)
);
}
add_action('admin_init', 'ui_new_role');
答案 0 :(得分:3)
创建一个新的“经理”角色。
$result = add_role(
'manager',
__( 'Manager' ),
array(
'read' => true, // true allows this capability
'edit_posts' => true,
'delete_posts' => true, // Use false to explicitly deny
)
);
if ( null !== $result ) {
echo 'New role created!';
}
else {
echo 'Manager role already exists.';
}
答案 1 :(得分:2)
根据documentation,您添加的角色不正确。您的特权名称与我所知不符。我认为最好通过插件添加。
function add_mgr_role()
{
add_role(
'manager',
'Manager',
array(
'read' => true,
'edit_posts' => true,
'delete_posts' => true
)
);
}
register_activation_hook(__FILE__, 'add_mgr_role');