Changeset 54399 for trunk/src/wp-includes/class-wp-theme-json-resolver.php
- Timestamp:
- 10/06/2022 06:00:21 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-theme-json-resolver.php
r54298 r54399 72 72 73 73 /** 74 * `theme.json` file cache. 75 * 76 * @since 6.1.0 77 * @var array 78 */ 79 protected static $theme_json_file_cache = array(); 80 81 /** 74 82 * Processes a file that adheres to the theme.json schema 75 83 * and returns an array with its contents, or a void array if none found. 76 84 * 77 85 * @since 5.8.0 86 * @since 6.1.0 Added caching. 78 87 * 79 88 * @param string $file_path Path to file. Empty if no file. … … 81 90 */ 82 91 protected static function read_json_file( $file_path ) { 83 $config = array();84 92 if ( $file_path ) { 93 if ( array_key_exists( $file_path, static::$theme_json_file_cache ) ) { 94 return static::$theme_json_file_cache[ $file_path ]; 95 } 96 85 97 $decoded_file = wp_json_file_decode( $file_path, array( 'associative' => true ) ); 86 98 if ( is_array( $decoded_file ) ) { 87 $config = $decoded_file; 88 } 89 } 90 return $config; 99 static::$theme_json_file_cache[ $file_path ] = $decoded_file; 100 return static::$theme_json_file_cache[ $file_path ]; 101 } 102 } 103 104 return array(); 91 105 } 92 106 … … 132 146 */ 133 147 public static function get_core_data() { 134 if ( null !== static::$core ) {135 return static::$core;136 }137 138 148 $config = static::read_json_file( __DIR__ . '/theme.json' ); 139 149 $config = static::translate( $config ); 150 140 151 /** 141 152 * Filters the default data provided by WordPress for global styles & settings. … … 179 190 $options = wp_parse_args( $options, array( 'with_supports' => true ) ); 180 191 181 if ( null === static::$theme ) { 182 $theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json' ) ); 183 $theme_json_data = static::translate( $theme_json_data, wp_get_theme()->get( 'TextDomain' ) ); 184 /** 185 * Filters the data provided by the theme for global styles & settings. 186 * 187 * @since 6.1.0 188 * 189 * @param WP_Theme_JSON_Data Class to access and update the underlying data. 192 $theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json' ) ); 193 $theme_json_data = static::translate( $theme_json_data, wp_get_theme()->get( 'TextDomain' ) ); 194 195 /** 196 * Filters the data provided by the theme for global styles and settings. 197 * 198 * @since 6.1.0 199 * 200 * @param WP_Theme_JSON_Data Class to access and update the underlying data. 201 */ 202 $theme_json = apply_filters( 'theme_json_theme', new WP_Theme_JSON_Data( $theme_json_data, 'theme' ) ); 203 $theme_json_data = $theme_json->get_data(); 204 static::$theme = new WP_Theme_JSON( $theme_json_data ); 205 206 if ( wp_get_theme()->parent() ) { 207 // Get parent theme.json. 208 $parent_theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json', true ) ); 209 $parent_theme_json_data = static::translate( $parent_theme_json_data, wp_get_theme()->parent()->get( 'TextDomain' ) ); 210 $parent_theme = new WP_Theme_JSON( $parent_theme_json_data ); 211 212 /* 213 * Merge the child theme.json into the parent theme.json. 214 * The child theme takes precedence over the parent. 190 215 */ 191 $theme_json = apply_filters( 'theme_json_theme', new WP_Theme_JSON_Data( $theme_json_data, 'theme' ) ); 192 $theme_json_data = $theme_json->get_data(); 193 static::$theme = new WP_Theme_JSON( $theme_json_data ); 194 195 if ( wp_get_theme()->parent() ) { 196 // Get parent theme.json. 197 $parent_theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json', true ) ); 198 $parent_theme_json_data = static::translate( $parent_theme_json_data, wp_get_theme()->parent()->get( 'TextDomain' ) ); 199 $parent_theme = new WP_Theme_JSON( $parent_theme_json_data ); 200 201 // Merge the child theme.json into the parent theme.json. 202 // The child theme takes precedence over the parent. 203 $parent_theme->merge( static::$theme ); 204 static::$theme = $parent_theme; 205 } 216 $parent_theme->merge( static::$theme ); 217 static::$theme = $parent_theme; 206 218 } 207 219 … … 398 410 */ 399 411 public static function get_user_data() { 400 if ( null !== static::$user ) {401 return static::$user;402 }403 404 412 $config = array(); 405 413 $user_cpt = static::get_user_data_from_wp_global_styles( wp_get_theme() );
Note: See TracChangeset
for help on using the changeset viewer.