wp_kses()
wp_kses( string $string, array[]|string $allowed_html, …
wp_kses( string $string, array[]|string $allowed_html, string[] $allowed_protocols = array() )
过滤文本内容并去掉不允许的HTML。
Filters text content and strips out disallowed HTML.
目录锚点:#说明#参数#源码#笔记
说明(Description)
此函数确保给定的文本字符串中只出现允许的HTML元素名、属性名、属性值和HTML实体。此函数需要无斜杠的数据。另请参阅wp_kses_post():以获取有关筛选帖子内容和字段的详细信息。wp_allowed_protocols():用于链接URL中的默认允许协议。
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $string | (string) | 要筛选的文本内容。 |
| $allowed_html | (array[] | string) | 允许的HTML元素和属性的数组,或上下文名称,如“post”。 |
| $allowed_protocols | (string[]) | 允许的URL协议数组。 |
源码(Source)
/**
* Filters content and keeps only allowable HTML elements.
*
* This function makes sure that only the allowed HTML element names, attribute
* names and attribute values plus only sane HTML entities will occur in
* $string. You have to remove any slashes from PHP's magic quotes before you
* call this function.
*
* The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news',
* 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This
* covers all common link protocols, except for 'javascript' which should not
* be allowed for untrusted users.
*
* @since 1.0.0
*
* @param string $string Content to filter through kses
* @param array $allowed_html List of allowed HTML elements
* @param array $allowed_protocols Optional. Allowed protocol in links.
* @return string Filtered content with only allowed HTML elements
*/
function wp_kses( $string, $allowed_html, $allowed_protocols = array() ) {
if ( empty( $allowed_protocols ) )
$allowed_protocols = wp_allowed_protocols();
$string = wp_kses_no_null( $string, array( 'slash_zero' => 'keep' ) );
$string = wp_kses_js_entities($string);
$string = wp_kses_normalize_entities($string);
$string = wp_kses_hook($string, $allowed_html, $allowed_protocols); // WP changed the order of these funcs and added args to wp_kses_hook
return wp_kses_split($string, $allowed_html, $allowed_protocols);
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 1.0.0 | wp-includes/kses.php | 11 | 20 |
笔记(Notes)
WordPress中的许多函数名都是不言而喻的,如果它们不是,它们的文档通常会揭示它们是如何获得它们的名称的。我发现这使得以后更容易回忆起它们的名字和用途。然而,wp_kes是一个例外。所以对于其他人来说:
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

还没有任何评论,赶紧来占个楼吧!