I got a request in the WordPress forums to have a way of autmatically turning off comments for entries that fall off the first page and here are the results. My idea is turn off comments for the posts that fall off your list once you post. Quite simple actually. It takes the post_ID of your new post (which is published status) , subtracts a pre-determined value to get the post for which comments need to be shut off, and then sets that information in the database.
Now that I try to post the hack, I realize it might be really difficult to find for non-programmers. Click here http://dinki.mine.nu/weblog/b2-img/b2edit.phps to get the hacked b2edit.php and save it under your wp-admin directory.
For WordPress 1.0+ :
Find post.php in your wp-admin folder and find this line:
} // end if publish
(this shows up twice, you want the one that is after the case ‘post’: )
and add this right above that // end if publish line:
//Comment off hack by LaughingLizard http://dinki.mine.nu/weblog/
$posts_per_page = get_settings(‘posts_per_page’);
$post_comment_fix_ID = $post_ID – $posts_per_page – 2;
$check_vars = $wpdb->get_results(”
SELECT post_title, ID FROM $tableposts
WHERE ID < = $post_comment_fix_ID AND comment_status = 'open' ");
if ($check_vars) {
foreach ($check_vars as $check_var) {
if (!preg_match ("//i”, $check_var->post_content)) {
$comment_close = $check_var->ID;
$result = $wpdb->query(”
UPDATE $tableposts SET
comment_status = ‘closed’
WHERE ID = ‘$comment_close’ “);
}
}
}
//End of Comments off hack
That’s it.
I installed it as above, but it does not seem to work for me.
As an example, I just put a comment here: http://www.uebelhart.net/index.php?p=12 which is a post much older than anything on the front page.
I pasted the code in the right place, and when going to
http://wordsend.org/wp-admin/post.php
I get the following error:
Parse error: parse error, unexpected T_STRING in /var/www/wordsend/wp-admin/post.php on line 409
Line 409 is this one:
SELECT post_title, ID FROM $tableposts
Help?..
This is NOT valid for anything above WordPress 1.0
Oh! Sad. I did look at your post carefully, and it says 1.0+. Okay, then.
Did you think about doing it by date instead of post ID? Post ID can’t be a bit unpredictable when you take into account draft posts and private posts.
Actually, my first instinct was to use the postID because it was readily available. But now that I have had some time to think about it and I have had to fix a few bugs that I did not think about, I believe that using the postID poses some issues. How about searching for entries where post_status=”publish” before including them in the count? I might incorporate that when I get a chance.
Could this please be updated for WP 1.0 and higher? I left a message on the WP forum
board about this. 🙂 Thanks!
Done. 🙂 Look again.
Thats a hard error to fix!
Give us some more information please.