diff --git a/wp-includes/comment.php b/wp-includes/comment.php index f17561be1a..7143461f6e 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -1387,7 +1387,7 @@ function update_comment_cache($comments) { // /** - * Close comments on old posts on the fly, without any extra DB queries. + * Close comments on old posts on the fly, without any extra DB queries. Hooked to the_posts. * * @access private * @since 2.7.0 @@ -1411,4 +1411,33 @@ function _close_comments_for_old_posts( $posts ) { return $posts; } +/** + * Close comments on an old post. Hooked to comments_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); + + if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * 24 * 60 * 60 ) ) + return false; + + return $open; +} + ?> diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 6c3affc2e5..ec47e8ad90 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -156,8 +156,10 @@ add_filter('comment_email', 'antispambot'); add_filter('option_tag_base', '_wp_filter_taxonomy_base'); add_filter('option_category_base', '_wp_filter_taxonomy_base'); add_filter( 'the_posts', '_close_comments_for_old_posts' ); +add_filter( 'comments_open', '_close_comments_for_old_post', 10, 2 ); +add_filter( 'pings_open', '_close_comments_for_old_post', 10, 2 ); -//Atom SSL support +// Atom SSL support add_filter('atom_service_url','atom_service_url_filter'); // Actions