Add locale param to jetpack redirect url (#51392)
* Add locale from php * Add changefile(s) from automation for the following project(s): woocommerce * Return a full locale with language and region code * Fix style * Fix error * Lint fixes * Lint fixes --------- Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
parent
e03c51c5ed
commit
5fe53a2e3f
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: add
|
||||||
|
|
||||||
|
Add `locale` param when redirecting to the Jetpack auth page.
|
|
@ -237,7 +237,10 @@ class OnboardingPlugins extends WC_REST_Data_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
$redirect_url = $request->get_param( 'redirect_url' );
|
$redirect_url = $request->get_param( 'redirect_url' );
|
||||||
$calypso_env = defined( 'WOOCOMMERCE_CALYPSO_ENVIRONMENT' ) && in_array( WOOCOMMERCE_CALYPSO_ENVIRONMENT, [ 'development', 'wpcalypso', 'horizon', 'stage' ], true ) ? WOOCOMMERCE_CALYPSO_ENVIRONMENT : 'production';
|
$calypso_env = defined( 'WOOCOMMERCE_CALYPSO_ENVIRONMENT' ) && in_array( WOOCOMMERCE_CALYPSO_ENVIRONMENT, array( 'development', 'wpcalypso', 'horizon', 'stage' ), true ) ? WOOCOMMERCE_CALYPSO_ENVIRONMENT : 'production';
|
||||||
|
|
||||||
|
$authorization_url = $manager->get_authorization_url( null, $redirect_url );
|
||||||
|
$authorization_url = add_query_arg( 'locale', $this->get_wpcom_locale(), $authorization_url );
|
||||||
|
|
||||||
if ( Features::is_enabled( 'use-wp-horizon' ) ) {
|
if ( Features::is_enabled( 'use-wp-horizon' ) ) {
|
||||||
$calypso_env = 'horizon';
|
$calypso_env = 'horizon';
|
||||||
|
@ -247,15 +250,53 @@ class OnboardingPlugins extends WC_REST_Data_Controller {
|
||||||
'success' => ! $errors->has_errors(),
|
'success' => ! $errors->has_errors(),
|
||||||
'errors' => $errors->get_error_messages(),
|
'errors' => $errors->get_error_messages(),
|
||||||
'url' => add_query_arg(
|
'url' => add_query_arg(
|
||||||
[
|
array(
|
||||||
'from' => $request->get_param( 'from' ),
|
'from' => $request->get_param( 'from' ),
|
||||||
'calypso_env' => $calypso_env,
|
'calypso_env' => $calypso_env,
|
||||||
],
|
),
|
||||||
$manager->get_authorization_url( null, $redirect_url )
|
$authorization_url,
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a locale string for wpcom.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function get_wpcom_locale() {
|
||||||
|
// List of locales that should be used with region code.
|
||||||
|
$locale_to_lang = array(
|
||||||
|
'bre' => 'br',
|
||||||
|
'de_AT' => 'de-at',
|
||||||
|
'de_CH' => 'de-ch',
|
||||||
|
'de' => 'de_formal',
|
||||||
|
'el' => 'el-po',
|
||||||
|
'en_GB' => 'en-gb',
|
||||||
|
'es_CL' => 'es-cl',
|
||||||
|
'es_MX' => 'es-mx',
|
||||||
|
'fr_BE' => 'fr-be',
|
||||||
|
'fr_CA' => 'fr-ca',
|
||||||
|
'nl_BE' => 'nl-be',
|
||||||
|
'nl' => 'nl_formal',
|
||||||
|
'pt_BR' => 'pt-br',
|
||||||
|
'sr' => 'sr_latin',
|
||||||
|
'zh_CN' => 'zh-cn',
|
||||||
|
'zh_HK' => 'zh-hk',
|
||||||
|
'zh_SG' => 'zh-sg',
|
||||||
|
'zh_TW' => 'zh-tw',
|
||||||
|
);
|
||||||
|
|
||||||
|
$system_locale = get_locale();
|
||||||
|
if ( isset( $locale_to_lang[ $system_locale ] ) ) {
|
||||||
|
// Return the locale with region code if it's in the list.
|
||||||
|
return $locale_to_lang[ $system_locale ];
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the locale is not in the list, return the language code only.
|
||||||
|
return explode( '_', $system_locale )[0];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the current user has permission to install plugins
|
* Check whether the current user has permission to install plugins
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue