method_get_block_css_declarations()
method_get_block_css_declarations( $block_attributes, $context, $cssprops, $prioritize, $post_id )
Converts block attributes into CSS declaration strings for a single breakpoint.
Description
The core CSS property resolution engine. Accepts an array of property keys and generates the corresponding CSS declarations by reading from responsiveSettings, top‑level color attributes, and other block attribute structures. This is the function that understands how each property key maps to CSS output.
Parameters
$block_attributes (array) :
The full block attributes array.
$context (string) :
The breakpoint context: 'base', 'mobile', 'tablet', or 'wide'. Default 'base'.
$cssprops (array) :
Array of property keys to generate. When empty, uses a default set of common properties. See the Property Keys section below.
$prioritize (bool) :
When true, appends !important to all generated values. Default false. Used for responsive breakpoint CSS to ensure overrides.
$post_id (int|false) :
The post whose featured image a useFeaturedImage block should resolve (get_the_post_thumbnail_url() at the breakpoint’s featuredImageSize). Default false. Threaded down from method_get_block_responsive_styles().
Return
(string) CSS declaration string (e.g., 'padding-top: 2rem; margin-bottom: 1rem;').
Supported Property Keys
| Key | CSS Output | Source |
|---|---|---|
padding-top through padding-right | padding-* | responsiveSettings.{bp}.padding.* |
margin-top through margin-right | margin-block-start/end or margin-left/right | responsiveSettings.{bp}.margin.* |
marginTopNonZero, etc. | Same, but skips zero values | Same |
marginLeftNonZero, marginRightNonZero | margin-left/right only if non‑zero | Same |
gap | row-gap / column-gap (since beta6; previously one gap) | responsiveSettings.{bp}.gap |
gapAsVars | --bs-gutter-y, --bs-gutter-x | responsiveSettings.{bp}.gap |
font-size / fontSize | font-size | responsiveSettings.{bp}.fontSize |
line-height / lineHeight | line-height | responsiveSettings.{bp}.lineHeight |
text-align / textAlign | text-align | responsiveSettings.{bp}.textAlign |
color / textColor | color | attributes.textColor |
linkHoverColor, linkActiveColor | color (for the caller’s :hover / active selector) | attributes.linkHoverColor, attributes.linkActiveColor |
linkColor | color | attributes.linkColor |
bgColor | background | attributes.bgGradient or attributes.bgColor |
bgShade | background | attributes.bgShadeGradient or attributes.bgShadeColor |
bgImg | background-image: url(...) | attributes.bgImg[size].url |
bgPosition | background-position with offset | responsiveSettings.{bp}.bgImgAlign + offsets |
bgSize | background-size | responsiveSettings.{bp}.bgDisplaySize |
bgRepeat | background-repeat | responsiveSettings.{bp}.bgRepeat |
border | border or per‑side borders | responsiveSettings.{bp}.border |
borderRadius | border-radius or per‑corner | responsiveSettings.{bp}.borderRadius |
boxShadow | box-shadow (multi‑layer) | responsiveSettings.base.shadows |
height, width | Corresponding property | responsiveSettings.{bp}.* |
minHeight, minWidth | min-height, min-width | responsiveSettings.{bp}.* |
alignItems | align-items | responsiveSettings.{bp}.alignItems |
justifyContent | justify-content | responsiveSettings.{bp}.justifyContent |
flexDirection | flex-direction | responsiveSettings.{bp}.flexDirection |
order | order (skips zero) | responsiveSettings.{bp}.order |
equalDimensions | width + height | responsiveSettings.{bp}.dimensions |
aspectRatio | height/padding-top | responsiveSettings.base.aspectUses |
aspectRatioDimension | aspect-ratio: X/Y | responsiveSettings.{bp}.aspectRatioX, aspectRatioY |
zeroHeight | height: 0; overflow: visible — or height: unset; overflow: unset when a non-base breakpoint turns the base’s true off | responsiveSettings.{bp}.zeroHeight |
overflow, zIndex | overflow, z-index | responsiveSettings.{bp}.overflow, zIndex |
hide | display: none; visibility: hidden | responsiveSettings.{bp}.hide |
flexGrow, flexShrink, flexBasis | flex-grow, flex-shrink, flex-basis (truthy values only) | responsiveSettings.{bp}.* |
flexWrap | flex-wrap | responsiveSettings.{bp}.flexWrap |
fontFamily, fontStyle, fontWeight, textTransform, letterSpacing | font-family, font-style, font-weight, text-transform, letter-spacing | responsiveSettings.{bp}.* |
backdrop | backdrop-filter: one name(value) per set key, space-separated (hueRotate → hue-rotate); keys whose value is empty() are skipped | responsiveSettings.{bp}.backdrop |
bgImg with useFeaturedImage | background-image: url(…) of the post thumbnail at featuredImageSize | $post_id, responsiveSettings.{bp}.featuredImageSize |
Source
File: lib/blocks.php
Notes
- Background properties (
bgImg,bgPosition,bgSize,bgRepeat) are only generated whencustomBgistruefor non‑base breakpoints, or always for thebasebreakpoint. - Color properties are sanitized through
method_sanitize_theme_color()to resolve theme color slugs. - Zero‑value dimensions are skipped to avoid overriding inherited sizing.
Changelog
| Version | Description |
|---|---|
| 2.0.0-alpha4 | Introduced (2e1bbd4). |
| 2.0.0-beta5 | Responsive tiers gated by enabled alone — the per-group customSpacing / customType / customDimensions / customBorders flags dropped — multi-layer box-shadow from shadows, and overflow, zIndex, linkHoverColor, linkActiveColor, minHeight, lineHeight keys (beta4c…beta5). |
| 2.0.0-beta6 | $post_id parameter and featured-image backgrounds; flexGrow / flexShrink / flexBasis; gaps emitted as row-gap / column-gap (09cc16b). |
| 2.0.0-beta7 | zeroHeight; debug error_log() calls removed (5afb83a). |
| 2.0.0-beta8 | aspectRatioDimension (bd7d2f4). |
| 2.0.0-beta11 | textAlign accepted as an alias of text-align (94e95b2). |
| 2.0.0-beta12 | margin-top / margin-bottom no longer default to 0 when no margin is set, matching the editor (6740460). |
| 2.0.0-beta15 | hide (a67fd5b). |
| 2.0.0-beta17 | fontFamily, fontStyle, fontWeight, textTransform, letterSpacing; textColor accepted as an alias of color (8db7ce9). |
| 2.0.0-beta20 | backdrop → backdrop-filter (ae61c10). |
| 2.0.0-beta21 | background-size: unset for the Image Size (size) background option (75910d2). |
| 2.0.0-beta24 | flexWrap (a3a3034). |