wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_add_block_state_style_rule › WordPress Function

Seit7.1.0
Veraltetn/v
› wp_add_block_state_style_rule ( $css_rules, $state, $selector, $style, $rules_group = null, $base_style = null )
Parameter: (6)
  • (array[]) $css_rules Style rules.
    Erforderlich: Ja
  • (string) $state Pseudo-state selector.
    Erforderlich: Ja
  • (string|null) $selector Block, feature, or element selector.
    Erforderlich: Ja
  • (array<string,mixed>) $style Style object.
    Erforderlich: Ja
  • (string|null) $rules_group Optional CSS grouping rule, e.g. a media query.
    Erforderlich: Nein
    Standard: null
  • (array<string,mixed>|null) $base_style Optional styles the state layers over.
    Erforderlich: Nein
    Standard: null
Definiert in:
Codex:
Changelog:
  • 7.2.0

Adds a compiled state style rule to a rule list.



Quellcode

function wp_add_block_state_style_rule( &$css_rules, $state, $selector, $style, $rules_group = null, $base_style = null ) {
	if ( empty( $style ) || ! is_array( $style ) ) {
		return;
	}

	$style = wp_get_state_style_with_fallback_dimension_styles( $style );

	$compiled     = wp_style_engine_get_styles(
		wp_normalize_state_style_for_css_output( $style )
	);
	$declarations = $compiled['declarations'] ?? array();
	$text_align   = $style['typography']['textAlign'] ?? null;
	// Base text alignment is class-based, so state styles need a declaration.
	if ( is_string( $text_align ) && '' !== trim( $text_align ) ) {
		$declarations['text-align'] = $text_align;
	}

	// Only block states pass a base; element states match the editor and skip it.
	if ( null !== $base_style ) {
		$base_clip    = $base_style['background']['backgroundClip'] ?? '';
		$declarations = array_merge(
			$declarations,
			wp_get_state_text_clip_escape( $style, is_string( $base_clip ) ? $base_clip : '' ),
			wp_get_state_text_fill_reset( $style )
		);
	}

	if ( empty( $declarations ) ) {
		return;
	}

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