method_get_block_responsive_styles()

 
 
 
 

method_get_block_responsive_styles( $block_attributes, $selectors, $ranges, $wrap )

Generates complete responsive CSS for a block from its attributes and a selector map.


Description

The primary CSS generation function for Method’s block system. Iterates over the specified breakpoint ranges, generates media‑query‑wrapped CSS for each CSS selector, and returns the combined output. Only generates CSS for breakpoints where responsiveSettings.{breakpoint}.enabled is true.


Parameters

$block_attributes (array) :
The full block attributes array.

$selectors (array) :
Associative array mapping CSS selectors to arrays of property keys. Example: ['#method-abc' => ['padding-top', 'bgColor']].

$ranges (array) :
Which breakpoints to generate CSS for. Default ['mobile', 'tablet', 'wide']. Include 'base' for non‑responsive styles.

$wrap (bool) :
When true, wraps output in <style> tags. When false, returns raw CSS for use with method_collect_css(). Default true.


Return

(string) Complete CSS string, optionally wrapped in <style> tags.


Source

File: lib/blocks.php


Usage

PHP
$cssargs = array(
    '#' . $methodId => array( 'margin-top', 'margin-bottom', 'boxShadow' ),
    '#' . $methodId . ' > .content' => array( 'padding-top', 'padding-bottom', 'bgColor' ),
);
$css = method_get_block_responsive_styles( $block_attributes, $cssargs, array( 'base', 'mobile', 'tablet', 'wide' ), false );
method_collect_css( $css, '#' . $methodId, 10 );

Notes

  • This function calls method_get_block_media_query_declarations() for each selector/breakpoint combination.
  • Media query breakpoint values come from method_get_block_breakpoints().
  • When $wrap is false, the CSS is typically passed to method_collect_css() for consolidation.

Changelog

VersionDescription
2.0.0Introduced.