Skip to content

Open settings submenu links in new tabs#9130

Open
vidushigupta0607 wants to merge 4 commits intoWordPress:trunkfrom
vidushigupta0607:track-23432-open-links-in-new-tab
Open

Open settings submenu links in new tabs#9130
vidushigupta0607 wants to merge 4 commits intoWordPress:trunkfrom
vidushigupta0607:track-23432-open-links-in-new-tab

Conversation

@vidushigupta0607
Copy link
Copy Markdown

@vidushigupta0607 vidushigupta0607 commented Jun 30, 2025

Problem:
Several external links on WordPress admin Settings pages—specifically General, Discussion, and Permalink—currently open in the same window. This creates multiple user experience issues:

Users may lose unsaved changes if they click an external link without saving.
Users may expect links to open in a new tab (like Edit Profile or Help links) and unintentionally navigate away.
Inconsistent link behavior across admin pages causes confusion and a fragmented interface.

Root Cause:
Some documentation/help links in the Settings pages lack target="_blank", making the UI inconsistent and unpredictable.

Solution:
Update affected external documentation/help links to include target="_blank", so they open in a new tab.
Add visual and screen-reader indicators for new-tab links to improve accessibility:

  • External link icon (Dashicons)
  • aria-label text for screen readers
  • Keep internal admin links navigating between Settings pages in the same tab, and add a JS warning for unsaved changes to prevent data loss.

Benefits:

  • Prevents accidental data loss on Settings pages.
  • Ensures consistent and predictable link behavior.
  • Improves accessibility and UX for all users.

Trac Ticket (New/Main): #64623

Related Ticket (Old): #23432

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jun 30, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props vidugupta, shailu25.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link
Copy Markdown

Hi @vidushigupta0607! 👋

Thank you for your contribution to WordPress! 💖

It looks like this is your first pull request to wordpress-develop. Here are a few things to be aware of that may help you out!

No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description.

Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making.

More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook.

Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook.

If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook.

The Developer Hub also documents the various coding standards that are followed:

Thank you,
The WordPress Project

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@vidushigupta0607
Copy link
Copy Markdown
Author

The account has been linked now!

@vidushigupta0607 vidushigupta0607 force-pushed the track-23432-open-links-in-new-tab branch from 30bf468 to 9190dcf Compare June 30, 2025 06:09
printf(
/* translators: %s: Documentation URL. */
__( 'Enter the same address here unless you <a href="%s">want your site home page to be different from your WordPress installation directory</a>.' ),
__( 'Enter the same address here unless you <a href="%s" target=_blank>want your site home page to be different from your WordPress installation directory</a>.' ),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
__( 'Enter the same address here unless you <a href="%s" target=_blank>want your site home page to be different from your WordPress installation directory</a>.' ),
__( 'Enter the same address here unless you <a href="%s" target="_blank">want your site home page to be different from your WordPress installation directory</a>.' ),

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR has been updated as per the new ticket for the issue

@vidushigupta0607 vidushigupta0607 force-pushed the track-23432-open-links-in-new-tab branch from 9190dcf to 40edf68 Compare April 9, 2026 07:12
Implement a JS-based beforeunload warning that alerts users when they attempt to navigate away from settings pages with unsaved changes. The warning:
- Only triggers when actual form changes exist (via serialize comparison)
- Handles all navigation scenarios (internal links, back/forward, tab close)
- Does NOT fire for new-tab links (which don't unload the current page)
- Suppresses warning on intentional form submission (Save Changes)
- Preserves browser bfcache by lazy-attaching beforeunload only after first user change

Additionally, fix inconsistent link accessibility across settings pages:
- Remove target="_blank" from internal admin links (e.g., moderation queue in Discussion Settings)
  to restore user control and rely on the new unsaved-changes warning for protection
- Add target="_blank" + accessibility indicators to external documentation/preview links
  following WordPress canonical pattern (visual icon + screen-reader text)
- Add rel="noopener noreferrer" for security on all new-tab links
- Ensure consistent behavior across General, Discussion, Reading, Writing, Permalink, and Privacy pages

Files modified:
- src/js/_enqueues/admin/settings.js: New module with beforeunload handler and lazy attachment
- src/wp-admin/options-head.php: Enqueue settings.js on all settings pages
- src/wp-includes/script-loader.php: Register settings script handle
- src/wp-admin/options-*.php: Update 9 link instances across 6 settings pages
- Gruntfile.js: Add build entries for new settings.js module
- tests/qunit/: Add QUnit tests for beforeunload behavior

Props: Accessibility review team, WordPress core team
Fixes: #64623 (Prevent losing data when clicking links on Settings pages)
…vior.

The settings.js module initializes at jQuery DOM ready before test forms
are created in QUnit beforeEach hooks. This caused tests to fail because
the module exited early when it couldn't find the settings form.

Fixed by replicating the settings module's initialization logic in the
test's beforeEach hook after creating the test form. This ensures the
lazy attachment handlers are properly attached to test forms.

Also simplified the lazy attachment test to directly check that
beforeunload returns undefined before changes and a message after,
rather than attempting to count handler invocations.

All 466 QUnit tests now pass.
@vidushigupta0607 vidushigupta0607 force-pushed the track-23432-open-links-in-new-tab branch from 40edf68 to 19f08fc Compare April 9, 2026 07:34
The closing PHP tag was missing a tab, causing a Generic.WhiteSpace.ScopeIndent
PHPCS error. Added proper tab indentation to match surrounding code structure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants