Automattic\WooCommerce\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors

Spacing_Preprocessor::get_root_paddingprivateWC 1.0

Extracts and sanitizes root horizontal padding from theme styles.

Method of the class: Spacing_Preprocessor{}

No Hooks.

Returns

Array. Root padding with 'left' and 'right' keys, or empty array if invalid.

Usage

// private - for code of main (parent) class only
$result = $this->get_root_padding( $styles ): array;
$styles(array) (required)
Theme styles.

Spacing_Preprocessor::get_root_padding() code WC 10.8.1

private function get_root_padding( array $styles ): array {
	$padding   = $styles['spacing']['padding'] ?? array();
	$has_left  = isset( $padding['left'] );
	$has_right = isset( $padding['right'] );

	// If neither horizontal padding key is defined, skip root padding entirely.
	if ( ! $has_left && ! $has_right ) {
		return array();
	}

	$left  = $has_left ? $padding['left'] : '0px';
	$right = $has_right ? $padding['right'] : '0px';

	// Validate against potentially malicious values.
	if ( ! is_string( $left ) || ! is_string( $right ) || preg_match( '/[<>"\']/', $left . $right ) ) {
		return array();
	}

	return array(
		'left'  => $left,
		'right' => $right,
	);
}