钩子文档

customize_validate_{$this->id}

💡 云策文档标注

概述

本文档介绍了 WordPress 自定义设置验证钩子 customize_validate_{$this->id},用于验证 Customize 设置值。开发者可通过此钩子修改验证结果,确保设置值的有效性。

关键要点

  • 钩子名称 customize_validate_{$this->id} 是动态的,其中 $this->id 指代设置 ID。
  • 验证时,插件应使用 WP_Error::add() 方法修改 $validity 对象,以指示验证失败。
  • 钩子参数包括 $validity(WP_Error 对象,初始为 true)、$value(设置值)和 $setting(WP_Customize_Setting 实例)。
  • 此钩子在 WP_Customize_Setting::validate() 方法中使用,自 WordPress 4.6.0 版本引入。

📄 原文内容

Validates a Customize setting value.

Description

Plugins should amend the $validity object via its WP_Error::add() method.

The dynamic portion of the hook name, $this->ID, refers to the setting ID.

Parameters

$validityWP_Error
Filtered from true to WP_Error when invalid.
$valuemixed
Value of the setting.
$settingWP_Customize_Setting

Source

$validity = apply_filters( "customize_validate_{$this->id}", $validity, $value, $this );

Changelog

Version Description
4.6.0 Introduced.