钩子文档

customize_sanitize_js_{$this->id}

💡 云策文档标注

概述

此文档介绍 WordPress 自定义器设置中用于 JavaScript 的过滤器钩子 customize_sanitize_js_{$this->id},它允许开发者对设置值进行过滤以便在 JavaScript 中使用。

关键要点

  • 钩子名称的动态部分 {$this->id} 对应设置 ID,用于针对特定设置进行过滤。
  • 参数包括 $value(设置值)和 $setting(WP_Customize_Setting 实例),用于在过滤器中处理值。
  • 此钩子在 WP_Customize_Setting::js_value() 方法中被调用,用于在 JavaScript 中安全使用设置值。
  • 自 WordPress 3.4.0 版本引入,是自定义器 API 的一部分。

📄 原文内容

Filters a Customize setting value for use in JavaScript.

Description

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

Parameters

$valuemixed
The setting value.
$settingWP_Customize_Setting

Source

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

Changelog

Version Description
3.4.0 Introduced.