From ef80502b9a8106956d2eaaec5988d870027f09b9 Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 15 Sep 2008 16:26:37 +0000 Subject: [PATCH] Close comments for old posts. see #7741 git-svn-id: http://svn.automattic.com/wordpress/trunk@8892 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/schema.php | 8 +++----- wp-admin/options-discussion.php | 4 ++++ wp-admin/options.php | 2 +- wp-includes/comment.php | 27 +++++++++++++++++++++++++++ wp-includes/default-filters.php | 1 + wp-includes/version.php | 2 +- 6 files changed, 37 insertions(+), 7 deletions(-) diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php index f0f23f967d..a96b4c0aa8 100644 --- a/wp-admin/includes/schema.php +++ b/wp-admin/includes/schema.php @@ -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) : diff --git a/wp-admin/options-discussion.php b/wp-admin/options-discussion.php index ea75c9ef03..bd81e5c943 100644 --- a/wp-admin/options-discussion.php +++ b/wp-admin/options-discussion.php @@ -36,6 +36,10 @@ include('admin-header.php'); />
+ ') ?> +
diff --git a/wp-admin/options.php b/wp-admin/options.php index 2aa7f463fa..bd5cb7f36f 100644 --- a/wp-admin/options.php +++ b/wp-admin/options.php @@ -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' ), diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 61b5462e69..394e9f31d8 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -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; +} + ?> diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index b596d3b393..6c3affc2e5 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -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'); diff --git a/wp-includes/version.php b/wp-includes/version.php index 8eca48a005..e692536db5 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -15,6 +15,6 @@ $wp_version = '2.7-hemorrhage'; * * @global int $wp_db_version */ -$wp_db_version = 8645; +$wp_db_version = 8890; ?>