Skip to content

Commit a5bdc76

Browse files
committed
6.2: update get_merged_data
#45969
1 parent fe37493 commit a5bdc76

File tree

2 files changed

+26
-68
lines changed

2 files changed

+26
-68
lines changed

lib/class-wp-theme-json-resolver.php

+26-11
Original file line numberDiff line numberDiff line change
@@ -519,17 +519,23 @@ public static function get_user_data() {
519519
/**
520520
* Returns the data merged from multiple origins.
521521
*
522-
* There are three sources of data (origins) for a site:
523-
* default, theme, and custom. The custom's has higher priority
524-
* than the theme's, and the theme's higher than default's.
522+
* There are four sources of data (origins) for a site:
523+
*
524+
* - default => WordPress
525+
* - blocks => each one of the blocks provides data for itself
526+
* - theme => the active theme
527+
* - custom => data provided by the user
528+
*
529+
* The custom's has higher priority than the theme's, the theme's higher than blocks',
530+
* and block's higher than default's.
525531
*
526532
* Unlike the getters
527533
* {@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_core_data/ get_core_data},
528534
* {@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_theme_data/ get_theme_data},
529535
* and {@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_user_data/ get_user_data},
530536
* this method returns data after it has been merged with the previous origins.
531537
* This means that if the same piece of data is declared in different origins
532-
* (user, theme, and core), the last origin overrides the previous.
538+
* (default, blocks, theme, custom), the last origin overrides the previous.
533539
*
534540
* For example, if the user has set a background color
535541
* for the paragraph block, and the theme has done it as well,
@@ -540,8 +546,9 @@ public static function get_user_data() {
540546
* added the `$origin` parameter.
541547
* @since 6.1.0 Added block data and generation of spacingSizes array.
542548
*
543-
* @param string $origin Optional. To what level should we merge data.
544-
* Valid values are 'theme' or 'custom'. Default 'custom'.
549+
* @param string $origin Optional. To what level should we merge data:'default', 'blocks', 'theme' or 'custom'.
550+
* 'custom' is used as default value as well as fallback value if the origin is unknown.
551+
*
545552
* @return WP_Theme_JSON
546553
*/
547554
public static function get_merged_data( $origin = 'custom' ) {
@@ -550,16 +557,24 @@ public static function get_merged_data( $origin = 'custom' ) {
550557
}
551558

552559
$result = static::get_core_data();
560+
if ( 'default' === $origin ) {
561+
$result->set_spacing_sizes();
562+
return $result;
563+
}
564+
553565
$result->merge( static::get_block_data() );
554-
$result->merge( static::get_theme_data() );
566+
if ( 'blocks' === $origin ) {
567+
return $result;
568+
}
555569

556-
if ( 'custom' === $origin ) {
557-
$result->merge( static::get_user_data() );
570+
$result->merge( static::get_theme_data() );
571+
if ( 'theme' === $origin ) {
572+
$result->set_spacing_sizes();
573+
return $result;
558574
}
559575

560-
// Generate the default spacingSizes array based on the merged spacingScale settings.
576+
$result->merge( static::get_user_data() );
561577
$result->set_spacing_sizes();
562-
563578
return $result;
564579
}
565580

lib/compat/wordpress-6.2/class-wp-theme-json-resolver-6-2.php

-57
Original file line numberDiff line numberDiff line change
@@ -17,63 +17,6 @@
1717
*/
1818
class WP_Theme_JSON_Resolver_6_2 extends WP_Theme_JSON_Resolver_Base {
1919

20-
/**
21-
* Returns the data merged from multiple origins.
22-
*
23-
* There are four sources of data (origins) for a site:
24-
*
25-
* - default => WordPress
26-
* - blocks => each one of the blocks provides data for itself
27-
* - theme => the active theme
28-
* - custom => data provided by the user
29-
*
30-
* The custom's has higher priority than the theme's, the theme's higher than blocks',
31-
* and block's higher than default's.
32-
*
33-
* Unlike the getters
34-
* {@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_core_data/ get_core_data},
35-
* {@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_theme_data/ get_theme_data},
36-
* and {@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_user_data/ get_user_data},
37-
* this method returns data after it has been merged with the previous origins.
38-
* This means that if the same piece of data is declared in different origins
39-
* (default, blocks, theme, custom), the last origin overrides the previous.
40-
*
41-
* For example, if the user has set a background color
42-
* for the paragraph block, and the theme has done it as well,
43-
* the user preference wins.
44-
*
45-
* @param string $origin Optional. To what level should we merge data:'default', 'blocks', 'theme' or 'custom'.
46-
* 'custom' is used as default value as well as fallback value if the origin is unknown.
47-
*
48-
* @return WP_Theme_JSON
49-
*/
50-
public static function get_merged_data( $origin = 'custom' ) {
51-
if ( is_array( $origin ) ) {
52-
_deprecated_argument( __FUNCTION__, '5.9.0' );
53-
}
54-
55-
$result = static::get_core_data();
56-
if ( 'default' === $origin ) {
57-
$result->set_spacing_sizes();
58-
return $result;
59-
}
60-
61-
$result->merge( static::get_block_data() );
62-
if ( 'blocks' === $origin ) {
63-
return $result;
64-
}
65-
66-
$result->merge( static::get_theme_data() );
67-
if ( 'theme' === $origin ) {
68-
$result->set_spacing_sizes();
69-
return $result;
70-
}
71-
72-
$result->merge( static::get_user_data() );
73-
$result->set_spacing_sizes();
74-
return $result;
75-
}
76-
7720
/**
7821
* Returns the user's origin config.
7922
*

0 commit comments

Comments
 (0)