加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > CMS系统 > wordpress > 正文

wordpress代码实现内容回复可见功能

发布时间:2020-12-14 14:28:14 所属栏目:wordpress 来源:网络整理
导读:由站长 通过网络收集整理的代码片段。编程之家小编现在分享给大家,也给大家做个参考。 今天给我的博客加了文章内容回复可见的功能,代码版的,网上有些都已经失效了,我特意重新整理了一份出来,并且在后台编辑器也加了快捷按钮,下面言归

以下代码由PHP站长网 52php.cn收集自互联网现在PHP站长网小编把它分享给大家,仅供参考

今天给我的博客加了文章内容回复可见的功能,代码版的,网上有些都已经失效了,我特意重新整理了一份出来,并且在后台编辑器也加了快捷按钮,下面言归正传,总共分为 3 步。

1. 在 functions.php 中加入下列代码:

// 部分内容评论可见

add_filter('the_content','hide');

add_filter('comment_text','hide');

function hide($content) {

if (preg_match_all('/<!--hide start{?([sS]*?)}?-->([sS]*?)<!--hide end-->/i',$content,$matches)) {

$params = $matches[1][0];

$defaults = array('reply_to_this' => 'false');

$params = wp_parse_args($params,$defaults);

$stats = 'hide';

?

if ($params['reply_to_this'] == 'true') {

global $current_user;

get_currentuserinfo();

?

if ($current_user->ID) {

$email = $current_user->user_email;

} else if (isset($_COOKIE['comment_author_email_'.COOKIEHASH])) {

$email = $_COOKIE['comment_author_email_'.COOKIEHASH];

}

?

$ereg = "^[_.a-z0-9]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,5}$";

if (eregi($ereg,$email)) {

global $wpdb;

global $id;

$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_author_email = '".$email."' and comment_post_id='".$id."'and comment_approved = '1'");

if ($comments) {

$stats = 'show';

}

}

$tip = __('<span class="vihide">抱歉,隐藏内容 <a href="#comments">回复</a> 后刷新可见</span>','hide');

} else {

if (isset($_COOKIE['comment_author_'.COOKIEHASH]) or current_user_can('level_0')) {

$stats = 'show';

}

$tip = __();

}

?

$hide_notice = $tip;

if ($stats == 'show') {

$content = str_replace($matches[0],$matches[2],$content);

} else {

$content = str_replace($matches[0],$hide_notice,$content);

}

}

?

return $content;

}

add_action('admin_footer','hide_footer_admin');

2.在 functions.php 加入下面代码,实现编辑器后面快捷按钮功能。

// 添加编辑器按钮 - 回复可见

function reply_view_tags($mce_settings) {

?>

<script type="text/javascript">

QTags.addButton( 'qiuzhuti_reply_view','回复可见','<!--hide start{reply_to_this=true}-->','<!--hide end-->' );

</script>

<?php

}

add_action('after_wp_tiny_mce','reply_view_tags');

3. 加入 css 样式,美化一下,可自行调整。

/*回复可见*/

.vihide{display:inline-block;text-align:center;border: 2px dashed #ff6666;padding:8px;margin:10px auto;color:#FF6666;width:100%;}

.vihide a{color:#04a1ef}

.vihide a:hover{color:#4ec6c8}

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读