Skip to content

Command Palette: Fix macOs label for sites unable to determine UA via PHP#77638

Open
peterwilsoncc wants to merge 10 commits intotrunkfrom
fix/77636-command-pallete-shortcut-js-fallback
Open

Command Palette: Fix macOs label for sites unable to determine UA via PHP#77638
peterwilsoncc wants to merge 10 commits intotrunkfrom
fix/77636-command-pallete-shortcut-js-fallback

Conversation

@peterwilsoncc
Copy link
Copy Markdown
Contributor

What?

Adds a JavaScript check of the User-Agent for displaying the text in the admin bar.

Closes #77636.
See Core-65121

Why?

On sites served over a CDN is it relatively common for the CDN to strip the User-Agent HTTP header, on macOS systems this causes the incorrect label to be displayed.

How?

Adds a JavaScript fallback to test the UA and determine the best label to use.

Testing Instructions

  1. Buy a macOS computer/use BrowserStack on macOS.
  2. In your wp-config.php file, add the code $_SERVER['HTTP_USER_AGENT'] = ''; to emulate a site behind a CDN stripping the header
  3. Visit /wp-admin
  4. Ensure the label is correct on this branch.
  5. Ensure the label is incorrect on trunk
  6. Remove the code added to the wp-config file to avoid confusion later.

Testing Instructions for Keyboard

N/A

Screenshots or screencast

Before After
Screenshot 2026-04-24 at 11 26 31 am Screenshot 2026-04-24 at 11 25 14 am

Use of AI Tools

N/A

@peterwilsoncc peterwilsoncc added [Type] Bug An existing feature does not function as intended [Feature] Command Palette labels Apr 24, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 24, 2026

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.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: peterwilsoncc <peterwilsoncc@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>

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

@peterwilsoncc peterwilsoncc force-pushed the fix/77636-command-pallete-shortcut-js-fallback branch from 13af4cc to 4343e24 Compare April 24, 2026 02:14
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 24, 2026

Flaky tests detected in 33e7592.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/24975080814
📝 Reported issues:

Copy link
Copy Markdown
Member

@ramonjd ramonjd left a comment

Choose a reason for hiding this comment

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

Just left some questions. 👋🏻

function gutenberg_add_admin_bar_script() {
if ( ! is_admin_bar_showing() ) {
return;
}
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.

do we only care about $_SERVER['HTTP_USER_AGENT']? if so could we skip the fallback if the string exists?

    // If PHP already has a reliable UA, trust it and skip the JS fallback.
    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
        return;
    }

I was wondering why something like

$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36';

wasn't forcing the Ctrl+K. Is it because the JS always loads here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ramonjd I've switched to navigator.platform as it's more reliable than UA sniffing. Due to the additional reliability I think having the script in place all the time will be helpful. I've also made a few other changes based on the reviews in WordPress/wordpress-develop#11636

Comment thread lib/compat/wordpress-7.0/command-palette.php Outdated
Comment thread lib/compat/wordpress-7.0/command-palette.php Outdated
@t-hamano t-hamano added the Backport to WP 7.0 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Apr 24, 2026
@github-project-automation github-project-automation Bot moved this to 🔎 Needs Review in WordPress 7.0 Editor Tasks Apr 25, 2026
peterwilsoncc and others added 10 commits April 27, 2026 13:25
…DNs.

Many CDNs will block the user agent from being sent to the application server in order to increase cache hits on the edge. This adds a JavaScript logic check for the UA string to the admin bar to ensure the text is correctly displayed if the UA is available via JavaScript.
Co-Authored-By: westonruter <westonruter@git.wordpress.org>
@peterwilsoncc peterwilsoncc force-pushed the fix/77636-command-pallete-shortcut-js-fallback branch from e724755 to 33e7592 Compare April 27, 2026 03:25
@t-hamano t-hamano added the OS Issues Issues or PRs that are related to OS specific problems label Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport to WP 7.0 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta [Feature] Command Palette OS Issues Issues or PRs that are related to OS specific problems [Type] Bug An existing feature does not function as intended

Projects

Status: 🔎 Needs Review

Development

Successfully merging this pull request may close these issues.

Command Palette: Add JavaScript operating system check for admin bar label text.

3 participants