Skip to content

Sidebar upsell: show only on connected sites#47967

Merged
dhasilva merged 9 commits intotrunkfrom
update/upsell-sidebar-hide-when-not-connected
Apr 9, 2026
Merged

Sidebar upsell: show only on connected sites#47967
dhasilva merged 9 commits intotrunkfrom
update/upsell-sidebar-hide-when-not-connected

Conversation

@simison
Copy link
Copy Markdown
Member

@simison simison commented Apr 7, 2026

Fixes JETPACK-1518
Closes #47993

Follow-up to #47418

Proposed changes

  • Hides upsell banner when site and user aren't connected yet
  • Hides also when site is in offline mode

Before
image

After

Other information

Related product discussion/links

  • internal ref p1775549007733249-slack-C0D96691V

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

Testing instructions

  • Have a free site, or modify is_free_plan() return true always
  • See sidebar has upsell
  • Set your site offline mode and see upsell gone add_filter( 'jetpack_offline_mode', '__return_true' );
  • Disconnect your Jetpack and see upsell gone.
  • You may also test with Jurassic Ninja before connecting the site.

@simison simison added Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Review This PR is ready for review. labels Apr 7, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

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 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!

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

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 or WordPress.com Site Helper), and enable the update/upsell-sidebar-hide-when-not-connected branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/upsell-sidebar-hide-when-not-connected
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/upsell-sidebar-hide-when-not-connected

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

