WordPress at a glance

is_wp_error() WP 2.1.0

Checks whether the passed variable is a WordPress Error.

It is used in WordPress to check whether the returned value of the function is a WordPress Error. Such errors have a description that can be used to find out the reason for the error. For example, wp_insert_term() function may return a WP_Error, and you can use its description to understand what has gone wrong.


true/false. True, if WP_Error. False, if not WP_Error.

No Hooks.


is_wp_error( $thing );
$thing(mixed) (required)
Check if unknown variable is a WP_Error object.


#1 Handle a WordPress error

// $result - is some variable that may be a WP_Error.

if( is_wp_error( $result ) ) {
	$error_string = $result->get_error_message();

	echo '<div id="message" class="error"><p>' . $error_string . '</p></div>';

	echo $res->get_error_code(); // -> 'error' or some other error key

Список изменений

С версии 2.1.0 Введена.

Code of is_wp_error() WP 5.5.1

function is_wp_error( $thing ) {
	return ( $thing instanceof WP_Error );

Related Functions

From category: Uncategorized

No comments
    Log In . Register