/**
 * Sets headers on archives
 */
function addh_set_headers_for_archive($options)
{
    // WordPress archives list the posts that belong to the archive from
    // newest to oldest. We set the HTTP headers for the archive page based
    // on the first post of the archive (newest).
    // There is no need to check for pagination, since every page of the archive
    // has different posts.
    //global $post; // Using this is possibly a mistake. This should be term/author/date object of the archive.
    // Get our post object from the list of posts.
    global $posts;
    if (empty($posts)) {
        return;
    }
    $post = $posts[0];
    // The post object we use for the HTTP headers is the latest post.
    // Here it is possible to filter this post object and use what you want.
    $post = apply_filters('addh_archive_post', $post);
    // Valid post types: post
    if (!is_object($post) || !isset($post->post_type) || !in_array(get_post_type($post), addh_get_supported_post_types_archive())) {
        return;
    }
    // Retrieve stored time of post object
    $post_mtime = $post->post_modified_gmt;
    $mtime = strtotime($post_mtime);
    addh_batch_generate_headers($post, $mtime, $options);
}
Beispiel #2
0
/**
 * Sets headers on archives
 */
function addh_set_headers_for_archive($options)
{
    // WordPress archives list the posts that belong to the archive from
    // newest to oldest. We set the HTTP headers for the archive page based
    // on the first post of the archive (newest).
    // There is no need to check for pagination, since every page of the archive
    // has different posts.
    //global $post; // Using this is possibly a mistake. This should be term/author/date object of the archive.
    // Get our post object from the list of posts.
    global $posts;
    if (empty($posts)) {
        return;
    }
    $post = $posts[0];
    // The post object we use for the HTTP headers is the latest post.
    // Here it is possible to filter this post object and use what you want.
    $post = apply_filters('addh_archive_post', $post);
    // Valid post types: post
    if (!is_object($post) || !isset($post->post_type) || !in_array(get_post_type($post), addh_get_supported_post_types_archive())) {
        return;
    }
    // Retrieve stored time of post object
    $post_mtime = $post->post_modified_gmt;
    $mtime = strtotime($post_mtime);
    // Check for old content (only if a threshold is set)
    if (absint($options['cache_old_content_threshold_seconds']) > 0) {
        // Find the time that determines whether a resource should be treated as 'old content'.
        // Basically this is the current GM time minus the 'old content threshold in seconds' as set in the option.
        $threshold_time_unix = absint(gmdate('U')) - absint($options['cache_old_content_threshold_seconds']);
        // Any content which has been last modified before that time should be treated as old
        // and the 'cache_old_content_max_age_seconds' option should be used as the caching
        // timeout, instead of 'cache_max_age_seconds'.
        // Here we check whether the mtime (last modified time) is older than the threshold time.
        if ($mtime < $threshold_time_unix) {
            // This content is old. Set the caching timeout to the caching timeout of old content.
            $options['cache_max_age_seconds'] = $options['cache_old_content_max_age_seconds'];
        }
    }
    addh_batch_generate_headers($post, $mtime, $options);
}