wp_pre_kses_less_than()
云策文档标注
概述
wp_pre_kses_less_than() 是一个 WordPress 函数,用于在 KSES 处理前转换文本中的孤立小于符号,以防止 HTML 解析问题。它作为内部辅助函数,常用于 sanitize_text_fields() 等函数中。
关键要点
- 函数作用:将文本中的孤立小于符号(如 <)转换为 HTML 实体(如 <),以配合 KSES 处理。
- 参数:接受一个字符串参数 $content,表示要转换的文本。
- 返回值:返回转换后的字符串。
- 实现方式:使用 preg_replace_callback 和回调函数 wp_pre_kses_less_than_callback 进行正则匹配和替换。
- 相关函数:与 wp_pre_kses_less_than_callback 和 sanitize_text_fields() 关联。
- 版本历史:自 WordPress 2.3.0 版本引入。
代码示例
function wp_pre_kses_less_than( $content ) {
return preg_replace_callback( '%]*?((?=|$)%', 'wp_pre_kses_less_than_callback', $content );
}
原文内容
Converts lone less than signs.
Description
KSES already converts lone greater than signs.
Parameters
$contentstringrequired-
Text to be converted.
Source
function wp_pre_kses_less_than( $content ) {
return preg_replace_callback( '%<[^>]*?((?=<)|>|$)%', 'wp_pre_kses_less_than_callback', $content );
}
Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |