WP_Error. fixes #2600
git-svn-id: https://develop.svn.wordpress.org/trunk@3667 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
e706f8cf36
commit
657b7d8176
@ -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
Block a user