4 个回答
- 投票数
-
- 2012-10-06
发生这种情况是因为您缺少URL中的必要随机数,该随机数正在
中进行检查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')
This happens because you are missing the neccessary nonce in the URL, which is being checked in
wp-login.php
case 'logout' : check_admin_referer('log-out'); ...
Use
wp_logout_url
in order to retreive the URL including the nonce. If you want to redirect to a custom URL, simply pass it as an argument.<a href="<?php echo wp_logout_url('/redirect/url/goes/here') ?>">Log out</a>
You could also use
wp_loginout
which generates the link for you including translation:echo wp_loginout('/redirect/url/goes/here')
-
echo wp_loginout('/redirect/url/goes/here')工作正常.echo wp_loginout('/redirect/url/goes/here') is working fine..
- 1
- 2015-10-30
- Mayur Devmurari
-
我正在使用wp_logout_url(get_permalink())并且没有跳过确认页面.随机数作为URL的一部分生成,但我仍被发送到确认页面I'm using `wp_logout_url( get_permalink())` and the confirmation page is not bypassed. The nonce is generated as part of the URL but I am still sent to the confirmation page
- 1
- 2018-12-17
- Ralphonz
-
同样的问题在这里:(Same issue here :(
- 0
- 2019-04-14
- Jarmerson
-
谢谢.工作我回声wp_logout_url();thanks. worked me that echo wp_logout_url();
- 0
- 2020-05-26
- Erhan Demirci
-
- 2016-04-04
如果您不能使用
wp_logout_url()
函数,则可以使用以下代码关闭此验证:add_action('check_admin_referer', 'logout_without_confirm', 10, 2); function logout_without_confirm($action, $result) { /** * Allow logout without confirmation */ if ($action == "log-out" && !isset($_GET['_wpnonce'])) { $redirect_to = isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : 'url-you-want-to-redirect'; $location = str_replace('&', '&', wp_logout_url($redirect_to)); header("Location: $location"); die; } }
将
'url-you-want-to-redirect'
替换为注销后要重定向的URL.将其添加到您的
functions.php
If you can't use
wp_logout_url()
function, You can turn off this validation using this code:add_action('check_admin_referer', 'logout_without_confirm', 10, 2); function logout_without_confirm($action, $result) { /** * Allow logout without confirmation */ if ($action == "log-out" && !isset($_GET['_wpnonce'])) { $redirect_to = isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : 'url-you-want-to-redirect'; $location = str_replace('&', '&', wp_logout_url($redirect_to)); header("Location: $location"); die; } }
Replace
'url-you-want-to-redirect'
with the URL you want to redirect after logout.Add it in your
functions.php
-
这适用于未经验证的注销,但不会重定向到我想要的URL.This works for logging out without validation, but it doesn't redirect to the url I want.
- 0
- 2017-06-29
- Phu Nguyen
-
@PhuNguyen您只需要在该代码中的冒号后面加引号的重定向请求中添加重定向URL.@PhuNguyen You just need to add the redirect URL to the redirect request in that code where there is ' ' quotes, after the colon.
- 0
- 2017-12-17
- NJENGAH
-
删除此验证是否有任何安全隐患?are there any security implications for removing this validation?
- 0
- 2018-03-20
- rok
-
@ user1264304我相信以某种方式加载到浏览器中的恶意JS可以重定向到登录页面,但要做的就是注销用户.真正的恶意代码可能会尝试在有效的随机数之前替换URL.用户可以导航到另一个站点,然后该站点具有指向当前站点的注销页面的链接-假设另一个站点知道该用户具有关系.同样,除了注销用户外,没有其他后果.我从未见过.因此,回答您的问题,我认为删除验证没有安全隐患.@user1264304 I believe malicious JS somehow loaded into the browser could do a redirect to the login page, but all it's going to do is logout the user. Truly malicious code would probably seek to replace the URL before a valid nonce. The user could navigate to another site which then has a link the current site's logout page - assuming the other site is aware that the user has a relationship. Again, no consequence other than logging out the user. I've never seen this. So to answer your question, I do Not think there is a security implication for removing the validation.
- 0
- 2018-05-04
- TonyG
-
错误,重定向过多...Err, Too Many Redirects...
- 0
- 2019-02-05
- Solomon Closson
-
对我来说是一个很好的解决方案,特别是因为它在我的注销页面上不需要多余的PHP.我只是使用此链接:wp-login.php?action=logout 作为重定向,我使用home_url(),因此它可以在任何站点上使用.Excellent solution for me especially because it needs no extra php on my logout page. I simply use this link:wp-login.php?action=logout And as redirect, I use home_url() so it works on any site.
- 0
- 2020-08-28
- Ralf
-
- 2019-03-04
如果您在菜单中创建自定义链接,则将标签设置为
“Logout”
,并将URL设置为http://yourdomain.com/wp-login.php?action=logout
.然后将此函数添加到您的functions.php
文件中:function change_menu($items){ foreach($items as $item){ if( $item->title == "Logout"){ $item->url = $item->url . "&_wpnonce=" . wp_create_nonce( 'log-out' ); } } return $items; } add_filter('wp_nav_menu_objects', 'change_menu');
如果要在注销后重定向到登录页面,则应将登录URL附加为:
$item->url = $item->url . "&_wpnonce=" . wp_create_nonce( 'log-out' ).'&redirect_to='.wp_login_url();
**尝试不起作用.确实要注销页面,然后单击按钮时4出了问题.
If you create a custom link in your menu, set the label to
“Logout”
, and set the URL tohttp://yourdomain.com/wp-login.php?action=logout
. Then add this function to yourfunctions.php
file:function change_menu($items){ foreach($items as $item){ if( $item->title == "Logout"){ $item->url = $item->url . "&_wpnonce=" . wp_create_nonce( 'log-out' ); } } return $items; } add_filter('wp_nav_menu_objects', 'change_menu');
If you want to redirect to the login page after logout then you should append login URL as:
$item->url = $item->url . "&_wpnonce=" . wp_create_nonce( 'log-out' ).'&redirect_to='.wp_login_url();
** tried that did not work. Really want to log out page then 4 something went wrong when clicking the button.
-
- 2019-08-01
这通过在末尾添加
/?customer-logout=true
对我有用.http://www.website.com/?customer-logout=true
This worked for me by adding
/?customer-logout=true
at the end.http://www.website.com/?customer-logout=true
立即通过以下方式注销:
它将我重定向到需要确认注销的页面.
如何取消确认并注销后重定向到首页?