CODE SNIPPET TO COMMUNITY MEMBERS WHO USE PRO SITE

Hey,

here’s a code snippet that will allow you to show to a site administrator how many days they have left before their site goes down the trash :slight_smile: it is very useful if you have enabled the “Pay to Blog ” module in pro sites. It also check if the site is a permanent or monthly/yearly subscription.

NB, it would be nice if we can drop in a cron job to make it send a reminder when the site has 24 hours before it expired. :slight_smile:

add_action( 'admin_bar_menu', 'show_plan', 999 );

function show_plan($wp_admin_bar) {

if( !is_main_site() ) {
$id = get_current_blog_id();
$user_email = wp_get_current_user();
$expire = ProSites::get_expire($id);
global $psts, $blog_id;
$month = 30 * 60 * 60 * 24;
$diff = $expire - time();
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
//check is user has a permanent account
if (current_user_can_for_blog($blog_id,'activate_plugins') && $expire =="9999999999" ){
$args = array(
'id' => 'pro_level',
'title' => sprintf("Status : Life Time"),
'parent' => 'top-secondary'
);
}
//show date left before account get expired
else if (current_user_can_for_blog($blog_id,'activate_plugins')){
$args = array(
'id' => 'pro_level',
'title' => sprintf("Days Left: %s %s %sn", ( $years != 0 ? $years . ' Y/, ' : '' ), ( $months != 0 ? $months . ' M/, ' : '' ), ( $days != 0 ? $days . ' D ' : '24hrs' )),
'href' => $month > $diff ? $psts->checkout_url($id) : '#',
'parent' => 'top-secondary'
);

}

$wp_admin_bar->add_node( $args );
}
}