Update WP_REST_Response::as_error() to handle the new format error responses introduced in [35653].

Props danielbachhuber
Fixes #34551


git-svn-id: https://develop.svn.wordpress.org/trunk@35671 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn
2015-11-18 18:28:55 +00:00
parent 20c9a88a18
commit 355e768312
2 changed files with 27 additions and 2 deletions

View File

@@ -243,8 +243,12 @@ class WP_REST_Response extends WP_HTTP_Response {
$error = new WP_Error;
if ( is_array( $this->get_data() ) ) {
foreach ( $this->get_data() as $err ) {
$error->add( $err['code'], $err['message'], $err['data'] );
$data = $this->get_data();
$error->add( $data['code'], $data['message'], $data['data'] );
if ( ! empty( $data['additional_errors'] ) ) {
foreach( $data['additional_errors'] as $err ) {
$error->add( $err['code'], $err['message'], $err['data'] );
}
}
} else {
$error->add( $this->get_status(), '', array( 'status' => $this->get_status() ) );