Make WordPress Core

Changeset 61688


Ignore:
Timestamp:
02/19/2026 10:19:54 AM (3 months ago)
Author:
audrasjb
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r61652 r61688  
    60906090 */
    60916091function 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.
     
    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     */
Note: See TracChangeset for help on using the changeset viewer.