Skip to content

Commit d78f35e

Browse files
committed
Refactor a bit
1 parent a95ce30 commit d78f35e

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

src/wp-includes/formatting.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3318,19 +3318,18 @@ function wp_targeted_link_rel( $text ) {
33183318
}
33193319

33203320
$p = new WP_HTML_Tag_Processor( $text );
3321-
while ( $p->next_tag( 'a' ) ) {
3322-
$target = $p->get_attribute( 'target' );
3323-
if ( null === $target ) {
3324-
continue;
3325-
}
3326-
3327-
$rel = $p->get_attribute( 'rel' );
3328-
$rel = true === $rel ? "" : $rel;
3329-
$link_text = "rel=\"{$rel}\"";
3321+
while ( $p->next_tag( 'a' ) && ! is_string( $p->get_attribute( 'target' ) ) ) {
3322+
$href = $p->get_attribute( 'href' );
3323+
$rel = $p->get_attribute( 'rel' );
3324+
$rel = true === $rel ? "" : $rel;
3325+
$link_text = sprintf( 'href="%s" rel="%s"', esc_attr( $href ), esc_attr( $rel ) );
33303326

33313327
/**
33323328
* Filters the rel values that are added to links with `target` attribute.
33333329
*
3330+
* @TODO: Some plugins scan the link text, though they mostly scan for URL patterns.
3331+
* We need to provide the existing tag HTML or find a way to update filters.
3332+
*
33343333
* @since 5.1.0
33353334
*
33363335
* @param string $rel The rel values.
@@ -3341,9 +3340,8 @@ function wp_targeted_link_rel( $text ) {
33413340
continue;
33423341
}
33433342

3344-
$all_parts = preg_split( '/\s/', "$rel $updated_rel", -1, PREG_SPLIT_NO_EMPTY );
3345-
$new_rel = implode( ' ', array_unique( $all_parts ) );
3346-
$p->set_attribute( 'rel', $new_rel );
3343+
$all_rel_parts = preg_split( '/\s/', "$rel $updated_rel", -1, PREG_SPLIT_NO_EMPTY );
3344+
$p->set_attribute( 'rel', implode( ' ', array_unique( $all_rel_parts ) ) );
33473345
}
33483346

33493347
return $p->get_updated_html();

0 commit comments

Comments
 (0)