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: ''

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;
	}

Changelog

Version Description
5.6.0 Errors can now contain more than one item of error data. WP_Error::$additional_data.
2.1.0 Introduced.

© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_error/add_data