WP_Theme_JSON::compute_preset_classes() – Given a settings array, it returns the generated rulesets for the preset classes.

You appear to be a bot. Output may be restricted

Description

Given a settings array, it returns the generated rulesets for the preset classes.

Usage

$string = WP_Theme_JSON::compute_preset_classes( $settings, $selector, $origins );

Parameters

$settings
( array ) required – Settings to process.
$selector
( string ) required – Selector wrapping the classes.
$origins
( array ) required – List of origins to process.

Returns

string The result of processing the presets.

Source

File name: wordpress/wp-includes/class-wp-theme-json.php
Lines:

1 to 29 of 29
  protected static function compute_preset_classes( $settings, $selector, $origins ) {
    if ( static::ROOT_BLOCK_SELECTOR === $selector ) {
      // Classes at the global level do not need any CSS prefixed,
      // and we don't want to increase its specificity.
      $selector = '';
    }

    $stylesheet = '';
    foreach ( static::PRESETS_METADATA as $preset_metadata ) {
      $slugs = static::get_settings_slugs( $settings, $preset_metadata, $origins );
      foreach ( $preset_metadata['classes'] as $class => $property ) {
        foreach ( $slugs as $slug ) {
          $css_var     = static::replace_slug_in_string( $preset_metadata['css_vars'], $slug );
          $class_name  = static::replace_slug_in_string( $class, $slug );
          $stylesheet .= static::to_ruleset(
            static::append_to_selector( $selector, $class_name ),
            array(
              array(
                'name'  => $property,
                'value' => 'var(' . $css_var . ') !important',
              ),
            )
          );
        }
      }
    }

    return $stylesheet;
  }
 

 View on GitHub View on Trac