我找到了使用以下函数的解决方案:
function auto_login() {
// make sure user is not logged in and "user" was POST\'d
$username = isset( $_POST[\'user\'] )? $_POST[\'user\'] : false;
if ( ! is_user_logged_in() && $username ){
// load the user by username
$user = get_user_by( \'login\', $username );
if ( $user ) {
// log user in using the $user object properties
wp_set_current_user( $user->ID, $user->user_login );
wp_set_auth_cookie( $user->ID );
do_action( \'wp_login\', $user->user_login );
}
}
}
add_action( \'wp_loaded\',\'auto_login\' );