WP_Error::get_error_messages( string|int $code = '' ): string[]

In this article

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

Parameters

$codestring|intoptional
Error code to retrieve the messages for.

Default:''

Return

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

Source

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

		return $all_messages;
	}

	return $this->errors[ $code ] ?? array();
}

Changelog

VersionDescription
2.1.0Introduced.

User Contributed Notes

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