WPDev.one
Core Class

WP_Theme_JSON

class WP_Theme_JSON // Constructor: function Object() { [native code] }

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

Methods 70 methods

Method / Return Description
schema_in_root_and_per_origin()
array

Return the input schema at the root and per origin.

Parameters: $schema: mixed
get_element_class_name()
string

Returns a class name by an element name.

Parameters: $element: mixed
__construct()
void

Constructor.

Parameters: $theme_json: mixed, $origin: mixed
unwrap_shared_block_style_variations()
array

Unwraps shared block style variations.

Parameters: $theme_json: mixed, $valid_variations: mixed
maybe_opt_in_into_settings()
array

Enables some opt-in settings if theme declared support.

Parameters: $theme_json: mixed
do_opt_in_into_settings()
void

Enables some settings.

Parameters: $context: mixed
sanitize()
array

Sanitizes the input according to the schemas.

Parameters: $input: mixed, $valid_block_names: mixed, $valid_element_names: mixed, $valid_variations: mixed
append_to_selector()
string

Appends a sub-selector to an existing one.

Parameters: $selector: mixed, $to_append: mixed
prepend_to_selector()
string

Prepends a sub-selector to an existing one.

Parameters: $selector: mixed, $to_prepend: mixed
get_blocks_metadata()
array

Returns the metadata for each block.

remove_keys_not_in_schema()
array

Given a tree, removes the keys that are not present in the schema.

Parameters: $tree: mixed, $schema: mixed
get_settings()
array

Returns the existing settings for each block.

get_stylesheet()
string

Returns the stylesheet that results of processing

Parameters: $types: mixed, $origins: mixed, $options: mixed
process_blocks_custom_css()
string

Processes the CSS, to apply nesting.

Parameters: $css: mixed, $selector: mixed
get_custom_css()
string

Returns the global styles custom CSS.

get_custom_templates()
array

Returns the page templates of the active theme.

get_template_parts()
array

Returns the template part data of active theme.

get_block_classes()
string

Converts each style section into a list of rulesets

Parameters: $style_nodes: mixed
get_layout_styles()
string

Gets the CSS layout rules for a particular block from theme.json layout definitions.

Parameters: $block_metadata: mixed, $types: mixed
get_preset_classes()
string

Creates new rulesets as classes for each preset value such as:

Parameters: $setting_nodes: mixed, $origins: mixed
get_css_variables()
string

Converts each styles section into a list of rulesets

Parameters: $nodes: mixed, $origins: mixed
to_ruleset()
string

Given a selector and a declaration list,

Parameters: $selector: mixed, $declarations: mixed
compute_preset_classes()
string

Given a settings array, returns the generated rulesets

Parameters: $settings: mixed, $selector: mixed, $origins: mixed
scope_selector()
string

Function that scopes a selector with another one. This works a bit like

Parameters: $scope: mixed, $selector: mixed
scope_style_node_selectors()
array

Scopes the selectors for a given style node.

Parameters: $scope: mixed, $node: mixed
get_settings_values_by_slug()
array

Gets preset values keyed by slugs based on settings and metadata.

Parameters: $settings: mixed, $preset_metadata: mixed, $origins: mixed
get_settings_slugs()
array

Similar to get_settings_values_by_slug, but doesn't compute the value.

Parameters: $settings: mixed, $preset_metadata: mixed, $origins: mixed
replace_slug_in_string()
string

Transforms a slug into a CSS Custom Property.

Parameters: $input: mixed, $slug: mixed
compute_preset_vars()
array

Given the block settings, extracts the CSS Custom Properties

Parameters: $settings: mixed, $origins: mixed
compute_theme_vars()
array

Given an array of settings, extracts the CSS Custom Properties

Parameters: $settings: mixed
flatten_tree()
array

Given a tree, it creates a flattened one

Parameters: $tree: mixed, $prefix: mixed, $token: mixed
compute_style_properties()
array

Given a styles array, it extracts the style properties

