]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/class-wp-error.php
WordPress 4.7.2-scripts
[autoinstalls/wordpress.git] / wp-includes / class-wp-error.php
index 1624195833c9d1ea37f4a9b05a018e5347bd2cfa..22273f89b23fd649604d5166914187c49e37246b 100644 (file)
@@ -11,8 +11,8 @@
  * WordPress Error class.
  *
  * Container for checking for WordPress errors and error messages. Return
- * WP_Error and use {@link is_wp_error()} to check if this class is returned.
- * Many core WordPress functions pass this class in the event of an error and
+ * WP_Error and use is_wp_error() to check if this class is returned. Many
+ * core WordPress functions pass this class in the event of an error and
  * if not handled properly will result in code errors.
  *
  * @package WordPress
@@ -24,37 +24,35 @@ class WP_Error {
         *
         * @since 2.1.0
         * @var array
-        * @access private
         */
-       var $errors = array();
+       public $errors = array();
 
        /**
         * Stores the list of data for error codes.
         *
         * @since 2.1.0
         * @var array
-        * @access private
         */
-       var $error_data = array();
+       public $error_data = array();
 
        /**
-        * PHP4 Constructor - Sets up error message.
+        * Initialize the error.
         *
-        * If code parameter is empty then nothing will be done. It is possible to
-        * add multiple messages to the same code, but with other methods in the
-        * class.
+        * If `$code` is empty, the other parameters will be ignored.
+        * When `$code` is not empty, `$message` will be used even if
+        * it is empty. The `$data` parameter will be used only if it
+        * is not empty.
         *
-        * All parameters are optional, but if the code parameter is set, then the
-        * data parameter is optional.
+        * Though the class is constructed with a single error code and
+        * message, multiple codes can be added using the `add()` method.
         *
         * @since 2.1.0
         *
         * @param string|int $code Error code
         * @param string $message Error message
         * @param mixed $data Optional. Error data.
-        * @return WP_Error
         */
-       function WP_Error($code = '', $message = '', $data = '') {
+       public function __construct( $code = '', $message = '', $data = '' ) {
                if ( empty($code) )
                        return;
 
@@ -70,9 +68,9 @@ class WP_Error {
         * @since 2.1.0
         * @access public
         *
-        * @return array List of error codes, if avaiable.
+        * @return array List of error codes, if available.
         */
-       function get_error_codes() {
+       public function get_error_codes() {
                if ( empty($this->errors) )
                        return array();
 
@@ -87,7 +85,7 @@ class WP_Error {
         *
         * @return string|int Empty string, if no error codes.
         */
-       function get_error_code() {
+       public function get_error_code() {
                $codes = $this->get_error_codes();
 
                if ( empty($codes) )
@@ -102,9 +100,9 @@ class WP_Error {
         * @since 2.1.0
         *
         * @param string|int $code Optional. Retrieve messages matching code, if exists.
-        * @return array Error strings on success, or empty array on failure (if using codee parameter).
+        * @return array Error strings on success, or empty array on failure (if using code parameter).
         */
-       function get_error_messages($code = '') {
+       public function get_error_messages($code = '') {
                // Return all messages if no code specified.
                if ( empty($code) ) {
                        $all_messages = array();
@@ -131,7 +129,7 @@ class WP_Error {
         * @param string|int $code Optional. Error code to retrieve message.
         * @return string
         */
-       function get_error_message($code = '') {
+       public function get_error_message($code = '') {
                if ( empty($code) )
                        $code = $this->get_error_code();
                $messages = $this->get_error_messages($code);
@@ -146,19 +144,18 @@ class WP_Error {
         * @since 2.1.0
         *
         * @param string|int $code Optional. Error code.
-        * @return mixed Null, if no errors.
+        * @return mixed Error data, if it exists.
         */
-       function get_error_data($code = '') {
+       public 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;
        }
 
        /**
-        * Append more error messages to list of error messages.
+        * Add an error or append additional message to an existing error.
         *
         * @since 2.1.0
         * @access public
@@ -167,7 +164,7 @@ class WP_Error {
         * @param string $message Error message.
         * @param mixed $data Optional. Error data.
         */
-       function add($code, $message, $data = '') {
+       public function add($code, $message, $data = '') {
                $this->errors[$code][] = $message;
                if ( ! empty($data) )
                        $this->error_data[$code] = $data;
@@ -183,30 +180,25 @@ class WP_Error {
         * @param mixed $data Error data.
         * @param string|int $code Error code.
         */
-       function add_data($data, $code = '') {
+       public function add_data($data, $code = '') {
                if ( empty($code) )
                        $code = $this->get_error_code();
 
                $this->error_data[$code] = $data;
        }
-}
 
-/**
- * Check whether variable is a WordPress Error.
- *
- * Looks at the object and if a WP_Error class. Does not check to see if the
- * parent is also WP_Error, so can't inherit WP_Error and still use this
- * function.
- *
- * @since 2.1.0
- *
- * @param mixed $thing Check if unknown variable is WordPress Error object.
- * @return bool True, if WP_Error. False, if not WP_Error.
- */
-function is_wp_error($thing) {
-       if ( is_object($thing) && is_a($thing, 'WP_Error') )
-               return true;
-       return false;
+       /**
+        * Removes the specified error.
+        *
+        * This function removes all error messages associated with the specified
+        * error code, along with any error data for that code.
+        *
+        * @since 4.1.0
+        *
+        * @param string|int $code Error code.
+        */
+       public function remove( $code ) {
+               unset( $this->errors[ $code ] );
+               unset( $this->error_data[ $code ] );
+       }
 }
-
-?>
\ No newline at end of file