WP_Error. fixes #2600
git-svn-id: http://svn.automattic.com/wordpress/trunk@3667 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
078c537718
commit
169842a7ce
|
@ -339,4 +339,55 @@ class WP {
|
|||
}
|
||||
}
|
||||
|
||||
class WP_Error {
|
||||
var $errors = array();
|
||||
|
||||
function WP_Error($code = '', $message = '') {
|
||||
if ( ! empty($code) )
|
||||
$this->errors[$code][] = $message;
|
||||
}
|
||||
|
||||
function get_error_codes() {
|
||||
if ( empty($this->errors) )
|
||||
return array();
|
||||
|
||||
return array_keys($this->errors);
|
||||
}
|
||||
|
||||
function get_error_code() {
|
||||
$codes = $this->get_error_codes();
|
||||
|
||||
if ( empty($codes) )
|
||||
return '';
|
||||
|
||||
return $codes[0];
|
||||
}
|
||||
|
||||
function get_error_messages($code) {
|
||||
if ( isset($this->errors[$code]) )
|
||||
return $this->errors[$code];
|
||||
else
|
||||
return array();
|
||||
}
|
||||
|
||||
function get_error_message($code = '') {
|
||||
if ( empty($code) )
|
||||
$code = $this->get_error_code();
|
||||
$messages = $this->get_error_messages($code);
|
||||
if ( empty($messages) )
|
||||
return '';
|
||||
return $messages[0];
|
||||
}
|
||||
|
||||
function add($code, $message) {
|
||||
$this->errors[$code][] = $message;
|
||||
}
|
||||
}
|
||||
|
||||
function is_wp_error($thing) {
|
||||
if ( is_object($thing) && is_a($thing, 'WP_Error') )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue