编辑了我的答案,因为原始代码有轻微缺陷。测试并三次检查,以确保它完全符合您的要求。:)
Enjoy!
function comment_author_profile_link(){
/* Get the comment author information */
global $comment;
$comment_ID = $comment->user_id;
$author = get_comment_author( $comment_ID );
$url = get_comment_author_url( $comment_ID );
/* Check if commenter is registered or not */
switch ($comment_ID == 0) {
case true:
/* Unregistered commenter */
if ( empty( $url ) || \'http://\' == $url )
$return = $author;
else
$return = "<a href=\'$url\' rel=\'external nofollow\' class=\'url\' target=\'_blank\'>$author</a>";
break;
case false:
/* Registered Commenter */
$registeredID = get_userdata($comment_ID);
$authorName = $registeredID->display_name;
$authorLevel = $registeredID->user_level;
$authorURL = $registeredID->user_url;
$authorID = $registeredID->ID;
/* Check if they have edit posts capabilities & is author or higher */
if ($authorLevel > 1 && user_can($authorID,\'edit_posts\') == true && count_user_posts($authorID) > 0) {
/* Author+ with Posts */
$return = \'<a href="\'.home_url().\'/?author=\'.$authorID.\'">\'.$authorName.\'</a>\';
} else {
/* Below Author */
if ( empty( $authorURL ) || \'http://\' == $authorURL )
$return = $authorName;
else
$return = "<a href=\'$authorURL\' rel=\'external nofollow\' class=\'url\' target=\'_blank\'>$authorName</a>";
}
break;
}
return $return;
}
add_filter(\'get_comment_author_link\', \'comment_author_profile_link\');