_close_comments_for_old_posts

The timeline below displays how wordpress function _close_comments_for_old_posts has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

//
// Internal.
//
/**
 * Closes comments on old posts on the fly, without any extra DB queries. Hooked to the_posts.
 *
 * @since 2.7.0
 * @access private
 *
 * @param WP_Post  $posts Post data object.
 * @param WP_Query $query Query object.
 * @return array
 */
function _close_comments_for_old_posts($posts, $query)
{
    if (empty($posts) || !$query->is_singular() || !get_option('close_comments_for_old_posts')) {
        return $posts;
    }
    /**
     * Filters the list of post types to automatically close comments for.
     *
     * @since 3.2.0
     *
     * @param string[] $post_types An array of post type names.
     */
    $post_types = apply_filters('close_comments_for_post_types', array('post'));
    if (!in_array($posts[0]->post_type, $post_types, true)) {
        return $posts;
    }
    $days_old = (int) get_option('close_comments_days_old');
    if (!$days_old) {
        return $posts;
    }
    if (time() - strtotime($posts[0]->post_date_gmt) > $days_old * DAY_IN_SECONDS) {
        $posts[0]->comment_status = 'closed';
        $posts[0]->ping_status = 'closed';
    }
    return $posts;
}

WordPress Version: 5.5

//
// Internal.
//
/**
 * Close comments on old posts on the fly, without any extra DB queries. Hooked to the_posts.
 *
 * @since 2.7.0
 * @access private
 *
 * @param WP_Post  $posts Post data object.
 * @param WP_Query $query Query object.
 * @return array
 */
function _close_comments_for_old_posts($posts, $query)
{
    if (empty($posts) || !$query->is_singular() || !get_option('close_comments_for_old_posts')) {
        return $posts;
    }
    /**
     * Filters the list of post types to automatically close comments for.
     *
     * @since 3.2.0
     *
     * @param string[] $post_types An array of post type names.
     */
    $post_types = apply_filters('close_comments_for_post_types', array('post'));
    if (!in_array($posts[0]->post_type, $post_types, true)) {
        return $posts;
    }
    $days_old = (int) get_option('close_comments_days_old');
    if (!$days_old) {
        return $posts;
    }
    if (time() - strtotime($posts[0]->post_date_gmt) > $days_old * DAY_IN_SECONDS) {
        $posts[0]->comment_status = 'closed';
        $posts[0]->ping_status = 'closed';
    }
    return $posts;
}

WordPress Version: 5.4

//
// Internal.
//
/**
 * Close comments on old posts on the fly, without any extra DB queries. Hooked to the_posts.
 *
 * @access private
 * @since 2.7.0
 *
 * @param WP_Post  $posts Post data object.
 * @param WP_Query $query Query object.
 * @return array
 */
function _close_comments_for_old_posts($posts, $query)
{
    if (empty($posts) || !$query->is_singular() || !get_option('close_comments_for_old_posts')) {
        return $posts;
    }
    /**
     * Filters the list of post types to automatically close comments for.
     *
     * @since 3.2.0
     *
     * @param string[] $post_types An array of post type names.
     */
    $post_types = apply_filters('close_comments_for_post_types', array('post'));
    if (!in_array($posts[0]->post_type, $post_types)) {
        return $posts;
    }
    $days_old = (int) get_option('close_comments_days_old');
    if (!$days_old) {
        return $posts;
    }
    if (time() - strtotime($posts[0]->post_date_gmt) > $days_old * DAY_IN_SECONDS) {
        $posts[0]->comment_status = 'closed';
        $posts[0]->ping_status = 'closed';
    }
    return $posts;
}

WordPress Version: 5.1

//
// Internal
//
/**
 * Close comments on old posts on the fly, without any extra DB queries. Hooked to the_posts.
 *
 * @access private
 * @since 2.7.0
 *
 * @param WP_Post  $posts Post data object.
 * @param WP_Query $query Query object.
 * @return array
 */
function _close_comments_for_old_posts($posts, $query)
{
    if (empty($posts) || !$query->is_singular() || !get_option('close_comments_for_old_posts')) {
        return $posts;
    }
    /**
     * Filters the list of post types to automatically close comments for.
     *
     * @since 3.2.0
     *
     * @param string[] $post_types An array of post type names.
     */
    $post_types = apply_filters('close_comments_for_post_types', array('post'));
    if (!in_array($posts[0]->post_type, $post_types)) {
        return $posts;
    }
    $days_old = (int) get_option('close_comments_days_old');
    if (!$days_old) {
        return $posts;
    }
    if (time() - strtotime($posts[0]->post_date_gmt) > $days_old * DAY_IN_SECONDS) {
        $posts[0]->comment_status = 'closed';
        $posts[0]->ping_status = 'closed';
    }
    return $posts;
}

