wp_kses_uri_attributes()WP 5.0.1

Получает список HTML-атрибутов, в которых (по спецификации) должен указываться URL-адрес.

В список входят все атрибуты: разрешенные и запрещенные в KSES WP.

1 раз — 0.000001 сек (скорость света) | 50000 раз — 0.10 сек (скорость света) | PHP 7.2.5, WP 5.0.1
Хуки из функции

Возвращает

Строку[]. Cписок HTML-атрибутов.

Использование

wp_kses_uri_attributes();

Примеры

0

#1 Что вернет функция

$uris = wp_kses_uri_attributes();

/* $uris = 
Array
(
	[0] => action
	[1] => archive
	[2] => background
	[3] => cite
	[4] => classid
	[5] => codebase
	[6] => data
	[7] => formaction
	[8] => href
	[9] => icon
	[10] => longdesc
	[11] => manifest
	[12] => poster
	[13] => profile
	[14] => src
	[15] => usemap
	[16] => xmlns
)
*/
0

#2 Очистим значение атрибута в котором указывается URI

Этот демонстрационный пример показывает, как нужно очищать значение атрибута, в котором должен быть URI. По такой логике чистятся значения в WP KSES:

$uris              = wp_kses_uri_attributes();
$allowed_protocols = wp_allowed_protocols();
$attrname          = 'href';
$thisval           = 'http://example.com';

if ( in_array( strtolower($attrname), $uris ) )
	$thisval = wp_kses_bad_protocol( $thisval, $allowed_protocols );

// если $thisval = 'foo://example.com'
echo $thisval; //> //example.com

// если $thisval = 'http://example.com'
echo $thisval; //> http://example.com

Список изменений

С версии 5.0.1 Введена.

Код wp_kses_uri_attributes() WP 6.4.3

function wp_kses_uri_attributes() {
	$uri_attributes = array(
		'action',
		'archive',
		'background',
		'cite',
		'classid',
		'codebase',
		'data',
		'formaction',
		'href',
		'icon',
		'longdesc',
		'manifest',
		'poster',
		'profile',
		'src',
		'usemap',
		'xmlns',
	);

	/**
	 * Filters the list of attributes that are required to contain a URL.
	 *
	 * Use this filter to add any `data-` attributes that are required to be
	 * validated as a URL.
	 *
	 * @since 5.0.1
	 *
	 * @param string[] $uri_attributes HTML attribute names whose value contains a URL.
	 */
	$uri_attributes = apply_filters( 'wp_kses_uri_attributes', $uri_attributes );

	return $uri_attributes;
}