• Resolved emoi

    (@emoi)


    Is there a way where I can get my comments to automatically close/lock after a certain period of time? For example, I write into my blog. After 30 days, the comments are automatically turned off.

Viewing 2 replies - 1 through 2 (of 2 total)
  • <?php
    /*
    Plugin Name: Auto-Close Comments
    Version:     0.2
    Plugin URI:  http://codex.wordpress.org/Plugins/Auto_shutoff_comments
    Description: Autoclose comments after 21 days.
    Author:      Scott Hanson
    Author URI:  http://www.papascott.de/
    */
    
    /* Add an index on comment_status to wp_posts to speed this up. */
    
    function autoclose_comments() {
        global $wpdb, $tableposts;
    
        if (!isset($tableposts))
            $tableposts = $wpdb->posts;
    
        // Set $age to the age at which a post should become stale
        $age = '120 DAY';
    
        $date = $wpdb->get_var("
            SELECT DATE_ADD(DATE_SUB(CURDATE(), INTERVAL $age), INTERVAL 1 DAY)
        ");
    
        $wpdb->query("
            	UPDATE $tableposts
    	SET comment_status = 'open', ping_status = 'open'
            	WHERE (comment_status = 'close' OR ping_status = 'close')
    	AND post_status = 'publish'
            	AND post_date < '$date'
        ");
    }
    
    add_action('publish_post',   'autoclose_comments', 7);
    add_action('edit_post',      'autoclose_comments', 7);
    add_action('delete_post',    'autoclose_comments', 7);
    add_action('comment_post',   'autoclose_comments', 7);
    add_action('trackback_post', 'autoclose_comments', 7);
    add_action('pingback_post',  'autoclose_comments', 7);
    add_action('edit_comment',   'autoclose_comments', 7);
    add_action('delete_comment', 'autoclose_comments', 7);
    add_action('template_save',  'autoclose_comments', 7);
    ?>

    A plugin called Comment Timeout will do just that.

    http://jamesmckay.net/code/comment-timeout

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Automatic comment close’ is closed to new replies.