I would allow guests comments who are not registered yet to comment only one single post. Other posts have to be commentable just for registered users.
Leave a Reply
You must be logged in to post a comment.
I would allow guests comments who are not registered yet to comment only one single post. Other posts have to be commentable just for registered users.
You must be logged in to post a comment.
That sounds like a useful feature. To get what you need you have to change three things:
The checkbox
If you open the Screen Options on a post editor page you can enable the Discussion metabox. We will add our checkbox to that metabox:
We are lucky, there is a hook:
'post_comment_status_meta_box-options'
. Letâs use it:As you can see, I invented a new post meta key
'_allow_anonymous_comments'
. The leading underscore will hide it from the Custom Fields metabox. (Related: How to delete custom field âsuggestionsâ from dropdown list)If the meta value exists already and if it is equal to
1
we preselect it.The filter
'acpp_metabox_label'
exists to allow theme authors translating that value. I was too lazy to add a language file for just one tiny string â¦Save the meta value
To save our value we hook into
'save_post'
, run some checks and store the result as an integer:Filter registration checks
And now we have to use that value on the front-end and change the result for checks on the option
comment_registration
. We donât want to change the blog wide value inwp-admin
:Thatâs why we add a check for
is_admin()
to that filter. Filtering option checks is actually simple: Hook into'pre_option_' . $option_name
and return any other value thanFALSE
. Since we do not want to returnTRUE
either, we trick that check by returning0
.This check is used by WordPress for the comment form, the comment reply links on threaded comments and when a comment is saved in
wp-comments-post.php
.Plugin
Thatâs all. You can download the code as a plugin on GitHub:
Plugin Anonymous comments per post