[wp-trac] [WordPress Trac] #42742: Add a has_errors() method to WP_Error

WordPress Trac noreply at wordpress.org
Wed Nov 29 01:56:23 UTC 2017


#42742: Add a has_errors() method to WP_Error
-------------------------+-------------------------------------------------
 Reporter:               |      Owner:
  DrewAPicture           |     Status:  new
     Type:  enhancement  |  Milestone:  Awaiting Review
 Priority:  normal       |    Version:
Component:  General      |   Keywords:  needs-patch needs-unit-tests good-
 Severity:  normal       |  first-bug
  Focuses:               |
-------------------------+-------------------------------------------------
 We should add a method to easily check whether a `WP_Error` object
 contains any errors.

 There isn't any one standard way to perform such an operation, and in
 fact, a cursory search of core yielded a variety of methods for checking
 whether there are any errors in the object, but nothing really consistent:

 * Checking `empty()` on the `$errors` property
 * Checking if the count from `get_error_codes()` is greater than 0
 * Checking if the value of `get_error_code()` is an empty string

 My proposal would be to introduce a boolean `has_errors()` method, or
 perhaps `empty()` that simply checks whether the `$errors` property is
 empty or not.

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


More information about the wp-trac mailing list