Make WordPress Core


Ignore:
Timestamp:
02/07/2023 06:52:24 PM (17 months ago)
Author:
jorbin
Message:

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.

File:
1 edited

Legend:

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

    r53562 r55289  
    109109        );
    110110        $urls_expected = array(
    111             '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>',
    112             'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>. Alice!',
    113             'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>, said Alice.',
    114             'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>; said Alice.',
    115             'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>: said Alice.',
    116             'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>) said Alice.',
     111            "<a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>",
     112            "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>. Alice!",
     113            "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>, said Alice.",
     114            "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>; said Alice.",
     115            "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>: said Alice.",
     116            "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>) said Alice.",
    117117        );
    118118
     
    136136        );
    137137        $urls_expected = array(
    138             '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>',
    139             'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>.',
    140             'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>,',
    141             'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>;',
    142             'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>:',
    143             'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>)',
     138            "<a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>",
     139            "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>.",
     140            "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>,",
     141            "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>;",
     142            "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>:",
     143            "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>)",
    144144        );
    145145
     
    218218        );
    219219        $urls_expected = array(
    220             'Example: WordPress, test (some text), I love example.com (<a href="http://example.org" rel="nofollow">http://example.org</a>), it is brilliant',
     220            'Example: WordPress, test (some text), I love example.com (<a href="http://example.org">http://example.org</a>), it is brilliant',
    221221            'Example: WordPress, test (some text), I love example.com (<a href="http://example.com" rel="nofollow">http://example.com</a>), it is brilliant',
    222222            'Some text followed by a bracketed link with a trailing elipsis (<a href="http://example.com" rel="nofollow">http://example.com</a>)...',
     
    422422    /**
    423423     * @ticket 48022
     424     * @ticket 56444
    424425     * @dataProvider data_add_rel_ugc_in_comments
    425426     */
     
    439440
    440441    public function data_add_rel_ugc_in_comments() {
     442
     443        $home_url_http  = set_url_scheme( home_url(), 'http' );
     444        $home_url_https = set_url_scheme( home_url(), 'https' );
     445
    441446        return array(
     447            // @ticket 48022
    442448            array(
    443449                'http://wordpress.org',
     
    446452            array(
    447453                'www.wordpress.org',
    448                 '<p><a href="http://www.wordpress.org" rel="nofollow ugc">http://www.wordpress.org</a>',
     454                '<p><a href=\'http://www.wordpress.org\' rel="nofollow ugc">http://www.wordpress.org</a>',
     455            ),
     456            // @ticket 56444
     457            array(
     458                'www.example.org',
     459                '<p><a href=\'http://www.example.org\' rel="nofollow ugc">http://www.example.org</a>',
     460            ),
     461            array(
     462                $home_url_http,
     463                '<a href="' . $home_url_http . '" rel="ugc">' . $home_url_http . '</a>',
     464            ),
     465            array(
     466                $home_url_https,
     467                '<a href="' . $home_url_https . '" rel="ugc">' . $home_url_https . '</a>',
    449468            ),
    450469        );
Note: See TracChangeset for help on using the changeset viewer.