如何绕过wordpress您确定要注销消息woocommerce,并注销到hompage?

时间:2017-07-10 18:05:54

标签: php wordpress woocommerce

我有一个带有注销链接的上方导航菜单,当我点击它时,会弹出一条消息,询问我是否确定要退出。如何绕过此消息,将其完全删除后自动退出到主页?我可以在退出菜单链接中添加什么链接?

目前正是这样:http://website.com/my-account/customer-logout/

2 个答案:

答案 0 :(得分:1)

这可能是因为您忘记了URL中的必要nonce,这是在wp-login.php中检查的:

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

您应该使用wp_logout_url来检索包含nonce的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');

就是这样。 最好的问候。

答案 1 :(得分: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;
}