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.

No Hooks.

Return

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

Usage

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

Examples

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

Changelog

Since 2.1.0 Introduced.

Code of is wp error: wp-includes/load.php WP 5.2.2

<?php
function is_wp_error( $thing ) {
	return ( $thing instanceof WP_Error );
}

Related Functions

From category: Uncategorized

No comments
    Hello, !     Log In . Register