is_wp_error( mixed $thing )

Checks whether the given variable is a WordPress Error.


Description Description

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


Top ↑

Parameters Parameters

$thing

(mixed) (Required) The variable to check.


Top ↑

Return Return

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


Top ↑

Source 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

Changelog
Version Description
2.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 2 content
    Contributed by WebMat

    example with wp_insert_user

    		
    $email = 'test@test.com';
    $userdata = array(
    	'user_login'  	=> $email,
    	'user_email'    => $email,
    );
    
    $user_id = wp_insert_user( $userdata );
    
    if ( is_wp_error( $user_id ) ) {
    	$error_code = array_key_first( $user_id->errors );
    	$error_message = $user_id->errors[$error_code][0];
    }
    

You must log in before being able to contribute a note or feedback.