WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/21/2019 08:39:16 PM (8 months ago)
Author:
SergeyBiryukov
Message:

Comments: Add rel="nofollow ugc" attribute when converting plain URLs to <a> 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 <a> 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/MakeClickable.php

    r42343 r46564  
    376376
    377377    /**
     378     * @ticket 30162
    378379     * @dataProvider data_script_and_style_tags
    379      * @ticket 30162
    380380     */
    381381    public function test_dont_link_script_and_style_tags( $tag ) {
     
    400400    }
    401401
     402    /**
     403     * @ticket 48022
     404     * @dataProvider data_add_rel_ugc_in_comments
     405     */
     406    public function test_add_rel_ugc_in_comments( $content, $expected ) {
     407        $comment_id = self::factory()->comment->create(
     408            array(
     409                'comment_content' => $content,
     410            )
     411        );
     412
     413        ob_start();
     414        comment_text( $comment_id );
     415        $comment_text = ob_get_clean();
     416
     417        $this->assertContains( $expected, make_clickable( $comment_text ) );
     418    }
     419
     420    public function data_add_rel_ugc_in_comments() {
     421        return array(
     422            array(
     423                'http://wordpress.org',
     424                '<a href="http://wordpress.org" rel="nofollow ugc">http://wordpress.org</a>',
     425            ),
     426            array(
     427                'www.wordpress.org',
     428                '<p><a href="http://www.wordpress.org" rel="nofollow ugc">http://www.wordpress.org</a>',
     429            ),
     430        );
     431    }
     432
    402433}
Note: See TracChangeset for help on using the changeset viewer.