[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/ -> class-wp-theme-json.php (summary)

WP_Theme_JSON class

File Size: 1229 lines (33 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WP_Theme_JSON:: (23 methods):
  __construct()
  sanitize()
  get_blocks_metadata()
  remove_keys_not_in_schema()
  get_settings()
  get_stylesheet()
  get_block_styles()
  get_css_variables()
  to_ruleset()
  append_to_selector()
  get_merged_preset_by_slug()
  compute_preset_classes()
  compute_preset_vars()
  compute_theme_vars()
  flatten_tree()
  compute_style_properties()
  has_properties()
  get_property_value()
  get_setting_nodes()
  get_style_nodes()
  merge()
  get_raw_data()
  get_from_editor_settings()


Class: WP_Theme_JSON  - X-Ref

Class that encapsulates the processing of structures that adhere to the theme.json spec.

__construct( $theme_json = array()   X-Ref
Constructor.

param: array $theme_json A structure that follows the theme.json schema.
param: string $origin    Optional. What source of data this object represents.
since: 5.8.0

sanitize( $input )   X-Ref
Sanitizes the input according to the schemas.

param: array $input Structure to sanitize.
since: 5.8.0
return: array The sanitized output.

get_blocks_metadata()   X-Ref
Returns the metadata for each block.

Example:

{
'core/paragraph': {
'selector': 'p',
'elements': {
'link' => 'link selector',
'etc'  => 'element selector'
}
},
'core/heading': {
'selector': 'h1',
'elements': {}
}
'core/group': {
'selector': '.wp-block-group',
'elements': {}
}
}

since: 5.8.0
return: array Block metadata.

remove_keys_not_in_schema( $tree, $schema )   X-Ref
Given a tree, removes the keys that are not present in the schema.

It is recursive and modifies the input in-place.

param: array $tree   Input to process.
param: array $schema Schema to adhere to.
since: 5.8.0
return: array Returns the modified $tree.

get_settings()   X-Ref
Returns the existing settings for each block.

Example:

{
'root': {
'color': {
'custom': true
}
},
'core/paragraph': {
'spacing': {
'customPadding': true
}
}
}

since: 5.8.0
return: array Settings per block.

get_stylesheet( $type = 'all' )   X-Ref
Returns the stylesheet that results of processing
the theme.json structure this object represents.

param: string $type Optional. Type of stylesheet we want. Accepts 'all',
since: 5.8.0
return: string Stylesheet.

get_block_styles( $style_nodes, $setting_nodes )   X-Ref
Converts each style section into a list of rulesets
containing the block styles to be appended to the stylesheet.

See glossary at https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax

For each section this creates a new ruleset such as:

block-selector {
style-property-one: value;
}

Additionally, it'll also create new rulesets
as classes for each preset value such as:

.has-value-color {
color: value;
}

.has-value-background-color {
background-color: value;
}

.has-value-font-size {
font-size: value;
}

.has-value-gradient-background {
background: value;
}

p.has-value-gradient-background {
background: value;
}

param: array $style_nodes   Nodes with styles.
param: array $setting_nodes Nodes with settings.
since: 5.8.0
return: string The new stylesheet.

get_css_variables( $nodes )   X-Ref
Converts each styles section into a list of rulesets
to be appended to the stylesheet.
These rulesets contain all the css variables (custom variables and preset variables).

See glossary at https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax

For each section this creates a new ruleset such as:

block-selector {
--wp--preset--category--slug: value;
--wp--custom--variable: value;
}

param: array $nodes Nodes with settings.
since: 5.8.0
return: string The new stylesheet.

to_ruleset( $selector, $declarations )   X-Ref
Given a selector and a declaration list,
creates the corresponding ruleset.

param: string $selector     CSS selector.
param: array  $declarations List of declarations.
since: 5.8.0
return: string CSS ruleset.

append_to_selector( $selector, $to_append )   X-Ref
No description

get_merged_preset_by_slug( $preset_per_origin, $value_key )   X-Ref
Given an array of presets keyed by origin and the value key of the preset,
it returns an array where each key is the preset slug and each value the preset value.

param: array  $preset_per_origin Array of presets keyed by origin.
param: string $value_key         The property of the preset that contains its value.
since: 5.8.0
return: array Array of presets where each key is a slug and each value is the preset value.

compute_preset_classes( $settings, $selector )   X-Ref
Given a settings array, it returns the generated rulesets
for the preset classes.

param: array  $settings Settings to process.
param: string $selector Selector wrapping the classes.
since: 5.8.0
return: string The result of processing the presets.

compute_preset_vars( $settings )   X-Ref
Given the block settings, it extracts the CSS Custom Properties
for the presets and adds them to the $declarations array
following the format:

array(
'name'  => 'property_name',
'value' => 'property_value,
)

param: array $settings Settings to process.
since: 5.8.0
return: array Returns the modified $declarations.

compute_theme_vars( $settings )   X-Ref
Given an array of settings, it extracts the CSS Custom Properties
for the custom values and adds them to the $declarations
array following the format:

array(
'name'  => 'property_name',
'value' => 'property_value,
)

param: array $settings Settings to process.
since: 5.8.0
return: array Returns the modified $declarations.

flatten_tree( $tree, $prefix = '', $token = '--' )   X-Ref
Given a tree, it creates a flattened one
by merging the keys and binding the leaf values
to the new keys.

It also transforms camelCase names into kebab-case
and substitutes '/' by '-'.

This is thought to be useful to generate
CSS Custom Properties from a tree,
although there's nothing in the implementation
of this function that requires that format.

For example, assuming the given prefix is '--wp'
and the token is '--', for this input tree:

{
'some/property': 'value',
'nestedProperty': {
'sub-property': 'value'
}
}

it'll return this output:

{
'--wp--some-property': 'value',
'--wp--nested-property--sub-property': 'value'
}

param: array  $tree   Input tree to process.
param: string $prefix Optional. Prefix to prepend to each variable. Default empty string.
param: string $token  Optional. Token to use between levels. Default '--'.
since: 5.8.0
return: array The flattened tree.

compute_style_properties( $styles )   X-Ref
Given a styles array, it extracts the style properties
and adds them to the $declarations array following the format:

array(
'name'  => 'property_name',
'value' => 'property_value,
)

param: array $styles Styles to process.
since: 5.8.0
return: array Returns the modified $declarations.

has_properties( $metadata )   X-Ref
Whether the metadata contains a key named properties.

param: array $metadata Description of the style property.
since: 5.8.0
return: bool True if properties exists, false otherwise.

get_property_value( $styles, $path )   X-Ref
Returns the style property for the given path.

It also converts CSS Custom Property stored as
"var:preset|color|secondary" to the form
"--wp--preset--color--secondary".

param: array $styles Styles subtree.
param: array $path   Which property to process.
since: 5.8.0
return: string Style property value.

get_setting_nodes( $theme_json, $selectors = array()   X-Ref
Builds metadata for the setting nodes, which returns in the form of:

[
[
'path'     => ['path', 'to', 'some', 'node' ],
'selector' => 'CSS selector for some node'
],
[
'path'     => [ 'path', 'to', 'other', 'node' ],
'selector' => 'CSS selector for other node'
],
]

param: array $theme_json The tree to extract setting nodes from.
param: array $selectors  List of selectors per block.
since: 5.8.0
return: array

get_style_nodes( $theme_json, $selectors = array()   X-Ref
Builds metadata for the style nodes, which returns in the form of:

[
[
'path'     => [ 'path', 'to', 'some', 'node' ],
'selector' => 'CSS selector for some node'
],
[
'path'     => ['path', 'to', 'other', 'node' ],
'selector' => 'CSS selector for other node'
],
]

param: array $theme_json The tree to extract style nodes from.
param: array $selectors  List of selectors per block.
since: 5.8.0
return: array

merge( $incoming )   X-Ref
Merge new incoming data.

param: WP_Theme_JSON $incoming Data to merge.
since: 5.8.0

get_raw_data()   X-Ref
Returns the raw data.

since: 5.8.0
return: array Raw data.

get_from_editor_settings( $settings )   X-Ref
Transforms the given editor settings according the
add_theme_support format to the theme.json format.

param: array $settings Existing editor settings.
since: 5.8.0
return: array Config that adheres to the theme.json schema.



Generated: Mon Sep 20 01:00:04 2021 Cross-referenced by PHPXref 0.7.1