WP_Theme_JSON::remove_insecure_properties( array $theme_json ): array

In this article

Removes insecure data from theme.json.

Parameters

$theme_jsonarrayrequired
Structure to sanitize.

Return

array Sanitized structure.

Source

		}
	}

	/*
	 * If root styles has a background-image or a background (gradient) set,
	 * set the min-height to '100%'. Minus `--wp-admin--admin-bar--height` for logged-in view.
	 * Setting the CSS rule on the HTML tag ensures background gradients and images behave similarly,
	 * and matches the behavior of the site editor.
	 */
	if ( $should_set_root_min_height ) {
		$block_rules .= static::to_ruleset(
			'html',
			array(
				array(
					'name'  => 'min-height',
					'value' => 'calc(100% - var(--wp-admin--admin-bar--height, 0px))',
				),
			)
		);
	}

	// Update declarations if there are separators with only background color defined.
	if ( '.wp-block-separator' === $selector ) {
		$declarations = static::update_separator_declarations( $declarations );
	}

	// 2. Generate and append the rules that use the general selector.
	$block_rules .= static::to_ruleset( ":root :where($selector)", $declarations );

	// 3. Generate and append the rules that use the duotone selector.
	if ( isset( $block_metadata['duotone'] ) && ! empty( $declarations_duotone ) ) {
		$block_rules .= static::to_ruleset( $block_metadata['duotone'], $declarations_duotone );
	}

	// 4. Generate Layout block gap styles.
	if (
		! $is_root_selector &&
		! empty( $block_metadata['name'] )
	) {
		$block_rules .= $this->get_layout_styles( $block_metadata );
	}

	// 5. Generate and append the feature level rulesets.
	foreach ( $feature_declarations as $feature_selector => $individual_feature_declarations ) {
		$block_rules .= static::to_ruleset( ":root :where($feature_selector)", $individual_feature_declarations );
	}

	// 6. Generate and append the style variation rulesets.
	foreach ( $style_variation_declarations as $style_variation_selector => $individual_style_variation_declarations ) {
		$block_rules .= static::to_ruleset( ":root :where($style_variation_selector)", $individual_style_variation_declarations );
		if ( isset( $style_variation_custom_css[ $style_variation_selector ] ) ) {
			$block_rules .= $style_variation_custom_css[ $style_variation_selector ];
		}
	}

	// 7. Generate and append any custom CSS rules pertaining to nested block style variations.
	if ( isset( $node['css'] ) && ! $is_root_selector ) {
		$block_rules .= $this->process_blocks_custom_css( $node['css'], $selector );
	}

	return $block_rules;
}

/**
 * Outputs the CSS for layout rules on the root.
 *
 * @since 6.1.0
 * @since 6.6.0 Use `ROOT_CSS_PROPERTIES_SELECTOR` for CSS custom properties and improved consistency of root padding rules.
 *              Updated specificity of body margin reset and first/last child selectors.
 *
 * @param string $selector The root node selector.
 * @param array  $block_metadata The metadata for the root block.
 * @return string The additional root rules CSS.
 */
public function get_root_layout_rules( $selector, $block_metadata ) {
	$css              = '';
	$settings         = isset( $this->theme_json['settings'] ) ? $this->theme_json['settings'] : array();
	$use_root_padding = isset( $this->theme_json['settings']['useRootPaddingAwareAlignments'] ) && true === $this->theme_json['settings']['useRootPaddingAwareAlignments'];

	/*
	* If there are content and wide widths in theme.json, output them
	* as custom properties on the body element so all blocks can use them.
	*/
	if ( isset( $settings['layout']['contentSize'] ) || isset( $settings['layout']['wideSize'] ) ) {
		$content_size = isset( $settings['layout']['contentSize'] ) ? $settings['layout']['contentSize'] : $settings['layout']['wideSize'];
		$content_size = static::is_safe_css_declaration( 'max-width', $content_size ) ? $content_size : 'initial';

Changelog

VersionDescription
5.9.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.