钩子文档

auth_{$object_type}_meta_{$meta_key}

💡 云策文档标注

概述

auth_{$object_type}_meta_{$meta_key} 是一个 WordPress 过滤器钩子,用于控制用户是否被允许编辑特定对象类型的特定元键。它通过返回布尔值来影响 map_meta_cap() 函数中的元能力映射。

关键要点

  • 钩子名称包含动态部分:$object_type 表示对象类型,$meta_key 表示元键。
  • 主要参数包括 $allowed(布尔值,默认 false)、$meta_key(字符串)、$object_id(整数)、$user_id(整数)、$cap(字符串)和 $caps(数组)。
  • 返回 true 会使 edit_{$object_type} 相关的元能力映射生效。
  • 该钩子自 WordPress 4.6.0 和 3.3.0 版本引入。

代码示例

$allowed = apply_filters( "auth_{$object_type}_meta_{$meta_key}", $allowed, $meta_key, $object_id, $user_id, $cap, $caps );

📄 原文内容

Filters whether the user is allowed to edit a specific meta key of a specific object type.

Description

Return true to have the mapped meta caps from edit_{$object_type} apply.

The dynamic portion of the hook name, $object_type refers to the object type being filtered.
The dynamic portion of the hook name, $meta_key, refers to the meta key passed to map_meta_cap() .

Parameters

$allowedbool
Whether the user can add the object meta. Default false.
$meta_keystring
The meta key.
$object_idint
Object ID.
$user_idint
User ID.
$capstring
Capability name.
$capsstring[]
Array of the user’s capabilities.

Source

$allowed = apply_filters( "auth_{$object_type}_meta_{$meta_key}", $allowed, $meta_key, $object_id, $user_id, $cap, $caps );

Changelog

Version Description
4.6.0
3.3.0 Introduced.