WP_Locale_Switcher::change_locale
Changes the site's locale to the given one.
Loads the translations, changes the global $wp_locale object and updates all post type labels.
Method of the class: WP_Locale_Switcher{}
Hooks from the method
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->change_locale( $locale );
- $locale(string) (required)
- The locale to change to.
Notes
- Global. WP_Locale.
$wp_localeWordPress date and time locale object. - Global. PHPMailer\PHPMailer\PHPMailer.
$phpmailer
Changelog
| Since 4.7.0 | Introduced. |
WP_Locale_Switcher::change_locale() WP Locale Switcher::change locale code WP 6.9.1
private function change_locale( $locale ) {
global $wp_locale, $phpmailer;
$this->load_translations( $locale );
$wp_locale = new WP_Locale();
WP_Translation_Controller::get_instance()->set_locale( $locale );
if ( $phpmailer instanceof WP_PHPMailer ) {
$phpmailer->setLanguage();
}
/**
* Fires when the locale is switched to or restored.
*
* @since 4.7.0
*
* @param string $locale The new locale.
*/
do_action( 'change_locale', $locale );
}