@github-actions github-actions bot added [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. and removed [Status] Needs Review This PR is ready for review. labels Apr 7, 2026
@jp-launch-control
Copy link
Copy Markdown

jp-launch-control bot commented Apr 7, 2026

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/admin-ui/src/class-admin-menu.php 143/171 (83.63%) -0.14% 3 ❤️‍🩹

Full summary · PHP report · JS report

keoshi
keoshi previously approved these changes Apr 7, 2026
Copy link
Copy Markdown
Contributor

@keoshi keoshi left a comment

Choose a reason for hiding this comment

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

Confirmed:

  1. The button is not visible when the site is not connected
Image
  1. The button shows up when it's connected
Image
  1. When disconnecting the user account (site-only connection) the button is visible. Clicking it correctly takes users to the checkout. However, checkout fails because the user is not connected to the site. Unrelated and not blocking, though we could show the button only when site+user are connected.
Image

@simison simison force-pushed the update/upsell-sidebar-hide-when-not-connected branch from 27c82e5 to 5d908bc Compare April 9, 2026 09:17
Copy link
Copy Markdown
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

Ah, I missed that PR of yours and opened #47993 yesterday.

I can close my PR, but I think it's worth adding the offline check to yours.

@simison
Copy link
Copy Markdown
Member Author

simison commented Apr 9, 2026

Nice one! I'll add that and I also like your method for tests more. Looks cleaner.

@simison simison force-pushed the update/upsell-sidebar-hide-when-not-connected branch from 6e35adb to 66199db Compare April 9, 2026 11:22
@dhasilva dhasilva added [Status] Needs Review This PR is ready for review. 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 Apr 9, 2026
@dhasilva dhasilva requested a review from Copilot April 9, 2026 15:05
Copy link
Copy Markdown
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

Updates the admin-ui package’s “Upgrade Jetpack” sidebar upsell so it only appears when the site is usable for upgrades (i.e., connected and not in offline mode), aligning the UI with actual upgrade capability on self‑hosted installs.

Changes:

  • Gate the upsell behind offline-mode detection and “site + current user connected” checks.
  • Add PHPUnit coverage for “site not connected” and “offline mode” hiding behavior.
  • Add a changelog fragment describing the behavior change.

Reviewed changes

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

File Description
projects/packages/admin-ui/src/class-admin-menu.php Adds offline-mode + connection gating to the upgrade submenu and its style enqueue, with an injectable connection manager for tests.
projects/packages/admin-ui/tests/php/bootstrap.php Ensures connection-related classes are available during the test bootstrap.
projects/packages/admin-ui/tests/php/Admin_Menu_Test.php Extends tests to assert the upsell is hidden when offline or when the site isn’t connected.
projects/packages/admin-ui/changelog/update-upsell-sidebar-hide-when-not-connected Adds a changelog entry for the upsell visibility change.

Comment on lines +13 to +20
if ( ! class_exists( 'Jetpack_Options' ) ) {
require_once __DIR__ . '/../../../connection/legacy/class-jetpack-options.php';
}

if ( ! class_exists( '\Automattic\Jetpack\Connection\Manager' ) ) {
require_once __DIR__ . '/../../../connection/src/class-manager.php';
}

Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

The test bootstrap is hard-coding monorepo-relative paths into require_once for the connection package. This bypasses the Composer dev dependency (automattic/jetpack-connection) and can break when this package is used/tested outside the monorepo (e.g., mirrored repo / different directory layout). Prefer relying on Composer autoload (or resolving the dependency via vendor/) rather than ../../../connection/... paths.

Suggested change
if ( ! class_exists( 'Jetpack_Options' ) ) {
require_once __DIR__ . '/../../../connection/legacy/class-jetpack-options.php';
}
if ( ! class_exists( '\Automattic\Jetpack\Connection\Manager' ) ) {
require_once __DIR__ . '/../../../connection/src/class-manager.php';
}
if ( ! class_exists( 'Jetpack_Options' ) || ! class_exists( '\Automattic\Jetpack\Connection\Manager' ) ) {
throw new RuntimeException(
'Missing test dependency: automattic/jetpack-connection must be installed and autoloaded via Composer.'
);
}

Copilot uses AI. Check for mistakes.
private static function is_site_and_user_connected() {
$connection_manager = self::$connection_manager;
if ( ! $connection_manager && class_exists( '\Automattic\Jetpack\Connection\Manager' ) ) {
$connection_manager = new \Automattic\Jetpack\Connection\Manager();
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

is_site_and_user_connected() instantiates a new \Automattic\Jetpack\Connection\Manager every time it runs when no dependency is injected. Since should_show_upgrade_menu() is called from multiple hooks in the same request (menu registration and enqueue), this can create multiple Manager instances unnecessarily. Consider caching the created Manager in self::$connection_manager after instantiation so subsequent calls reuse it.

Suggested change
$connection_manager = new \Automattic\Jetpack\Connection\Manager();
$connection_manager = new \Automattic\Jetpack\Connection\Manager();
self::$connection_manager = $connection_manager;

Copilot uses AI. Check for mistakes.
Comment on lines +384 to +398
public function test_upgrade_menu_item_hidden_when_site_not_connected() {
wp_set_current_user( self::$admin_user_id );
$connection = $this->getMockBuilder( 'Automattic\Jetpack\Connection\Manager' )
->disableOriginalConstructor()
->getMock();
$connection->expects( $this->atLeastOnce() )
->method( 'is_connected' )
->willReturn( false );
Admin_Menu::set_connection_manager( $connection );

Admin_Menu::init();
do_action( 'admin_menu' );

$this->assertUpgradeMenuItemAbsent();
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

New behavior requires both site and user to be connected (is_user_connected), but the tests only cover the site-not-connected case and offline mode. Add coverage for the case where the site is connected but the current user is not (for both menu item registration and stylesheet enqueue) to ensure the new gating logic is enforced.

Copilot uses AI. Check for mistakes.
Significance: minor
Type: changed

Sidebar upsell: hide when site is not connected to Jetpack.com.
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

The changelog entry text is inconsistent with the behavior introduced in this PR: it mentions “Jetpack.com” (the connection is to WordPress.com) and doesn't mention the offline-mode suppression. Please update the entry text to accurately reflect the conditions under which the sidebar upsell is hidden.

Suggested change
Sidebar upsell: hide when site is not connected to Jetpack.com.
Hide the sidebar upsell when the site is not connected to WordPress.com or is in offline mode.

Copilot uses AI. Check for mistakes.
…cted test, fix changelog

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dhasilva dhasilva requested a review from a team April 9, 2026 15:58
Copy link
Copy Markdown
Contributor

@dhasilva dhasilva left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This looks good, should be good to merge.

Not a blocker, more of a question. We typically do not add class_exists and is_callable checks for those methods in other packages in the codebase, mostly because the package is required by the consuming package so we know those are available. Do we really need those here?

@dhasilva dhasilva merged commit 6670a2b into trunk Apr 9, 2026
118 of 120 checks passed
@dhasilva dhasilva deleted the update/upsell-sidebar-hide-when-not-connected branch April 9, 2026 20:32
@github-actions github-actions bot removed the [Status] Needs Review This PR is ready for review. label Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Package] Admin Ui [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants