From 654c413990e5750b49ba5cff1ab99e332b7177e4 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 21 Oct 2019 20:41:04 +0000 Subject: [PATCH] Comments: Add `rel="nofollow ugc"` attribute when converting plain URLs to `` tags in comments via `make_clickable()`. Introduce `make_clickable_rel` filter for the `rel` value that is added to URL matches converted to links. This is a follow-up to [46349], which added the `rel="nofollow ugc"` attribute to existing `` tags in comments via `wp_rel_ugc()`. UGC stands for User Generated Content, and the `ugc` attribute value is recommended for links within user generated content, such as comments and forum posts. See https://webmasters.googleblog.com/2019/09/evolving-nofollow-new-ways-to-identify.html. Props blogginglife, SergeyBiryukov. Reviewed by desrosj, audrasjb. Fixes #48022. Built from https://develop.svn.wordpress.org/trunk@46564 git-svn-id: http://core.svn.wordpress.org/trunk@46361 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/formatting.php | 33 ++++++++++++++++++++++++++++++--- wp-includes/version.php | 2 +- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index a5eddae784..1c94f2906e 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -2835,7 +2835,24 @@ function _make_url_clickable_cb( $matches ) { return $matches[0]; } - return $matches[1] . "$url" . $suffix; + if ( 'comment_text' === current_filter() ) { + $rel = 'nofollow ugc'; + } else { + $rel = 'nofollow'; + } + + /** + * Filters the rel value that is added to URL matches converted to links. + * + * @since 5.3.0 + * + * @param string $rel The rel value. + * @param string $url The matched URL being converted to a link tag. + */ + $rel = apply_filters( 'make_clickable_rel', $rel, $url ); + $rel = esc_attr( $rel ); + + return $matches[1] . "$url" . $suffix; } /** @@ -2865,7 +2882,17 @@ function _make_web_ftp_clickable_cb( $matches ) { return $matches[0]; } - return $matches[1] . "$dest$ret"; + if ( 'comment_text' === current_filter() ) { + $rel = 'nofollow ugc'; + } else { + $rel = 'nofollow'; + } + + /** This filter is documented in wp-includes/formatting.php */ + $rel = apply_filters( 'make_clickable_rel', $rel, $dest ); + $rel = esc_attr( $rel ); + + return $matches[1] . "$dest$ret"; } /** @@ -3148,7 +3175,7 @@ function wp_targeted_link_rel_callback( $matches ) { * * @since 5.1.0 * - * @param string The rel values. + * @param string $rel The rel values. * @param string $link_html The matched content of the link tag including all HTML attributes. */ $rel = apply_filters( 'wp_targeted_link_rel', 'noopener noreferrer', $link_html ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 28ff42bcd6..786e6f82e8 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.3-RC1-46563'; +$wp_version = '5.3-RC1-46564'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.