map_meta_cap
云策文档标注
概述
map_meta_cap 是一个 WordPress 过滤器,用于映射用户能力检查所需的原始能力。它允许开发者自定义能力检查的逻辑,基于用户ID和上下文参数。
关键要点
- 过滤器名称:map_meta_cap,用于过滤用户满足特定能力所需的原始能力列表。
- 参数:包括原始能力数组 $caps、被检查的能力 $cap、用户ID $user_id 和上下文参数数组 $args。
- 应用场景:常用于自定义权限系统,如基于对象ID(如文章或页面)动态调整用户能力。
- 相关函数:map_meta_cap() 函数在 wp-includes/capabilities.php 中实现此映射逻辑。
- 版本历史:自 WordPress 2.8.0 版本引入。
原文内容
Filters the primitive capabilities required of the given user to satisfy the capability being checked.
Parameters
$capsstring[]-
Primitive capabilities required of the user.
$capstring-
Capability being checked.
$user_idint-
The user ID.
$argsarray-
Adds context to the capability check, typically starting with an object ID.
Source
return apply_filters( 'map_meta_cap', $caps, $cap, $user_id, $args );
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |