Wordpress Plugin : Flexible Comment Moderation – A Step by Step Guide

Finally, how to handle submitted comments

This is the last step. Now that the administration area finished, we can move to handling the submitted comments. This is the one that triggered comment_post action hook. As seen above, comment_post action will throw a comment ID parameter.
We will use this parameter to get current comment object using built in function get_comment and get it’s status. Wether it’s approved, awaiting moderation, or marked as SPAM.

<?php
	$comment = get_comment($comment_id);
	$status = $comment->comment_approved;
?>

We will continue the process based on this status. If it’s marked as SPAM by wordpress (be it from akismet or another comment spam plugin or maybe wordpress blacklist) we will leave it intact. If not, we will get the post ID from where current comment is submitted and check wether it override the comment system or not. If it override it then we can continue the process.
Our code will look something like this:

<?php
function cr_flexible_comment_moderation_comment_post( $comment_id ) {
	$comment = get_comment($comment_id);
	$status = $comment->comment_approved;
	if($status !== "spam" ) // approved
	{
		$post_id =  $comment->comment_post_ID;

		$msm = get_post_meta( $post_id, '_cr_flexible_comment_moderation_system_mode', true);
		$mom = get_post_meta( $post_id, '_cr_flexible_comment_moderation_overide_mode', true);

		if("overide" == $msm)
		{
			$cstatus = "";
			if("approve" == $mom)
			{
				$cstatus = "approve";
			}
			else if("moderate" == $mom)
			{
				$cstatus = "hold";
			}
			wp_set_comment_status($comment_id, $cstatus);
		}
	}
	return $comment_id;
}
?>

After Word

That’s it, now we have our own flexible comment moderation plugin. I hope you enjoy this tutorial. I’m not a wordpress guru, so if there’s something wrong or could be implemented in smarter way, you can always leave a comment here so I and all reader here can learn it.


Pages: 1 2 3

  • Jake
    Works Perfectly. Thank You so much!
  • I search for this.
    Very useful if you write a post about some recent news and you cant approve manual all the comments!
  • I run several WP-blogs. Most of them are in german. The german blogging communitz is a kind of strange so I try to avoid them.

    I am glad to find sites like this and have in general the feeling that the WP-Community in english is much more helpful than the german one and of course offers a bigger veriety in themes and plugins.

    Therefore I am happy to spend some hours to adjust the themes and plugins (most of them are ok) to german.

    to all out there who are sharing their knowlegde and Ideas.. Thank you a lot
  • gaziantep nakliyat
    thank you:D
blog comments powered by Disqus