function wp_memento_catch_vars()
{
    // Handle a timegate request
    if (get_query_var('timegate_url')) {
        // Get the requested URL and clean it up
        $timegate_url = get_query_var('timegate_url');
        $timegate_url = str_replace("http:/", "http://", $timegate_url);
        $timegate_url .= "/";
        // Pull the original post from the database
        $post_id = url_to_postid($timegate_url);
        // If it doesn't exist, throw a 404 error
        if ($post_id == 0) {
            include get_query_template('404');
            exit;
        }
        // Get the requested memento datetime
        $headers = getallheaders();
        $accept_datetime = $headers["Accept-Datetime"];
        // If no datetime is provided, redirect to the most recent version
        if ($accept_datetime == '') {
            // Do that here
            wp_redirect($timegate_url);
            exit;
        }
        // Verify that the provided datetime is valid
        if (count(date_parse($accept_datetime)['errors']) > 0) {
            header('HTTP/1.1 400 BAD REQUEST');
            exit;
        }
        // Parse the datetime string into a date aware object
        $accept_datetime = new DateTime($accept_datetime);
        // Query all of the revisions for this post
        $revisions = get_post_revisions($post_id);
        // Loop through all of the posts ...
        $revision_array = array();
        foreach ($revisions as &$r) {
            // And for each one pull the datetime
            $date = new DateTime($r->post_date_gmt);
            // And compare it against the submitted memento request
            $diff = abs($date->getTimestamp() - $accept_datetime->getTimestamp());
            // Key it into a new array using that difference
            $revision_array[$diff] = $r;
        }
        // Resort the array so the one with the smallest difference is first
        ksort($revision_array);
        // Pull out that closest revision from array
        $nearest_revision = array_values($revision_array)[0];
        // Redirect the request to the detail page for that revision
        $permalink = get_revision_permalink($nearest_revision->parent_post, $nearest_revision);
        wp_redirect($permalink);
        exit;
    }
    // Handle a timemap list request
    if (get_query_var('timemap_url')) {
        // Get the timemap URL and clean it up
        $timemap_url = get_query_var('timemap_url');
        $timemap_url = str_replace("http:/", "http://", $timemap_url);
        $timemap_url .= "/";
        // Pull the original post from the database
        $post_id = url_to_postid($timemap_url);
        // If it doesn't exist, throw a 404 error
        if ($post_id == 0) {
            include get_query_template('404');
            exit;
        }
        // Render the timemap response
        $charset = get_option('blog_charset');
        header('Content-Type: application/link-format; charset=' . $charset);
        $post = get_post($post_id);
        $revision_list = get_post_revisions($post_id);
        array_unshift($revision_list, $post);
        include 'timemap-list.php';
        // Finish
        exit;
    }
}
   ; rel="self";type="application/link-format"
   ; from="<?php 
echo get_min_post_date_gmt($revision_list);
?>
 GMT"
   ; until="<?php 
echo get_max_post_date_gmt($revision_list);
?>
 GMT",
<?php 
$i = 0;
$len = count($revision_list);
foreach ($revision_list as $revision) {
    ?>
   <<?php 
    echo get_revision_permalink($post, $revision);
    ?>
>
   ; rel="<?php 
    if ($i == 0) {
        echo 'first ';
    }
    if ($i == $len - 1) {
        echo 'last ';
    }
    ?>
memento"; datetime="<?php 
    echo $revision->post_date_gmt;
    ?>
 GMT"<?php 
    if ($i != $len - 1) {