WP_Theme_JSON_Resolver::get_style_variations()
Returns the style variations defined by the theme.
Метод класса: WP_Theme_JSON_Resolver{}
Хуков нет.
Возвращает
Массив
.
Использование
$result = WP_Theme_JSON_Resolver::get_style_variations();
Список изменений
С версии 6.0.0 | Введена. |
Код WP_Theme_JSON_Resolver::get_style_variations() WP Theme JSON Resolver::get style variations WP 6.1.1
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; }