[wp-trac] [WordPress Trac] #38777: Add method to merge one WP_Error into another
WordPress Trac
noreply at wordpress.org
Mon Nov 14 05:03:57 UTC 2016
#38777: Add method to merge one WP_Error into another
--------------------------+-----------------------------
Reporter: rmccue | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
Focuses: rest-api |
--------------------------+-----------------------------
`WP_Error` can store multiple error messages and codes, but this requires
building the error object manually. If you have two existing error
instances and want to merge them into a single one, you have to do this
manually:
{{{
foreach ( $other_errors as $code => $messages ) {
foreach ( $messages as $message ) {
$error->add( $code, $message );
}
if ( $error_data = $error->get_error_data( $code ) ) {
$error->add_data( $error_data, $code );
}
}
}}}
While this multi-error feature isn't widely used, it's very helpful in the
REST API, where multi-errors are natively supported via an
`additional_errors` key in the error response.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38777>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list