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



wp_apply_spacing_support › WordPress Function

Since5.8.0
Deprecatedn/a
wp_apply_spacing_support ( $block_type, $block_attributes )
Access:
  • private
Parameters: (2)
  • (WP_Block_Type) $block_type Block Type.
    Required: Yes
  • (array) $block_attributes Block attributes.
    Required: Yes
Returns:
  • (array) Block spacing CSS classes and inline styles.
Defined at:
Codex:

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

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


Source

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 ) );
}