General: Remove noopener from links opening in a new tab in wp_list_bookmarks().
Some checks are pending
Cleanup Pull Requests / Clean up pull requests (push) Waiting to run
Coding Standards / PHP coding standards (push) Waiting to run
Coding Standards / JavaScript coding standards (push) Waiting to run
Coding Standards / Slack Notifications (push) Blocked by required conditions
Coding Standards / Failed workflow tasks (push) Blocked by required conditions
End-to-end Tests / Test with SCRIPT_DEBUG disabled (push) Waiting to run
End-to-end Tests / Test with SCRIPT_DEBUG enabled (push) Waiting to run
End-to-end Tests / Slack Notifications (push) Blocked by required conditions
End-to-end Tests / Failed workflow tasks (push) Blocked by required conditions
JavaScript Tests / QUnit Tests (push) Waiting to run
JavaScript Tests / Slack Notifications (push) Blocked by required conditions
JavaScript Tests / Failed workflow tasks (push) Blocked by required conditions
Performance Tests / Determine Matrix (push) Waiting to run
Performance Tests / ${{ matrix.multisite && 'Multisite' || 'Single Site' }} ${{ matrix.memcached && 'Memcached' || 'Default' }} (push) Blocked by required conditions
Performance Tests / Compare (push) Blocked by required conditions
Performance Tests / Slack Notifications (push) Blocked by required conditions
Performance Tests / Failed workflow tasks (push) Blocked by required conditions
PHP Compatibility / Check PHP compatibility (push) Waiting to run
PHP Compatibility / Slack Notifications (push) Blocked by required conditions
PHP Compatibility / Failed workflow tasks (push) Blocked by required conditions
PHPUnit Tests / PHP 7.2 (push) Waiting to run
PHPUnit Tests / PHP 7.3 (push) Waiting to run
PHPUnit Tests / PHP 7.4 (push) Waiting to run
PHPUnit Tests / PHP 8.0 (push) Waiting to run
PHPUnit Tests / PHP 8.1 (push) Waiting to run
PHPUnit Tests / PHP 8.2 (push) Waiting to run
PHPUnit Tests / PHP 8.3 (push) Waiting to run
PHPUnit Tests / PHP 8.4 (push) Waiting to run
PHPUnit Tests / html-api-html5lib-tests (push) Waiting to run
PHPUnit Tests / Slack Notifications (push) Blocked by required conditions
PHPUnit Tests / Failed workflow tasks (push) Blocked by required conditions
Test Build Processes / Core running from build (push) Waiting to run
Test Build Processes / Core running from src (push) Waiting to run
Test Build Processes / Gutenberg running from build (push) Waiting to run
Test Build Processes / Gutenberg running from src (push) Waiting to run
Test Build Processes / Slack Notifications (push) Blocked by required conditions
Test Build Processes / Failed workflow tasks (push) Blocked by required conditions
Upgrade Develop Version Tests / Build (push) Waiting to run
Upgrade Develop Version Tests / Upgrade from 4.9 (push) Blocked by required conditions
Upgrade Develop Version Tests / Upgrade from 6.5 (push) Blocked by required conditions
Upgrade Develop Version Tests / Upgrade from 6.6 (push) Blocked by required conditions
Upgrade Develop Version Tests / Upgrade from 6.7 (push) Blocked by required conditions
Upgrade Develop Version Tests / Slack Notifications (push) Blocked by required conditions
Upgrade Develop Version Tests / Failed workflow tasks (push) Blocked by required conditions

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
This commit is contained in:
Jb Audras 2025-03-19 23:13:46 +00:00
parent 44465fda84
commit 2af76ed75d
2 changed files with 0 additions and 116 deletions

View File

@ -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 . '"';
}

View File

@ -1,108 +0,0 @@
<?php
/**
* Test wp_list_bookmarks().
*
* @group bookmark
* @covers ::wp_list_bookmarks
*/
class Tests_Functions_wpListBookmarks extends WP_UnitTestCase {
/**
* Test that wp_list_bookmarks adds "noopener" to the "rel" attribute.
*
* @dataProvider data_wp_list_bookmarks_adds_noopener
*
* @ticket 53839
*
* @param array $args The arguments to create the bookmark.
* @param string $expected Expected string to test.
*/
public function test_wp_list_bookmarks_adds_noopener( $args, $expected ) {
self::factory()->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',
),
),
);
}
}