# sanitize_url()

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

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

> Устаревший элемент. Помечен устаревшим с версии 5.9.0.

## Сигнатура

```php
sanitize_url( string $url, string[] $protocols = null ): string
```

## Описание

См. alsoesc_url()

## Параметры

- `$url` `string` — обязательный. URL, который нужно очистить.
- `$protocols` `string[]` — необязательный, по умолчанию `null`. Массив допустимых протоколов.
  
  По умолчанию — возвращаемое значение wp_allowed_protocols() .

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

`string` — esc_url() 'db'

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

Файл: `wp-includes/formatting.php:4618`

```php
function sanitize_url( $url, $protocols = null ) {
	return esc_url( $url, $protocols, 'db' );
}
```

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

- 6.9.0 — Prepends https:// to the URL if it does not already contain a scheme and the first item in $protocols is 'https'.
- 5.9.0 — Restored (un-deprecated).
- 2.8.0 — Deprecated in favor of esc_url_raw() .
- 2.3.1 — Introduced.

## Связанные

Использует: [`esc_url`](https://chugunov.pro/api-wordpress/functions/esc_url/).
Используется в: `WP_Theme_JSON_Resolver::get_resolved_theme_uris`, `WP_REST_Font_Faces_Controller::sanitize_src`, [`_wp_theme_json_webfonts_handler`](https://chugunov.pro/api-wordpress/functions/_wp_theme_json_webfonts_handler/), `WP_REST_Menu_Items_Controller::get_item_schema`, [`wp_default_packages_inline_scripts`](https://chugunov.pro/api-wordpress/functions/wp_default_packages_inline_scripts/), [`_wp_privacy_send_request_confirmation_notification`](https://chugunov.pro/api-wordpress/functions/_wp_privacy_send_request_confirmation_notification/), [`_wp_privacy_send_erasure_fulfillment_notification`](https://chugunov.pro/api-wordpress/functions/_wp_privacy_send_erasure_fulfillment_notification/), [`wp_send_user_request`](https://chugunov.pro/api-wordpress/functions/wp_send_user_request/), [`wp_privacy_send_personal_data_export_email`](https://chugunov.pro/api-wordpress/functions/wp_privacy_send_personal_data_export_email/), `WP_Customize_Manager::_sanitize_external_header_video`, [`rest_sanitize_value_from_schema`](https://chugunov.pro/api-wordpress/functions/rest_sanitize_value_from_schema/), `WP_Customize_Manager::_sanitize_background_setting`, `WP_Customize_Manager::_validate_external_header_video`, [`get_header_video_url`](https://chugunov.pro/api-wordpress/functions/get_header_video_url/), [`rest_send_cors_headers`](https://chugunov.pro/api-wordpress/functions/rest_send_cors_headers/), [`rest_output_link_header`](https://chugunov.pro/api-wordpress/functions/rest_output_link_header/), [`get_post_embed_url`](https://chugunov.pro/api-wordpress/functions/get_post_embed_url/), `WP_Customize_Manager::set_return_url`, `WP_Customize_Manager::customize_pane_settings`, `WP_Customize_Manager::set_preview_url`, `WP_REST_Server::serve_request`, `WP_Customize_Nav_Menu_Item_Setting::sanitize`, [`get_editor_stylesheets`](https://chugunov.pro/api-wordpress/functions/get_editor_stylesheets/), [`login_footer`](https://chugunov.pro/api-wordpress/functions/login_footer/), [`wp_prepare_themes_for_js`](https://chugunov.pro/api-wordpress/functions/wp_prepare_themes_for_js/), [`export_wp`](https://chugunov.pro/api-wordpress/functions/export_wp/), [`edit_user`](https://chugunov.pro/api-wordpress/functions/edit_user/), [`wp_media_upload_handler`](https://chugunov.pro/api-wordpress/functions/wp_media_upload_handler/), [`wp_ajax_send_link_to_editor`](https://chugunov.pro/api-wordpress/functions/wp_ajax_send_link_to_editor/), [`edit_post`](https://chugunov.pro/api-wordpress/functions/edit_post/), [`_wp_ajax_delete_comment_response`](https://chugunov.pro/api-wordpress/functions/_wp_ajax_delete_comment_response/), `Custom_Image_Header::set_header_image`, `Custom_Background::wp_set_background_image`, `Custom_Background::handle_upload`, `WP_Customize_Manager::customize_preview_settings`, [`_custom_background_cb`](https://chugunov.pro/api-wordpress/functions/_custom_background_cb/), [`get_header_image`](https://chugunov.pro/api-wordpress/functions/get_header_image/), [`get_uploaded_header_images`](https://chugunov.pro/api-wordpress/functions/get_uploaded_header_images/), [`get_url_in_content`](https://chugunov.pro/api-wordpress/functions/get_url_in_content/), [`sanitize_option`](https://chugunov.pro/api-wordpress/functions/sanitize_option/).

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