[英]Load Page Only if User Logged in
I'd like to load different pages on a button click on the condition that the user is already logged in (or not). 我想在用户已经登录(或未登录)的条件下,单击按钮加载不同的页面。 I've tried the below code however I'm getting the error "Uncaught ReferenceError: is_user_logged_in is not defined"
我尝试了下面的代码,但是出现错误“ Uncaught ReferenceError:is_user_logged_in未定义”
My current code is: 我当前的代码是:
if(is_user_logged_in())
{
localStorage.setItem('mood-board', JSON.stringify(selectedOptions));
window.location.href = "https://manilva.co/click-to-reveal/";
}
else
{
localStorage.setItem('mood-board', JSON.stringify(selectedOptions));
window.location.href = "https://manilva.co/register/";
}
The function is_user_logged_in
is actually a wordpress internal function and written in PHP
. 函数
is_user_logged_in
实际上是一个wordpress内部函数,用PHP
。 So it can not be used in JS
directly so here is the workaround for this. 因此,不能直接在
JS
使用它,因此这里是解决方法。
So the code should be the following: 因此,代码应如下所示:
<?php if(is_user_logged_in()) { ?>
<script>
localStorage.setItem('mood-board', JSON.stringify(selectedOptions));
window.location.href = "https://manilva.co/click-to-reveal/";
</script>
<?php } else { ?>
<script>
localStorage.setItem('mood-board', JSON.stringify(selectedOptions));
window.location.href = "https://manilva.co/register/";
</script>
<?php } ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.