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

wordpress代码实现内容回复可见功能,第1张

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

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。内存溢出小编现在分享给大家,也给大家做个参考。

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

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的wordpress代码实现内容回复可见功能全部内容,希望文章能够帮你解决wordpress代码实现内容回复可见功能所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/1010501.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存