-
Notifications
You must be signed in to change notification settings - Fork 799
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor filter and profile in preparation for reverse sync PR
- Loading branch information
Showing
3 changed files
with
49 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 0 additions & 44 deletions
44
projects/packages/jetpack-mu-wpcom/src/features/calypso-locale-sync/calypso-locale-sync.php
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
...s/packages/jetpack-mu-wpcom/src/features/calypso-locale-sync/sync-wp-admin-to-calypso.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* Makes sure Calypso and wp-admin locales are in sync. | ||
* | ||
* @package automattic/jetpack-mu-wpcom | ||
*/ | ||
|
||
use Automattic\Jetpack\Connection\Client; | ||
use Automattic\Jetpack\Connection\Manager as Connection_Manager; | ||
|
||
/** | ||
* 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). | ||
$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 ); | ||
} |