确定是否允许属性。

原型

wp_kses_attr_check( string $name, string $value, string $whole, string $vless, string $element, array $allowed_html )

参数

$name (string) (Required) 属性名称。不允许时返回空字符串。

$value (string) (Required) 属性值。返回过滤的值。

$whole (string) (Required) name = value输入。返回筛选输入。

$vless (string) (Required) ‘y’属性如“启用”,否则为’n’。

$element (string) (Required) 此属性所属的元素的名称。

$allowed_html (array) (Required) 允许的元素和属性的完整列表。

返回值

(bool)  是否允许属性?

源文件

路径:wp-includes/kses.php

<?php
...
function wp_kses_attr_check( &$name, &$value, &$whole, $vless, $element, $allowed_html ) {
	$allowed_attr = $allowed_html[ strtolower( $element ) ];
	$name_low = strtolower( $name );
	if ( ! isset( $allowed_attr[$name_low] ) || '' == $allowed_attr[$name_low] ) {
		/*
		 * Allow `data-*` attributes.
		 *
		 * When specifying `$allowed_html`, the attribute name should be set as
		 * `data-*` (not to be mixed with the HTML 4.0 `data` attribute, see
		 * https://www.w3.org/TR/html40/struct/objects.html#adef-data).
		 *
		 * Note: the attribute name should only contain `A-Za-z0-9_-` chars,
		 * double hyphens `--` are not accepted by WordPress.
		 */
		if ( strpos( $name_low, 'data-' ) === 0 && ! empty( $allowed_attr['data-*'] ) && preg_match( '/^data(?:-[a-z0-9_]+)+$/', $name_low, $match ) ) {
			/*
			 * Add the whole attribute name to the allowed attributes and set any restrictions
			 * for the `data-*` attribute values for the current element.
			 */
			$allowed_attr[ $match[0] ] = $allowed_attr['data-*'];
		} else {
			$name = $value = $whole = '';
			return false;
		}
	}
	if ( 'style' == $name_low ) {
		$new_value = safecss_filter_attr( $value );
		if ( empty( $new_value ) ) {
			$name = $value = $whole = '';
			return false;
		}
		$whole = str_replace( $value, $new_value, $whole );
		$value = $new_value;
	}
	if ( is_array( $allowed_attr[ $name_low ] ) ) {
		// there are some checks
		foreach ( $allowed_attr[$name_low] as $currkey => $currval ) {
			if ( ! wp_kses_check_attr_val( $value, $vless, $currkey, $currval ) ) {
				$name = $value = $whole = '';
				return false;
			}
		}
	}
	return true;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/wp_kses_attr_check/