Changeset 58797
- Timestamp:
- 07/24/2024 12:24:31 AM (17 months ago)
- Location:
- trunk
- Files:
-
- 6 edited
-
src/wp-includes/block-supports/background.php (modified) (1 diff)
-
src/wp-includes/class-wp-theme-json-resolver.php (modified) (4 diffs)
-
src/wp-includes/class-wp-theme-json.php (modified) (1 diff)
-
src/wp-includes/global-styles-and-settings.php (modified) (2 diffs)
-
tests/phpunit/tests/theme/wpThemeJson.php (modified) (2 diffs)
-
tests/phpunit/tests/theme/wpThemeJsonResolver.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-supports/background.php
r58222 r58797 63 63 } 64 64 65 $background_styles = array(); 66 $background_styles['backgroundImage'] = isset( $block_attributes['style']['background']['backgroundImage'] ) ? $block_attributes['style']['background']['backgroundImage'] : array(); 65 $background_styles = array(); 66 $background_styles['backgroundImage'] = $block_attributes['style']['background']['backgroundImage'] ?? null; 67 $background_styles['backgroundSize'] = $block_attributes['style']['background']['backgroundSize'] ?? null; 68 $background_styles['backgroundPosition'] = $block_attributes['style']['background']['backgroundPosition'] ?? null; 69 $background_styles['backgroundRepeat'] = $block_attributes['style']['background']['backgroundRepeat'] ?? null; 67 70 68 71 if ( ! empty( $background_styles['backgroundImage'] ) ) { 69 $background_styles['backgroundSize'] = isset( $block_attributes['style']['background']['backgroundSize'] ) ? $block_attributes['style']['background']['backgroundSize'] : 'cover'; 70 $background_styles['backgroundPosition'] = isset( $block_attributes['style']['background']['backgroundPosition'] ) ? $block_attributes['style']['background']['backgroundPosition'] : null; 71 $background_styles['backgroundRepeat'] = isset( $block_attributes['style']['background']['backgroundRepeat'] ) ? $block_attributes['style']['background']['backgroundRepeat'] : null; 72 $background_styles['backgroundSize'] = $background_styles['backgroundSize'] ?? 'cover'; 72 73 73 74 // If the background size is set to `contain` and no position is set, set the position to `center`. -
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 } -
trunk/src/wp-includes/class-wp-theme-json.php
r58749 r58797 521 521 const VALID_STYLES = array( 522 522 'background' => array( 523 'backgroundImage' => 'top',524 'backgroundPosition' => 'top',525 'backgroundRepeat' => 'top',526 'backgroundSize' => 'top',523 'backgroundImage' => null, 524 'backgroundPosition' => null, 525 'backgroundRepeat' => null, 526 'backgroundSize' => null, 527 527 ), 528 528 'border' => array( -
trunk/src/wp-includes/global-styles-and-settings.php
r58710 r58797 248 248 * 249 249 * @since 6.1.0 250 * @since 6.7.0 Resolve relative paths in block styles. 250 251 * 251 252 * @global WP_Styles $wp_styles … … 255 256 256 257 $tree = WP_Theme_JSON_Resolver::get_merged_data(); 258 $tree = WP_Theme_JSON_Resolver::resolve_theme_file_uris( $tree ); 257 259 $block_nodes = $tree->get_styles_block_nodes(); 258 260 foreach ( $block_nodes as $metadata ) { -
trunk/tests/phpunit/tests/theme/wpThemeJson.php
r58749 r58797 5022 5022 5023 5023 $expected_styles = "html{min-height: calc(100% - var(--wp-admin--admin-bar--height, 0px));}:root :where(body){background-image: url('http://example.org/image.png');background-position: center center;background-repeat: no-repeat;background-size: contain;}"; 5024 $this->assertSame( $expected_styles, $theme_json->get_styles_for_block( $body_node ), 'Styles returned from "::get_stylesheet()" with top-level background styles type do esnot match expectations' );5024 $this->assertSame( $expected_styles, $theme_json->get_styles_for_block( $body_node ), 'Styles returned from "::get_stylesheet()" with top-level background styles type do not match expectations' ); 5025 5025 5026 5026 $theme_json = new WP_Theme_JSON( … … 5039 5039 5040 5040 $expected_styles = "html{min-height: calc(100% - var(--wp-admin--admin-bar--height, 0px));}:root :where(body){background-image: url('http://example.org/image.png');background-position: center center;background-repeat: no-repeat;background-size: contain;}"; 5041 $this->assertSame( $expected_styles, $theme_json->get_styles_for_block( $body_node ), 'Styles returned from "::get_stylesheet()" with top-level background image as string type does not match expectations' ); 5041 $this->assertSame( $expected_styles, $theme_json->get_styles_for_block( $body_node ), 'Styles returned from "::get_stylesheet()" with top-level background image as string type do not match expectations' ); 5042 } 5043 5044 /** 5045 * @ticket 61588 5046 */ 5047 public function test_get_block_background_image_styles() { 5048 $theme_json = new WP_Theme_JSON( 5049 array( 5050 'version' => WP_Theme_JSON::LATEST_SCHEMA, 5051 'styles' => array( 5052 'blocks' => array( 5053 'core/group' => array( 5054 'background' => array( 5055 'backgroundImage' => "url('http://example.org/group.png')", 5056 'backgroundSize' => 'cover', 5057 'backgroundRepeat' => 'no-repeat', 5058 'backgroundPosition' => 'center center', 5059 ), 5060 ), 5061 'core/quote' => array( 5062 'background' => array( 5063 'backgroundImage' => array( 5064 'url' => 'http://example.org/quote.png', 5065 ), 5066 'backgroundSize' => 'cover', 5067 'backgroundRepeat' => 'no-repeat', 5068 'backgroundPosition' => 'center center', 5069 ), 5070 ), 5071 ), 5072 ), 5073 ) 5074 ); 5075 5076 $quote_node = array( 5077 'name' => 'core/quote', 5078 'path' => array( 'styles', 'blocks', 'core/quote' ), 5079 'selector' => '.wp-block-quote', 5080 'selectors' => array( 5081 'root' => '.wp-block-quote', 5082 ), 5083 ); 5084 5085 $quote_styles = ":root :where(.wp-block-quote){background-image: url('http://example.org/quote.png');background-position: center center;background-repeat: no-repeat;background-size: cover;}"; 5086 $this->assertSame( $quote_styles, $theme_json->get_styles_for_block( $quote_node ), 'Styles returned from "::get_styles_for_block()" with block-level background styles do not match expectations' ); 5087 5088 $group_node = array( 5089 'name' => 'core/group', 5090 'path' => array( 'styles', 'blocks', 'core/group' ), 5091 'selector' => '.wp-block-group', 5092 'selectors' => array( 5093 'root' => '.wp-block-group', 5094 ), 5095 ); 5096 5097 $group_styles = ":root :where(.wp-block-group){background-image: url('http://example.org/group.png');background-position: center center;background-repeat: no-repeat;background-size: cover;}"; 5098 $this->assertSame( $group_styles, $theme_json->get_styles_for_block( $group_node ), 'Styles returned from "::get_styles_for_block()" with block-level background styles as string type do not match expectations' ); 5042 5099 } 5043 5100 -
trunk/tests/phpunit/tests/theme/wpThemeJsonResolver.php
r58466 r58797 1258 1258 * @covers WP_Theme_JSON_Resolver::resolve_theme_file_uris 1259 1259 * @ticket 61273 1260 * @ticket 61588 1260 1261 */ 1261 1262 public function test_resolve_theme_file_uris() { … … 1267 1268 'backgroundImage' => array( 1268 1269 'url' => 'file:./assets/image.png', 1270 ), 1271 ), 1272 'blocks' => array( 1273 'core/quote' => array( 1274 'background' => array( 1275 'backgroundImage' => array( 1276 'url' => 'file:./assets/quote.png', 1277 ), 1278 ), 1279 ), 1280 'core/verse' => array( 1281 'background' => array( 1282 'backgroundImage' => array( 1283 'url' => 'file:./assets/verse.png', 1284 ), 1285 ), 1269 1286 ), 1270 1287 ), … … 1281 1298 ), 1282 1299 ), 1300 'blocks' => array( 1301 'core/quote' => array( 1302 'background' => array( 1303 'backgroundImage' => array( 1304 'url' => 'https://example.org/wp-content/themes/example-theme/assets/quote.png', 1305 ), 1306 ), 1307 ), 1308 'core/verse' => array( 1309 'background' => array( 1310 'backgroundImage' => array( 1311 'url' => 'https://example.org/wp-content/themes/example-theme/assets/verse.png', 1312 ), 1313 ), 1314 ), 1315 ), 1283 1316 ), 1284 1317 ); … … 1294 1327 * @covers WP_Theme_JSON_Resolver::get_resolved_theme_uris 1295 1328 * @ticket 61273 1329 * @ticket 61588 1296 1330 */ 1297 1331 public function test_get_resolved_theme_uris() { … … 1305 1339 ), 1306 1340 ), 1341 'blocks' => array( 1342 'core/quote' => array( 1343 'background' => array( 1344 'backgroundImage' => array( 1345 'url' => 'file:./assets/quote.jpg', 1346 ), 1347 ), 1348 ), 1349 'core/verse' => array( 1350 'background' => array( 1351 'backgroundImage' => array( 1352 'url' => 'file:./assets/verse.gif', 1353 ), 1354 ), 1355 ), 1356 ), 1307 1357 ), 1308 1358 ) … … 1315 1365 'target' => 'styles.background.backgroundImage.url', 1316 1366 'type' => 'image/png', 1367 ), 1368 array( 1369 'name' => 'file:./assets/quote.jpg', 1370 'href' => 'https://example.org/wp-content/themes/example-theme/assets/quote.jpg', 1371 'target' => 'styles.blocks.core/quote.background.backgroundImage.url', 1372 'type' => 'image/jpeg', 1373 ), 1374 array( 1375 'name' => 'file:./assets/verse.gif', 1376 'href' => 'https://example.org/wp-content/themes/example-theme/assets/verse.gif', 1377 'target' => 'styles.blocks.core/verse.background.backgroundImage.url', 1378 'type' => 'image/gif', 1317 1379 ), 1318 1380 );
Note: See TracChangeset
for help on using the changeset viewer.