AdvancedCustomFields / acf

Advanced Custom Fields
http://advancedcustomfields.com/
823 stars 168 forks source link

rest_pre_dispatch conflicts #838

Open pentatonicfunk opened 1 year ago

pentatonicfunk commented 1 year ago

This function is hooked into rest_pre_dispatch: https://github.com/AdvancedCustomFields/acf/blob/fd6fbd054972ea4d54d3edc92fe66cf2b713d0ec/includes/rest-api/class-acf-rest-api.php#L26-L44 This method basically void method ( in the end it will always returns null )

the filter priority is 10 ( which is default, and higher chance to possibly conflict with other plugins that utilize this filter )

add_filter( 'rest_pre_dispatch', array( $this, 'initialize' ), 10, 3 );

meanwhile the core filter expects a "possible" return value:

/**
    * Filters the pre-calculated result of a REST API dispatch request.
    *
    * Allow hijacking the request before dispatching by returning a non-empty. The returned value
    * will be used to serve the request instead.
    *
    * @since 4.4.0
    *
    * @param mixed           $result  Response to replace the requested version with. Can be anything
    *                                 a normal endpoint can return, or null to not hijack the request.
    * @param WP_REST_Server  $server  Server instance.
    * @param WP_REST_Request $request Request used to generate the response.
*/
$result = apply_filters( 'rest_pre_dispatch', null, $this, $request );

Sample Case: