Forums

Auto Closed Comments After 30 Days (8 posts)

  1. Lester Chan
    Member
    Posted 8 years ago #

    Hi there, I have created a small hack that will auto close your comments after 30 days.

    // Auto Closing Comments. Comments Will Automatically Be Closed After A Month Old.
    if($post->comment_status != 'closed') {
    $current_time = time();
    $post_time = the_time('U', false) + 2678400;
    if($post_time < $current_time) {
    $wpdb->query("UPDATE $tableposts SET comment_status = 'closed' WHERE ID = '$id' AND comment_status = 'open'");
    }
    }
    // End Auto Closing Comments

    Place the code in your index page right after start_wp();.
    This is how it works. For everypost on the page it will check the post date and compare. If it is more than 1 month old, it will update the "commet_status" field of $tableposts to "closed".
    It is a small scale, feel free to modify it and make it more efficient.

  2. Anonymous
    Unregistered
    Posted 7 years ago #

    Hi, I tried this code and it works:
    $current_time = time();
    $post_time = the_time('U', false) + 2678400;
    if (('open' == $post->comment_status) && ($post_time < $current_time)) {
    $wpdb->query("UPDATE $tableposts SET comment_status = 'closed' WHERE ID = '$id' AND comment_status = 'open'");
    }

  3. Anonymous
    Unregistered
    Posted 7 years ago #

    Can someone clarify where this code needs to be inserted in index.php as my file does not contain the command start_wp();
    I'm using 1.2.1

  4. Mark (podz)
    Support Maven
    Posted 7 years ago #

    There's a plugin you could use ?
    http://wiki.wordpress.org/Auto%20shutoff%20comments

  5. Anonymous
    Unregistered
    Posted 7 years ago #

    I've just activated the plug in and got the following error message
    Sorry, you need to enable sending referrers, for this feature to work.
    ?????
    I also got this message earlier tonight trying to delete a very old post.

  6. Mark (podz)
    Support Maven
    Posted 7 years ago #

    Odd.... have you just changed firewall ?
    http://codex.wordpress.org/Enable_Sending_Referrers

  7. Anonymous
    Unregistered
    Posted 7 years ago #

    That's sorted it. I had just changed to kerio because zonealarm free version kept bugging on me and just needed to untick a box.
    thanks, AGAIN :-)

  8. Mark (podz)
    Support Maven
    Posted 7 years ago #

    You are most welcome :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.