WP_Theme_JSON_Resolver::get_style_variations( string $scope = 'theme' ): array
- Since
- 6.0.0, 6.2.0, 6.6.0
- Source
wp-includes/class-wp-theme-json-resolver.php:810
Returns the style variations defined by the theme.
Parameters
$scopestringoptional- The scope or type of style variation to retrieve e.g. theme, block etc.Default:
'theme'
Return
array
Uses · 10
- get_stylesheet_directory()Retrieves stylesheet directory path for the active theme.
- get_template_directory()Retrieves template directory path for the active theme.
- wp_get_theme()Gets a WP_Theme object for a theme.
- static::recursively_iterate_json()
- WP_Theme_JSON_Resolver::read_json_file()Processes a file that adheres to the theme.json schema and returns an array with its contents, or a void array if none found.
- static::style_variation_has_scope()
- static::translate()
- wp_get_theme()::get()
- new WP_Theme_JSON($translated)::get_raw_data()
- WP_Theme_JSON::__construct()Constructor.
Used by · 4
- WP_Font_Face_Resolver::get_fonts_from_style_variations()Gets fonts defined in style variations.
- WP_REST_Global_Styles_Controller::get_theme_items()Returns the given theme global styles variations.
- WP_REST_Global_Styles_Controller::prepare_item_for_database()Prepares a single global styles config for update.
- _wp_theme_json_webfonts_handler()Runs the theme.json webfonts handler.
Source
public static function get_style_variations( $scope = 'theme' ) { $variation_files = array(); $variations = array(); $base_directory = get_stylesheet_directory() . '/styles'; $template_directory = get_template_directory() . '/styles'; if ( is_dir( $base_directory ) ) { $variation_files = static::recursively_iterate_json( $base_directory ); } if ( is_dir( $template_directory ) && $template_directory !== $base_directory ) { $variation_files_parent = static::recursively_iterate_json( $template_directory ); // If the child and parent variation file basename are the same, only include the child theme's. foreach ( $variation_files_parent as $parent_path => $parent ) { foreach ( $variation_files as $child_path => $child ) { if ( basename( $parent_path ) === basename( $child_path ) ) { unset( $variation_files_parent[ $parent_path ] ); } } } $variation_files = array_merge( $variation_files, $variation_files_parent ); } ksort( $variation_files ); foreach ( $variation_files as $path => $file ) { $decoded_file = self::read_json_file( $path ); if ( is_array( $decoded_file ) && static::style_variation_has_scope( $decoded_file, $scope ) ) { $translated = static::translate( $decoded_file, wp_get_theme()->get( 'TextDomain' ) ); $variation = ( new WP_Theme_JSON( $translated ) )->get_raw_data(); if ( empty( $variation['title'] ) ) { $variation['title'] = basename( $path, '.json' ); } $variations[] = $variation; } } return $variations; }History
Introduced in 6.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
6.6.0
Added configurable scope parameter to allow filtering theme.json partial files by the scope to which they can be applied e.g. theme vs block etc. Added basic caching for read theme.json partial files.from the docblock
6.2.0
Returns parent theme variations if theme is a child.from the docblock
6.0.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/class-wp-theme-json-resolver.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.