From 100a220c0e84c1dc87c175a443cce63ac71f52ac Mon Sep 17 00:00:00 2001 From: Ashar Fuadi Date: Tue, 14 May 2024 09:58:34 +0700 Subject: [PATCH] Refactor filter and profile in preparation for reverse sync PR --- .../src/class-jetpack-mu-wpcom.php | 2 +- .../calypso-locale-sync.php | 44 ----------------- .../sync-wp-admin-to-calypso.php | 48 +++++++++++++++++++ 3 files changed, 49 insertions(+), 45 deletions(-) delete mode 100644 projects/packages/jetpack-mu-wpcom/src/features/calypso-locale-sync/calypso-locale-sync.php create mode 100644 projects/packages/jetpack-mu-wpcom/src/features/calypso-locale-sync/sync-wp-admin-to-calypso.php diff --git a/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php b/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php index acdee2de11636..d6a99b53f891c 100644 --- a/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php +++ b/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php @@ -87,7 +87,7 @@ public static function load_features() { require_once __DIR__ . '/features/site-editor-dashboard-link/site-editor-dashboard-link.php'; require_once __DIR__ . '/features/wpcom-site-menu/wpcom-site-menu.php'; require_once __DIR__ . '/features/wpcom-themes/wpcom-themes.php'; - require_once __DIR__ . '/features/calypso-locale-sync/calypso-locale-sync.php'; + require_once __DIR__ . '/features/calypso-locale-sync/sync-wp-admin-to-calypso.php'; // Initializers, if needed. \Marketplace_Products_Updater::init(); diff --git a/projects/packages/jetpack-mu-wpcom/src/features/calypso-locale-sync/calypso-locale-sync.php b/projects/packages/jetpack-mu-wpcom/src/features/calypso-locale-sync/calypso-locale-sync.php deleted file mode 100644 index 40ac7e72e30b8..0000000000000 --- a/projects/packages/jetpack-mu-wpcom/src/features/calypso-locale-sync/calypso-locale-sync.php +++ /dev/null @@ -1,44 +0,0 @@ -is_user_connected(); - - if ( ! $update || $old_locale === $locale || ! $is_user_connected ) { - // Only proceed for locale changes on an existing connected WPCOM user. - return $meta; - } - - if ( ! $locale ) { - // No locale means the "Site Default" option, which is the Site language (WPLANG). - $locale = get_option( 'WPLANG', '' ); - } - - Client::wpcom_json_api_request_as_user( - '/me/locale', - '2', - array( - 'method' => 'POST', - ), - array( 'locale' => $locale ), - 'wpcom' - ); - - return $meta; - }, - 8, - 3 - ); -} diff --git a/projects/packages/jetpack-mu-wpcom/src/features/calypso-locale-sync/sync-wp-admin-to-calypso.php b/projects/packages/jetpack-mu-wpcom/src/features/calypso-locale-sync/sync-wp-admin-to-calypso.php new file mode 100644 index 0000000000000..e44773f553d18 --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/src/features/calypso-locale-sync/sync-wp-admin-to-calypso.php @@ -0,0 +1,48 @@ +is_user_connected(); + + if ( ! $update || $old_locale === $locale || ! $is_user_connected ) { + // Only proceed for locale changes on an existing connected WPCOM user. + return $meta; + } + + if ( ! $locale ) { + // No locale means the "Site Default" option, which is the Site language (WPLANG). + $locale = get_option( 'WPLANG', '' ); + } + + Client::wpcom_json_api_request_as_user( + '/me/locale', + '2', + array( + 'method' => 'POST', + ), + array( 'locale' => $locale ), + 'wpcom' + ); + + return $meta; +} + +if ( function_exists( 'wpcom_is_nav_redesign_enabled' ) && wpcom_is_nav_redesign_enabled() ) { + add_filter( 'insert_user_meta', 'sync_wp_admin_locale_to_calypso', 8, 3 ); +}