最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

filters - Remove Comment Author Link only for subscribers

programmeradmin2浏览0评论

I am using this function

add_filter( 'get_comment_author_link', 'remove_comment_author_link', 10, 3 );
function remove_comment_author_link( $return, $author, $comment_ID ) {
   return $author;
}

to remove the users profile link from comments of a post.

I have been trying to use this filter but for removing the link only from subcribers users and not from everybody.

Any help would be appreciated.

I am using this function

add_filter( 'get_comment_author_link', 'remove_comment_author_link', 10, 3 );
function remove_comment_author_link( $return, $author, $comment_ID ) {
   return $author;
}

to remove the users profile link from comments of a post.

I have been trying to use this filter but for removing the link only from subcribers users and not from everybody.

Any help would be appreciated.

Share Improve this question asked May 11, 2020 at 15:02 HonolulumanHonoluluman 351 silver badge13 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

This doesn't feel very nice since it calls get_comment() and get_userdata(), but I'm not sure there's an obvious better way since the code that calls this doesn't pass in the records we need:

function remove_comment_author_link( $return, $author, $comment_ID ) {
    $comment = get_comment( $comment_ID );

    if ( $comment && $comment->user_id ) {
        $user = get_userdata( $comment->user_id );

        if ( $user && $user->has_cap( "edit_posts" ) ) {
            // This user is contributor or better: show author link
            return $return;
        }
    }

    // Subscriber or not a blog user
    return $author;
}

and other functions have already made the exact same lookups and so the values will already be in wp_cache_get() for this page load.

I'm also using "edit_posts" to test if a user is better than subscriber: there may be better ways to do this too. (And I'm surprised we don't have to HTML-escape $author, but the existing get_author_comment_link() code doesn't.)

发布评论

评论列表(0)

  1. 暂无评论