kses_remove_filters()
云策文档标注
概述
kses_remove_filters() 是一个快速移除所有 KSES 输入表单内容过滤器的过程函数。它主要用于在 WordPress Loop 中移除 KSES 对内容应用的过滤器,但不会移除 kses_init() 函数从 'init' 和 'set_current_user' 钩子中的注册。
关键要点
- 移除 KSES 在标题、评论、全局样式和文章内容保存时的过滤器,包括 wp_filter_kses 和 wp_filter_post_kses 等。
- 不会影响 kses_init() 函数在 'init' 和 'set_current_user' 钩子中的默认优先级注册。
- 适用于需要临时禁用 KSES 过滤的场景,如自定义内容处理或调试。
代码示例
function kses_remove_filters() {
// Normal filtering.
remove_filter( 'title_save_pre', 'wp_filter_kses' );
// Comment filtering.
remove_filter( 'pre_comment_content', 'wp_filter_post_kses' );
remove_filter( 'pre_comment_content', 'wp_filter_kses' );
// Global Styles filtering.
remove_filter( 'content_save_pre', 'wp_filter_global_styles_post', 9 );
remove_filter( 'content_filtered_save_pre', 'wp_filter_global_styles_post', 9 );
// Post filtering.
remove_filter( 'content_save_pre', 'wp_filter_post_kses' );
remove_filter( 'excerpt_save_pre', 'wp_filter_post_kses' );
remove_filter( 'content_filtered_save_pre', 'wp_filter_post_kses' );
}注意事项
- KSES 是“KSES Strips Evil Scripts”的递归缩写,是一个 PHP 编写的 HTML/XHTML 过滤器,用于移除恶意脚本和防止跨站脚本攻击(XSS)。
- 使用此函数可能降低内容安全性,建议仅在必要时调用,并确保后续恢复或采取其他安全措施。
原文内容
Removes all KSES input form content filters.
Description
A quick procedural method to removing all of the filters that KSES uses for content in WordPress Loop.
Does not remove the kses_init() function from ‘init’ hook (priority is default). Also does not remove kses_init() function from ‘set_current_user’ hook (priority is also default).
Source
function kses_remove_filters() {
// Normal filtering.
remove_filter( 'title_save_pre', 'wp_filter_kses' );
// Comment filtering.
remove_filter( 'pre_comment_content', 'wp_filter_post_kses' );
remove_filter( 'pre_comment_content', 'wp_filter_kses' );
// Global Styles filtering.
remove_filter( 'content_save_pre', 'wp_filter_global_styles_post', 9 );
remove_filter( 'content_filtered_save_pre', 'wp_filter_global_styles_post', 9 );
// Post filtering.
remove_filter( 'content_save_pre', 'wp_filter_post_kses' );
remove_filter( 'excerpt_save_pre', 'wp_filter_post_kses' );
remove_filter( 'content_filtered_save_pre', 'wp_filter_post_kses' );
}
Changelog
| Version | Description |
|---|---|
| 2.0.6 | Introduced. |
Skip to note 2 content
a4jp
Notes: KSES is a recursive acronym which stands for “KSES Strips Evil Scripts”. KSES is an HTML/XHTML filter written in PHP. It removes all unwanted HTML elements and attributes, and it also does several checks on attribute values. KSES can be used to avoid Cross-Site Scripting (XSS).