Close comments for old posts. see #7741

git-svn-id: http://svn.automattic.com/wordpress/trunk@8892 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-09-15 16:26:37 +00:00
parent 8a4cf0eab8
commit ef80502b9a
6 changed files with 37 additions and 7 deletions

View File

@ -258,17 +258,15 @@ function populate_options() {
add_option('enable_app', 0);
add_option('enable_xmlrpc', 0);
// 2.7
add_option('large_size_w', 1024);
add_option('large_size_h', 1024);
// 2.7
add_option('large_size_w', 1024);
add_option('large_size_h', 1024);
add_option('image_default_link_type', 'file');
add_option('image_default_size', '');
add_option('image_default_align', '');
add_option('close_comments_for_old_posts', 0);
add_option('close_comments_days_old', 14);
// Delete unused options
$unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce', '_wp_http_referer', 'Update', 'action', 'rich_editing', 'autosave_interval', 'deactivated_plugins');
foreach ($unusedoptions as $option) :

View File

@ -36,6 +36,10 @@ include('admin-header.php');
<input name="default_comment_status" type="checkbox" id="default_comment_status" value="open" <?php checked('open', get_option('default_comment_status')); ?> />
<?php _e('Allow people to post comments on the article') ?></label>
<br />
<label for="close_comments_for_old_posts">
<input name="close_comments_for_old_posts" type="checkbox" id="close_comments_for_old_posts" value="1" <?php checked('1', get_option('close_comments_for_old_posts')); ?> />
<?php _e('Close comments on articles older than') ?></label> <?php printf(__('%s days'), '<input name="close_comments_days_old" type="text" id="close_comments_days_old" value="' . attribute_escape(get_option('close_comments_days_old')) . '" size="3" />') ?>
<br />
<small><em><?php echo '(' . __('These settings may be overridden for individual articles.') . ')'; ?></em></small>
</fieldset></td>
</tr>

View File

@ -23,7 +23,7 @@ wp_reset_vars(array('action'));
$whitelist_options = array(
'general' => array('blogname', 'blogdescription', 'admin_email', 'users_can_register', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'comment_registration', 'default_role'),
'discussion' => array( 'default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comments_notify', 'moderation_notify', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating' ),
'discussion' => array( 'default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comments_notify', 'moderation_notify', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating', 'close_comments_for_old_posts', 'close_comments_days_old' ),
'misc' => array( 'hack_file', 'use_linksupdate', 'uploads_use_yearmonth_folders', 'upload_path', 'thumbnail_size_w', 'thumbnail_size_h', 'thumbnail_crop', 'medium_size_w', 'medium_size_h', 'image_default_size', 'image_default_align', 'image_default_link_type', 'large_size_w', 'large_size_h' ),
'privacy' => array( 'blog_public' ),
'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'blog_charset', 'gzipcompression', 'show_on_front', 'page_on_front', 'page_for_posts' ),

View File

@ -1406,4 +1406,31 @@ function update_comment_cache($comments) {
wp_cache_add($comment->comment_ID, $comment, 'comment');
}
//
// Internal
//
/**
* Close comments on old posts on the fly, without any extra DB queries.
*
* @since 2.7
* @package WordPress
* @subpackage Internal
*/
function _close_comments_for_old_posts( $posts ) {
if ( !is_single() || !get_option('close_comments_for_old_posts') )
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 * 24 * 60 * 60 ) ) {
$posts[0]->comment_status = 'closed';
$posts[0]->ping_status = 'closed';
}
return $posts;
}
?>

View File

@ -155,6 +155,7 @@ add_filter('pre_comment_content', 'wp_rel_nofollow', 15);
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' );
//Atom SSL support
add_filter('atom_service_url','atom_service_url_filter');

View File

@ -15,6 +15,6 @@ $wp_version = '2.7-hemorrhage';
*
* @global int $wp_db_version
*/
$wp_db_version = 8645;
$wp_db_version = 8890;
?>