再谈评论区亲密度

评论区的亲密度显示应该是去年在某个时间加的功能。不过这个亲密度系统其实是有bug的,如果是注册用户,登录之后发送的评论会导致“集美们”标签失效。

对于这个问题,其实在上线不久之后就发现了,但是呢,主要是由于自己太懒了所以一直没改。但是,今天有人找上门来了,倦意 表示想要这个标签。

于是又翻了一下之前的代码,增加了注册用户的处理逻辑:

$user = get_user_by('email',$comment_author_email);
        if($user!= false) {
                //      $user_url = $wp_user['user_email'];
                //echo $user;i
                //
                $comment_reg_author_url= $user->user_url;
                $parsedUrl = parse_url($comment_reg_author_url);
                if (isset($parsedUrl['host'])) {
                        $domainName = $parsedUrl['host'];
                        $comment_author_url_qs = esc_sql('%'.$domainName.'%');
                        $linkurls = $wpdb->get_results(
                                "SELECT link_url FROM $wpdb->links WHERE link_url like '$comment_author_url_qs'");
                        if(count($linkurls)>0) {
                                echo '<img decoding="async" loading="lazy" src="https://badgen.net/badge/友链/集美们/blue?icon=chrome" alt="" height="16">&nbsp';
                                $is_add_link_badge =true;
                        }
                }
        }

全部代码:

//评论VIP标志
function get_author_class($comment_author_email,$comment_author_url) {
        global $wpdb;
        $is_add_link_badge = false;
        $adminEmail = 'root@obaby.org.cn';
        $author_count = count($wpdb->get_results(
                "SELECT comment_ID as author_count FROM $wpdb->comments WHERE comment_author_email = '$comment_author_email' "));
        if(email_exists($comment_author_email)&& $comment_author_email!=$adminEmail)echo '<img decoding="async" loading="lazy" src="https://badgen.net/badge/用户/已认证/CCFF33?icon=rss" alt="" height="16">&nbsp';
        $user = get_user_by('email',$comment_author_email);
        if($user!= false) {
                //      $user_url = $wp_user['user_email'];
                //echo $user;i
                //
                $comment_reg_author_url= $user->user_url;
                $parsedUrl = parse_url($comment_reg_author_url);
                if (isset($parsedUrl['host'])) {
                        $domainName = $parsedUrl['host'];
                        $comment_author_url_qs = esc_sql('%'.$domainName.'%');
                        $linkurls = $wpdb->get_results(
                                "SELECT link_url FROM $wpdb->links WHERE link_url like '$comment_author_url_qs'");
                        if(count($linkurls)>0) {
                                echo '<img decoding="async" loading="lazy" src="https://badgen.net/badge/友链/集美们/blue?icon=chrome" alt="" height="16">&nbsp';
                                $is_add_link_badge =true;
                        }
                }
        }
        if($comment_author_email ==$adminEmail)
        {
                echo '<img decoding="async" loading="lazy" src="https://badgen.net/badge/管理员/小妖精/ff91a4?icon=terminal" alt="公主" height="16">&nbsp';
                echo '<img decoding="async" loading="lazy" src="https://badgen.net/badge/角色/女王/red?icon=matrix" alt="Queen" height="16">&nbsp';
                $is_add_link_badge =true;
        }
        $parsedUrl = parse_url($comment_author_url);
        if (isset($parsedUrl['host'])&&$is_add_link_badge==false) {
                $domainName = $parsedUrl['host'];
                $comment_author_url_qs = esc_sql('%'.$domainName.'%');
                $linkurls = $wpdb->get_results(
                        "SELECT link_url FROM $wpdb->links WHERE link_url like '$comment_author_url_qs'");
                if(count($linkurls)>0) {
                        echo '<img decoding="async" loading="lazy" src="https://badgen.net/badge/友链/集美们/blue?icon=chrome" alt="" height="16">&nbsp';
                }
        }
        if($author_count>=1 && $author_count<10 && $comment_author_email!=$adminEmail)
                echo '<img decoding="async" loading="lazy" src="https://badgen.net/badge/亲密度/Level 1/gray?icon=codebeat" alt="Level 1" height="16">'; else if($author_count>=10 && $author_count<20 && $comment_author_email!=$adminEmail)
                echo '<img decoding="async" loading="lazy" src="https://badgen.net/badge/亲密度/Level 2/cyan?icon=codebeat" alt="Level 2" height="16">'; else if($author_count>=20 && $author_count<50 && $comment_author_email!=$adminEmail)
                echo  '<img decoding="async" loading="lazy" src="https://badgen.net/badge/亲密度/Level 3/green?icon=codebeat" alt="Level 3" height="16">'; else if($author_count>=50 && $author_count<100 && $comment_author_email!=$adminEmail)
                echo  '<img decoding="async" loading="lazy" src="https://badgen.net/badge/亲密度/Level 4/yellow?icon=codebeat" alt="Level 4" height="16">'; else if($author_count>=100 && $author_count<200 && $comment_author_email!=$adminEmail)
                echo  '<img decoding="async" loading="lazy" src="https://badgen.net/badge/亲密度/Level 5/orange?icon=codebeat" alt="Level 5" height="16">'; else if($author_count>=200 && $author_count<500 && $comment_author_email!=$adminEmail)
                echo  '<img decoding="async" loading="lazy" src="https://badgen.net/badge/亲密度/Level 6/red?icon=codebeat" alt="Level 6" height="16">'; else if($author_count>=500 && $author_count<1000 && $comment_author_email!=$adminEmail)
                echo  '<img decoding="async" loading="lazy" src="https://badgen.net/badge/亲密度/Level 7/pink?icon=codebeat" alt="Level 7" height="16">'; else if($author_count>=1000 && $author_count<2000 && $comment_author_email!=$adminEmail)
                echo  '<img decoding="async" loading="lazy" src="https://badgen.net/badge/亲密度/Level 8/purple?icon=codebeat" alt="Level 8" height="16">'; else if($author_count>=2000 && $comment_author_email!=$adminEmail)
                echo  '<img decoding="async" loading="lazy" src="https://badgen.net/badge/亲密度/Level 9/purple?icon=codebeat" alt="Level 9" height="16">';

}


