From 2af76ed75d89884e5ae0261c020f705e8261dff4 Mon Sep 17 00:00:00 2001 From: Jb Audras Date: Wed, 19 Mar 2025 23:13:46 +0000 Subject: [PATCH] General: Remove `noopener` from links opening in a new tab in `wp_list_bookmarks()`. This changeset removes the automatic addition of `rel="noopener"` from links targeting a new tab via `target="_blank"` in the `wp_list_bookmarks()` function. Since this was introduced, supported browsers have changed their security policies and no longer allow the opened link to have JavaScript access to the previous tab. This also removes the unit test cases previously located in `wpListBookmarks.php` as they were dedicated to test the presence of `rel="noopener"`. Follow-up to [52061], [59120]. Props audrasjb, rvouill, marineevain, jeremy80. Fixes #63096. git-svn-id: https://develop.svn.wordpress.org/trunk@60058 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/bookmark-template.php | 8 -- .../tests/bookmark/wpListBookmarks.php | 108 ------------------ 2 files changed, 116 deletions(-) delete mode 100644 tests/phpunit/tests/bookmark/wpListBookmarks.php diff --git a/src/wp-includes/bookmark-template.php b/src/wp-includes/bookmark-template.php index af48fbfdca..893494a7e9 100644 --- a/src/wp-includes/bookmark-template.php +++ b/src/wp-includes/bookmark-template.php @@ -105,14 +105,6 @@ function _walk_bookmarks( $bookmarks, $args = '' ) { $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 . '"'; } diff --git a/tests/phpunit/tests/bookmark/wpListBookmarks.php b/tests/phpunit/tests/bookmark/wpListBookmarks.php deleted file mode 100644 index ba0121fd00..0000000000 --- a/tests/phpunit/tests/bookmark/wpListBookmarks.php +++ /dev/null @@ -1,108 +0,0 @@ -bookmark->create( $args ); - $this->assertStringContainsString( $expected, wp_list_bookmarks( 'echo=0' ) ); - } - - /** - * Data provider. - * - * @return array - */ - public function data_wp_list_bookmarks_adds_noopener() { - return array( - 'target as "_blank"' => array( - 'args' => array( - 'link_name' => 'With _blank', - 'link_url' => 'https://www.wordpress.org', - 'link_target' => '_blank', - ), - 'expected' => 'rel="noopener"', - ), - 'target as "_blank" and a link relationship' => array( - 'args' => array( - 'link_name' => 'With _blank and a link relationship', - 'link_url' => 'https://www.wordpress.org', - 'link_target' => '_blank', - 'link_rel' => 'me', - ), - 'expected' => 'rel="me noopener"', - ), - 'target as "_top"' => array( - 'args' => array( - 'link_name' => 'With _top', - 'link_url' => 'https://www.wordpress.org', - 'link_target' => '_top', - ), - 'expected' => 'rel="noopener"', - ), - 'target as "_top" and a link relationship' => array( - 'args' => array( - 'link_name' => 'With _top and a link relationship', - 'link_url' => 'https://www.wordpress.org', - 'link_target' => '_top', - 'link_rel' => 'me', - ), - 'expected' => 'rel="me noopener"', - ), - ); - } - - /** - * Test that wp_list_bookmarks does not add "noopener" to the "rel" attribute. - * - * @dataProvider data_wp_list_bookmarks_does_not_add_noopener - * - * @ticket 53839 - * - * @param array $args The arguments to create the bookmark. - */ - public function test_wp_list_bookmarks_does_not_add_noopener( $args ) { - self::factory()->bookmark->create( $args ); - $this->assertStringNotContainsString( 'noopener', wp_list_bookmarks( 'echo=0' ) ); - } - - /** - * Data provider. - * - * @return array - */ - public function data_wp_list_bookmarks_does_not_add_noopener() { - return array( - 'target as "_none"' => array( - 'args' => array( - 'link_name' => 'With _blank', - 'link_url' => 'https://www.wordpress.org', - 'link_target' => '_none', - ), - ), - 'target as "_none" and a link relationship' => array( - 'args' => array( - 'link_name' => 'With _blank and a link relationship', - 'link_url' => 'https://www.wordpress.org', - 'link_target' => '_none', - 'link_rel' => 'me', - ), - ), - ); - } -}