要在WordPress评论模块中实现登录可见功能,您可以使用以下步骤:
function custom_comment_login_visibility( $comment_text ) {
if ( ! is_user_logged_in() ) {
$comment_text = '此评论仅对已登录用户可见。请登录或注册。';
}
return $comment_text;
}
add_filter( 'comment_text', 'custom_comment_login_visibility' );
<div id="comment<?php comment_ID(); ?>" <?php comment_class( $comment_classes ); ?>>
<div class="commentcontent">
<?php comment_text(); ?>
</div>
<! 其他评论信息的显示 >
</div>
然后,将其替换为以下代码:
<div id="comment<?php comment_ID(); ?>" <?php comment_class( $comment_classes ); ?>>
<div class="commentcontent">
<?php echo custom_comment_login_visibility( get_comment_text() ); ?>
</div>
<! 其他评论信息的显示 >
</div>
这将调用之前定义的custom_comment_login_visibility函数,以便在评论正文中显示登录可见消息。
请注意,此方法仅在评论内容中添加登录可见消息。如果您希望对整个评论部分进行访问控制,可能需要使用插件或更复杂的自定义开发。