[编辑]以下是修改后的代码:
$post_id = get_the_ID(); // ID of the current post.
$user_id = get_current_user_id(); // ID of the current user.
$post_author_id = get_post_field( \'post_author\', $post_id );
$is_post_author = ( $user_id && $post_author_id == $user_id );
$can_comment = $is_post_author;
/*
* If $can_comment is not yet TRUE, then it\'s because either:
* a) The user is not the author of the post; or
* b) The user is not registered on the site; or
* c) The user is logged-out.
*/
if ( $user_id && ! $can_comment ) {
$comment_count = get_comments( array(
\'post_id\' => $post_id,
\'user_id\' => $user_id,
\'count\' => true,
) );
$can_comment = empty( $comment_count );
}
if ( ! $is_post_author ) {
if ( $can_comment ) {
echo \'Post your comment.\';
} else {
echo \'Sorry, you\\\'ve commented. Or you can\\\'t comment..\';
}
}