WP_Theme_JSON_Resolver::get_style_variations() WordPress Method

The WP_Theme_JSON_Resolver::get_style_variations() method is used to get an array of all available style variations for the current theme.

WP_Theme_JSON_Resolver::get_style_variations() #

Returns the style variations defined by the theme.


Return

(array)


Top ↑

Source

File: wp-includes/class-wp-theme-json-resolver.php

	public static function get_style_variations() {
		$variations     = array();
		$base_directory = get_stylesheet_directory() . '/styles';
		if ( is_dir( $base_directory ) ) {
			$nested_files      = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $base_directory ) );
			$nested_html_files = iterator_to_array( new RegexIterator( $nested_files, '/^.+\.json$/i', RecursiveRegexIterator::GET_MATCH ) );
			ksort( $nested_html_files );
			foreach ( $nested_html_files as $path => $file ) {
				$decoded_file = wp_json_file_decode( $path, array( 'associative' => true ) );
				if ( is_array( $decoded_file ) ) {
					$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;
	}


Top ↑

Changelog

Changelog
VersionDescription
6.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.