diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php
index a0438e9c53..5bd10e1855 100644
|
a
|
b
|
function wp_targeted_link_rel( $text ) {
|
| 3054 | 3054 | function wp_targeted_link_rel_callback( $matches ) { |
| 3055 | 3055 | $link_html = $matches[1]; |
| 3056 | 3056 | $rel_match = array(); |
| 3057 | | |
| | 3057 | $rel = 'noopener noreferrer'; |
| | 3058 | |
| 3058 | 3059 | /** |
| 3059 | 3060 | * Filters the rel values that are added to links with `target` attribute. |
| 3060 | 3061 | * |
| … |
… |
function wp_targeted_link_rel_callback( $matches ) {
|
| 3063 | 3064 | * @param string The rel values. |
| 3064 | 3065 | * @param string $link_html The matched content of the link tag including all HTML attributes. |
| 3065 | 3066 | */ |
| 3066 | | $rel = apply_filters( 'wp_targeted_link_rel', 'noopener noreferrer', $link_html ); |
| | 3067 | $targeted_link_rel = apply_filters( 'wp_targeted_link_rel', $rel, $link_html ); |
| | 3068 | if( $targeted_link_rel ){ |
| | 3069 | $rel = $targeted_link_rel; |
| | 3070 | } |
| 3067 | 3071 | |
| 3068 | 3072 | // Value with delimiters, spaces around are optional. |
| 3069 | 3073 | $attr_regex = '|rel\s*=\s*?(\\\\{0,1}["\'])(.*?)\\1|i'; |
diff --git a/tests/phpunit/tests/formatting/WPTargetedLinkRel.php b/tests/phpunit/tests/formatting/WPTargetedLinkRel.php
index 49c843ec2c..832b82bef7 100644
|
a
|
b
|
class Tests_Targeted_Link_Rel extends WP_UnitTestCase {
|
| 71 | 71 | $expected = '<p>Links: <a href="/" target="_blank" rel="noopener noreferrer">Change me</a> <a href="/">Do not change me</a></p>'; |
| 72 | 72 | $this->assertEquals( $expected, wp_targeted_link_rel( $content ) ); |
| 73 | 73 | } |
| | 74 | |
| | 75 | public function test_filter_non_empty_value() { |
| | 76 | add_filter('wp_targeted_link_rel', array( $this, 'filter_empty_targeted_link_rel' ) ); |
| | 77 | $content = '<p>Links: <a href="/" target="_blank">No rel</a></p>'; |
| | 78 | $expected = '<p>Links: <a href="/" target="_blank" rel="noopener noreferrer">No rel</a></p>'; |
| | 79 | $this->assertEquals( $expected, wp_targeted_link_rel( $content ) ); |
| | 80 | remove_filter( 'wp_targeted_link_rel', array( $this, 'filter_empty_targeted_link_rel' ) ); |
| | 81 | } |
| | 82 | |
| | 83 | public function filter_empty_targeted_link_rel( $value ) { |
| | 84 | return ''; |
| | 85 | } |
| | 86 | |
| 74 | 87 | } |