I use wp_logout_url() to output a logout link. How can I avoid displaying the confirmation page that appears after clicking the link?
<a href="<?= wp_logout_url(get_permalink()); ?>">Log out</a>
Why does this even happen? I already did some googling and it seems to have something to do with a missing nonce but in my case the nonce isn't missing at all. wp_logout_url() adds the nonce to the link.
edit:
I have figured out now that if I log in with the standard WordPress /wp-admin/ login form, logging out works without the confirmation page. But if I use my own custom frontend login form that uses wp_signon(), logging out only works with the confirmation page.
Here is my login code:
add_action('after_setup_theme', 'my_login');
function my_login()
{
if(!empty($_POST['my_username']) && !empty($_POST['my_password']))
{
$user = wp_signon([
'user_login' => $_POST['my_username'],
'user_password' => $_POST['my_password'],
'remember' => true],
is_ssl());
if(is_wp_error($user))
{
echo $user->get_error_message();
}
else
{
wp_set_current_user($user->ID);
}
}
}
The form on the frontend simply is:
<form method="post" action="<?= get_permalink(); ?>">
<p><input type="text" name="my_username" placeholder="Username" /></p>
<p><input type="password" name="my_password" placeholder="Password" /></p>
<p><input type="submit" name="submit" value="Login" /></p>
</form>
Am I doing something wrong here which causes this to behave differently to the normal WordPress login?