Skip to content

Commit eba32f5

Browse files
dhasilvaclaude
andcommitted
Address review feedback: cache connection manager, add user-not-connected test, fix changelog
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 66199db commit eba32f5

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Significance: minor
22
Type: changed
33

4-
Sidebar upsell: hide when site is not connected to Jetpack.com.
4+
Hide the sidebar upsell when the site is not connected to Jetpack or is in offline mode.

projects/packages/admin-ui/src/class-admin-menu.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ private static function should_show_upgrade_menu() {
304304
private static function is_site_and_user_connected() {
305305
$connection_manager = self::$connection_manager;
306306
if ( ! $connection_manager && class_exists( '\Automattic\Jetpack\Connection\Manager' ) ) {
307-
$connection_manager = new \Automattic\Jetpack\Connection\Manager();
307+
$connection_manager = new \Automattic\Jetpack\Connection\Manager();
308+
self::$connection_manager = $connection_manager;
308309
}
309310

310311
if (

projects/packages/admin-ui/tests/php/Admin_Menu_Test.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,26 @@ public function test_upgrade_menu_item_hidden_when_site_not_connected() {
397397
$this->assertUpgradeMenuItemAbsent();
398398
}
399399

400+
/**
401+
* Upgrade item is absent when the user is not connected (site is connected).
402+
*
403+
* @return void
404+
*/
405+
public function test_upgrade_menu_item_hidden_when_user_not_connected() {
406+
wp_set_current_user( self::$admin_user_id );
407+
$connection = $this->getMockBuilder( 'Automattic\Jetpack\Connection\Manager' )
408+
->disableOriginalConstructor()
409+
->getMock();
410+
$connection->method( 'is_connected' )->willReturn( true );
411+
$connection->method( 'is_user_connected' )->willReturn( false );
412+
Admin_Menu::set_connection_manager( $connection );
413+
414+
Admin_Menu::init();
415+
do_action( 'admin_menu' );
416+
417+
$this->assertUpgradeMenuItemAbsent();
418+
}
419+
400420
/**
401421
* Upgrade item is absent when the site is in offline (development) mode.
402422
*

0 commit comments

Comments
 (0)