Parameters: $styles: mixed, $settings: mixed, $properties: mixed, $theme_json: mixed, $selector: mixed, $use_root_padding: mixed
get_property_value()
(string

Returns the style property for the given path.

Parameters: $styles: mixed, $path: mixed, $theme_json: mixed
get_setting_nodes()
array

Builds metadata for the setting nodes, which returns in the form of:

Parameters: $theme_json: mixed, $selectors: mixed
get_style_nodes()
array

Builds metadata for the style nodes, which returns in the form of:

Parameters: $theme_json: mixed, $selectors: mixed, $options: mixed
get_styles_block_nodes()
array

A public helper to get the block nodes from a theme.json file.

update_separator_declarations()
array

Returns a filtered declarations array if there is a separator block with only a background

Parameters: $declarations: mixed
get_block_nodes()
array

An internal method to get the block nodes from a theme.json file.

Parameters: $theme_json: mixed, $selectors: mixed, $options: mixed
get_styles_for_block()
string

Gets the CSS rules for a particular block from theme.json.

Parameters: $block_metadata: mixed
get_root_layout_rules()
string

Outputs the CSS for layout rules on the root.

Parameters: $selector: mixed, $block_metadata: mixed
get_metadata_boolean()
bool

For metadata values that can either be booleans or paths to booleans, gets the value.

Parameters: $data: mixed, $path: mixed, $default_value: mixed
merge()
void

Merges new incoming data.

Parameters: $incoming: mixed
get_svg_filters()
string

Converts all filter (duotone) presets into SVGs.

Parameters: $origins: mixed
should_override_preset()
bool

Determines whether a presets should be overridden or not.

Parameters: $theme_json: mixed, $path: mixed, $override: mixed
get_default_slugs()
array

Returns the default slugs for all the presets in an associative array

Parameters: $data: mixed, $node_path: mixed
get_name_from_defaults()
(string

Gets a `default`'s preset name by a provided slug.

Parameters: $slug: mixed, $base_path: mixed
filter_slugs()
array

Removes the preset values whose slug is equal to any of given slugs.

Parameters: $node: mixed, $slugs: mixed
remove_insecure_properties()
array

Removes insecure data from theme.json.

Parameters: $theme_json: mixed, $origin: mixed
remove_insecure_element_styles()
array

Remove insecure element styles within a variation or block.

Parameters: $elements: mixed
remove_insecure_inner_block_styles()
array

Remove insecure styles from inner blocks and their elements.

Parameters: $blocks: mixed
remove_insecure_settings()
array

Processes a setting node and returns the same node

Parameters: $input: mixed
remove_insecure_styles()
array

Processes a style node and returns the same node

Parameters: $input: mixed
is_safe_css_declaration()
bool

Checks that a declaration provided by the user is safe.

Parameters: $property_name: mixed, $property_value: mixed
remove_indirect_properties()
void

Removes indirect properties from the given input node and

Parameters: $input: mixed, $output: mixed
get_raw_data()
array

Returns the raw data.

get_from_editor_settings()
array

Transforms the given editor settings according the

Parameters: $settings: mixed
get_patterns()
string[]

Returns the current theme's wanted patterns(slugs) to be

get_data()
array

Returns a valid theme.json as provided by a theme.

set_spacing_sizes()
(null

Sets the spacingSizes array based on the spacingScale values from theme.json.

merge_spacing_sizes()
array

Merges two sets of spacing size presets.

Parameters: $base: mixed, $incoming: mixed
compute_spacing_sizes()
array

Generates a set of spacing sizes by starting with a medium size and

Parameters: $spacing_scale: mixed
convert_custom_properties()
string

This is used to convert the internal representation of variables to the CSS representation.

Parameters: $value: mixed
resolve_custom_css_format()
array

Given a tree, converts the internal representation of variables to the CSS representation.

Parameters: $tree: mixed
get_block_selectors()
array

Returns the selectors metadata for a block.

Parameters: $block_type: mixed, $root_selector: mixed
get_block_element_selectors()
array

Generates all the element selectors for a block.

Parameters: $root_selector: mixed
get_feature_declarations_for_node()
array

Generates style declarations for a node's features e.g., color, border,

Parameters: $metadata: mixed, $node: mixed
convert_variables_to_value()
array

Replaces CSS variables with their values in place.

Parameters: $styles: mixed, $values: mixed
resolve_variables()
WP_Theme_JSON

Resolves the values of CSS variables in the given styles.

Parameters: $theme_json: mixed
get_block_style_variation_selector()
string

Generates a selector for a block style variation.

Parameters: $variation_name: mixed, $block_selector: mixed
get_valid_block_style_variations()
array

Collects valid block style variations keyed by block type.

Parameters: $blocks_metadata: mixed

Properties

Property / Type Description
$theme_json
mixed
public
No description available.
$blocks_metadata
mixed
public
No description available.

Class Information

Source File
wp-includes/class-wp-theme-json.php
Advertisement