Changeset 58797 for trunk/src/wp-includes/class-wp-theme-json-resolver.php
- Timestamp:
- 07/24/2024 12:24:31 AM (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-theme-json-resolver.php
r58468 r58797 849 849 * 850 850 * @since 6.6.0 851 * @since 6.7.0 Resolve relative paths in block styles. 851 852 * 852 853 * @param WP_Theme_JSON $theme_json A theme json instance. … … 861 862 862 863 $theme_json_data = $theme_json->get_raw_data(); 863 864 // Top level styles.865 $background_image_url = isset( $theme_json_data['styles']['background']['backgroundImage']['url'] ) ? $theme_json_data['styles']['background']['backgroundImage']['url'] : null;866 867 864 /* 868 865 * The same file convention when registering web fonts. … … 870 867 */ 871 868 $placeholder = 'file:./'; 869 870 // Top level styles. 871 $background_image_url = $theme_json_data['styles']['background']['backgroundImage']['url'] ?? null; 872 872 if ( 873 873 isset( $background_image_url ) && … … 889 889 } 890 890 891 // Block styles. 892 if ( ! empty( $theme_json_data['styles']['blocks'] ) ) { 893 foreach ( $theme_json_data['styles']['blocks'] as $block_name => $block_styles ) { 894 if ( ! isset( $block_styles['background']['backgroundImage']['url'] ) ) { 895 continue; 896 } 897 $background_image_url = $block_styles['background']['backgroundImage']['url']; 898 if ( 899 is_string( $background_image_url ) && 900 // Skip if the src doesn't start with the placeholder, as there's nothing to replace. 901 str_starts_with( $background_image_url, $placeholder ) 902 ) { 903 $file_type = wp_check_filetype( $background_image_url ); 904 $src_url = str_replace( $placeholder, '', $background_image_url ); 905 $resolved_theme_uri = array( 906 'name' => $background_image_url, 907 'href' => sanitize_url( get_theme_file_uri( $src_url ) ), 908 'target' => "styles.blocks.{$block_name}.background.backgroundImage.url", 909 ); 910 if ( isset( $file_type['type'] ) ) { 911 $resolved_theme_uri['type'] = $file_type['type']; 912 } 913 $resolved_theme_uris[] = $resolved_theme_uri; 914 } 915 } 916 } 917 891 918 return $resolved_theme_uris; 892 919 }
Note: See TracChangeset
for help on using the changeset viewer.