php/class-wp-cli.php
public static function error_to_string( $errors ) {
		if ( is_string( $errors ) ) {
			return $errors;
		}

		// Only json_encode() the data when it needs it
		$render_data = function( $data ) {
			if ( is_array( $data ) || is_object( $data ) ) {
				return json_encode( $data );
			}

			return '"' . $data . '"';
		};

		if ( is_object( $errors ) && is_a( $errors, 'WP_Error' ) ) {
			foreach ( $errors->get_error_messages() as $message ) {
				if ( $errors->get_error_data() ) {
					return $message . ' ' . $render_data( $errors->get_error_data() );
				}

				return $message;
			}
		}
	}
public static function error_to_string( $errors ) {
		if ( is_string( $errors ) ) {
			return $errors;
		}

		// Only json_encode() the data when it needs it
		$render_data = function( $data ) {
			if ( is_array( $data ) || is_object( $data ) ) {
				return json_encode( $data );
			}

			return '"' . $data . '"';
		};

		if ( is_object( $errors ) && is_a( $errors, 'WP_Error' ) ) {
			foreach ( $errors->get_error_messages() as $message ) {
				if ( $errors->get_error_data() ) {
					return $message . ' ' . $render_data( $errors->get_error_data() );
				}

				return $message;
			}
		}
	}
public static function error_to_string ( $ errors ) { if ( is_string ( $ errors ) ) { return $ errors ; } // Only json_encode() the data when it needs it $ render_data = function ( $ data ) { if ( is_array ( $ data ) || is_object ( $ data ) ) { return json_encode ( $ data ) ; } return '"' . $ data . '"' ; } ; if ( is_object ( $ errors ) && is_a ( $ errors , 'WP_Error' ) ) { foreach ( $ errors -> get_error_messages ( ) as $ message ) { if ( $ errors -> get_error_data ( ) ) { return $ message . ' ' . $ render_data ( $ errors -> get_error_data ( ) ) ; } return $ message ; } } }
Convert a wp_error into a string

@param mixed $errors
@return string
Convert a wp_error into a string