WP_Theme_JSON
- Source
wp-includes/class-wp-theme-json.php:19
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.
Compatibility
- WordPress
- core
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Hooks and filters 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.
Properties · 2
$theme_jsonarrayprotected- Container of data in theme.json format.
$blocks_metadataarrayprotected static- Holds block metadata extracted from block.json to be shared among all instances so we don't process it twice.
Methods · 70
- schema_in_root_and_per_origin()Return the input schema at the root and per origin.
- get_element_class_name()Returns a class name by an element name.
- __construct()Constructor.
- unwrap_shared_block_style_variations()Unwraps shared block style variations.
- maybe_opt_in_into_settings()Enables some opt-in settings if theme declared support.
- do_opt_in_into_settings()Enables some settings.
- sanitize()Sanitizes the input according to the schemas.
- append_to_selector()Appends a sub-selector to an existing one.
- prepend_to_selector()Prepends a sub-selector to an existing one.
- get_blocks_metadata()Returns the metadata for each block.
- remove_keys_not_in_schema()Given a tree, removes the keys that are not present in the schema.
- get_settings()Returns the existing settings for each block.
- get_stylesheet()Returns the stylesheet that results of processing the theme.json structure this object represents.
- process_blocks_custom_css()Processes the CSS, to apply nesting.
- get_custom_css()Returns the global styles custom CSS.
- get_custom_templates()Returns the page templates of the active theme.
- get_template_parts()Returns the template part data of active theme.
- get_block_classes()Converts each style section into a list of rulesets containing the block styles to be appended to the stylesheet.
- get_layout_styles()Gets the CSS layout rules for a particular block from theme.json layout definitions.
- get_preset_classes()Creates new rulesets as classes for each preset value such as:
- get_css_variables()Converts each styles section into a list of rulesets to be appended to the stylesheet.
- to_ruleset()Given a selector and a declaration list, creates the corresponding ruleset.
- compute_preset_classes()Given a settings array, returns the generated rulesets for the preset classes.
- scope_selector()Function that scopes a selector with another one. This works a bit like SCSS nesting except the `&` operator isn't supported.
- scope_style_node_selectors()Scopes the selectors for a given style node.
- get_settings_values_by_slug()Gets preset values keyed by slugs based on settings and metadata.
- get_settings_slugs()Similar to get_settings_values_by_slug, but doesn't compute the value.
- replace_slug_in_string()Transforms a slug into a CSS Custom Property.
- 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:
- get_property_value()Returns the style property for the given path.
- get_setting_nodes()Builds metadata for the setting nodes, which returns in the form of:
- get_style_nodes()Builds metadata for the style nodes, which returns in the form of:
- get_styles_block_nodes()A public helper to get the block nodes from a theme.json file.
- 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_block_nodes()An internal method to get the block nodes from a theme.json file.
- get_styles_for_block()Gets the CSS rules for a particular block from theme.json.
- get_root_layout_rules()Outputs the CSS for layout rules on the root.
- get_metadata_boolean()For metadata values that can either be booleans or paths to booleans, gets the value.
- merge()Merges new incoming data.
- get_svg_filters()Converts all filter (duotone) presets into SVGs.
- should_override_preset()Determines whether a presets should be overridden or not.
- 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.
- get_name_from_defaults()Gets a `default`'s preset name by a provided slug.
- filter_slugs()Removes the preset values whose slug is equal to any of given slugs.
- remove_insecure_properties()Removes insecure data from theme.json.
- remove_insecure_element_styles()Remove insecure element styles within a variation or block.
- remove_insecure_inner_block_styles()Remove insecure styles from inner blocks and their elements.
- remove_insecure_settings()Processes a setting node and returns the same node without the insecure settings.
- remove_insecure_styles()Processes a style node and returns the same node without the insecure styles.
- is_safe_css_declaration()Checks that a declaration provided by the user is safe.
- remove_indirect_properties()Removes indirect properties from the given input node and sets in the given output node.
- get_raw_data()Returns the raw data.
- get_from_editor_settings()Transforms the given editor settings according the add_theme_support format to the theme.json format.
- get_patterns()Returns the current theme's wanted patterns(slugs) to be registered from Pattern Directory.
- get_data()Returns a valid theme.json as provided by a theme.
- set_spacing_sizes()Sets the spacingSizes array based on the spacingScale values from theme.json.
- merge_spacing_sizes()Merges two sets of spacing size presets.
- 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_block_selectors()Returns the selectors metadata for a block.
- get_block_element_selectors()Generates all the element selectors for a block.
- 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.
- convert_variables_to_value()Replaces CSS variables with their values in place.
- resolve_variables()Resolves the values of CSS variables in the given styles.
- get_block_style_variation_selector()Generates a selector for a block style variation.
- get_valid_block_style_variations()Collects valid block style variations keyed by block type.
Source code
#[AllowDynamicProperties]class WP_Theme_JSON { /** * Container of data in theme.json format. * * @since 5.8.0 * @var array */ protected $theme_json = null; /** * Holds block metadata extracted from block.json * to be shared among all instances so we don't * process it twice. * * @since 5.8.0 * @since 6.1.0 Initialize as an empty array. * @var array */ protected static $blocks_metadata = array(); /** * The CSS selector for the top-level preset settings. * * @since 6.6.0 * @var string */ const ROOT_CSS_PROPERTIES_SELECTOR = ':root'; /** * The CSS selector for the top-level styles. * * @since 5.8.0 * @var string */ const ROOT_BLOCK_SELECTOR = 'body'; /** * The sources of data this object can represent. * * @since 5.8.0 * @since 6.1.0 Added 'blocks'. * @var string[] */ const VALID_ORIGINS = array( 'default', 'blocks', 'theme', 'custom', ); /** * Presets are a set of values that serve * to bootstrap some styles: colors, font sizes, etc. * * They are a unkeyed array of values such as: * * array( * array( * 'slug' => 'unique-name-within-the-set', * 'name' => 'Name for the UI', * <value_key> => 'value' * ), * ) * * This contains the necessary metadata to process them: * * - path => Where to find the preset within the settings section. * - prevent_override => Disables override of default presets by theme presets. * The relationship between whether to override the defaults * and whether the defaults are enabled is inverse: * - If defaults are enabled => theme presets should not be overridden * - If defaults are disabled => theme presets should be overridden * For example, a theme sets defaultPalette to false, * making the default palette hidden from the user. * In that case, we want all the theme presets to be present, * so they should override the defaults by setting this false. * - use_default_names => whether to use the default names * - value_key => the key that represents the valueChangelog
14 changes between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
7.1.0
Method
get_viewport_media_queries() added.verified against source7.1.0
Method
is_valid_viewport_breakpoint_size() added.verified against source7.1.0
Method
get_viewport_breakpoint_value_in_pixels() added.verified against source7.1.0
Method
sanitize_viewport_settings() added.verified against source7.1.0
Method
split_selector_list() added.verified against source7.1.0
Method
get_feature_selector() added.verified against source7.1.0
Method
update_button_width_declarations() added.verified against source7.1.0
Method
get_block_style_variation_feature_selector() added.verified against source7.1.0
Method
get_block_name_from_metadata_path() added.verified against source7.0.4
Method
process_pseudo_selectors() added.verified against source7.0.4
Method
update_paragraph_text_indent_selector() added.verified against source7.0.4
Method
preserve_valid_typed_settings() added.verified against source6.8.8
Method
remove_insecure_element_styles() added.verified against source6.8.8
Method
remove_insecure_inner_block_styles() added.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 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.