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

In this article

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

Parameters

$codestring|intrequired
Error code.
$messagestringrequired
Error message.
$datamixedoptional
Error data.

Default:''

Source

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

Hooks

do_action( ‘wp_error_added’, string|int $code, string $message, mixed $data, WP_Error $wp_error )

Fires when an error is added to a WP_Error object.

Changelog

VersionDescription
2.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.