Few WordPress-related improvements

In wordpress database, column comment_status is of type enum(‘open’, ‘closed’, ‘registered_only’). But for some reason, ‘registered_only’ is never used anywhere…

I use disable comments plugin, which is excellent because it is very simple. Here is the relevant part:
[code lang=”php”]$wpdb->query(‘UPDATE wp_posts
SET comment_status = “closed”, ping_status = “closed”
WHERE DATEDIFF(NOW(), post_date) > ‘ . $days);[/code]

And if you want it to set the comments to registered_only, you only need to change it to:
[code lang=”php”]$wpdb->query(‘UPDATE wp_posts
SET comment_status = “registered_only”, ping_status = “closed”
WHERE DATEDIFF(NOW(), post_date) > ‘ . $days);[/code]

Well… now if only ‘registered only’ did what it was supposed to, you’d be done with it. But as it doesn’t, we need to change some things. They are dependent on the theme you’re using, I’ll use the default theme to illustrate what needs to be changed. First, look into comments.php file for something this:
[code lang=”php”]if (‘open’ == $post->comment_status)[/code]
and change it to:
[code lang=”php”]if (‘open’ == $post->comment_status
|| ‘registered_only’ == $post->comment_status)[/code]
In the default theme, this needed to be changed at two places.

Then there’s one more thing:
[code lang=”php”]if (get_option(‘comment_registration’) && !$user_ID)[/code]
should be changed to:
[code lang=”php”]if ((get_option(‘comment_registration’)
|| (‘registered_only’ == $post->comment_status)) && !$user_ID)[/code]

After that, it pretty much works. You need to have user registration enabled in wordpress, though. Also, while I was at it, I decided to prevent against bots registering. So I installed Sabre. Sabre is nice, but its CAPTCHA rather sucks… well, anyway — more on that in the next post. 8-)