根据主题的设置方式,comments_open
可能是您想要的筛选器。(在functions.php中)
add_filter( \'comments_open\', \'block_comments_for_others\', 10, 2 );
function block_comments_for_others( $is_open, $post_id ) {
$is_open = false;
$post_author_id = get_post_field( \'post_author\', $post_id );
if ( get_current_user_id() == $post_author_id || current_user_can(\'administrator\') )
$is_open = true;
return $is_open;
}
或者在您的主题中显示评论时,可能会出现类似的情况:
if ( get_current_user_id() == get_the_author_meta( \'ID\' ) || current_user_can(\'administrator\') ) {
comments_template();
} else {
echo "No commenting for you";
}