Automattic\WooCommerce\EmailEditor\Integrations\Utils

Styles_Helper::get_styles_from_blockpublic staticWC 1.0

Wrapper for wp_style_engine_get_styles which ensures all values are returned.

Method of the class: Styles_Helper{}

Returns

Array.

Usage

$result = Styles_Helper::get_styles_from_block( $block_styles, $skip_convert_vars );
$block_styles(array) (required)
Array of block styles.
$skip_convert_vars(true|false)
If true, --wp_preset--spacing--x type values will be left in the original var:preset:spacing:x format.
Default: false

Styles_Helper::get_styles_from_block() code WC 10.7.0

public static function get_styles_from_block( array $block_styles, $skip_convert_vars = false ) {
	$unsupported_props = array(
		'margin' => array( 'spacing', 'margin' ),
	);
	$unsupported_props = apply_filters( 'woocommerce_email_editor_styles_unsupported_props', $unsupported_props );
	foreach ( $unsupported_props as $path ) {
		if ( ! is_array( $path ) || count( $path ) === 0 ) {
			continue;
		}

		$pointer  = & $block_styles;
		$last_key = array_pop( $path );

		foreach ( $path as $segment ) {
			if ( ! is_string( $segment ) && ! is_int( $segment ) ) {
				continue 2;
			}
			if ( ! array_key_exists( $segment, $pointer ) || ! is_array( $pointer[ $segment ] ) ) {
				continue 2;
			}
			$pointer = & $pointer[ $segment ];
		}

		if ( ( is_string( $last_key ) || is_int( $last_key ) ) && array_key_exists( $last_key, $pointer ) ) {
			unset( $pointer[ $last_key ] );
		}
	}
	return wp_parse_args(
		wp_style_engine_get_styles( $block_styles, array( 'convert_vars_to_classnames' => $skip_convert_vars ) ),
		self::$empty_block_styles
	);
}