web-dev-qa-db-fra.com

Nom du lien dans les commentaires vers la page de l'auteur? Commenter Auteur Meta dans Commentaires?

Je ne savais pas exactement comment formuler la question, alors je suis sûr que je ne trouve pas non plus ce dont j'ai besoin lors de la recherche sur Google.

Je souhaite lier tous les noms des commentateurs à leur page author.php s'ils ont la capacité edit_posts (auteurs, éditeurs et administrateurs), sinon un lien vers le site Web indiqué dans leur profil.

Je n'ai pas l'habitude d'utiliser comment_author.

Merci.

4
Travis Pflanz

Edité ma réponse car le code original était légèrement imparfait. Testé et vérifié trois fois pour s’assurer qu’il fait exactement ce que vous avez demandé. :)

Prendre plaisir!

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');
5
akamaozu