WordPress Error class.

Container for checking for WordPress errors and error messages. Return WP_Error and use is_wp_error() to check if this class is returned. Many core WordPress functions pass this class in the event of an error and if not handled properly will result in code errors.

package WordPress
since 2.1.0

 Methods

WP_Error()

WP_Error($code = '', $message = '', $data = ''

Parameters

$code

$message

$data

PHP4 Constructor - Sets up error message.

__construct(string|integer $code = '', string $message = '', mixed $data = '') : \WP_Error

If code parameter is empty then nothing will be done. It is possible to add multiple messages to the same code, but with other methods in the class.

All parameters are optional, but if the code parameter is set, then the data parameter is optional.

since 2.1.0

Parameters

$code

stringinteger

Error code

$message

string

Error message

$data

mixed

Optional. Error data.

Returns

\WP_Error

Append more error messages to list of error messages.

add(string|integer $code, string $message, mixed $data = ''
since 2.1.0
access public

Parameters

$code

stringinteger

Error code.

$message

string

Error message.

$data

mixed

Optional. Error data.

Add data for error code.

add_data(mixed $data, string|integer $code = ''

The error code can only contain one error data.

since 2.1.0

Parameters

$data

mixed

Error data.

$code

stringinteger

Error code.

Retrieve first error code available.

get_error_code() : string | integer
since 2.1.0
access public

Returns

stringintegerEmpty string, if no error codes.

Retrieve all error codes.

get_error_codes() : array
since 2.1.0
access public

Returns

arrayList of error codes, if avaiable.

Retrieve error data for error code.

get_error_data(string|integer $code = '') : mixed
since 2.1.0

Parameters

$code

stringinteger

Optional. Error code.

Returns

mixedNull, if no errors.

Get single error message.

get_error_message(string|integer $code = '') : string

This will get the first message available for the code. If no code is given then the first code available will be used.

since 2.1.0

Parameters

$code

stringinteger

Optional. Error code to retrieve message.

Returns

string

Retrieve all error messages or error messages matching code.

get_error_messages(string|integer $code = '') : array
since 2.1.0

Parameters

$code

stringinteger

Optional. Retrieve messages matching code, if exists.

Returns

arrayError strings on success, or empty array on failure (if using codee parameter).

 Properties

 

Stores the list of data for error codes.

$error_data : array

Default

array()
since 2.1.0
access private
 

Stores the list of errors.

$errors : array

Default

array()
since 2.1.0
access private