WordPress.org

Make WordPress Core

Opened 9 days ago

Last modified 4 days ago

#48022 reviewing enhancement

Support "ugc" rel attribute value in comments

Reported by: audrasjb Owned by: SergeyBiryukov
Milestone: 5.3 Priority: normal
Severity: normal Version:
Component: Comments Keywords: has-patch needs-dev-note has-unit-tests dev-feedback
Focuses: Cc:

Description

As announced by Google few hours earlier, rel="ugc" link attribute is now supported for user generated content like comments.

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.

Source: https://webmasters.googleblog.com/2019/09/evolving-nofollow-new-ways-to-identify.html

Let's explore a way to add this attribute value into comment links.

Attachments (6)

48022.diff (2.2 KB) - added by audrasjb 9 days ago.
First step - adds needed functions in formatting.php
48022.1.diff (2.2 KB) - added by audrasjb 9 days ago.
Adds 5.3.0 @since information to the new functions DocBlocks
48022.2.patch (3.3 KB) - added by dkarfa 8 days ago.
48022.3.patch (3.3 KB) - added by dkarfa 8 days ago.
FInal fix.
48022.4.patch (3.3 KB) - added by dkarfa 8 days ago.
48022.5.diff (6.6 KB) - added by audrasjb 4 days ago.
Adding unit tests for rel gc

Download all attachments as: .zip

Change History (13)

@audrasjb
9 days ago

First step - adds needed functions in formatting.php

@audrasjb
9 days ago

Adds 5.3.0 @since information to the new functions DocBlocks

#1 @audrasjb
9 days ago

  • Keywords dev-feedback has-patch needs-testing needs-unit-tests added; 2nd-opinion removed
  • Milestone changed from Awaiting Review to 5.3

In 48022.1.diff, fixing DocBlock @since value.

Milestoning the ticket to 5.3, since I think the implementation looks ok.
Indeed, let's first add the possibility to add that attribute value as we did with nofolllow attribute value.

We could look on real implementation in WordPress comments later if strongly needed.

Pinging @SergeyBiryukov for dev-feedback.

#2 @joostdevalk
9 days ago

In general, we should be adding rel="nofollow ugc" and not just rel="ugc". While Google now supports rel="ugc", other search engines only support rel="nofollow", so we should really combine them and deliver both.

Other than that the patch looks good @audrasjb but I'm wondering where you're hooking it to comment content? We also need to change the attributes on comment author links from nofollow to nofollow ugc.

@dkarfa
8 days ago

@dkarfa
8 days ago

FInal fix.

@dkarfa
8 days ago

#3 @audrasjb
7 days ago

Good catch @joostdevalk, thanks. We should definitely use nofollow ugc.

Thanks for the refresh @dkarfa but I think we'll encounter some edge cases:

  • If the link is already containing nofollow tag, we want to replace that with nofollow ugc
  • If the link is already containing ugc tag, we want to replace that with nofollow ugc
  • If the link is already containing ugc nofollow tag, we want to replace that with nofollow ugc

I guess we would also need some unit tests.
Will try to work on these tomorrow :)

Cheers,
Jb

#4 @audrasjb
4 days ago

  • Keywords needs-dev-note added; dev-feedback needs-testing removed

I tested @dkarfa ’s patch and it looks totally fine to me.

Here is the edge cases I tested:

<a href="https://google.com">Nothing special</a>
<a href="https://google.com" rel="nofollow">Rel nofollow</a>
<a href="https://google.com" rel="ugc nofollow">Rel ugc</a>
<a href="https://google.com" rel="sponsored nofollow">Rel sponsored</a>
<a href="https://google.com" rel="nofollow ugc">Rel nofollow ugc</a>
<a href="https://google.com" rel="nofollow sponsored ugc">Rel nofollow sponsored ugc</a>
<a href="https://google.com" rel="nofollow ug">Rel nofollow ug</a>
<a href="https://google.com" rel="nofollow ugc sponsored">Rel nofollow ugc sponsored</a>
<a href="https://google.com" rel="ugc nofollow">Rel ugc nofollow</a>
<a href="https://google.com" rel="external nofollow">Rel external</a>
<a href="https://google.com" rel="stuffy nofollow">Other rel</a>

And here is the result with 48022.4.patch:

<a href="https://google.com" rel="nofollow ugc">Nothing special</a>
<a href="https://google.com" rel="nofollow ugc">Rel nofollow</a>
<a href="https://google.com" rel="ugc nofollow">Rel ugc</a>
<a href="https://google.com" rel="sponsored nofollow ugc">Rel sponsored</a>
<a href="https://google.com" rel="nofollow ugc">Rel nofollow ugc</a>
<a href="https://google.com" rel="nofollow sponsored ugc">Rel nofollow sponsored ugc</a>
<a href="https://google.com" rel="nofollow ug ugc">Rel nofollow ug</a>
<a href="https://google.com" rel="nofollow ugc sponsored">Rel nofollow ugc sponsored</a>
<a href="https://google.com" rel="ugc nofollow">Rel ugc nofollow</a>
<a href="https://google.com" rel="external nofollow ugc">Rel external</a>
<a href="https://google.com" rel="stuffy nofollow ugc">Other rel</a>

👍

@audrasjb
4 days ago

Adding unit tests for rel gc

#5 @audrasjb
4 days ago

  • Keywords has-unit-tests dev-feedback added; needs-unit-tests removed

#6 @SergeyBiryukov
4 days ago

  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#7 @SergeyBiryukov
4 days ago

48022.5.diff is a good start, though I'm not a fan of duplicating the entire wp_rel_nofollow_callback() function just for a different attribute :)

  • Could we introduce a helper function that both wp_rel_nofollow_callback() and wp_rel_ugc_callback() could wrap?
  • Perhaps we could even just add ugc to the existing wp_rel_nofollow_callback() function? Core only uses it for comments, though I guess plugins and themes could use it for other purposes, which would need to be explored.
Note: See TracTickets for help on using tickets.