基本身份验证插件似乎正在修改contributor
用户角色,删除其edit_posts
能力。由于您需要激活此插件,我看到了几个选项
创建一个具有编辑帖子功能的新用户角色创建一个只有所需功能的新角色。这样可以避免干扰现有角色的权限。将这段代码添加到插件主文件中(根据需要更改函数名称、功能和角色数据)。
function add_new_special_rol(){
$role = add_role( \'special_role_slug\', \'Special Role Name\', array(//Capabilities array
\'edit_posts\' => true, // True allows that capability
\'switch_themes\' => false, // False restricts that capability
));
}
function remove_special_rol(){
$role = remove_role(\'special_role_slug\');
}
register_activation_hook( __FILE__, \'add_new_special_rol\' );
register_deactivation_hook( __FILE__, \'remove_special_rol\' );
请记住
add_role
和
remove_role
函数修改数据库,因此
used only when deactivating or activating a plugin/theme, 这就是为什么我们用
register_activation_hook
和
register_deactivation_hook
.
You can see all capabilities available herehttps://wordpress.org/support/article/roles-and-capabilities/#switch_themes
编辑贡献者角色能力
您可以覆盖
edit_posts
对于
contributor
角色
function modify_contributor_role_capabilities($wp_roles){
//We get the contributor role object
$contributor_role = $wp_roles->get_role(\'contributor\');
if($contributor_role)
//then we make them be able to edit posts modifying their capabilities array
$contributor_role->capabilities[\'edit_posts\'] = true;
};
//Hook the function to the \'wp_roles_init\' hook, that gives us access to the WP_Roles instance
//high priority just in case
add_action( \'wp_roles_init\', \'modify_contributor_role_capabilities\', 999 );
在这种情况下,我们将修改
contributor
角色,无需修改数据库。这可以通过
wp_roles_init
行动挂钩,其中
can only be used in a plugin.