Admin Menu: add group_id + signal fields and top-level groups[] for sidebar redesign#48715
Admin Menu: add group_id + signal fields and top-level groups[] for sidebar redesign#48715chriskmnds wants to merge 2 commits into
Conversation
…idebar redesign Additive schema extension for `/wpcom/v2/admin-menu`. Per-item `group_id` and `signal` fields plus a sibling top-level `groups[]` array, sourced from the public `wp-admin-sidebar` plugin's `Sidebar_Classifier` + `Sidebar_Signals` when loaded. The classifier hydration is gated behind `class_exists()` so non-WPCOM Jetpack installs see no shape change. Calypso's `MySitesSidebarUnified` view consumes these fields to render the redesigned grouped sidebar with behaviour identical to the public plugin's wp-admin rendering. Per-item fields use the snake_case shape emitted by `Sidebar_Signals::map_to_nav` so the same vocabulary is canonical end-to-end.
PHPCS: align consecutive assignments, broaden the eval phpcs:ignore to
cover both Squiz.PHP.Eval.Discouraged and MediaWiki.Usage.ForbiddenFunctions.eval
sniffs that fire on the same call.
Phan: suppress PhanUndeclaredClass{Method,Reference} for the gated
Sidebar_Classifier calls (class is provided by WPCOM's wp-admin-sidebar
mu-plugin and the runtime path is already guarded by class_exists()).
Rewrite isset(X) ? X : Y to X ?? Y to silence
PhanPluginDuplicateConditionalNullCoalescing.
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
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 1 file.
Full summary · PHP report · JS report If appropriate, add one of these labels to override the failing coverage check:
Covered by non-unit tests
|
Part of DES-575
Overview
Extends
/wpcom/v2/admin-menuwith two additive per-item fields (group_id,signal) and a sibling top-levelgroups[]array describing the synthetic group rows the redesigned sidebar needs. MirrorsWordPress/wp-admin-sidebarv0.1.7 (the version currently vendored as the wpcom in-tree-copy atwp-content/mu-plugins/wp-admin-sidebar/).This endpoint is the server side of the A.3 Calypso parity workstream. Pair with the Calypso PRs:
Automattic/wp-calypso#110578Automattic/wp-calypso#110588What changed
prepare_menu_for_response()best-effort-hydrates the classifier nav model and, when present, returns{ menu, groups }instead of the legacy flat list. When the classifier isn't loaded, the response shape is byte-identical totrunk.prepare_menu_item()+prepare_submenu_item()attachgroup_id+signalfrom the classifier index by menu slug. O(1) lookup; items with no nav-model match are unchanged.get_item_schema()describes the new per-item fields (group_id,signal) and the optional{ menu, groups }envelope.patch/enhancement).Screenshots
This is a backend-only schema extension. There's no Jetpack-side UI to screenshot. The visual before/after for the redesigned sidebar lives in the paired Calypso PRs (#110578, #110588) and the public plugin's wp-admin output.
Gating
The redesigned response shape is gated end-to-end on the public plugin's
wp_admin_sidebar_enabledfilter:class_exists()guards everywhere ensure dead-code safety.wpcom-admin-sidebar-integration) wireswp_admin_sidebar_enabledto thewpcom-admin-sidebar-redesignblog sticker viaWPCOM_Gating::is_enabled. No sticker → filter resolves false →Sidebar_Classifier::build_nav_model()short-circuits → endpoint emits the legacy flat shape.So a blog without the sticker sees byte-identical behaviour to today, both in the response and on the client (Calypso treats absent
groups[]as "render the legacy flat sidebar"). Removing the sticker is the rollback path, no Jetpack / Calypso deploy needed.Cross-surface persistence (layoutDelta)
The Calypso customize mode (Phase 2 PR #110588) needs to read the saved layout-delta the user persisted from wp-admin. The wp-admin side stores it in a per-user-per-blog WPCOM user attribute via
WPCOM_User_Attribute_Storage.The expected shape (additive to the existing response envelope):
Schema delta
Per-item (top-level + child):
Top-level (when classifier is loaded):
Does this pull request change what data or activity we track or use?
No. The endpoint exposes structural metadata about the admin menu the user is already authorised to see; no new tracking or logging.
Testing instructions
Without the public
wp-admin-sidebarplugin loaded/wpcom/v2/admin-menuresponse shape is byte-identical totrunk: same flat-array root, nogroup_id/signalon items, nogroups[]. Existing Calypso behaviour is unchanged.With the plugin loaded and gating enabled
wpcom-admin-sidebar-redesignblog sticker on a test blog:wp blog-stickers add --blog_id=<id> --sticker=wpcom-admin-sidebar-redesign --who=<user>.wp_admin_sidebar_enabledtotruefor the request user / blog.The response root becomes
{ menu: [...], groups: [...] }. Each item hasgroup_id(string or null) andsignal(object or null). Thegroups[]array contains one{ id, label, default_expanded, signal }row per synthetic group the classifier emitted.Calypso integration check
Pair with
Automattic/wp-calypso#110578(Phase 1). Once this endpoint deploys, open/home/<site-slug>on Calypso for the stickered blog. The "My Plugins" group should render below the top-level items, in the public plugin's blue (#71aee2), with the hamburger toggle + chevron header. Items inside should show the correct signals (red number bubble, "Premium" chip, etc.) per the per-itemsignalpayload.PHPUnit
test_response_is_legacy_shape_without_classifier: legacy flat-array contract when the classifier is absent.test_response_carries_group_fields_when_classifier_is_loaded: wrapped shape, per-item attachment by slug, andgroups[]rows when stub classifier + signals classes are visible.test_prepare_menu_item,test_prepare_submenu_item,test_parse_menu_item, etc.) unchanged.Related
WordPress/wp-admin-sidebarv0.1.7,src/class-sidebar-classifier.php,src/class-sidebar-signals.php.wp-content/mu-plugins/wpcom-admin-sidebar-integration/inAutomattic/wpcom.children).