Make pings_open() and comments_open() aware of old post settings. see #7741

git-svn-id: http://svn.automattic.com/wordpress/trunk@9015 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-09-28 03:31:26 +00:00
parent 33ad03831d
commit a21c2c2890
2 changed files with 33 additions and 2 deletions

View File

@ -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 * @access private
* @since 2.7.0 * @since 2.7.0
@ -1411,4 +1411,33 @@ function _close_comments_for_old_posts( $posts ) {
return $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;
}
?> ?>

View File

@ -156,6 +156,8 @@ add_filter('comment_email', 'antispambot');
add_filter('option_tag_base', '_wp_filter_taxonomy_base'); add_filter('option_tag_base', '_wp_filter_taxonomy_base');
add_filter('option_category_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( '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'); add_filter('atom_service_url','atom_service_url_filter');