There’s probably a way to do this via one of the meta cap filters, but off the top of my head you could use the comments_open
filter to check if the currently logged in user is the author of the post and change the output of the comments_open()
function accordingly.
I’m on the patio, so can’t test, but something like this should work:
add_filter( 'comments_open', 'wpse158190_comments_open', 10, 2 );
function wpse158190_comments_open( $open, $post_id ) {
global $current_user;
get_currentuserinfo();
$post = get_post( $post_id ); // 'global $post;' may also work here
if ( $current_user->ID == $post->post_author ) return TRUE;
}
Edit:
As noted in comments, the above will also disallow anyone but the author from seeing comments.
Looking through the comment_form()
function in core, I don’t see a very clean way to accomplish this. You could run a late hook of the comment_form_default_fields
filter in order to remove the fields:
add_filter( 'comment_form_default_fields', 'wpse158195_comment_form_default_fields', 99 );
function wpse158195_comment_form_default_fields( $fields ) {
global $current_user;
get_currentuserinfo();
$post = get_post( $post_id ); // 'global $post;' may also work here
if ( $current_user->ID != $post->post_author ) unset $fields;
return $fields
}
However, I suspect this will leave a useless “Leave a reply” heading and “Post Comment” button. You could hide these by injecting some CSS on the page via the comment_form_before
action:
add_action( 'comment_form_before', 'wpse158195_comment_form_before' );
function 158195_comment_form_before() {
global $current_user;
get_currentuserinfo();
$post = get_post( $post_id ); // 'global $post;' may also work here
if ( $current_user->ID != $post->post_author ) : ?>
<style type="text/css">
#respond.comment-respond { display: none; }
</style>
<?php endif;
}