wp/wp-includes/class-wp-error.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * WordPress Error API.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * Contains the WP_Error class and the is_wp_error() function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 * WordPress Error class.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * Container for checking for WordPress errors and error messages. Return
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 * WP_Error and use {@link is_wp_error()} to check if this class is returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 * Many core WordPress functions pass this class in the event of an error and
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 * if not handled properly will result in code errors.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
class WP_Error {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
	 * Stores the list of errors.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    28
	public $errors = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
	 * Stores the list of data for error codes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    36
	public $error_data = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    39
	 * Initialize the error.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    41
	 * If `$code` is empty, the other parameters will be ignored.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    42
	 * When `$code` is not empty, `$message` will be used even if
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    43
	 * it is empty. The `$data` parameter will be used only if it
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    44
	 * is not empty.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    46
	 * Though the class is constructed with a single error code and
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    47
	 * message, multiple codes can be added using the `add()` method.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
	 * @param string|int $code Error code
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
	 * @param string $message Error message
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
	 * @param mixed $data Optional. Error data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    55
	public function __construct( $code = '', $message = '', $data = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
		if ( empty($code) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
		$this->errors[$code][] = $message;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
		if ( ! empty($data) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
			$this->error_data[$code] = $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
	 * Retrieve all error codes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
	 * @return array List of error codes, if available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    73
	public function get_error_codes() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
		if ( empty($this->errors) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
			return array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
		return array_keys($this->errors);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
	 * Retrieve first error code available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
	 * @return string|int Empty string, if no error codes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    88
	public function get_error_code() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
		$codes = $this->get_error_codes();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
		if ( empty($codes) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
			return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
		return $codes[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
	 * Retrieve all error messages or error messages matching code.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
	 * @param string|int $code Optional. Retrieve messages matching code, if exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
	 * @return array Error strings on success, or empty array on failure (if using code parameter).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   105
	public function get_error_messages($code = '') {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
		// Return all messages if no code specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
		if ( empty($code) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
			$all_messages = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
			foreach ( (array) $this->errors as $code => $messages )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
				$all_messages = array_merge($all_messages, $messages);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
			return $all_messages;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
		if ( isset($this->errors[$code]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
			return $this->errors[$code];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
			return array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
	 * Get single error message.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
	 * This will get the first message available for the code. If no code is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
	 * given then the first code available will be used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
	 * @param string|int $code Optional. Error code to retrieve message.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   132
	public function get_error_message($code = '') {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
		if ( empty($code) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
			$code = $this->get_error_code();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
		$messages = $this->get_error_messages($code);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
		if ( empty($messages) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
			return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
		return $messages[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
	 * Retrieve error data for error code.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
	 * @param string|int $code Optional. Error code.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
	 * @return mixed Null, if no errors.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   149
	public function get_error_data($code = '') {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
		if ( empty($code) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
			$code = $this->get_error_code();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
		if ( isset($this->error_data[$code]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
			return $this->error_data[$code];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
		return null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   159
	 * Add an error or append additional message to an existing error.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
	 * @param string|int $code Error code.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
	 * @param string $message Error message.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
	 * @param mixed $data Optional. Error data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   168
	public function add($code, $message, $data = '') {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
		$this->errors[$code][] = $message;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
		if ( ! empty($data) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
			$this->error_data[$code] = $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
	 * Add data for error code.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
	 * The error code can only contain one error data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
	 * @param mixed $data Error data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
	 * @param string|int $code Error code.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   184
	public function add_data($data, $code = '') {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
		if ( empty($code) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
			$code = $this->get_error_code();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
		$this->error_data[$code] = $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   190
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   191
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   192
	 * Removes the specified error.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   193
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   194
	 * This function removes all error messages associated with the specified
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   195
	 * error code, along with any error data for that code.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   196
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   197
	 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   198
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   199
	 * @param string|int $code Error code.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   200
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   201
	public function remove( $code ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   202
		unset( $this->errors[ $code ] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   203
		unset( $this->error_data[ $code ] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   204
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
 * Check whether variable is a WordPress Error.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
 * Returns true if $thing is an object of the WP_Error class.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
 * @param mixed $thing Check if unknown variable is a WP_Error object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
 * @return bool True, if WP_Error. False, if not WP_Error.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   217
function is_wp_error( $thing ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   218
	return ( $thing instanceof WP_Error );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
}