Skip to content

Premium Analytics: hide commerce widget categories without their plugin - #50736

Merged
louwie17 merged 2 commits into
trunkfrom
update/wooa7s-1775-hide-woo-bookings-widgets
Jul 23, 2026
Merged

louwie17 merged 2 commits into
trunkfrom
update/wooa7s-1775-hide-woo-bookings-widgets

Conversation

@louwie17

@louwie17 louwie17 commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes WOOA7S-1775

Proposed changes

  • Add a registry-time widget availability policy, filter_registrable_widget_types_by_plugin, hooked on REGISTRABLE_WIDGET_TYPES_FILTER (same pattern as the dev-only gate from Premium Analytics: add React Query Devtools dev-only widget #50002): the WooCommerce widget categories — store, orders, coupons, and bookings — are only registered while WooCommerce is active.
  • Read WooCommerce availability through the store section's signal (is_woocommerce_dashboard_section_available(), including its jetpack_premium_analytics_woocommerce_dashboard_section_available filter), so the store section and its widgets can't disagree — forcing the section available via the filter surfaces the widgets too.
  • Additionally gate the bookings category on the WooCommerce Bookings extension, mirroring the detection used by woocommerce-analytics' Bookings sync module (class_exists( 'WC_Bookings' ), with a guarded is_plugin_active() fallback).
  • Recategorize jpa/top-performing-bookings from store to bookings — it renders bookings data, so it belongs behind the Bookings gate.
  • Switch the existing developer-only gate from a name match to a category: developer check, as its own comment instructed now that the wp-build manifest carries category.

Out of scope, by design:

Related product discussion/links

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

No.

Testing instructions

  • Run the unit tests: cd projects/packages/premium-analytics && composer phpunit -- --filter Widget_Availability_Test (or the full suite).
  • On a site with this branch and WooCommerce deactivated:
    • Open the Premium Analytics dashboard and the widget library — no store/orders/coupons/bookings widgets should be offered.
    • The widget-modules REST list (/wpcom/v2/dashboards/widget-modules via the dashboard, or observe the network tab on dashboard load) should contain no widgets from those categories.
  • Activate WooCommerce (without WooCommerce Bookings):
    • The store/orders/coupons widgets are registered again, and the Store section is visible.
    • The five bookings widgets (bookings-*, store-conversion-rate-bookings, top-performing-bookings) remain hidden.
  • Activate WooCommerce Bookings: the bookings widgets appear as well.

@github-actions

github-actions Bot commented Jul 22, 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 (WordPress.com Site Helper), and enable the update/wooa7s-1775-hide-woo-bookings-widgets branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/wooa7s-1775-hide-woo-bookings-widgets

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

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!

@jp-launch-control

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/premium-analytics/src/widget-availability.php 29/33 (87.88%) -4.43% 3 ❤️‍🩹

Full summary · PHP report · JS report

@louwie17
louwie17 marked this pull request as ready for review July 22, 2026 12:36
@louwie17
louwie17 requested a review from a team July 22, 2026 12:36
@louwie17
louwie17 requested a review from a team as a code owner July 22, 2026 12:36
louwie17 and others added 2 commits July 22, 2026 15:18
Gate the WooCommerce widget categories (store, orders, coupons, bookings)
at registry time: they are only registered while WooCommerce is active,
read through the store section's availability signal so section and
widgets cannot disagree. The bookings category additionally requires the
WooCommerce Bookings extension, detected the same way as
woocommerce-analytics' Bookings sync module.

Recategorize top-performing-bookings from store to bookings — it renders
bookings data, so it belongs behind the Bookings gate.

Switch the developer-only gate from a name match to a category check, as
its comment instructed now that the build manifest carries category.

Refs WOOA7S-1775, WOOA7S-1722.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Lm9n11NbC2AZVAgzoEywr
…checks

Move `bookings` out of WOOCOMMERCE_WIDGET_CATEGORIES into its own
WOOCOMMERCE_BOOKINGS_WIDGET_CATEGORIES constant and check each list
independently — the Bookings extension cannot run without WooCommerce,
so its presence implies both.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Lm9n11NbC2AZVAgzoEywr
@louwie17
louwie17 force-pushed the update/wooa7s-1775-hide-woo-bookings-widgets branch from 52c9f3f to 8ccb874 Compare July 22, 2026 13:20

@retrofox retrofox 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, Lourens 🙇‍♂️

Approving this because it solves the immediate problem, is well tested, and the section/widget coupling via the availability signal is the right call within this pattern 🚀

But :-) I want to leave on record that I see this as transitional, not the model to build on.

