• pandraka

    (@pandraka)


    I’m working on a site that needs to expire users who are inactive after 90 days. if a user logs in on day 53, then I need to reset their expiration date to the current date + 90 days.

    The function I think might work is

    function reset_expire_date() {

    $e_user = new Expire_User( $user_id );
    $e_user->set_expire_time_in_future( 3, ‘months’ );
    }
    add_action(‘wp_login’, ‘reset_expire_date’);

    I’m not sure how to check if the user isn’t subject to expieration ie an user whose expiration is never or not set at all. I’d also like to make the expiration date use the default Expiry Date. Any suggestions?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter pandraka

    (@pandraka)

    I’m trying to update the expiry date everytime an user logs on to the site. this is the code I put this in my child theme’s function.php file:

    // modifies the users expire date on login

    function reset_expire_date() {

    $e_user = new Expire_User( $user_id );

    $e_user->set_expire_time_in_future( 3, ‘months’ );
    }
    add_action(‘wp_login’, ‘reset_expire_date’);

    The date should be updated on login, but isn’t. I can’t see any error in the error log. Any ideas?

    jurnet

    (@jurnet)

    I can answer because i work on it now.
    This my code :
    function reset_expire_date() {
    if( class_exists( ‘Expire_Users’ ) ) {
    $user_id = get_current_user_id();
    $e_user = new Expire_User( $user_id );
    $e_user->set_expire_time_in_future( 180, ‘days’ );
    $e_user->save_user();
    var_dump($e_user);
    }
    die();
    }
    add_action(‘wp_login’, ‘reset_expire_date’);

    Thread Starter pandraka

    (@pandraka)

    Thank you for your response. I had to put this issue down for a bit, but I am currently working on it again.

    Thread Starter pandraka

    (@pandraka)

    @jurnet I guess I’m doing something wrong, because the code didn’t work. I put the code into my child theme’s functions.php file. It doesn’t update the date at all.

    I did a test using the child theme’s header file to see if I was able to do a proof of concept. In the header file I put:
    if(class_exists(‘Expire_Users’)){
    $user_id = get_current_user_id();
    $user_expire_date = get_user_meta($user_Id,’_expire_user_date’,true);
    if ( !empty($user_expire_date)) {
    $amt = 180;
    $expire_timestamp = current_time( ‘timestamp’ ) + ( DAY_IN_SECONDS * $amt );
    update_user_meta($user_id,’_expire_user_date’,$expire_timestamp);
    }else{
    echo ‘<p> user does not have an expire date ‘.$user_id.'</p>’;
    }

    }

    That works, but when I put this logic into the functions.php file, nothing updates

    function reset_expire_date() {
    if(class_exists(‘Expire_Users’)){
    $user_id = get_current_user_id();
    $user_expire_date = get_user_meta($user_Id,’_expire_user_date’,true);
    if ( !empty($user_expire_date)) {
    $amt = 180;
    $expire_timestamp = current_time( ‘timestamp’ ) + ( DAY_IN_SECONDS * $amt );
    update_user_meta($user_id,’_expire_user_date’,$expire_timestamp);

    }
    }
    }
    add_action(‘wp_login’,’reset_expire_date’);
    ?>

    I’m not quite sure what I’m doing wrong. Thanks for any help/suggestions

    • This reply was modified 6 years, 9 months ago by pandraka.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Update expiration date when user logs on’ is closed to new replies.