Make WordPress Core

Changeset 52061


Ignore:
Timestamp:
11/08/2021 11:05:50 PM (19 months ago)
Author:
hellofromTonya
Message:

General: Add "noopener" to wp_list_bookmarks() output.

In the bookmarks walker _walk_bookmarks(), add a 'noopener' to the bookmark's rel attribute when there's target attribute.

Adds a new test class for wp_list_bookmarks() and tests for this change.

Follow-up to [3880], [10712].

Props birgire, costdev, hellofromTonya, mukesh27 , sergeybiryukov, tw2113.
Fixes #53839.

Location:
trunk
Files:
1 added
1 edited

Legend:

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

    r49688 r52061  
    103103        }
    104104        $rel = $bookmark->link_rel;
     105
     106        $target = $bookmark->link_target;
     107        if ( '' !== $target ) {
     108            if ( is_string( $rel ) && '' !== $rel ) {
     109                if ( ! str_contains( $rel, 'noopener' ) ) {
     110                    $rel = trim( $rel ) . ' noopener';
     111                }
     112            } else {
     113                $rel = 'noopener';
     114            }
     115
     116            $target = ' target="' . $target . '"';
     117        }
     118
    105119        if ( '' !== $rel ) {
    106120            $rel = ' rel="' . esc_attr( $rel ) . '"';
    107121        }
    108         $target = $bookmark->link_target;
    109         if ( '' !== $target ) {
    110             $target = ' target="' . $target . '"';
    111         }
     122
    112123        $output .= '<a href="' . $the_link . '"' . $rel . $title . $target . '>';
    113124
Note: See TracChangeset for help on using the changeset viewer.