Create default pages in store locale language (#37795)

This commit is contained in:
Barry Hughes 2023-04-21 10:35:53 -07:00 committed by GitHub
commit bf8d19e35a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: fix
When creating default storefront pages, the site language (and not the language of the current user) should be used.

View File

@ -710,6 +710,9 @@ class WC_Install {
* Create pages that the plugin relies on, storing page IDs in variables.
*/
public static function create_pages() {
// Set the locale to the store locale to ensure pages are created in the correct language.
wc_switch_to_site_locale();
include_once dirname( __FILE__ ) . '/admin/wc-admin-functions.php';
/**
@ -780,6 +783,9 @@ class WC_Install {
! empty( $page['post_status'] ) ? $page['post_status'] : 'publish'
);
}
// Restore the locale to the default locale.
wc_restore_locale();
}
/**

View File

@ -2211,7 +2211,9 @@ function wc_get_permalink_structure() {
* @since 3.1.0
*/
function wc_switch_to_site_locale() {
if ( function_exists( 'switch_to_locale' ) ) {
global $wp_locale_switcher;
if ( function_exists( 'switch_to_locale' ) && isset( $wp_locale_switcher ) ) {
switch_to_locale( get_locale() );
// Filter on plugin_locale so load_plugin_textdomain loads the correct locale.
@ -2228,7 +2230,9 @@ function wc_switch_to_site_locale() {
* @since 3.1.0
*/
function wc_restore_locale() {
if ( function_exists( 'restore_previous_locale' ) ) {
global $wp_locale_switcher;
if ( function_exists( 'restore_previous_locale' ) && isset( $wp_locale_switcher ) ) {
restore_previous_locale();
// Remove filter.