diff --git a/lib/class-wp-rest-block-editor-settings-controller.php b/lib/class-wp-rest-block-editor-settings-controller.php new file mode 100644 index 00000000000000..c46869e2000fbf --- /dev/null +++ b/lib/class-wp-rest-block-editor-settings-controller.php @@ -0,0 +1,64 @@ +namespace = 'wp/v2'; + $this->rest_base = 'block-editor-settings'; + } + + /** + * Registers the necessary REST API routes. + */ + public function register_routes() { + register_rest_route( + $this->namespace, + '/' . $this->rest_base, + array( + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_items' ), + 'permission_callback' => array( $this, 'get_items_permissions_check' ), + ), + ) + ); + } + + /** + * Checks whether a given request has permission to read block editor settings + * + * @return WP_Error|bool True if the request has permission, WP_Error object otherwise. + */ + public function get_items_permissions_check() { + if ( ! current_user_can( 'edit_posts' ) ) { + $error = __( 'Sorry, you are not allowed to read the block editor settings.', 'gutenberg' ); + return new WP_Error( 'rest_cannot_read_settings', $error, array( 'status' => rest_authorization_required_code() ) ); + } + + return true; + } + + /** + * Return all block editor settings + * + * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. + */ + public function get_items() { + $settings = apply_filters( 'block_editor_settings', array() ); + + return rest_ensure_response( $settings ); + } +} diff --git a/lib/global-styles.php b/lib/global-styles.php index 9419759fc00325..102f4c7a002889 100644 --- a/lib/global-styles.php +++ b/lib/global-styles.php @@ -209,6 +209,8 @@ function gutenberg_experimental_global_styles_settings( $settings ) { $origin = 'user'; } $tree = WP_Theme_JSON_Resolver::get_merged_data( $theme_support_data, $origin ); + // Check for mobile editor. + $is_mobile = isset( $_REQUEST['is_mobile'] ) && 'true' === $_REQUEST['is_mobile']; // STEP 1: ADD FEATURES // @@ -223,11 +225,12 @@ function gutenberg_experimental_global_styles_settings( $settings ) { // In the site editor, the user can change styles, so the client // needs the ability to create them. Hence, we pass it some data // for this: base styles (core+theme) and the ID of the user CPT. - $screen = get_current_screen(); + $screen = ! $is_mobile && get_current_screen(); if ( - ! empty( $screen ) && + ( ( ! empty( $screen ) && function_exists( 'gutenberg_is_edit_site_page' ) && - gutenberg_is_edit_site_page( $screen->id ) && + gutenberg_is_edit_site_page( $screen->id ) || + $is_mobile ) ) && WP_Theme_JSON_Resolver::theme_has_support() && gutenberg_is_fse_theme() ) { diff --git a/lib/load.php b/lib/load.php index feb404433c6e56..bf9239dab836d9 100644 --- a/lib/load.php +++ b/lib/load.php @@ -67,6 +67,9 @@ function gutenberg_is_experiment_enabled( $name ) { if ( ! class_exists( 'WP_REST_Templates_Controller' ) ) { require_once __DIR__ . '/full-site-editing/class-wp-rest-templates-controller.php'; } + if ( ! class_exists( 'WP_REST_Block_Editor_Settings_Controller' ) ) { + require dirname( __FILE__ ) . '/class-wp-rest-block-editor-settings-controller.php'; + } /** * End: Include for phase 2 */ diff --git a/lib/rest-api.php b/lib/rest-api.php index 3fa0181c6f1738..910223eb9be699 100644 --- a/lib/rest-api.php +++ b/lib/rest-api.php @@ -73,6 +73,15 @@ function gutenberg_register_batch_endpoint() { } add_action( 'rest_api_init', 'gutenberg_register_batch_endpoint' ); +/** + * Registers the Block types REST API routes. + */ +function gutenberg_register_rest_block_editor_settings() { + $editor_settings = new WP_REST_Block_Editor_Settings_Controller(); + $editor_settings->register_routes(); +} +add_action( 'rest_api_init', 'gutenberg_register_rest_block_editor_settings' ); + /** * Hook in to the nav menu item post type and enable a post type rest endpoint. *