From cdde213d831f59cb8e7b91846551131ace7162a6 Mon Sep 17 00:00:00 2001 From: Miguel Date: Thu, 8 Aug 2024 14:03:46 +0900 Subject: [PATCH 1/2] Remove unused files --- .../sync-calypso-to-wp-admin.php | 100 ------------------ .../sync-wp-admin-to-calypso.php | 69 ------------ 2 files changed, 169 deletions(-) delete mode 100644 projects/packages/jetpack-mu-wpcom/src/features/calypso-locale-sync/sync-calypso-to-wp-admin.php delete 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/features/calypso-locale-sync/sync-calypso-to-wp-admin.php b/projects/packages/jetpack-mu-wpcom/src/features/calypso-locale-sync/sync-calypso-to-wp-admin.php deleted file mode 100644 index aa879705d9f45..0000000000000 --- a/projects/packages/jetpack-mu-wpcom/src/features/calypso-locale-sync/sync-calypso-to-wp-admin.php +++ /dev/null @@ -1,100 +0,0 @@ -is_user_connected( get_current_user_id() ) ) { - return; - } - // Get user locale - $user_data = $connection_manager->get_connected_user_data( get_current_user_id() ); - $locale = get_jetpack_locale( $user_data['user_locale'] ); - - // Check for changes - if ( $locale && $locale !== get_user_option( 'locale' ) ) { - // Install - install_locale( $locale ); - - // Update user meta - update_user_option( get_current_user_id(), 'locale', $locale, true ); - - // Redirect to the same page to refresh changes. - if ( isset( $_SERVER['REQUEST_URI'] ) ) { - wp_safe_redirect( wp_unslash( $_SERVER['REQUEST_URI'] ) ); - exit; - } - } -} - -if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) { - // Not for POST requests because this syncing needs to be avoided when the locale is updated via /wp-admin/profile.php - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] !== 'POST' ) { - add_filter( 'admin_init', 'sync_calypso_locale_to_wp_admin' ); - } -} - -/** - * Get Jetpack locale name. - * - * @param string $slug Locale slug. - * @return string Jetpack locale. - */ -function get_jetpack_locale( $slug = '' ) { - $jetpack_locale = ''; - - if ( ! class_exists( 'GP_Locales' ) ) { - if ( defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) && file_exists( (string) JETPACK__GLOTPRESS_LOCALES_PATH ) ) { - require_once JETPACK__GLOTPRESS_LOCALES_PATH; - } - } - - if ( class_exists( 'GP_Locales' ) ) { - $jetpack_locale_object = GP_Locales::by_field( 'slug', $slug ); - if ( $jetpack_locale_object instanceof GP_Locale ) { - $jetpack_locale = $jetpack_locale_object->wp_locale ? $jetpack_locale_object->wp_locale : 'en_US'; - } - } - - return $jetpack_locale; -} - -/** - * Install locale if not yet available. - * - * @param string $locale The new locale slug. - */ -function install_locale( $locale = '' ) { - if ( ! in_array( $locale, get_available_languages(), true ) - && ! empty( $locale ) && current_user_can( 'install_languages' ) ) { - if ( ! function_exists( 'wp_download_language_pack' ) ) { - require_once ABSPATH . 'wp-admin/includes/translation-install.php'; - } - - if ( ! function_exists( 'request_filesystem_credentials' ) ) { - require_once ABSPATH . 'wp-admin/includes/file.php'; - } - - if ( wp_can_install_language_pack() ) { - wp_download_language_pack( $locale ); - load_default_textdomain( $locale ); - } - } -} 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 deleted file mode 100644 index 0ab3eaff23ebf..0000000000000 --- a/projects/packages/jetpack-mu-wpcom/src/features/calypso-locale-sync/sync-wp-admin-to-calypso.php +++ /dev/null @@ -1,69 +0,0 @@ - 'POST', - ), - array( 'locale' => $locale ), - 'wpcom' - ); -} - -/** - * Sync locale updated via /wp-admin/profile.php to Calypso. - * - * @param array $meta Meta values and keys for the user. - * @param WP_User $user User object. - * @param boolean $update Whether the user is being updated rather than created. - */ -function sync_wp_admin_locale_to_calypso( $meta, $user, $update ) { - $locale = $meta['locale']; - $old_locale = get_user_locale( $user ); - $is_user_connected = ( new Connection_Manager( 'jetpack' ) )->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) or "en". - $locale = get_option( 'WPLANG' ); - if ( ! $locale ) { - $locale = 'en'; - } - } - - update_calypso_locale( $locale ); - - return $meta; -} - -/** - * Sync wp-admin site locale to Calypso when wp-admin user locale has "Site Default" option selected. - * - * @param array $old_value Old value of the option WPLANG. - * @param array $new_value New value of the option WPLANG. - */ -function sync_wp_admin_site_locale_with_site_default_to_calypso( $old_value, $new_value ) { - if ( empty( get_user_option( 'locale' ) ) ) { - // No user locale means to use the site language (WPLANG) or "en". - update_calypso_locale( $new_value ? $new_value : 'en' ); - } -} From c96d627a4b5a71f05b57a44bb573b3284ff257fb Mon Sep 17 00:00:00 2001 From: Miguel Date: Thu, 8 Aug 2024 14:06:44 +0900 Subject: [PATCH 2/2] changelog --- .../changelog/clean-calypso-locale-sync-files | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/packages/jetpack-mu-wpcom/changelog/clean-calypso-locale-sync-files diff --git a/projects/packages/jetpack-mu-wpcom/changelog/clean-calypso-locale-sync-files b/projects/packages/jetpack-mu-wpcom/changelog/clean-calypso-locale-sync-files new file mode 100644 index 0000000000000..100abbd55b0f2 --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/clean-calypso-locale-sync-files @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +WordPress.com Features: Remove unused files for Calypso Locale Bidirectional Sync