[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

WP_Theme_JSON class

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

Defines 1 class

WP_Theme_JSON:: (42 methods):
  __construct()
  maybe_opt_in_into_settings()
  do_opt_in_into_settings()
  sanitize()
  get_blocks_metadata()
  remove_keys_not_in_schema()
  get_settings()
  get_stylesheet()
  get_custom_templates()
  get_template_parts()
  get_block_classes()
  get_preset_classes()
  get_css_variables()
  to_ruleset()
  append_to_selector()
  compute_preset_classes()
  scope_selector()
  get_settings_values_by_slug()
  get_settings_slugs()
  replace_slug_in_string()
  compute_preset_vars()
  compute_theme_vars()
  flatten_tree()
  compute_style_properties()
  get_property_value()
  get_setting_nodes()
  get_style_nodes()
  get_metadata_boolean()
  merge()
  get_svg_filters()
  should_override_preset()
  get_default_slugs()
  get_name_from_defaults()
  filter_slugs()
  remove_insecure_properties()
  remove_insecure_settings()
  remove_insecure_styles()
  is_safe_css_declaration()
  get_raw_data()
  get_from_editor_settings()
  get_patterns()
  get_data()


Class: WP_Theme_JSON  - X-Ref

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

This class is for internal core usage and is not supposed to be used by extenders (plugins and/or themes).
This is a low-level API that may need to do breaking changes. Please,
use get_global_settings, get_global_styles, and get_global_stylesheet instead.

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

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

maybe_opt_in_into_settings( $theme_json )   X-Ref
Enables some opt-in settings if theme declared support.

return: array The modified theme.json structure.
since: 5.9.0
param: array $theme_json A theme.json structure to modify.

do_opt_in_into_settings( &$context )   X-Ref
Enables some settings.

since: 5.9.0
param: array $context The context to which the settings belong.

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

return: array The sanitized output.
since: 5.8.0
since: 5.9.0 Added the `$valid_block_names` and `$valid_element_name` parameters.
param: array $input               Structure to sanitize.
param: array $valid_block_names   List of valid block names.
param: array $valid_element_names List of valid element names.

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/image': {
'selector': '.wp-block-image',
'duotone': 'img',
'elements': {}
}
}

return: array Block metadata.
since: 5.8.0
since: 5.9.0 Added `duotone` key with CSS selector.

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.

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

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

Example:

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

return: array Settings per block.
since: 5.8.0

