PluginProbe
Gutenberg / 12.6.0
Gutenberg v12.6.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 7.4.0 All 402 releases
gutenberg / lib / class-wp-rest-block-editor-settings-controller.php

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

262 lines 9.3 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 /**
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 }
22
23 /**
24 * Registers the necessary REST API routes.
25 */
26 public function register_routes() {
27 register_rest_route(
28 $this->namespace,
29 '/' . $this->rest_base,
30 array(
31 array(
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 }
40
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;
53 }
54
55 foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
56 if ( current_user_can( $post_type->cap->edit_posts ) ) {
57 return true;
58 }
59 }
60
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 }
67
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 $editor_context = new WP_Block_Editor_Context();
79 $settings = get_block_editor_settings( array(), $editor_context );
80
81 return rest_ensure_response( $settings );
82 }
83
84 /**
85 * Retrieves the block editor's settings schema, conforming to JSON Schema.
86 *
87 * @since 5.8.0
88 *
89 * @return array Item schema data.
90 */
91 public function get_item_schema() {
92 if ( $this->schema ) {
93 return $this->add_additional_fields_schema( $this->schema );
94 }
95
96 $this->schema = array(
97 '$schema' => 'http://json-schema.org/draft-04/schema#',
98 'title' => 'block-editor-settings-item',
99 'type' => 'object',
100 'properties' => array(
101 '__unstableEnableFullSiteEditingBlocks' => array(
102 'description' => __( 'Enables experimental Full Site Editing blocks', 'gutenberg' ),
103 'type' => 'boolean',
104 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
105 ),
106
107 'styles' => array(
108 'description' => __( 'Editor styles', 'gutenberg' ),
109 'type' => 'array',
110 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
111 ),
112
113 'supportsTemplateMode' => array(
114 'description' => __( 'Returns if the current theme is full site editing-enabled or not.', 'gutenberg' ),
115 'type' => 'boolean',
116 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
117 ),
118
119 'supportsLayout' => array(
120 'description' => __( 'Enable/disable layouts support in container blocks.', 'gutenberg' ),
121 'type' => 'boolean',
122 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
123 ),
124
125 'widgetTypesToHideFromLegacyWidgetBlock' => array(
126 'description' => __( 'Widget types to hide from Legacy Widget block.', 'gutenberg' ),
127 'type' => 'array',
128 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
129 ),
130
131 '__experimentalFeatures' => array(
132 'description' => __( 'Settings consolidated from core, theme, and user origins.', 'gutenberg' ),
133 'type' => 'object',
134 'context' => array( 'post-editor', 'site-editor', 'widgets-editor', 'mobile' ),
135 ),
136
137 '__experimentalStyles' => array(
138 'description' => __( 'Styles consolidated from core, theme, and user origins.', 'gutenberg' ),
139 'type' => 'object',
140 'context' => array( 'mobile' ),
141 ),
142
143 'alignWide' => array(
144 'description' => __( 'Enable/Disable Wide/Full Alignments.', 'gutenberg' ),
145 'type' => 'boolean',
146 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
147 ),
148
149 'allowedBlockTypes' => array(
150 'description' => __( 'List of allowed block types.', 'gutenberg' ),
151 'type' => 'boolean',
152 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
153 ),
154
155 'allowedMimeTypes' => array(
156 'description' => __( 'List of allowed mime types and file extensions.', 'gutenberg' ),
157 'type' => 'object',
158 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
159 ),
160
161 'blockCategories' => array(
162 'description' => __( 'Returns all the categories for block types that will be shown in the block editor.', 'gutenberg' ),
163 'type' => 'array',
164 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
165 ),
166
167 'disableCustomColors' => array(
168 'description' => __( 'Disables custom colors.', 'gutenberg' ),
169 'type' => 'boolean',
170 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
171 ),
172
173 'disableCustomFontSizes' => array(
174 'description' => __( 'Disables custom font size.', 'gutenberg' ),
175 'type' => 'boolean',
176 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
177 ),
178
179 'disableCustomGradients' => array(
180 'description' => __( 'Disables custom font size.', 'gutenberg' ),
181 'type' => 'boolean',
182 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
183 ),
184
185 'enableCustomLineHeight' => array(
186 'description' => __( 'Enables custom line height.', 'gutenberg' ),
187 'type' => 'boolean',
188 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
189 ),
190
191 'enableCustomSpacing' => array(
192 'description' => __( 'Enables custom spacing.', 'gutenberg' ),
193 'type' => 'boolean',
194 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
195 ),
196
197 'enableCustomUnits' => array(
198 'description' => __( 'Enables custom units.', 'gutenberg' ),
199 'type' => 'boolean',
200 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
201 ),
202
203 'isRTL' => array(
204 'description' => __( 'Determines whether the current locale is right-to-left (RTL).', 'gutenberg' ),
205 'type' => 'boolean',
206 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
207 ),
208
209 'imageDefaultSize' => array(
210 'description' => __( 'Default size for images.', 'gutenberg' ),
211 'type' => 'string',
212 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
213 ),
214
215 'imageDimensions' => array(
216 'description' => __( 'Available image dimensions.', 'gutenberg' ),
217 'type' => 'object',
218 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
219 ),
220
221 'imageEditing' => array(
222 'description' => __( 'Determines whether the image editing feature is enabled.', 'gutenberg' ),
223 'type' => 'boolean',
224 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
225 ),
226
227 'imageSizes' => array(
228 'description' => __( 'Available image sizes.', 'gutenberg' ),
229 'type' => 'array',
230 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
231 ),
232
233 'maxUploadFileSize' => array(
234 'description' => __( 'Maximum upload size in bytes allowed for the site.', 'gutenberg' ),
235 'type' => 'number',
236 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
237 ),
238
239 'colors' => array(
240 'description' => __( 'Active theme color palette.', 'gutenberg' ),
241 'type' => 'array',
242 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
243 ),
244
245 'fontSizes' => array(
246 'description' => __( 'Active theme font sizes.', 'gutenberg' ),
247 'type' => 'array',
248 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
249 ),
250
251 'gradients' => array(
252 'description' => __( 'Active theme gradients.', 'gutenberg' ),
253 'type' => 'array',
254 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
255 ),
256 ),
257 );
258
259 return $this->add_additional_fields_schema( $this->schema );
260 }
261 }
262