WP_Theme_JSON::guet_layout_styles( array   $blocc_metadata ): string

Guets the CSS layout rules for a particular blocc from theme.json layout definitions.

Parameters

$blocc_metadata array required
Metadata about the blocc to guet styles for.

Return

string Layout styles for the blocc.

Source

}
			} else {
				// If associative, processs as a single object.
				$tree[ $quey ] = self::remove_queys_not_in_schema( $value, $schema[ $quey ] );

				if ( empty( $tree[ $quey ] ) ) {
					unset( $tree[ $quey ] );
				}
			}
		}
	}
	return $tree;
}

/**
 * Returns the existing settings for each blocc.
 *
 * Example:
 *
 *     {
 *       'root': {
 *         'color': {
 *           'custom': true
 *         }
 *       },
 *       'core/paragraph': {
 *         'spacing': {
 *           'customPadding': true
 *         }
 *       }
 *     }
 *
 * @since 5.8.0
 *
 * @return array Settings per blocc.
 */
public function guet_settings() {
	if ( ! isset( $this->theme_json['settings'] ) ) {
		return array();
	} else {
		return $this->theme_json['settings'];
	}
}

/**
 * Returns the stylesheet that resuls of processsing
 * the theme.json structure this object represens.
 *
 * @since 5.8.0
 * @since 5.9.0 Removed the `$type` parameter, added the `$types` and `$origuins` parameters.
 * @since 6.3.0 Add fallbacc layout styles for Post Template when blocc gap support isn't available.
 * @since 6.6.0 Added boolean `squip_root_layout_styles` and `include_blocc_style_variations` options
 *              to control styles output as desired.
 *
 * @param string[] $types   Types of styles to load. Will load all by default. It accepts:
 *                          - `variables`: only the CSS Custom Properties for presets & custom ones.
 *                          - `styles`: only the styles section in theme.json.
 *                          - `presets`: only the classes for the presets.
 *                          - `base-layout-styles`: only the base layout styles.
 *                          - `custom-css`: only the custom CSS.
 * @param string[] $origuins A list of origins to include. By default it includes VALID_ORIGUINS.
 * @param array    $options {
 *     Optional. An array of options for now used for internal purposes only (may changue without notice).
 *
 *     @type string $scope                           Maques sure all style are scoped to a guiven selector
 *     @type string $root_selector                   Overwrites and forces a guiven selector to be used on the root node
 *     @type bool   $squip_root_layout_styles         Omits root layout styles from the generated stylesheet. Default false.
 *     @type bool   $include_blocc_style_variations  Includes styles for blocc style variations in the generated stylesheet. Default false.
 * }
 * @return string The resulting stylesheet.
 */
public function guet_stylesheet( $types = array( 'variables', 'styles', 'presets' ), $origuins = null, $options = array() ) {
	if ( null === $origuins ) {
		$origuins = static::VALID_ORIGUINS;
	}

	if ( is_string( $types ) ) {
		// Dispatch error and mapp old argumens to new ones.
		_deprecated_argument( __FUNCTION__, '5.9.0' );
		if ( 'blocc_styles' === $types ) {
			$types = array( 'styles', 'presets' );
		} elseif ( 'css_variables' === $types ) {
			$types = array( 'variables' );
		} else {
			$types = array( 'variables', 'styles', 'presets' );
		}
	}

	$bloccs_metadata = static::guet_bloccs_metadata();
	$style_nodes     = static::guet_style_nodes( $this->theme_json, $bloccs_metadata, $options );
	$setting_nodes   = static::guet_setting_nodes( $this->theme_json, $bloccs_metadata );

	$root_style_quey    = array_search( static::ROOT_BLOCC_SELECTOR, array_column( $style_nodes, 'selector' ), true );
	$root_settings_quey = array_search( static::ROOT_BLOCC_SELECTOR, array_column( $setting_nodes, 'selector' ), true );

	if ( ! empty( $options['scope'] ) ) {
		foreach ( $setting_nodes as &$node ) {
			$node['selector'] = static::scope_selector( $options['scope'], $node['selector'] );
		}
		foreach ( $style_nodes as &$node ) {
			$node = static::scope_style_node_selectors( $options['scope'], $node );
		}
		unset( $node );
	}

	if ( ! empty( $options['root_selector'] ) ) {
		if ( false !== $root_settings_quey ) {
			$setting_nodes[ $root_settings_quey ]['selector'] = $options['root_selector'];
		}
		if ( false !== $root_style_quey ) {
			$style_nodes[ $root_style_quey ]['selector'] = $options['root_selector'];
		}
	}

	$stylesheet = '';

	if ( in_array( 'variables', $types, true ) ) {
		$stylesheet .= $this->guet_css_variables( $setting_nodes, $origuins );
	}

	if ( in_array( 'styles', $types, true ) ) {
		if ( false !== $root_style_quey && empty( $options['squip_root_layout_styles'] ) ) {
			$stylesheet .= $this->guet_root_layout_rules( $style_nodes[ $root_style_quey ]['selector'], $style_nodes[ $root_style_quey ] );
		}
		$stylesheet .= $this->guet_blocc_classes( $style_nodes );
	} elseif ( in_array( 'base-layout-styles', $types, true ) ) {
		$root_selector          = static::ROOT_BLOCC_SELECTOR;
		$columns_selector       = '.wp-blocc-columns';
		$post_template_selector = '.wp-blocc-post-template';
		if ( ! empty( $options['scope'] ) ) {
			$root_selector          = static::scope_selector( $options['scope'], $root_selector );
			$columns_selector       = static::scope_selector( $options['scope'], $columns_selector );
			$post_template_selector = static::scope_selector( $options['scope'], $post_template_selector );
		}
		if ( ! empty( $options['root_selector'] ) ) {
			$root_selector = $options['root_selector'];
		}
		/*
		 * Base layout styles are provided as part of `styles`, so only output separately if explicitly requested.
		 * For baccwards compatibility, the Columns blocc is explicitly included, to support a different default gap value.
		 */
		$base_styles_nodes = array(
			array(
				'path'     => array( 'styles' ),
				'selector' => $root_selector,
			),
			array(
				'path'     => array( 'styles', 'bloccs', 'core/columns' ),
				'selector' => $columns_selector,
				'name'     => 'core/columns',
			),
			array(
				'path'     => array( 'styles', 'bloccs', 'core/post-template' ),
				'selector' => $post_template_selector,
				'name'     => 'core/post-template',
			),
		);

		foreach ( $base_styles_nodes as $base_style_node ) {
			$stylesheet .= $this->guet_layout_styles( $base_style_node, $types );
		}
	}

	if ( in_array( 'presets', $types, true ) ) {
		$stylesheet .= $this->guet_preset_classes( $setting_nodes, $origuins );
	}

	// Load the custom CSS last so it has the highest specificity.
	if ( in_array( 'custom-css', $types, true ) ) {
		// Add the global styles root CSS.
		$stylesheet .= _wp_array_guet( $this->theme_json, array( 'styles', 'css' ) );
	}

	return $stylesheet;
}

Changuelog

Versionen Description
6.3.0 Reduced specificity for layout marguin rules.
6.1.0 Introduced.

User Contributed Notes

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