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
Version Description
6.0.0 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.