Dashboard: backend default layout filter#78040
Conversation
let plugins register a default via get_user_metadata
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
mirror the JS hook so both sides reference the same names
aligns with core/ used by blocks and preferences scopes
move the bundled hello-world default into its own file and isolate test filter chain so tests don't observe the seed
|
Size Change: 0 B Total Size: 7.95 MB ℹ️ View Unchanged
|
|
Flaky tests detected in 150a7e5. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/25456144870
|
| @@ -1,5 +1,5 @@ | |||
| { | |||
| "name": "wordpress/hello-world", | |||
| "name": "core/hello-world", | |||
There was a problem hiding this comment.
👍 good, consistent with e.g. blocks slugs.
Part of #78035.
What?
Adds
gutenberg_inject_dashboard_default_layout(), aget_user_metadatahook that lets plugins and themes register a default dashboard layout from the backend.The default surfaces transparently through
@wordpress/preferencesfor users who have not customized theirs.Why?
The dashboard's JS surface reads its layout from the
core/preferencesstore, which is persisted on the server throughpersisted_preferencesuser meta. With the user-meta layer in place, the missing piece is a way for plugins and themes to seed a layout that new users see on first paint, without having to ship JS bootstrap code.Solving this on the backend keeps the seed logic in one place. Whoever extends WordPress (plugin, theme, mu-plugin) can register a default with a single
add_filter()call. The dashboard surface stays oblivious: a default and a user-saved layout look identical at the preferences-store boundary.How?
A new
lib/experimental/dashboard-widgets/dashboard-layout.phpregistersgutenberg_inject_dashboard_default_layout()onget_user_metadataat priority 99.The filter only does work when the meta key matches
{prefix}persisted_preferences. It reads the user's actual stored value (with itself temporarily removed to avoid recursion), and short-circuits when the user already has a non-empty layout undercore/dashboard.dashboardLayout.When the stored layout is empty, the filter applies
gutenberg_dashboard_default_layoutand, if the result is a non-empty array, returns the merged preferences with the default placed under the same scope and key the JS side reads.The file is loaded under the existing
gutenberg-dashboard-widgetsexperiment gate, alongsideload.phpandwidget-types.php.Testing
Run the PHPUnit suite for this filter:
Five cases cover:
Manual smoke from a mu-plugin:
Open the dashboard page as a user that has no
dashboardLayoutstored. The widget appears on first paint.The default registered through the filter is visible from the same store the surface reads. From the browser devtools console:
This returns the array of widget instances currently in the layout. With no user customizations, it's exactly what
gutenberg_dashboard_default_layoutreturned. Once the user moves, adds, or removes a widget, the JS side writes back to the same preferences key and the call returns the persisted layout instead.