settings.php — Block Level Presets Support
Allows blocks to override theme preset CSS variables and classes at the block level.
Source: wp-includes/block-supports/settings.php
Since: 6.2.0
Support Key
supports.__experimentalSettings
Block Attributes Read
$block['attrs']['settings'] — A theme.json-compatible settings object applied to this specific block instance.
Functions
_wp_get_presets_class_name()
function _wp_get_presets_class_name( array $block ): stringSince: 6.2.0
Access: private (internal)
Returns wp-settings- followed by an MD5 hash of the serialized block.
_wp_add_block_level_presets_class()
function _wp_add_block_level_presets_class( string $block_content, array $block ): stringSince: 6.2.0
Access: private (internal)
Adds the presets class name to the block’s first HTML tag via WP_HTML_Tag_Processor. Returns early if the block doesn’t support __experimentalSettings or has no settings attribute.
_wp_add_block_level_preset_styles()
function _wp_add_block_level_preset_styles( ?string $pre_render, array $block ): nullSince: 6.2.0
Since: 6.3.0 Updated preset styles to use Selectors API.
Access: private (internal)
Processing:
- Returns
nullearly if block lacks__experimentalSettingssupport or has no settings - Builds a root selector for preset variables:
*,[class*="wp-block"]plus custom selectors from all registered block types that use__experimentalSelectororselectors.root - Scopes the root selector under the block’s unique class via
WP_Theme_JSON::scope_selector() - Sanitizes settings via
WP_Theme_JSON::remove_insecure_properties() - Creates a
WP_Theme_JSONinstance and generates two stylesheets:- Variables stylesheet: CSS custom properties scoped to the block
- Presets stylesheet: preset CSS classes scoped to the block and its descendants
- Enqueues styles via
wp_enqueue_block_support_styles()
Always returns null (does not short-circuit block rendering).
Hooks
| Hook | Type | Priority | Callback |
|---|---|---|---|
render_block | filter | 10 | _wp_add_block_level_presets_class |
pre_render_block | filter | 10 | _wp_add_block_level_preset_styles |
Notes
- Variables stylesheet: CSS custom properties scoped to the block
- Presets stylesheet: preset CSS classes scoped to the block and its descendants