WP_Error::add
Adds an error or appends an additional message to an existing error.
Method of the class: WP_Error{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$WP_Error = new WP_Error(); $WP_Error->add( $code, $message, $data );
- $code(string|int) (required)
- Error code.
- $message(string) (required)
- Error message.
- $data(mixed)
- Error data.
Default: empty string
Changelog
| Since 2.1.0 | Introduced. |
WP_Error::add() WP Error::add code WP 6.9
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 );
}