author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
18 | 1 |
<?php |
2 |
/** |
|
3 |
* Block Editor API. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Editor |
|
7 |
* @since 5.8.0 |
|
8 |
*/ |
|
9 |
||
10 |
/** |
|
11 |
* Returns the list of default categories for block types. |
|
12 |
* |
|
13 |
* @since 5.8.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
14 |
* @since 6.3.0 Reusable Blocks renamed to Patterns. |
18 | 15 |
* |
16 |
* @return array[] Array of categories for block types. |
|
17 |
*/ |
|
18 |
function get_default_block_categories() { |
|
19 |
return array( |
|
20 |
array( |
|
21 |
'slug' => 'text', |
|
22 |
'title' => _x( 'Text', 'block category' ), |
|
23 |
'icon' => null, |
|
24 |
), |
|
25 |
array( |
|
26 |
'slug' => 'media', |
|
27 |
'title' => _x( 'Media', 'block category' ), |
|
28 |
'icon' => null, |
|
29 |
), |
|
30 |
array( |
|
31 |
'slug' => 'design', |
|
32 |
'title' => _x( 'Design', 'block category' ), |
|
33 |
'icon' => null, |
|
34 |
), |
|
35 |
array( |
|
36 |
'slug' => 'widgets', |
|
37 |
'title' => _x( 'Widgets', 'block category' ), |
|
38 |
'icon' => null, |
|
39 |
), |
|
40 |
array( |
|
41 |
'slug' => 'theme', |
|
42 |
'title' => _x( 'Theme', 'block category' ), |
|
43 |
'icon' => null, |
|
44 |
), |
|
45 |
array( |
|
46 |
'slug' => 'embed', |
|
47 |
'title' => _x( 'Embeds', 'block category' ), |
|
48 |
'icon' => null, |
|
49 |
), |
|
50 |
array( |
|
51 |
'slug' => 'reusable', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
52 |
'title' => _x( 'Patterns', 'block category' ), |
18 | 53 |
'icon' => null, |
54 |
), |
|
55 |
); |
|
56 |
} |
|
57 |
||
58 |
/** |
|
59 |
* Returns all the categories for block types that will be shown in the block editor. |
|
60 |
* |
|
61 |
* @since 5.0.0 |
|
62 |
* @since 5.8.0 It is possible to pass the block editor context as param. |
|
63 |
* |
|
64 |
* @param WP_Post|WP_Block_Editor_Context $post_or_block_editor_context The current post object or |
|
65 |
* the block editor context. |
|
66 |
* |
|
67 |
* @return array[] Array of categories for block types. |
|
68 |
*/ |
|
69 |
function get_block_categories( $post_or_block_editor_context ) { |
|
70 |
$block_categories = get_default_block_categories(); |
|
71 |
$block_editor_context = $post_or_block_editor_context instanceof WP_Post ? |
|
72 |
new WP_Block_Editor_Context( |
|
73 |
array( |
|
74 |
'post' => $post_or_block_editor_context, |
|
75 |
) |
|
76 |
) : $post_or_block_editor_context; |
|
77 |
||
78 |
/** |
|
79 |
* Filters the default array of categories for block types. |
|
80 |
* |
|
81 |
* @since 5.8.0 |
|
82 |
* |
|
83 |
* @param array[] $block_categories Array of categories for block types. |
|
84 |
* @param WP_Block_Editor_Context $block_editor_context The current block editor context. |
|
85 |
*/ |
|
86 |
$block_categories = apply_filters( 'block_categories_all', $block_categories, $block_editor_context ); |
|
19 | 87 |
|
18 | 88 |
if ( ! empty( $block_editor_context->post ) ) { |
89 |
$post = $block_editor_context->post; |
|
90 |
||
91 |
/** |
|
92 |
* Filters the default array of categories for block types. |
|
93 |
* |
|
94 |
* @since 5.0.0 |
|
95 |
* @deprecated 5.8.0 Use the {@see 'block_categories_all'} filter instead. |
|
96 |
* |
|
97 |
* @param array[] $block_categories Array of categories for block types. |
|
98 |
* @param WP_Post $post Post being loaded. |
|
99 |
*/ |
|
100 |
$block_categories = apply_filters_deprecated( 'block_categories', array( $block_categories, $post ), '5.8.0', 'block_categories_all' ); |
|
101 |
} |
|
102 |
||
103 |
return $block_categories; |
|
104 |
} |
|
105 |
||
106 |
/** |
|
107 |
* Gets the list of allowed block types to use in the block editor. |
|
108 |
* |
|
109 |
* @since 5.8.0 |
|
110 |
* |
|
111 |
* @param WP_Block_Editor_Context $block_editor_context The current block editor context. |
|
112 |
* |
|
19 | 113 |
* @return bool|string[] Array of block type slugs, or boolean to enable/disable all. |
18 | 114 |
*/ |
115 |
function get_allowed_block_types( $block_editor_context ) { |
|
116 |
$allowed_block_types = true; |
|
117 |
||
118 |
/** |
|
119 |
* Filters the allowed block types for all editor types. |
|
120 |
* |
|
121 |
* @since 5.8.0 |
|
122 |
* |
|
19 | 123 |
* @param bool|string[] $allowed_block_types Array of block type slugs, or boolean to enable/disable all. |
18 | 124 |
* Default true (all registered block types supported). |
125 |
* @param WP_Block_Editor_Context $block_editor_context The current block editor context. |
|
126 |
*/ |
|
127 |
$allowed_block_types = apply_filters( 'allowed_block_types_all', $allowed_block_types, $block_editor_context ); |
|
19 | 128 |
|
18 | 129 |
if ( ! empty( $block_editor_context->post ) ) { |
130 |
$post = $block_editor_context->post; |
|
131 |
||
132 |
/** |
|
133 |
* Filters the allowed block types for the editor. |
|
134 |
* |
|
135 |
* @since 5.0.0 |
|
136 |
* @deprecated 5.8.0 Use the {@see 'allowed_block_types_all'} filter instead. |
|
137 |
* |
|
19 | 138 |
* @param bool|string[] $allowed_block_types Array of block type slugs, or boolean to enable/disable all. |
139 |
* Default true (all registered block types supported) |
|
140 |
* @param WP_Post $post The post resource data. |
|
18 | 141 |
*/ |
142 |
$allowed_block_types = apply_filters_deprecated( 'allowed_block_types', array( $allowed_block_types, $post ), '5.8.0', 'allowed_block_types_all' ); |
|
143 |
} |
|
144 |
||
145 |
return $allowed_block_types; |
|
146 |
} |
|
147 |
||
148 |
/** |
|
149 |
* Returns the default block editor settings. |
|
150 |
* |
|
151 |
* @since 5.8.0 |
|
152 |
* |
|
153 |
* @return array The default block editor settings. |
|
154 |
*/ |
|
155 |
function get_default_block_editor_settings() { |
|
156 |
// Media settings. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
157 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
158 |
// wp_max_upload_size() can be expensive, so only call it when relevant for the current user. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
159 |
$max_upload_size = 0; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
160 |
if ( current_user_can( 'upload_files' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
161 |
$max_upload_size = wp_max_upload_size(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
162 |
if ( ! $max_upload_size ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
163 |
$max_upload_size = 0; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
164 |
} |
18 | 165 |
} |
166 |
||
167 |
/** This filter is documented in wp-admin/includes/media.php */ |
|
168 |
$image_size_names = apply_filters( |
|
169 |
'image_size_names_choose', |
|
170 |
array( |
|
171 |
'thumbnail' => __( 'Thumbnail' ), |
|
172 |
'medium' => __( 'Medium' ), |
|
173 |
'large' => __( 'Large' ), |
|
174 |
'full' => __( 'Full Size' ), |
|
175 |
) |
|
176 |
); |
|
177 |
||
178 |
$available_image_sizes = array(); |
|
179 |
foreach ( $image_size_names as $image_size_slug => $image_size_name ) { |
|
180 |
$available_image_sizes[] = array( |
|
181 |
'slug' => $image_size_slug, |
|
182 |
'name' => $image_size_name, |
|
183 |
); |
|
184 |
} |
|
185 |
||
186 |
$default_size = get_option( 'image_default_size', 'large' ); |
|
187 |
$image_default_size = in_array( $default_size, array_keys( $image_size_names ), true ) ? $default_size : 'large'; |
|
188 |
||
189 |
$image_dimensions = array(); |
|
190 |
$all_sizes = wp_get_registered_image_subsizes(); |
|
191 |
foreach ( $available_image_sizes as $size ) { |
|
192 |
$key = $size['slug']; |
|
193 |
if ( isset( $all_sizes[ $key ] ) ) { |
|
194 |
$image_dimensions[ $key ] = $all_sizes[ $key ]; |
|
195 |
} |
|
196 |
} |
|
197 |
||
19 | 198 |
// These styles are used if the "no theme styles" options is triggered or on |
199 |
// themes without their own editor styles. |
|
200 |
$default_editor_styles_file = ABSPATH . WPINC . '/css/dist/block-editor/default-editor-styles.css'; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
201 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
202 |
static $default_editor_styles_file_contents = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
203 |
if ( ! $default_editor_styles_file_contents && file_exists( $default_editor_styles_file ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
204 |
$default_editor_styles_file_contents = file_get_contents( $default_editor_styles_file ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
205 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
206 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
207 |
$default_editor_styles = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
208 |
if ( $default_editor_styles_file_contents ) { |
19 | 209 |
$default_editor_styles = array( |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
210 |
array( 'css' => $default_editor_styles_file_contents ), |
19 | 211 |
); |
212 |
} |
|
213 |
||
18 | 214 |
$editor_settings = array( |
19 | 215 |
'alignWide' => get_theme_support( 'align-wide' ), |
216 |
'allowedBlockTypes' => true, |
|
217 |
'allowedMimeTypes' => get_allowed_mime_types(), |
|
218 |
'defaultEditorStyles' => $default_editor_styles, |
|
219 |
'blockCategories' => get_default_block_categories(), |
|
220 |
'isRTL' => is_rtl(), |
|
221 |
'imageDefaultSize' => $image_default_size, |
|
222 |
'imageDimensions' => $image_dimensions, |
|
223 |
'imageEditing' => true, |
|
224 |
'imageSizes' => $available_image_sizes, |
|
225 |
'maxUploadFileSize' => $max_upload_size, |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
226 |
'__experimentalDashboardLink' => admin_url( '/' ), |
19 | 227 |
// The following flag is required to enable the new Gallery block format on the mobile apps in 5.9. |
228 |
'__unstableGalleryWithImageBlocks' => true, |
|
18 | 229 |
); |
230 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
231 |
$theme_settings = get_classic_theme_supports_block_editor_settings(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
232 |
foreach ( $theme_settings as $key => $value ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
233 |
$editor_settings[ $key ] = $value; |
18 | 234 |
} |
235 |
||
236 |
return $editor_settings; |
|
237 |
} |
|
238 |
||
239 |
/** |
|
240 |
* Returns the block editor settings needed to use the Legacy Widget block which |
|
241 |
* is not registered by default. |
|
242 |
* |
|
243 |
* @since 5.8.0 |
|
244 |
* |
|
245 |
* @return array Settings to be used with get_block_editor_settings(). |
|
246 |
*/ |
|
247 |
function get_legacy_widget_block_editor_settings() { |
|
248 |
$editor_settings = array(); |
|
249 |
||
250 |
/** |
|
251 |
* Filters the list of widget-type IDs that should **not** be offered by the |
|
252 |
* Legacy Widget block. |
|
253 |
* |
|
254 |
* Returning an empty array will make all widgets available. |
|
255 |
* |
|
256 |
* @since 5.8.0 |
|
257 |
* |
|
19 | 258 |
* @param string[] $widgets An array of excluded widget-type IDs. |
18 | 259 |
*/ |
260 |
$editor_settings['widgetTypesToHideFromLegacyWidgetBlock'] = apply_filters( |
|
261 |
'widget_types_to_hide_from_legacy_widget_block', |
|
262 |
array( |
|
263 |
'pages', |
|
264 |
'calendar', |
|
265 |
'archives', |
|
266 |
'media_audio', |
|
267 |
'media_image', |
|
268 |
'media_gallery', |
|
269 |
'media_video', |
|
270 |
'search', |
|
271 |
'text', |
|
272 |
'categories', |
|
273 |
'recent-posts', |
|
274 |
'recent-comments', |
|
275 |
'rss', |
|
276 |
'tag_cloud', |
|
277 |
'custom_html', |
|
278 |
'block', |
|
279 |
) |
|
280 |
); |
|
281 |
||
282 |
return $editor_settings; |
|
283 |
} |
|
284 |
||
285 |
/** |
|
19 | 286 |
* Collect the block editor assets that need to be loaded into the editor's iframe. |
287 |
* |
|
288 |
* @since 6.0.0 |
|
289 |
* @access private |
|
290 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
291 |
* @global WP_Styles $wp_styles The WP_Styles current instance. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
292 |
* @global WP_Scripts $wp_scripts The WP_Scripts current instance. |
19 | 293 |
* |
294 |
* @return array { |
|
295 |
* The block editor assets. |
|
296 |
* |
|
297 |
* @type string|false $styles String containing the HTML for styles. |
|
298 |
* @type string|false $scripts String containing the HTML for scripts. |
|
299 |
* } |
|
300 |
*/ |
|
301 |
function _wp_get_iframed_editor_assets() { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
302 |
global $wp_styles, $wp_scripts; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
303 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
304 |
// Keep track of the styles and scripts instance to restore later. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
305 |
$current_wp_styles = $wp_styles; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
306 |
$current_wp_scripts = $wp_scripts; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
307 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
308 |
// Create new instances to collect the assets. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
309 |
$wp_styles = new WP_Styles(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
310 |
$wp_scripts = new WP_Scripts(); |
19 | 311 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
312 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
313 |
* Register all currently registered styles and scripts. The actions that |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
314 |
* follow enqueue assets, but don't necessarily register them. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
315 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
316 |
$wp_styles->registered = $current_wp_styles->registered; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
317 |
$wp_scripts->registered = $current_wp_scripts->registered; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
318 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
319 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
320 |
* We generally do not need reset styles for the iframed editor. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
321 |
* However, if it's a classic theme, margins will be added to every block, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
322 |
* which is reset specifically for list items, so classic themes rely on |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
323 |
* these reset styles. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
324 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
325 |
$wp_styles->done = |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
326 |
wp_theme_has_theme_json() ? array( 'wp-reset-editor-styles' ) : array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
327 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
328 |
wp_enqueue_script( 'wp-polyfill' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
329 |
// Enqueue the `editorStyle` handles for all core block, and dependencies. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
330 |
wp_enqueue_style( 'wp-edit-blocks' ); |
19 | 331 |
|
332 |
if ( current_theme_supports( 'wp-block-styles' ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
333 |
wp_enqueue_style( 'wp-block-library-theme' ); |
19 | 334 |
} |
335 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
336 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
337 |
* We don't want to load EDITOR scripts in the iframe, only enqueue |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
338 |
* front-end assets for the content. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
339 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
340 |
add_filter( 'should_load_block_editor_scripts_and_styles', '__return_false' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
341 |
do_action( 'enqueue_block_assets' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
342 |
remove_filter( 'should_load_block_editor_scripts_and_styles', '__return_false' ); |
19 | 343 |
|
344 |
$block_registry = WP_Block_Type_Registry::get_instance(); |
|
345 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
346 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
347 |
* Additionally, do enqueue `editorStyle` assets for all blocks, which |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
348 |
* contains editor-only styling for blocks (editor content). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
349 |
*/ |
19 | 350 |
foreach ( $block_registry->get_all_registered() as $block_type ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
351 |
if ( isset( $block_type->editor_style_handles ) && is_array( $block_type->editor_style_handles ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
352 |
foreach ( $block_type->editor_style_handles as $style_handle ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
353 |
wp_enqueue_style( $style_handle ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
354 |
} |
19 | 355 |
} |
356 |
} |
|
357 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
358 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
359 |
* Remove the deprecated `print_emoji_styles` handler. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
360 |
* It avoids breaking style generation with a deprecation message. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
361 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
362 |
$has_emoji_styles = has_action( 'wp_print_styles', 'print_emoji_styles' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
363 |
if ( $has_emoji_styles ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
364 |
remove_action( 'wp_print_styles', 'print_emoji_styles' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
365 |
} |
19 | 366 |
|
367 |
ob_start(); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
368 |
wp_print_styles(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
369 |
wp_print_font_faces(); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
370 |
wp_print_font_faces_from_style_variations(); |
19 | 371 |
$styles = ob_get_clean(); |
372 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
373 |
if ( $has_emoji_styles ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
374 |
add_action( 'wp_print_styles', 'print_emoji_styles' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
375 |
} |
19 | 376 |
|
377 |
ob_start(); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
378 |
wp_print_head_scripts(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
379 |
wp_print_footer_scripts(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
380 |
$scripts = ob_get_clean(); |
19 | 381 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
382 |
// Restore the original instances. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
383 |
$wp_styles = $current_wp_styles; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
384 |
$wp_scripts = $current_wp_scripts; |
19 | 385 |
|
386 |
return array( |
|
387 |
'styles' => $styles, |
|
388 |
'scripts' => $scripts, |
|
389 |
); |
|
390 |
} |
|
391 |
||
392 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
393 |
* Finds the first occurrence of a specific block in an array of blocks. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
394 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
395 |
* @since 6.3.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
396 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
397 |
* @param array $blocks Array of blocks. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
398 |
* @param string $block_name Name of the block to find. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
399 |
* @return array Found block, or empty array if none found. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
400 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
401 |
function wp_get_first_block( $blocks, $block_name ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
402 |
foreach ( $blocks as $block ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
403 |
if ( $block_name === $block['blockName'] ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
404 |
return $block; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
405 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
406 |
if ( ! empty( $block['innerBlocks'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
407 |
$found_block = wp_get_first_block( $block['innerBlocks'], $block_name ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
408 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
409 |
if ( ! empty( $found_block ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
410 |
return $found_block; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
411 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
412 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
413 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
414 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
415 |
return array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
416 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
417 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
418 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
419 |
* Retrieves Post Content block attributes from the current post template. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
420 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
421 |
* @since 6.3.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
422 |
* @since 6.4.0 Return null if there is no post content block. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
423 |
* @access private |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
424 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
425 |
* @global int $post_ID |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
426 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
427 |
* @return array|null Post Content block attributes array or null if Post Content block doesn't exist. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
428 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
429 |
function wp_get_post_content_block_attributes() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
430 |
global $post_ID; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
431 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
432 |
$is_block_theme = wp_is_block_theme(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
433 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
434 |
if ( ! $is_block_theme || ! $post_ID ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
435 |
return null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
436 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
437 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
438 |
$template_slug = get_page_template_slug( $post_ID ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
439 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
440 |
if ( ! $template_slug ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
441 |
$post_slug = 'singular'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
442 |
$page_slug = 'singular'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
443 |
$template_types = get_block_templates(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
444 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
445 |
foreach ( $template_types as $template_type ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
446 |
if ( 'page' === $template_type->slug ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
447 |
$page_slug = 'page'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
448 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
449 |
if ( 'single' === $template_type->slug ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
450 |
$post_slug = 'single'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
451 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
452 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
453 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
454 |
$what_post_type = get_post_type( $post_ID ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
455 |
switch ( $what_post_type ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
456 |
case 'page': |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
457 |
$template_slug = $page_slug; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
458 |
break; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
459 |
default: |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
460 |
$template_slug = $post_slug; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
461 |
break; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
462 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
463 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
464 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
465 |
$current_template = get_block_templates( array( 'slug__in' => array( $template_slug ) ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
466 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
467 |
if ( ! empty( $current_template ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
468 |
$template_blocks = parse_blocks( $current_template[0]->content ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
469 |
$post_content_block = wp_get_first_block( $template_blocks, 'core/post-content' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
470 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
471 |
if ( isset( $post_content_block['attrs'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
472 |
return $post_content_block['attrs']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
473 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
474 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
475 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
476 |
return null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
477 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
478 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
479 |
/** |
18 | 480 |
* Returns the contextualized block editor settings for a selected editor context. |
481 |
* |
|
482 |
* @since 5.8.0 |
|
483 |
* |
|
484 |
* @param array $custom_settings Custom settings to use with the given editor type. |
|
485 |
* @param WP_Block_Editor_Context $block_editor_context The current block editor context. |
|
486 |
* |
|
487 |
* @return array The contextualized block editor settings. |
|
488 |
*/ |
|
489 |
function get_block_editor_settings( array $custom_settings, $block_editor_context ) { |
|
490 |
$editor_settings = array_merge( |
|
491 |
get_default_block_editor_settings(), |
|
492 |
array( |
|
493 |
'allowedBlockTypes' => get_allowed_block_types( $block_editor_context ), |
|
494 |
'blockCategories' => get_block_categories( $block_editor_context ), |
|
495 |
), |
|
496 |
$custom_settings |
|
497 |
); |
|
498 |
||
19 | 499 |
$global_styles = array(); |
500 |
$presets = array( |
|
501 |
array( |
|
502 |
'css' => 'variables', |
|
503 |
'__unstableType' => 'presets', |
|
504 |
'isGlobalStyles' => true, |
|
505 |
), |
|
506 |
array( |
|
507 |
'css' => 'presets', |
|
508 |
'__unstableType' => 'presets', |
|
509 |
'isGlobalStyles' => true, |
|
510 |
), |
|
511 |
); |
|
512 |
foreach ( $presets as $preset_style ) { |
|
513 |
$actual_css = wp_get_global_stylesheet( array( $preset_style['css'] ) ); |
|
514 |
if ( '' !== $actual_css ) { |
|
515 |
$preset_style['css'] = $actual_css; |
|
516 |
$global_styles[] = $preset_style; |
|
517 |
} |
|
518 |
} |
|
18 | 519 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
520 |
if ( wp_theme_has_theme_json() ) { |
19 | 521 |
$block_classes = array( |
522 |
'css' => 'styles', |
|
523 |
'__unstableType' => 'theme', |
|
524 |
'isGlobalStyles' => true, |
|
18 | 525 |
); |
19 | 526 |
$actual_css = wp_get_global_stylesheet( array( $block_classes['css'] ) ); |
527 |
if ( '' !== $actual_css ) { |
|
528 |
$block_classes['css'] = $actual_css; |
|
529 |
$global_styles[] = $block_classes; |
|
530 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
531 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
532 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
533 |
* Add the custom CSS as a separate stylesheet so any invalid CSS |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
534 |
* entered by users does not break other global styles. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
535 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
536 |
$global_styles[] = array( |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
537 |
'css' => wp_get_global_stylesheet( array( 'custom-css' ) ), |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
538 |
'__unstableType' => 'user', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
539 |
'isGlobalStyles' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
540 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
541 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
542 |
// If there is no `theme.json` file, ensure base layout styles are still available. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
543 |
$block_classes = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
544 |
'css' => 'base-layout-styles', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
545 |
'__unstableType' => 'base-layout', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
546 |
'isGlobalStyles' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
547 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
548 |
$actual_css = wp_get_global_stylesheet( array( $block_classes['css'] ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
549 |
if ( '' !== $actual_css ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
550 |
$block_classes['css'] = $actual_css; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
551 |
$global_styles[] = $block_classes; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
552 |
} |
18 | 553 |
} |
554 |
||
19 | 555 |
$editor_settings['styles'] = array_merge( $global_styles, get_block_editor_theme_styles() ); |
556 |
||
557 |
$editor_settings['__experimentalFeatures'] = wp_get_global_settings(); |
|
18 | 558 |
// These settings may need to be updated based on data coming from theme.json sources. |
559 |
if ( isset( $editor_settings['__experimentalFeatures']['color']['palette'] ) ) { |
|
560 |
$colors_by_origin = $editor_settings['__experimentalFeatures']['color']['palette']; |
|
19 | 561 |
$editor_settings['colors'] = isset( $colors_by_origin['custom'] ) ? |
562 |
$colors_by_origin['custom'] : ( |
|
18 | 563 |
isset( $colors_by_origin['theme'] ) ? |
564 |
$colors_by_origin['theme'] : |
|
19 | 565 |
$colors_by_origin['default'] |
18 | 566 |
); |
567 |
} |
|
568 |
if ( isset( $editor_settings['__experimentalFeatures']['color']['gradients'] ) ) { |
|
569 |
$gradients_by_origin = $editor_settings['__experimentalFeatures']['color']['gradients']; |
|
19 | 570 |
$editor_settings['gradients'] = isset( $gradients_by_origin['custom'] ) ? |
571 |
$gradients_by_origin['custom'] : ( |
|
18 | 572 |
isset( $gradients_by_origin['theme'] ) ? |
573 |
$gradients_by_origin['theme'] : |
|
19 | 574 |
$gradients_by_origin['default'] |
18 | 575 |
); |
576 |
} |
|
577 |
if ( isset( $editor_settings['__experimentalFeatures']['typography']['fontSizes'] ) ) { |
|
578 |
$font_sizes_by_origin = $editor_settings['__experimentalFeatures']['typography']['fontSizes']; |
|
19 | 579 |
$editor_settings['fontSizes'] = isset( $font_sizes_by_origin['custom'] ) ? |
580 |
$font_sizes_by_origin['custom'] : ( |
|
18 | 581 |
isset( $font_sizes_by_origin['theme'] ) ? |
582 |
$font_sizes_by_origin['theme'] : |
|
19 | 583 |
$font_sizes_by_origin['default'] |
18 | 584 |
); |
585 |
} |
|
586 |
if ( isset( $editor_settings['__experimentalFeatures']['color']['custom'] ) ) { |
|
587 |
$editor_settings['disableCustomColors'] = ! $editor_settings['__experimentalFeatures']['color']['custom']; |
|
588 |
unset( $editor_settings['__experimentalFeatures']['color']['custom'] ); |
|
589 |
} |
|
590 |
if ( isset( $editor_settings['__experimentalFeatures']['color']['customGradient'] ) ) { |
|
591 |
$editor_settings['disableCustomGradients'] = ! $editor_settings['__experimentalFeatures']['color']['customGradient']; |
|
592 |
unset( $editor_settings['__experimentalFeatures']['color']['customGradient'] ); |
|
593 |
} |
|
594 |
if ( isset( $editor_settings['__experimentalFeatures']['typography']['customFontSize'] ) ) { |
|
595 |
$editor_settings['disableCustomFontSizes'] = ! $editor_settings['__experimentalFeatures']['typography']['customFontSize']; |
|
596 |
unset( $editor_settings['__experimentalFeatures']['typography']['customFontSize'] ); |
|
597 |
} |
|
19 | 598 |
if ( isset( $editor_settings['__experimentalFeatures']['typography']['lineHeight'] ) ) { |
599 |
$editor_settings['enableCustomLineHeight'] = $editor_settings['__experimentalFeatures']['typography']['lineHeight']; |
|
600 |
unset( $editor_settings['__experimentalFeatures']['typography']['lineHeight'] ); |
|
18 | 601 |
} |
602 |
if ( isset( $editor_settings['__experimentalFeatures']['spacing']['units'] ) ) { |
|
603 |
$editor_settings['enableCustomUnits'] = $editor_settings['__experimentalFeatures']['spacing']['units']; |
|
604 |
unset( $editor_settings['__experimentalFeatures']['spacing']['units'] ); |
|
605 |
} |
|
19 | 606 |
if ( isset( $editor_settings['__experimentalFeatures']['spacing']['padding'] ) ) { |
607 |
$editor_settings['enableCustomSpacing'] = $editor_settings['__experimentalFeatures']['spacing']['padding']; |
|
608 |
unset( $editor_settings['__experimentalFeatures']['spacing']['padding'] ); |
|
18 | 609 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
610 |
if ( isset( $editor_settings['__experimentalFeatures']['spacing']['customSpacingSize'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
611 |
$editor_settings['disableCustomSpacingSizes'] = ! $editor_settings['__experimentalFeatures']['spacing']['customSpacingSize']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
612 |
unset( $editor_settings['__experimentalFeatures']['spacing']['customSpacingSize'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
613 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
614 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
615 |
if ( isset( $editor_settings['__experimentalFeatures']['spacing']['spacingSizes'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
616 |
$spacing_sizes_by_origin = $editor_settings['__experimentalFeatures']['spacing']['spacingSizes']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
617 |
$editor_settings['spacingSizes'] = isset( $spacing_sizes_by_origin['custom'] ) ? |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
618 |
$spacing_sizes_by_origin['custom'] : ( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
619 |
isset( $spacing_sizes_by_origin['theme'] ) ? |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
620 |
$spacing_sizes_by_origin['theme'] : |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
621 |
$spacing_sizes_by_origin['default'] |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
622 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
623 |
} |
18 | 624 |
|
19 | 625 |
$editor_settings['__unstableResolvedAssets'] = _wp_get_iframed_editor_assets(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
626 |
$editor_settings['__unstableIsBlockBasedTheme'] = wp_is_block_theme(); |
19 | 627 |
$editor_settings['localAutosaveInterval'] = 15; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
628 |
$editor_settings['disableLayoutStyles'] = current_theme_supports( 'disable-layout-styles' ); |
19 | 629 |
$editor_settings['__experimentalDiscussionSettings'] = array( |
630 |
'commentOrder' => get_option( 'comment_order' ), |
|
631 |
'commentsPerPage' => get_option( 'comments_per_page' ), |
|
632 |
'defaultCommentsPage' => get_option( 'default_comments_page' ), |
|
633 |
'pageComments' => get_option( 'page_comments' ), |
|
634 |
'threadComments' => get_option( 'thread_comments' ), |
|
635 |
'threadCommentsDepth' => get_option( 'thread_comments_depth' ), |
|
636 |
'defaultCommentStatus' => get_option( 'default_comment_status' ), |
|
637 |
'avatarURL' => get_avatar_url( |
|
638 |
'', |
|
639 |
array( |
|
640 |
'size' => 96, |
|
641 |
'force_default' => true, |
|
642 |
'default' => get_option( 'avatar_default' ), |
|
643 |
) |
|
644 |
), |
|
645 |
); |
|
646 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
647 |
$post_content_block_attributes = wp_get_post_content_block_attributes(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
648 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
649 |
if ( isset( $post_content_block_attributes ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
650 |
$editor_settings['postContentAttributes'] = $post_content_block_attributes; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
651 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
652 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
653 |
$editor_settings['canUpdateBlockBindings'] = current_user_can( 'edit_block_binding', $block_editor_context ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
654 |
|
18 | 655 |
/** |
656 |
* Filters the settings to pass to the block editor for all editor type. |
|
657 |
* |
|
658 |
* @since 5.8.0 |
|
659 |
* |
|
660 |
* @param array $editor_settings Default editor settings. |
|
661 |
* @param WP_Block_Editor_Context $block_editor_context The current block editor context. |
|
662 |
*/ |
|
663 |
$editor_settings = apply_filters( 'block_editor_settings_all', $editor_settings, $block_editor_context ); |
|
19 | 664 |
|
18 | 665 |
if ( ! empty( $block_editor_context->post ) ) { |
666 |
$post = $block_editor_context->post; |
|
667 |
||
668 |
/** |
|
669 |
* Filters the settings to pass to the block editor. |
|
670 |
* |
|
671 |
* @since 5.0.0 |
|
672 |
* @deprecated 5.8.0 Use the {@see 'block_editor_settings_all'} filter instead. |
|
673 |
* |
|
674 |
* @param array $editor_settings Default editor settings. |
|
675 |
* @param WP_Post $post Post being edited. |
|
676 |
*/ |
|
677 |
$editor_settings = apply_filters_deprecated( 'block_editor_settings', array( $editor_settings, $post ), '5.8.0', 'block_editor_settings_all' ); |
|
678 |
} |
|
679 |
||
680 |
return $editor_settings; |
|
681 |
} |
|
682 |
||
683 |
/** |
|
684 |
* Preloads common data used with the block editor by specifying an array of |
|
685 |
* REST API paths that will be preloaded for a given block editor context. |
|
686 |
* |
|
687 |
* @since 5.8.0 |
|
688 |
* |
|
19 | 689 |
* @global WP_Post $post Global post object. |
690 |
* @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. |
|
691 |
* @global WP_Styles $wp_styles The WP_Styles object for printing styles. |
|
18 | 692 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
693 |
* @param (string|string[])[] $preload_paths List of paths to preload. |
18 | 694 |
* @param WP_Block_Editor_Context $block_editor_context The current block editor context. |
695 |
*/ |
|
696 |
function block_editor_rest_api_preload( array $preload_paths, $block_editor_context ) { |
|
19 | 697 |
global $post, $wp_scripts, $wp_styles; |
18 | 698 |
|
699 |
/** |
|
700 |
* Filters the array of REST API paths that will be used to preloaded common data for the block editor. |
|
701 |
* |
|
702 |
* @since 5.8.0 |
|
703 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
704 |
* @param (string|string[])[] $preload_paths Array of paths to preload. |
19 | 705 |
* @param WP_Block_Editor_Context $block_editor_context The current block editor context. |
18 | 706 |
*/ |
707 |
$preload_paths = apply_filters( 'block_editor_rest_api_preload_paths', $preload_paths, $block_editor_context ); |
|
19 | 708 |
|
18 | 709 |
if ( ! empty( $block_editor_context->post ) ) { |
710 |
$selected_post = $block_editor_context->post; |
|
711 |
||
712 |
/** |
|
713 |
* Filters the array of paths that will be preloaded. |
|
714 |
* |
|
715 |
* Preload common data by specifying an array of REST API paths that will be preloaded. |
|
716 |
* |
|
717 |
* @since 5.0.0 |
|
718 |
* @deprecated 5.8.0 Use the {@see 'block_editor_rest_api_preload_paths'} filter instead. |
|
719 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
720 |
* @param (string|string[])[] $preload_paths Array of paths to preload. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
721 |
* @param WP_Post $selected_post Post being edited. |
18 | 722 |
*/ |
723 |
$preload_paths = apply_filters_deprecated( 'block_editor_preload_paths', array( $preload_paths, $selected_post ), '5.8.0', 'block_editor_rest_api_preload_paths' ); |
|
724 |
} |
|
725 |
||
726 |
if ( empty( $preload_paths ) ) { |
|
727 |
return; |
|
728 |
} |
|
729 |
||
730 |
/* |
|
19 | 731 |
* Ensure the global $post, $wp_scripts, and $wp_styles remain the same after |
732 |
* API data is preloaded. |
|
18 | 733 |
* Because API preloading can call the_content and other filters, plugins |
19 | 734 |
* can unexpectedly modify the global $post or enqueue assets which are not |
735 |
* intended for the block editor. |
|
18 | 736 |
*/ |
737 |
$backup_global_post = ! empty( $post ) ? clone $post : $post; |
|
19 | 738 |
$backup_wp_scripts = ! empty( $wp_scripts ) ? clone $wp_scripts : $wp_scripts; |
739 |
$backup_wp_styles = ! empty( $wp_styles ) ? clone $wp_styles : $wp_styles; |
|
740 |
||
741 |
foreach ( $preload_paths as &$path ) { |
|
742 |
if ( is_string( $path ) && ! str_starts_with( $path, '/' ) ) { |
|
743 |
$path = '/' . $path; |
|
744 |
continue; |
|
745 |
} |
|
746 |
||
747 |
if ( is_array( $path ) && is_string( $path[0] ) && ! str_starts_with( $path[0], '/' ) ) { |
|
748 |
$path[0] = '/' . $path[0]; |
|
749 |
} |
|
750 |
} |
|
751 |
||
752 |
unset( $path ); |
|
18 | 753 |
|
754 |
$preload_data = array_reduce( |
|
755 |
$preload_paths, |
|
756 |
'rest_preload_api_request', |
|
757 |
array() |
|
758 |
); |
|
759 |
||
19 | 760 |
// Restore the global $post, $wp_scripts, and $wp_styles as they were before API preloading. |
761 |
$post = $backup_global_post; |
|
762 |
$wp_scripts = $backup_wp_scripts; |
|
763 |
$wp_styles = $backup_wp_styles; |
|
18 | 764 |
|
765 |
wp_add_inline_script( |
|
766 |
'wp-api-fetch', |
|
767 |
sprintf( |
|
768 |
'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );', |
|
769 |
wp_json_encode( $preload_data ) |
|
770 |
), |
|
771 |
'after' |
|
772 |
); |
|
773 |
} |
|
774 |
||
775 |
/** |
|
776 |
* Creates an array of theme styles to load into the block editor. |
|
777 |
* |
|
778 |
* @since 5.8.0 |
|
779 |
* |
|
780 |
* @global array $editor_styles |
|
781 |
* |
|
19 | 782 |
* @return array An array of theme styles for the block editor. |
18 | 783 |
*/ |
784 |
function get_block_editor_theme_styles() { |
|
785 |
global $editor_styles; |
|
786 |
||
19 | 787 |
$styles = array(); |
18 | 788 |
|
789 |
if ( $editor_styles && current_theme_supports( 'editor-styles' ) ) { |
|
790 |
foreach ( $editor_styles as $style ) { |
|
791 |
if ( preg_match( '~^(https?:)?//~', $style ) ) { |
|
792 |
$response = wp_remote_get( $style ); |
|
793 |
if ( ! is_wp_error( $response ) ) { |
|
794 |
$styles[] = array( |
|
795 |
'css' => wp_remote_retrieve_body( $response ), |
|
796 |
'__unstableType' => 'theme', |
|
19 | 797 |
'isGlobalStyles' => false, |
18 | 798 |
); |
799 |
} |
|
800 |
} else { |
|
801 |
$file = get_theme_file_path( $style ); |
|
802 |
if ( is_file( $file ) ) { |
|
803 |
$styles[] = array( |
|
804 |
'css' => file_get_contents( $file ), |
|
805 |
'baseURL' => get_theme_file_uri( $style ), |
|
806 |
'__unstableType' => 'theme', |
|
19 | 807 |
'isGlobalStyles' => false, |
18 | 808 |
); |
809 |
} |
|
810 |
} |
|
811 |
} |
|
812 |
} |
|
813 |
||
814 |
return $styles; |
|
815 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
816 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
817 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
818 |
* Returns the classic theme supports settings for block editor. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
819 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
820 |
* @since 6.2.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
821 |
* @since 6.6.0 Add support for 'editor-spacing-sizes' theme support. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
822 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
823 |
* @return array The classic theme supports settings. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
824 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
825 |
function get_classic_theme_supports_block_editor_settings() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
826 |
$theme_settings = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
827 |
'disableCustomColors' => get_theme_support( 'disable-custom-colors' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
828 |
'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
829 |
'disableCustomGradients' => get_theme_support( 'disable-custom-gradients' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
830 |
'disableLayoutStyles' => get_theme_support( 'disable-layout-styles' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
831 |
'enableCustomLineHeight' => get_theme_support( 'custom-line-height' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
832 |
'enableCustomSpacing' => get_theme_support( 'custom-spacing' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
833 |
'enableCustomUnits' => get_theme_support( 'custom-units' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
834 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
835 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
836 |
// Theme settings. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
837 |
$color_palette = current( (array) get_theme_support( 'editor-color-palette' ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
838 |
if ( false !== $color_palette ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
839 |
$theme_settings['colors'] = $color_palette; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
840 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
841 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
842 |
$font_sizes = current( (array) get_theme_support( 'editor-font-sizes' ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
843 |
if ( false !== $font_sizes ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
844 |
$theme_settings['fontSizes'] = $font_sizes; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
845 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
846 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
847 |
$gradient_presets = current( (array) get_theme_support( 'editor-gradient-presets' ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
848 |
if ( false !== $gradient_presets ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
849 |
$theme_settings['gradients'] = $gradient_presets; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
850 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
851 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
852 |
$spacing_sizes = current( (array) get_theme_support( 'editor-spacing-sizes' ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
853 |
if ( false !== $spacing_sizes ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
854 |
$theme_settings['spacingSizes'] = $spacing_sizes; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
855 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
856 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
857 |
return $theme_settings; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
858 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
859 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
860 |
/** |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
861 |
* Initialize site preview. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
862 |
* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
863 |
* This function sets IFRAME_REQUEST to true if the site preview parameter is set. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
864 |
* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
865 |
* @since 6.8.0 |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
866 |
*/ |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
867 |
function wp_initialize_site_preview_hooks() { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
868 |
if ( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
869 |
! defined( 'IFRAME_REQUEST' ) && |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
870 |
isset( $_GET['wp_site_preview'] ) && |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
871 |
1 === (int) $_GET['wp_site_preview'] && |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
872 |
current_user_can( 'edit_theme_options' ) |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
873 |
) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
874 |
define( 'IFRAME_REQUEST', true ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
875 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
876 |
} |