[wp-trac] [WordPress Trac] #38777: Add method to merge one WP_Error into another

WordPress Trac noreply at wordpress.org
Thu Apr 30 12:03:38 UTC 2020


#38777: Add method to merge one WP_Error into another
--------------------------------------+-----------------------
 Reporter:  rmccue                    |       Owner:  dlh
     Type:  feature request           |      Status:  assigned
 Priority:  normal                    |   Milestone:  5.5
Component:  General                   |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:  rest-api
--------------------------------------+-----------------------
Changes (by dlh):

 * keywords:  needs-patch needs-unit-tests => has-patch has-unit-tests


Comment:

 [attachment:"38777.diff"] takes a shot at the new `WP_Error::merge()`
 method, working basically as outlined in the ticket description, along
 with tests.

 @TimothyBlynJacobs Your question about conflicting error data is a good
 one. This patch will cause incoming error data to overwrite existing error
 data, which was an arbitrary choice; I'm open to other ideas.

 As mentioned, I'd previously implemented this method for other purposes in
 my own work. As part of that work, I've found it convenient to also have
 an `WP_Error::export()` method, which copies the current error into
 another one. It's sometimes been semantically helpful to me to think of
 either performing an action on an error (`merge()`) or causing an effect
 on another error (`export()`).

 I've included an `export()` with the patch. But, no one asked for it, so
 I'm also happy to remove it.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/38777#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list