REST API: Normalize WP_REST_Server::dispatch() to return a response object.
Previously, the `rest_pre_dispatch` filter could be used to return a `WP_Error` instance. This would cause a fatal error for `rest_post_dispath` filters that were rightly expecting a `WP_REST_Response` object to be passed instead. Props DaveFX, felipeelia. Fixes #56566. Built from https://develop.svn.wordpress.org/trunk@55361 git-svn-id: http://core.svn.wordpress.org/trunk@54894 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -984,6 +984,15 @@ class WP_REST_Server {
|
||||
$result = apply_filters( 'rest_pre_dispatch', null, $this, $request );
|
||||
|
||||
if ( ! empty( $result ) ) {
|
||||
|
||||
// Normalize to either WP_Error or WP_REST_Response...
|
||||
$result = rest_ensure_response( $result );
|
||||
|
||||
// ...then convert WP_Error across.
|
||||
if ( is_wp_error( $result ) ) {
|
||||
$result = $this->error_to_response( $result );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user