From 4e523e20b04e0850d729c89d114771bf65f3fc26 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Tue, 23 Nov 2021 09:36:14 +0000 Subject: [PATCH] Update: Migrate global styles user database data on the rest endpoint (#36747) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update: Automatically migrate global styles user database data on the rest endpoint. * Fix lint issues Co-authored-by: André <583546+oandregal@users.noreply.github.com> --- .../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 e2b2af15dd3c1..9094905718eb5 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 = array(); + 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 );