get_stylesheet( $types = array( 'variables', 'styles', 'presets' )   X-Ref
Returns the stylesheet that results of processing
the theme.json structure this object represents.

return: string Stylesheet.
since: 5.8.0
since: 5.9.0 Removed the `$type` parameter`, added the `$types` and `$origins` parameters.
param: array $types   Types of styles to load. Will load all by default. It accepts:
param: array $origins A list of origins to include. By default it includes VALID_ORIGINS.

get_custom_templates()   X-Ref
Returns the page templates of the active theme.

return: array
since: 5.9.0

get_template_parts()   X-Ref
Returns the template part data of active theme.

return: array
since: 5.9.0

get_block_classes( $style_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;
}

return: string The new stylesheet.
since: 5.8.0 As `get_block_styles()`.
since: 5.9.0 Renamed from `get_block_styles()` to `get_block_classes()`
param: array $style_nodes Nodes with styles.

get_preset_classes( $setting_nodes, $origins )   X-Ref
Creates 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;
}

return: string The new stylesheet.
since: 5.9.0
param: array $setting_nodes Nodes with settings.
param: array $origins       List of origins to process presets from.

get_css_variables( $nodes, $origins )   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;
}

return: string The new stylesheet.
since: 5.8.0
since: 5.9.0 Added the `$origins` parameter.
param: array $nodes   Nodes with settings.
param: array $origins List of origins to process.

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

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

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

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

return: string The result of processing the presets.
since: 5.8.0
since: 5.9.0 Added the `$origins` parameter.
param: array  $settings Settings to process.
param: string $selector Selector wrapping the classes.
param: array  $origins  List of origins to process.

scope_selector( $scope, $selector )   X-Ref
Function that scopes a selector with another one. This works a bit like
SCSS nesting except the `&` operator isn't supported.

<code>
$scope = '.a, .b .c';
$selector = '> .x, .y';
$merged = scope_selector( $scope, $selector );
// $merged is '.a > .x, .a .y, .b .c > .x, .b .c .y'
</code>

return: string Scoped selector.
since: 5.9.0
param: string $scope    Selector to scope to.
param: string $selector Original selector.

get_settings_values_by_slug( $settings, $preset_metadata, $origins )   X-Ref
Gets preset values keyed by slugs based on settings and metadata.

<code>
$settings = array(
'typography' => array(
'fontFamilies' => array(
array(
'slug'       => 'sansSerif',
'fontFamily' => '"Helvetica Neue", sans-serif',
),
array(
'slug'   => 'serif',
'colors' => 'Georgia, serif',
)
),
),
);
$meta = array(
'path'      => array( 'typography', 'fontFamilies' ),
'value_key' => 'fontFamily',
);
$values_by_slug = get_settings_values_by_slug();
// $values_by_slug === array(
//   'sans-serif' => '"Helvetica Neue", sans-serif',
//   'serif'      => 'Georgia, serif',
// );
</code>

return: array Array of presets where each key is a slug and each value is the preset value.
since: 5.9.0
param: array $settings        Settings to process.
param: array $preset_metadata One of the PRESETS_METADATA values.
param: array $origins         List of origins to process.

get_settings_slugs( $settings, $preset_metadata, $origins = null )   X-Ref
Similar to get_settings_values_by_slug, but doesn't compute the value.

return: array Array of presets where the key and value are both the slug.
since: 5.9.0
param: array $settings        Settings to process.
param: array $preset_metadata One of the PRESETS_METADATA values.
param: array $origins         List of origins to process.

replace_slug_in_string( $input, $slug )   X-Ref
Transform a slug into a CSS Custom Property.

return: string The CSS Custom Property. Something along the lines of `--wp--preset--color--black`.
since: 5.9.0
param: string $input String to replace.
param: string $slug  The slug value to use to generate the custom property.

compute_preset_vars( $settings, $origins )   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,
)

return: array Returns the modified $declarations.
since: 5.8.0
since: 5.9.0 Added the `$origins` parameter.
param: array $settings Settings to process.
param: array $origins  List of origins to process.

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,
)

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

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'
}

return: array The flattened tree.
since: 5.8.0
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 '--'.

compute_style_properties( $styles, $settings = array()   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,
)

return: array Returns the modified $declarations.
since: 5.8.0
since: 5.9.0 Added the `$settings` and `$properties` parameters.
param: array $styles    Styles to process.
param: array $settings  Theme settings.
param: array $properties Properties metadata.

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".

return: string|array Style property value.
since: 5.8.0
since: 5.9.0 Added support for values of array type, which are returned as is.
param: array $styles Styles subtree.
param: array $path   Which property to process.

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'
],
]

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

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',
'duotone'  => 'CSS selector for duotone for some node'
],
[
'path'     => ['path', 'to', 'other', 'node' ],
'selector' => 'CSS selector for other node',
'duotone'  => null
],
]

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

get_metadata_boolean( $data, $path, $default = false )   X-Ref
For metadata values that can either be booleans or paths to booleans, gets the value.

```php
$data = array(
'color' => array(
'defaultPalette' => true
)
);

static::get_metadata_boolean( $data, false );
// => false

static::get_metadata_boolean( $data, array( 'color', 'defaultPalette' ) );
// => true
```

return: bool Value of boolean metadata.
since: 6.0.0
param: array      $data    The data to inspect.
param: bool|array $path    Boolean or path to a boolean.
param: bool       $default Default value if the referenced path is missing.

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

since: 5.8.0
since: 5.9.0 Duotone preset also has origins.
param: WP_Theme_JSON $incoming Data to merge.

get_svg_filters( $origins )   X-Ref
Converts all filter (duotone) presets into SVGs.

return: string SVG filters.
since: 5.9.1
param: array $origins List of origins to process.

should_override_preset( $theme_json, $path, $override )   X-Ref
Returns whether a presets should be overridden or not.

return: boolean
since: 5.9.0
param: array      $theme_json The theme.json like structure to inspect.
param: array      $path       Path to inspect.
param: bool|array $override   Data to compute whether to override the preset.

get_default_slugs( $data, $node_path )   X-Ref
Returns the default slugs for all the presets in an associative array
whose keys are the preset paths and the leafs is the list of slugs.

For example:

array(
'color' => array(
'palette'   => array( 'slug-1', 'slug-2' ),
'gradients' => array( 'slug-3', 'slug-4' ),
),
)

return: array
since: 5.9.0
param: array $data      A theme.json like structure.
param: array $node_path The path to inspect. It's 'settings' by default.

get_name_from_defaults( $slug, $base_path )   X-Ref
No description

filter_slugs( $node, $slugs )   X-Ref
Removes the preset values whose slug is equal to any of given slugs.

return: array The new node.
since: 5.9.0
param: array $node  The node with the presets to validate.
param: array $slugs The slugs that should not be overridden.

remove_insecure_properties( $theme_json )   X-Ref
Removes insecure data from theme.json.

return: array Sanitized structure.
since: 5.9.0
param: array $theme_json Structure to sanitize.

remove_insecure_settings( $input )   X-Ref
Processes a setting node and returns the same node
without the insecure settings.

return: array
since: 5.9.0
param: array $input Node to process.

remove_insecure_styles( $input )   X-Ref
Processes a style node and returns the same node
without the insecure styles.

return: array
since: 5.9.0
param: array $input Node to process.

is_safe_css_declaration( $property_name, $property_value )   X-Ref
Checks that a declaration provided by the user is safe.

return: bool
since: 5.9.0
param: string $property_name  Property name in a CSS declaration, i.e. the `color` in `color: red`.
param: string $property_value Value in a CSS declaration, i.e. the `red` in `color: red`.

get_raw_data()   X-Ref
Returns the raw data.

return: array Raw data.
since: 5.8.0

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

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

get_patterns()   X-Ref
Returns the current theme's wanted patterns(slugs) to be
registered from Pattern Directory.

return: string[]
since: 6.0.0

get_data()   X-Ref
Returns a valid theme.json as provided by a theme.

Unlike get_raw_data() this returns the presets flattened, as provided by a theme.
This also uses appearanceTools instead of their opt-ins if all of them are true.

return: array
since: 6.0.0



Generated: Wed Apr 24 01:00:03 2024 Cross-referenced by PHPXref 0.7.1