# wp_kses_bad_protocol()

URL: https://chugunov.pro/api-wordpress/functions/wp_kses_bad_protocol/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 1.0.0.

## Сигнатура

```php
wp_kses_bad_protocol( string $content, string[] $allowed_protocols ): string
```

## Описание

Удаляет все недопустимые протоколы в начале строки. Игнорирует пробельные символы и регистр букв, а также распознаёт HTML-сущности. Работает рекурсивно, поэтому её не обмануть строкой вроде javascript:javascript:alert(57).

## Параметры

- `$content` `string` — обязательный. Содержимое, из которого нужно отфильтровать плохие протоколы.
- `$allowed_protocols` `string[]` — обязательный. Массив разрешённых URL-протоколов.

## Возвращаемое значение

`string`

## Исходный код

Файл: `wp-includes/kses.php:1894`

```php
function wp_kses_bad_protocol( $content, $allowed_protocols ) {
	$content = wp_kses_no_null( $content );

	// Short-circuit if the string starts with `https://` or `http://`. Most common cases.
	if (
		( str_starts_with( $content, 'https://' ) && in_array( 'https', $allowed_protocols, true ) ) ||
		( str_starts_with( $content, 'http://' ) && in_array( 'http', $allowed_protocols, true ) )
	) {
		return $content;
	}

	$iterations = 0;

	do {
		$original_content = $content;
		$content          = wp_kses_bad_protocol_once( $content, $allowed_protocols );
	} while ( $original_content !== $content && ++$iterations < 6 );

	if ( $original_content !== $content ) {
		return '';
	}

	return $content;
}
```

## История изменений

- 1.0.0 — Introduced.

## Связанные

Использует: [`wp_kses_no_null`](https://chugunov.pro/api-wordpress/functions/wp_kses_no_null/), [`wp_kses_bad_protocol_once`](https://chugunov.pro/api-wordpress/functions/wp_kses_bad_protocol_once/).
Используется в: [`wp_kses_one_attr`](https://chugunov.pro/api-wordpress/functions/wp_kses_one_attr/), [`esc_url`](https://chugunov.pro/api-wordpress/functions/esc_url/), [`safecss_filter_attr`](https://chugunov.pro/api-wordpress/functions/safecss_filter_attr/), [`wp_kses_hair`](https://chugunov.pro/api-wordpress/functions/wp_kses_hair/), `WP_Http::request`, [`wp_http_validate_url`](https://chugunov.pro/api-wordpress/functions/wp_http_validate_url/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/wp_kses_bad_protocol/