WordPress Version: 4.6

//
// Internal
//
/**
 * Close comments on old posts on the fly, without any extra DB queries. Hooked to the_posts.
 *
 * @access private
 * @since 2.7.0
 *
 * @param WP_Post  $posts Post data object.
 * @param WP_Query $query Query object.
 * @return array
 */
function _close_comments_for_old_posts($posts, $query)
{
    if (empty($posts) || !$query->is_singular() || !get_option('close_comments_for_old_posts')) {
        return $posts;
    }
    /**
     * Filters the list of post types to automatically close comments for.
     *
     * @since 3.2.0
     *
     * @param array $post_types An array of registered post types. Default array with 'post'.
     */
    $post_types = apply_filters('close_comments_for_post_types', array('post'));
    if (!in_array($posts[0]->post_type, $post_types)) {
        return $posts;
    }
    $days_old = (int) get_option('close_comments_days_old');
    if (!$days_old) {
        return $posts;
    }
    if (time() - strtotime($posts[0]->post_date_gmt) > $days_old * DAY_IN_SECONDS) {
        $posts[0]->comment_status = 'closed';
        $posts[0]->ping_status = 'closed';
    }
    return $posts;
}

WordPress Version: 4.3

//
// Internal
//
/**
 * Close comments on old posts on the fly, without any extra DB queries. Hooked to the_posts.
 *
 * @access private
 * @since 2.7.0
 *
 * @param WP_Post  $posts Post data object.
 * @param WP_Query $query Query object.
 * @return array
 */
function _close_comments_for_old_posts($posts, $query)
{
    if (empty($posts) || !$query->is_singular() || !get_option('close_comments_for_old_posts')) {
        return $posts;
    }
    /**
     * Filter the list of post types to automatically close comments for.
     *
     * @since 3.2.0
     *
     * @param array $post_types An array of registered post types. Default array with 'post'.
     */
    $post_types = apply_filters('close_comments_for_post_types', array('post'));
    if (!in_array($posts[0]->post_type, $post_types)) {
        return $posts;
    }
    $days_old = (int) get_option('close_comments_days_old');
    if (!$days_old) {
        return $posts;
    }
    if (time() - strtotime($posts[0]->post_date_gmt) > $days_old * DAY_IN_SECONDS) {
        $posts[0]->comment_status = 'closed';
        $posts[0]->ping_status = 'closed';
    }
    return $posts;
}

WordPress Version: 3.8

//
// Internal
//
/**
 * Close comments on old posts on the fly, without any extra DB queries. Hooked to the_posts.
 *
 * @access private
 * @since 2.7.0
 *
 * @param object $posts Post data object.
 * @param object $query Query object.
 * @return object
 */
function _close_comments_for_old_posts($posts, $query)
{
    if (empty($posts) || !$query->is_singular() || !get_option('close_comments_for_old_posts')) {
        return $posts;
    }
    /**
     * Filter the list of post types to automatically close comments for.
     *
     * @since 3.2.0
     *
     * @param array $post_types An array of registered post types. Default array with 'post'.
     */
    $post_types = apply_filters('close_comments_for_post_types', array('post'));
    if (!in_array($posts[0]->post_type, $post_types)) {
        return $posts;
    }
    $days_old = (int) get_option('close_comments_days_old');
    if (!$days_old) {
        return $posts;
    }
    if (time() - strtotime($posts[0]->post_date_gmt) > $days_old * DAY_IN_SECONDS) {
        $posts[0]->comment_status = 'closed';
        $posts[0]->ping_status = 'closed';
    }
    return $posts;
}

WordPress Version: 3.7

//
// Internal
//
/**
 * Close comments on old posts on the fly, without any extra DB queries. Hooked to the_posts.
 *
 * @access private
 * @since 2.7.0
 *
 * @param object $posts Post data object.
 * @param object $query Query object.
 * @return object
 */
function _close_comments_for_old_posts($posts, $query)
{
    if (empty($posts) || !$query->is_singular() || !get_option('close_comments_for_old_posts')) {
        return $posts;
    }
    $post_types = apply_filters('close_comments_for_post_types', array('post'));
    if (!in_array($posts[0]->post_type, $post_types)) {
        return $posts;
    }
    $days_old = (int) get_option('close_comments_days_old');
    if (!$days_old) {
        return $posts;
    }
    if (time() - strtotime($posts[0]->post_date_gmt) > $days_old * DAY_IN_SECONDS) {
        $posts[0]->comment_status = 'closed';
        $posts[0]->ping_status = 'closed';
    }
    return $posts;
}