根据@JacobPeattie关于使用cookie的建议,我为这个问题构建了以下工作解决方案:
/* LOGIN / LOGOUT */
/* --- */
/* AUTOLOGIN */
if( isset($_GET[\'username\']) ) {
$user = get_user_by(\'login\', $_GET[\'username\']);
// Redirect URL //
if ( !is_wp_error( $user ) ) {
if ( in_array( \'customer\', (array) $user->roles ) ) {
wp_clear_auth_cookie();
wp_set_current_user ( $user->ID );
wp_set_auth_cookie ( $user->ID );
wp_redirect( \'/lovelists/toon-lovelist/\' );
$autologin = 1;
setcookie( \'autologin_status\', $autologin, time()+31556926 , "/" );
exit();
}
}
}
/* AUTOLOGOUT */
function log_out_user() {
global $wp;
$path = $_SERVER[\'REQUEST_URI\'];
if ( is_user_logged_in() && $_COOKIE[\'autologin_status\'] == 1 && ( $path == \'/lovelists/maak-lovelist/\' || $path == \'/lovelists/login/\' ) ) {
wp_logout(); // this will logout user
unset( $_COOKIE[\'autologin_status\'] );
}
}
add_action( \'init\', \'log_out_user\' );