简单方法:使用此插件https://wordpress.org/plugins/user-role-editor/
更复杂的方式:您可以使用函数。php将所有自定义功能添加到特定角色。但ofc需要这些功能的名称。
如果要向X个角色添加X个相同的功能,则此代码非常有用。
添加到函数。php
function wphm_add_custom_capabilities_to_roles($roles, $capabilities) {
foreach($roles as $the_role) {
$role = get_role($the_role);
foreach($capabilities as $capability) {
$role -> add_cap($capability);
}
}
}
wphm_add_custom_capabilities_to_roles(
array( // these roles will recieve capabilities
\'custom_user_role_wphm_support\',
\'administrator\'
),
array( // capabilities
"read_wphm_custom",
"read_private_wphm_custom",
"edit_wphm_custom",
"edit_others_wphm_custom",
"edit_published_wphm_custom",
"publish_wphm_custom",
"delete_others_wphm_custom",
"delete_private_wphm_custom",
"delete_published_wphm_custom"
)
);
要使用此循环删除功能,只需修改一行$角色->add\\u cap($功能);至$角色->删除\\u上限($功能)