wppaste
WordPress

WP_Error

Since
2.1.0
Source
wp-includes/class-wp-error.php:18
WordPress Error class.

Description

Container for checking for WordPress errors and error messages. Return WP_Error and use is_wp_error() to check if this class is returned. Many core WordPress functions pass this class in the event of an error and if not handled properly will result in code errors.

Compatibility

WordPress
since 2.1.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Hooks and filters fired · 1

Every hook that fires from inside WP_Error, in the order it appears in the class, grouped by the method that fires it.

Properties · 3

$errorsarraypublic
Stores the list of errors.
$error_dataarraypublic
Stores the most recently added data for each error code.
$additional_dataarray[]protected
Stores previously added data added for error codes, oldest-to-newest by code.

Methods · 14

Source code

#[AllowDynamicProperties]class WP_Error {	/**	 * Stores the list of errors.	 *	 * @since 2.1.0	 * @var array	 */	public $errors = array(); 	/**	 * Stores the most recently added data for each error code.	 *	 * @since 2.1.0	 * @var array	 */	public $error_data = array(); 	/**	 * Stores previously added data added for error codes, oldest-to-newest by code.	 *	 * @since 5.6.0	 * @var array[]	 */	protected $additional_data = array(); 	/**	 * Initializes the error.	 *	 * If `$code` is empty, the other parameters will be ignored.	 * When `$code` is not empty, `$message` will be used even if	 * it is empty. The `$data` parameter will be used only if it	 * is not empty.	 *	 * Though the class is constructed with a single error code and	 * message, multiple codes can be added using the `add()` method.	 *	 * @since 2.1.0	 *	 * @param string|int $code    Error code.	 * @param string     $message Error message.	 * @param mixed      $data    Optional. Error data. Default empty string.	 */	public function __construct( $code = '', $message = '', $data = '' ) {		if ( empty( $code ) ) {			return;		} 		$this->add( $code, $message, $data );	} 	/**	 * Retrieves all error codes.	 *	 * @since 2.1.0	 *	 * @return array List of error codes, if available.	 */	public function get_error_codes() {		if ( ! $this->has_errors() ) {			return array();		} 		return array_keys( $this->errors );	} 	/**	 * Retrieves the first error code available.	 *	 * @since 2.1.0	 *	 * @return string|int Empty string, if no error codes.	 */	public function get_error_code() {		$codes = $this->get_error_codes(); 		if ( empty( $codes ) ) {			return '';		}

Changelog

Introduced in 2.1.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/class-wp-error.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.