run:R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:51
R W Run
23.8 KB
2026-03-11 16:18:51
R W Run
7.8 KB
2026-03-11 16:18:52
R W Run
36.1 KB
2026-03-11 16:18:51
R W Run
11.9 KB
2026-03-11 16:18:52
R W Run
18.94 KB
2026-03-11 16:18:52
R W Run
7.35 KB
2026-03-11 16:18:52
R W Run
28.6 KB
2026-03-11 16:18:51
R W Run
316 By
2026-03-11 16:18:51
R W Run
12.9 KB
2026-03-11 16:18:51
R W Run
61.02 KB
2026-03-11 16:18:52
R W Run
15 KB
2026-03-11 16:18:51
R W Run
112.05 KB
2026-03-11 16:18:51
R W Run
12.47 KB
2026-03-11 16:18:51
R W Run
15.07 KB
2026-03-11 16:18:52
R W Run
9.84 KB
2026-03-11 16:18:52
R W Run
13.17 KB
2026-03-11 16:18:52
R W Run
33.83 KB
2026-03-11 16:18:51
R W Run
42.63 KB
2026-03-11 16:18:51
R W Run
55.71 KB
2026-03-11 16:18:52
R W Run
12.53 KB
2026-03-11 16:18:51
R W Run
2.55 KB
2026-03-11 16:18:52
R W Run
28.92 KB
2026-03-11 16:18:52
R W Run
539 By
2026-03-11 16:18:51
R W Run
367 By
2026-03-11 16:18:52
R W Run
42.65 KB
2026-03-11 16:18:51
R W Run
401 By
2026-03-11 16:18:51
R W Run
6.61 KB
2026-03-11 16:18:51
R W Run
664 By
2026-03-11 16:18:52
R W Run
20.63 KB
2026-03-11 16:18:51
R W Run
2.18 KB
2026-03-11 16:18:52
R W Run
453 By
2026-03-11 16:18:52
R W Run
457 By
2026-03-11 16:18:51
R W Run
36.83 KB
2026-03-11 16:18:52
R W Run
2.41 KB
2026-03-11 16:18:52
R W Run
8.28 KB
2026-03-11 16:18:51
R W Run
13.89 KB
2026-03-11 16:18:51
R W Run
11.76 KB
2026-03-11 16:18:51
R W Run
2.65 KB
2026-03-11 16:18:51
R W Run
7.43 KB
2026-03-11 16:18:51
R W Run
17.46 KB
2026-03-11 16:18:51
R W Run
5.14 KB
2026-03-11 16:18:52
R W Run
16.7 KB
2026-03-11 16:18:51
R W Run
8.28 KB
2026-03-11 16:18:52
R W Run
2.92 KB
2026-03-11 16:18:52
R W Run
1.32 KB
2026-03-11 16:18:51
R W Run
4.6 KB
2026-03-11 16:18:52
R W Run
11.62 KB
2026-03-11 16:18:52
R W Run
2.5 KB
2026-03-11 16:18:51
R W Run
1.97 KB
2026-03-11 16:18:51
R W Run
11.25 KB
2026-03-11 16:18:52
R W Run
5.32 KB
2026-03-11 16:18:51
R W Run
10.99 KB
2026-03-11 16:18:52
R W Run
68.32 KB
2026-03-11 16:18:51
R W Run
6.34 KB
2026-03-11 16:18:51
R W Run
5.49 KB
2026-03-11 16:18:51
R W Run
1.99 KB
2026-03-11 16:18:52
R W Run
7.02 KB
2026-03-11 16:18:51
R W Run
4.91 KB
2026-03-11 16:18:52
R W Run
16.86 KB
2026-03-11 16:18:51
R W Run
24.23 KB
2026-03-11 16:18:51
R W Run
3.97 KB
2026-03-11 16:18:51
R W Run
47.66 KB
2026-03-11 16:18:51
R W Run
9.22 KB
2026-03-11 16:18:51
R W Run
25.51 KB
2026-03-11 16:18:51
R W Run
198.38 KB
2026-03-11 16:18:52
R W Run
56.65 KB
2026-03-11 16:18:51
R W Run
10.46 KB
2026-03-11 16:18:51
R W Run
10.95 KB
2026-03-11 16:18:52
R W Run
29.26 KB
2026-03-11 16:18:51
R W Run
70.91 KB
2026-03-11 16:18:52
R W Run
35.3 KB
2026-03-11 16:18:52
R W Run
16.61 KB
2026-03-11 16:18:52
R W Run
2.57 KB
2026-03-11 16:18:52
R W Run
39.83 KB
2026-03-11 16:18:51
R W Run
70.64 KB
2026-03-11 16:18:51
R W Run
15.56 KB
2026-03-11 16:18:52
R W Run
7.33 KB
2026-03-11 16:18:52
R W Run
253 By
2026-03-11 16:18:51
R W Run
7.96 KB
2026-03-11 16:18:52
R W Run
3.23 KB
2026-03-11 16:18:52
R W Run
969 By
2026-03-11 16:18:52
R W Run
16.28 KB
2026-03-11 16:18:51
R W Run
7.22 KB
2026-03-11 16:18:51
R W Run
12.95 KB
2026-03-11 16:18:51
R W Run
6.53 KB
2026-03-11 16:18:51
R W Run
3.42 KB
2026-03-11 16:18:52
R W Run
5.84 KB
2026-03-11 16:18:51
R W Run
1.97 KB
2026-03-11 16:18:51
R W Run
4.3 KB
2026-03-11 16:18:52
R W Run
2.91 KB
2026-03-11 16:18:51
R W Run
16.46 KB
2026-03-11 16:18:52
R W Run
40.6 KB
2026-03-11 16:18:51
R W Run
20.22 KB
2026-03-11 16:18:51
R W Run
36.11 KB
2026-03-11 16:18:52
R W Run
17.01 KB
2026-03-11 16:18:51
R W Run
7.27 KB
2026-03-11 16:18:52
R W Run
6.62 KB
2026-03-11 16:18:52
R W Run
16.49 KB
2026-03-11 16:18:52
R W Run
1.79 KB
2026-03-11 16:18:52
R W Run
29.82 KB
2026-03-11 16:18:51
R W Run
6.67 KB
2026-03-11 16:18:52
R W Run
8.98 KB
2026-03-11 16:18:52
R W Run
19.42 KB
2026-03-11 16:18:51
R W Run
12.01 KB
2026-03-11 16:18:51
R W Run
17.11 KB
2026-03-11 16:18:51
R W Run
6.74 KB
2026-03-11 16:18:52
R W Run
30.93 KB
2026-03-11 16:18:51
R W Run
4.99 KB
2026-03-11 16:18:51
R W Run
4.25 KB
2026-03-11 16:18:51
R W Run
24.72 KB
2026-03-11 16:18:51
R W Run
29.96 KB
2026-03-11 16:18:52
R W Run
6.41 KB
2026-03-11 16:18:51
R W Run
160 KB
2026-03-11 16:18:51
R W Run
6.72 KB
2026-03-11 16:18:52
R W Run
10.92 KB
2026-03-11 16:18:51
R W Run
4.77 KB
2026-03-11 16:18:51
R W Run
3.38 KB
2026-03-11 16:18:51
R W Run
11.18 KB
2026-03-11 16:18:51
R W Run
62.19 KB
2026-03-11 16:18:51
R W Run
2.46 KB
2026-03-11 16:18:51
R W Run
9.17 KB
2026-03-11 16:18:51
R W Run
32.15 KB
2026-03-11 16:18:51
R W Run
34.05 KB
2026-03-11 16:18:52
R W Run
7.15 KB
2026-03-11 16:18:51
R W Run
3.47 KB
2026-03-11 16:18:52
R W Run
1.87 KB
2026-03-11 16:18:52
R W Run
30.91 KB
2026-03-11 16:18:51
R W Run
7.29 KB
2026-03-11 16:18:52
R W Run
7.35 KB
2026-03-11 16:18:51
R W Run
12.54 KB
2026-03-11 16:18:51
R W Run
19.12 KB
2026-03-11 16:18:51
R W Run
18.12 KB
2026-03-11 16:18:52
R W Run
39.99 KB
2026-03-11 16:18:52
R W Run
5.17 KB
2026-03-11 16:18:52
R W Run
979 By
2026-03-11 16:18:51
R W Run
18.44 KB
2026-03-11 16:18:52
R W Run
10.24 KB
2026-03-11 16:18:51
R W Run
1.77 KB
2026-03-11 16:18:52
R W Run
34.9 KB
2026-03-11 16:18:51
R W Run
7.19 KB
2026-03-11 16:18:52
R W Run
160.5 KB
2026-03-11 16:18:51
R W Run
64.27 KB
2026-03-11 16:18:51
R W Run
27.95 KB
2026-03-11 16:18:51
R W Run
4.69 KB
2026-03-11 16:18:51
R W Run
2.94 KB
2026-03-11 16:18:51
R W Run
43.13 KB
2026-03-11 16:18:52
R W Run
2.25 KB
2026-03-11 16:18:52
R W Run
22.5 KB
2026-03-11 16:18:51
R W Run
13.01 KB
2026-03-11 16:18:52
R W Run
3.27 KB
2026-03-11 16:18:51
R W Run
18 KB
2026-03-11 16:18:51
R W Run
210.4 KB
2026-03-11 16:18:52
R W Run
25.86 KB
2026-03-11 16:18:52
R W Run
115.85 KB
2026-03-11 16:18:51
R W Run
373 By
2026-03-11 16:18:52
R W Run
343 By
2026-03-11 16:18:52
R W Run
338 By
2026-03-11 16:18:51
R W Run
100.73 KB
2026-03-11 16:18:52
R W Run
130.93 KB
2026-03-11 16:18:51
R W Run
19.1 KB
2026-03-11 16:18:51
R W Run
17.41 KB
2026-03-11 16:18:52
R W Run
41.98 KB
2026-03-11 16:18:52
R W Run
400 By
2026-03-11 16:18:52
R W Run
11.1 KB
2026-03-11 16:18:52
R W Run
37.02 KB
2026-03-11 16:18:51
R W Run
2.24 KB
2026-03-11 16:18:51
R W Run
188.13 KB
2026-03-11 16:18:51
R W Run
338 By
2026-03-11 16:18:51
R W Run
38 KB
2026-03-11 16:18:51
R W Run
4.02 KB
2026-03-11 16:18:52
R W Run
5.38 KB
2026-03-11 16:18:51
R W Run
3.05 KB
2026-03-11 16:18:52
R W Run
2.61 KB
2026-03-11 16:18:51
R W Run
1.16 KB
2026-03-11 16:18:52
R W Run
4.04 KB
2026-03-11 16:18:51
R W Run
3.71 KB
2026-03-11 16:18:51
R W Run
24.6 KB
2026-03-11 16:18:51
R W Run
9.56 KB
2026-03-11 16:18:51
R W Run
346.43 KB
2026-03-11 16:18:52
R W Run
281.84 KB
2026-03-11 16:18:52
R W Run
14.95 KB
2026-03-11 16:18:51
R W Run
8.44 KB
2026-03-11 16:18:52
R W Run
168.95 KB
2026-03-11 16:18:52
R W Run
20.71 KB
2026-03-11 16:18:52
R W Run
25.27 KB
2026-03-11 16:18:51
R W Run
5.72 KB
2026-03-11 16:18:51
R W Run
4.63 KB
2026-03-11 16:18:52
R W Run
81.73 KB
2026-03-11 16:18:51
R W Run
67.18 KB
2026-03-11 16:18:51
R W Run
156.36 KB
2026-03-11 16:18:52
R W Run
55.19 KB
2026-03-11 16:18:51
R W Run
162 By
2026-03-11 16:18:51
R W Run
61.72 KB
2026-03-11 16:18:51
R W Run
216.06 KB
2026-03-11 16:18:52
R W Run
65.09 KB
2026-03-11 16:18:51
R W Run
25.24 KB
2026-03-11 16:18:52
R W Run
4.81 KB
2026-03-11 16:18:51
R W Run
6.48 KB
2026-03-11 16:18:52
R W Run
21.25 KB
2026-03-11 16:18:51
R W Run
2.79 KB
2026-03-11 16:18:52
R W Run
89.69 KB
2026-03-11 16:18:52
R W Run
19.42 KB
2026-03-11 16:18:52
R W Run
3.69 KB
2026-03-11 16:18:52
R W Run
4.11 KB
2026-03-11 16:18:51
R W Run
40.74 KB
2026-03-11 16:18:51
R W Run
25.38 KB
2026-03-11 16:18:51
R W Run
43.31 KB
2026-03-11 16:18:52
R W Run
102.57 KB
2026-03-11 16:18:52
R W Run
6.18 KB
2026-03-11 16:18:51
R W Run
124.47 KB
2026-03-11 16:18:52
R W Run
35.65 KB
2026-03-11 16:18:52
R W Run
6.94 KB
2026-03-11 16:18:52
R W Run
67.04 KB
2026-03-11 16:18:52
R W Run
10.62 KB
2026-03-11 16:18:51
R W Run
289.35 KB
2026-03-11 16:18:52
R W Run
36.23 KB
2026-03-11 16:18:51
R W Run
200 By
2026-03-11 16:18:52
R W Run
200 By
2026-03-11 16:18:52
R W Run
98.29 KB
2026-03-11 16:18:52
R W Run
30.02 KB
2026-03-11 16:18:52
R W Run
19.03 KB
2026-03-11 16:18:52
R W Run
5.06 KB
2026-03-11 16:18:52
R W Run
255 By
2026-03-11 16:18:51
R W Run
22.66 KB
2026-03-11 16:18:52
R W Run
154.63 KB
2026-03-11 16:18:51
R W Run
9.68 KB
2026-03-11 16:18:51
R W Run
258 By
2026-03-11 16:18:51
R W Run
23.49 KB
2026-03-11 16:18:51
R W Run
3.16 KB
2026-03-11 16:18:51
R W Run
8.4 KB
2026-03-11 16:18:52
R W Run
441 By
2026-03-11 16:18:51
R W Run
7.39 KB
2026-03-11 16:18:51
R W Run
173 KB
2026-03-11 16:18:52
R W Run
544 By
2026-03-11 16:18:52
R W Run
4.17 KB
2026-03-11 16:18:51
R W Run
35.97 KB
2026-03-11 16:18:52
R W Run
1.69 KB
2026-03-11 16:18:51
R W Run
2.84 KB
2026-03-11 16:18:52
R W Run
6.09 KB
2026-03-11 16:18:51
R W Run
8.71 KB
2026-03-11 16:18:51
R W Run
131.84 KB
2026-03-11 16:18:51
R W Run
37.45 KB
2026-03-11 16:18:51
R W Run
173.89 KB
2026-03-11 16:18:51
R W Run
7.09 KB
2026-03-11 16:18:51
R W Run
6.41 KB
2026-03-11 16:18:51
R W Run
1.08 KB
2026-03-11 16:18:51
R W Run
69.46 KB
2026-03-11 16:18:52
R W Run
445 By
2026-03-11 16:18:51
R W Run
799 By
2026-03-11 16:18:52
R W Run
error_log
📄global-styles-and-settings.php
1<?php
2/**
3 * APIs to interact with global settings & styles.
4 *
5 * @package WordPress
6 */
7
8/**
9 * Gets the settings resulting of merging core, theme, and user data.
10 *
11 * @since 5.9.0
12 *
13 * @param array $path Path to the specific setting to retrieve. Optional.
14 * If empty, will return all settings.
15 * @param array $context {
16 * Metadata to know where to retrieve the $path from. Optional.
17 *
18 * @type string $block_name Which block to retrieve the settings from.
19 * If empty, it'll return the settings for the global context.
20 * @type string $origin Which origin to take data from.
21 * Valid values are 'all' (core, theme, and user) or 'base' (core and theme).
22 * If empty or unknown, 'all' is used.
23 * }
24 * @return mixed The settings array or individual setting value to retrieve.
25 */
26function wp_get_global_settings( $path = array(), $context = array() ) {
27 if ( ! empty( $context['block_name'] ) ) {
28 $new_path = array( 'blocks', $context['block_name'] );
29 foreach ( $path as $subpath ) {
30 $new_path[] = $subpath;
31 }
32 $path = $new_path;
33 }
34
35 /*
36 * This is the default value when no origin is provided or when it is 'all'.
37 *
38 * The $origin is used as part of the cache key. Changes here need to account
39 * for clearing the cache appropriately.
40 */
41 $origin = 'custom';
42 if (
43 ! wp_theme_has_theme_json() ||
44 ( isset( $context['origin'] ) && 'base' === $context['origin'] )
45 ) {
46 $origin = 'theme';
47 }
48
49 /*
50 * By using the 'theme_json' group, this data is marked to be non-persistent across requests.
51 * See `wp_cache_add_non_persistent_groups` in src/wp-includes/load.php and other places.
52 *
53 * The rationale for this is to make sure derived data from theme.json
54 * is always fresh from the potential modifications done via hooks
55 * that can use dynamic data (modify the stylesheet depending on some option,
56 * settings depending on user permissions, etc.).
57 * See some of the existing hooks to modify theme.json behavior:
58 * https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/
59 *
60 * A different alternative considered was to invalidate the cache upon certain
61 * events such as options add/update/delete, user meta, etc.
62 * It was judged not enough, hence this approach.
63 * See https://github.com/WordPress/gutenberg/pull/45372
64 */
65 $cache_group = 'theme_json';
66 $cache_key = 'wp_get_global_settings_' . $origin;
67
68 /*
69 * Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme
70 * developer's workflow.
71 */
72 $can_use_cached = ! wp_is_development_mode( 'theme' );
73
74 $settings = false;
75 if ( $can_use_cached ) {
76 $settings = wp_cache_get( $cache_key, $cache_group );
77 }
78
79 if ( false === $settings ) {
80 $settings = WP_Theme_JSON_Resolver::get_merged_data( $origin )->get_settings();
81 if ( $can_use_cached ) {
82 wp_cache_set( $cache_key, $settings, $cache_group );
83 }
84 }
85
86 return _wp_array_get( $settings, $path, $settings );
87}
88
89/**
90 * Gets the styles resulting of merging core, theme, and user data.
91 *
92 * @since 5.9.0
93 * @since 6.3.0 the internal link format "var:preset|color|secondary" is resolved
94 * to "var(--wp--preset--font-size--small)" so consumers don't have to.
95 * @since 6.3.0 `transforms` is now usable in the `context` parameter. In case [`transforms`]['resolve_variables']
96 * is defined, variables are resolved to their value in the styles.
97 *
98 * @param array $path Path to the specific style to retrieve. Optional.
99 * If empty, will return all styles.
100 * @param array $context {
101 * Metadata to know where to retrieve the $path from. Optional.
102 *
103 * @type string $block_name Which block to retrieve the styles from.
104 * If empty, it'll return the styles for the global context.
105 * @type string $origin Which origin to take data from.
106 * Valid values are 'all' (core, theme, and user) or 'base' (core and theme).
107 * If empty or unknown, 'all' is used.
108 * @type array $transforms Which transformation(s) to apply.
109 * Valid value is array( 'resolve-variables' ).
110 * If defined, variables are resolved to their value in the styles.
111 * }
112 * @return mixed The styles array or individual style value to retrieve.
113 */
114function wp_get_global_styles( $path = array(), $context = array() ) {
115 if ( ! empty( $context['block_name'] ) ) {
116 $path = array_merge( array( 'blocks', $context['block_name'] ), $path );
117 }
118
119 $origin = 'custom';
120 if ( isset( $context['origin'] ) && 'base' === $context['origin'] ) {
121 $origin = 'theme';
122 }
123
124 $resolve_variables = isset( $context['transforms'] )
125 && is_array( $context['transforms'] )
126 && in_array( 'resolve-variables', $context['transforms'], true );
127
128 $merged_data = WP_Theme_JSON_Resolver::get_merged_data( $origin );
129 if ( $resolve_variables ) {
130 $merged_data = WP_Theme_JSON::resolve_variables( $merged_data );
131 }
132 $styles = $merged_data->get_raw_data()['styles'];
133 return _wp_array_get( $styles, $path, $styles );
134}
135
136
137/**
138 * Returns the stylesheet resulting of merging core, theme, and user data.
139 *
140 * @since 5.9.0
141 * @since 6.1.0 Added 'base-layout-styles' support.
142 * @since 6.6.0 Resolves relative paths in theme.json styles to theme absolute paths.
143 *
144 * @param array $types Optional. Types of styles to load.
145 * See {@see 'WP_Theme_JSON::get_stylesheet'} for all valid types.
146 * If empty, it'll load the following:
147 * - for themes without theme.json: 'variables', 'presets', 'base-layout-styles'.
148 * - for themes with theme.json: 'variables', 'presets', 'styles'.
149 * @return string Stylesheet.
150 */
151function wp_get_global_stylesheet( $types = array() ) {
152 /*
153 * Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme
154 * developer's workflow.
155 */
156 $can_use_cached = empty( $types ) && ! wp_is_development_mode( 'theme' );
157
158 /*
159 * By using the 'theme_json' group, this data is marked to be non-persistent across requests.
160 * @see `wp_cache_add_non_persistent_groups()`.
161 *
162 * The rationale for this is to make sure derived data from theme.json
163 * is always fresh from the potential modifications done via hooks
164 * that can use dynamic data (modify the stylesheet depending on some option,
165 * settings depending on user permissions, etc.).
166 * See some of the existing hooks to modify theme.json behavior:
167 * @see https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/
168 *
169 * A different alternative considered was to invalidate the cache upon certain
170 * events such as options add/update/delete, user meta, etc.
171 * It was judged not enough, hence this approach.
172 * @see https://github.com/WordPress/gutenberg/pull/45372
173 */
174 $cache_group = 'theme_json';
175 $cache_key = 'wp_get_global_stylesheet';
176 if ( $can_use_cached ) {
177 $cached = wp_cache_get( $cache_key, $cache_group );
178 if ( $cached ) {
179 return $cached;
180 }
181 }
182
183 $tree = WP_Theme_JSON_Resolver::resolve_theme_file_uris( WP_Theme_JSON_Resolver::get_merged_data() );
184 $supports_theme_json = wp_theme_has_theme_json();
185
186 if ( empty( $types ) && ! $supports_theme_json ) {
187 $types = array( 'variables', 'presets', 'base-layout-styles' );
188 } elseif ( empty( $types ) ) {
189 $types = array( 'variables', 'styles', 'presets' );
190 }
191
192 /*
193 * If variables are part of the stylesheet, then add them.
194 * This is so themes without a theme.json still work as before 5.9:
195 * they can override the default presets.
196 * See https://core.trac.wordpress.org/ticket/54782
197 */
198 $styles_variables = '';
199 if ( in_array( 'variables', $types, true ) ) {
200 /*
201 * Only use the default, theme, and custom origins. Why?
202 * Because styles for `blocks` origin are added at a later phase
203 * (i.e. in the render cycle). Here, only the ones in use are rendered.
204 * @see wp_add_global_styles_for_blocks
205 */
206 $origins = array( 'default', 'theme', 'custom' );
207 $styles_variables = $tree->get_stylesheet( array( 'variables' ), $origins );
208 $types = array_diff( $types, array( 'variables' ) );
209 }
210
211 /*
212 * For the remaining types (presets, styles), we do consider origins:
213 *
214 * - themes without theme.json: only the classes for the presets defined by core
215 * - themes with theme.json: the presets and styles classes, both from core and the theme
216 */
217 $styles_rest = '';
218 if ( ! empty( $types ) ) {
219 /*
220 * Only use the default, theme, and custom origins. Why?
221 * Because styles for `blocks` origin are added at a later phase
222 * (i.e. in the render cycle). Here, only the ones in use are rendered.
223 * @see wp_add_global_styles_for_blocks
224 */
225 $origins = array( 'default', 'theme', 'custom' );
226 /*
227 * If the theme doesn't have theme.json but supports both appearance tools and color palette,
228 * the 'theme' origin should be included so color palette presets are also output.
229 */
230 if ( ! $supports_theme_json && ( current_theme_supports( 'appearance-tools' ) || current_theme_supports( 'border' ) ) && current_theme_supports( 'editor-color-palette' ) ) {
231 $origins = array( 'default', 'theme' );
232 } elseif ( ! $supports_theme_json ) {
233 $origins = array( 'default' );
234 }
235 $styles_rest = $tree->get_stylesheet( $types, $origins );
236 }
237
238 $stylesheet = $styles_variables . $styles_rest;
239 if ( $can_use_cached ) {
240 wp_cache_set( $cache_key, $stylesheet, $cache_group );
241 }
242
243 return $stylesheet;
244}
245
246/**
247 * Adds global style rules to the inline style for each block.
248 *
249 * @since 6.1.0
250 * @since 6.7.0 Resolve relative paths in block styles.
251 *
252 * @global WP_Styles $wp_styles
253 */
254function wp_add_global_styles_for_blocks() {
255 global $wp_styles;
256
257 $tree = WP_Theme_JSON_Resolver::get_merged_data();
258 $tree = WP_Theme_JSON_Resolver::resolve_theme_file_uris( $tree );
259 $block_nodes = $tree->get_styles_block_nodes();
260
261 $can_use_cached = ! wp_is_development_mode( 'theme' );
262 $update_cache = false;
263
264 if ( $can_use_cached ) {
265 // Hash the merged WP_Theme_JSON data to bust cache on settings or styles change.
266 $cache_hash = md5( wp_json_encode( $tree->get_raw_data() ) );
267 $cache_key = 'wp_styles_for_blocks';
268 $cached = get_transient( $cache_key );
269
270 // Reset the cached data if there is no value or if the hash has changed.
271 if ( ! is_array( $cached ) || $cached['hash'] !== $cache_hash ) {
272 $cached = array(
273 'hash' => $cache_hash,
274 'blocks' => array(),
275 );
276
277 // Update the cache if the hash has changed.
278 $update_cache = true;
279 }
280 }
281
282 foreach ( $block_nodes as $metadata ) {
283
284 if ( $can_use_cached ) {
285 // Use the block name as the key for cached CSS data. Otherwise, use a hash of the metadata.
286 $cache_node_key = isset( $metadata['name'] ) ? $metadata['name'] : md5( wp_json_encode( $metadata ) );
287
288 if ( isset( $cached['blocks'][ $cache_node_key ] ) ) {
289 $block_css = $cached['blocks'][ $cache_node_key ];
290 } else {
291 $block_css = $tree->get_styles_for_block( $metadata );
292 $cached['blocks'][ $cache_node_key ] = $block_css;
293
294 // Update the cache if the cache contents have changed.
295 $update_cache = true;
296 }
297 } else {
298 $block_css = $tree->get_styles_for_block( $metadata );
299 }
300
301 if ( ! wp_should_load_block_assets_on_demand() ) {
302 wp_add_inline_style( 'global-styles', $block_css );
303 continue;
304 }
305
306 $stylesheet_handle = 'global-styles';
307
308 /*
309 * When `wp_should_load_block_assets_on_demand()` is true, block styles are
310 * enqueued for each block on the page in class WP_Block's render function.
311 * This means there will be a handle in the styles queue for each of those blocks.
312 * Block-specific global styles should be attached to the global-styles handle, but
313 * only for blocks on the page, thus we check if the block's handle is in the queue
314 * before adding the inline style.
315 * This conditional loading only applies to core blocks.
316 * TODO: Explore how this could be expanded to third-party blocks as well.
317 */
318 if ( isset( $metadata['name'] ) ) {
319 if ( str_starts_with( $metadata['name'], 'core/' ) ) {
320 $block_name = str_replace( 'core/', '', $metadata['name'] );
321 $block_handle = 'wp-block-' . $block_name;
322 if ( in_array( $block_handle, $wp_styles->queue, true ) ) {
323 wp_add_inline_style( $stylesheet_handle, $block_css );
324 }
325 } else {
326 wp_add_inline_style( $stylesheet_handle, $block_css );
327 }
328 }
329
330 // The likes of block element styles from theme.json do not have $metadata['name'] set.
331 if ( ! isset( $metadata['name'] ) && ! empty( $metadata['path'] ) ) {
332 $block_name = wp_get_block_name_from_theme_json_path( $metadata['path'] );
333 if ( $block_name ) {
334 if ( str_starts_with( $block_name, 'core/' ) ) {
335 $block_name = str_replace( 'core/', '', $block_name );
336 $block_handle = 'wp-block-' . $block_name;
337 if ( in_array( $block_handle, $wp_styles->queue, true ) ) {
338 wp_add_inline_style( $stylesheet_handle, $block_css );
339 }
340 } else {
341 wp_add_inline_style( $stylesheet_handle, $block_css );
342 }
343 }
344 }
345 }
346
347 if ( $update_cache ) {
348 set_transient( $cache_key, $cached );
349 }
350}
351
352/**
353 * Gets the block name from a given theme.json path.
354 *
355 * @since 6.3.0
356 * @access private
357 *
358 * @param array $path An array of keys describing the path to a property in theme.json.
359 * @return string Identified block name, or empty string if none found.
360 */
361function wp_get_block_name_from_theme_json_path( $path ) {
362 // Block name is expected to be the third item after 'styles' and 'blocks'.
363 if (
364 count( $path ) >= 3
365 && 'styles' === $path[0]
366 && 'blocks' === $path[1]
367 && str_contains( $path[2], '/' )
368 ) {
369 return $path[2];
370 }
371
372 /*
373 * As fallback and for backward compatibility, allow any core block to be
374 * at any position.
375 */
376 $result = array_values(
377 array_filter(
378 $path,
379 static function ( $item ) {
380 if ( str_contains( $item, 'core/' ) ) {
381 return true;
382 }
383 return false;
384 }
385 )
386 );
387 if ( isset( $result[0] ) ) {
388 return $result[0];
389 }
390 return '';
391}
392
393/**
394 * Checks whether a theme or its parent has a theme.json file.
395 *
396 * @since 6.2.0
397 *
398 * @return bool Returns true if theme or its parent has a theme.json file, false otherwise.
399 */
400function wp_theme_has_theme_json() {
401 static $theme_has_support = array();
402
403 $stylesheet = get_stylesheet();
404
405 if (
406 isset( $theme_has_support[ $stylesheet ] ) &&
407 /*
408 * Ignore static cache when the development mode is set to 'theme', to avoid interfering with
409 * the theme developer's workflow.
410 */
411 ! wp_is_development_mode( 'theme' )
412 ) {
413 return $theme_has_support[ $stylesheet ];
414 }
415
416 $stylesheet_directory = get_stylesheet_directory();
417 $template_directory = get_template_directory();
418
419 // This is the same as get_theme_file_path(), which isn't available in load-styles.php context
420 if ( $stylesheet_directory !== $template_directory && file_exists( $stylesheet_directory . '/theme.json' ) ) {
421 $path = $stylesheet_directory . '/theme.json';
422 } else {
423 $path = $template_directory . '/theme.json';
424 }
425
426 /** This filter is documented in wp-includes/link-template.php */
427 $path = apply_filters( 'theme_file_path', $path, 'theme.json' );
428
429 $theme_has_support[ $stylesheet ] = file_exists( $path );
430
431 return $theme_has_support[ $stylesheet ];
432}
433
434/**
435 * Cleans the caches under the theme_json group.
436 *
437 * @since 6.2.0
438 */
439function wp_clean_theme_json_cache() {
440 wp_cache_delete( 'wp_get_global_stylesheet', 'theme_json' );
441 wp_cache_delete( 'wp_get_global_styles_svg_filters', 'theme_json' );
442 wp_cache_delete( 'wp_get_global_settings_custom', 'theme_json' );
443 wp_cache_delete( 'wp_get_global_settings_theme', 'theme_json' );
444 wp_cache_delete( 'wp_get_global_styles_custom_css', 'theme_json' );
445 wp_cache_delete( 'wp_get_theme_data_template_parts', 'theme_json' );
446 WP_Theme_JSON_Resolver::clean_cached_data();
447}
448
449/**
450 * Returns the current theme's wanted patterns (slugs) to be
451 * registered from Pattern Directory.
452 *
453 * @since 6.3.0
454 *
455 * @return string[]
456 */
457function wp_get_theme_directory_pattern_slugs() {
458 return WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) )->get_patterns();
459}
460
461/**
462 * Returns the metadata for the custom templates defined by the theme via theme.json.
463 *
464 * @since 6.4.0
465 *
466 * @return array Associative array of `$template_name => $template_data` pairs,
467 * with `$template_data` having "title" and "postTypes" fields.
468 */
469function wp_get_theme_data_custom_templates() {
470 return WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) )->get_custom_templates();
471}
472
473/**
474 * Returns the metadata for the template parts defined by the theme.
475 *
476 * @since 6.4.0
477 *
478 * @return array Associative array of `$part_name => $part_data` pairs,
479 * with `$part_data` having "title" and "area" fields.
480 */
481function wp_get_theme_data_template_parts() {
482 $cache_group = 'theme_json';
483 $cache_key = 'wp_get_theme_data_template_parts';
484 $can_use_cached = ! wp_is_development_mode( 'theme' );
485
486 if ( $can_use_cached ) {
487 $metadata = wp_cache_get( $cache_key, $cache_group );
488 if ( false !== $metadata ) {
489 return $metadata;
490 }
491 }
492
493 $metadata = WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) )->get_template_parts();
494 if ( $can_use_cached ) {
495 wp_cache_set( $cache_key, $metadata, $cache_group );
496 }
497
498 return $metadata;
499}
500
501/**
502 * Determines the CSS selector for the block type and property provided,
503 * returning it if available.
504 *
505 * @since 6.3.0
506 *
507 * @param WP_Block_Type $block_type The block's type.
508 * @param string|array $target The desired selector's target, `root` or array path.
509 * @param boolean $fallback Whether to fall back to broader selector.
510 *
511 * @return string|null CSS selector or `null` if no selector available.
512 */
513function wp_get_block_css_selector( $block_type, $target = 'root', $fallback = false ) {
514 if ( empty( $target ) ) {
515 return null;
516 }
517
518 $has_selectors = ! empty( $block_type->selectors );
519
520 // Root Selector.
521
522 // Calculated before returning as it can be used as fallback for
523 // feature selectors later on.
524 $root_selector = null;
525
526 if ( $has_selectors && isset( $block_type->selectors['root'] ) ) {
527 // Use the selectors API if available.
528 $root_selector = $block_type->selectors['root'];
529 } elseif ( isset( $block_type->supports['__experimentalSelector'] ) && is_string( $block_type->supports['__experimentalSelector'] ) ) {
530 // Use the old experimental selector supports property if set.
531 $root_selector = $block_type->supports['__experimentalSelector'];
532 } else {
533 // If no root selector found, generate default block class selector.
534 $block_name = str_replace( '/', '-', str_replace( 'core/', '', $block_type->name ) );
535 $root_selector = ".wp-block-{$block_name}";
536 }
537
538 // Return selector if it's the root target we are looking for.
539 if ( 'root' === $target ) {
540 return $root_selector;
541 }
542
543 // If target is not `root` we have a feature or subfeature as the target.
544 // If the target is a string convert to an array.
545 if ( is_string( $target ) ) {
546 $target = explode( '.', $target );
547 }
548
549 // Feature Selectors ( May fallback to root selector ).
550 if ( 1 === count( $target ) ) {
551 $fallback_selector = $fallback ? $root_selector : null;
552
553 // Prefer the selectors API if available.
554 if ( $has_selectors ) {
555 // Look for selector under `feature.root`.
556 $path = array( current( $target ), 'root' );
557 $feature_selector = _wp_array_get( $block_type->selectors, $path, null );
558
559 if ( $feature_selector ) {
560 return $feature_selector;
561 }
562
563 // Check if feature selector is set via shorthand.
564 $feature_selector = _wp_array_get( $block_type->selectors, $target, null );
565
566 return is_string( $feature_selector ) ? $feature_selector : $fallback_selector;
567 }
568
569 // Try getting old experimental supports selector value.
570 $path = array( current( $target ), '__experimentalSelector' );
571 $feature_selector = _wp_array_get( $block_type->supports, $path, null );
572
573 // Nothing to work with, provide fallback or null.
574 if ( null === $feature_selector ) {
575 return $fallback_selector;
576 }
577
578 // Scope the feature selector by the block's root selector.
579 return WP_Theme_JSON::scope_selector( $root_selector, $feature_selector );
580 }
581
582 // Subfeature selector
583 // This may fallback either to parent feature or root selector.
584 $subfeature_selector = null;
585
586 // Use selectors API if available.
587 if ( $has_selectors ) {
588 $subfeature_selector = _wp_array_get( $block_type->selectors, $target, null );
589 }
590
591 // Only return if we have a subfeature selector.
592 if ( $subfeature_selector ) {
593 return $subfeature_selector;
594 }
595
596 // To this point we don't have a subfeature selector. If a fallback
597 // has been requested, remove subfeature from target path and return
598 // results of a call for the parent feature's selector.
599 if ( $fallback ) {
600 return wp_get_block_css_selector( $block_type, $target[0], $fallback );
601 }
602
603 return null;
604}
605