pre_set_theme_mod_{$name}
云策文档标注
概述
pre_set_theme_mod_{$name} 是一个动态 Hook,用于在保存主题修改值时进行过滤。它允许开发者在设置主题选项前拦截和修改值。
关键要点
- 这是一个动态 Hook,$name 部分对应主题修改数组的键名,如 'header_textcolor' 或 'header_image'。
- 参数包括 $value(新值)和 $old_value(当前值),可用于验证或调整修改。
- Hook 在 set_theme_mod() 函数中被调用,影响主题修改的保存过程。
代码示例
$mods[ $name ] = apply_filters( "pre_set_theme_mod_{$name}", $value, $old_value );注意事项
- Hook 从 WordPress 3.9.0 版本开始引入,使用时需确保兼容性。
- 开发者应谨慎处理 $value 和 $old_value,避免意外修改主题数据。
原文内容
Filters the theme modification, or ‘theme_mod’, value on save.
Description
The dynamic portion of the hook name, $name, refers to the key name of the modification array. For example, ‘header_textcolor’, ‘header_image’, and so on depending on the theme options.
Parameters
$valuemixed-
The new value of the theme modification.
$old_valuemixed-
The current value of the theme modification.
Source
$mods[ $name ] = apply_filters( "pre_set_theme_mod_{$name}", $value, $old_value );
Changelog
| Version | Description |
|---|---|
| 3.9.0 | Introduced. |