Nana主题增加私密留言评论的功能步骤
1、打开 Nana主题的 functions.php 文件,在最后一个 ?> 的前面添加以下代码:
//私密评论
function liao_private_message_hook( $comment_content , $comment){
$comment_ID = $comment->comment_ID;
$parent_ID = $comment->comment_parent;
$parent_email = get_comment_author_email($parent_ID);
$is_private = get_comment_meta($comment_ID,’_private’,true);
$email = $comment->comment_author_email;
$current_commenter = wp_get_current_commenter();
if ( $is_private ) $comment_content = ‘#私密# ‘ . $comment_content;
if ( $current_commenter[‘comment_author_email’] == $email || $parent_email == $current_commenter[‘comment_author_email’] || current_user_can(‘delete_user’) ) return $comment_content;
if ( $is_private ) return ‘该评论为私密评论’;
return $comment_content;
}
add_filter(‘get_comment_text’,’liao_private_message_hook’,10,2);
function liao_mark_private_message( $comment_id ){
if ( $_POST[‘is-private‘] ) {
add_comment_meta($comment_id,’_private’,’true’);
}
}
add_action(‘comment_post’, ‘liao_mark_private_message’);
2、打开 Nana主题的 comments.php 文件,找到以下代码:
<?php comment_id_fields(); do_action(‘comment_form’, $post->ID); ?>
修改为:
私密评论
<?php comment_id_fields(); do_action(‘comment_form’, $post->ID); ?>
3、打开 Nana主题的Nanaincfunctionswidgets.php 文件,找到以下代码:
<?php echo convert_smilies($my_comment->comment_content); ?>
修改为
<?php echo liao_private_message_hook($my_comment->comment_content,$my_comment);?>
即可。
至此,主题已经具备了私密留言评论的功能。只需要我们在评论时,勾选私密评论即可。具体如下图所示:
记得勾选私密评论按钮
提交评论后,评论者本人是可以在当前页面和侧边栏近期评论中看到具体的评论内容,但是如果清空浏览器缓存的话,连评论者自己也是无法看到评论内容的。具体如下图所示:
只有评论者本人和站长可见
如果不是评论者或站长的话,其他游客用户是无法看到具体的评论内容的,只能看到“该评论为私密评论”的字样。具体如下图所示: