WP_Error::add() WordPress Method

The WP_Error::add() method is used to add an error to a WP_Error object. The first parameter is the error code, which is a unique identifier for the error. The second parameter is the error message, which is a human-readable description of the error. The third parameter is the data that should be associated with the error. This can be anything, but is typically an array of information that will help to debug the error.

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

Adds an error or appends an additional message to an existing error.


Parameters

$code

(string|int)(Required)Error code.

$message

(string)(Required)Error message.

$data

(mixed)(Optional) Error data.

Default value: ''


Top ↑

Source

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

	public function add( $code, $message, $data = '' ) {
		$this->errors[ $code ][] = $message;

		if ( ! empty( $data ) ) {
			$this->add_data( $data, $code );
		}

		/**
		 * Fires when an error is added to a WP_Error object.
		 *
		 * @since 5.6.0
		 *
		 * @param string|int $code     Error code.
		 * @param string     $message  Error message.
		 * @param mixed      $data     Error data. Might be empty.
		 * @param WP_Error   $wp_error The WP_Error object.
		 */
		do_action( 'wp_error_added', $code, $message, $data, $this );
	}


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.