Skip to content

Commit a7161d8

Browse files
committed
Stats admin: only register the Stats dashboard for connected sites
Drop the pre-connection registration: the Stats menu now only appears once the site is connected, as before this branch. What remains is the consolidation of the registration decision in Main::maybe_register_dashboard() — connected, stats module active, Odyssey enabled, and not a noheader chart-image request — with the stats module falling back to the old interface when it declines.
1 parent 4c47c40 commit a7161d8

4 files changed

Lines changed: 16 additions & 31 deletions

File tree

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Significance: minor
2-
Type: added
1+
Significance: patch
2+
Type: changed
3+
Comment: Consolidate the Stats dashboard menu registration decision in Main::maybe_register_dashboard(). No user-facing change.
34

4-
Register the Stats dashboard before the site connects, so new installations can reach the Stats pricing grid rendered by Odyssey.

projects/packages/stats-admin/src/class-main.php

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ public static function init() {
5353
*/
5454
private function __construct() {
5555
add_action( 'rest_api_init', array( REST_Controller::class, 'register' ) );
56-
57-
if ( is_admin() ) {
58-
self::maybe_register_dashboard();
59-
}
60-
6156
// Disable JITM assets on the Stats page.
6257
// JITM is handled separately by Stats: https://github.com/Automattic/wp-calypso/pull/95273.
6358
add_filter(
@@ -80,28 +75,18 @@ function ( $show, $screen_id ) {
8075
* Register the Odyssey dashboard as the Stats menu when it should own the
8176
* Stats screen, and report whether it did.
8277
*
83-
* Called from two entry points covering disjoint cases: this package's
84-
* constructor for sites that haven't connected yet (the stats module,
85-
* which normally registers the menu, only loads once connected), and the
86-
* stats module's stats_admin_menu() for connected sites, which falls back
87-
* to the old Stats interface when this declines.
78+
* Called from the stats module's stats_admin_menu(), which falls back to
79+
* the old Stats interface when this declines: when the site isn't
80+
* connected, the stats module is inactive, the site opted out of Odyssey,
81+
* or the request is a noheader chart image (the adminbar sparkline and
82+
* dashboard widget), which the legacy interface serves.
8883
*
8984
* @return bool Whether the dashboard was registered.
9085
*/
9186
public static function maybe_register_dashboard() {
92-
// Unconnected sites can't load the stats module; register the
93-
// dashboard so Odyssey — which hosts the Stats pricing grid and owns
94-
// its eligibility — is reachable before connecting.
95-
if ( ! ( new Manager() )->is_connected() ) {
96-
Dashboard::init();
97-
return true;
98-
}
99-
100-
// On connected sites the stats module owns the screen: respect the
101-
// Odyssey opt-out, and leave noheader chart-image requests (the
102-
// adminbar sparkline and dashboard widget) to the legacy interface.
10387
if (
104-
! ( new Modules() )->is_active( 'stats' )
88+
! ( new Manager() )->is_connected()
89+
|| ! ( new Modules() )->is_active( 'stats' )
10590
|| ! Stats_Options::get_option( 'enable_odyssey_stats' )
10691
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
10792
|| isset( $_GET['noheader'] )

projects/packages/stats-admin/tests/php/Main_Test.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ public function tearDown(): void {
3030
}
3131

3232
/**
33-
* An unconnected site registers the dashboard, so Odyssey (and its
34-
* pricing grid) is reachable before connecting.
33+
* An unconnected site declines, so the Stats menu only registers once the
34+
* site is connected.
3535
*/
36-
public function test_maybe_register_dashboard_for_unconnected_site() {
36+
public function test_maybe_register_dashboard_declines_for_unconnected_site() {
3737
remove_filter( 'jetpack_options', array( $this, 'mock_jetpack_site_connection_options' ) );
3838
( new Connection_Manager() )->reset_connection_status();
3939

40-
$this->assertTrue( Main::maybe_register_dashboard() );
40+
$this->assertFalse( Main::maybe_register_dashboard() );
4141
}
4242

4343
/**
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Significance: patch
2-
Type: enhancement
2+
Type: other
3+
Comment: Stats: delegate the Odyssey dashboard registration decision to the stats-admin package. No user-facing change.
34

4-
Stats: Show the Stats pricing grid for new installations without a plan, including before the site is connected.

0 commit comments

Comments
 (0)