Support » Plugins » (yet another) block comments on older posts

  • Hi. I wanted to block comments on older entries, so I had a look in the Wiki, but all the solutions seemed overly complicated, so I wrote my own. It doesn’t fit into myhacks.php, rather I edited wp-comments.php itself:
    These lines sit in the ‘header’ of wp-comments.php, right after the call to $wpdb->getresults(); which retrieves the comments.
    <pre>//block comments if post is older than $maxdate
    //current time in seconds, minus time in seconds of post
    day, divided by seconds in day gives days since the post
    was posted
    $maxdate = 21;
    $dayssince = floor((time() - strtotime($post->post_date)) / (60*60*24));
    if ($dayssince > $maxdate) $commentsblocked = true;
    Change $maxage to the number in days you want the cutoff to be. I then inserted a hook a bit later in the document:
    if ('open' == $post->comment_status) {
    was changed to
    if ('open' == $post->comment_status && !$commentsblocked) {
    $dayssince can be used in other places in your document. If you don’t want to use it, the first section can be shortened to a single line:
    $commentsblocked = (floor((time() - strtotime($post->post_date)) / (60*60*24)) > 21) ? true : false;
    Here, change ’21’ to whatever you had $maxdate set to.

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘(yet another) block comments on older posts’ is closed to new replies.