_close_comments_for_old_post

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

WordPress Version: 6.1

/**
 * Closes comments on an old post. Hooked to comments_open and pings_open.
 *
 * @since 2.7.0
 * @access private
 *
 * @param bool $open    Comments open or closed.
 * @param int  $post_id Post ID.
 * @return bool $open
 */
function _close_comments_for_old_post($open, $post_id)
{
    if (!$open) {
        return $open;
    }
    if (!get_option('close_comments_for_old_posts')) {
        return $open;
    }
    $days_old = (int) get_option('close_comments_days_old');
    if (!$days_old) {
        return $open;
    }
    $post = get_post($post_id);
    /** This filter is documented in wp-includes/comment.php */
    $post_types = apply_filters('close_comments_for_post_types', array('post'));
    if (!in_array($post->post_type, $post_types, true)) {
        return $open;
    }
    // Undated drafts should not show up as comments closed.
    if ('0000-00-00 00:00:00' === $post->post_date_gmt) {
        return $open;
    }
    if (time() - strtotime($post->post_date_gmt) > $days_old * DAY_IN_SECONDS) {
        return false;
    }
    return $open;
}

WordPress Version: 5.5

/**
 * Close comments on an old post. Hooked to comments_open and pings_open.
 *
 * @since 2.7.0
 * @access private
 *
 * @param bool $open    Comments open or closed.
 * @param int  $post_id Post ID.
 * @return bool $open
 */
function _close_comments_for_old_post($open, $post_id)
{
    if (!$open) {
        return $open;
    }
    if (!get_option('close_comments_for_old_posts')) {
        return $open;
    }
    $days_old = (int) get_option('close_comments_days_old');
    if (!$days_old) {
        return $open;
    }
    $post = get_post($post_id);
    /** This filter is documented in wp-includes/comment.php */
    $post_types = apply_filters('close_comments_for_post_types', array('post'));
    if (!in_array($post->post_type, $post_types, true)) {
        return $open;
    }
    // Undated drafts should not show up as comments closed.
    if ('0000-00-00 00:00:00' === $post->post_date_gmt) {
        return $open;
    }
    if (time() - strtotime($post->post_date_gmt) > $days_old * DAY_IN_SECONDS) {
        return false;
    }
    return $open;
}

WordPress Version: 4.4

/**
 * Close comments on an old post. Hooked to comments_open and pings_open.
 *
 * @access private
 * @since 2.7.0
 *
 * @param bool $open Comments open or closed
 * @param int $post_id Post ID
 * @return bool $open
 */
function _close_comments_for_old_post($open, $post_id)
{
    if (!$open) {
        return $open;
    }
    if (!get_option('close_comments_for_old_posts')) {
        return $open;
    }
    $days_old = (int) get_option('close_comments_days_old');
    if (!$days_old) {
        return $open;
    }
    $post = get_post($post_id);
    /** This filter is documented in wp-includes/comment.php */
    $post_types = apply_filters('close_comments_for_post_types', array('post'));
    if (!in_array($post->post_type, $post_types)) {
        return $open;
    }
    // Undated drafts should not show up as comments closed.
    if ('0000-00-00 00:00:00' === $post->post_date_gmt) {
        return $open;
    }
    if (time() - strtotime($post->post_date_gmt) > $days_old * DAY_IN_SECONDS) {
        return false;
    }
    return $open;
}

WordPress Version: 3.8

/**
 * Close comments on an old post. Hooked to comments_open and pings_open.
 *
 * @access private
 * @since 2.7.0
 *
 * @param bool $open Comments open or closed
 * @param int $post_id Post ID
 * @return bool $open
 */
function _close_comments_for_old_post($open, $post_id)
{
    if (!$open) {
        return $open;
    }
    if (!get_option('close_comments_for_old_posts')) {
        return $open;
    }
    $days_old = (int) get_option('close_comments_days_old');
    if (!$days_old) {
        return $open;
    }
    $post = get_post($post_id);
    /** This filter is documented in wp-includes/comment.php */
    $post_types = apply_filters('close_comments_for_post_types', array('post'));
    if (!in_array($post->post_type, $post_types)) {
        return $open;
    }
    if (time() - strtotime($post->post_date_gmt) > $days_old * DAY_IN_SECONDS) {
        return false;
    }
    return $open;
}

WordPress Version: 3.7

/**
 * Close comments on an old post. Hooked to comments_open and pings_open.
 *
 * @access private
 * @since 2.7.0
 *
 * @param bool $open Comments open or closed
 * @param int $post_id Post ID
 * @return bool $open
 */
function _close_comments_for_old_post($open, $post_id)
{
    if (!$open) {
        return $open;
    }
    if (!get_option('close_comments_for_old_posts')) {
        return $open;
    }
    $days_old = (int) get_option('close_comments_days_old');
    if (!$days_old) {
        return $open;
    }
    $post = get_post($post_id);
    $post_types = apply_filters('close_comments_for_post_types', array('post'));
    if (!in_array($post->post_type, $post_types)) {
        return $open;
    }
    if (time() - strtotime($post->post_date_gmt) > $days_old * DAY_IN_SECONDS) {
        return false;
    }
    return $open;
}