[wp-trac] [WordPress Trac] #48022: Support "ugc" rel attribute value in comments

WordPress Trac noreply at wordpress.org
Mon Sep 30 13:20:33 UTC 2019


#48022: Support "ugc" rel attribute value in comments
-------------------------------------------------+-------------------------
 Reporter:  audrasjb                             |       Owner:
                                                 |  SergeyBiryukov
     Type:  task (blessed)                       |      Status:  closed
 Priority:  normal                               |   Milestone:  5.3
Component:  Comments                             |     Version:
 Severity:  normal                               |  Resolution:  fixed
 Keywords:  has-patch needs-dev-note has-unit-   |     Focuses:
  tests                                          |
-------------------------------------------------+-------------------------

Comment (by SergeyBiryukov):

 Replying to [comment:12 audrasjb]:
 > One small thought: shouldn't we add new unit tests (see
 [https://core.trac.wordpress.org/attachment/ticket/48022/48022.5.diff
 48022.5.diff]) or edit existing unit tests to handle `rel=ugc` attribute
 value?

 [46349] did add the tests from [attachment:"48022.5.diff"]:
 [source:trunk/tests/phpunit/tests/formatting/WPRelUgc.php?rev=46349], let
 me know if I've missed something :)

 > Dev note draft: https://docs.google.com/document/d
 /1yWniQr5AbMLQjcvRm9dUW4ynKFqutN-jYfOg0e5CS3o/edit?usp=sharing

 Thanks for the note! It looks good to me, except for this example:
 > Add external rel attribute value to a given link:
 > {{{
 > $link = '<a href="example.com">External link example</a>';
 > $external_link = wp_rel_callback( $link, 'external' );
 > echo $external_link;
 > }}}

 `wp_rel_callback()` is meant to be used as a callback for
 `preg_replace_callback()`, just like `wp_rel_nofollow_callback()` was used
 before, and won't be able to handle a full `<a>` tag.

 This would be the correct example:
 {{{
 $link = '<a href="example.com">External link example</a>';

 $external_link = preg_replace_callback(
         '|<a (.+?)>|i',
         function( $matches ) {
                 return wp_rel_callback( $matches, 'external' );
         },
         $link
 );

 echo $external_link;
 }}}

 We could probably make it a bit easier by introducing a generic `wp_rel()`
 or `wp_rel_attr()` function, however that seems out of scope for this
 ticket.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48022#comment:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list