-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add a new endpoint that exposes block editor settings through the REST API #29969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
484e3ee
9737fbc
0b90f30
ba80bcc
d1cc0f5
1cfd9d1
052d241
b4205d5
d332e6e
e3e1c77
2c7abac
ffe9ac1
6837fa7
d9f3277
e18eaa3
2328ff6
ede0fc1
ddb0dcd
3a3908f
108debd
2d24002
ec6fa21
f5db2fc
3897d19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,23 @@ | ||
| <?php | ||
| /** | ||
| * REST API: WP_REST_Block_Editor_Global_Styles_Settings_Controller class | ||
| * REST API: WP_REST_Block_Editor_Settings_Controller class | ||
| * | ||
| * @package WordPress | ||
| * @subpackage REST_API | ||
| */ | ||
|
|
||
| /** | ||
| * Core class used to retrieve the block editor global styles settings via the REST API. | ||
| * Core class used to retrieve the block editor settings via the REST API. | ||
| * | ||
| * @see WP_REST_Controller | ||
| */ | ||
| class WP_REST_Block_Editor_Global_Styles_Settings_Controller extends WP_REST_Controller { | ||
| class WP_REST_Block_Editor_Settings_Controller extends WP_REST_Controller { | ||
| /** | ||
| * Constructs the controller. | ||
| */ | ||
| public function __construct() { | ||
| $this->namespace = 'wp-block-editor/v1'; | ||
| $this->rest_base = 'global-styles'; | ||
| $this->rest_base = 'settings'; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -57,7 +57,7 @@ public function get_items_permissions_check( $request ) {// phpcs:ignore Variabl | |
| } | ||
|
|
||
| /** | ||
| * Returns the block editor's global styles settings | ||
| * Returns the block editor's settings | ||
| * | ||
| * @since 5.8.0 | ||
| * | ||
|
|
@@ -66,13 +66,18 @@ public function get_items_permissions_check( $request ) {// phpcs:ignore Variabl | |
| * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. | ||
| */ | ||
| public function get_items( $request ) {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
| $settings = apply_filters( 'block_editor_global_styles_rest_settings', array() ); | ||
| $settings = apply_filters( 'block_editor_settings', array() ); | ||
| unset( $settings['styles'] ); | ||
| unset( $settings['defaultEditorStyles'] ); | ||
| unset( $settings['availableLegacyWidgets'] ); | ||
| unset( $settings['__unstableEnableFullSiteEditingBlocks'] ); | ||
| unset( $settings['__experimentalGlobalStylesUserEntityId'] ); | ||
|
|
||
| return rest_ensure_response( $settings ); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves the block editor's global styles schema, conforming to JSON Schema. | ||
| * Retrieves the block editor's settings schema, conforming to JSON Schema. | ||
| * | ||
| * @since 5.8.0 | ||
| * | ||
|
|
@@ -85,34 +90,22 @@ public function get_item_schema() { | |
|
|
||
| $this->schema = array( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sounds great. It looks like there are some items that are off in terms of in which context they're available. Some that I've noticed that should be Also: any thoughts on best practices to keep this schema up to date as things evolve would be great.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If we would start using the same endpoint for the web then it could help to maintain the schema 😄 In related efforts, I plan we switch to the REST API endpoint for block types on the web rather than expose them with JS function call on the server.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @nosolosw !
I updated those to be
Awesome 😃! Do you know more or less when that's going to be updated?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've just merged #31762 which adds more data for mobile. Upon hitting the button, it just occurred to me that something was off. I think it boils down to the contexts we define in this PR: My understanding is that we use this to filter what kind of data we pass through the request. If the plan is to move the settings retrieval to use the REST request, checks like https://github.com/WordPress/gutenberg/pull/31762/files#diff-0b8e98dead5542e95159bd3c482158111d3f16637e7eef9af13373358fa42dedR91 don't make sense. However, the current contexts are also not enough. I'm thinking we actually need a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, prepared #31819 to add a |
||
| '$schema' => 'http://json-schema.org/draft-04/schema#', | ||
| 'title' => 'block-editor-global-styles-settings-item', | ||
| 'title' => 'block-editor-settings-item', | ||
| 'type' => 'object', | ||
| 'properties' => array( | ||
| 'colors' => array( | ||
| 'description' => __( 'Active theme colors.', 'gutenberg' ), | ||
| 'type' => 'array', | ||
| 'context' => array( 'view' ), | ||
| ), | ||
|
|
||
| 'gradients' => array( | ||
| 'description' => __( 'Active theme gradients.', 'gutenberg' ), | ||
| 'type' => 'array', | ||
| '__experimentalFeatures' => array( | ||
| 'description' => __( 'Active theme settings and default values.', 'gutenberg' ), | ||
| 'type' => 'object', | ||
| 'context' => array( 'view' ), | ||
| ), | ||
|
|
||
| 'globalStyles' => array( | ||
| 'description' => __( 'Theme support for global styles.', 'gutenberg' ), | ||
| 'isFSETheme' => array( | ||
| 'description' => __( 'Theme support for full site editing.', 'gutenberg' ), | ||
| 'type' => 'boolean', | ||
| 'context' => array( 'view' ), | ||
| ), | ||
|
|
||
| 'globalStylesUserEntityId' => array( | ||
| 'description' => __( 'User entity id for Global styles settings.', 'gutenberg' ), | ||
| 'type' => 'integer', | ||
| 'context' => array( 'view' ), | ||
| ), | ||
|
|
||
| 'globalStylesBaseStyles' => array( | ||
| '__experimentalGlobalStylesBaseStyles' => array( | ||
| 'description' => __( 'Global styles settings.', 'gutenberg' ), | ||
| 'type' => 'object', | ||
| 'context' => array( 'view' ), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.