quick readme & manual) Version: 1.0.1 Author: Ozh Author URI: http://planetOzh.com */ /************************************* * OPTIONAL EDIT BELOW * * ~~ * *************************************/ $ozh_moderate['max_age'] = 5; /* Age (number of days) of a post to become auto moderated * The age of the post is the age of the last activity on it : * (writing or) modifying it, or someone commenting it. An old post * with a discussion still going on will be consider active. */ $ozh_moderate['status_ok'] = ''; /* Result of for a post considered active. * Set this to "This post is opened to comments" if you want to make things clear */ $ozh_moderate['status_moderated'] = "Moderation Active: Old stuff here... Therefore your comment on this post will be moderated (i.e. don't submit twice !)
"; /* Result of for a post considered inactive. * I find it a good idea to warn about moderation, and to ask for no multiple submission */ /************************************* * DO NOT EDIT BELOW * * ~~ * *************************************/ /**************************************************************************************************************************/ // script called directly (or something global badly misconfigured :) if (!function_exists("get_option")) {wp_ozh_automoderate_readme();die;} //Wordpress Version 1.2 / 1.3+ compatibility, add this to every plugin you write :) if(!isset($wpdb->posts)) { foreach (array ("posts", "users", "categories", "post2cat", "comments", "links", "linkcategories", "options", "optiontypes", "optionvalues", "optiongroups", "optiongroup_options", "postmeta") as $table) { $wpdb->$table = ${"table".$table}; } } // the comment # $id has been added, let's check it against criteria function wp_ozh_automoderate($id) { global $wpdb, $ozh_moderate; $max_age = $ozh_moderate['max_age']; $limit = date("Y-m-d",mktime(0,0,0,date("m"), date("d") - $ozh_moderate['max_age'], date("Y"))); $post_id = $wpdb->get_var("SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID='$id'"); $lastcomment = $wpdb->get_results("select comment_date from $wpdb->comments WHERE comment_post_ID = '$post_id' AND comment_approved='1' ORDER BY comment_date DESC LIMIT 0,2"); if (is_array($lastcomment)) array_shift ($lastcomment); if (!$lastcomment[0]->comment_date) { // this is the first comment on this post // let's compare its date with the post's age $age = $wpdb->get_var("SELECT post_modified from $wpdb->posts WHERE ID = '$post_id'"); if ($age < $limit) { // post too old, let's moderate wp_ozh_automoderate_domod($id); } } elseif ($lastcomment[0]->comment_date < $limit) { // previous comment on this post is too old // this comment is going to be moderated wp_ozh_automoderate_domod($id); } } // this function moderates a comment that has been added function wp_ozh_automoderate_domod($id) { global $wpdb; $return = $wpdb->query("UPDATE $wpdb->comments SET comment_approved='0' WHERE comment_id='$id'"); } // this function prints the post status : comments accepted, comments moderated, comments closed function wp_ozh_automoderate_status($display=1) { global $wpdb, $ozh_moderate, $id; $post_id = $id; $limit = date("Y-m-d",mktime(0,0,0,date("m"), date("d") - $ozh_moderate['max_age'], date("Y"))); $lastcomment = $wpdb->get_var("select comment_date from $wpdb->comments WHERE comment_post_ID = '$post_id' AND comment_approved='1' ORDER BY comment_date DESC LIMIT 0,1"); if (!$lastcomment) { // no comments, let's check post's age $age = $wpdb->get_var("SELECT post_modified from $wpdb->posts WHERE ID = '$post_id'"); if ($age < $limit) { // post too old print $ozh_moderate['status_moderated']; } else { print $ozh_moderate['status_ok']; } } elseif ($lastcomment < $limit) { // last comment on this post is too old $msg = $ozh_moderate['status_moderated']; } else { $msg = $ozh_moderate['status_ok']; } if ($display) { print $msg; } else { return $msg; } } function wp_ozh_automoderate_readme () { echo ' Auto Moderate Comments on Old Posts Plugin for Wordpress - By Ozh

Thanks :)

Thank you for installing this plugin !

About this plugin

This plugins sends to moderation queue any comment added on a post where there has been no activity for XX days.

No activity means : the post has not been posted, or modified, or there have been no comment made on it, in the last XX days. So an old post with a discussion still going on it is consider still active, which is smarter than forcing a discussion to be moderated for the sake of the post age.

Of course, trackbacks and pingbacks are processed the same way.

Installation and Configuration

Feedback

I\'d appreciate your leaving a comment on the plugin page, to suggest any improvement, bug fix, or just to say if you like the plugin or not :) By the way, you\'ll find on my site several other WordPress plugins you may find valueable

Disclaimer

Any resemblance between this page and a well-known admin interface is purely coincidental :-P

'; } add_action('comment_post', 'wp_ozh_automoderate',30); add_action('trackback_post', 'wp_ozh_automoderate',30); add_action('pingback_post', 'wp_ozh_automoderate',30); ?>