content restriction - How can I fetch user registration age

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 c

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 } ?>

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

相关推荐

  • content restriction - How can I fetch user registration age

    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 c

    3小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信