在需要显示标签的地方调用function get_author_class($comment_author_email,$comment_author_url) 函数就ok了。

现在就ok了:

☆版权☆

* 网站名称:obaby@mars
* 网址:https://h4ck.org.cn/
* 个性:https://oba.by/
* 本文标题: 《再谈评论区亲密度》
* 本文链接:https://image.h4ck.org.cn/2024/03/15777
* 短链接:https://oba.by/?p=15777
* 转载文章请标明文章来源,原文标题以及原文链接。请遵从 《署名-非商业性使用-相同方式共享 2.5 中国大陆 (CC BY-NC-SA 2.5 CN) 》许可协议。


You may also like

40 comments

  1.  Level 5
    Firefox 123 Firefox 123 Windows 10 Windows 10 cn云南省红河州 移动

    这玩意我也有但是我那名字没想好,哪天从新想想,学学你的

    1. 公主 Queen 
      Google Chrome 118 Google Chrome 118 Mac OS X 10.15 Mac OS X 10.15 cn山东省青岛市 联通

      嗯嗯,可以弄上去,哈哈哈。其实没啥太大意义,就是纯粹觉得好玩。

  2. Level 3
    Microsoft Edge 122 Microsoft Edge 122 Windows 10 Windows 10 cn重庆市 移动/(丰都县)移动

    实在不爱注册更多网站了,密码根本记不住呀。所以我个人很喜欢这种记名不实名的方式。

    1. 公主 Queen 
      Google Chrome 118 Google Chrome 118 Mac OS X 10.15 Mac OS X 10.15 cn山东省青岛市 联通

      哈哈哈,不是一定要注册啊。嘻嘻。
      有邮箱就能关联到信息啦。

    1. 公主 Queen 
      Google Chrome 120 Google Chrome 120 Android 10 Android 10 cnAsia/Shanghai

      这 哈哈哈 裸照要吗? 要也不给你。
      之前换下来的那俩显示器我找了找找不到底座了。
      想要的话给我个地址给你发个到付。嘻嘻
      可以用显示器支架用,主要是我都是用支架的。

  3.  Level 5
    Google Chrome 121 Google Chrome 121 Mac OS X 10.15 Mac OS X 10.15 cn北京市 联通

    这个插件我原来还用来着,后来换主题老冲突,然后就给停了,可以开发个公共版的,大家一起来拼一下各自的网站亲密度,哈哈哈。你搞个排行榜,全部博客亲密度PK一下。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注