Improve handling the existing `rel` attribute in `wp_rel_nofollow_callback()`.

Merges [45990] to the 4.6 branch.
Props xknown, sstoqnov.
Built from https://develop.svn.wordpress.org/branches/4.6@45998


git-svn-id: http://core.svn.wordpress.org/branches/4.6@45809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-09-04 17:53:19 +00:00
parent f08a1c1302
commit ef17e2b3b8
1 changed files with 8 additions and 4 deletions

View File

@ -2713,11 +2713,11 @@ function wp_rel_nofollow( $text ) {
*/ */
function wp_rel_nofollow_callback( $matches ) { function wp_rel_nofollow_callback( $matches ) {
$text = $matches[1]; $text = $matches[1];
$atts = shortcode_parse_atts( $matches[1] ); $atts = wp_kses_hair( $matches[1], wp_allowed_protocols() );
$rel = 'nofollow'; $rel = 'nofollow';
if ( ! empty( $atts['href'] ) ) { if ( ! empty( $atts['href'] ) ) {
$href_parts = wp_parse_url( $atts['href'] ); $href_parts = wp_parse_url( $atts['href']['value'] );
$href_scheme = isset( $href_parts['scheme'] ) ? $href_parts['scheme'] : ''; $href_scheme = isset( $href_parts['scheme'] ) ? $href_parts['scheme'] : '';
$href_host = isset( $href_parts['host'] ) ? $href_parts['host'] : ''; $href_host = isset( $href_parts['host'] ) ? $href_parts['host'] : '';
$home_parts = wp_parse_url( home_url() ); $home_parts = wp_parse_url( home_url() );
@ -2730,7 +2730,7 @@ function wp_rel_nofollow_callback( $matches ) {
} }
if ( ! empty( $atts['rel'] ) ) { if ( ! empty( $atts['rel'] ) ) {
$parts = array_map( 'trim', explode( ' ', $atts['rel'] ) ); $parts = array_map( 'trim', explode( ' ', $atts['rel']['value'] ) );
if ( false === array_search( 'nofollow', $parts ) ) { if ( false === array_search( 'nofollow', $parts ) ) {
$parts[] = 'nofollow'; $parts[] = 'nofollow';
} }
@ -2739,7 +2739,11 @@ function wp_rel_nofollow_callback( $matches ) {
$html = ''; $html = '';
foreach ( $atts as $name => $value ) { foreach ( $atts as $name => $value ) {
$html .= "{$name}=\"" . esc_attr( $value ) . "\" "; if ( isset( $value['vless'] ) && 'y' === $value['vless'] ) {
$html .= $name . ' ';
} else {
$html .= "{$name}=\"" . esc_attr( $value['value'] ) . '" ';
}
} }
$text = trim( $html ); $text = trim( $html );
} }