/**
  * Make sure that the context for the request is made known so we know whether it can be customized.
  *
  * @param \WP_HTTP_Response $response 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_HTTP_Response Response.
  */
 public function export_context_with_response($response, $server, $request)
 {
     unset($server);
     if ('edit' === $request['context']) {
         $response->header('X-Customize-REST-Resources-Context', $request['context']);
     }
     return $response;
 }
示例#2
0
/**
 * @param WP_HTTP_Response $result  Result to send to the client. Usually a WP_REST_Response.
 * @param WP_REST_Server   $this    Server instance.
 * @param WP_REST_Request  $request Request used to generate the response.
 *
 * @return WP_HTTP_Response
 */
function epoch_post_dispatch($result, $server, $request)
{
    if (isset($_GET['epoch'], $_GET['post']) && 0 < absint($_GET['post'])) {
        $query = new WP_Comment_Query(array('post_ID' => $_GET['post'], 'number' => 1, 'order' => 'DESC'));
        $highest = 0;
        if (0 != $query->found_comments) {
            $highest = wp_list_pluck($query->comments, 'comment_ID');
        }
        $result->header('X-EPOCH-HIGHEST', $highest);
    }
    return $result;
}