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 badges1 Answer
Reset to default 1This 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.)