wp cron - How to expire guest users after 1.5 hours logged in?

I want to pre create a table of users 1-200Then after login for the first time itEdited to be further explained & d

I want to pre create a table of users 1-200 Then after login for the first time it


Edited to be further explained & described: I'm trying to issue access to all pages for a guest user with a defined (set) timing of 90 minutes after the first login.

I want to create N guests users. After each user logs in for the first time; the user is granted 90 minutes to explore the web freely. After the time has finished the user could be deleted/changed password or whatever works easier.

Thanks in advance.

I want to pre create a table of users 1-200 Then after login for the first time it


Edited to be further explained & described: I'm trying to issue access to all pages for a guest user with a defined (set) timing of 90 minutes after the first login.

I want to create N guests users. After each user logs in for the first time; the user is granted 90 minutes to explore the web freely. After the time has finished the user could be deleted/changed password or whatever works easier.

Thanks in advance.

Share Improve this question edited Jul 9, 2020 at 2:23 Victor Vazquez asked Jul 7, 2020 at 17:27 Victor VazquezVictor Vazquez 11 bronze badge 2
  • Maybe a better way is to 'expire' the access codes after xx time. The access code could have a datestamp embedded (in the same method as a password). Your process would decode the access code and compare the embedded datestamp with current time If within allowed time, allow the code to work. But your question is very thin on details. – Rick Hellewell Commented Jul 7, 2020 at 17:45
  • Hello Rick, thanks for trying to help me out. To give a solid start... I don't have any experience coding, just learnt basics on youtube. I built a wordpress page where only members can get access to it. Later I was requested to add this "temporary users" where they can only access the page for 90 mins. Hope this clarifies it a bit. – Victor Vazquez Commented Jul 8, 2020 at 20:06
Add a comment  | 

1 Answer 1

Reset to default 0

In your single.php template file:

<?php
if (has_post()) {
    the_post();

    $user = wp_get_current_user();
    $hasPermission = in_array('subscriber', $user->roles);
    // or maybe instead of a role, you can check for your custom permission:
    // $hasPermission = current_user_can('view_access_codes');

    $postTime = get_post_time('U', true);
    $timeThreshold = time() - 60 * 60 * 1.5;
    $hasTimePassed = $postTime < $timeThreshold;

    if (!$hasPermission && $hasTimePassed) {
        status_header(\WP_Http::FORBIDDEN);
        ?>
        Only registered users can view this page.
        <?php
    } else {
        // print the post
    }
}

or with the PHP DateTime object:

$postDate = new \DateTime(get_post_time(DATE_W3C));
$postDate->modify('+90 minutes');
$hasTimePassed = $postDate < new \DateTime();

Beware that the post still can be accessible by other means, such as the REST API or your RSS feed. For these I'd recommend using the the_content filter.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742281392a4414553.html

相关推荐

  • wp cron - How to expire guest users after 1.5 hours logged in?

    I want to pre create a table of users 1-200Then after login for the first time itEdited to be further explained & d

    21小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信