Link name in comments to Author page? Comment Author Meta in Comments?

Edited my answer since the original code was slightly flawed. Tested and triplechecked this to make sure it does exactly what you’ve requested. 🙂

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="https://wordpress.stackexchange.com/questions/50661/$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');

Leave a Comment