/** * Fallback filter the API response to inject the Customized REST resources. * * This filter cannot apply on embedded resources since they get injected * after the rest_post_dispatch filter is called. For this reason, it serves * as a fallback if the customize_rest_server_response_data filter can't be * used in our WP_REST_Server subclass. * * @param \WP_HTTP_Response $result Result to send to the client. Usually a \WP_REST_Response. * @param \WP_REST_Server $server Server instance. * @param \WP_REST_Request $request Request used to generate the response. * @return \WP_REST_Response */ public static function filter_rest_post_dispatch($result, $server, $request) { // Skip filtering on rest_post_dispatch if our server subclass is used. if ($server instanceof WP_Customize_REST_Server) { return $result; } unset($request); $data = $result->get_data(); $links = null; if ($result instanceof \WP_REST_Response) { $links = $result->get_links(); } if (!empty($links)) { $data = static::filter_single_resource($data, $links); } else { if (isset($data[0])) { $data = array_map(array(__CLASS__, 'filter_single_resource'), $data); } } $result->set_data($data); return $result; }