0

I have two wordpress installations: a single one and a multisite with subdirectories. On both my users can logout with the url:

[URL to]/wp-login.php?action=logout&redirect_to=%2Fmydir%2F&_wpnonce=[some_code]

This works on the single site without confirmation, but on the site within the multisite it doesn't. Here the user needs to confirm the logout.

How can I bypass the confirmation?

Thank you.

1
0

Output the logout link with wc_logout_url() and it will be nonced and have no confirmation. The confirmation is a security measure.

You could also try adding the following to your functions.php or a plugin:

// Logout without confirmation.
function wpse_bypass_logout_confirmation() {
    global $wp;

    if ( isset( $wp->query_vars['customer-logout'] ) ) {
        wp_redirect( str_replace( '&', '&', wp_logout_url( wc_get_page_permalink( 'myaccount' ) ) ) );
        exit;
    }
}
add_action( 'template_redirect', 'wpse_bypass_logout_confirmation' );
3
  • I'm not using WooCommerce. I'm using on both pages php code echo '<a href="'.wp_logout_url($referer).'">Logout</a>'; This generates on both pages this url. But on multisite installation it requires a confirmation. – pehu Sep 6 '19 at 17:33
  • That’s why I provided the add_action option – Mike Baxter Sep 7 '19 at 1:16
  • Now I know the cause, I will communicate the solution later. It is not a multisite problem. Thank you for your help. – pehu Sep 8 '19 at 11:17
0

The structure of the urls from my Wordpress installations is

/wpone/   # Single site installation
/wptwo/   # Multisite installation with subdirectories
/wptwo/site1/
/wptwo/site2/

and so on. Furthermore, I have a directory

/site1/ 

on which I call via .htaccess the content of

/wptwo/site1/

When a user logs in, Wordpress set 3 cookies: wordpress_test_cookie, wordpress_logged_in and wordpress_sec. wordpress_test_cookie and wordpress_logged_in are valid only for /wptwo/site1/ and not for /site1/. This is checked during the generation of wpnonce. When I call /site1/logout/, it is not the same as /wptwo/site1/logout/. Logout via /wptwo/site1/logout/ works without confirmation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.