is_wp_error( mixed $thing )

Check whether variable is a WordPress Error.


Description Description

Returns true if $thing is an object of the WP_Error class.


Top ↑

Parameters Parameters

$thing

(mixed) (Required) Check if unknown variable is a WP_Error object.


Top ↑

Return Return

(bool) True, if WP_Error. False, if not WP_Error.


Top ↑

Source Source

File: wp-includes/load.php

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


Top ↑

Changelog Changelog

Changelog
Version Description
2.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 3 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.