钩子文档

option_page_capability_{$option_page}

💡 云策文档标注

概述

此过滤器用于修改使用 Settings API 时特定选项页面所需的权限。默认情况下,所有注册设置选项组需要 manage_options 权限,此过滤器允许针对特定选项页面调整权限要求。

关键要点

  • 过滤器名称:option_page_capability_{$option_page},其中 {$option_page} 对应选项组(如 register_setting() 的第一个参数)。
  • 默认权限:manage_options,适用于所有注册设置选项组。
  • 参数:$capability(字符串),表示页面所需的权限,默认为 manage_options。
  • 应用场景:可用于自定义权限,例如为通过 add_management_page 添加的页面设置不同权限,而不仅限于 add_options_page。
  • 版本历史:从 WordPress 3.2.0 版本引入。

代码示例

$capability = apply_filters( "option_page_capability_{$option_page}", $capability );

注意事项

  • 注意 {$option_page} 实际指代选项组(如 register_setting() 的第一个参数),因此此过滤器也适用于通过 add_management_page 添加的页面,而不仅仅是 add_options_page。

📄 原文内容

Filters the capability required when using the Settings API.

Description

By default, the options groups for all registered settings require the manage_options capability.
This filter is required to change the capability required for a certain options page.

Parameters

$capabilitystring
The capability used for the page, which is manage_options by default.

Source

$capability = apply_filters( "option_page_capability_{$option_page}", $capability );

Changelog

Version Description
3.2.0 Introduced.

User Contributed Notes