_wp_kses_directive_binds_value_restricted_attribute()
Determines whether a directive binds an attribute whose value KSES restricts.
This only applies to elements for which KSES restricts the value of at least one attribute. On those elements, a data-wp-bind directive is reported unless it binds an attribute which KSES allows there with any value. KSES calls this to keep such a directive out of content saved by an author who cannot post unfiltered HTML.
Внутренняя функция — эта функция рассчитана на использование самим ядром. Не рекомендуется использовать эту функцию в своем коде.
Хуков нет.
Возвращает
bool. Whether the directive binds an attribute whose value KSES restricts.
Использование
_wp_kses_directive_binds_value_restricted_attribute( $directive_name, $allowed_attributes ): bool;
- $directive_name(строка) (обязательный)
- The directive attribute name, in lowercase.
- $allowed_attributes(массив|true|false) (обязательный)
- The attributes KSES allows on the element.
Список изменений
| С версии 7.1.4 | Введена. |
Код _wp_kses_directive_binds_value_restricted_attribute() wp kses directive binds value restricted attribute WP 7.1.4
function _wp_kses_directive_binds_value_restricted_attribute( string $directive_name, $allowed_attributes ): bool {
if ( ! str_starts_with( $directive_name, 'data-wp-bind--' ) ) {
return false;
}
if ( ! _wp_kses_restricts_attribute_values( $allowed_attributes ) ) {
return false;
}
/*
* Both the whole remainder of the name and the part before a unique ID are checked, so
* that the result does not depend on how the unique ID is parsed. A binding with a unique
* ID is not applied at all, so removing one changes nothing.
*/
$bound_attribute = substr( $directive_name, strlen( 'data-wp-bind--' ) );
$bound_attributes = array( $bound_attribute );
$unique_id_index = strpos( $bound_attribute, '---' );
if ( false !== $unique_id_index ) {
$bound_attributes[] = substr( $bound_attribute, 0, $unique_id_index );
}
foreach ( $bound_attributes as $attribute_name ) {
if ( isset( $allowed_attributes[ $attribute_name ] ) ) {
$rules = $allowed_attributes[ $attribute_name ];
} elseif ( 1 === preg_match( '/^data-[a-z0-9_-]+$/', $attribute_name ) && isset( $allowed_attributes['data-*'] ) ) {
$rules = $allowed_attributes['data-*'];
} else {
return true;
}
if ( ! $rules || is_array( $rules ) ) {
return true;
}
}
return false;
}