Open settings submenu links in new tabs#9130
Open settings submenu links in new tabs#9130vidushigupta0607 wants to merge 4 commits intoWordPress:trunkfrom
Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Hi @vidushigupta0607! 👋 Thank you for your contribution to WordPress! 💖 It looks like this is your first pull request to 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, |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
The account has been linked now! |
30bf468 to
9190dcf
Compare
src/wp-admin/options-general.php
Outdated
| 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>.' ), |
There was a problem hiding this comment.
| __( '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>.' ), |
There was a problem hiding this comment.
The PR has been updated as per the new ticket for the issue
9190dcf to
40edf68
Compare
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.
40edf68 to
19f08fc
Compare
The closing PHP tag was missing a tab, causing a Generic.WhiteSpace.ScopeIndent PHPCS error. Added proper tab indentation to match surrounding code structure.
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:
Benefits:
Trac Ticket (New/Main): #64623
Related Ticket (Old): #23432