Changeset 58936 for trunk/src/wp-includes/class-wp-theme-json.php
- Timestamp:
- 08/26/2024 05:38:05 AM (17 months ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/class-wp-theme-json.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-theme-json.php
r58896 r58936 2296 2296 * array( 2297 2297 * 'name' => 'property_name', 2298 * 'value' => 'property_value ,2298 * 'value' => 'property_value', 2299 2299 * ) 2300 2300 * … … 2304 2304 * @since 6.5.0 Output a `min-height: unset` rule when `aspect-ratio` is set. 2305 2305 * @since 6.6.0 Pass current theme JSON settings to wp_get_typography_font_size_value(), and process background properties. 2306 * @since 6.7.0 `ref` resolution of background properties, and assigning custom default values. 2306 2307 * 2307 2308 * @param array $styles Styles to process. … … 2357 2358 } 2358 2359 2359 // Processes background styles. 2360 if ( 'background' === $value_path[0] && isset( $styles['background'] ) ) { 2361 $background_styles = wp_style_engine_get_styles( array( 'background' => $styles['background'] ) ); 2362 $value = isset( $background_styles['declarations'][ $css_property ] ) ? $background_styles['declarations'][ $css_property ] : $value; 2360 /* 2361 * Processes background image styles. 2362 * If the value is a URL, it will be converted to a CSS `url()` value. 2363 * For uploaded image (images with a database ID), apply size and position defaults, 2364 * equal to those applied in block supports in lib/background.php. 2365 */ 2366 if ( 'background-image' === $css_property && ! empty( $value ) ) { 2367 $background_styles = wp_style_engine_get_styles( 2368 array( 'background' => array( 'backgroundImage' => $value ) ) 2369 ); 2370 $value = $background_styles['declarations'][ $css_property ]; 2371 } 2372 if ( empty( $value ) && static::ROOT_BLOCK_SELECTOR !== $selector && ! empty( $styles['background']['backgroundImage']['id'] ) ) { 2373 if ( 'background-size' === $css_property ) { 2374 $value = 'cover'; 2375 } 2376 // If the background size is set to `contain` and no position is set, set the position to `center`. 2377 if ( 'background-position' === $css_property ) { 2378 $background_size = $styles['background']['backgroundSize'] ?? null; 2379 $value = 'contain' === $background_size ? '50% 50%' : null; 2380 } 2363 2381 } 2364 2382 … … 2422 2440 * This is already done by the sanitize method, 2423 2441 * so every property will be in the standard form. 2442 * @since 6.7.0 Added support for background image refs. 2424 2443 * 2425 2444 * @param array $styles Styles subtree. … … 2438 2457 /* 2439 2458 * This converts references to a path to the value at that path 2440 * where the value sis an array with a "ref" key, pointing to a path.2459 * where the value is an array with a "ref" key, pointing to a path. 2441 2460 * For example: { "ref": "style.color.background" } => "#fff". 2461 * In the case of backgroundImage, if both a ref and a URL are present in the value, 2462 * the URL takes precedence and the ref is ignored. 2442 2463 */ 2443 2464 if ( is_array( $value ) && isset( $value['ref'] ) ) { 2444 2465 $value_path = explode( '.', $value['ref'] ); 2445 2466 $ref_value = _wp_array_get( $theme_json, $value_path ); 2467 // Background Image refs can refer to a string or an array containing a URL string. 2468 $ref_value_url = $ref_value['url'] ?? null; 2446 2469 // Only use the ref value if we find anything. 2447 if ( ! empty( $ref_value ) && is_string( $ref_value) ) {2470 if ( ! empty( $ref_value ) && ( is_string( $ref_value ) || is_string( $ref_value_url ) ) ) { 2448 2471 $value = $ref_value; 2449 2472 } … … 3084 3107 * @since 5.8.0 3085 3108 * @since 5.9.0 Duotone preset also has origins. 3109 * @since 6.7.0 Replace background image objects during merge. 3086 3110 * 3087 3111 * @param WP_Theme_JSON $incoming Data to merge. … … 3205 3229 _wp_array_set( $this->theme_json, $path, $content ); 3206 3230 } 3231 } 3232 } 3233 3234 /* 3235 * Style values are merged at the leaf level, however 3236 * some values provide exceptions, namely style values that are 3237 * objects and represent unique definitions for the style. 3238 */ 3239 $style_nodes = static::get_styles_block_nodes(); 3240 foreach ( $style_nodes as $style_node ) { 3241 $path = $style_node['path']; 3242 /* 3243 * Background image styles should be replaced, not merged, 3244 * as they themselves are specific object definitions for the style. 3245 */ 3246 $background_image_path = array_merge( $path, static::PROPERTIES_METADATA['background-image'] ); 3247 $content = _wp_array_get( $incoming_data, $background_image_path, null ); 3248 if ( isset( $content ) ) { 3249 _wp_array_set( $this->theme_json, $background_image_path, $content ); 3207 3250 } 3208 3251 }
Note: See TracChangeset
for help on using the changeset viewer.