[wp-trac] [WordPress Trac] #53290: Prevent tagging certain links in comments with rel="nofollow ugc"

WordPress Trac noreply at wordpress.org
Fri May 28 06:28:22 UTC 2021


#53290: Prevent tagging certain links in comments with rel="nofollow ugc"
--------------------------+-----------------------------
 Reporter:  galbaras      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Comments      |    Version:  5.7.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Assuming that user generated content links should not be followed is
 generally reasonable. However, there are some exceptions, some of which
 can be overcome by filters, and some, for which there are none.

 1. The function `get_comment_author_link()` shouldn't modify the author
 link indiscriminately. Although its output can be filtered, it would be
 better to prevent link tagging for specific authors. This can be achieved
 by adding the following code on line 223 of wp-includes/comment-
 template.php:

 {{{#!php
 if ( empty( $url ) || 'http://' === $url || in_array( get_comment_author(
 $comment_ID ), apply_filters( 'comment_authors_link_allowed', [] ) ) {
     return = $author;
 }
 }}}

 2. The function `wp_rel_ugc()` shouldn't modify the author link
 indiscriminately either. It should get the comment ID and use the
 `comment_link_allowed_authors` filter as well to prevent some authors'
 links from being modified. The top of the function then becomes:

 {{{#!php
 function wp_rel_ugc( $text, $comment_ID ) {
         if ( in_array( get_comment_author( $comment_ID ), apply_filters(
 'comment_authors_link_allowed', [] ) ) {
                 return $text;
         }
 }}}

 3. The function `wp_rel_callback()` should accept a list of allowed
 domains, which should include the local domain by default. Line 3075 of
 wp-includes/formatting.php should become:

 {{{#!php
 if ( ! empty( $atts['href'] ) && ! in_array( $atts['href'], apply_filters(
 'comment_link_allowed_domains', [ get_option( 'home' ) ) ) ) {
 }}}

 These changes will provide flexibility that's currently missing in the
 comment link tagging functionality.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53290>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list