wp-cli/role-command

添加、删除、列出和重置角色和权限。

安装次数: 4,645,657

依赖关系: 3

建议者: 0

安全性: 0

星星: 5

关注者: 8

分支: 11

开放问题: 0

类型:wp-cli-package

v2.0.14 2023-08-30 16:18 UTC

README

添加、删除、列出和重置角色和权限。

Testing

快速链接: 使用 | 安装 | 贡献 | 支持

使用

本包实现了以下命令

wp role

管理用户角色,包括创建新角色和重置为默认值。

wp role

请参阅有关角色和权限以及WP User类的参考资料。

示例

# List roles.
$ wp role list --fields=role --format=csv
role
administrator
editor
author
contributor
subscriber

# Check to see if a role exists.
$ wp role exists editor
Success: Role with ID 'editor' exists.

# Create a new role.
$ wp role create approver Approver
Success: Role with key 'approver' created.

# Delete an existing role.
$ wp role delete approver
Success: Role with key 'approver' deleted.

# Reset existing roles to their default capabilities.
$ wp role reset administrator author contributor
Success: Reset 3/3 roles.

wp role create

创建一个新角色。

wp role create <role-key> <role-name> [--clone=<role>]

选项

<role-key>
	The internal name of the role.

<role-name>
	The publicly visible name of the role.

[--clone=<role>]
	Clone capabilities from an existing role.

示例

# Create role for Approver.
$ wp role create approver Approver
Success: Role with key 'approver' created.

# Create role for Product Administrator.
$ wp role create productadmin "Product Administrator"
Success: Role with key 'productadmin' created.

wp role delete

删除一个现有角色。

wp role delete <role-key>

选项

<role-key>
	The internal name of the role.

示例

# Delete approver role.
$ wp role delete approver
Success: Role with key 'approver' deleted.

# Delete productadmin role.
wp role delete productadmin
Success: Role with key 'productadmin' deleted.

wp role exists

检查角色是否存在。

wp role exists <role-key>

如果角色存在,则退出时返回代码0,如果不存在,则返回1。

选项

<role-key>
	The internal name of the role.

示例

# Check if a role exists.
$ wp role exists editor
Success: Role with ID 'editor' exists.

wp role list

列出所有角色。

wp role list [--fields=<fields>] [--field=<field>] [--format=<format>]

选项

[--fields=<fields>]
	Limit the output to specific object fields.

[--field=<field>]
	Prints the value of a single field.

[--format=<format>]
	Render output in a particular format.
	---
	default: table
	options:
	  - table
	  - csv
	  - json
	  - count
	  - yaml
	---

可用字段

以下字段将默认显示在每个角色中

  • name
  • role

没有可选字段。

示例

# List roles.
$ wp role list --fields=role --format=csv
role
administrator
editor
author
contributor
subscriber

wp role reset

将任何默认角色重置为默认权限。

wp role reset [<role-key>...] [--all]

使用WordPress的populate_roles()函数将一个或多个角色恢复到新WordPress安装时的状态。删除添加的任何权限,并恢复删除的任何权限。自定义角色不受影响。

选项

[<role-key>...]
	The internal name of one or more roles to reset.

[--all]
	If set, all default roles will be reset.

示例

# Reset three roles.
$ wp role reset administrator author contributor
Restored 1 capability to and removed 0 capabilities from 'administrator' role.
No changes necessary for 'author' role.
No changes necessary for 'contributor' role.
Success: 1 of 3 roles reset.

# Reset a custom role.
$ wp role reset custom_role
Custom role 'custom_role' not affected.
Error: Must specify a default role to reset.

# Reset all default roles.
$ wp role reset --all
Success: All default roles reset.

wp cap

添加、删除和列出用户角色的权限。

wp cap

请参阅有关角色和权限以及WP User类的参考资料。

示例

# Add 'spectate' capability to 'author' role.
$ wp cap add 'author' 'spectate'
Success: Added 1 capability to 'author' role.

# Add all caps from 'editor' role to 'author' role.
$ wp cap list 'editor' | xargs wp cap add 'author'
Success: Added 24 capabilities to 'author' role.

# Remove all caps from 'editor' role that also appear in 'author' role.
$ wp cap list 'author' | xargs wp cap remove 'editor'
Success: Removed 34 capabilities from 'editor' role.

wp cap add

向指定的角色添加权限。

wp cap add <role> <cap>... [--grant]

选项

<role>
	Key for the role.

<cap>...
	One or more capabilities to add.

[--grant]
	Adds the capability as an explicit boolean value, instead of implicitly defaulting to `true`.
	---
	default: true
	options:
	  - true
	  - false
	---

示例

# Add 'spectate' capability to 'author' role.
$ wp cap add author spectate
Success: Added 1 capability to 'author' role.

wp cap list

列出指定角色的权限。

wp cap list <role> [--format=<format>] [--show-grant]

选项

<role>
	Key for the role.

[--format=<format>]
	Render output in a particular format.
	---
	default: list
	options:
	  - list
	  - table
	  - csv
	  - json
	  - count
	  - yaml
	---

[--show-grant]
	Display all capabilities defined for a role including grant.
	---
	default: false
	---

示例

# Display alphabetical list of Contributor capabilities.
$ wp cap list 'contributor' | sort
delete_posts
edit_posts
level_0
level_1
read

wp cap remove

从指定角色中删除权限。

wp cap remove <role> <cap>...

选项

<role>
	Key for the role.

<cap>...
	One or more capabilities to remove.

示例

# Remove 'spectate' capability from 'author' role.
$ wp cap remove author spectate
Success: Removed 1 capability from 'author' role.

安装

此包包含在WP-CLI本身中,无需额外安装。

要安装此包的最新版本,覆盖WP-CLI中包含的版本,请运行

wp package install [email protected]:wp-cli/role-command.git

贡献

我们感谢您主动为该项目做出贡献。

贡献不仅限于代码。我们鼓励您根据您的能力以最适合的方式做出贡献,例如撰写教程、在当地聚会中提供演示、帮助其他用户解决支持问题或修订我们的文档。

有关更详细的介绍,请查看WP-CLI贡献指南。本包遵循那些政策和指南。

报告错误

你认为你发现了一个错误?我们非常希望你能帮助我们修复它。

在创建新问题之前,你应该搜索现有问题,看看是否已经有了对该错误的现有解决方案,或者它是否已经被较新版本修复。

一旦你进行了一些搜索并发现没有针对你错误的开放或已解决的问题,请创建一个新问题。尽可能提供详细信息,如果可能的话,提供清晰的复现步骤。有关更多指导,请查看我们的错误报告文档

创建拉取请求

想要贡献一个新功能?请首先创建一个新问题来讨论这个功能是否适合本项目。

一旦你决定投入时间来完成你的拉取请求,请遵循我们的创建拉取请求指南,以确保这是一次愉快的体验。关于本地工作的具体细节,请查看"设置"。

支持

GitHub问题不是用于一般性支持问题的地方,但你可以尝试其他途径:https://wp-cli.org/#support

此README.md是通过使用wp scaffold package-readme文档)从项目的代码库动态生成的。如需提出更改建议,请向代码库的相应部分提交拉取请求。