Changeset 52746
- Timestamp:
- 02/17/2022 11:13:09 AM (3 years ago)
- Location:
- branches/5.9
- Files:
-
- 3 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 -
branches/5.9/src/wp-includes/class-wp-theme-json.php
r52434 r52746 25 25 * @var array 26 26 */ 27 pr ivate$theme_json = null;27 protected $theme_json = null; 28 28 29 29 /** … … 35 35 * @var array 36 36 */ 37 pr ivatestatic $blocks_metadata = null;37 protected static $blocks_metadata = null; 38 38 39 39 /** … … 367 367 */ 368 368 public function __construct( $theme_json = array(), $origin = 'theme' ) { 369 if ( ! in_array( $origin, s elf::VALID_ORIGINS, true ) ) {369 if ( ! in_array( $origin, static::VALID_ORIGINS, true ) ) { 370 370 $origin = 'theme'; 371 371 } 372 372 373 373 $this->theme_json = WP_Theme_JSON_Schema::migrate( $theme_json ); 374 $valid_block_names = array_keys( s elf::get_blocks_metadata() );375 $valid_element_names = array_keys( s elf::ELEMENTS );376 $theme_json = s elf::sanitize( $this->theme_json, $valid_block_names, $valid_element_names );377 $this->theme_json = s elf::maybe_opt_in_into_settings( $theme_json );374 $valid_block_names = array_keys( static::get_blocks_metadata() ); 375 $valid_element_names = array_keys( static::ELEMENTS ); 376 $theme_json = static::sanitize( $this->theme_json, $valid_block_names, $valid_element_names ); 377 $this->theme_json = static::maybe_opt_in_into_settings( $theme_json ); 378 378 379 379 // Internally, presets are keyed by origin. 380 $nodes = s elf::get_setting_nodes( $this->theme_json );380 $nodes = static::get_setting_nodes( $this->theme_json ); 381 381 foreach ( $nodes as $node ) { 382 foreach ( s elf::PRESETS_METADATA as $preset_metadata ) {382 foreach ( static::PRESETS_METADATA as $preset_metadata ) { 383 383 $path = array_merge( $node['path'], $preset_metadata['path'] ); 384 384 $preset = _wp_array_get( $this->theme_json, $path, null ); … … 401 401 * @return array The modified theme.json structure. 402 402 */ 403 pr ivatestatic function maybe_opt_in_into_settings( $theme_json ) {403 protected static function maybe_opt_in_into_settings( $theme_json ) { 404 404 $new_theme_json = $theme_json; 405 405 … … 408 408 true === $new_theme_json['settings']['appearanceTools'] 409 409 ) { 410 s elf::do_opt_in_into_settings( $new_theme_json['settings'] );410 static::do_opt_in_into_settings( $new_theme_json['settings'] ); 411 411 } 412 412 … … 414 414 foreach ( $new_theme_json['settings']['blocks'] as &$block ) { 415 415 if ( isset( $block['appearanceTools'] ) && ( true === $block['appearanceTools'] ) ) { 416 s elf::do_opt_in_into_settings( $block );416 static::do_opt_in_into_settings( $block ); 417 417 } 418 418 } … … 429 429 * @param array $context The context to which the settings belong. 430 430 */ 431 pr ivatestatic function do_opt_in_into_settings( &$context ) {431 protected static function do_opt_in_into_settings( &$context ) { 432 432 $to_opt_in = array( 433 433 array( 'border', 'color' ), … … 464 464 * @return array The sanitized output. 465 465 */ 466 pr ivatestatic function sanitize( $input, $valid_block_names, $valid_element_names ) {466 protected static function sanitize( $input, $valid_block_names, $valid_element_names ) { 467 467 $output = array(); 468 468 … … 471 471 } 472 472 473 $output = array_intersect_key( $input, array_flip( s elf::VALID_TOP_LEVEL_KEYS ) );473 $output = array_intersect_key( $input, array_flip( static::VALID_TOP_LEVEL_KEYS ) ); 474 474 475 475 // Some styles are only meant to be available at the top-level (e.g.: blockGap), 476 476 // hence, the schema for blocks & elements should not have them. 477 $styles_non_top_level = s elf::VALID_STYLES;477 $styles_non_top_level = static::VALID_STYLES; 478 478 foreach ( array_keys( $styles_non_top_level ) as $section ) { 479 479 foreach ( array_keys( $styles_non_top_level[ $section ] ) as $prop ) { … … 493 493 $schema_settings_blocks = array(); 494 494 foreach ( $valid_block_names as $block ) { 495 $schema_settings_blocks[ $block ] = s elf::VALID_SETTINGS;495 $schema_settings_blocks[ $block ] = static::VALID_SETTINGS; 496 496 $schema_styles_blocks[ $block ] = $styles_non_top_level; 497 497 $schema_styles_blocks[ $block ]['elements'] = $schema_styles_elements; 498 498 } 499 $schema['styles'] = s elf::VALID_STYLES;499 $schema['styles'] = static::VALID_STYLES; 500 500 $schema['styles']['blocks'] = $schema_styles_blocks; 501 501 $schema['styles']['elements'] = $schema_styles_elements; 502 $schema['settings'] = s elf::VALID_SETTINGS;502 $schema['settings'] = static::VALID_SETTINGS; 503 503 $schema['settings']['blocks'] = $schema_settings_blocks; 504 504 … … 514 514 } 515 515 516 $result = s elf::remove_keys_not_in_schema( $input[ $subtree ], $schema[ $subtree ] );516 $result = static::remove_keys_not_in_schema( $input[ $subtree ], $schema[ $subtree ] ); 517 517 518 518 if ( empty( $result ) ) { … … 555 555 * @return array Block metadata. 556 556 */ 557 pr ivatestatic function get_blocks_metadata() {558 if ( null !== s elf::$blocks_metadata ) {559 return s elf::$blocks_metadata;560 } 561 562 s elf::$blocks_metadata = array();557 protected static function get_blocks_metadata() { 558 if ( null !== static::$blocks_metadata ) { 559 return static::$blocks_metadata; 560 } 561 562 static::$blocks_metadata = array(); 563 563 564 564 $registry = WP_Block_Type_Registry::get_instance(); … … 569 569 is_string( $block_type->supports['__experimentalSelector'] ) 570 570 ) { 571 s elf::$blocks_metadata[ $block_name ]['selector'] = $block_type->supports['__experimentalSelector'];571 static::$blocks_metadata[ $block_name ]['selector'] = $block_type->supports['__experimentalSelector']; 572 572 } else { 573 s elf::$blocks_metadata[ $block_name ]['selector'] = '.wp-block-' . str_replace( '/', '-', str_replace( 'core/', '', $block_name ) );573 static::$blocks_metadata[ $block_name ]['selector'] = '.wp-block-' . str_replace( '/', '-', str_replace( 'core/', '', $block_name ) ); 574 574 } 575 575 … … 578 578 is_string( $block_type->supports['color']['__experimentalDuotone'] ) 579 579 ) { 580 s elf::$blocks_metadata[ $block_name ]['duotone'] = $block_type->supports['color']['__experimentalDuotone'];580 static::$blocks_metadata[ $block_name ]['duotone'] = $block_type->supports['color']['__experimentalDuotone']; 581 581 } 582 582 … … 584 584 // If the block selector is compounded, will append the element to each 585 585 // individual block selector. 586 $block_selectors = explode( ',', s elf::$blocks_metadata[ $block_name ]['selector'] );587 foreach ( s elf::ELEMENTS as $el_name => $el_selector ) {586 $block_selectors = explode( ',', static::$blocks_metadata[ $block_name ]['selector'] ); 587 foreach ( static::ELEMENTS as $el_name => $el_selector ) { 588 588 $element_selector = array(); 589 589 foreach ( $block_selectors as $selector ) { 590 590 $element_selector[] = $selector . ' ' . $el_selector; 591 591 } 592 s elf::$blocks_metadata[ $block_name ]['elements'][ $el_name ] = implode( ',', $element_selector );593 } 594 } 595 596 return s elf::$blocks_metadata;592 static::$blocks_metadata[ $block_name ]['elements'][ $el_name ] = implode( ',', $element_selector ); 593 } 594 } 595 596 return static::$blocks_metadata; 597 597 } 598 598 … … 608 608 * @return array Returns the modified $tree. 609 609 */ 610 pr ivatestatic function remove_keys_not_in_schema( $tree, $schema ) {610 protected static function remove_keys_not_in_schema( $tree, $schema ) { 611 611 $tree = array_intersect_key( $tree, $schema ); 612 612 … … 617 617 618 618 if ( is_array( $schema[ $key ] ) && is_array( $tree[ $key ] ) ) { 619 $tree[ $key ] = s elf::remove_keys_not_in_schema( $tree[ $key ], $schema[ $key ] );619 $tree[ $key ] = static::remove_keys_not_in_schema( $tree[ $key ], $schema[ $key ] ); 620 620 621 621 if ( empty( $tree[ $key ] ) ) { … … 671 671 * - `styles`: only the styles section in theme.json. 672 672 * - `presets`: only the classes for the presets. 673 * @param array $origins A list of origins to include. By default it includes `self::VALID_ORIGINS`.673 * @param array $origins A list of origins to include. By default it includes VALID_ORIGINS. 674 674 * @return string Stylesheet. 675 675 */ 676 public function get_stylesheet( $types = array( 'variables', 'styles', 'presets' ), $origins = self::VALID_ORIGINS ) { 676 public function get_stylesheet( $types = array( 'variables', 'styles', 'presets' ), $origins = null ) { 677 if ( null === $origins ) { 678 $origins = static::VALID_ORIGINS; 679 } 680 677 681 if ( is_string( $types ) ) { 678 682 // Dispatch error and map old arguments to new ones. … … 687 691 } 688 692 689 $blocks_metadata = s elf::get_blocks_metadata();690 $style_nodes = s elf::get_style_nodes( $this->theme_json, $blocks_metadata );691 $setting_nodes = s elf::get_setting_nodes( $this->theme_json, $blocks_metadata );693 $blocks_metadata = static::get_blocks_metadata(); 694 $style_nodes = static::get_style_nodes( $this->theme_json, $blocks_metadata ); 695 $setting_nodes = static::get_setting_nodes( $this->theme_json, $blocks_metadata ); 692 696 693 697 $stylesheet = ''; … … 776 780 * @return string The new stylesheet. 777 781 */ 778 pr ivatefunction get_block_classes( $style_nodes ) {782 protected function get_block_classes( $style_nodes ) { 779 783 $block_rules = ''; 780 784 … … 787 791 $selector = $metadata['selector']; 788 792 $settings = _wp_array_get( $this->theme_json, array( 'settings' ) ); 789 $declarations = s elf::compute_style_properties( $node, $settings );793 $declarations = static::compute_style_properties( $node, $settings ); 790 794 791 795 // 1. Separate the ones who use the general selector … … 807 811 * @link https://github.com/WordPress/gutenberg/issues/36147. 808 812 */ 809 if ( s elf::ROOT_BLOCK_SELECTOR === $selector ) {813 if ( static::ROOT_BLOCK_SELECTOR === $selector ) { 810 814 $block_rules .= 'body { margin: 0; }'; 811 815 } 812 816 813 817 // 2. Generate the rules that use the general selector. 814 $block_rules .= s elf::to_ruleset( $selector, $declarations );818 $block_rules .= static::to_ruleset( $selector, $declarations ); 815 819 816 820 // 3. Generate the rules that use the duotone selector. 817 821 if ( isset( $metadata['duotone'] ) && ! empty( $declarations_duotone ) ) { 818 $selector_duotone = s elf::scope_selector( $metadata['selector'], $metadata['duotone'] );819 $block_rules .= s elf::to_ruleset( $selector_duotone, $declarations_duotone );820 } 821 822 if ( s elf::ROOT_BLOCK_SELECTOR === $selector ) {822 $selector_duotone = static::scope_selector( $metadata['selector'], $metadata['duotone'] ); 823 $block_rules .= static::to_ruleset( $selector_duotone, $declarations_duotone ); 824 } 825 826 if ( static::ROOT_BLOCK_SELECTOR === $selector ) { 823 827 $block_rules .= '.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }'; 824 828 $block_rules .= '.wp-site-blocks > .alignright { float: right; margin-left: 2em; }'; … … 865 869 * @return string The new stylesheet. 866 870 */ 867 pr ivatefunction get_preset_classes( $setting_nodes, $origins ) {871 protected function get_preset_classes( $setting_nodes, $origins ) { 868 872 $preset_rules = ''; 869 873 … … 875 879 $selector = $metadata['selector']; 876 880 $node = _wp_array_get( $this->theme_json, $metadata['path'], array() ); 877 $preset_rules .= s elf::compute_preset_classes( $node, $selector, $origins );881 $preset_rules .= static::compute_preset_classes( $node, $selector, $origins ); 878 882 } 879 883 … … 902 906 * @return string The new stylesheet. 903 907 */ 904 pr ivatefunction get_css_variables( $nodes, $origins ) {908 protected function get_css_variables( $nodes, $origins ) { 905 909 $stylesheet = ''; 906 910 foreach ( $nodes as $metadata ) { … … 912 916 913 917 $node = _wp_array_get( $this->theme_json, $metadata['path'], array() ); 914 $declarations = array_merge( s elf::compute_preset_vars( $node, $origins ), self::compute_theme_vars( $node ) );915 916 $stylesheet .= s elf::to_ruleset( $selector, $declarations );918 $declarations = array_merge( static::compute_preset_vars( $node, $origins ), static::compute_theme_vars( $node ) ); 919 920 $stylesheet .= static::to_ruleset( $selector, $declarations ); 917 921 } 918 922 … … 930 934 * @return string CSS ruleset. 931 935 */ 932 pr ivatestatic function to_ruleset( $selector, $declarations ) {936 protected static function to_ruleset( $selector, $declarations ) { 933 937 if ( empty( $declarations ) ) { 934 938 return ''; … … 958 962 * @return string 959 963 */ 960 pr ivatestatic function append_to_selector( $selector, $to_append ) {964 protected static function append_to_selector( $selector, $to_append ) { 961 965 $new_selectors = array(); 962 966 $selectors = explode( ',', $selector ); … … 980 984 * @return string The result of processing the presets. 981 985 */ 982 pr ivatestatic function compute_preset_classes( $settings, $selector, $origins ) {983 if ( s elf::ROOT_BLOCK_SELECTOR === $selector ) {986 protected static function compute_preset_classes( $settings, $selector, $origins ) { 987 if ( static::ROOT_BLOCK_SELECTOR === $selector ) { 984 988 // Classes at the global level do not need any CSS prefixed, 985 989 // and we don't want to increase its specificity. … … 988 992 989 993 $stylesheet = ''; 990 foreach ( s elf::PRESETS_METADATA as $preset_metadata ) {991 $slugs = s elf::get_settings_slugs( $settings, $preset_metadata, $origins );994 foreach ( static::PRESETS_METADATA as $preset_metadata ) { 995 $slugs = static::get_settings_slugs( $settings, $preset_metadata, $origins ); 992 996 foreach ( $preset_metadata['classes'] as $class => $property ) { 993 997 foreach ( $slugs as $slug ) { 994 $css_var = s elf::replace_slug_in_string( $preset_metadata['css_vars'], $slug );995 $class_name = s elf::replace_slug_in_string( $class, $slug );996 $stylesheet .= s elf::to_ruleset(997 s elf::append_to_selector( $selector, $class_name ),998 $css_var = static::replace_slug_in_string( $preset_metadata['css_vars'], $slug ); 999 $class_name = static::replace_slug_in_string( $class, $slug ); 1000 $stylesheet .= static::to_ruleset( 1001 static::append_to_selector( $selector, $class_name ), 998 1002 array( 999 1003 array( … … 1027 1031 * @return string Scoped selector. 1028 1032 */ 1029 pr ivatestatic function scope_selector( $scope, $selector ) {1033 protected static function scope_selector( $scope, $selector ) { 1030 1034 $scopes = explode( ',', $scope ); 1031 1035 $selectors = explode( ',', $selector ); … … 1077 1081 * @return array Array of presets where each key is a slug and each value is the preset value. 1078 1082 */ 1079 pr ivatestatic function get_settings_values_by_slug( $settings, $preset_metadata, $origins ) {1083 protected static function get_settings_values_by_slug( $settings, $preset_metadata, $origins ) { 1080 1084 $preset_per_origin = _wp_array_get( $settings, $preset_metadata['path'], array() ); 1081 1085 … … 1119 1123 * @return array Array of presets where the key and value are both the slug. 1120 1124 */ 1121 private static function get_settings_slugs( $settings, $preset_metadata, $origins = self::VALID_ORIGINS ) { 1125 protected static function get_settings_slugs( $settings, $preset_metadata, $origins = null ) { 1126 if ( null === $origins ) { 1127 $origins = static::VALID_ORIGINS; 1128 } 1129 1122 1130 $preset_per_origin = _wp_array_get( $settings, $preset_metadata['path'], array() ); 1123 1131 … … 1146 1154 * @return string The CSS Custom Property. Something along the lines of `--wp--preset--color--black`. 1147 1155 */ 1148 pr ivatestatic function replace_slug_in_string( $input, $slug ) {1156 protected static function replace_slug_in_string( $input, $slug ) { 1149 1157 return strtr( $input, array( '$slug' => $slug ) ); 1150 1158 } … … 1167 1175 * @return array Returns the modified $declarations. 1168 1176 */ 1169 pr ivatestatic function compute_preset_vars( $settings, $origins ) {1177 protected static function compute_preset_vars( $settings, $origins ) { 1170 1178 $declarations = array(); 1171 foreach ( s elf::PRESETS_METADATA as $preset_metadata ) {1172 $values_by_slug = s elf::get_settings_values_by_slug( $settings, $preset_metadata, $origins );1179 foreach ( static::PRESETS_METADATA as $preset_metadata ) { 1180 $values_by_slug = static::get_settings_values_by_slug( $settings, $preset_metadata, $origins ); 1173 1181 foreach ( $values_by_slug as $slug => $value ) { 1174 1182 $declarations[] = array( 1175 'name' => s elf::replace_slug_in_string( $preset_metadata['css_vars'], $slug ),1183 'name' => static::replace_slug_in_string( $preset_metadata['css_vars'], $slug ), 1176 1184 'value' => $value, 1177 1185 ); … … 1197 1205 * @return array Returns the modified $declarations. 1198 1206 */ 1199 pr ivatestatic function compute_theme_vars( $settings ) {1207 protected static function compute_theme_vars( $settings ) { 1200 1208 $declarations = array(); 1201 1209 $custom_values = _wp_array_get( $settings, array( 'custom' ), array() ); 1202 $css_vars = s elf::flatten_tree( $custom_values );1210 $css_vars = static::flatten_tree( $custom_values ); 1203 1211 foreach ( $css_vars as $key => $value ) { 1204 1212 $declarations[] = array( … … 1248 1256 * @return array The flattened tree. 1249 1257 */ 1250 pr ivatestatic function flatten_tree( $tree, $prefix = '', $token = '--' ) {1258 protected static function flatten_tree( $tree, $prefix = '', $token = '--' ) { 1251 1259 $result = array(); 1252 1260 foreach ( $tree as $property => $value ) { … … 1261 1269 $result = array_merge( 1262 1270 $result, 1263 s elf::flatten_tree( $value, $new_prefix, $token )1271 static::flatten_tree( $value, $new_prefix, $token ) 1264 1272 ); 1265 1273 } else { … … 1287 1295 * @return array Returns the modified $declarations. 1288 1296 */ 1289 private static function compute_style_properties( $styles, $settings = array(), $properties = self::PROPERTIES_METADATA ) { 1297 protected static function compute_style_properties( $styles, $settings = array(), $properties = null ) { 1298 if ( null === $properties ) { 1299 $properties = static::PROPERTIES_METADATA; 1300 } 1301 1290 1302 $declarations = array(); 1291 1303 if ( empty( $styles ) ) { … … 1294 1306 1295 1307 foreach ( $properties as $css_property => $value_path ) { 1296 $value = s elf::get_property_value( $styles, $value_path );1308 $value = static::get_property_value( $styles, $value_path ); 1297 1309 1298 1310 // Look up protected properties, keyed by value path. … … 1301 1313 $path_string = implode( '.', $value_path ); 1302 1314 if ( 1303 array_key_exists( $path_string, s elf::PROTECTED_PROPERTIES ) &&1304 _wp_array_get( $settings, s elf::PROTECTED_PROPERTIES[ $path_string ], null ) === null1315 array_key_exists( $path_string, static::PROTECTED_PROPERTIES ) && 1316 _wp_array_get( $settings, static::PROTECTED_PROPERTIES[ $path_string ], null ) === null 1305 1317 ) { 1306 1318 continue; … … 1337 1349 * @return string|array Style property value. 1338 1350 */ 1339 pr ivatestatic function get_property_value( $styles, $path ) {1351 protected static function get_property_value( $styles, $path ) { 1340 1352 $value = _wp_array_get( $styles, $path, '' ); 1341 1353 … … 1380 1392 * @return array 1381 1393 */ 1382 pr ivatestatic function get_setting_nodes( $theme_json, $selectors = array() ) {1394 protected static function get_setting_nodes( $theme_json, $selectors = array() ) { 1383 1395 $nodes = array(); 1384 1396 if ( ! isset( $theme_json['settings'] ) ) { … … 1389 1401 $nodes[] = array( 1390 1402 'path' => array( 'settings' ), 1391 'selector' => s elf::ROOT_BLOCK_SELECTOR,1403 'selector' => static::ROOT_BLOCK_SELECTOR, 1392 1404 ); 1393 1405 … … 1434 1446 * @return array 1435 1447 */ 1436 pr ivatestatic function get_style_nodes( $theme_json, $selectors = array() ) {1448 protected static function get_style_nodes( $theme_json, $selectors = array() ) { 1437 1449 $nodes = array(); 1438 1450 if ( ! isset( $theme_json['styles'] ) ) { … … 1443 1455 $nodes[] = array( 1444 1456 'path' => array( 'styles' ), 1445 'selector' => s elf::ROOT_BLOCK_SELECTOR,1457 'selector' => static::ROOT_BLOCK_SELECTOR, 1446 1458 ); 1447 1459 … … 1450 1462 $nodes[] = array( 1451 1463 'path' => array( 'styles', 'elements', $element ), 1452 'selector' => s elf::ELEMENTS[ $element ],1464 'selector' => static::ELEMENTS[ $element ], 1453 1465 ); 1454 1466 } … … 1524 1536 * we remove it from the theme presets. 1525 1537 */ 1526 $nodes = s elf::get_setting_nodes( $incoming_data );1527 $slugs_global = s elf::get_default_slugs( $this->theme_json, array( 'settings' ) );1538 $nodes = static::get_setting_nodes( $incoming_data ); 1539 $slugs_global = static::get_default_slugs( $this->theme_json, array( 'settings' ) ); 1528 1540 foreach ( $nodes as $node ) { 1529 $slugs_node = s elf::get_default_slugs( $this->theme_json, $node['path'] );1541 $slugs_node = static::get_default_slugs( $this->theme_json, $node['path'] ); 1530 1542 $slugs = array_merge_recursive( $slugs_global, $slugs_node ); 1531 1543 … … 1538 1550 1539 1551 // Replace the presets. 1540 foreach ( s elf::PRESETS_METADATA as $preset ) {1541 $override_preset = s elf::should_override_preset( $this->theme_json, $node['path'], $preset['override'] );1542 1543 foreach ( s elf::VALID_ORIGINS as $origin ) {1552 foreach ( static::PRESETS_METADATA as $preset ) { 1553 $override_preset = static::should_override_preset( $this->theme_json, $node['path'], $preset['override'] ); 1554 1555 foreach ( static::VALID_ORIGINS as $origin ) { 1544 1556 $base_path = array_merge( $node['path'], $preset['path'] ); 1545 1557 $path = array_merge( $base_path, array( $origin ) ); … … 1552 1564 foreach ( $content as &$item ) { 1553 1565 if ( ! array_key_exists( 'name', $item ) ) { 1554 $name = s elf::get_name_from_defaults( $item['slug'], $base_path );1566 $name = static::get_name_from_defaults( $item['slug'], $base_path ); 1555 1567 if ( null !== $name ) { 1556 1568 $item['name'] = $name; … … 1567 1579 } else { 1568 1580 $slugs_for_preset = _wp_array_get( $slugs, $preset['path'], array() ); 1569 $content = s elf::filter_slugs( $content, $slugs_for_preset );1581 $content = static::filter_slugs( $content, $slugs_for_preset ); 1570 1582 _wp_array_set( $this->theme_json, $path, $content ); 1571 1583 } … … 1585 1597 * @return boolean 1586 1598 */ 1587 pr ivatestatic function should_override_preset( $theme_json, $path, $override ) {1599 protected static function should_override_preset( $theme_json, $path, $override ) { 1588 1600 if ( is_bool( $override ) ) { 1589 1601 return $override; … … 1637 1649 * @return array 1638 1650 */ 1639 pr ivatestatic function get_default_slugs( $data, $node_path ) {1651 protected static function get_default_slugs( $data, $node_path ) { 1640 1652 $slugs = array(); 1641 1653 1642 foreach ( s elf::PRESETS_METADATA as $metadata ) {1654 foreach ( static::PRESETS_METADATA as $metadata ) { 1643 1655 $path = array_merge( $node_path, $metadata['path'], array( 'default' ) ); 1644 1656 $preset = _wp_array_get( $data, $path, null ); … … 1669 1681 * @return string|null 1670 1682 */ 1671 pr ivatefunction get_name_from_defaults( $slug, $base_path ) {1683 protected function get_name_from_defaults( $slug, $base_path ) { 1672 1684 $path = array_merge( $base_path, array( 'default' ) ); 1673 1685 $default_content = _wp_array_get( $this->theme_json, $path, null ); … … 1692 1704 * @return array The new node. 1693 1705 */ 1694 pr ivatestatic function filter_slugs( $node, $slugs ) {1706 protected static function filter_slugs( $node, $slugs ) { 1695 1707 if ( empty( $slugs ) ) { 1696 1708 return $node; … … 1720 1732 $theme_json = WP_Theme_JSON_Schema::migrate( $theme_json ); 1721 1733 1722 $valid_block_names = array_keys( s elf::get_blocks_metadata() );1723 $valid_element_names = array_keys( s elf::ELEMENTS );1724 $theme_json = s elf::sanitize( $theme_json, $valid_block_names, $valid_element_names );1725 1726 $blocks_metadata = s elf::get_blocks_metadata();1727 $style_nodes = s elf::get_style_nodes( $theme_json, $blocks_metadata );1734 $valid_block_names = array_keys( static::get_blocks_metadata() ); 1735 $valid_element_names = array_keys( static::ELEMENTS ); 1736 $theme_json = static::sanitize( $theme_json, $valid_block_names, $valid_element_names ); 1737 1738 $blocks_metadata = static::get_blocks_metadata(); 1739 $style_nodes = static::get_style_nodes( $theme_json, $blocks_metadata ); 1728 1740 foreach ( $style_nodes as $metadata ) { 1729 1741 $input = _wp_array_get( $theme_json, $metadata['path'], array() ); … … 1732 1744 } 1733 1745 1734 $output = s elf::remove_insecure_styles( $input );1746 $output = static::remove_insecure_styles( $input ); 1735 1747 if ( ! empty( $output ) ) { 1736 1748 _wp_array_set( $sanitized, $metadata['path'], $output ); … … 1738 1750 } 1739 1751 1740 $setting_nodes = s elf::get_setting_nodes( $theme_json );1752 $setting_nodes = static::get_setting_nodes( $theme_json ); 1741 1753 foreach ( $setting_nodes as $metadata ) { 1742 1754 $input = _wp_array_get( $theme_json, $metadata['path'], array() ); … … 1745 1757 } 1746 1758 1747 $output = s elf::remove_insecure_settings( $input );1759 $output = static::remove_insecure_settings( $input ); 1748 1760 if ( ! empty( $output ) ) { 1749 1761 _wp_array_set( $sanitized, $metadata['path'], $output ); … … 1775 1787 * @return array 1776 1788 */ 1777 pr ivatestatic function remove_insecure_settings( $input ) {1789 protected static function remove_insecure_settings( $input ) { 1778 1790 $output = array(); 1779 foreach ( s elf::PRESETS_METADATA as $preset_metadata ) {1780 foreach ( s elf::VALID_ORIGINS as $origin ) {1791 foreach ( static::PRESETS_METADATA as $preset_metadata ) { 1792 foreach ( static::VALID_ORIGINS as $origin ) { 1781 1793 $path_with_origin = array_merge( $preset_metadata['path'], array( $origin ) ); 1782 1794 $presets = _wp_array_get( $input, $path_with_origin, null ); … … 1803 1815 $preset_is_valid = true; 1804 1816 foreach ( $preset_metadata['properties'] as $property ) { 1805 if ( ! s elf::is_safe_css_declaration( $property, $value ) ) {1817 if ( ! static::is_safe_css_declaration( $property, $value ) ) { 1806 1818 $preset_is_valid = false; 1807 1819 break; … … 1832 1844 * @return array 1833 1845 */ 1834 pr ivatestatic function remove_insecure_styles( $input ) {1846 protected static function remove_insecure_styles( $input ) { 1835 1847 $output = array(); 1836 $declarations = s elf::compute_style_properties( $input );1848 $declarations = static::compute_style_properties( $input ); 1837 1849 1838 1850 foreach ( $declarations as $declaration ) { 1839 if ( s elf::is_safe_css_declaration( $declaration['name'], $declaration['value'] ) ) {1840 $path = s elf::PROPERTIES_METADATA[ $declaration['name'] ];1851 if ( static::is_safe_css_declaration( $declaration['name'], $declaration['value'] ) ) { 1852 $path = static::PROPERTIES_METADATA[ $declaration['name'] ]; 1841 1853 1842 1854 // Check the value isn't an array before adding so as to not … … 1860 1872 * @return bool 1861 1873 */ 1862 pr ivatestatic function is_safe_css_declaration( $property_name, $property_value ) {1874 protected static function is_safe_css_declaration( $property_name, $property_value ) { 1863 1875 $style_to_validate = $property_name . ': ' . $property_value; 1864 1876 $filtered = esc_html( safecss_filter_attr( $style_to_validate ) ); … … 1888 1900 public static function get_from_editor_settings( $settings ) { 1889 1901 $theme_settings = array( 1890 'version' => s elf::LATEST_SCHEMA,1902 'version' => static::LATEST_SCHEMA, 1891 1903 'settings' => array(), 1892 1904 );
Note: See TracChangeset
for help on using the changeset viewer.