Skip to content

Premium Analytics: Keep the Stats menu under My Home, not below Upgrades - #54626

Merged
dognose24 merged 2 commits into
trunkfrom
fix/premium-analytics-stats-menu-position
Nov 9, 2026
Merged

dognose24 merged 2 commits into
trunkfrom
fix/premium-analytics-stats-menu-position

Conversation

@dognose24

@dognose24 dognose24 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to the review of #54454, which found it and notes that Simple sites already have the same order since #54452. Independent of #54454, so it can land first.

Proposed changes

On WordPress.com the Stats v2 dashboard's menu entry sat below Hosting and Upgrades instead of under My Home, where classic Stats sits. With classic Stats retired, that is where Stats itself ends up.

  • The dashboard asked for menu position 2, which the Dashboard already holds. add_menu_page() then gives the second entry a fraction hashed from its slug and title: 2.36713 as "Stats v2", 2.21518 as "Stats". wp-admin/menu.php sorts the menu with strnatcasecmp, which reads that fraction as a whole number, so 2.21518 sorts after Hosting's 2.98 and Upgrades' 2.99. Classic Stats asks for 2 as well and only sorts first because its fraction, 2.09281, starts with a zero.
  • It now asks for 2.1, through a MENU_POSITION constant used by both registration paths. Nothing else is there, so core adds no fraction, and it sorts after My Home (2.01) and classic Stats and before Hosting.
Before After
Classic Stats beside it 截圖 2026-11-07 凌晨3 08 42 截圖 2026-11-07 凌晨3 19 16
Classic Stats retired Dashboard, My Home, Hosting, Upgrades, Stats Dashboard, My Home, Stats, Hosting, Upgrades
  • Off WordPress.com nothing moves: the entry was and stays between the Dashboard and Jetpack.
  • Admin_Menu::add_top_level_menu() documented $position as int|null, though it hands the value on to add_menu_page(), which takes int|float. The docblock now says int|float|null, so no Phan suppression is needed at the call. Docblock only, with a comment-only change entry for admin-ui; no version bump.

Related product discussion/links

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

No.

Testing instructions

The order only shows next to the entries WordPress.com adds, so either test on a WordPress.com site or stand them in locally.

On a local Jetpack site with Stats v2 enabled, add the two neighbours at the positions jetpack-mu-wpcom gives them:

add_action(
	'admin_menu',
	function () {
		add_menu_page( 'Hosting', 'Hosting', 'read', 'hosting-test', '__return_null', 'dashicons-cloud', 2.98 );
		add_menu_page( 'Upgrades', 'Upgrades', 'read', 'upgrades-test', '__return_null', 'dashicons-cart', 2.99 );
	}
);
  1. On trunk, Stats v2 is below Upgrades. On this branch it is above Hosting, right after the Dashboard (and after Stats, where the classic page has a top-level entry).

  2. Retire classic Stats by adding this next to the snippet above, in an mu-plugin (the flag is read on plugins_loaded, so the filter has to be there before that):

    add_filter( 'jetpack_feature_flag_enabled_jetpack-stats-classic-page-retired', '__return_true' );

    The entry is now labelled Stats and stays above Hosting. On trunk it is below Upgrades.

  3. On a Simple or Atomic site with this branch, Stats sits under My Home in wp-admin, and in the WordPress.com sidebar, which reads the same menu.

What was run for this PR:

  • The new unit test, which fails on trunk for both labels and passes here.
  • Steps 1 and 2 on a local Docker site (WordPress 7.1.4, Jetpack and the Stats plugin active), with My Home, Hosting and Upgrades stood in at 2.01, 2.98 and 2.99, reading the menu wp-admin renders:
trunk this branch
Flag off Dashboard, My Home, Stats, Hosting, Upgrades, Stats v2, Jetpack Dashboard, My Home, Stats, Stats v2, Hosting, Upgrades, Jetpack
Flag on Dashboard, My Home, Hosting, Upgrades, Stats, Jetpack Dashboard, My Home, Stats, Hosting, Upgrades, Jetpack

