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



wp_apply_spacing_support › WordPress Function

Seit5.8.0
Veraltetn/v
wp_apply_spacing_support ( $block_type, $block_attributes )
Zugriff:
  • private
Parameter: (2)
  • (WP_Block_Type) $block_type Block Type.
    Erforderlich: Ja
  • (array) $block_attributes Block attributes.
    Erforderlich: Ja
Gibt zurück:
  • (array) Block spacing CSS classes and inline styles.
Definiert in:
Codex:

Add CSS classes for block spacing to the incoming attributes array.

This will be applied to the block markup in the front-end.


Quellcode

function wp_apply_spacing_support( $block_type, $block_attributes ) {
	$has_padding_support = wp_has_spacing_feature_support( $block_type, 'padding' );
	$has_margin_support  = wp_has_spacing_feature_support( $block_type, 'margin' );
	$styles              = array();

	if ( $has_padding_support ) {
		$padding_value = _wp_array_get( $block_attributes, array( 'style', 'spacing', 'padding' ), null );
		if ( null !== $padding_value ) {
			foreach ( $padding_value as $key => $value ) {
				$styles[] = sprintf( 'padding-%s: %s;', $key, $value );
			}
		}
	}

	if ( $has_margin_support ) {
		$margin_value = _wp_array_get( $block_attributes, array( 'style', 'spacing', 'margin' ), null );
		if ( null !== $margin_value ) {
			foreach ( $margin_value as $key => $value ) {
				$styles[] = sprintf( 'margin-%s: %s;', $key, $value );
			}
		}
	}

	return empty( $styles ) ? array() : array( 'style' => implode( ' ', $styles ) );
}