WordPress根据最后一次评论时间判断是否显示评论者链接

现在WordPress博客博主指不定哪天就不更新关站,域名也不续费被域名注册商收回释放。

有很多域名就会被做小视频或者小图片的人购买解析到某站,指不定评论者的网站挂了,被搞成了有害人身心健康的网站呢。

而为了防范这种情况,同时也增强博客网站的互动性,可以根据评论者最后一次评论时间来决定是否显示评论者链接。

比如,评论者的最后一次评论时间距离当前时间超过了 10 天,就禁止显示评论者网站链接。

直接function.php贴上代码

/**
* WordPress根据最后一次评论时间来决定是否显示评论者链接
* http://www.ilxtx.com/display-or-hide-comment-author-link-according-to-last-comment-date.html
*/
function lxtx_show_comment_author_link( $return , $author, $comment_ID ){
    if ( !is_user_logged_in() ) { // 登录用户无鸭梨
        date_default_timezone_set('PRC');
        $limit_days = 10; // 天数,代表最后一次评论时间距离今天超过10天的话,则隐藏评论链接
        $comment = get_comment( $comment_ID );
        if ( !empty($comment->comment_author_email) ) {
            $last_comment = get_comments(array(
                'author_email' => $comment->comment_author_email,
                'number' => '1',
                'orderby' => 'comment_date',
                'order' => 'DESC',
                'status' => 'approve',
                'type' => 'comment'
            ));
            if ( (time() - strtotime($last_comment->comment_date)) > $limit_days*24*3600 ) {
                $return = $author;
            }
        }else{
            $return = $author;
        }
    }
    return $return;
}
add_filter('get_comment_author_link','lxtx_show_comment_author_link', 10, 3);

未经允许不得转载:主机格调 » WordPress根据最后一次评论时间判断是否显示评论者链接

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