method_get_block_css_declarations()
method_get_block_css_declarations( $block_attributes, $context, $cssprops, $prioritize )
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.
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 | gap: {y} {x} | 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 | text-align | responsiveSettings.{bp}.textAlign |
color | color | attributes.textColor |
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 |
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 | Introduced. |