PluginProbe
Gutenberg / 21.7.0
Gutenberg v21.7.0
24.1.0 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 All 404 releases
gutenberg / lib / experimental / class-wp-rest-block-editor-settings-controller.php

class-wp-rest-block-editor-settings-controller.php in Gutenberg 21.7.0, at lib/experimental/class-wp-rest-block-editor-settings-controller.php

326 lines 11.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * REST API: WP_REST_Block_Editor_Settings_Controller class
4 *
5 * @package WordPress
6 * @subpackage REST_API
7 */
8
9 if ( ! class_exists( 'WP_REST_Block_Editor_Settings_Controller' ) ) {
10
11 /**
12 * Core class used to retrieve the block editor settings via the REST API.
13 *
14 * @see WP_REST_Controller
15 */
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,
32 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 );
41 }
42
43 /**
44 * Checks whether a given request has permission to read block editor settings
45 *
46 * @since 5.8.0
47 *
48 * @param WP_REST_Request $request Full details about the request.
49 *
50 * @return WP_Error|bool True if the request has permission, WP_Error object otherwise.
51 */
52 public function get_items_permissions_check( $request ) {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
53 if ( current_user_can( 'edit_posts' ) ) {
54 return true;
55 }
56
57 foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
58 if ( current_user_can( $post_type->cap->edit_posts ) ) {
59 return true;
60 }
61 }
62
63 return new WP_Error(
64 'rest_cannot_read_block_editor_settings',
65 __( 'Sorry, you are not allowed to read the block editor settings.', 'gutenberg' ),
66 array( 'status' => rest_authorization_required_code() )
67 );
68 }
69
70 /**
71 * Returns the block editor's settings
72 *
73 * @since 5.8.0
74 *
75 * @param WP_REST_Request $request Full details about the request.
76 *
77 * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure.
78 */
79 public function get_items( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis
80 switch ( $request['context'] ) {
81 case 'post-editor':
82 default:
83 $editor_context_name = 'core/edit-post';
84 break;
85 case 'widgets-editor':
86 $editor_context_name = 'core/edit-widgets';
87 break;
88 case 'site-editor':
89 $editor_context_name = 'core/edit-site';
90 break;
91 case 'mobile':
92 $editor_context_name = 'core/mobile';
93 break;
94 }
95
96 add_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings_mobile', PHP_INT_MAX );
97
98 $editor_context = new WP_Block_Editor_Context( array( 'name' => $editor_context_name ) );
99 $settings = get_block_editor_settings( array(), $editor_context );
100
101 remove_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings_mobile', PHP_INT_MAX );
102
103 return rest_ensure_response( $settings );
104 }
105
106 /**
107 * Retrieves the block editor's settings schema, conforming to JSON Schema.
108 *
109 * @since 5.8.0
110 *
111 * @return array Item schema data.
112 */
113 public function get_item_schema() {
114 if ( $this->schema ) {
115 return $this->add_additional_fields_schema( $this->schema );
116 }
117
118 $schema = array(
119 '$schema' => 'http://json-schema.org/draft-04/schema#',
120 'title' => 'block-editor-settings-item',
121 'type' => 'object',
122 'properties' => array(
123 '__unstableEnableFullSiteEditingBlocks' => array(
124 'description' => __( 'Enables experimental Site Editor blocks', 'gutenberg' ),
125 'type' => 'boolean',
126 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
127 ),
128
129 'styles' => array(
130 'description' => __( 'Editor styles', 'gutenberg' ),
131 'type' => 'array',
132 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
133 ),
134
135 'supportsTemplateMode' => array(
136 'description' => __( 'Indicates whether the current theme supports block-based templates.', 'gutenberg' ),
137 'type' => 'boolean',
138 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
139 ),
140
141 'supportsLayout' => array(
142 'description' => __( 'Enable/disable layouts support in container blocks.', 'gutenberg' ),
143 'type' => 'boolean',
144 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
145 ),
146
147 'widgetTypesToHideFromLegacyWidgetBlock' => array(
148 'description' => __( 'Widget types to hide from Legacy Widget block.', 'gutenberg' ),
149 'type' => 'array',
150 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
151 ),
152
153 '__experimentalFeatures' => array(
154 'description' => __( 'Settings consolidated from core, theme, and user origins.', 'gutenberg' ),
155 'type' => 'object',
156 'context' => array( 'post-editor', 'site-editor', 'widgets-editor', 'mobile' ),
157 ),
158
159 '__experimentalStyles' => array(
160 'description' => __( 'Styles consolidated from core, theme, and user origins.', 'gutenberg' ),
161 'type' => 'object',
162 'context' => array( 'mobile' ),
163 ),
164
165 '__experimentalEnableQuoteBlockV2' => array(
166 'description' => __( 'Whether the V2 of the quote block that uses inner blocks should be enabled.', 'gutenberg' ),
167 'type' => 'boolean',
168 'context' => array( 'mobile' ),
169 ),
170
171 '__experimentalEnableListBlockV2' => array(
172 'description' => __( 'Whether the V2 of the list block that uses inner blocks should be enabled.', 'gutenberg' ),
173 'type' => 'boolean',
174 'context' => array( 'mobile' ),
175 ),
176
177 'alignWide' => array(
178 'description' => __( 'Enable/Disable Wide/Full Alignments.', 'gutenberg' ),
179 'type' => 'boolean',
180 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
181 ),
182
183 'allowedBlockTypes' => array(
184 'description' => __( 'List of allowed block types.', 'gutenberg' ),
185 'type' => 'boolean',
186 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
187 ),
188
189 'allowedMimeTypes' => array(
190 'description' => __( 'List of allowed mime types and file extensions.', 'gutenberg' ),
191 'type' => 'object',
192 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
193 ),
194
195 'blockCategories' => array(
196 'description' => __( 'Returns all the categories for block types that will be shown in the block editor.', 'gutenberg' ),
197 'type' => 'array',
198 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
199 ),
200
201 'blockInspectorTabs' => array(
202 'description' => __( 'Block inspector tab display overrides.', 'gutenberg' ),
203 'type' => 'object',
204 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
205 ),
206
207 'disableCustomColors' => array(
208 'description' => __( 'Disables custom colors.', 'gutenberg' ),
209 'type' => 'boolean',
210 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
211 ),
212
213 'disableCustomFontSizes' => array(
214 'description' => __( 'Disables custom font size.', 'gutenberg' ),
215 'type' => 'boolean',
216 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
217 ),
218
219 'disableCustomGradients' => array(
220 'description' => __( 'Disables custom font size.', 'gutenberg' ),
221 'type' => 'boolean',
222 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
223 ),
224
225 'disableLayoutStyles' => array(
226 'description' => __( 'Disables output of layout styles.', 'gutenberg' ),
227 'type' => 'boolean',
228 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
229 ),
230
231 'enableCustomLineHeight' => array(
232 'description' => __( 'Enables custom line height.', 'gutenberg' ),
233 'type' => 'boolean',
234 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
235 ),
236
237 'enableCustomSpacing' => array(
238 'description' => __( 'Enables custom spacing.', 'gutenberg' ),
239 'type' => 'boolean',
240 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
241 ),
242
243 'enableCustomUnits' => array(
244 'description' => __( 'Enables custom units.', 'gutenberg' ),
245 'type' => 'boolean',
246 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
247 ),
248
249 'isRTL' => array(
250 'description' => __( 'Determines whether the current locale is right-to-left (RTL).', 'gutenberg' ),
251 'type' => 'boolean',
252 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
253 ),
254
255 'imageDefaultSize' => array(
256 'description' => __( 'Default size for images.', 'gutenberg' ),
257 'type' => 'string',
258 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
259 ),
260
261 'imageDimensions' => array(
262 'description' => __( 'Available image dimensions.', 'gutenberg' ),
263 'type' => 'object',
264 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
265 ),
266
267 'imageEditing' => array(
268 'description' => __( 'Determines whether the image editing feature is enabled.', 'gutenberg' ),
269 'type' => 'boolean',
270 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
271 ),
272
273 'imageSizes' => array(
274 'description' => __( 'Available image sizes.', 'gutenberg' ),
275 'type' => 'array',
276 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
277 ),
278
279 'maxUploadFileSize' => array(
280 'description' => __( 'Maximum upload size in bytes allowed for the site.', 'gutenberg' ),
281 'type' => 'number',
282 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
283 ),
284
285 'colors' => array(
286 'description' => __( 'Active theme color palette.', 'gutenberg' ),
287 'type' => 'array',
288 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
289 ),
290
291 'fontSizes' => array(
292 'description' => __( 'Active theme font sizes.', 'gutenberg' ),
293 'type' => 'array',
294 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
295 ),
296
297 'gradients' => array(
298 'description' => __( 'Active theme gradients.', 'gutenberg' ),
299 'type' => 'array',
300 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
301 ),
302 'spacingSizes' => array(
303 'description' => __( 'Active theme spacing sizes.', 'gutenberg' ),
304 'type' => 'array',
305 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
306 ),
307 'spacingScale' => array(
308 'description' => __( 'Active theme spacing scale.', 'gutenberg' ),
309 'type' => 'array',
310 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
311 ),
312 'disableCustomSpacingSizes' => array(
313 'description' => __( 'Disables custom spacing sizes.', 'gutenberg' ),
314 'type' => 'boolean',
315 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
316 ),
317 ),
318 );
319
320 $this->schema = $schema;
321
322 return $this->add_additional_fields_schema( $this->schema );
323 }
324 }
325 }
326