From cfa19b1d3766df16c4bc4763b6b365e4ba1354bf Mon Sep 17 00:00:00 2001 From: Gabriel Demichelis Date: Fri, 2 Feb 2024 00:51:14 -0300 Subject: [PATCH] Test user color-schema to Calypso settings --- .../class.wpcom-json-api-get-site-endpoint.php | 5 +++++ ...ass.wpcom-json-api-get-site-v1-2-endpoint.php | 1 + .../masterbar/masterbar/class-masterbar.php | 16 +--------------- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php index a8bdde68b29b0..f554bb0d66230 100644 --- a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php +++ b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php @@ -83,6 +83,7 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint { 'was_migration_trial' => '(bool) If the site ever used a migration trial.', 'was_hosting_trial' => '(bool) If the site ever used a hosting trial.', 'wpcom_site_setup' => '(string) The WP.com site setup identifier.', + 'admin_color' => '(string) Admin color schema.', ); /** @@ -116,6 +117,7 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint { 'is_core_site_editor_enabled', 'is_wpcom_atomic', 'is_wpcom_staging_site', + 'admin_color', ); /** @@ -611,6 +613,9 @@ protected function render_response_key( $key, &$response, $is_user_logged_in ) { case 'was_upgraded_from_trial': $response[ $key ] = $this->site->was_upgraded_from_trial(); break; + case 'admin_color': + $response[ $key ] = get_user_meta( get_current_user_id(), 'admin_color', true ); + break; } do_action( 'post_render_site_response_key', $key ); diff --git a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-v1-2-endpoint.php b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-v1-2-endpoint.php index ab3040ff43a34..b3d198857f8d0 100644 --- a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-v1-2-endpoint.php +++ b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-v1-2-endpoint.php @@ -77,6 +77,7 @@ class WPCOM_JSON_API_GET_Site_V1_2_Endpoint extends WPCOM_JSON_API_GET_Site_Endp 'was_upgraded_from_trial' => '(bool) If the site ever upgraded to a paid plan from a trial.', 'was_migration_trial' => '(bool) If the site ever used a migration trial.', 'was_hosting_trial' => '(bool) If the site ever used a hosting trial.', + 'admin_color' => '(string) Admin color schema.', ); /** diff --git a/projects/plugins/jetpack/modules/masterbar/masterbar/class-masterbar.php b/projects/plugins/jetpack/modules/masterbar/masterbar/class-masterbar.php index f5ae844195d29..63d84bd8eb051 100644 --- a/projects/plugins/jetpack/modules/masterbar/masterbar/class-masterbar.php +++ b/projects/plugins/jetpack/modules/masterbar/masterbar/class-masterbar.php @@ -143,9 +143,6 @@ public function __construct() { update_user_option( $this->user_id, 'locale', $this->user_locale, true ); update_user_option( $this->user_id, 'admin_color', $this->user_data['color_scheme'] ); } - if ( 'wp-admin' === get_option( 'wpcom_admin_interface' ) ) { - update_user_option( $this->user_id, 'admin_color', get_user_meta( $this->user_id, 'admin_color', true ) ); - } add_action( 'admin_bar_init', array( $this, 'init' ) ); if ( ! empty( $this->user_data['ID'] ) ) { @@ -215,18 +212,7 @@ class_exists( 'Jetpack_AMP_Support' ) add_action( 'a8c_wpcom_masterbar_enqueue_rtl_notification_styles', '__return_true' ); } - if ( $this->site_woa ) { - if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) { - // If Atomic and using wp-admin interface, update the user_option with the user's color scheme. - update_user_option( $this->user_id, 'admin_color', get_user_meta( $this->user_id, 'admin_color', true ) ); - } else { - // If Atomic and not using wp-admin interface, store, install user locale, and hide and replace the language dropdown for the current user. - $this->user_locale = $this->get_jetpack_locale( $this->user_locale ); - $this->install_locale( $this->user_locale ); - update_user_option( $this->user_id, 'locale', $this->user_locale, true ); - update_user_option( $this->user_id, 'admin_color', $this->user_data['color_scheme'] ); - } - } + // Hides and replaces the language dropdown for the current user, on WoA. if ( $this->site_woa && 'wp-admin' !== get_option( 'wpcom_admin_interface' ) && defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE ) {