Ticket #43187: 43187.diff
File 43187.diff, 3.7 KB (added by , 7 years ago) |
---|
-
src/wp-includes/default-filters.php
475 475 // Shortcodes 476 476 add_filter( 'the_content', 'do_shortcode', 11 ); // AFTER wpautop() 477 477 478 // Phishing prevention 479 add_filter( 'the_content', 'wp_rel_nofollow_noopener', 12 ); 480 478 481 // Media 479 482 add_action( 'wp_playlist_scripts', 'wp_playlist_scripts' ); 480 483 add_action( 'customize_controls_enqueue_scripts', 'wp_plupload_default_settings' ); -
src/wp-includes/formatting.php
2985 2985 } 2986 2986 2987 2987 /** 2988 * Adds rel nofollow and noopener all HTML A elements in content where target=_blank. 2989 * 2990 * @param string $text Content that may contain HTML A elements. 2991 * @return string Converted content. 2992 */ 2993 function wp_rel_nofollow_noopener( $text ) { 2994 $text = preg_replace_callback( '|<a (.+_blank.+?)>|i', 'wp_rel_nofollow_noopener_callback', $text ); 2995 return $text; 2996 } 2997 2998 /** 2999 * Callback to add rel="nofollow noopener" string to HTML A element that 3000 * has target=_blank. 3001 * 3002 * Will remove already existing nofollow and noopener from the 3003 * string to prevent from invalidating (X)HTML. 3004 * 3005 * @param array $matches Single Match 3006 * @return string HTML A Element with rel nofollow and noopener if the target is _blank 3007 */ 3008 function wp_rel_nofollow_noopener_callback( $matches ) { 3009 $text = $matches[1]; 3010 $atts = shortcode_parse_atts( $matches[1] ); 3011 $rel = 'nofollow noopener'; 3012 3013 if ( ! isset( $atts['target'] ) || '_blank' !== $atts['target'] ) { 3014 return "<a $text>"; 3015 } 3016 3017 if ( ! empty( $atts['rel'] ) ) { 3018 $parts = array_map( 'trim', explode( ' ', $atts['rel'] ) ); 3019 if ( false === array_search( 'nofollow', $parts ) ) { 3020 $parts[] = 'nofollow'; 3021 } 3022 if ( false === array_search( 'noopener', $parts ) ) { 3023 $parts[] = 'noopener'; 3024 } 3025 $rel = implode( ' ', $parts ); 3026 unset( $atts['rel'] ); 3027 3028 $html = ''; 3029 foreach ( $atts as $name => $value ) { 3030 $html .= "{$name}=\"$value\" "; 3031 } 3032 $text = trim( $html ); 3033 } 3034 return "<a $text rel=\"$rel\">"; 3035 } 3036 3037 /** 2988 3038 * Callback to add rel=nofollow string to HTML A element. 2989 3039 * 2990 3040 * Will remove already existing rel="nofollow" and rel='nofollow' from the -
tests/phpunit/tests/rest-api/rest-attachments-controller.php
1016 1016 ), 1017 1017 'description' => array( 1018 1018 'raw' => '<a href="#" target="_blank">link</a>', 1019 'rendered' => '<p><a href="#" target="_blank" >link</a></p>',1019 'rendered' => '<p><a href="#" target="_blank" rel="nofollow noopener">link</a></p>', 1020 1020 ), 1021 1021 'caption' => array( 1022 1022 'raw' => '<a href="#" target="_blank">link</a>', -
tests/phpunit/tests/rest-api/rest-posts-controller.php
3186 3186 ), 3187 3187 'content' => array( 3188 3188 'raw' => '<a href="#" target="_blank">link</a>', 3189 'rendered' => '<p><a href="#" target="_blank" >link</a></p>',3189 'rendered' => '<p><a href="#" target="_blank" rel="nofollow noopener">link</a></p>', 3190 3190 ), 3191 3191 'excerpt' => array( 3192 3192 'raw' => '<a href="#" target="_blank">link</a>',