Step 3 was not run: nothing here was tested on a Simple or Atomic site. The screenshots above are from that local site, with the three WordPress.com entries stood in.

🤖 Generated with Claude Code

The dashboard asked for menu position 2, which the Dashboard holds. Core
then gives the second entry a hashed fraction (2.36713 as "Stats v2",
2.21518 as "Stats"), and the menu's natural sort reads that fraction as
a whole number, so on WordPress.com the entry landed after Hosting (2.98)
and Upgrades (2.99).

Ask for 2.1 instead: free, so core adds nothing, and it sorts after
My Home (2.01) and classic Stats, before Hosting.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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!


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: December 8, 2026
    • Code freeze: December 7, 2026

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


Premium Analytics plugin:

No scheduled milestone found for this plugin.

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


Stats Data plugin:

No scheduled milestone found for this plugin.

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 Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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 fix/premium-analytics-stats-menu-position branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/premium-analytics-stats-menu-position
bin/jetpack-downloader test jetpack-mu-wpcom-plugin fix/premium-analytics-stats-menu-position

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

@jp-launch-control

Copy link
Copy Markdown

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report · JS report

@dognose24 dognose24 removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Nov 6, 2026
@dognose24
dognose24 marked this pull request as ready for review November 6, 2026 17:31
@dognose24
dognose24 requested a review from a team as a code owner November 6, 2026 17:31
@dognose24 dognose24 added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Nov 6, 2026
adamwoodnz
adamwoodnz previously approved these changes Nov 9, 2026

@adamwoodnz adamwoodnz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @dognose24, this fixes the cause rather than the symptom, and the test reproduces core's natural sort over the real WordPress.com neighbours instead of asserting the constant, so it catches a regression in the ordering and not just a changed number. One non-blocking comment inline.

jetpack test php packages/premium-analytics passes.

// A fixed key rather than the slug, which carries a build-specific suffix. No gate:
// the dashboard has no My Jetpack product class and no module to name.
Admin_Menu::add_top_level_menu( $menu_title, $menu_title, $capability, self::MENU_PAGE_SLUG, $render_callback, 'dashicons-chart-bar', 2, array( 'key' => 'jetpack-premium-analytics' ) );
// @phan-suppress-next-line PhanTypeMismatchArgument -- Handed on to add_menu_page(), which takes a float.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit, not blocking: this treats the symptom. The cause is packages/admin-ui/src/class-admin-menu.php:433, which documents $position as int|null while its own docblock says the parameters mirror add_menu_page(), and core's takes int|float. Widening that @param to int|float|null would remove the need for a suppression here and for every future caller that wants a fractional position; as written, the next one copies the suppression. Reasonable as an interim step, and the -- <reason> justification is there as the repo requires. This is about where the fix belongs, not whether this PR is safe.

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.

Agreed, and taken in 4f03915: the docblock now reads int|float|null, as add_menu_page() takes, and the suppression is gone. Docblock only, so the admin-ui entry is comment-only and its version stays put.

chihsuan
chihsuan previously approved these changes Nov 9, 2026

@chihsuan chihsuan left a comment

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.

Thanks @dognose24 this looks good. Confirmed Stats stays under My Home in both English and German. 👍

Just sharing: classic Stats still asks for 2, so its spot follows the translated label. In French and German it lands below Upgrades. Since it's being retired, I think that's fine.

add_top_level_menu() hands $position on to add_menu_page(), which takes
int|float, but its docblock said int|null, so a fractional position
needed a Phan suppression at the call. Widen the docblock instead and
drop the suppression from Premium Analytics.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dognose24
dognose24 dismissed stale reviews from chihsuan and adamwoodnz via 4f03915 November 9, 2026 02:53
@dognose24
dognose24 merged commit 92a0695 into trunk Nov 9, 2026
136 checks passed
@dognose24
dognose24 deleted the fix/premium-analytics-stats-menu-position branch November 9, 2026 03:18
@github-actions github-actions Bot added [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. and removed [Status] Needs Review This PR is ready for review. labels Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Admin Ui [Package] Premium Analytics [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Premium Analytics [Plugin] Stats Data [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. [Tests] Includes Tests [Type] Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants