[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

WP_Theme_JSON_Resolver class

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

Defines 1 class

WP_Theme_JSON_Resolver:: (22 methods):
  read_json_file()
  get_fields_to_translate()
  translate()
  get_core_data()
  has_same_registered_blocks()
  get_theme_data()
  get_block_data()
  remove_json_comments()
  get_user_data_from_wp_global_styles()
  get_user_data()
  get_merged_data()
  get_user_global_styles_post_id()
  theme_has_support()
  get_file_path_from_theme()
  clean_cached_data()
  recursively_iterate_json()
  style_variation_has_scope()
  get_style_variations()
  get_resolved_theme_uris()
  resolve_theme_file_uris()
  inject_variations_from_block_style_variation_files()
  inject_variations_from_block_styles_registry()


Class: WP_Theme_JSON_Resolver  - X-Ref

Class that abstracts the processing of the different data sources
for site-level config and offers an API to work with them.

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.

read_json_file( $file_path )   X-Ref
Processes a file that adheres to the theme.json schema
and returns an array with its contents, or a void array if none found.

param: string $file_path Path to file. Empty if no file.
return: array Contents that adhere to the theme.json schema.

get_fields_to_translate()   X-Ref
Returns a data structure used in theme.json translation.

return: array An array of theme.json fields that are translatable and the keys that are translatable.

translate( $theme_json, $domain = 'default' )   X-Ref
Given a theme.json structure modifies it in place to update certain values
by its translated strings according to the language set by the user.

param: array  $theme_json The theme.json to translate.
param: string $domain     Optional. Text domain. Unique identifier for retrieving translated strings.
return: array Returns the modified $theme_json_structure.

get_core_data()   X-Ref
Returns core's origin config.

return: WP_Theme_JSON Entity that holds core data.

has_same_registered_blocks( $origin )   X-Ref
Checks whether the registered blocks were already processed for this origin.

param: string $origin Data source for which to cache the blocks.
return: bool True on success, false otherwise.

get_theme_data( $deprecated = array()   X-Ref
Returns the theme's data.

Data from theme.json will be backfilled from existing
theme supports, if any. Note that if the same data
is present in theme.json and in theme supports,
the theme.json takes precedence.

param: array $deprecated Deprecated. Not used.
param: array $options {
return: WP_Theme_JSON Entity that holds theme data.

get_block_data()   X-Ref
Gets the styles for blocks from the block.json file.

return: WP_Theme_JSON

remove_json_comments( $input_array )   X-Ref
When given an array, this will remove any keys with the name `//`.

param: array $input_array The array to filter.
return: array The filtered array.

get_user_data_from_wp_global_styles( $theme, $create_post = false, $post_status_filter = array( 'publish' )   X-Ref
Returns the custom post type that contains the user's origin config
for the active theme or an empty array if none are found.

This can also create and return a new draft custom post type.

param: WP_Theme $theme              The theme object. If empty, it
param: bool     $create_post        Optional. Whether a new custom post
param: array    $post_status_filter Optional. Filter custom post type by
return: array Custom Post Type for the user's origin config.

get_user_data()   X-Ref
Returns the user's origin config.

return: WP_Theme_JSON Entity that holds styles for user data.

get_merged_data( $origin = 'custom' )   X-Ref
Returns the data merged from multiple origins.

There are four sources of data (origins) for a site:

- default => WordPress
- blocks  => each one of the blocks provides data for itself
- theme   => the active theme
- custom  => data provided by the user

The custom's has higher priority than the theme's, the theme's higher than blocks',
and block's higher than default's.

Unlike the getters
{@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_core_data/ get_core_data},
{@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_theme_data/ get_theme_data},
and {@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_user_data/ get_user_data},
this method returns data after it has been merged with the previous origins.
This means that if the same piece of data is declared in different origins
(default, blocks, theme, custom), the last origin overrides the previous.

For example, if the user has set a background color
for the paragraph block, and the theme has done it as well,
the user preference wins.

param: string $origin Optional. To what level should we merge data: 'default', 'blocks', 'theme' or 'custom'.
return: WP_Theme_JSON

get_user_global_styles_post_id()   X-Ref
Returns the ID of the custom post type
that stores user data.

return: integer|null

theme_has_support()   X-Ref
Determines whether the active theme has a theme.json file.

return: bool

get_file_path_from_theme( $file_name, $template = false )   X-Ref
Builds the path to the given file and checks that it is readable.

If it isn't, returns an empty string, otherwise returns the whole file path.

param: string $file_name Name of the file.
param: bool   $template  Optional. Use template theme directory. Default false.
return: string The whole file path or empty if the file doesn't exist.

clean_cached_data()   X-Ref
Cleans the cached data so it can be recalculated.


recursively_iterate_json( $dir )   X-Ref
Returns an array of all nested JSON files within a given directory.

param: string $dir The directory to recursively iterate and list files of.
return: array The merged array.

style_variation_has_scope( $variation, $scope )   X-Ref
Determines if a supplied style variation matches the provided scope.

For backwards compatibility, if a variation does not define any scope
related property, e.g. `blockTypes`, it is assumed to be a theme style
variation.

param: array  $variation Theme.json shaped style variation object.
param: string $scope     Scope to check e.g. theme, block etc.
return: boolean

get_style_variations( $scope = 'theme' )   X-Ref
Returns the style variations defined by the theme.

param: string $scope The scope or type of style variation to retrieve e.g. theme, block etc.
return: array

get_resolved_theme_uris( $theme_json )   X-Ref
Resolves relative paths in theme.json styles to theme absolute paths
and returns them in an array that can be embedded
as the value of `_link` object in REST API responses.

param: WP_Theme_JSON $theme_json A theme json instance.
return: array An array of resolved paths.

resolve_theme_file_uris( $theme_json )   X-Ref
Resolves relative paths in theme.json styles to theme absolute paths
and merges them with incoming theme JSON.

param: WP_Theme_JSON $theme_json A theme json instance.
return: WP_Theme_JSON Theme merged with resolved paths, if any found.

inject_variations_from_block_style_variation_files( $data, $variations )   X-Ref
Adds variations sourced from block style variations files to the supplied theme.json data.

param: array $data       Array following the theme.json specification.
param: array $variations Shared block style variations.
return: array Theme json data including shared block style variation definitions.

inject_variations_from_block_styles_registry( $data )   X-Ref
Adds variations sourced from the block styles registry to the supplied theme.json data.

param: array $data Array following the theme.json specification.
return: array Theme json data including shared block style variation definitions.



Generated : Thu Nov 21 08:20:01 2024 Cross-referenced by PHPXref