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.
Built from https://develop.svn.wordpress.org/trunk@52061


git-svn-id: http://core.svn.wordpress.org/trunk@51653 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
hellofromTonya 2021-11-08 23:06:58 +00:00
parent a308811553
commit 85fedc53ba
2 changed files with 16 additions and 5 deletions

View File

@ -102,13 +102,24 @@ function _walk_bookmarks( $bookmarks, $args = '' ) {
$title = ' title="' . $title . '"';
}
$rel = $bookmark->link_rel;
$target = $bookmark->link_target;
if ( '' !== $target ) {
if ( is_string( $rel ) && '' !== $rel ) {
if ( ! str_contains( $rel, 'noopener' ) ) {
$rel = trim( $rel ) . ' noopener';
}
} else {
$rel = 'noopener';
}
$target = ' target="' . $target . '"';
}
if ( '' !== $rel ) {
$rel = ' rel="' . esc_attr( $rel ) . '"';
}
$target = $bookmark->link_target;
if ( '' !== $target ) {
$target = ' target="' . $target . '"';
}
$output .= '<a href="' . $the_link . '"' . $rel . $title . $target . '>';
$output .= $parsed_args['link_before'];

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.9-alpha-52060';
$wp_version = '5.9-alpha-52061';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.