[wp-hackers] Addition to check_comment(): return false if thepost is older than 21 days

Mark Jaquith mark.wordpress at txfx.net
Sat Oct 2 08:42:44 UTC 2004


Kitty wrote:

>So basically, we need to do one of several things:
>o  Outsource all of check_comments to an included "system plugin"
>o  Make check_comments pass on more info to plugins after the initial
>   go/no-go checks are done. (Less DB queries that way)
>o  Something else that hasn't been thought of yet.
>
>I think at this point, code needs to be shown. Write up your favorite
>method and post a diff. Let us have a whack at breaking it, and then
>we'll have an idea of what works best.
>
Done.  Now, if check_comment returns TRUE, the comment is given a 
$comment_score of 0.  If it returns FALSE, it is given a $comment_score 
of 5.  Next, it does:
$comment_score = do_action('comment_check', $comment_score);

If someone so wished, they could make a plugin that ignores the 
$comment_score given by check_comment() by simply running their plugin 
with first priority, and resetting $comment_score to zero.

After all plugins have been run, $comment_score is checked.  If  the 
$comment score is >= 5, $approved is set to 0, and the comment goes to 
moderation.  Otherwise, the comment is approved ($approved = 1).

Obviously, the value of 5 will need to be user-definable, but this 
should do for testing purposes.

Here is a basic example of a plugin that uses this:

<?php
function superheros($comment_score){
global $author;

if ( $author == "superman" ){
$comment_score += 10;   
} elseif ( $author == "spiderman" ){
$comment_score -=10;
}
return $comment_score;
}

add_action('comment_check', 'superheros');
?>


Don't hesitate to blow me out of the water if I flubbed this up... I'm 
rather new to diffs, PHP, Wordpress... everything.
-------------- next part --------------
Index: wp-comments-post.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-comments-post.php,v
retrieving revision 1.14
diff -u -r1.14 wp-comments-post.php
--- wp-comments-post.php	5 Sep 2004 01:50:38 -0000	1.14
+++ wp-comments-post.php	2 Oct 2004 07:57:18 -0000
@@ -66,9 +66,17 @@
 // If we've made it this far, let's post.
 
 if( check_comment($author, $email, $url, $comment, $user_ip, $user_agent) ) {
-	$approved = 1;
+	$comment_score = 0;
 } else {
-	$approved = 0;
+	$comment_score = 5;
+}
+
+$comment_score = do_action('comment_check', $comment_score);
+
+if ( $comment_score >= 5 ) { // to do: replace number with get_settings('comment_score_cutoff')
+$approved = 0;	
+} else {
+$approved = 1;	
 }
 
 $wpdb->query("INSERT INTO $wpdb->comments 


More information about the hackers mailing list