
免费领流量卡 | 广告招租 |
前言
这篇文章介绍了如何在WordPress主题子比主题中添加私密评论功能的教程。要实现这个功能,需要在子比主题的functions.php文件中添加一段代码,并在comments.php文件中搜索提交评论的位置上方添加另一段代码。具体的代码和文件路径可以参考文章中的指导。
效果图
![图片[1] - 子比主题美化 – 评论区中添加“私密”评论功能代码美化教程 - 狐狸资源网](https://www.foxccs.com/wp-content/uploads/2024/07/image-233.png)
部署教程
1、打开子比主题的 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 '<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');
2、打开子比主题的 comments.php
文件,搜索提交评论,在其上方添加下方代码之后保存即可。(如图)
文件路径:/wp-content/themes/zibll/template/comments.php
![图片[2] - 子比主题美化 – 评论区中添加“私密”评论功能代码美化教程 - 狐狸资源网](https://www.foxccs.com/wp-content/uploads/2024/07/image-234.png)
1 2

© 版权声明
免责声明:本站采用CC BY-NC-SA 4.0协议,完整转载请注明来自狐狸资源网
THE END
- 最新
- 最热
只看作者