The pattern this consolidates is PA bundling every widget and then subtracting, from a central policy file, those whose backing plugin is missing.

That forces PA to know every domain, which categories belong to which plugin, and how to detect each one (class_exists( 'WC_Bookings' )).

Every new integration grows that same file. It doesn't scale, and it inverts the extensibility model: the dashboard should be common ground where each plugin registers its own widgets and sections, the same way plugins register blocks or admin pages.

If the plugin isn't active, its widgets simply don't exist. Availability becomes a structural fact instead of an inference we reconstruct with detection code.

Ownership follows the domain: the commerce widgets should be registered by WooCommerce Analytics, WooCommerce core, or whatever owns that domain.

Same for the widgets that mirror what Jetpack Stats offers today: they belong to Stats. Instead of defining widgets inside PA, the plugin defines them.

Taken to its conclusion, PA stops being a widget owner and becomes the shell: registry, sections, layouts, REST. At that point, it could even live in Jetpack core as just another page, like Jetpack Forms.

@louwie17
louwie17 merged commit 0fc0f24 into trunk Jul 23, 2026
71 of 72 checks passed
@louwie17
louwie17 deleted the update/wooa7s-1775-hide-woo-bookings-widgets branch July 23, 2026 07:24
@louwie17

Copy link
Copy Markdown
Contributor Author

But :-) I want to leave on record that I see this as transitional, not the model to build on.

The pattern this consolidates is PA bundling every widget and then subtracting, from a central policy file, those whose backing plugin is missing.

That forces PA to know every domain, which categories belong to which plugin, and how to detect each one (class_exists( 'WC_Bookings' )).

Every new integration grows that same file. It doesn't scale, and it inverts the extensibility model: the dashboard should be common ground where each plugin registers its own widgets and sections, the same way plugins register blocks or admin pages.

If the plugin isn't active, its widgets simply don't exist. Availability becomes a structural fact instead of an inference we reconstruct with detection code.

Ownership follows the domain: the commerce widgets should be registered by WooCommerce Analytics, WooCommerce core, or whatever owns that domain.

Same for the widgets that mirror what Jetpack Stats offers today: they belong to Stats. Instead of defining widgets inside PA, the plugin defines them.

Taken to its conclusion, PA stops being a widget owner and becomes the shell: registry, sections, layouts, REST. At that point, it could even live in Jetpack core as just another page, like Jetpack Forms.

Totally agree! I think this would be worth exploring more as we dive back into the Woo related work more. The slight question is, where will it live? In WooCommerce plugin it-self? In Jetpack as a composer package which Woo could in turn install? :)

@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] In Progress labels Jul 23, 2026
@retrofox

Copy link
Copy Markdown
Contributor

It's already a Jetpack package, consumed by the Premium Analytics plugin, right?. This means we could potentially

  • create Analytics dashboards for different plugins
  • allow other plugins to register widget types
  • populate the widgets list for every plugin
  • extend dashboard layout and sections

@louwie17

Copy link
Copy Markdown
Contributor Author

It's already a Jetpack package, consumed by the Premium Analytics plugin, right?. This means we could potentially

  • create Analytics dashboards for different plugins
  • allow other plugins to register widget types
  • populate the widgets list for every plugin
  • extend dashboard layout and sections

Yup, makes sense! We could use WooCommerce as the testing ground for this & Bookings of-course.

It would mean we did have to move all our Woo related work out of the package atm.

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

Labels

[Package] Premium Analytics [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants