diff --git a/src/Membership.php b/src/Membership.php index e7a52ee..8a23b0d 100644 --- a/src/Membership.php +++ b/src/Membership.php @@ -16,7 +16,7 @@ class Membership { * Membership constructor. * Get user data if requested * - * @param string $user_id + * @param string $user_id */ public function __construct( $user_id = '' ) { if ( $user_id ) { @@ -95,7 +95,12 @@ public function get_subscription_date( $group_id ) { * @return mixed */ public function get_valid_to( $group_id ) { - return get_user_meta( $this->user_id, '_ssc_group_subscription_valid_to_' . $group_id, true ); + $valid_to = get_user_meta( $this->user_id, '_ssc_group_subscription_valid_to_' . $group_id, true ); + if ( $valid_to === '1970-01-01' ) { + $valid_to = ''; + } + + return $valid_to; } /** diff --git a/src/Rest.php b/src/Rest.php index 5ad1913..70f794a 100644 --- a/src/Rest.php +++ b/src/Rest.php @@ -136,7 +136,7 @@ public function create_item( $request ) { $membership = new Membership( $user_id ); // Check if the user is already member of the group, if so, adjust the valid to date - if ( ! empty( $membership->groups[ $group ]['valid_to'] ) ) { + if ( ! empty( $membership->groups[ $group ]['valid_to']) && $valid_to_months !== '' ) { $valid_from = $request->get_param( 'valid_from' ) ?: ''; $original_valid_to = $membership->groups[ $group ]['valid_to']; $original_valid_from = isset( $membership->groups[ $group ]['valid_from'] )