From 14ddb61201588e6d31effe6e3ca7eff17d74ffbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Fri, 14 May 2021 10:23:58 +0200 Subject: [PATCH 1/2] Add mobile context --- lib/class-wp-rest-block-editor-settings-controller.php | 10 ++++++++-- lib/global-styles.php | 8 +++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/class-wp-rest-block-editor-settings-controller.php b/lib/class-wp-rest-block-editor-settings-controller.php index 70841e152f79e3..398457e4911e54 100644 --- a/lib/class-wp-rest-block-editor-settings-controller.php +++ b/lib/class-wp-rest-block-editor-settings-controller.php @@ -129,9 +129,9 @@ public function get_item_schema() { ), '__experimentalFeatures' => array( - 'description' => __( 'Active theme settings and default values.', 'gutenberg' ), + 'description' => __( 'Settings consolidated from core, theme, and user origins.', 'gutenberg' ), 'type' => 'object', - 'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ), + 'context' => array( 'post-editor', 'site-editor', 'widgets-editor', 'mobile' ), ), '__experimentalGlobalStylesUserEntityId' => array( @@ -146,6 +146,12 @@ public function get_item_schema() { 'context' => array( 'site-editor' ), ), + '__experimentalStyles' => array( + 'description' => __( 'Styles consolidated from core, theme, and user origins.', 'gutenberg' ), + 'type' => 'object', + 'context' => array( 'mobile' ), + ), + 'alignWide' => array( 'description' => __( 'Enable/Disable Wide/Full Alignments.', 'gutenberg' ), 'type' => 'boolean', diff --git a/lib/global-styles.php b/lib/global-styles.php index 77b078351a9eba..32244b0fca259f 100644 --- a/lib/global-styles.php +++ b/lib/global-styles.php @@ -88,8 +88,10 @@ function_exists( 'gutenberg_is_edit_site_page' ) && $context = 'site-editor'; } + // So far, only mobile will use the endpoint. + // However, we should be more specific here. if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { - $context = 'rest-request'; + $context = 'mobile'; } $origin = 'theme'; @@ -102,7 +104,7 @@ function_exists( 'gutenberg_is_edit_site_page' ) && } $consolidated = WP_Theme_JSON_Resolver::get_merged_data( $settings, $origin ); - if ( 'rest-request' === $context ) { + if ( 'mobile' === $context ) { $settings['__experimentalStyles'] = $consolidated->get_raw_data()['styles']; } @@ -116,7 +118,7 @@ function_exists( 'gutenberg_is_edit_site_page' ) && if ( 'site-editor' !== $context && - 'rest-request' !== $context && + 'mobile' !== $context && ( WP_Theme_JSON_Resolver::theme_has_support() || get_theme_support( 'experimental-link-color' ) ) ) { $block_styles = array( 'css' => gutenberg_experimental_global_styles_get_stylesheet( $consolidated, 'block_styles' ) ); From c521a076fad810d1beb7f1fee34248d05d94e1c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Fri, 14 May 2021 11:00:40 +0200 Subject: [PATCH 2/2] Check for context string from mobile --- lib/global-styles.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/global-styles.php b/lib/global-styles.php index 32244b0fca259f..8d5552e5e7244c 100644 --- a/lib/global-styles.php +++ b/lib/global-styles.php @@ -88,9 +88,12 @@ function_exists( 'gutenberg_is_edit_site_page' ) && $context = 'site-editor'; } - // So far, only mobile will use the endpoint. - // However, we should be more specific here. - if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { + if ( + defined( 'REST_REQUEST' ) && + REST_REQUEST && + isset( $_GET['context'] ) && + 'mobile' === $_GET['context'] + ) { $context = 'mobile'; }