最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

content restriction - How can I fetch user registration age

programmeradmin4浏览0评论

How can I fetch the user registration age? Like for example user A registered 7 days ago, user B 10 days ago etc.

In my current project, I have this requirement where there are set of tutorial videos which based on the age of user registration videos should be open to access every week.

For example, Video 1 can be accessed on the first day of user registration and Video 2 will be accessible only after 7 days of his registration Video 3 after 14 days etc the same for all the videos.

I cannot restrict this manually and make it accessible after every week because this should be depended on EACH USER registration age and not overall, I need some inputs like ways to fetch user registration age so that I have some jQuery code in mind to make video links accessible.

How can I fetch the user registration age? Like for example user A registered 7 days ago, user B 10 days ago etc.

In my current project, I have this requirement where there are set of tutorial videos which based on the age of user registration videos should be open to access every week.

For example, Video 1 can be accessed on the first day of user registration and Video 2 will be accessible only after 7 days of his registration Video 3 after 14 days etc the same for all the videos.

I cannot restrict this manually and make it accessible after every week because this should be depended on EACH USER registration age and not overall, I need some inputs like ways to fetch user registration age so that I have some jQuery code in mind to make video links accessible.

Share Improve this question edited Sep 1, 2019 at 4:44 dh47 asked Aug 31, 2019 at 10:10 dh47dh47 502 silver badges16 bronze badges 2
  • There's $user->user_registered you can use to compute this, and then e.g. use this in your search for posts against a post_meta property for 'unlock days' or similar. You should probably also check the current user against the age for a given single post when viewing it to avoid them just guessing URLs. – Rup Commented Aug 31, 2019 at 11:17
  • Can u please help me with some more insights on how to code it to fetch the X days ago etc @Rup – dh47 Commented Aug 31, 2019 at 11:46
Add a comment  | 

1 Answer 1

Reset to default 0

Solved the above task, posting the answer here so that someone can use the code

I added this code in functions.php

function is_user_video_perweek( $reg_days_ago )
{
    $currentuser = wp_get_current_user();
    return ( isset( $currentuser->data->user_registered ) && strtotime( $currentuser->data->user_registered ) < strtotime( sprintf( '-%d days', $reg_days_ago ) ) );    
}

and then in footer.php I called this function and wrote conditions to disable links using javascript example

<?php if( is_user_video_perweek( 84 ) )
{
?>
<script type="text/javascript">

    jQuery(".page-id-1572 #allvideos a").css("pointer-events", "auto");

</script>
<?php
}elseif( is_user_video_perweek( 0 ) ){?>
<script type="text/javascript">

    jQuery(".page-id-1572 #allvideos a").css("pointer-events", "none");

</script>
<?php } ?>
发布评论

评论列表(0)

  1. 暂无评论