wp_trigger_error( string $function_name, string $message, int $error_level = E_USER_NOTICE )
Generates a user-level error/warning/notice/deprecation message.
Description
Generates the message when WP_DEBUG
is true.
Parameters
- $function_name
-
(Required) The function that triggered the error.
- $message
-
(Required) The message explaining the error.<br> The message can contain allowed HTML 'a' (with href), 'code', 'br', 'em', and 'strong' tags and http or https protocols.<br> If it contains other HTML tags or protocols, the message should be escaped before passing to this function to avoid being stripped wp_kses().
- $error_level
-
(Optional) The designated error type for this error.<br> Only works with E_USER family of constants.
Default value: E_USER_NOTICE
Source
File: wp-includes/functions.php
function wp_trigger_error( $function_name, $message, $error_level = E_USER_NOTICE ) {
// 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 CP-2.2.0
*
* @param string $function_name The function that was called.
* @param string $message A message explaining what has been done incorrectly.
* @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 );
}
Changelog
Version | Description |
---|---|
CP-2.2.0 | Introduced. CP-2.2.0 |