Skip to content

Conversation

@dsas
Copy link
Contributor

@dsas dsas commented Dec 17, 2025

Fixes DOTCOM-15345

Proposed changes:

  • Add a new site switcher feature to the WordPress Command Palette (requires WP 6.9+)
  • Implement REST API proxy endpoint at /jetpack/v4/sites/compact to fetch user's WordPress.com sites via the user's Jetpack connection
  • Add client-side localStorage caching (1 hour duration) with user-specific cache keys to minimize API requests
  • Implement search filtering to quickly find sites by name or domain
  • Display site icons with fallback to generic site logo
  • Support dynamic command labels based on whether site has a name or just domain

Implementation details:

  • _inc/site-switcher-endpoint.php: REST endpoint for Jetpack sites that proxies the public-api endpoint
  • _inc/site-switcher.php: JS enqueueing, and config
  • _inc/site-switcher.js: React hooks-based command loader with search filtering and caching
  • Commands show as "Switch to Site Name (domain.com)" or "Switch to: domain.com" if no name
  • Generic search terms like "site" or "switch site" show all sites; specific searches filter results

Other information:

  • Have you written new tests for your changes, if applicable? - No tests added (following pattern of other _inc/*.js files)
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Not really. This feature only fetches existing site data through the established Jetpack connection API.

Testing instructions:

Prerequisites:

  • Jetpack plugin installed and connected to WordPress.com
  • User must have multiple WordPress.com sites

Testing steps:

  1. Install and activate Jetpack plugin from this branch
    On Simple you need to also apply 198424-ghe-Automattic/wpcom
  2. Ensure your site is connected to WordPress.com with a user account that has multiple sites
  3. On a Jetpack site navigate to any wp-admin page, on a simple or WoA site then navigate to the site-editor (core command palette is blocked by wp command palette otherwise)
  4. Open the Command Palette:
    • Mac: Cmd + K
    • Windows/Linux: Ctrl + K
  5. Type "site" or "switch site" - you should see all your WordPress.com sites listed
  6. Try searching for a specific site name or domain - results should filter accordingly
  7. Click on a site command - you should be redirected to that site's wp-admin

Expected behavior:

  • All sites show on search for generic keywords
  • Search filters work for both site names and domains
  • Icons display correctly (site-specific or fallback logo)
  • Navigation to selected site works
  • Subsequent page loads use cached data (check Network tab - no compact request for 1 hour)

Cache testing:

  1. Open browser DevTools > Network tab
  2. Open command palette and search for sites - you should see a request to /jetpack/v4/sites/compact
  3. Reload the page and open command palette again - no new request (using localStorage cache)
  4. Wait 1 hour or manually clear localStorage to see cache refresh
Screen.Recording.2025-12-18.at.11.48.56.mov

This command allows the user to search for and switch any of their
WordPress.com connected sites.
@github-actions github-actions bot added the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label Dec 17, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 17, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: January 6, 2026

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Dec 17, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 17, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the dotcom-15345-command-palette-integrate-the-new-site-switch-commands-into branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack dotcom-15345-command-palette-integrate-the-new-site-switch-commands-into

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@dsas dsas self-assigned this Dec 17, 2025
@dsas dsas marked this pull request as draft December 17, 2025 14:57
@dsas dsas added [Status] In Progress [Type] Feature Development of a new feature and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Dec 17, 2025
@dsas dsas requested a review from Copilot December 17, 2025 14:57
@jp-launch-control
Copy link

jp-launch-control bot commented Dec 17, 2025

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/plugins/jetpack/load-jetpack.php 1/42 (2.38%) -0.06% 1 ❤️‍🩹

2 files are newly checked for coverage.

File Coverage
projects/plugins/jetpack/_inc/site-switcher.php 0/40 (0.00%) 💔
projects/plugins/jetpack/_inc/site-switcher-endpoint.php 9/50 (18.00%) 💔

Full summary · PHP report · JS report

Coverage check overridden by I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. .

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a site switcher feature to the WordPress Command Palette (WordPress 6.9+), allowing users to quickly switch between their WordPress.com connected sites directly from wp-admin. The implementation includes a REST API proxy endpoint, client-side caching via localStorage, and search filtering capabilities.

Key Changes:

  • New REST API endpoint /jetpack/v4/sites/compact that proxies requests to WordPress.com's /me/sites/compact API to fetch the user's site list
  • Client-side JavaScript that integrates with WordPress Command Palette using useCommandLoader hook, with 1-hour localStorage caching
  • Script enqueuing logic that loads the site switcher on all admin pages

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 11 comments.

File Description
projects/plugins/jetpack/load-jetpack.php Includes the new site-switcher.php file in the plugin bootstrap
projects/plugins/jetpack/changelog/switch-sites-command-palette Changelog entry documenting the enhancement
projects/plugins/jetpack/_inc/site-switcher.php REST endpoint registration, script enqueuing, and user ID injection for cache namespacing
projects/plugins/jetpack/_inc/site-switcher.js React-based command loader with search filtering, localStorage caching, and site navigation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 13 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dsas dsas added the I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. label Dec 18, 2025
Command palette introduced in WP 6.3.
@dsas dsas marked this pull request as ready for review December 18, 2025 11:47
@simison
Copy link
Member

simison commented Dec 18, 2025

Couple clarifying Qs:

  • What shows up for users who have just one site?
  • What shows up for users on Jetpack sites who aren't the Jetpack connection owner or aren't connected to WP.com?
  • On multi-site WP installations with Jetpack, are there similar core commands and how this works alongside them?

@dsas
Copy link
Contributor Author

dsas commented Dec 18, 2025

  • What shows up for users who have just one site?

Good question, it was just showing the current site. I've made a change to exclude the current site

  • What shows up for users on Jetpack sites who aren't the Jetpack connection owner or aren't connected to WP.com?

If you're not connected then it will try to get your sites and fail (it's an authenticated endpoint), this means it won't offer you any sites to switch to.

If you are connected, but the Jetpack site connection owner is someone else, then it'll use your connection and show you just the sites you have access to.

  • On multi-site WP installations with Jetpack, are there similar core commands and how this works alongside them?

There are no similar core commands at this time, at least not that I was able to find.

@simison
Copy link
Member

simison commented Dec 18, 2025

If you're not connected then it will try to get your sites and fail (it's an authenticated endpoint), this means it won't offer you any sites to switch to.

Cool; there's a helper method that returns the connection status, and that would help avoid firing API request that we know would fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress [Type] Feature Development of a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants