Class that encapsulates the processing of structures that adhere to the theme.json spec.
Description
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.
Hooks fired · 1
Every hook that fires from inside WP_Theme_JSON, in the order it appears in the class, grouped by the method that fires it.
compute_preset_vars()Given the block settings, extracts the CSS Custom Properties for the presets and adds them to the $declarations array following the format:
compute_theme_vars()Given an array of settings, extracts the CSS Custom Properties for the custom values and adds them to the $declarations array following the format:
flatten_tree()Given a tree, it creates a flattened one by merging the keys and binding the leaf values to the new keys.
compute_style_properties()Given a styles array, it extracts the style properties and adds them to the $declarations array following the format:
update_separator_declarations()Returns a filtered declarations array if there is a separator block with only a background style defined in theme.json by adding a color attribute to reflect the changes in the front.
get_default_slugs()Returns the default slugs for all the presets in an associative array whose keys are the preset paths and the leaves is the list of slugs.
compute_spacing_sizes()Generates a set of spacing sizes by starting with a medium size and applying an operator with an increment value to generate the rest of the sizes outward from the medium size. The medium slug is '50' with the rest of the slugs being 10 apart. The generated names use t-shirt sizing.
convert_custom_properties()This is used to convert the internal representation of variables to the CSS representation.
resolve_custom_css_format()Given a tree, converts the internal representation of variables to the CSS representation.
get_feature_declarations_for_node()Generates style declarations for a node's features e.g., color, border, typography etc. that have custom selectors in their related block's metadata.
19#[AllowDynamicProperties]20classWP_Theme_JSON{2122/**23 * Container of data in theme.json format.24 *25 * @since 5.8.026 * @var array27 */28protected$theme_json=null;2930/**31 * Holds block metadata extracted from block.json32 * to be shared among all instances so we don't33 * process it twice.34 *35 * @since 5.8.036 * @since 6.1.0 Initialize as an empty array.37 * @var array38 */39protectedstatic$blocks_metadata=array();4041/**42 * The CSS selector for the top-level preset settings.43 *44 * @since 6.6.045 * @var string46 */47constROOT_CSS_PROPERTIES_SELECTOR=':root';4849/**50 * The CSS selector for the top-level styles.51 *52 * @since 5.8.053 * @var string54 */55constROOT_BLOCK_SELECTOR='body';5657/**58 * The sources of data this object can represent.59 *60 * @since 5.8.061 * @since 6.1.0 Added 'blocks'.62 * @var string[]63 */64constVALID_ORIGINS=array(65'default',66'blocks',67'theme',68'custom',69);7071/**72* Presets are a set of values that serve73* to bootstrap some styles: colors, font sizes, etc.74*75* They are a unkeyed array of values such as:76*77*array(78*array(79*'slug'=>'unique-name-within-the-set',80*'name'=>'Name for the UI',81*<value_key>=>'value'82*),83*)84*85* This contains the necessary metadata to process them:86*87*- path => Where to find the preset within the settings section.88*- prevent_override => Disables override of default presets by theme presets.89* The relationship between whether to override the defaults90*and whether the defaults are enabled is inverse:91*-If defaults are enabled => theme presets should not be overridden92*-If defaults are disabled => theme presets should be overridden93*For example, a theme sets defaultPalette to false,94* making the default palette hidden from the user.95* In that case, we want all the theme presets to be present,96* so they should override the defaults by setting this false.97*- use_default_names => whether to usethedefault names98*- value_key => the key that represents the value
Signature, return type and hooks compared across 5 parsed releases.
7.1.0
Method get_viewport_media_queries() added.verified against source
7.1.0
Method is_valid_viewport_breakpoint_size() added.verified against source
7.1.0
Method get_viewport_breakpoint_value_in_pixels() added.verified against source
7.1.0
Method sanitize_viewport_settings() added.verified against source
7.1.0
Method split_selector_list() added.verified against source
7.1.0
Method get_feature_selector() added.verified against source
7.1.0
Method update_button_width_declarations() added.verified against source
7.1.0
Method get_block_style_variation_feature_selector() added.verified against source
7.1.0
Method get_block_name_from_metadata_path() added.verified against source
7.0.4
Method process_pseudo_selectors() added.verified against source
7.0.4
Method update_paragraph_text_indent_selector() added.verified against source
7.0.4
Method preserve_valid_typed_settings() added.verified against source
6.8.8
Method remove_insecure_element_styles() added.verified against source
6.8.8
Method remove_insecure_inner_block_styles() added.verified against source
About this page
Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/class-wp-theme-json.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.