pre_kses
云策文档标注
概述
pre_kses 是一个 WordPress 过滤器,用于在内容通过 KSES(KSES Strips Evil Scripts)处理前进行过滤。它允许开发者自定义允许的 HTML 元素、属性或上下文名称,从而增强内容安全性和灵活性。
关键要点
- pre_kses 过滤器在 KSES 处理前应用,用于修改允许的 HTML 元素、属性或上下文名称。
- 参数包括 $content(要过滤的内容)、$allowed_html(允许的 HTML 元素和属性数组或上下文名称如 'post')和 $allowed_protocols(允许的 URL 协议数组)。
- KSES 是递归缩写,意为“KSES 剥离恶意脚本”,用于防止不安全 HTML 在 WordPress 内容中执行。
- 该过滤器自 WordPress 2.3.0 版本引入,相关函数如 wp_kses_hook() 可用于添加 KSES 钩子。
代码示例
return apply_filters( 'pre_kses', $content, $allowed_html, $allowed_protocols );
原文内容
Filters content to be run through KSES.
Parameters
$contentstring-
Content to filter through KSES.
$allowed_htmlarray[]|string-
An array of allowed HTML elements and attributes, or a context name such as
'post'. See wp_kses_allowed_html() for the list of accepted context names. $allowed_protocolsstring[]-
Array of allowed URL protocols.
Source
return apply_filters( 'pre_kses', $content, $allowed_html, $allowed_protocols );
Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |