WP_Error::get_error_messages()publicWP 2.1.0

Retrieves all error messages, or the error messages for the given error code.

{} It's a method of the class: WP_Error{}

No Hooks.

Return

String[]. Error strings on success, or empty array if there are none.

Usage

$WP_Error = new WP_Error();
$WP_Error->get_error_messages( $code );
$code(string|int)
Retrieve messages matching code, if exists.
Default: ''

Changelog

Since 2.1.0 Introduced.

Code of WP_Error::get_error_messages() WP 6.1.1

public function get_error_messages( $code = '' ) {
	// Return all messages if no code specified.
	if ( empty( $code ) ) {
		$all_messages = array();
		foreach ( (array) $this->errors as $code => $messages ) {
			$all_messages = array_merge( $all_messages, $messages );
		}

		return $all_messages;
	}

	if ( isset( $this->errors[ $code ] ) ) {
		return $this->errors[ $code ];
	} else {
		return array();
	}
}