登录弹出窗口在wordpress中使用unlogeduser几分钟后

时间:2021-08-28 06:18:05

I am trying to achieve like below.

我想要实现如下。

I have a website that I am building here http://ahsanurrahman.com/myprojects/cms/wp/chris-aa/pr1/

我有一个网站,我在这里建立http://ahsanurrahman.com/myprojects/cms/wp/chris-aa/pr1/

I want to force visitor to login or register using a popup that comes out automatically after 5 minutes or like that and remains forever until they login or register. To achieve this I have done like below

我想强制访问者使用弹出窗口登录或注册,该弹出窗口在5分钟后自动出现或类似,并一直保持到登录或注册为止。为了达到这个目的,我在下面做了

<?php
if ( ( is_single() || is_front_page() || is_page() ) 
       && !is_page('login') && !is_page('register') && !is_user_logged_in()){

    echo'<div class="overlay-bg">
</div>
<div class="overlay-content popup3">
    <h1>You must login or Register to view this site.</h1>
</div>';
} 

?>

To show that popup I am using java-script that shows after 1 minutes if the user not logedin. But if they refresh the page the popup gone and come after 1 minutes again.

为了显示该弹出窗口,我使用的是java脚本,如果用户没有logedin,则在1分钟后显示。但如果他们刷新页面,弹出窗口就会消失,并在1分钟后再次出现。

So what I want to do is that I want to show the popup to each visitor after 1 minutes but want to keep that popup remains there until they login or register forever even they refresh it.

所以我想做的是我希望在1分钟后向每个访问者显示弹出窗口,但是希望保持弹出窗口保持不变,直到他们登录或永久注册,即使他们刷新它。

Thanks

1 个解决方案

#1


0  

I got the answer from my self with the help of my friend .The cookie should set like below

在朋友的帮助下,我从自己那里得到了答案。曲奇饼应如下所示

<?php
setcookie("visited",true);

if(!empty($_COOKIE['visited']) && $_COOKIE['visited'] == true)
 $popup_time = 0;
 else
 $popup_time = 60000; 
?>

Here $popup_time variable is set to the function javascript code like below

这里$ popup_time变量设置为函数javascript代码,如下所示

setTimeout(function() {
        // Show popup3 after 2 seconds
        showPopup(3);
    }, <?php echo $popup_time?>);

And that's it :) . I am frustrated that no one given me a right way here.

就是这样:)。我很沮丧,没有人在这里给我一个正确的方法。

Anyway thanks

#1


0  

I got the answer from my self with the help of my friend .The cookie should set like below

在朋友的帮助下,我从自己那里得到了答案。曲奇饼应如下所示

<?php
setcookie("visited",true);

if(!empty($_COOKIE['visited']) && $_COOKIE['visited'] == true)
 $popup_time = 0;
 else
 $popup_time = 60000; 
?>

Here $popup_time variable is set to the function javascript code like below

这里$ popup_time变量设置为函数javascript代码,如下所示

setTimeout(function() {
        // Show popup3 after 2 seconds
        showPopup(3);
    }, <?php echo $popup_time?>);

And that's it :) . I am frustrated that no one given me a right way here.

就是这样:)。我很沮丧,没有人在这里给我一个正确的方法。

Anyway thanks