2017-07-10 16 views
0

我有一個帶有註銷鏈接的上層導航菜單,當我點擊它時,彈出一個消息,詢問我是否確定要註銷。我如何繞過這條信息,徹底刪除它有自動註銷到主頁?我可以在註銷菜單鏈接中加入什麼鏈接?如何繞過wordpress,您確定要註銷郵件woocommerce,並註銷到hompage?

目前,它是這樣的:http://website.com/my-account/customer-logout/

+0

這是一個重複:https://wordpress.stackexchange.com/questions/67336/how-to-log -out-without-confirmation-do-you-really-want-to-log-out –

+0

此外,你還沒有展示你如何設計URL來註銷。如果您手動將其添加到導航菜單中,則無法使用下面的答案。 –

回答

1

這也許是因爲你忘了在URL中neccessary隨機數,這是在WP-login.php中被檢查:

case 'logout' : 
check_admin_referer('log-out'); 
... 

您應該使用wp_logout_url以便檢索包含隨機數的URL。如果你想重定向到一個定製URL,只是把它作爲一個參數:

<a href="<?php echo wp_logout_url('/redirect/url/goes/here') ?>">Log out</a> 

另一件事,你也可以使用wp_loginout產生包括翻譯的鏈接給你:

echo wp_loginout('/redirect/url/goes/here'); 

That'它。 此致敬禮。

+0

由於OP建議他們可能手動將其添加到他們的導航菜單(而不是通過代碼),因此您可能在解決問題時也解決了這個問題。 –

+0

這個答案來自這裏:https://wordpress.stackexchange.com/a/67342/20963 – David

0

由於重複從一個網站允許到另一個,我在原有基礎上的工作在這裏張貼這樣的回答:https://wordpress.stackexchange.com/a/156261/11704

根據您的問題,這聽起來像你想Log Out鏈接出現在你的資產淨值菜單。

爲了做到這一點,併爲該鏈接包含適當的NONCE(在你的情況下,這是缺少的,這就是爲什麼「你確定要註銷嗎?」消息出現),你需要創建一個插件或修改你的主題。

下面的代碼添加到您的自定義插件文件,或者你的主題functions.php文件:

// hook into WP filter for nav items 
add_filter('wp_nav_menu_items', 'my_loginout_menu_link', 10, 2); 

// modify links in nav menu 
function my_log_in_out_menu_link($items, $args) { 
    // only do this if it's the "main" navigation 
    if ($args->theme_location == 'primary') { 
     // if the user is logged in, add a log out link 
     if (is_user_logged_in()) { 
     // use the official WP code to get the logout URL. 
     // passed-in argument will cause it redirect to home page 
     $items .= '<li class="log-out"><a href="'. wp_logout_url(home_url('/')) .'">'. __("Log Out", "your_themes_i18n_slug") .'</a></li>'; 
     } else { 
     // if the user is NOT logged in, add a log in link 
     $items .= '<li class="log-in"><a href="'. wp_login_url(get_permalink()) .'">'. __("Log In", "your_themes_i18n_slug") .'</a></li>'; 
     } 
    } 

    return $items; 
}