WP_Error::__construct()publicWP 2.1.0

Initializes the error.

If $code is empty, the other parameters will be ignored. When $code is not empty, $message will be used even if it is empty. The $data parameter will be used only if it is not empty.

Though the class is constructed with a single error code and message, multiple codes can be added using the add() method.

Method of the class: WP_Error{}

No Hooks.


null. Nothing.


$WP_Error = new WP_Error();
$WP_Error->__construct( $code, $message, $data );
Error code.
Default: ''
Error message.
Default: ''
Error data.
Default: ''


Since 2.1.0 Introduced.

WP_Error::__construct() code WP 6.1.1

public function __construct( $code = '', $message = '', $data = '' ) {
	if ( empty( $code ) ) {

	$this->add( $code, $message, $data );