Make WordPress Core


Ignore:
Timestamp:
02/07/2023 06:52:24 PM (22 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/wpRelUgc.php

    r53562 r55289  
    1212     */
    1313    public function test_add_ugc() {
    14         if ( PHP_VERSION_ID >= 80100 ) {
    15             /*
    16              * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
    17              * via hooked in filter functions until a more structural solution to the
    18              * "missing input validation" conundrum has been architected and implemented.
    19              */
    20             $this->expectDeprecation();
    21             $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
    22         }
    23 
    2414        $content  = '<p>This is some cool <a href="/">Code</a></p>';
    2515        $expected = '<p>This is some cool <a href=\"/\" rel=\"nofollow ugc\">Code</a></p>';
     
    3121     */
    3222    public function test_convert_ugc() {
    33         if ( PHP_VERSION_ID >= 80100 ) {
    34             /*
    35              * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
    36              * via hooked in filter functions until a more structural solution to the
    37              * "missing input validation" conundrum has been architected and implemented.
    38              */
    39             $this->expectDeprecation();
    40             $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
    41         }
    42 
    4323        $content  = '<p>This is some cool <a href="/" rel="weird">Code</a></p>';
    4424        $expected = '<p>This is some cool <a href=\"/\" rel=\"weird nofollow ugc\">Code</a></p>';
     
    5131     */
    5232    public function test_wp_rel_ugc( $input, $output, $expect_deprecation = false ) {
    53         if ( true === $expect_deprecation && PHP_VERSION_ID >= 80100 ) {
    54             /*
    55              * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
    56              * via hooked in filter functions until a more structural solution to the
    57              * "missing input validation" conundrum has been architected and implemented.
    58              */
    59             $this->expectDeprecation();
    60             $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
    61         }
    62 
    6333        $this->assertSame( wp_slash( $output ), wp_rel_ugc( $input ) );
    6434    }
     
    10070            array(
    10171                '<a href="' . $home_url_http . '/some-url">Home URL (http)</a>',
    102                 '<a href="' . $home_url_http . '/some-url">Home URL (http)</a>',
     72                '<a href="' . $home_url_http . '/some-url" rel="ugc">Home URL (http)</a>',
    10373            ),
    10474            array(
    10575                '<a href="' . $home_url_https . '/some-url">Home URL (https)</a>',
    106                 '<a href="' . $home_url_https . '/some-url">Home URL (https)</a>',
     76                '<a href="' . $home_url_https . '/some-url" rel="ugc">Home URL (https)</a>',
    10777            ),
    10878        );
     
    11080
    11181    public function test_append_ugc_with_valueless_attribute() {
    112         if ( PHP_VERSION_ID >= 80100 ) {
    113             /*
    114              * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
    115              * via hooked in filter functions until a more structural solution to the
    116              * "missing input validation" conundrum has been architected and implemented.
    117              */
    118             $this->expectDeprecation();
    119             $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
    120         }
    12182
    12283        $content  = '<p>This is some cool <a href="demo.com" download rel="hola">Code</a></p>';
Note: See TracChangeset for help on using the changeset viewer.