is_wp_error() WordPress Function

The is_wp_error() function checks whether a given value is a WordPress Error object. This is useful for checking the return value of functions that may return an error.

is_wp_error( mixed $thing ) #

Checks whether the given variable is a WordPress Error.


Description

Returns whether $thing is an instance of the WP_Error class.


Top ↑

Parameters

$thing

(mixed)(Required)The variable to check.


Top ↑

Return

(bool) Whether the variable is an instance of WP_Error.


Top ↑

Source

File: wp-includes/load.php

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;
}


Top ↑

Changelog

Changelog
VersionDescription
2.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.