Changeset 58264 for trunk/src/wp-includes/class-wp-theme-json-resolver.php
- Timestamp:
- 05/31/2024 05:47:23 AM (6 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-theme-json-resolver.php
r58263 r58264 702 702 } 703 703 704 /** 705 * Determines if a supplied style variation matches the provided scope. 706 * 707 * For backwards compatibility, if a variation does not define any scope 708 * related property, e.g. `blockTypes`, it is assumed to be a theme style 709 * variation. 710 * 711 * @since 6.6.0 712 * 713 * @param array $variation Theme.json shaped style variation object. 714 * @param string $scope Scope to check e.g. theme, block etc. 715 * 716 * @return boolean 717 */ 718 private static function style_variation_has_scope( $variation, $scope ) { 719 if ( 'block' === $scope ) { 720 return isset( $variation['blockTypes'] ); 721 } 722 723 if ( 'theme' === $scope ) { 724 return ! isset( $variation['blockTypes'] ); 725 } 726 727 return false; 728 } 704 729 705 730 /** … … 708 733 * @since 6.0.0 709 734 * @since 6.2.0 Returns parent theme variations if theme is a child. 735 * @since 6.6.0 Added configurable scope parameter to allow filtering 736 * theme.json partial files by the scope to which they 737 * can be applied e.g. theme vs block etc. 738 * 739 * @param string $scope The scope or type of style variation to retrieve e.g. theme, block etc. 710 740 * 711 741 * @return array 712 742 */ 713 public static function get_style_variations( ) {743 public static function get_style_variations( $scope = 'theme' ) { 714 744 $variation_files = array(); 715 745 $variations = array(); … … 734 764 foreach ( $variation_files as $path => $file ) { 735 765 $decoded_file = wp_json_file_decode( $path, array( 'associative' => true ) ); 736 if ( is_array( $decoded_file ) ) {766 if ( is_array( $decoded_file ) && static::style_variation_has_scope( $decoded_file, $scope ) ) { 737 767 $translated = static::translate( $decoded_file, wp_get_theme()->get( 'TextDomain' ) ); 738 768 $variation = ( new WP_Theme_JSON( $translated ) )->get_raw_data();
Note: See TracChangeset
for help on using the changeset viewer.