I am working on WordPress site and I have changed the login functionality a bit and it needs the users to delete old cookies before using this functionality I have created. I am trying to clear the cookies of the user by setting a new cookie custom_wordpress_login_cookie
as a way to know which of the users have old cookies in the browser as shown in the following code.
add_action('init', 'clear_all_cookies_before_login');
function clear_all_cookies_before_login(){
if( ! isset( $_COOKIE['custom_wordpress_login_cookie'] ) ){
foreach( $_COOKIE as $key => $value ){
setcookie( $key, '', time() - YEAR_IN_SECONDS);
}
setcookie( 'custom_wordpress_login_cookie', 'true', time() YEAR_IN_SECONDS, '/', COOKIE_DOMAIN, false, true );
}
}
The new cookie is being set, but the old cookies still persists. What could be the issue ?
CodePudding user response:
you must used first unset
unset( $_COOKIE[$v_username] );
setcookie( $v_username, '', time() - ( 15 * 60 ) );
Once that’s done, we will force the cookie to expire by setting its value variable to a null value (“”) and passing in a timestamp that’s in the past (time() - ( 15 * 60 )).
CodePudding user response:
Don't use wordpress, use python instead.