IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    再谈评论区亲密度

    obaby发表于 2024-03-11 13:54:49
    love 0

    评论区的亲密度显示应该是去年在某个时间加的功能。不过这个亲密度系统其实是有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了:

    The post 再谈评论区亲密度 first appeared on obaby@mars.



沪ICP备19023445号-2号
友情链接