Skip to content

Instantly share code, notes, and snippets.

@flowdee
Created May 21, 2017 08:37
Show Gist options
  • Save flowdee/126a93cb1628b939282bd2d922cf525b to your computer and use it in GitHub Desktop.
Save flowdee/126a93cb1628b939282bd2d922cf525b to your computer and use it in GitHub Desktop.
EDD License upgrade: Extend expiration
/**
* License upgrade: Extend expiration
*/
add_action('edd_sl_license_upgraded', function( $license_id, $args ) {
$license = edd_software_licensing()->get_license( $license_id );
$download_id =$license->download->id;
$download = new EDD_SL_Download( $download_id );
$download_exp_length = $download->get_expiration_length();
$download_exp_length_unit = $download->get_expiration_unit();
$exp_date = ucfirst( $license->expiration );
$exp_date_new = strtotime('+' . $download_exp_length . ' ' . $download_exp_length_unit, $exp_date);
$updated = update_post_meta( $license_id, '_edd_sl_expiration', $exp_date_new );
if ( $updated ) {
$log_id = wp_insert_post(
array(
'post_title' => __( 'LOG - Expiration extended after license upgrade: +', 'edd' ) . $download_exp_length . ' ' . $download_exp_length_unit,
'post_name' => 'fwwp-log-license-extended-' . $license_id . '-' . md5( current_time( 'timestamp' ) ),
'post_type' => 'edd_license_log',
'post_content' => json_encode( 'Expiration extended.' ),
'post_status' => 'publish'
)
);
add_post_meta( $log_id, '_edd_sl_log_license_id', $license_id );
}
}, 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment