Make WordPress Core


Ignore:
Timestamp:
02/17/2023 03:43:47 PM (2 years ago)
Author:
TimothyBlynJacobs
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/class-wp-rest-server.php

    r54965 r55361  
    985985
    986986        if ( ! empty( $result ) ) {
     987
     988            // Normalize to either WP_Error or WP_REST_Response...
     989            $result = rest_ensure_response( $result );
     990
     991            // ...then convert WP_Error across.
     992            if ( is_wp_error( $result ) ) {
     993                $result = $this->error_to_response( $result );
     994            }
     995
    987996            return $result;
    988997        }
Note: See TracChangeset for help on using the changeset viewer.