^ Back to top

WordPress评论回复可见

plkj

功能代码:

//评论可见代码增强版,可镶嵌短代码
    function reply($content){
        if (preg_match_all('/<!--reply start-->([sS]*)<!--reply end-->/i', $content, $hide_words)){
        $stats = 'hide';
        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';
            }
        }
        $admin_email = "274728691@qq.com"; //博主Email,博主直接查看  
        if ($email == $admin_email) {
            $stats = 'show';
            }
            $hide_notice = '<div style="text-align:center;border:1px dashed #FF9A9A;padding:8px;margin:10px auto;color:#FF6666;">温馨提示:此处内容需要<a href="'. get_permalink().'#respond" title="评论本文">评论本文</a>后,<a href="javascript:window.location.reload();" title="刷新">刷新本页</a>才能查看。</div>';
            if( $stats == 'show' ){
                $content = str_replace($hide_words[0], $hide_words[1], $content);
            }else{
                $content = str_replace($hide_words[0], $hide_notice, $content);
            }
        }
        return $content;
    }
    add_filter('the_content', 'reply');
//评论可见代码增强版,可镶嵌短代码结束

将博主的email处替换为自己的即可!

效果:等了你五百年了,现在才到,有什么用?

陌陌评论 2

评论前必须登录!

登陆 注册
  1. 梦想网络
    似乎我的代码过时了。。。赶紧更新这个
  2. 飞絮落叶雪
    额,缩略图是娃娃,还是真人啊