Skip to content

Commit 8f46778

Browse files
committed
Bail early for given origin
1 parent c75fc6d commit 8f46778

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

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

+58
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,62 @@ public static function _clean_cached_data_upon_upgrading( $upgrader, $options )
5757
}
5858
}
5959

60+
/**
61+
* Returns the data merged from multiple origins.
62+
*
63+
* There are four sources of data (origins) for a site:
64+
*
65+
* - default => WordPress
66+
* - blocks => each one of the blocks provides data for itself
67+
* - theme => the active theme
68+
* - custom => data provided by the user
69+
*
70+
* The custom's has higher priority than the theme's, the theme's higher than blocks',
71+
* and block's higher than default's.
72+
*
73+
* Unlike the getters
74+
* {@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_core_data/ get_core_data},
75+
* {@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_theme_data/ get_theme_data},
76+
* and {@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_user_data/ get_user_data},
77+
* this method returns data after it has been merged with the previous origins.
78+
* This means that if the same piece of data is declared in different origins
79+
* (default, blocks, theme, custom), the last origin overrides the previous.
80+
*
81+
* For example, if the user has set a background color
82+
* for the paragraph block, and the theme has done it as well,
83+
* the user preference wins.
84+
*
85+
* @param string $origin Optional. To what level should we merge data:'default', 'blocks', 'theme' or 'custom'.
86+
* 'custom' is used as default value as well as fallback value if the origin is unknown.
87+
*
88+
* @return WP_Theme_JSON
89+
*/
90+
public static function get_merged_data( $origin = 'custom' ) {
91+
if ( is_array( $origin ) ) {
92+
_deprecated_argument( __FUNCTION__, '5.9.0' );
93+
}
94+
95+
$result = static::get_core_data();
96+
if ( 'default' === $origin ) {
97+
$result->set_spacing_sizes();
98+
return $result;
99+
}
100+
101+
$result->merge( static::get_block_data() );
102+
if ( 'blocks' === $origin ) {
103+
$result->set_spacing_sizes();
104+
return $result;
105+
}
106+
107+
$result->merge( static::get_theme_data() );
108+
if ( 'theme' === $origin ) {
109+
$result->set_spacing_sizes();
110+
return $result;
111+
}
112+
113+
$result->merge( static::get_user_data() );
114+
115+
$result->set_spacing_sizes();
116+
return $result;
117+
}
60118
}

0 commit comments

Comments
 (0)