Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Only allow post author to reply to a comment on their post. WordPress

  • SOLVED

Only allow post author to reply to a comment on their post.

I'm looking for a nifty piece of code that will prevent a post's author from initiating a new comment on their own post/s. Essentially, the post's author can only <strong><strong>reply</strong></strong> to a comment on their own post. <em>The author can however post any comment on other author's posts</em>.

Answers (1)

2014-11-15

Dbranes answers:

Here's one way to prevent it:

add_action( 'pre_comment_on_post', 'wpq_pre_commenting' );
function wpq_pre_commenting( $pid ) {
$parent_id = filter_input( INPUT_POST, 'comment_parent', FILTER_SANITIZE_NUMBER_INT );
$post = get_post( $pid );
$cuid = get_current_user_id();
if( ! is_null( $post ) && $post->post_author == $cuid && 0 == $parent_id ) {
wp_die( 'Sorry, post author can only reply to a comment!' );
}
}


pjeaje comments:

Thanks :)