如何在 Wordpress 中创建自定义用户角色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12985692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:02:49  来源:igfitidea点击:

How To Create Custom User Role in Wordpress

wordpress

提问by Niraj Desai

I have to create a Reviewer (custom) role for users in WordPress , how can I create a custom rule ?

我必须在 WordPress 中为用户创建一个审阅者(自定义)角色,我该如何创建自定义规则?

回答by The Alpha

You can use add rolefunction like

您可以使用添加角色功能,如

<?php add_role( $role, $display_name, $capabilities ); ?>

Example

例子

add_role('basic_contributor', 'Basic Contributor', array(
    'read' => true, // True allows that capability
    'edit_posts' => true,
    'delete_posts' => false, // Use false to explicitly deny
));

Also see this tutorial (custom rule discussed)and this plugin too if you don't want to write any code.

如果您不想编写任何代码,请参阅本教程(讨论自定义规则)本插件。

回答by Colorful Tones

If you're not looking to write a lot of code, but want to use a plugin then I highly recommend Justin Tadlock's Members plugin: https://wordpress.org/extend/plugins/members/

如果您不想编写大量代码,但想使用插件,那么我强烈推荐 Justin Tadlock 的会员插件:https: //wordpress.org/extend/plugins/members/

It should easily offer the functionality you seek.

它应该很容易提供您寻求的功能。

Good luck!

祝你好运!

回答by Mitul Shah

It is better to use plugin so You can add/edit capability for specific users too. There are 2 good plugins available

最好使用插件,以便您也可以为特定用户添加/编辑功能。有 2 个不错的插件可用

User Role Editor

用户角色编辑器

and

Capability Manager Enhanced

能力管理器增强

回答by Mustaasam Saleem

You can delete WordPress Default User Roles and create your own.

您可以删除 WordPress 默认用户角色并创建自己的角色。

From your WordPress Admin Panel. Navigate to:

从您的 WordPress 管理面板。导航:

Appearance > Editor > (Choose Your Theme) > Theme functions

外观>编辑器>(选择你的主题)>主题功能

add_role('newbie', __(
 'Newbie'),
 array(
 'read' => true, // Allows user to read
 'create_posts' => true, // Allows user to create new posts
 'edit_posts' => true, // Allows user to edit their own posts
 )
);

Source

来源