Get the SEO Newsletter

How to Test for Comment Moderation Settings

Summary:
In this article I show you how to test for two comment moderation settings in Wordpress. 1) Whether all comments are being moderated before being shown, and 2) Whether comments from new commentators only are being moderated before being shown.

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!

<?php if (get_option('comment_moderation') == 1) : ?>
<span>All comments are moderated before being shown</span>
<?php elseif(get_option('comment_whitelist') == 1) : ?>
<span>New comments are moderated before being shown</span>
<?php endif; ?>

Code Explanation

get_option(‘comment_moderation’) equals 1 when the checkbox, “An administrator must always approve the comment” is checked.

<?php get_option('comment_whitelist'); ?>

equals 1 when the checkbox, “Comment author must have a previously approved comment” is checked. Incidentally, when this checkbox is not checked,

<?php get_option('comment_whitelist'); ?>

returns null.

 
Bookmark and Share

1 Comment so far ↓

  1. Thanx. I didn’t know anything about the Option Reference. This would be helpful to get the settings of a wordpress installation.


Leave a Reply

Email is required but will not be published. All comments are moderated and no-followed. Please do not use keywords or domains as names and do not advertise.

Please keep comments directly related to the post topic or another commenters question. If you have a question not directly related to the post, try asking your question in the WordPress Forums or Our Forums.