WordPress 函数:wp_kses

这个函数确保只有被允许的 HTML 标签和属性名,属性值,以及一些正确的 HTML 实体出现在 $string 中,在调用这个函数之前,需要先移除 PHP magic quotes 生成的 / 。

用法

<?php wp_kses($string, $allowed_html, $allowed_protocols); ?>

参数

$string
(string) (required) 将通过 kses 过滤的内容
Default: None

$allowed_html
(array) (required) 允许的 HTML 标签列表
Default: None

$allowed_protocols
(array) (optional) $string 中的链接允许的协议
Default: 默认的协议是:http, https, ftp, mailto, news, irc, gopher, nntp, feed, 和 telnet。 这个基本覆盖了大部分的链接协议,除了 javascript,它不允许被一些不受信任用户使用。

返回值

(string)
过滤了不合法 HTML 代码之后的字符串。

注解

下面是一个创建允许的HTML标签和属性的实例:

array(
    'a' => array(
        'href' => array(),
        'title' => array()
    ),
    'br' => array(),
    'em' => array(),
    'strong' => array()
);

修改记录

Since: 1.0.0

源文件

wp-includes/kses.php