Test for Comment Moderation Settings

>> Sunday, December 06, 2009


While designing the Unnamed Wordpress Theme, which you can download for free here, I decided to design a feature that would tell commentators whether or not comments were being moderated, and if so, display whether all comments were being moderated, or only comments from new commentators. These options can be set in Settings > Discussion panel. The two options I wanted to check for were:
  1. The checkbox,“An administrator must always approve the comment,” and…
  2. The checkbox, “Comment author must have a previously approved comment”
Unfortunately, hours of searching turned up nothing about how I could get this done, although I did find this great Option Reference, which would have been nice to have before I spent a Saturday morning figuring this out on my own.
Turns out, Wordpress’ get_option() function is what you need to test for those settings. So I added this code to my comments.php file and presto!
1.if (get_option('comment_moderation') == 1) : ?>


2.All comments are moderated before being shown
3.elseif(get_option('comment_whitelist') == 1) : ?>


4.New comments are moderated before being shown
5.endif; ?>




Code Explanation

get_option(’comment_moderation’) equals 1 when the checkbox, “An administrator must always approve the comment” is checked.
view sourceprint?
1.'comment_whitelist'); ?>




equals 1 when the checkbox, “Comment author must have a previously approved comment” is checked. Incidentally, when this checkbox is not checked,
view sourceprint?
1.'comment_whitelist'); ?>




returns null.




blog comments powered by Disqus

Post a Comment

Related Posts with Thumbnails

  © Blogger template Webnolia by Ourblogtemplates.com 2009

Back to TOP