文章最后更新时间:
给你的网站添加一个私密评论功能,该教程几乎适配99%的WordPress主题,这里以子比主题为例。文章源自奇客源码-https://www.qkget.cn/2356.html
文章源自奇客源码-https://www.qkget.cn/2356.html
教程如下
打开子比主题的 functions.php 文件,在最后一个 ?> 的前面添加以下代码:文章源自奇客源码-https://www.qkget.cn/2356.html
//私密评论
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 '<span style="color:#A6A6A6"><i class="fa fa-lock fa-fw"></i>该评论为私密评论</span>';
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'] ) {
update_comment_meta($comment_id,'_private','true');
}
}
add_action('comment_post', 'liao_mark_private_message');打开子比主题的 comments.php 文件,搜索提交评论,在其上方添加下方代码之后保存即可。(如图)文章源自奇客源码-https://www.qkget.cn/2356.html

文件路径:/wp-content/themes/zibll/template/comments.php文章源自奇客源码-https://www.qkget.cn/2356.html
<label class="but c-blue pw-1em" data-placement="top" data-toggle="tooltip" title="" style="margin-bottom: 0px; overflow: hidden; position: relative;" data-original-title="你的评论仅评论双方可见。"> <input name="is-private" type="checkbox">私密评论</label>文章源自奇客源码-https://www.qkget.cn/2356.html
© 版权声明
网站名称:奇客源码
本文链接:
版权声明:知识共享署名-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)协议进行许可
本站资源仅供个人学习交流,转载时请以超链接形式标明文章原始出处,(如有侵权联系删除)
本文链接:
版权声明:知识共享署名-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)协议进行许可
本站资源仅供个人学习交流,转载时请以超链接形式标明文章原始出处,(如有侵权联系删除)
本站代码模板仅供学习交流使用请勿商业运营,严禁从事违法,侵权等任何非法活动,否则后果自负!
THE END





















子比主题美化
精品源码资源

暂无评论内容