@@ -519,17 +519,23 @@ public static function get_user_data() {
519
519
/**
520
520
* Returns the data merged from multiple origins.
521
521
*
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.
525
531
*
526
532
* Unlike the getters
527
533
* {@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_core_data/ get_core_data},
528
534
* {@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_theme_data/ get_theme_data},
529
535
* and {@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_user_data/ get_user_data},
530
536
* this method returns data after it has been merged with the previous origins.
531
537
* 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.
533
539
*
534
540
* For example, if the user has set a background color
535
541
* for the paragraph block, and the theme has done it as well,
@@ -540,8 +546,9 @@ public static function get_user_data() {
540
546
* added the `$origin` parameter.
541
547
* @since 6.1.0 Added block data and generation of spacingSizes array.
542
548
*
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
+ *
545
552
* @return WP_Theme_JSON
546
553
*/
547
554
public static function get_merged_data ( $ origin = 'custom ' ) {
@@ -550,16 +557,24 @@ public static function get_merged_data( $origin = 'custom' ) {
550
557
}
551
558
552
559
$ result = static ::get_core_data ();
560
+ if ( 'default ' === $ origin ) {
561
+ $ result ->set_spacing_sizes ();
562
+ return $ result ;
563
+ }
564
+
553
565
$ result ->merge ( static ::get_block_data () );
554
- $ result ->merge ( static ::get_theme_data () );
566
+ if ( 'blocks ' === $ origin ) {
567
+ return $ result ;
568
+ }
555
569
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 ;
558
574
}
559
575
560
- // Generate the default spacingSizes array based on the merged spacingScale settings.
576
+ $ result -> merge ( static :: get_user_data () );
561
577
$ result ->set_spacing_sizes ();
562
-
563
578
return $ result ;
564
579
}
565
580
0 commit comments