Add an option to make comments private in WordPress

Currently there is no WordPress plugin which set comments as private. I saw an article about making comments private using a bbPress plugin named "bbPress Topics for Posts".  However, it seems that this plugin is no longer updated . Due to the outdated plugin, this method is not valid for most WordPress themes.

I found a plugin named "WordPress Comments Fields" which allows admin to add custom fields in comment area. It seems that this plugin works in most themes (It worked well in two of three themes in my system.) Please note that you should disable the JetPack Comments plugin to make it worked.

First, please install and activate the "WordPress Comments Fields" plugin. You can add a custom comment meta field under "Comments Fields" in the Dashboard.

WordPress Comments Fields - A new custom field addedWhen you add a new field, it will be shown in your comments system:

A new comment meta field added in WordPressIn a sample above, a new drop down list was added. (Of course, you can add any meta fields (e.g. for inputting a regional information such as "City".)

When users add comments, the added comment meta field appears  in each comment:

comment metaAs shown above, the custom met fields are shown immediately after the comment content. (You will be able to hide them by modifying the plugin source files with ease.)

The problem is how we can retrieve the value of the newly added "custom meta field" from database. You can find that the custom field values were added under the table "commentmeta."

commentmeta values in database
If we can retrieve these meta field values, we will be able to create a php code which compares each value if it's a private or public and then outputs "It's a private comment" if its value is "private." To obtain the meta field, we need to use get comment meta function. 

php $meta_values = get_comment_meta( $comment_id, $key, $single ); ?>

A conditional php code can be added within a loop related to comments. You can find a comment loop statement in your theme's function file (functions.php.) The conditional php code snippet could be as follows:

$comment_ID_this = $comment->comment_ID;
$comment_meta_value = get_comment_meta($comment_ID_this, 'secretid', true);
if($comment_meta_value == 'Private') {
// Your code for "private" comments
else {
// You code for "public" comments

You will be able to create the code for "private" comments without difficulty. As discussed in this post, it will be possible to make comments private with a WordPress plugin "WordPress Comments Fields."


Leave a Comment