Allow passing extra data back with errors.

git-svn-id: http://svn.automattic.com/wordpress/trunk@4122 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2006-08-29 20:17:41 +00:00
parent eb78ba192c
commit 11e556e7e6
1 changed files with 29 additions and 5 deletions

View File

@ -348,10 +348,16 @@ class WP {
class WP_Error {
var $errors = array();
var $error_data = array();
function WP_Error($code = '', $message = '', $data = '') {
if ( empty($code) )
return;
function WP_Error($code = '', $message = '') {
if ( ! empty($code) )
$this->errors[$code][] = $message;
if ( ! empty($data) )
$this->error_data[$code] = $data;
}
function get_error_codes() {
@ -395,8 +401,26 @@ class WP_Error {
return $messages[0];
}
function add($code, $message) {
function get_error_data($code = '') {
if ( empty($code) )
$code = $this->get_error_code();
if ( isset($this->error_data[$code]) )
return $this->error_data[$code];
return null;
}
function add($code, $message, $data = '') {
$this->errors[$code][] = $message;
if ( ! empty($data) )
$this->error_data[$code] = $data;
}
function add_data($data, $code = '') {
if ( empty($code) )
$code = $this->get_error_code();
$this->error_data[$code] = $data;
}
}