WordPress at Your Fingertips
function is not described

WC_API_Server::error_to_array() protected WC 2.1

Convert an error to an array

This iterates over all error codes and messages to change it into a flat array. This enables simpler client behaviour, as it is represented as a list in JSON rather than an object/map

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

No Hooks.

Return

Array. List of associative arrays with code and message keys

Usage

// protected - for code of main (parent) or child class
$result = $this->error_to_array( $error );
$error(WP_Error) (required)
-

Changelog

Since 2.1 Introduced.

Code of WC_API_Server::error_to_array() WC 5.6.0

protected function error_to_array( $error ) {
	$errors = array();
	foreach ( (array) $error->errors as $code => $messages ) {
		foreach ( (array) $messages as $message ) {
			$errors[] = array( 'code' => $code, 'message' => $message );
		}
	}
	return array( 'errors' => $errors );
}