The Call
$error = new WP_Error( $code, $message, $data );
The Output
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
(
[0] => "msg A"
[1] => "msg B"
[2] => "msg C"
)
)
[error_data] => Array
(
[my_code] => "Data"
)
)
After inspecting & playing around with the wp error class, I came to the following Qs:
Problem
I can pass an unlimited number of $code
s to the class and then pass an unlimited number of $message
s to each code. Point is that I can't pass more than one $data
per $code
.
Q: What is the intended use case of $data
?1)
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.
Edit #1
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.
Edit #2
You can find the ticket to fix the wp_die()
handler here.
Edit #3
A draft of a first "Theme Errors API" can be found here on github. Forking, etc. and commenting is highly appreciated.