Skip to content

Instantly share code, notes, and snippets.

@pbrocks
Last active June 21, 2019 23:04
Show Gist options
  • Save pbrocks/aee566cff779ec04668413a0c682a3a5 to your computer and use it in GitHub Desktop.
Save pbrocks/aee566cff779ec04668413a0c682a3a5 to your computer and use it in GitHub Desktop.
Add a banner message to the top of your site to let members know that their membership has expired.
<?php
/**
* Add a banner message to the top of your site to let members know that their membership has expired.
*/
// Let's build the banner message to display if member expired.
function extra_warning_for_renewal( $input ) {
global $pmpro_pages;
$target = get_permalink( $pmpro_pages['levels'] );
$message = 'Hi ' . $input['display_name'] . '. Your ' . ( ( $input['message'] ) ? $input['membership_name'] . ' subscription, expired on ' . $input['enddate'] . ' <a class="button-primary" href="' . esc_url( $target ) . '">' . $input['message'] . '</a>' : '' );
echo '<div style="width:100%;height:4rem;background-color:salmon;"><h4 style="text-align:center;color:white;padding:1rem;"> ' . $message . ' </h4></div>';
}
// Gather the user information.
add_action( 'wp_head', 'check_user_for_renewal' );
function check_user_for_renewal() {
$user_id = get_current_user_id();
$level = pmpro_getMembershipLevelForUser( $user_id );
$user_info = get_userdata( $user_id );
$info['expiration_date'] = ( $level->enddate ) ? date( 'm/d/Y', $level->enddate ) : 'not set';
$info['subscription_id'] = $level->subscription_id;
$info['membership_id'] = $level->id;
$info['membership_name'] = $level->name;
$info['display_name'] = $user_info->data->display_name;
$info['user_registered'] = $user_info->data->user_registered;
$info['user_email'] = $user_info->data->user_email;
$info['billing_amount'] = $level->billing_amount;
$info['cycle_period'] = $level->cycle_period;
$info['cycle_number'] = $level->cycle_number;
$info['start_unix'] = $level->startdate;
$info['startdate'] = date( 'm/d/Y', $level->startdate );
$info['end_unix'] = $level->enddate;
$info['enddate'] = ( null === date( 'm/d/Y', $level->enddate ) ) ? date( 'm/d/Y', $level->enddate ) : date( 'm/d/Y', strtotime( "+{$info['cycle_number']} {$info['cycle_period']} -1 day", strtotime( $info['startdate'] ) ) );
if ( strtotime( $info['enddate'] ) < time() ) {
$info['message'] = 'Time to Renew. Click Here!';
extra_warning_for_renewal( $info );
}
return $info;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment