wp_kses_attr()
wp_kses_attr( string $element, string $attr, array $all…
wp_kses_attr( string $element, string $attr, array $allowed_html, string[] $allowed_protocols )
如果此元素不允许任何属性,则移除所有属性。
Removes all attributes, if none are allowed for this element.
如果此元素不允许任何属性,则移除所有属性。
Removes all attributes, if none are allowed for this element.
目录锚点:#说明#参数#源码
说明(Description)
如果允许某些代码,则调用wp_kses_hair()进一步拆分它们,然后根据kses_hair()返回的数据构建新的HTML代码。如果还有的字符,也会删除。它要做的另一件事是检查标记是否有结束的XHTML斜杠,如果有,它也会在返回的代码中放入一个。
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $element | (string) | HTML元素/标记。 |
| $attr | (string) | 从HTML元素到结束HTML元素标记的HTML属性。 |
| $allowed_html | (array) | 允许的HTML元素。 |
| $allowed_protocols | (string[]) | 允许的URL协议数组。 |
源码(Source)
/**
* Removes all attributes, if none are allowed for this element.
*
* If some are allowed it calls wp_kses_hair() to split them further, and then
* it builds up new HTML code from the data that kses_hair() returns. It also
* removes "<" and="" "="">" characters, if there are any left. One more thing it does
* is to check if the tag has a closing XHTML slash, and if it does, it puts one
* in the returned code as well.
*
* @since 1.0.0
*
* @param string $element HTML element/tag
* @param string $attr HTML attributes from HTML element to closing HTML element tag
* @param array $allowed_html Allowed HTML elements
* @param array $allowed_protocols Allowed protocols to keep
* @return string Sanitized HTML element
*/
function wp_kses_attr($element, $attr, $allowed_html, $allowed_protocols) {
if ( ! is_array( $allowed_html ) )
$allowed_html = wp_kses_allowed_html( $allowed_html );
// Is there a closing XHTML slash at the end of the attributes?
$xhtml_slash = '';
if (preg_match('%s*/s*$%', $attr))
$xhtml_slash = ' /';
// Are any attributes allowed at all for this element?
if ( ! isset($allowed_html[strtolower($element)]) || count($allowed_html[strtolower($element)]) == 0 )
return "<$element$xhtml_slash>";
// Split it
$attrarr = wp_kses_hair($attr, $allowed_protocols);
// Go through $attrarr, and save the allowed attributes for this element
// in $attr2
$attr2 = '';
foreach ( $attrarr as $arreach ) {
if ( wp_kses_attr_check( $arreach['name'], $arreach['value'], $arreach['whole'], $arreach['vless'], $element, $allowed_html ) ) {
$attr2 .= ' '.$arreach['whole'];
}
}
// Remove any "<" or="" "="">" characters
$attr2 = preg_replace('/[<>]/', '', $attr2);
return "<$element$attr2$xhtml_slash>";
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 1.0.0 | wp-includes/kses.php | 10 | 7 |
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。



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