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.

  • 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 Aug 31 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 Aug 31 at 11:46
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 } ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.