WP_Error::add_data() WordPress Method

The WP_Error::add_data() method is used to add data to an error object. This is useful for debugging purposes or for displaying additional information to the user. The first parameter is the key of the data to add, and the second parameter is the value of the data.

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

Adds data to an error with the given code.


Parameters

$data

(mixed)(Required)Error data.

$code

(string|int)(Optional)Error code.

Default value: ''


Top ↑

Source

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

	public function add_data( $data, $code = '' ) {
		if ( empty( $code ) ) {
			$code = $this->get_error_code();
		}

		if ( isset( $this->error_data[ $code ] ) ) {
			$this->additional_data[ $code ][] = $this->error_data[ $code ];
		}

		$this->error_data[ $code ] = $data;
	}


Top ↑

Changelog

Changelog
VersionDescription
5.6.0Errors can now contain more than one item of error data. WP_Error::$additional_data.
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.