PluginProbe
Gutenberg / 14.5.2
Gutenberg v14.5.2
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
← All changes | lib/experimental/class-wp-rest-block-editor-settings-controller.php +251 -612 23.4.0 → 14.5.2 View file →
@@ -5,667 +5,306 @@
5 5 * @package WordPress
6 6 * @subpackage REST_API
7 7 */
8 8
9 -if ( ! class_exists( 'WP_REST_Block_Editor_Settings_Controller' ) ) {
9 +/**
10 + * Core class used to retrieve the block editor settings via the REST API.
11 + *
12 + * @see WP_REST_Controller
13 + */
14 +class WP_REST_Block_Editor_Settings_Controller extends WP_REST_Controller {
15 + /**
16 + * Constructs the controller.
17 + */
18 + public function __construct() {
19 + $this->namespace = 'wp-block-editor/v1';
20 + $this->rest_base = 'settings';
21 + }
10 22
11 23 /**
12 - * Core class used to retrieve the block editor settings via the REST API.
13 - *
14 - * @see WP_REST_Controller
24 + * Registers the necessary REST API routes.
15 25 */
16 - class WP_REST_Block_Editor_Settings_Controller extends WP_REST_Controller {
17 - /**
18 - * Constructs the controller.
19 - */
20 - public function __construct() {
21 - $this->namespace = 'wp-block-editor/v1';
22 - $this->rest_base = 'settings';
23 - }
24 -
25 - /**
26 - * Registers the necessary REST API routes.
27 - */
28 - public function register_routes() {
29 - register_rest_route(
30 - $this->namespace,
31 - '/' . $this->rest_base,
26 + public function register_routes() {
27 + register_rest_route(
28 + $this->namespace,
29 + '/' . $this->rest_base,
30 + array(
32 31 array(
33 - array(
34 - 'methods' => WP_REST_Server::READABLE,
35 - 'callback' => array( $this, 'get_items' ),
36 - 'permission_callback' => array( $this, 'get_items_permissions_check' ),
37 - ),
38 - 'schema' => array( $this, 'get_public_item_schema' ),
39 - )
40 - );
32 + 'methods' => WP_REST_Server::READABLE,
33 + 'callback' => array( $this, 'get_items' ),
34 + 'permission_callback' => array( $this, 'get_items_permissions_check' ),
35 + ),
36 + 'schema' => array( $this, 'get_public_item_schema' ),
37 + )
38 + );
39 + }
41 40
42 - register_rest_route(
43 - $this->namespace,
44 - '/assets',
45 - array(
46 - array(
47 - 'methods' => WP_REST_Server::READABLE,
48 - 'callback' => array( $this, 'get_assets' ),
49 - 'permission_callback' => array( $this, 'get_items_permissions_check' ),
50 - ),
51 - 'schema' => array( $this, 'get_assets_schema' ),
52 - )
53 - );
41 + /**
42 + * Checks whether a given request has permission to read block editor settings
43 + *
44 + * @since 5.8.0
45 + *
46 + * @param WP_REST_Request $request Full details about the request.
47 + *
48 + * @return WP_Error|bool True if the request has permission, WP_Error object otherwise.
49 + */
50 + public function get_items_permissions_check( $request ) {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
51 + if ( current_user_can( 'edit_posts' ) ) {
52 + return true;
54 53 }
55 54
56 - /**
57 - * Checks whether a given request has permission to read block editor settings
58 - *
59 - * @since 5.8.0
60 - *
61 - * @param WP_REST_Request $request Full details about the request.
62 - *
63 - * @return WP_Error|bool True if the request has permission, WP_Error object otherwise.
64 - */
65 - public function get_items_permissions_check( $request ) {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
66 - if ( current_user_can( 'edit_posts' ) ) {
55 + foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
56 + if ( current_user_can( $post_type->cap->edit_posts ) ) {
67 57 return true;
68 58 }
69 -
70 - foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
71 - if ( current_user_can( $post_type->cap->edit_posts ) ) {
72 - return true;
73 - }
74 - }
75 -
76 - return new WP_Error(
77 - 'rest_cannot_read_block_editor_settings',
78 - __( 'Sorry, you are not allowed to read the block editor settings.', 'gutenberg' ),
79 - array( 'status' => rest_authorization_required_code() )
80 - );
81 59 }
82 60
83 - /**
84 - * Returns the block editor's settings
85 - *
86 - * @since 5.8.0
87 - *
88 - * @param WP_REST_Request $request Full details about the request.
89 - *
90 - * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure.
91 - */
92 - public function get_items( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis
93 - // Simplified context handling: mobile vs default.
94 - // Only 'mobile' context is special; everything else uses the default editor context.
95 - $context_param = $request->get_param( 'context' );
96 - $editor_context_name = 'mobile' === $context_param ? 'core/mobile' : 'core/edit-post';
61 + return new WP_Error(
62 + 'rest_cannot_read_block_editor_settings',
63 + __( 'Sorry, you are not allowed to read the block editor settings.', 'gutenberg' ),
64 + array( 'status' => rest_authorization_required_code() )
65 + );
66 + }
97 67
98 - // Apply mobile-specific settings filter only for mobile context.
99 - if ( 'mobile' === $context_param ) {
100 - add_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings_mobile', PHP_INT_MAX );
101 - }
102 -
103 - $editor_context = new WP_Block_Editor_Context( array( 'name' => $editor_context_name ) );
104 - $settings = get_block_editor_settings( array(), $editor_context );
105 -
106 - if ( 'mobile' === $context_param ) {
107 - remove_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings_mobile', PHP_INT_MAX );
108 - }
109 -
110 - return rest_ensure_response( $settings );
68 + /**
69 + * Returns the block editor's settings
70 + *
71 + * @since 5.8.0
72 + *
73 + * @param WP_REST_Request $request Full details about the request.
74 + *
75 + * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure.
76 + */
77 + public function get_items( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis
78 + switch ( $request['context'] ) {
79 + case 'post-editor':
80 + default:
81 + $editor_context_name = 'core/edit-post';
82 + break;
83 + case 'widgets-editor':
84 + $editor_context_name = 'core/edit-widgets';
85 + break;
86 + case 'site-editor':
87 + $editor_context_name = 'core/edit-site';
88 + break;
89 + case 'mobile':
90 + $editor_context_name = 'core/mobile';
91 + break;
111 92 }
112 93
113 - /**
114 - * Retrieves the block editor's settings schema, conforming to JSON Schema.
115 - *
116 - * @since 5.8.0
117 - *
118 - * @return array Item schema data.
119 - */
120 - public function get_item_schema() {
121 - if ( $this->schema ) {
122 - return $this->add_additional_fields_schema( $this->schema );
123 - }
94 + $editor_context = new WP_Block_Editor_Context( array( 'name' => $editor_context_name ) );
95 + $settings = get_block_editor_settings( array(), $editor_context );
124 96
125 - $schema = array(
126 - '$schema' => 'http://json-schema.org/draft-04/schema#',
127 - 'title' => 'block-editor-settings-item',
128 - 'type' => 'object',
129 - 'properties' => array(
130 - '__unstableEnableFullSiteEditingBlocks' => array(
131 - 'description' => __( 'Enables experimental Site Editor blocks', 'gutenberg' ),
132 - 'type' => 'boolean',
133 - 'context' => array( 'default' ),
134 - ),
97 + return rest_ensure_response( $settings );
98 + }
135 99
136 - 'styles' => array(
137 - 'description' => __( 'Editor styles', 'gutenberg' ),
138 - 'type' => 'array',
139 - 'context' => array( 'default' ),
140 - ),
141 -
142 - 'supportsTemplateMode' => array(
143 - 'description' => __( 'Indicates whether the current theme supports block-based templates.', 'gutenberg' ),
144 - 'type' => 'boolean',
145 - 'context' => array( 'default' ),
146 - ),
147 -
148 - 'supportsLayout' => array(
149 - 'description' => __( 'Enable/disable layouts support in container blocks.', 'gutenberg' ),
150 - 'type' => 'boolean',
151 - 'context' => array( 'default' ),
152 - ),
153 -
154 - 'widgetTypesToHideFromLegacyWidgetBlock' => array(
155 - 'description' => __( 'Widget types to hide from Legacy Widget block.', 'gutenberg' ),
156 - 'type' => 'array',
157 - 'context' => array( 'default' ),
158 - ),
159 -
160 - '__experimentalFeatures' => array(
161 - 'description' => __( 'Settings consolidated from core, theme, and user origins.', 'gutenberg' ),
162 - 'type' => 'object',
163 - 'context' => array( 'default', 'mobile' ),
164 - ),
165 -
166 - '__experimentalStyles' => array(
167 - 'description' => __( 'Styles consolidated from core, theme, and user origins.', 'gutenberg' ),
168 - 'type' => 'object',
169 - 'context' => array( 'mobile' ),
170 - ),
171 -
172 - '__experimentalEnableQuoteBlockV2' => array(
173 - 'description' => __( 'Whether the V2 of the quote block that uses inner blocks should be enabled.', 'gutenberg' ),
174 - 'type' => 'boolean',
175 - 'context' => array( 'mobile' ),
176 - ),
177 -
178 - '__experimentalEnableListBlockV2' => array(
179 - 'description' => __( 'Whether the V2 of the list block that uses inner blocks should be enabled.', 'gutenberg' ),
180 - 'type' => 'boolean',
181 - 'context' => array( 'mobile' ),
182 - ),
183 -
184 - 'alignWide' => array(
185 - 'description' => __( 'Enable/Disable Wide/Full Alignments.', 'gutenberg' ),
186 - 'type' => 'boolean',
187 - 'context' => array( 'default' ),
188 - ),
189 -
190 - 'allowedBlockTypes' => array(
191 - 'description' => __( 'List of allowed block types.', 'gutenberg' ),
192 - 'type' => 'boolean',
193 - 'context' => array( 'default' ),
194 - ),
195 -
196 - 'allowedMimeTypes' => array(
197 - 'description' => __( 'List of allowed mime types and file extensions.', 'gutenberg' ),
198 - 'type' => 'object',
199 - 'context' => array( 'default' ),
200 - ),
201 -
202 - 'blockCategories' => array(
203 - 'description' => __( 'Returns all the categories for block types that will be shown in the block editor.', 'gutenberg' ),
204 - 'type' => 'array',
205 - 'context' => array( 'default' ),
206 - ),
207 -
208 - 'blockInspectorTabs' => array(
209 - 'description' => __( 'Block inspector tab display overrides.', 'gutenberg' ),
210 - 'type' => 'object',
211 - 'context' => array( 'default' ),
212 - ),
213 -
214 - 'disableCustomColors' => array(
215 - 'description' => __( 'Disables custom colors.', 'gutenberg' ),
216 - 'type' => 'boolean',
217 - 'context' => array( 'default' ),
218 - ),
219 -
220 - 'disableCustomFontSizes' => array(
221 - 'description' => __( 'Disables custom font size.', 'gutenberg' ),
222 - 'type' => 'boolean',
223 - 'context' => array( 'default' ),
224 - ),
225 -
226 - 'disableCustomGradients' => array(
227 - 'description' => __( 'Disables custom font size.', 'gutenberg' ),
228 - 'type' => 'boolean',
229 - 'context' => array( 'default' ),
230 - ),
231 -
232 - 'disableLayoutStyles' => array(
233 - 'description' => __( 'Disables output of layout styles.', 'gutenberg' ),
234 - 'type' => 'boolean',
235 - 'context' => array( 'default' ),
236 - ),
237 -
238 - 'enableCustomLineHeight' => array(
239 - 'description' => __( 'Enables custom line height.', 'gutenberg' ),
240 - 'type' => 'boolean',
241 - 'context' => array( 'default' ),
242 - ),
243 -
244 - 'enableCustomSpacing' => array(
245 - 'description' => __( 'Enables custom spacing.', 'gutenberg' ),
246 - 'type' => 'boolean',
247 - 'context' => array( 'default' ),
248 - ),
249 -
250 - 'enableCustomUnits' => array(
251 - 'description' => __( 'Enables custom units.', 'gutenberg' ),
252 - 'type' => 'boolean',
253 - 'context' => array( 'default' ),
254 - ),
255 -
256 - 'isRTL' => array(
257 - 'description' => __( 'Determines whether the current locale is right-to-left (RTL).', 'gutenberg' ),
258 - 'type' => 'boolean',
259 - 'context' => array( 'default' ),
260 - ),
261 -
262 - 'imageDefaultSize' => array(
263 - 'description' => __( 'Default size for images.', 'gutenberg' ),
264 - 'type' => 'string',
265 - 'context' => array( 'default' ),
266 - ),
267 -
268 - 'imageDimensions' => array(
269 - 'description' => __( 'Available image dimensions.', 'gutenberg' ),
270 - 'type' => 'object',
271 - 'context' => array( 'default' ),
272 - ),
273 -
274 - 'imageEditing' => array(
275 - 'description' => __( 'Determines whether the image editing feature is enabled.', 'gutenberg' ),
276 - 'type' => 'boolean',
277 - 'context' => array( 'default' ),
278 - ),
279 -
280 - 'imageSizes' => array(
281 - 'description' => __( 'Available image sizes.', 'gutenberg' ),
282 - 'type' => 'array',
283 - 'context' => array( 'default' ),
284 - ),
285 -
286 - 'maxUploadFileSize' => array(
287 - 'description' => __( 'Maximum upload size in bytes allowed for the site.', 'gutenberg' ),
288 - 'type' => 'number',
289 - 'context' => array( 'default' ),
290 - ),
291 -
292 - 'colors' => array(
293 - 'description' => __( 'Active theme color palette.', 'gutenberg' ),
294 - 'type' => 'array',
295 - 'context' => array( 'default' ),
296 - ),
297 -
298 - 'fontSizes' => array(
299 - 'description' => __( 'Active theme font sizes.', 'gutenberg' ),
300 - 'type' => 'array',
301 - 'context' => array( 'default' ),
302 - ),
303 -
304 - 'gradients' => array(
305 - 'description' => __( 'Active theme gradients.', 'gutenberg' ),
306 - 'type' => 'array',
307 - 'context' => array( 'default' ),
308 - ),
309 - 'spacingSizes' => array(
310 - 'description' => __( 'Active theme spacing sizes.', 'gutenberg' ),
311 - 'type' => 'array',
312 - 'context' => array( 'default' ),
313 - ),
314 - 'spacingScale' => array(
315 - 'description' => __( 'Active theme spacing scale.', 'gutenberg' ),
316 - 'type' => 'array',
317 - 'context' => array( 'default' ),
318 - ),
319 - 'disableCustomSpacingSizes' => array(
320 - 'description' => __( 'Disables custom spacing sizes.', 'gutenberg' ),
321 - 'type' => 'boolean',
322 - 'context' => array( 'default' ),
323 - ),
324 - ),
325 - );
326 -
327 - $this->schema = $schema;
328 -
100 + /**
101 + * Retrieves the block editor's settings schema, conforming to JSON Schema.
102 + *
103 + * @since 5.8.0
104 + *
105 + * @return array Item schema data.
106 + */
107 + public function get_item_schema() {
108 + if ( $this->schema ) {
329 109 return $this->add_additional_fields_schema( $this->schema );
330 110 }
331 111
332 - /**
333 - * Retrieves editor assets (scripts, styles, and inline content).
334 - *
335 - * @since Gutenberg 5.8.0
336 - *
337 - * @param WP_REST_Request $request Full details about the request.
338 - * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
339 - */
340 - public function get_assets( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
341 - // Load WordPress admin environment.
342 - $this->load_admin_environment();
112 + $this->schema = array(
113 + '$schema' => 'http://json-schema.org/draft-04/schema#',
114 + 'title' => 'block-editor-settings-item',
115 + 'type' => 'object',
116 + 'properties' => array(
117 + '__unstableEnableFullSiteEditingBlocks' => array(
118 + 'description' => __( 'Enables experimental Full Site Editing blocks', 'gutenberg' ),
119 + 'type' => 'boolean',
120 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
121 + ),
343 122
344 - // Set up the block editor context.
345 - set_current_screen();
346 - $current_screen = get_current_screen();
347 - if ( $current_screen ) {
348 - $current_screen->is_block_editor( true );
349 - }
123 + 'styles' => array(
124 + 'description' => __( 'Editor styles', 'gutenberg' ),
125 + 'type' => 'array',
126 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
127 + ),
350 128
351 - // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
352 - $hook_suffix = 'block-editor-assets';
129 + 'supportsTemplateMode' => array(
130 + 'description' => __( 'Returns if the current theme is full site editing-enabled or not.', 'gutenberg' ),
131 + 'type' => 'boolean',
132 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
133 + ),
353 134
354 - // Remove unwanted scripts/styles.
355 - remove_action( 'admin_enqueue_scripts', 'gutenberg_enqueue_command_palette_assets', 9 );
356 - remove_action( 'admin_enqueue_scripts', 'gutenberg_enqueue_command_palette_assets' );
357 - remove_action( 'admin_enqueue_scripts', 'wp_auth_check_load' );
358 - remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
359 - remove_action( 'admin_print_styles', 'print_emoji_styles' );
135 + 'supportsLayout' => array(
136 + 'description' => __( 'Enable/disable layouts support in container blocks.', 'gutenberg' ),
137 + 'type' => 'boolean',
138 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
139 + ),
360 140
361 - // Preload blocks - this creates inline scripts.
362 - $server_block_settings = get_block_editor_server_block_settings();
363 - wp_add_inline_script(
364 - 'wp-block-library',
365 - 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( $server_block_settings, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) . ');',
366 - 'before'
367 - );
141 + 'widgetTypesToHideFromLegacyWidgetBlock' => array(
142 + 'description' => __( 'Widget types to hide from Legacy Widget block.', 'gutenberg' ),
143 + 'type' => 'array',
144 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
145 + ),
368 146
369 - // Preload server-registered block bindings sources.
370 - $registered_sources = get_all_registered_block_bindings_sources();
371 - if ( ! empty( $registered_sources ) ) {
372 - $filtered_sources = array();
373 - foreach ( $registered_sources as $source ) {
374 - $filtered_sources[] = array(
375 - 'name' => $source->name,
376 - 'label' => $source->label,
377 - 'usesContext' => $source->uses_context,
378 - );
379 - }
380 - $script = sprintf( 'for ( const source of %s ) { wp.blocks.registerBlockBindingsSource( source ); }', wp_json_encode( $filtered_sources, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) );
381 - wp_add_inline_script(
382 - 'wp-block-library',
383 - $script,
384 - 'before'
385 - );
386 - }
147 + '__experimentalFeatures' => array(
148 + 'description' => __( 'Settings consolidated from core, theme, and user origins.', 'gutenberg' ),
149 + 'type' => 'object',
150 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor', 'mobile' ),
151 + ),
387 152
388 - $load_blocks_scripts = 'wp.blockLibrary.registerCoreBlocks( wp.blockLibrary.__experimentalGetCoreBlocks().filter( ( block ) => block.name !== "core/freeform" ) );';
389 - wp_add_inline_script(
390 - 'wp-block-library',
391 - $load_blocks_scripts,
392 - 'after'
393 - );
153 + '__experimentalStyles' => array(
154 + 'description' => __( 'Styles consolidated from core, theme, and user origins.', 'gutenberg' ),
155 + 'type' => 'object',
156 + 'context' => array( 'mobile' ),
157 + ),
394 158
395 - // Enqueue editor assets.
396 - wp_enqueue_script( 'wp-format-library' );
397 - wp_enqueue_script( 'wp-block-library' );
398 - wp_enqueue_style( 'wp-editor' );
399 - wp_enqueue_style( 'wp-block-library' );
400 - wp_enqueue_style( 'wp-format-library' );
401 - wp_enqueue_media();
159 + '__experimentalEnableQuoteBlockV2' => array(
160 + 'description' => __( 'Whether the V2 of the quote block that uses inner blocks should be enabled.', 'gutenberg' ),
161 + 'type' => 'boolean',
162 + 'context' => array( 'mobile' ),
163 + ),
402 164
403 - do_action( 'enqueue_block_editor_assets' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
165 + '__experimentalEnableListBlockV2' => array(
166 + 'description' => __( 'Whether the V2 of the list block that uses inner blocks should be enabled.', 'gutenberg' ),
167 + 'type' => 'boolean',
168 + 'context' => array( 'mobile' ),
169 + ),
404 170
405 - // Never allow old admin styles as a dependency.
406 - wp_deregister_style( 'common' );
407 - wp_deregister_style( 'forms' );
171 + 'alignWide' => array(
172 + 'description' => __( 'Enable/Disable Wide/Full Alignments.', 'gutenberg' ),
173 + 'type' => 'boolean',
174 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
175 + ),
408 176
409 - // Trigger rendering hooks to capture all assets.
410 - ob_start();
411 - do_action( 'admin_enqueue_scripts', $hook_suffix ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
412 - do_action( "admin_print_styles-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
413 - do_action( 'admin_print_styles' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
414 - do_action( "admin_print_scripts-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
415 - do_action( 'admin_print_scripts' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
416 - do_action( "admin_head-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
417 - do_action( 'admin_head' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
418 - do_action( 'admin_footer', '' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
419 - do_action( 'wp_print_footer_scripts' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores,WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
420 - do_action( "admin_print_footer_scripts-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
421 - do_action( 'admin_print_footer_scripts' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
422 - do_action( "admin_footer-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
423 - $html_output = ob_get_clean();
424 - // Extract all script tags with type="text/html" (WordPress media templates use text/html, not text/template).
425 - // Templates are already in html_output from the admin_footer hook.
426 - $html_templates = array();
427 - if ( preg_match_all( '/<script[^>]*type\s*=\s*["\']text\/html["\'][^>]*>.*?<\/script>/is', $html_output, $matches ) ) {
428 - $html_templates = $matches[0];
429 - }
177 + 'allowedBlockTypes' => array(
178 + 'description' => __( 'List of allowed block types.', 'gutenberg' ),
179 + 'type' => 'boolean',
180 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
181 + ),
430 182
431 - // Process the captured assets.
432 - return rest_ensure_response( $this->process_assets( $html_templates ) );
433 - }
183 + 'allowedMimeTypes' => array(
184 + 'description' => __( 'List of allowed mime types and file extensions.', 'gutenberg' ),
185 + 'type' => 'object',
186 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
187 + ),
434 188
435 - /**
436 - * Process WordPress assets and return structured data.
437 - *
438 - * @since Gutenberg 5.8.0
439 - *
440 - * @global WP_Scripts $wp_scripts WordPress scripts objects.
441 - * @global WP_Styles $wp_styles WordPress styles objects.
442 - *
443 - * @param array $html_templates Optional. Array of HTML template strings.
444 - * @return array Structured asset data.
445 - */
446 - private function process_assets( $html_templates = array() ) {
447 - global $wp_scripts, $wp_styles;
189 + 'blockCategories' => array(
190 + 'description' => __( 'Returns all the categories for block types that will be shown in the block editor.', 'gutenberg' ),
191 + 'type' => 'array',
192 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
193 + ),
448 194
449 - $styles_data = array();
450 - $scripts_data = array();
451 - $inline_styles = array(
452 - 'before' => array(),
453 - 'after' => array(),
454 - );
455 - $inline_scripts = array(
456 - 'before' => array(),
457 - 'after' => array(),
458 - );
195 + 'disableCustomColors' => array(
196 + 'description' => __( 'Disables custom colors.', 'gutenberg' ),
197 + 'type' => 'boolean',
198 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
199 + ),
459 200
460 - // Get boot module asset file for dependencies.
461 - $boot_asset_file = include __DIR__ . '/../../build/modules/boot/index.min.asset.php';
462 - $boot_dependencies = $boot_asset_file['dependencies'] ?? array();
201 + 'disableCustomFontSizes' => array(
202 + 'description' => __( 'Disables custom font size.', 'gutenberg' ),
203 + 'type' => 'boolean',
204 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
205 + ),
463 206
464 - // Get all dependencies that should be excluded (boot dependencies + their deep dependencies).
465 - $excluded_scripts = $this->get_all_dependencies( $boot_dependencies, $wp_scripts );
466 - $excluded_styles = $this->get_all_dependencies( array( 'wp-components', 'wp-commands', 'dashicons' ), $wp_styles );
207 + 'disableCustomGradients' => array(
208 + 'description' => __( 'Disables custom font size.', 'gutenberg' ),
209 + 'type' => 'boolean',
210 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
211 + ),
467 212
468 - // Process styles - include all dependencies of queued styles.
469 - $all_needed_styles = array();
470 - foreach ( $wp_styles->queue as $handle ) {
471 - $all_needed_styles = array_merge( $all_needed_styles, $this->get_all_dependencies( array( $handle ), $wp_styles ) );
472 - }
473 - $all_needed_styles = array_unique( $all_needed_styles );
213 + 'disableLayoutStyles' => array(
214 + 'description' => __( 'Disables output of layout styles.', 'gutenberg' ),
215 + 'type' => 'boolean',
216 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
217 + ),
474 218
475 - foreach ( $all_needed_styles as $handle ) {
476 - // Skip styles that are already loaded by the boot module.
477 - if ( in_array( $handle, $excluded_styles, true ) ) {
478 - continue;
479 - }
219 + 'enableCustomLineHeight' => array(
220 + 'description' => __( 'Enables custom line height.', 'gutenberg' ),
221 + 'type' => 'boolean',
222 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
223 + ),
480 224
481 - if ( isset( $wp_styles->registered[ $handle ] ) ) {
482 - $style = $wp_styles->registered[ $handle ];
483 - $styles_data[ $handle ] = array(
484 - 'src' => $style->src,
485 - 'deps' => $style->deps,
486 - 'version' => $style->ver,
487 - 'media' => $style->args,
488 - );
225 + 'enableCustomSpacing' => array(
226 + 'description' => __( 'Enables custom spacing.', 'gutenberg' ),
227 + 'type' => 'boolean',
228 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
229 + ),
489 230
490 - $inline_style = $wp_styles->get_data( $handle, 'after' );
491 - if ( ! empty( $inline_style ) ) {
492 - $inline_styles['after'][ $handle ] = $inline_style;
493 - }
494 - $inline_style = $wp_styles->get_data( $handle, 'before' );
495 - if ( ! empty( $inline_style ) ) {
496 - $inline_styles['before'][ $handle ] = $inline_style;
497 - }
498 - }
499 - }
231 + 'enableCustomUnits' => array(
232 + 'description' => __( 'Enables custom units.', 'gutenberg' ),
233 + 'type' => 'boolean',
234 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
235 + ),
500 236
501 - // Process scripts - include all dependencies of queued scripts.
502 - $all_needed_scripts = array();
503 - foreach ( $wp_scripts->queue as $handle ) {
504 - $all_needed_scripts = array_merge( $all_needed_scripts, $this->get_all_dependencies( array( $handle ), $wp_scripts ) );
505 - }
506 - $all_needed_scripts = array_unique( $all_needed_scripts );
237 + 'isRTL' => array(
238 + 'description' => __( 'Determines whether the current locale is right-to-left (RTL).', 'gutenberg' ),
239 + 'type' => 'boolean',
240 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
241 + ),
507 242
508 - foreach ( $all_needed_scripts as $handle ) {
509 - // Skip scripts that are already loaded by the boot module.
510 - if ( in_array( $handle, $excluded_scripts, true ) ) {
511 - continue;
512 - }
243 + 'imageDefaultSize' => array(
244 + 'description' => __( 'Default size for images.', 'gutenberg' ),
245 + 'type' => 'string',
246 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
247 + ),
513 248
514 - if ( isset( $wp_scripts->registered[ $handle ] ) ) {
515 - $script = $wp_scripts->registered[ $handle ];
516 - $scripts_data[ $handle ] = array(
517 - 'src' => $script->src,
518 - 'deps' => $script->deps,
519 - 'version' => $script->ver,
520 - 'in_footer' => isset( $script->extra['group'] ) && 1 === $script->extra['group'],
521 - );
249 + 'imageDimensions' => array(
250 + 'description' => __( 'Available image dimensions.', 'gutenberg' ),
251 + 'type' => 'object',
252 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
253 + ),
522 254
523 - // Get inline scripts using proper WordPress methods.
524 - $before_script = $wp_scripts->get_inline_script_data( $handle, 'before' );
525 - $after_script = $wp_scripts->get_inline_script_data( $handle, 'after' );
255 + 'imageEditing' => array(
256 + 'description' => __( 'Determines whether the image editing feature is enabled.', 'gutenberg' ),
257 + 'type' => 'boolean',
258 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
259 + ),
526 260
527 - // Get extra script data (localized data).
528 - $extra_script = $wp_scripts->print_extra_script( $handle, false );
261 + 'imageSizes' => array(
262 + 'description' => __( 'Available image sizes.', 'gutenberg' ),
263 + 'type' => 'array',
264 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
265 + ),
529 266
530 - // Store before scripts (includes extra/localized data).
531 - $before_content = '';
532 - if ( ! empty( $before_script ) ) {
533 - $before_content .= $before_script . "\n";
534 - }
535 - if ( ! empty( $extra_script ) ) {
536 - $before_content .= $extra_script . "\n";
537 - }
267 + 'maxUploadFileSize' => array(
268 + 'description' => __( 'Maximum upload size in bytes allowed for the site.', 'gutenberg' ),
269 + 'type' => 'number',
270 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
271 + ),
538 272
539 - if ( ! empty( $before_content ) ) {
540 - $inline_scripts['before'][ $handle ] = trim( $before_content );
541 - }
273 + 'colors' => array(
274 + 'description' => __( 'Active theme color palette.', 'gutenberg' ),
275 + 'type' => 'array',
276 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
277 + ),
542 278
543 - // Store after scripts separately.
544 - if ( ! empty( $after_script ) ) {
545 - $inline_scripts['after'][ $handle ] = trim( $after_script );
546 - }
547 - }
548 - }
279 + 'fontSizes' => array(
280 + 'description' => __( 'Active theme font sizes.', 'gutenberg' ),
281 + 'type' => 'array',
282 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
283 + ),
549 284
550 - // Build an import map from registered script modules.
551 - // the import map need to be dynamically extended in the frontend.
552 - $script_modules = wp_script_modules();
553 - $registered = array();
554 - $reflection = new ReflectionClass( $script_modules );
555 - $property = $reflection->getProperty( 'registered' );
556 - /*
557 - * ReflectionProperty::setAccessible is:
558 - * - needed until 8.1.0, as property `registered` is private.
559 - * - redundant as of 8.1.0, which made non-public reflection accessible by default.
560 - * - deprecated as of 8.5.0.
561 - */
562 - if ( PHP_VERSION_ID < 80100 ) {
563 - $property->setAccessible( true );
564 - }
565 - $registered = $property->getValue( $script_modules );
566 - $import_map = array();
567 - foreach ( $registered as $id => $module ) {
568 - // Handle both array and object formats.
569 - if ( is_array( $module ) && isset( $module['src'] ) ) {
570 - $import_map[ $id ] = $module['src'];
571 - } elseif ( is_object( $module ) && isset( $module->src ) ) {
572 - $import_map[ $id ] = $module->src;
573 - }
574 - }
575 -
576 - return array(
577 - 'scripts' => $scripts_data,
578 - 'styles' => $styles_data,
579 - 'inline_scripts' => $inline_scripts,
580 - 'inline_styles' => $inline_styles,
581 - 'html_templates' => $html_templates,
582 - 'script_modules' => $import_map,
583 - );
584 - }
585 -
586 - /**
587 - * Get all dependencies recursively (works for both scripts and styles).
588 - *
589 - * @since Gutenberg 5.8.0
590 - *
591 - * @param array|string $handles The handles to get dependencies for.
592 - * @param WP_Dependencies $wp_assets The WordPress dependencies object.
593 - * @return array Array of all dependencies.
594 - */
595 - private function get_all_dependencies( $handles, $wp_assets ) {
596 - $all_deps = array();
597 - $handles = (array) $handles;
598 -
599 - foreach ( $handles as $handle ) {
600 - if ( isset( $wp_assets->registered[ $handle ] ) ) {
601 - $asset = $wp_assets->registered[ $handle ];
602 - $all_deps[] = $handle;
603 -
604 - if ( ! empty( $asset->deps ) ) {
605 - $child_deps = $this->get_all_dependencies( $asset->deps, $wp_assets );
606 - $all_deps = array_merge( $all_deps, $child_deps );
607 - }
608 - }
609 - }
610 -
611 - return array_unique( $all_deps );
612 - }
613 -
614 - /**
615 - * Load WordPress admin environment and required functions.
616 - *
617 - * This mirrors the initialization that happens in wp-admin context
618 - * to ensure all necessary functions and hooks are available.
619 - *
620 - * @since Gutenberg 5.8.0
621 - */
622 - private function load_admin_environment() {
623 - // Load core admin files that provide essential functions.
624 - require_once ABSPATH . 'wp-admin/includes/admin.php';
625 - }
626 -
627 - /**
628 - * Retrieves the editor assets schema, conforming to JSON Schema.
629 - *
630 - * @since Gutenberg 5.8.0
631 - *
632 - * @return array Item schema data.
633 - */
634 - public function get_assets_schema() {
635 - $schema = array(
636 - '$schema' => 'http://json-schema.org/draft-04/schema#',
637 - 'title' => 'block-editor-assets',
638 - 'type' => 'object',
639 - 'properties' => array(
640 - 'scripts' => array(
641 - 'description' => __( 'Editor scripts data.', 'gutenberg' ),
642 - 'type' => 'object',
643 - 'readonly' => true,
644 - ),
645 - 'styles' => array(
646 - 'description' => __( 'Editor styles data.', 'gutenberg' ),
647 - 'type' => 'object',
648 - 'readonly' => true,
649 - ),
650 - 'inline_scripts' => array(
651 - 'description' => __( 'Inline scripts for editor assets.', 'gutenberg' ),
652 - 'type' => 'object',
653 - 'readonly' => true,
654 - ),
655 - 'inline_styles' => array(
656 - 'description' => __( 'Inline styles for editor assets.', 'gutenberg' ),
657 - 'type' => 'object',
658 - 'readonly' => true,
659 - ),
660 - 'script_modules' => array(
661 - 'description' => __( 'Script modules to load into the import map.', 'gutenberg' ),
662 - 'type' => 'object',
663 - 'readonly' => true,
664 - ),
285 + 'gradients' => array(
286 + 'description' => __( 'Active theme gradients.', 'gutenberg' ),
287 + 'type' => 'array',
288 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
665 289 ),
666 - );
290 + 'spacingSizes' => array(
291 + 'description' => __( 'Active theme spacing sizes.', 'gutenberg' ),
292 + 'type' => 'array',
293 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
294 + ),
295 + 'spacingScale' => array(
296 + 'description' => __( 'Active theme spacing scale.', 'gutenberg' ),
297 + 'type' => 'array',
298 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
299 + ),
300 + 'disableCustomSpacingSizes' => array(
301 + 'description' => __( 'Disables custom spacing sizes.', 'gutenberg' ),
302 + 'type' => 'boolean',
303 + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
304 + ),
305 + ),
306 + );
667 307
668 - return $this->add_additional_fields_schema( $schema );
669 - }
308 + return $this->add_additional_fields_schema( $this->schema );
670 309 }
671 310 }