- Timestamp:
- 02/17/2022 11:13:09 AM (3 years ago)
- Location:
- branches/5.9
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.9
-
branches/5.9/src/wp-includes/class-wp-theme-json-resolver.php
r52372 r52746 26 26 * @var WP_Theme_JSON 27 27 */ 28 pr ivatestatic $core = null;28 protected static $core = null; 29 29 30 30 /** … … 34 34 * @var WP_Theme_JSON 35 35 */ 36 pr ivatestatic $theme = null;36 protected static $theme = null; 37 37 38 38 /** … … 42 42 * @var bool 43 43 */ 44 pr ivatestatic $theme_has_support = null;44 protected static $theme_has_support = null; 45 45 46 46 /** … … 50 50 * @var WP_Theme_JSON 51 51 */ 52 pr ivatestatic $user = null;52 protected static $user = null; 53 53 54 54 /** … … 59 59 * @var int 60 60 */ 61 pr ivatestatic $user_custom_post_type_id = null;61 protected static $user_custom_post_type_id = null; 62 62 63 63 /** … … 68 68 * @var array 69 69 */ 70 pr ivatestatic $i18n_schema = null;70 protected static $i18n_schema = null; 71 71 72 72 /** … … 79 79 * @return array Contents that adhere to the theme.json schema. 80 80 */ 81 pr ivatestatic function read_json_file( $file_path ) {81 protected static function read_json_file( $file_path ) { 82 82 $config = array(); 83 83 if ( $file_path ) { … … 114 114 * @return array Returns the modified $theme_json_structure. 115 115 */ 116 pr ivatestatic function translate( $theme_json, $domain = 'default' ) {117 if ( null === s elf::$i18n_schema ) {118 $i18n_schema = wp_json_file_decode( __DIR__ . '/theme-i18n.json' );119 s elf::$i18n_schema = null === $i18n_schema ? array() : $i18n_schema;120 } 121 122 return translate_settings_using_i18n_schema( s elf::$i18n_schema, $theme_json, $domain );116 protected static function translate( $theme_json, $domain = 'default' ) { 117 if ( null === static::$i18n_schema ) { 118 $i18n_schema = wp_json_file_decode( __DIR__ . '/theme-i18n.json' ); 119 static::$i18n_schema = null === $i18n_schema ? array() : $i18n_schema; 120 } 121 122 return translate_settings_using_i18n_schema( static::$i18n_schema, $theme_json, $domain ); 123 123 } 124 124 … … 131 131 */ 132 132 public static function get_core_data() { 133 if ( null !== s elf::$core ) {134 return s elf::$core;135 } 136 137 $config = self::read_json_file( __DIR__ . '/theme.json' );138 $config = self::translate( $config );139 s elf::$core = new WP_Theme_JSON( $config, 'default' );140 141 return s elf::$core;133 if ( null !== static::$core ) { 134 return static::$core; 135 } 136 137 $config = static::read_json_file( __DIR__ . '/theme.json' ); 138 $config = static::translate( $config ); 139 static::$core = new WP_Theme_JSON( $config, 'default' ); 140 141 return static::$core; 142 142 } 143 143 … … 160 160 _deprecated_argument( __METHOD__, '5.9.0' ); 161 161 } 162 if ( null === s elf::$theme ) {163 $theme_json_data = s elf::read_json_file( self::get_file_path_from_theme( 'theme.json' ) );164 $theme_json_data = s elf::translate( $theme_json_data, wp_get_theme()->get( 'TextDomain' ) );165 s elf::$theme= new WP_Theme_JSON( $theme_json_data );162 if ( null === static::$theme ) { 163 $theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json' ) ); 164 $theme_json_data = static::translate( $theme_json_data, wp_get_theme()->get( 'TextDomain' ) ); 165 static::$theme = new WP_Theme_JSON( $theme_json_data ); 166 166 167 167 if ( wp_get_theme()->parent() ) { 168 168 // Get parent theme.json. 169 $parent_theme_json_data = s elf::read_json_file( self::get_file_path_from_theme( 'theme.json', true ) );170 $parent_theme_json_data = s elf::translate( $parent_theme_json_data, wp_get_theme()->parent()->get( 'TextDomain' ) );169 $parent_theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json', true ) ); 170 $parent_theme_json_data = static::translate( $parent_theme_json_data, wp_get_theme()->parent()->get( 'TextDomain' ) ); 171 171 $parent_theme = new WP_Theme_JSON( $parent_theme_json_data ); 172 172 173 173 // Merge the child theme.json into the parent theme.json. 174 174 // The child theme takes precedence over the parent. 175 $parent_theme->merge( s elf::$theme );176 s elf::$theme = $parent_theme;175 $parent_theme->merge( static::$theme ); 176 static::$theme = $parent_theme; 177 177 } 178 178 } … … 182 182 * to override the ones declared via theme supports. 183 183 * So we take theme supports, transform it to theme.json shape 184 * and merge the s elf::$theme upon that.184 * and merge the static::$theme upon that. 185 185 */ 186 186 $theme_support_data = WP_Theme_JSON::get_from_editor_settings( get_default_block_editor_settings() ); 187 if ( ! s elf::theme_has_support() ) {187 if ( ! static::theme_has_support() ) { 188 188 if ( ! isset( $theme_support_data['settings']['color'] ) ) { 189 189 $theme_support_data['settings']['color'] = array(); … … 211 211 } 212 212 $with_theme_supports = new WP_Theme_JSON( $theme_support_data ); 213 $with_theme_supports->merge( s elf::$theme );213 $with_theme_supports->merge( static::$theme ); 214 214 215 215 return $with_theme_supports; … … 300 300 */ 301 301 public static function get_user_data() { 302 if ( null !== s elf::$user ) {303 return s elf::$user;302 if ( null !== static::$user ) { 303 return static::$user; 304 304 } 305 305 306 306 $config = array(); 307 $user_cpt = s elf::get_user_data_from_wp_global_styles( wp_get_theme() );307 $user_cpt = static::get_user_data_from_wp_global_styles( wp_get_theme() ); 308 308 309 309 if ( array_key_exists( 'post_content', $user_cpt ) ) { … … 327 327 } 328 328 } 329 s elf::$user = new WP_Theme_JSON( $config, 'custom' );330 331 return s elf::$user;329 static::$user = new WP_Theme_JSON( $config, 'custom' ); 330 331 return static::$user; 332 332 } 333 333 … … 364 364 365 365 $result = new WP_Theme_JSON(); 366 $result->merge( s elf::get_core_data() );367 $result->merge( s elf::get_theme_data() );366 $result->merge( static::get_core_data() ); 367 $result->merge( static::get_theme_data() ); 368 368 369 369 if ( 'custom' === $origin ) { 370 $result->merge( s elf::get_user_data() );370 $result->merge( static::get_user_data() ); 371 371 } 372 372 … … 383 383 */ 384 384 public static function get_user_global_styles_post_id() { 385 if ( null !== s elf::$user_custom_post_type_id ) {386 return s elf::$user_custom_post_type_id;387 } 388 389 $user_cpt = s elf::get_user_data_from_wp_global_styles( wp_get_theme(), true );385 if ( null !== static::$user_custom_post_type_id ) { 386 return static::$user_custom_post_type_id; 387 } 388 389 $user_cpt = static::get_user_data_from_wp_global_styles( wp_get_theme(), true ); 390 390 391 391 if ( array_key_exists( 'ID', $user_cpt ) ) { 392 s elf::$user_custom_post_type_id = $user_cpt['ID'];393 } 394 395 return s elf::$user_custom_post_type_id;392 static::$user_custom_post_type_id = $user_cpt['ID']; 393 } 394 395 return static::$user_custom_post_type_id; 396 396 } 397 397 … … 405 405 */ 406 406 public static function theme_has_support() { 407 if ( ! isset( s elf::$theme_has_support ) ) {408 s elf::$theme_has_support = (409 is_readable( s elf::get_file_path_from_theme( 'theme.json' ) ) ||410 is_readable( s elf::get_file_path_from_theme( 'theme.json', true ) )407 if ( ! isset( static::$theme_has_support ) ) { 408 static::$theme_has_support = ( 409 is_readable( static::get_file_path_from_theme( 'theme.json' ) ) || 410 is_readable( static::get_file_path_from_theme( 'theme.json', true ) ) 411 411 ); 412 412 } 413 413 414 return s elf::$theme_has_support;414 return static::$theme_has_support; 415 415 } 416 416 … … 427 427 * @return string The whole file path or empty if the file doesn't exist. 428 428 */ 429 pr ivatestatic function get_file_path_from_theme( $file_name, $template = false ) {429 protected static function get_file_path_from_theme( $file_name, $template = false ) { 430 430 $path = $template ? get_template_directory() : get_stylesheet_directory(); 431 431 $candidate = $path . '/' . $file_name; … … 442 442 */ 443 443 public static function clean_cached_data() { 444 s elf::$core = null;445 s elf::$theme = null;446 s elf::$user = null;447 s elf::$user_custom_post_type_id = null;448 s elf::$theme_has_support = null;449 s elf::$i18n_schema = null;444 static::$core = null; 445 static::$theme = null; 446 static::$user = null; 447 static::$user_custom_post_type_id = null; 448 static::$theme_has_support = null; 449 static::$i18n_schema = null; 450 450 } 451 451
Note: See TracChangeset
for help on using the changeset viewer.