admin管理员组文章数量:1323498
I am making a Logout button, but in order for it to work properly the link needs to have the correct nonce ("site/wp-login.php?action=logout&wp_nonce=X". I have found in another question (How to log out without confirmation 'Do you really want to log out?"?) a way to add the nonce, but it is only for menu links:
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');
How can I do the same for a button?
I am making a Logout button, but in order for it to work properly the link needs to have the correct nonce ("site/wp-login.php?action=logout&wp_nonce=X". I have found in another question (How to log out without confirmation 'Do you really want to log out?"?) a way to add the nonce, but it is only for menu links:
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');
How can I do the same for a button?
Share Improve this question asked Sep 1, 2020 at 18:05 Filipe RochaFilipe Rocha 1011 bronze badge 1- I have found the best solution and explanation: scratchcode.io/how-to-logout-without-confirmation-in-wordpress – Mayank Dudakiya Commented Dec 20, 2020 at 7:25
1 Answer
Reset to default 0Use wp_logout_url()
https://developer.wordpress/reference/functions/wp_logout_url/
<a href="<?php echo wp_logout_url(); ?>">Logout</a>
本文标签: phpChange button link to add nonce
版权声明:本文标题:php - Change button link to add nonce 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742143846a2422702.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论