Add a nonce and confirmation for logging out via the customer my account page
This commit is contained in:
parent
396c8aa4fc
commit
636ad8b652
|
@ -56,10 +56,14 @@ class WC_Shortcode_My_Account {
|
||||||
} else {
|
} else {
|
||||||
wc_get_template( 'myaccount/form-login.php' );
|
wc_get_template( 'myaccount/form-login.php' );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Start output buffer since the html may need discarding for BW compatibility
|
// Start output buffer since the html may need discarding for BW compatibility
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
if ( isset( $wp->query_vars['customer-logout'] ) ) {
|
||||||
|
wc_add_notice( sprintf( __( 'Are you sure you want to log out? <a href="%s">Confirm and log out</a>', 'woocommerce' ), wc_logout_url() ) );
|
||||||
|
}
|
||||||
|
|
||||||
// Collect notices before output
|
// Collect notices before output
|
||||||
$notices = wc_get_notices();
|
$notices = wc_get_notices();
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ function wc_template_redirect() {
|
||||||
wp_redirect( wc_get_page_permalink( 'cart' ) );
|
wp_redirect( wc_get_page_permalink( 'cart' ) );
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
} elseif ( isset( $wp->query_vars['customer-logout'] ) ) {
|
} elseif ( isset( $wp->query_vars['customer-logout'] ) && ! empty( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'], 'customer-logout' ) ) {
|
||||||
|
|
||||||
// Logout
|
// Logout
|
||||||
wp_redirect( str_replace( '&', '&', wp_logout_url( wc_get_page_permalink( 'myaccount' ) ) ) );
|
wp_redirect( str_replace( '&', '&', wp_logout_url( wc_get_page_permalink( 'myaccount' ) ) ) );
|
||||||
|
@ -2646,7 +2646,7 @@ function wc_logout_url( $redirect = '' ) {
|
||||||
$redirect = $redirect ? $redirect : wc_get_page_permalink( 'myaccount' );
|
$redirect = $redirect ? $redirect : wc_get_page_permalink( 'myaccount' );
|
||||||
|
|
||||||
if ( $logout_endpoint ) {
|
if ( $logout_endpoint ) {
|
||||||
return wc_get_endpoint_url( 'customer-logout', '', $redirect );
|
return wp_nonce_url( wc_get_endpoint_url( 'customer-logout', '', $redirect ), 'customer-logout' );
|
||||||
} else {
|
} else {
|
||||||
return wp_logout_url( $redirect );
|
return wp_logout_url( $redirect );
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
<p><?php
|
<p><?php
|
||||||
/* translators: 1: user display name 2: logout url */
|
/* translators: 1: user display name 2: logout url */
|
||||||
printf(
|
printf(
|
||||||
__( 'Hello %1$s (not %1$s? <a href="%2$s">Sign out</a>)', 'woocommerce' ),
|
__( 'Hello %1$s (not %1$s? <a href="%2$s">Log out</a>)', 'woocommerce' ),
|
||||||
'<strong>' . esc_html( $current_user->display_name ) . '</strong>',
|
'<strong>' . esc_html( $current_user->display_name ) . '</strong>',
|
||||||
esc_url( wc_logout_url( wc_get_page_permalink( 'myaccount' ) ) )
|
esc_url( wc_logout_url( wc_get_page_permalink( 'myaccount' ) ) )
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue