wpseek.com
A WordPress-centric search engine for devs and theme authors



wp_get_block_state_style_rules › WordPress Function

Since7.1.0
Deprecatedn/a
wp_get_block_state_style_rules ( $state_styles, $block_type, $rules_group = null )
Parameters: (3)
  • (array) $state_styles Map of state to style array.
    Required: Yes
  • (WP_Block_Type) $block_type Block type.
    Required: Yes
  • (string|null) $rules_group Optional CSS grouping rule, e.g. a media query.
    Required: No
    Default: null
Returns:
  • (array[]) State style rules.
Defined at:
Codex:

Builds compiled state style rules, preserving the selector each rule targets.



Source

function wp_get_block_state_style_rules( $state_styles, $block_type, $rules_group = null ) {
	$css_rules       = array();
	$block_selectors = isset( $block_type->selectors ) && is_array( $block_type->selectors )
		? $block_type->selectors
		: array();

	foreach ( $state_styles as $state => $state_style ) {
		if ( empty( $state_style ) || ! is_array( $state_style ) ) {
			continue;
		}

		foreach ( wp_get_state_style_groups( $state_style, $block_selectors ) as $group ) {
			$compiled = wp_style_engine_get_styles(
				wp_normalize_state_style_for_css_output( $group['style'] )
			);

			if ( ! empty( $compiled['declarations'] ) ) {
				$css_rules[] = array(
					'state'        => $state,
					'selector'     => $group['selector'],
					'declarations' => $compiled['declarations'],
				);
				if ( ! empty( $rules_group ) ) {
					$css_rules[ count( $css_rules ) - 1 ]['rules_group'] = $rules_group;
				}
			}
		}
	}

	return $css_rules;
}