remove_role()
云策文档标注
概述
remove_role() 函数用于从 WordPress 中移除一个角色,前提是该角色存在。它通过调用全局 WP_Roles 实例的 remove_role 方法实现。
关键要点
- 函数接受一个必需参数 $role,指定要移除的角色名称。
- 内部实现依赖于 wp_roles() 函数获取 WP_Roles 实例,并调用其 remove_role() 方法。
- 此函数自 WordPress 2.0.0 版本引入,用于管理用户角色。
代码示例
// 移除 'subscriber' 角色(如果存在)
remove_role( 'subscriber' );
原文内容
Removes a role, if it exists.
Parameters
$rolestringrequired-
Role name.
Source
function remove_role( $role ) {
wp_roles()->remove_role( $role );
}
Changelog
| Version | Description |
|---|---|
| 2.0.0 | Introduced. |
Skip to note 2 content
Codex
Example
Remove the ‘subscriber’ role if it exists.