Make WordPress Core


Ignore:
Timestamp:
09/20/2020 05:43:00 PM (3 years ago)
Author:
johnbillion
Message:

General: Introduce the wp_error_added and wp_error_checked actions.

These actions allow debugging tools to track WP_Error instances as they're created and subsequently passed between functions which check for error objects.

Props Shelob9, Mte90, TimothyBlynJacobs, johnbillion

Fixes #40568

File:
1 edited

Legend:

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

    r48941 r49022  
    14471447
    14481448/**
    1449  * Check whether variable is a WordPress Error.
    1450  *
    1451  * Returns true if $thing is an object of the WP_Error class.
     1449 * Checks whether the given variable is a WordPress Error.
     1450 *
     1451 * Returns whether `$thing` is an instance of the `WP_Error` class.
    14521452 *
    14531453 * @since 2.1.0
    14541454 *
    1455  * @param mixed $thing Check if unknown variable is a WP_Error object.
    1456  * @return bool True, if WP_Error. False, if not WP_Error.
     1455 * @param mixed $thing The variable to check.
     1456 * @return bool Whether the variable is an instance of WP_Error.
    14571457 */
    14581458function is_wp_error( $thing ) {
    1459     return ( $thing instanceof WP_Error );
     1459    $is = ( $thing instanceof WP_Error );
     1460
     1461    if ( $is ) {
     1462        /**
     1463         * Fires when `is_wp_error()` is called and it's an instance of `WP_Error`.
     1464         *
     1465         * @since 5.6.0
     1466         *
     1467         * @param WP_Error $thing The error object passed to `is_wp_error()`.
     1468         */
     1469        do_action( 'wp_error_checked', $thing );
     1470    }
     1471
     1472    return $is;
    14601473}
    14611474
Note: See TracChangeset for help on using the changeset viewer.