Comments: Improve rel attribute usage in comments.
Internal links should be followed and it should be easier to modify other rel attributes on comments. This adds a helper function for determining if a URL is internal and also adds some new filters to make it easy to modify rel attributes in comments. Props thomasplevy, desrosj, sabernhardt, benish74, samiamnot, galbaras, jorbin. Fixes #53290, #56444. Built from https://develop.svn.wordpress.org/trunk@55289 git-svn-id: http://core.svn.wordpress.org/trunk@54822 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -218,14 +218,45 @@ function get_comment_author_email_link( $linktext = '', $before = '', $after = '
|
||||
* @return string The comment author name or HTML link for author's URL.
|
||||
*/
|
||||
function get_comment_author_link( $comment_ID = 0 ) {
|
||||
$comment = get_comment( $comment_ID );
|
||||
$url = get_comment_author_url( $comment );
|
||||
$author = get_comment_author( $comment );
|
||||
$comment = get_comment( $comment_ID );
|
||||
$comment_ID = ! empty( $comment->comment_ID ) ? $comment->comment_ID : (string) $comment_ID;
|
||||
$url = get_comment_author_url( $comment );
|
||||
$author = get_comment_author( $comment );
|
||||
|
||||
if ( empty( $url ) || 'http://' === $url ) {
|
||||
$return = $author;
|
||||
} else {
|
||||
$return = "<a href='$url' rel='external nofollow ugc' class='url'>$author</a>";
|
||||
$rel_parts = array( 'ugc' );
|
||||
if ( ! wp_is_internal_link( $url ) ) {
|
||||
$rel_parts = array_merge(
|
||||
$rel_parts,
|
||||
array( 'external', 'nofollow' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the rel attributes of the comment author's link.
|
||||
*
|
||||
* @since 6.2.0
|
||||
*
|
||||
* @param string[] $rel_parts An array of strings representing the rel
|
||||
* tags which will be joined into the anchor's
|
||||
* rel attribute.
|
||||
* @param WP_Comment $comment The comment object
|
||||
*/
|
||||
$rel_parts = apply_filters( 'comment_author_link_rel', $rel_parts, $comment );
|
||||
|
||||
$rel = implode( ' ', $rel_parts );
|
||||
$rel = esc_attr( $rel );
|
||||
// empty space before rel necessary for later sprintf.
|
||||
$rel = ! empty( $rel ) ? sprintf( ' rel="%s"', $rel ) : '';
|
||||
|
||||
$return = sprintf(
|
||||
'<a href="%1$s" class="url"%2$s>%3$s</a>',
|
||||
$url,
|
||||
$rel,
|
||||
$author
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,7 +270,7 @@ function get_comment_author_link( $comment_ID = 0 ) {
|
||||
* @param string $author The comment author's username.
|
||||
* @param string $comment_ID The comment ID as a numeric string.
|
||||
*/
|
||||
return apply_filters( 'get_comment_author_link', $return, $author, $comment->comment_ID );
|
||||
return apply_filters( 'get_comment_author_link', $return, $author, $comment_ID );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user