WordPress更改当前用户函数:set_current_user
WordPress函数set_current_user用于更改当前登录用户,在一些需要代登录的场景比较有用。自WordPress 3.0.0版本起,已不建议使用set_current_user()函数,应该使用wp_set_current_user()函数。
set_current_user( int|null $id, string $name = '' )
函数参数
$id
整数
用户ID
$name
字符串
用户登录名
函数使用示例
$user_id = 2; $user = get_user_by('id', $user_id); if($user) { wp_set_current_user($user_id, $user->user_login); wp_set_auth_cookie($user_id); do_action('wp_login', $user->user_login, $user); }
扩展阅读
set_current_user()函数位于:wp-includes/pluggable-deprecated.php
相关函数:
- wp_set_current_user()
本网站文章仅供交流学习 ,不作为商用, 版权归属原作者,部分文章推送时未能及时与原作者取得联系,若来源标注错误或侵犯到您的权益烦请告知,我们将立即删除.