switch_to_user_locale

函式
switch_to_user_locale ( $user_id )
引數
  • (int) $user_id User ID.
    Required:
返回值
  • (bool) True on success, false on failure.
定義位置
相關方法
switch_to_localeget_user_localeswitch_to_blogswitch_themerestore_previous_locale
引入
6.2.0
棄用
-

switch_to_user_locale(): 這個函式暫時將WordPress網站的語言環境切換到指定使用者的語言環境。

function switch_to_user_locale( $user_id ) {
	/* @var WP_Locale_Switcher $wp_locale_switcher */
	global $wp_locale_switcher;

	if ( ! $wp_locale_switcher ) {
		return false;
	}

	return $wp_locale_switcher->switch_to_user_locale( $user_id );
}

常見問題

FAQs
檢視更多 >