# wp_trigger_error()

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

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

## Сигнатура

```php
wp_trigger_error( string $function_name, string $message, int $error_level = E_USER_NOTICE )
```

## Описание

Генерирует сообщение, когда WP_DEBUG равно true.

## Параметры

- `$function_name` `string` — обязательный. Функция, вызвавшая ошибку.
- `$message` `string` — обязательный. Сообщение, поясняющее ошибку.
  
  Сообщение может содержать разрешённые HTML-теги 'a' (с href), 'code', 'br', 'em' и 'strong', а также протоколы http или https.
  
  Если оно содержит другие HTML-теги или протоколы, сообщение следует экранировать перед передачей в эту функцию, чтобы они не были удалены wp_kses().
- `$error_level` `int` — необязательный, по умолчанию `E_USER_NOTICE`. Заданный тип для этой ошибки.
  
  Работает только с константами семейства E_USER.

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

Файл: `wp-includes/functions.php:6104`

```php
function wp_trigger_error( $function_name, $message, $error_level = E_USER_NOTICE ) {
	/**
	 * Always fires when the given function triggers a user-level error/warning/notice/deprecation message.
	 *
	 * Can be used to attach custom error handlers even if WP_DEBUG is not truthy.
	 *
	 * @since 7.0.0
	 *
	 * @param string $function_name The function that triggered the error.
	 * @param string $message       The message explaining the error.
	 * @param int    $error_level   The designated error type for this error.
	 */
	do_action( 'wp_trigger_error_always_run', $function_name, $message, $error_level );

	/**
	 * Filters whether to trigger an error.
	 *
	 * @since 7.0.0
	 *
	 * @param bool   $trigger       Whether to trigger the error. Default true.
	 * @param string $function_name The function that triggered the error.
	 * @param string $message       The message explaining the error.
	 * @param int    $error_level   The designated error type for this error.
	 */
	if ( ! apply_filters( 'wp_trigger_error_trigger_error', true, $function_name, $message, $error_level ) ) {
		return;
	}

	// Bail out if WP_DEBUG is not turned on.
	if ( ! WP_DEBUG ) {
		return;
	}

	/**
	 * Fires when the given function triggers a user-level error/warning/notice/deprecation message.
	 *
	 * Can be used for debug backtracking.
	 *
	 * @since 6.4.0
	 *
	 * @param string $function_name The function that triggered the error.
	 * @param string $message       The message explaining the error.
	 * @param int    $error_level   The designated error type for this error.
	 */
	do_action( 'wp_trigger_error_run', $function_name, $message, $error_level );

	if ( ! empty( $function_name ) ) {
		$message = sprintf( '%s(): %s', $function_name, $message );
	}

	$message = wp_kses(
		$message,
		array(
			'a'      => array( 'href' => true ),
			'br'     => array(),
			'code'   => array(),
			'em'     => array(),
			'strong' => array(),
		),
		array( 'http', 'https' )
	);

	if ( E_USER_ERROR === $error_level ) {
		throw new WP_Exception( $message );
	}

	trigger_error( $message, $error_level );
}
```

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

- 6.4.0 — Introduced.

## Связанные

Использует: [`wp_kses`](https://chugunov.pro/api-wordpress/functions/wp_kses/), [`do_action`](https://chugunov.pro/api-wordpress/functions/do_action/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/).
Используется в: [`_wp_connectors_pass_default_keys_to_ai_client`](https://chugunov.pro/api-wordpress/functions/_wp_connectors_pass_default_keys_to_ai_client/), [`_wp_connectors_is_ai_api_key_valid`](https://chugunov.pro/api-wordpress/functions/_wp_connectors_is_ai_api_key_valid/), `WP_Icons_Registry::get_content`, `WP_Icons_Registry::__construct`, `WP_HTML_Processor::serialize`, [`wp_unique_prefixed_id`](https://chugunov.pro/api-wordpress/functions/wp_unique_prefixed_id/), [`_deprecated_class`](https://chugunov.pro/api-wordpress/functions/_deprecated_class/), [`_wp_delete_all_temp_backups`](https://chugunov.pro/api-wordpress/functions/_wp_delete_all_temp_backups/), [`wp_opcache_invalidate_directory`](https://chugunov.pro/api-wordpress/functions/wp_opcache_invalidate_directory/), `WP_Theme_JSON::set_spacing_sizes`, `WP_Theme_JSON_Resolver::get_user_data`, [`wp_json_file_decode`](https://chugunov.pro/api-wordpress/functions/wp_json_file_decode/), [`_filter_block_template_part_area`](https://chugunov.pro/api-wordpress/functions/_filter_block_template_part_area/), [`clean_dirsize_cache`](https://chugunov.pro/api-wordpress/functions/clean_dirsize_cache/), [`recurse_dirsize`](https://chugunov.pro/api-wordpress/functions/recurse_dirsize/), [`_deprecated_hook`](https://chugunov.pro/api-wordpress/functions/_deprecated_hook/), [`_deprecated_constructor`](https://chugunov.pro/api-wordpress/functions/_deprecated_constructor/), `MagpieRSS::__construct`, `WP_Text_Diff_Renderer_Table::__unset`, `WP_Text_Diff_Renderer_Table::__get`, `WP_Text_Diff_Renderer_Table::__set`, `WP_Text_Diff_Renderer_Table::__isset`, `WP_User_Query::__get`, `WP_User_Query::__set`, `WP_User_Query::__isset`, `WP_User_Query::__unset`, `WP_List_Table::__get`, `WP_List_Table::__set`, `WP_List_Table::__isset`, `WP_List_Table::__unset`, [`translations_api`](https://chugunov.pro/api-wordpress/functions/translations_api/), `WP_Upgrader::maintenance_mode`, [`themes_api`](https://chugunov.pro/api-wordpress/functions/themes_api/), [`get_core_checksums`](https://chugunov.pro/api-wordpress/functions/get_core_checksums/), [`plugins_api`](https://chugunov.pro/api-wordpress/functions/plugins_api/), [`search_theme_directories`](https://chugunov.pro/api-wordpress/functions/search_theme_directories/), [`wp_strip_all_tags`](https://chugunov.pro/api-wordpress/functions/wp_strip_all_tags/), [`_deprecated_function`](https://chugunov.pro/api-wordpress/functions/_deprecated_function/), [`_deprecated_file`](https://chugunov.pro/api-wordpress/functions/_deprecated_file/), [`_deprecated_argument`](https://chugunov.pro/api-wordpress/functions/_deprecated_argument/).

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