WP_Error::get_error_messages() WordPress Method

The WP_Error::get_error_messages() function retrieves all error messages for a given WP_Error object. The messages are returned as an array of strings, each representing an error message.

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

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


Parameters

$code

(string|int)(Optional) Retrieve messages matching code, if exists.

Default value: ''


Top ↑

Return

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


Top ↑

Source

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

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


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.