Returns the stylesheet that results of processing the theme.json structure this object represents.
Parameters
$types
string[]optional- 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.
Default:
array('variables', 'styles', 'presets')
$origins
string[]optional- A list of origins to include. By default it includes VALID_ORIGINS.
Default:
null
$options
arrayoptional- An array of options for now used for internal purposes only (may change without notice).
The options currently supported are'scope'
that makes sure all style are scoped to a given selector, and root_selector which overwrites and forces a given selector to be used on the root node.Default:
array()
Source
$schema_styles_blocks[ $block ]['variations'] = $schema_styles_variations;
}
$schema['styles'] = static::VALID_STYLES;
$schema['styles']['blocks'] = $schema_styles_blocks;
$schema['styles']['elements'] = $schema_styles_elements;
$schema['settings'] = static::VALID_SETTINGS;
$schema['settings']['blocks'] = $schema_settings_blocks;
$schema['settings']['typography']['fontFamilies'] = static::schema_in_root_and_per_origin( static::FONT_FAMILY_SCHEMA );
// Remove anything that's not present in the schema.
foreach ( array( 'styles', 'settings' ) as $subtree ) {
if ( ! isset( $input[ $subtree ] ) ) {
continue;
}
if ( ! is_array( $input[ $subtree ] ) ) {
unset( $output[ $subtree ] );
continue;
}
$result = static::remove_keys_not_in_schema( $input[ $subtree ], $schema[ $subtree ] );
if ( empty( $result ) ) {
unset( $output[ $subtree ] );
} else {
$output[ $subtree ] = static::resolve_custom_css_format( $result );
}
}
return $output;
}
/**
* Appends a sub-selector to an existing one.
*
* Given the compounded $selector "h1, h2, h3"
* and the $to_append selector ".some-class" the result will be
* "h1.some-class, h2.some-class, h3.some-class".
*
* @since 5.8.0
* @since 6.1.0 Added append position.
* @since 6.3.0 Removed append position parameter.
*
* @param string $selector Original selector.
* @param string $to_append Selector to append.
* @return string The new selector.
*/
protected static function append_to_selector( $selector, $to_append ) {
if ( ! str_contains( $selector, ',' ) ) {
return $selector . $to_append;
}
$new_selectors = array();
$selectors = explode( ',', $selector );
foreach ( $selectors as $sel ) {
$new_selectors[] = $sel . $to_append;
}
return implode( ',', $new_selectors );
}
/**
* Prepends a sub-selector to an existing one.
*
* Given the compounded $selector "h1, h2, h3"
* and the $to_prepend selector ".some-class " the result will be
* ".some-class h1, .some-class h2, .some-class h3".
*
* @since 6.3.0
*
* @param string $selector Original selector.
* @param string $to_prepend Selector to prepend.
* @return string The new selector.
*/
protected static function prepend_to_selector( $selector, $to_prepend ) {
if ( ! str_contains( $selector, ',' ) ) {
return $to_prepend . $selector;
}
$new_selectors = array();
$selectors = explode( ',', $selector );
foreach ( $selectors as $sel ) {
$new_selectors[] = $to_prepend . $sel;
}
return implode( ',', $new_selectors );
}
/**
* Returns the metadata for each block.
*
* Example:
*
* {
* 'core/paragraph': {
* 'selector': 'p',
* 'elements': {
* 'link' => 'link selector',
* 'etc' => 'element selector'
User Contributed Notes
You must log in before being able to contribute a note or feedback.