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



git-svn-id: https://develop.svn.wordpress.org/trunk@49022 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn
2020-09-20 17:43:00 +00:00
parent dd076bb611
commit 2b742beb5c
2 changed files with 34 additions and 12 deletions

View File

@@ -1446,17 +1446,30 @@ function wp_doing_cron() {
}
/**
* Check whether variable is a WordPress Error.
* Checks whether the given variable is a WordPress Error.
*
* Returns true if $thing is an object of the WP_Error class.
* Returns whether `$thing` is an instance of the `WP_Error` class.
*
* @since 2.1.0
*
* @param mixed $thing Check if unknown variable is a WP_Error object.
* @return bool True, if WP_Error. False, if not WP_Error.
* @param mixed $thing The variable to check.
* @return bool Whether the variable is an instance of WP_Error.
*/
function is_wp_error( $thing ) {
return ( $thing instanceof WP_Error );
$is = ( $thing instanceof WP_Error );
if ( $is ) {
/**
* Fires when `is_wp_error()` is called and it's an instance of `WP_Error`.
*
* @since 5.6.0
*
* @param WP_Error $thing The error object passed to `is_wp_error()`.
*/
do_action( 'wp_error_checked', $thing );
}
return $is;
}
/**