Skip to content

Commit 69cfb47

Browse files
committed
General: Allow to hook into wp_trigger_error() when WP_DEBUG is not truthy.
This changeset allow developers to attach custom error handlers into `wp_trigger_error()` even if `WP_DEBUG` is not truthy. It introduces two new hooks, making `wp_trigger_error()` consistent with what is available in `_doing_it_wrong`: - `wp_trigger_error_always_run` always fires when the given function triggers a user-level error/warning/notice/deprecation message. - `wp_trigger_error_trigger_error` filters whether to trigger the error. Props kkmuffme, swissspidy, audrasjb. Fixes #60886. git-svn-id: https://develop.svn.wordpress.org/trunk@61688 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 0964835 commit 69cfb47

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

src/wp-includes/functions.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6089,6 +6089,32 @@ function _doing_it_wrong( $function_name, $message, $version ) {
60896089
* Only works with E_USER family of constants. Default E_USER_NOTICE.
60906090
*/
60916091
function wp_trigger_error( $function_name, $message, $error_level = E_USER_NOTICE ) {
6092+
/**
6093+
* Always fires when the given function triggers a user-level error/warning/notice/deprecation message.
6094+
*
6095+
* Can be used to attach custom error handlers even if WP_DEBUG is not truthy.
6096+
*
6097+
* @since 7.0.0
6098+
*
6099+
* @param string $function_name The function that triggered the error.
6100+
* @param string $message The message explaining the error.
6101+
* @param int $error_level The designated error type for this error.
6102+
*/
6103+
do_action( 'wp_trigger_error_always_run', $function_name, $message, $error_level );
6104+
6105+
/**
6106+
* Filters whether to trigger an error.
6107+
*
6108+
* @since 7.0.0
6109+
*
6110+
* @param bool $trigger Whether to trigger the error. Default true.
6111+
* @param string $function_name The function that triggered the error.
6112+
* @param string $message The message explaining the error.
6113+
* @param int $error_level The designated error type for this error.
6114+
*/
6115+
if ( ! apply_filters( 'wp_trigger_error_trigger_error', true, $function_name, $message, $error_level ) ) {
6116+
return;
6117+
}
60926118

60936119
// Bail out if WP_DEBUG is not turned on.
60946120
if ( ! WP_DEBUG ) {
@@ -6102,8 +6128,8 @@ function wp_trigger_error( $function_name, $message, $error_level = E_USER_NOTIC
61026128
*
61036129
* @since 6.4.0
61046130
*
6105-
* @param string $function_name The function that was called.
6106-
* @param string $message A message explaining what has been done incorrectly.
6131+
* @param string $function_name The function that triggered the error.
6132+
* @param string $message The message explaining the error.
61076133
* @param int $error_level The designated error type for this error.
61086134
*/
61096135
do_action( 'wp_trigger_error_run', $function_name, $message, $error_level );

0 commit comments

Comments
 (0)