Premium Analytics: carry widget.json metadata through the registry and REST - #50615
Conversation
translate, sanitize and register the new manifest fields
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 2 files.
|
widget.json metadata through the registry and REST
drop links whose href fails esc_url_raw
chihsuan
left a comment
There was a problem hiding this comment.
Nice work. this matches the upstream dashboard widget metadata pipeline, with a reasonable PA-specific text-domain fallback.
The only remaining items are the two failing CI checks. Once those are fixed, this looks good to merge.
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
test fixture declares the function, so phan no longer flags it
Fixes #
Proposed changes
This ports the upstream
lib/experimental/dashboard-widgetsdelta that pairs with the@wordpress/widget-primitives/@wordpress/widget-dashboard0.3.x line (already bundled since #50293) into our PA-namespaced copy of the backend.The wp-build manifest already emits the declarative
widget.jsonmetadata; this PR makes the PHP pipeline carry it end-to-end.Widget_TypeGains the five declarative metadata fields:
category,title,description,help,keywords(allnullwhen a widget does not declare them).Registry hydration translates the user-facing strings on the way in,...
...using the new
src/widget-i18n.jsonschema and core'stranslate_settings_using_i18n_schema().One deliberate divergence from upstream: a widget with no
textdomainfalls back to thejetpack-premium-analyticsdomain instead of skipping translation, since every bundled widget shares it.This matters because the client overlay prefers the server value (
record.title ?? metadata.title), so an untranslated server string would otherwise beat the widget module's translated__()title.The
helpnote is sanitized at registrationContent keeps only
em/strongmarkup, and links missing alabelorhrefare dropped.The
jetpack/v4/widget-modulesREST record now exposes the five fields.nullvalues are safe:useWidgetTypes()falls back to the widget module's metadata.New
Widget_Metadata_Testcovers the translation domains (default and widget-declared), thehelpsanitization rules, and the REST record end to end.Side effect worth noting: registry-time availability filter candidates now carry
category, which was the missing prerequisite for server-side category-based gating discussed around #50002 / #50031.Related product discussion/links
lib/experimental/dashboard-widgetsas of the canary the bundled packages were cut from.Does this pull request change what data or activity we track or use?
No.
Testing instructions
jetpack build --deps packages/premium-analytics.projects/packages/premium-analytics/build/widgets/registry.phpincludecategory,title,description(andhelp/keywordsasnullfor now)./wp-json/jetpack/v4/widget-modulesas an admin: each record should now includecategory,title,description,help,keywordsin addition to the existingname/render_module/widget_module/presentation.Before

After

composer phpunitinprojects/packages/premium-analytics(335 tests, includes the newWidget_Metadata_Test).