Retrieve Custom User Meta from Expire Users Plugin [RESOLVED]

I need a nudge in the right direction. I’m using the User Registration Add-On and the Expire Users plugin to setup a simple membership site. Everything is setup and works fine except that I cannot seem to retrieve the “Expires Date” timestamp from the user meta stored in “_expire_user_date” (created by the Expire Users plugin).

I have started a custom function below to compare the current date to the stored date, then add one year to the date (whichever is greater). This new “renewal date” will then be stored in a hidden field in the GF, populated dynamically. However the issue seems to be I cannot get the timestamp from “_expire_user_date” as my $current_expire_date variable.

# Populate "Expiration Date" hidden field + 1 year on the membership renewal form
function timestamp_renewal_date() {
	// If it's not a logged-in user viewing this, never mind
	if( ! is_user_logged_in() ) :
		return;
	endif;
	// Get the "_expire_user_date" user meta value for the current user
	$current_expire_date = get_user_meta( get_current_user_id(), '_expire_user_date', true );
  $current_date = strtotime("now");
  if ($current_expire_date > $current_date) {
    $expire_date = date('d-m-Y H:i:s', $current_expire_date);
    return strtotime('+1 year',$expire_date);
  } else {
    return strtotime('+1 year');
  }
}
add_action( 'gform_field_value_renewaldate', 'timestamp_renewal_date' );

Thanks in advance for any help.

Take a look at this documentation regarding Gravity Forms logging:

You will first need to enable Gravity Forms logging:

Then add your own custom statements to your code to see what the value of $current_expire_date is when you retrieve it. It may be empty, or in a format you are not expecting.

After adding custom logging statements to your code and enabling logging, please test the form where the renewaldate field should be pre-populated, and then check the Gravity Forms Core log for your custom logging statements to see what is going on. Post the link to the log file if you need assistance figuring this out.

1 Like

Thank you Chris! Thanks for introducing me to the logging and debugging in gravity forms. That is one of the best features of GF. It helped me determine that I was actually retrieving the expires date timestamp, but I had just been using the strtotime function incorrectly.

Below is my updated code in case anybody finds it useful in the future.

# Populate "Expiration Date" hidden field + 1 year for the membership renewal form
function timestamp_renewal_date() {
	// If it's not a logged-in user viewing this, never mind
	if( ! is_user_logged_in() ) :
		return;
	endif;
	// Get the "_expire_user_date" user meta value for the current user
	$current_expire_date = get_user_meta( get_current_user_id(), '_expire_user_date', true );
  $current_date = strtotime("now");
  if ($current_expire_date > $current_date) {
    $expire_date = date('d-m-Y H:i:s', $current_expire_date);
    return strtotime($expire_date . "+1 year");
  } else {
    return strtotime('+1 year');
  }
}
add_action( 'gform_field_value_renewaldate', 'timestamp_renewal_date' );
1 Like

this

Weekend