Skip to content

Commit

Permalink
Refactor a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
dmsnell committed Sep 5, 2023
1 parent a95ce30 commit d78f35e
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/wp-includes/formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -3318,19 +3318,18 @@ function wp_targeted_link_rel( $text ) {
}

$p = new WP_HTML_Tag_Processor( $text );
while ( $p->next_tag( 'a' ) ) {
$target = $p->get_attribute( 'target' );
if ( null === $target ) {
continue;
}

$rel = $p->get_attribute( 'rel' );
$rel = true === $rel ? "" : $rel;
$link_text = "rel=\"{$rel}\"";
while ( $p->next_tag( 'a' ) && ! is_string( $p->get_attribute( 'target' ) ) ) {
$href = $p->get_attribute( 'href' );
$rel = $p->get_attribute( 'rel' );
$rel = true === $rel ? "" : $rel;

Check failure on line 3324 in src/wp-includes/formatting.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

String "" does not require double quotes; use single quotes instead
$link_text = sprintf( 'href="%s" rel="%s"', esc_attr( $href ), esc_attr( $rel ) );

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

$all_parts = preg_split( '/\s/', "$rel $updated_rel", -1, PREG_SPLIT_NO_EMPTY );
$new_rel = implode( ' ', array_unique( $all_parts ) );
$p->set_attribute( 'rel', $new_rel );
$all_rel_parts = preg_split( '/\s/', "$rel $updated_rel", -1, PREG_SPLIT_NO_EMPTY );
$p->set_attribute( 'rel', implode( ' ', array_unique( $all_rel_parts ) ) );
}

return $p->get_updated_html();
Expand Down

0 comments on commit d78f35e

Please sign in to comment.