WP_Error::get_error_message() WordPress Method

The get_error_message() method is a useful tool for retrieving error messages from a WP_Error object. This can be helpful when debugging your code or when dealing with unexpected errors.

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

Gets a single error message.


Description

This will get the first message available for the code. If no code is given then the first code available will be used.


Top ↑

Parameters

$code

(string|int)(Optional) Error code to retrieve message.

Default value: ''


Top ↑

Return

(string) The error message.


Top ↑

Source

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

	public function get_error_message( $code = '' ) {
		if ( empty( $code ) ) {
			$code = $this->get_error_code();
		}
		$messages = $this->get_error_messages( $code );
		if ( empty( $messages ) ) {
			return '';
		}
		return $messages[0];
	}


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.