$error = new WP_Error( $code, $message, $data );
Say I added three messages (msg A, msg B, msg C) to the code
my_code and with the last message I added "Data" as
$data, which overwrote all
$data added with the previous calls to the error class.
WP_Error Object ( [errors] => Array ( [my_code] => Array (  => "msg A"  => "msg B"  => "msg C" ) ) [error_data] => Array ( [my_code] => "Data" ) )
After inspecting & playing around with the wp error class, I came to the following Qs:
I can pass an unlimited number of
$codes to the class and then pass an unlimited number of
$messages to each code. Point is that I can't pass more than one
Q: What is the intended use case of
1) Currently I'm trying to build a pretty simple WP_Error wrapper API (basically a set of easy-to-use functions). The Goal is to make a trac ticket out of it and move it to WP core.
I found a pretty strange behaviour in /wp-includes/functions.php with the
wp_die(); function: If you provide an error object, the function automatically fills the title provided by
$data['title']. So from looking at this I thought that
$data could be an associative array that can hold any amount of additional, dynamic data.
Q: But - and this is only valid if this is the intended use case - if
$data is a) an array and b) I successfully added additional data in there: How would I connect that to the according messages?
Q: Further: Why doesn't
wp_die(); abort if I have no error? This makes using it as dynamically - in case - added error output completely invalid.
You can find the ticket to fix the
wp_die() handler here.
A draft of a first "Theme Errors API" can be found here on github. Forking, etc. and commenting is highly appreciated.