From acd28810d8c52c792b191334ce209a3c12fec765 Mon Sep 17 00:00:00 2001 From: Jorge Date: Mon, 22 Nov 2021 18:40:19 +0000 Subject: [PATCH 1/2] Update: Automatically migrate global styles user database data on the rest endpoint. --- .../class-gutenberg-rest-global-styles-controller.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/compat/wordpress-5.9/class-gutenberg-rest-global-styles-controller.php b/lib/compat/wordpress-5.9/class-gutenberg-rest-global-styles-controller.php index d9cb749076137..e16cde30755c8 100644 --- a/lib/compat/wordpress-5.9/class-gutenberg-rest-global-styles-controller.php +++ b/lib/compat/wordpress-5.9/class-gutenberg-rest-global-styles-controller.php @@ -216,8 +216,12 @@ protected function prepare_item_for_database( $request ) { * @return WP_REST_Response $data */ public function prepare_item_for_response( $post, $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable - $config = json_decode( $post->post_content, true ); - $is_global_styles_user_theme_json = isset( $config['isGlobalStylesUserThemeJSON'] ) && true === $config['isGlobalStylesUserThemeJSON']; + $raw_config = json_decode( $post->post_content, true ); + $is_global_styles_user_theme_json = isset( $raw_config['isGlobalStylesUserThemeJSON'] ) && true === $raw_config['isGlobalStylesUserThemeJSON']; + $config; + if( $is_global_styles_user_theme_json ) { + $config = ( new WP_Theme_JSON_Gutenberg( $raw_config, 'user' ) )->get_raw_data(); + } $fields = $this->get_fields_for_response( $request ); From 848f97bc4bc77857d81048fd07f6804163b69bec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Tue, 23 Nov 2021 09:53:07 +0100 Subject: [PATCH 2/2] Fix lint issues --- .../class-gutenberg-rest-global-styles-controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/compat/wordpress-5.9/class-gutenberg-rest-global-styles-controller.php b/lib/compat/wordpress-5.9/class-gutenberg-rest-global-styles-controller.php index e16cde30755c8..1dc749164a162 100644 --- a/lib/compat/wordpress-5.9/class-gutenberg-rest-global-styles-controller.php +++ b/lib/compat/wordpress-5.9/class-gutenberg-rest-global-styles-controller.php @@ -218,8 +218,8 @@ protected function prepare_item_for_database( $request ) { public function prepare_item_for_response( $post, $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable $raw_config = json_decode( $post->post_content, true ); $is_global_styles_user_theme_json = isset( $raw_config['isGlobalStylesUserThemeJSON'] ) && true === $raw_config['isGlobalStylesUserThemeJSON']; - $config; - if( $is_global_styles_user_theme_json ) { + $config = array(); + if ( $is_global_styles_user_theme_json ) { $config = ( new WP_Theme_JSON_Gutenberg( $raw_config, 'user' ) )->get_raw_data(); }