在WordPress中登出后阻止返回操作。

huangapple go评论58阅读模式
英文:

Prevent the back action after logout in wordpress

问题

我试图在WordPress注销后阻止返回按钮。当我从管理面板注销时,将我重定向到登录页面,然后当我点击返回按钮时,页面加载管理面板缓存(如果在缓存页面上点击元素,将重定向到登录页面,因为会话已过期)。

如何在WordPress中防止注销后的返回操作?

WordPress是否有任何防止缓存页面的函数?

我必须使用JavaScript吗?

备注:我的Web服务器是NGINX。

英文:

I am try to prevent back button after logout in WordPress. When I log out from admin panel redirect me to login page then when I click on back button page load admin panel cached (if click on elements in cached page redirect to login page because session expired).
How can I Prevent the back action after logout in WordPress?

WordPress have any function for prevent cache page?

I must use JavaScript?

Notes: My web server is NGINX

答案1

得分: 2

以下是翻译好的部分:

在许多不同的浏览器上似乎都有效的东西在这里。
<br />转到您的 wp-includes/functions.php 文件,并将此代码添加到底部(您可能需要清除您的 WordPress 缓存一次,以便它显示在页面上。

function custom_admin_js_force_logout() {
		echo &#39;&quot;
&lt;script&gt;
    window.onunload = function(){};
    if (window.performance &amp;&amp; window.performance.navigation.type === window.performance.navigation.TYPE_BACK_FORWARD) {
        document.body.innerHTML=null; // 在重新加载之前隐藏页面
        location.reload();
    }
&lt;/script&gt;
	&quot;&#39;;
}
add_action(&#39;admin_footer&#39;, &#39;custom_admin_js_force_logout&#39;);
英文:

Here is something I use and seems to work on many different browsers.
<br />Go to your wp-includes/functions.php file and add this code at the very bottom (you may need to clear your wordpress cache one time so it shows on the pages.

function custom_admin_js_force_logout() {
		echo &#39;&quot;
&lt;script&gt;
    window.onunload = function(){};
    if (window.performance &amp;&amp; window.performance.navigation.type === window.performance.navigation.TYPE_BACK_FORWARD) {
        document.body.innerHTML=null; // hide page before reload
        location.reload();
    }
&lt;/script&gt;
	&quot;&#39;;
}
add_action(&#39;admin_footer&#39;, &#39;custom_admin_js_force_logout&#39;);

huangapple
  • 本文由 发表于 2023年5月22日 00:20:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76300851.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定