在Wordpress Core中修复之前,您可以使用这种“脏”方式:
Switch to user locale before admin bar items are processed:
add_filter( \'admin_bar_menu\', \'ws390690_admin_bar_in_user_locale\', 10, 1 );
function ws390690_admin_bar_in_user_locale($wp_admin_bar){
switch_to_locale( get_user_locale() );
return $wp_admin_bar;
}
Switch back to site locale after admin bar has been rendered:
add_filter( \'wp_after_admin_bar_render\', \'ws390690_admin_bar_in_user_locale_back\', 10, 2 );
function ws390690_admin_bar_in_user_locale_back(){
restore_previous_locale();
}
正如@henrywright所提到的,它也在这里工作
https://core.trac.wordpress.org/ticket/38643