Make WordPress Core

Opened 3 years ago

Last modified 12 months ago

#38777 new feature request

Add method to merge one WP_Error into another

Reported by: rmccue Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: General Keywords: needs-patch 2nd-opinion
Focuses: rest-api Cc:


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.

Change History (1)

#1 @desrosj
12 months ago

  • Keywords needs-patch 2nd-opinion added
  • Milestone changed from Awaiting Review to Future Release
  • Type changed from defect (bug) to feature request
Note: See TracTickets for help on using tickets.