Goal
Avoid building Ultimate Multisite Gutenberg block metadata and loading Gutenberg support assets on ordinary wp-admin screens that are not block editors.
Evidence
On an authenticated subscriber Dashboard request, Block_Editor_Widget_Manager::handle_element() registered blocks for every Ultimate Multisite UI element. register_block() called each element's fields() method to derive attributes.
Three element field definitions synchronously called get_pages():
inc/ui/class-current-site-element.php
inc/ui/class-my-sites-element.php
inc/ui/class-site-actions-element.php
The request trace attributed at least 240 object-cache reads and six SQL queries to those three page-list loads: 120 uncached-ID checks and 120 WP_Post instance reads. None of the resulting page options were used by the WordPress Dashboard.
The same ordinary Dashboard also enqueued wu-gutenberg-support.js, because Gutenberg_Support::add_scripts() runs on every admin_enqueue_scripts event without checking whether the current screen is a block editor.
Implementation context
Primary files:
inc/builders/block-editor/class-block-editor-widget-manager.php
inc/compat/class-gutenberg-support.php
inc/ui/class-current-site-element.php
inc/ui/class-my-sites-element.php
inc/ui/class-site-actions-element.php
Recommended approach:
- Enqueue Gutenberg support assets only when
get_current_screen()->is_block_editor() is true, while preserving any explicitly supported site editor/widget editor contexts.
- Avoid evaluating expensive field
options merely to derive server-side block attribute types.
- Make the shared page-option list lazy and request-memoized so the three elements do not independently query and hydrate the same pages.
- Preserve frontend dynamic-block registration and REST block-editor previews.
Tests
- Ordinary Dashboard/Profile screens do not enqueue
wu-gutenberg-support.
- Block editor screens still enqueue and localize the script.
- Registering block attributes does not execute page-option providers.
- Consolidating editor settings executes a lazy page provider once per request.
- Dynamic blocks still render on frontend and REST preview requests.
Verification
vendor/bin/phpunit --filter Block_Editor_Widget_Manager_Test
vendor/bin/phpcs inc/builders/block-editor/class-block-editor-widget-manager.php inc/compat/class-gutenberg-support.php inc/ui/class-current-site-element.php inc/ui/class-my-sites-element.php inc/ui/class-site-actions-element.php
vendor/bin/phpstan analyse
Goal
Avoid building Ultimate Multisite Gutenberg block metadata and loading Gutenberg support assets on ordinary wp-admin screens that are not block editors.
Evidence
On an authenticated subscriber Dashboard request,
Block_Editor_Widget_Manager::handle_element()registered blocks for every Ultimate Multisite UI element.register_block()called each element'sfields()method to derive attributes.Three element field definitions synchronously called
get_pages():inc/ui/class-current-site-element.phpinc/ui/class-my-sites-element.phpinc/ui/class-site-actions-element.phpThe request trace attributed at least 240 object-cache reads and six SQL queries to those three page-list loads: 120 uncached-ID checks and 120
WP_Postinstance reads. None of the resulting page options were used by the WordPress Dashboard.The same ordinary Dashboard also enqueued
wu-gutenberg-support.js, becauseGutenberg_Support::add_scripts()runs on everyadmin_enqueue_scriptsevent without checking whether the current screen is a block editor.Implementation context
Primary files:
inc/builders/block-editor/class-block-editor-widget-manager.phpinc/compat/class-gutenberg-support.phpinc/ui/class-current-site-element.phpinc/ui/class-my-sites-element.phpinc/ui/class-site-actions-element.phpRecommended approach:
get_current_screen()->is_block_editor()is true, while preserving any explicitly supported site editor/widget editor contexts.optionsmerely to derive server-side block attribute types.Tests
wu-gutenberg-support.Verification