WordPress.org

Ready to get started?Download WordPress

Forums

Page Security by Contexture
[resolved] Time line for users (2 posts)

  1. msrie
    Member
    Posted 3 years ago #

    Hi,

    Great plugin. I was wondering about setting time frames for users, i.e. if a user has subscribed or logged in the first time is there a way to only have that username and password valid for 2 weeks or so?

    Thanks a lot,

    Marie

  2. Matt van Andel
    Member
    Plugin Author

    Posted 3 years ago #

    Yes, but you'd have to get your hands dirty with a bit of code.

    There's a few ways you could do this, but here's some pointers:

    1. Start by creating an appropriate hook in your theme's functions.php file, or as a new plugin. You'd probably want to use the user_register hook.
    2. Use CTXPS_Queries::add_membership_with_expiration() to automatically register new users to a specified group with a specified expiration date (this is located in contexture-page-security/core/model_queries.php.

    Here's some code right off the top of my head that may do the trick (totally untested) - you'll need to check it to ensure the correct group id and whatnot suit your needs, of course.

    add_action('user_register','autoregister_user',10,1);
    function autoregister_user($user_id){
       $group_id = 3;
       $expires = strtotime(date("Y-m-d")) . " +2 week");
       $expires = date("Y-m-d",$expires);
       CTXPS_Queries::add_membership_with_expiration($user_id,$group_id,$expires);
    }

    Theoretically, the above will automatically enroll any newly registered user in the group with id 3, and that membership will expire two weeks from the day they registered.

    Hope this helps.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic