admin管理员组文章数量:1332395
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
1 Answer
Reset to default 0In 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.
本文标签: wp cronHow to expire guest users after 15 hours logged in
版权声明:本文标题:wp cron - How to expire guest users after 1.5 hours logged in? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742281391a2446158.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论