WordPress.org

Make WordPress Core

Ticket #9959: 9959.patch

File 9959.patch, 1.3 KB (added by junsuijin, 5 years ago)
  • formatting.php

     
    12701270        global $wpdb; 
    12711271        // This is a pre save filter, so text is already escaped. 
    12721272        $text = stripslashes($text); 
    1273         $text = preg_replace_callback('|<a (.+?)>|i', 'wp_rel_nofollow_callback', $text); 
     1273        $r = array( 
     1274                "|(<a\b[^>]*?\srel=['\"])(?![^'\"]*\bnofollow\b)|i" => "$1nofollow ", 
     1275                "|<a\b(?![^>]*\srel=['\"])|i" => '<a rel="nofollow"' 
     1276        ); 
     1277        $text = preg_replace(array_keys($r), array_values($r), $text); 
    12741278        $text = $wpdb->escape($text); 
    12751279        return $text; 
    12761280} 
    12771281 
    12781282/** 
    1279  * Callback to used to add rel=nofollow string to HTML A element. 
    1280  * 
    1281  * Will remove already existing rel="nofollow" and rel='nofollow' from the 
    1282  * string to prevent from invalidating (X)HTML. 
    1283  * 
    1284  * @since 2.3.0 
    1285  * 
    1286  * @param array $matches Single Match 
    1287  * @return string HTML A Element with rel nofollow. 
    1288  */ 
    1289 function wp_rel_nofollow_callback( $matches ) { 
    1290         $text = $matches[1]; 
    1291         $text = str_replace(array(' rel="nofollow"', " rel='nofollow'"), '', $text); 
    1292         return "<a $text rel=\"nofollow\">"; 
    1293 } 
    1294  
    1295  
    1296 /** 
    12971283 * Convert one smiley code to the icon graphic file equivalent. 
    12981284 * 
    12991285 * Looks up one smiley code in the $wpsmiliestrans global array and returns an