is_wp_error

The timeline below displays how wordpress function is_wp_error has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.6

/**
 * Checks whether the given variable is a WordPress Error.
 *
 * Returns whether `$thing` is an instance of the `WP_Error` class.
 *
 * @since 2.1.0
 *
 * @param mixed $thing The variable to check.
 * @return bool Whether the variable is an instance of WP_Error.
 */
function is_wp_error($thing)
{
    $is_wp_error = $thing instanceof WP_Error;
    if ($is_wp_error) {
        /**
         * Fires when `is_wp_error()` is called and its parameter is an instance of `WP_Error`.
         *
         * @since 5.6.0
         *
         * @param WP_Error $thing The error object passed to `is_wp_error()`.
         */
        do_action('is_wp_error_instance', $thing);
    }
    return $is_wp_error;
}

WordPress Version: 4.2

/**
 * Check whether variable is a WordPress Error.
 *
 * Returns true if $thing is an object 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.
 */
function is_wp_error($thing)
{
    return $thing instanceof WP_Error;
}

WordPress Version: 3.7

/**
 * Check whether variable is a WordPress Error.
 *
 * Returns true if $thing is an object 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.
 */
function is_wp_error($thing)
{
    if (is_object($thing) && is_a($thing, 'WP_Error')) {
        return true;
    }
    return false;
}