WordPress.org

Make WordPress Core

Changeset 34277


Ignore:
Timestamp:
09/18/2015 04:35:37 AM (5 years ago)
Author:
wonderboymusic
Message:

Comments: in wp_rel_nofollow_callback(), account for the fact that a link might already have a rel attribute. Currently, if a link already has a rel, it will result it duplicate attributes on the element with conflicting values.

Adds unit tests.

Props junsuijin, wonderboymusic.
Fixes #9959.

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r34222 r34277  
    22602260function wp_rel_nofollow_callback( $matches ) {
    22612261    $text = $matches[1];
    2262     $text = str_replace(array(' rel="nofollow"', " rel='nofollow'"), '', $text);
    2263     return "<a $text rel=\"nofollow\">";
     2262    $atts = shortcode_parse_atts( $matches[1] );
     2263    $rel = 'nofollow';
     2264    if ( ! empty( $atts['rel'] ) ) {
     2265        $parts = array_map( 'trim', explode( ' ', $atts['rel'] ) );
     2266        if ( false === array_search( 'nofollow', $parts ) ) {
     2267            $parts[] = 'nofollow';
     2268        }
     2269        $rel = implode( ' ', $parts );
     2270        unset( $atts['rel'] );
     2271
     2272        $html = '';
     2273        foreach ( $atts as $name => $value ) {
     2274            $html .= "{$name}=\"$value\" ";
     2275        }
     2276        $text = trim( $html );
     2277    }
     2278    return "<a $text rel=\"$rel\">";
    22642279}
    22652280
Note: See TracChangeset for help on using the changeset viewer.