[wp-trac] [WordPress Trac] #28092: Ability to filter or remove error codes from WP_Error class

WordPress Trac noreply at wordpress.org
Thu May 1 14:23:48 UTC 2014


#28092: Ability to filter or remove error codes from WP_Error class
------------------------------------+-----------------------------
 Reporter:  AdamCapriola            |      Owner:
     Type:  feature request         |     Status:  new
 Priority:  normal                  |  Milestone:  Awaiting Review
Component:  Login and Registration  |    Version:  3.9
 Severity:  normal                  |   Keywords:
  Focuses:                          |
------------------------------------+-----------------------------
 It would be very helpful if the
 [https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-
 error.php WP_Error class] would have a `remove` or adjusted `add`
 function. There is currently no way to filter or overwrite the error
 messages that come up. Specific messages can't even be targeted via CSS to
 hide them.

 Here is an example of what could be added to the class:

 {{{
 function remove($code) {
         if ( array_key_exists( $code, $this->errors ) )
                 unset($this->errors[$code]);
 }
 }}}

 Alternatively (and preferentially), the `add` function could omit the
 ability to add multiple errors with the same "error code" so then they
 could simply be overwritten. (What is the reasoning for allowing multiple
 errors with the same error code anyway?)

 {{{
 function add($code, $message, $data = '') {
         $this->errors[$code] = $message;
         if ( ! empty($data) )
                 $this->error_data[$code] = $data;
 }
 }}}

 Finally, one other option would be to add maybe `<span class="sanitized-
 error-code">` around the error messages. The messages could then be hidden
 by CSS if needed. This is probably the lesser of these ideas, though.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/28092>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list