我有一个简单的自动登录挂钩,如下所示:
function auto_login() {
if (!is_user_logged_in()) {
//Removed some code for brevity.
$user = get_userdatabylogin($domainName);
if ($user != null) {
//Set the auth cookie.
wp_set_auth_cookie($user->ID, false, null);
//Set the current user (this will also set WP objects at the global level)
wp_set_current_user($user->ID);
}
}
}
add_action(\'init\', \'auto_login\');
这段代码确实有效,但为了在页面顶部获得管理栏,需要刷新页面。这让我觉得我没有在Wordpress页面生命周期中尽早填充一些全局对象。
我应该在其他地方调用此方法吗init
?