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 |1 Answer
Reset to default 0Solved 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 } ?>
$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