WP_Error::__construct() WordPress Method

The WP_Error::__construct() method is used to create a new WP_Error object.

WP_Error::__construct( string|int $code = '', string $message = '', mixed $data = '' ) #

Initializes the error.


Description

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.


Top ↑

Parameters

$code

(string|int)(Optional)Error code.

Default value: ''

$message

(string)(Optional)Error message.

Default value: ''

$data

(mixed)(Optional) Error data.

Default value: ''


Top ↑

Source

File: wp-includes/class-wp-error.php

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

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


Top ↑

Changelog

Changelog
VersionDescription
2.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.