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

KeyCSS OutputSource
padding-top through padding-rightpadding-*responsiveSettings.{bp}.padding.*
margin-top through margin-rightmargin-block-start/end or margin-left/rightresponsiveSettings.{bp}.margin.*
marginTopNonZero, etc.Same, but skips zero valuesSame
marginLeftNonZero, marginRightNonZeromargin-left/right only if non‑zeroSame
gapgap: {y} {x}responsiveSettings.{bp}.gap
gapAsVars--bs-gutter-y, --bs-gutter-xresponsiveSettings.{bp}.gap
font-size / fontSizefont-sizeresponsiveSettings.{bp}.fontSize
line-height / lineHeightline-heightresponsiveSettings.{bp}.lineHeight
text-aligntext-alignresponsiveSettings.{bp}.textAlign
colorcolorattributes.textColor
linkColorcolorattributes.linkColor
bgColorbackgroundattributes.bgGradient or attributes.bgColor
bgShadebackgroundattributes.bgShadeGradient or attributes.bgShadeColor
bgImgbackground-image: url(...)attributes.bgImg[size].url
bgPositionbackground-position with offsetresponsiveSettings.{bp}.bgImgAlign + offsets
bgSizebackground-sizeresponsiveSettings.{bp}.bgDisplaySize
bgRepeatbackground-repeatresponsiveSettings.{bp}.bgRepeat
borderborder or per‑side bordersresponsiveSettings.{bp}.border
borderRadiusborder-radius or per‑cornerresponsiveSettings.{bp}.borderRadius
boxShadowbox-shadow (multi‑layer)responsiveSettings.base.shadows
height, widthCorresponding propertyresponsiveSettings.{bp}.*
minHeight, minWidthmin-height, min-widthresponsiveSettings.{bp}.*
alignItemsalign-itemsresponsiveSettings.{bp}.alignItems
justifyContentjustify-contentresponsiveSettings.{bp}.justifyContent
flexDirectionflex-directionresponsiveSettings.{bp}.flexDirection
orderorder (skips zero)responsiveSettings.{bp}.order
equalDimensionswidth + heightresponsiveSettings.{bp}.dimensions
aspectRatioheight/padding-topresponsiveSettings.base.aspectUses

Source

File: lib/blocks.php


Notes

  • Background properties (bgImg, bgPosition, bgSize, bgRepeat) are only generated when customBg is true for non‑base breakpoints, or always for the base breakpoint.
  • 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

VersionDescription
2.0.0Introduced.