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.

Built from https://develop.svn.wordpress.org/trunk@34277


git-svn-id: http://core.svn.wordpress.org/trunk@34241 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-09-18 04:36:24 +00:00
parent fe6a7e4baa
commit c1c8b55617
2 changed files with 18 additions and 3 deletions

View File

@ -2259,8 +2259,23 @@ function wp_rel_nofollow( $text ) {
*/
function wp_rel_nofollow_callback( $matches ) {
$text = $matches[1];
$text = str_replace(array(' rel="nofollow"', " rel='nofollow'"), '', $text);
return "<a $text rel=\"nofollow\">";
$atts = shortcode_parse_atts( $matches[1] );
$rel = 'nofollow';
if ( ! empty( $atts['rel'] ) ) {
$parts = array_map( 'trim', explode( ' ', $atts['rel'] ) );
if ( false === array_search( 'nofollow', $parts ) ) {
$parts[] = 'nofollow';
}
$rel = implode( ' ', $parts );
unset( $atts['rel'] );
$html = '';
foreach ( $atts as $name => $value ) {
$html .= "{$name}=\"$value\" ";
}
$text = trim( $html );
}
return "<a $text rel=\"$rel\">";
}
/**

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-alpha-34276';
$wp_version = '4.4-alpha-34277';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.