function pmproet_email_data($data, $email)
{
    global $current_user, $pmpro_currency_symbol, $wpdb;
    if (!empty($data) && !empty($data['user_login'])) {
        $user = get_user_by('login', $data['user_login']);
    }
    if (empty($user)) {
        $user = $current_user;
    }
    $pmpro_user_meta = $wpdb->get_row("SELECT * FROM {$wpdb->pmpro_memberships_users} WHERE user_id = '" . $user->ID . "' AND status='active'");
    //make sure data is an array
    if (!is_array($data)) {
        $data = array();
    }
    //general data
    $new_data['sitename'] = get_option("blogname");
    $new_data['siteemail'] = pmpro_getOption("from_email");
    if (empty($new_data['login_link'])) {
        $new_data['login_link'] = wp_login_url();
    }
    $new_data['levels_link'] = pmpro_url("levels");
    //user data
    if (!empty($user)) {
        $new_data['name'] = $user->display_name;
        $new_data['user_login'] = $user->user_login;
        $new_data['display_name'] = $user->display_name;
        $new_data['user_email'] = $user->user_email;
    }
    //membership data
    if (!empty($user->membership_level)) {
        $new_data['enddate'] = date(get_option('date_format'), $user->membership_level->enddate);
    }
    //invoice data
    if (!empty($data['invoice_id'])) {
        $invoice = new MemberOrder($data['invoice_id']);
        if (!empty($invoice)) {
            $new_data['billing_name'] = $invoice->billing->name;
            $new_data['billing_street'] = $invoice->billing->street;
            $new_data['billing_city'] = $invoice->billing->city;
            $new_data['billing_state'] = $invoice->billing->state;
            $new_data['billing_zip'] = $invoice->billing->zip;
            $new_data['billing_country'] = $invoice->billing->country;
            $new_data['billing_phone'] = $invoice->billing->phone;
            $new_data['cardtype'] = $invoice->cardtype;
            $new_data['accountnumber'] = hideCardNumber($invoice->accountnumber);
            $new_data['expirationmonth'] = $invoice->expirationmonth;
            $new_data['expirationyear'] = $invoice->expirationyear;
            $new_data['instructions'] = wpautop(pmpro_getOption('instructions'));
            $new_data['invoice_id'] = $invoice->code;
            $new_data['invoice_total'] = $pmpro_currency_symbol . number_format($invoice->total, 2);
            $new_data['invoice_link'] = pmpro_url('invoice', '?invoice=' . $invoice->code);
            //billing address
            $new_data["billing_address"] = pmpro_formatAddress($invoice->billing->name, $invoice->billing->street, "", $invoice->billing->city, $invoice->billing->state, $invoice->billing->zip, $invoice->billing->country, $invoice->billing->phone);
        }
    }
    //membership change
    if (!empty($user->membership_level) && !empty($user->membership_level->ID)) {
        $new_data["membership_change"] = sprintf(__("The new level is %s.", "pmpro"), $user->membership_level->name);
    } else {
        $new_data["membership_change"] = __("Your membership has been cancelled", "pmpro");
    }
    if (!empty($user->membership_level) && !empty($user->membership_level->enddate)) {
        $new_data["membership_change"] .= ". " . sprintf(__("This membership will expire on %s", "pmpro"), date(get_option('date_format'), $user->membership_level->enddate));
    } elseif (!empty($email->expiration_changed)) {
        $new_data["membership_change"] .= ". " . __("This membership does not expire", "pmpro");
    }
    //membership expiration
    $new_data['membership_expiration'] = '';
    if (!empty($pmpro_user_meta->enddate)) {
        $new_data['membership_expiration'] = "<p>" . sprintf(__("This membership will expire on %s.", "pmpro"), $pmpro_user_meta->enddate . "</p>\n");
    }
    //if others are used in the email look in usermeta
    $et_body = pmpro_getOption('email_' . $email->template . '_body');
    $templates_in_email = preg_match_all("/!!([^!]+)!!/", $et_body, $matches);
    if (!empty($templates_in_email)) {
        $matches = $matches[1];
        foreach ($matches as $match) {
            if (empty($new_data[$match])) {
                $usermeta = get_user_meta($user->ID, $match, true);
                if (!empty($usermeta)) {
                    if (is_array($usermeta) && !empty($usermeta['fullurl'])) {
                        $new_data[$match] = $usermeta['fullurl'];
                    } elseif (is_array($usermeta)) {
                        $new_data[$match] = implode(", ", $usermeta);
                    } else {
                        $new_data[$match] = $usermeta;
                    }
                }
            }
        }
    }
    //now replace any new_data not already in data
    foreach ($new_data as $key => $value) {
        if (!isset($data[$key])) {
            $data[$key] = $value;
        }
    }
    return $data;
}
			<?php 
echo __('Date:', 'pmpro') . '&nbsp;' . date('Y-m-d', $order->timestamp);
?>
		</td>
	</tr>
	<?php 
if (!empty($order->billing->name)) {
    ?>
		<tr>
			<td>
				<strong><?php 
    _e('Bill to:', 'pmpro');
    ?>
</strong><br>
				<?php 
    echo pmpro_formatAddress($order->billing->name, $order->billing->street, "", $order->billing->city, $order->billing->state, $order->billing->zip, $order->billing->country, $order->billing->phone);
    ?>
				<?php 
}
?>
			</td>
		</tr>
	</thead>
	<tbody>
	<tr>
		<td colspan="2">
			<table style="width:100%;border-width:1px;border-style:solid;border-collapse:collapse;">
				<tr style="border-width:1px;border-style:solid;border-collapse:collapse;">
					<th style="text-align:center;border-width:1px;border-style:solid;border-collapse:collapse;"><?php 
_e('ID', 'pmpro');
?>
 function sendInvoiceEmail($user = NULL, $invoice = NULL)
 {
     global $wpdb, $current_user;
     if (!$user) {
         $user = $current_user;
     }
     if (!$user || !$invoice) {
         return false;
     }
     $user->membership_level = pmpro_getMembershipLevelForUser($user->ID);
     $this->email = $user->user_email;
     $this->subject = sprintf(__("INVOICE for %s membership", "pmpro"), get_option("blogname"));
     $this->template = "invoice";
     $this->data = array("subject" => $this->subject, "name" => $user->display_name, "user_login" => $user->user_login, "sitename" => get_option("blogname"), "siteemail" => pmpro_getOption("from_email"), "membership_id" => $user->membership_level->id, "membership_level_name" => $user->membership_level->name, "display_name" => $user->display_name, "user_email" => $user->user_email, "invoice_id" => $invoice->code, "invoice_total" => pmpro_formatPrice($invoice->total), "invoice_date" => date_i18n(get_option('date_format'), $invoice->timestamp), "billing_name" => $invoice->billing->name, "billing_street" => $invoice->billing->street, "billing_city" => $invoice->billing->city, "billing_state" => $invoice->billing->state, "billing_zip" => $invoice->billing->zip, "billing_country" => $invoice->billing->country, "billing_phone" => $invoice->billing->phone, "cardtype" => $invoice->cardtype, "accountnumber" => hideCardNumber($invoice->accountnumber), "expirationmonth" => $invoice->expirationmonth, "expirationyear" => $invoice->expirationyear, "login_link" => wp_login_url(pmpro_url("account")), "invoice_link" => wp_login_url(pmpro_url("invoice", "?invoice=" . $invoice->code)));
     $this->data["billing_address"] = pmpro_formatAddress($invoice->billing->name, $invoice->billing->street, "", $invoice->billing->city, $invoice->billing->state, $invoice->billing->zip, $invoice->billing->country, $invoice->billing->phone);
     if ($invoice->getDiscountCode()) {
         $this->data["discount_code"] = "<p>" . __("Discount Code", "pmpro") . ": " . $invoice->discount_code . "</p>\n";
     } else {
         $this->data["discount_code"] = "";
     }
     $enddate = $wpdb->get_var("SELECT UNIX_TIMESTAMP(enddate) FROM {$wpdb->pmpro_memberships_users} WHERE user_id = '" . $user->ID . "' AND status = 'active' LIMIT 1");
     if ($enddate) {
         $this->data["membership_expiration"] = "<p>" . sprintf(__("This membership will expire on %s.", "pmpro"), date_i18n(get_option('date_format'), $enddate)) . "</p>\n";
     } else {
         $this->data["membership_expiration"] = "";
     }
     return $this->sendEmail();
 }
    echo $theuser->last_name;
    ?>
</td>
							<td><a href="mailto:<?php 
    echo esc_attr($theuser->user_email);
    ?>
"><?php 
    echo $theuser->user_email;
    ?>
</a></td>
							<?php 
    do_action("pmpro_memberslist_extra_cols_body", $theuser);
    ?>
							<td>
								<?php 
    echo pmpro_formatAddress(trim($theuser->pmpro_bfirstname . " " . $theuser->pmpro_blastname), $theuser->pmpro_baddress1, $theuser->pmpro_baddress2, $theuser->pmpro_bcity, $theuser->pmpro_bstate, $theuser->pmpro_bzipcode, $theuser->pmpro_bcountry, $theuser->pmpro_bphone);
    ?>
							</td>
							<td><?php 
    echo $auser->membership;
    ?>
</td>
							<td>
								<?php 
    if ((double) $auser->initial_payment > 0) {
        ?>
									<?php 
        echo pmpro_formatPrice($auser->initial_payment);
        ?>
								<?php 
    }
function pmpropbc_reminder_emails()
{
    global $wpdb;
    //make sure we only run once a day
    $now = current_time('timestamp');
    $today = date("Y-m-d", $now);
    //have to run for each level, so get levels
    $levels = pmpro_getAllLevels(true, true);
    if (empty($levels)) {
        return;
    }
    foreach ($levels as $level) {
        //get options
        $options = pmpropbc_getOptions($level->id);
        if (!empty($options['reminder_days'])) {
            $date = date("Y-m-d", strtotime("+ " . $options['reminder_days'] . " days", $now));
        } else {
            $date = $today;
        }
        //need to get all combos of pay cycle and period
        $sqlQuery = "SELECT DISTINCT(CONCAT(cycle_number, ' ', cycle_period)) FROM {$wpdb->pmpro_memberships_users} WHERE membership_id = '" . $level->id . "' AND cycle_number > 0 AND status = 'active'";
        $combos = $wpdb->get_col($sqlQuery);
        if (empty($combos)) {
            continue;
        }
        foreach ($combos as $combo) {
            //get all check orders still pending after X days
            $sqlQuery = "\r\n\t\t\t\tSELECT id \r\n\t\t\t\tFROM {$wpdb->pmpro_membership_orders} \r\n\t\t\t\tWHERE membership_id = {$level->id} \r\n\t\t\t\t\tAND gateway = 'check' \r\n\t\t\t\t\tAND status = 'pending' \r\n\t\t\t\t\tAND DATE_ADD(timestamp, INTERVAL {$combo}) <= '" . $date . "'\r\n\t\t\t\t\tAND notes NOT LIKE '%Reminder Sent:%' AND notes NOT LIKE '%Reminder Skipped:%'\r\n\t\t\t\tORDER BY id\r\n\t\t\t";
            if (defined('PMPRO_CRON_LIMIT')) {
                $sqlQuery .= " LIMIT " . PMPRO_CRON_LIMIT;
            }
            $orders = $wpdb->get_col($sqlQuery);
            if (empty($orders)) {
                continue;
            }
            foreach ($orders as $order_id) {
                //get some data
                $order = new MemberOrder($order_id);
                $user = get_userdata($order->user_id);
                $user->membership_level = pmpro_getMembershipLevelForUser($order->user_id);
                //if they are no longer a member, let's not send them an email
                if (empty($user->membership_level) || empty($user->membership_level->ID) || $user->membership_level->id != $order->membership_id) {
                    //note when we send the reminder
                    $new_notes = $order->notes . "Reminder Skipped:" . $today . "\n";
                    $wpdb->query("UPDATE {$wpdb->pmpro_membership_orders} SET notes = '" . esc_sql($new_notes) . "' WHERE id = '" . $order_id . "' LIMIT 1");
                    continue;
                }
                //note when we send the reminder
                $new_notes = $order->notes . "Reminder Sent:" . $today . "\n";
                $wpdb->query("UPDATE {$wpdb->pmpro_membership_orders} SET notes = '" . esc_sql($new_notes) . "' WHERE id = '" . $order_id . "' LIMIT 1");
                //setup email to send
                $email = new PMProEmail();
                $email->template = "check_pending_reminder";
                $email->email = $user->user_email;
                $email->subject = sprintf(__("Reminder: New Invoice for %s at %s", "pmpropbc"), $user->membership_level->name, get_option("blogname"));
                //get body from template
                $email->body = file_get_contents(PMPRO_PAY_BY_CHECK_DIR . "/email/" . $email->template . ".html");
                //setup more data
                $email->data = array("name" => $user->display_name, "user_login" => $user->user_login, "sitename" => get_option("blogname"), "siteemail" => pmpro_getOption("from_email"), "membership_id" => $user->membership_level->id, "membership_level_name" => $user->membership_level->name, "membership_cost" => pmpro_getLevelCost($user->membership_level), "login_link" => wp_login_url(pmpro_url("account")), "display_name" => $user->display_name, "user_email" => $user->user_email);
                $email->data["instructions"] = pmpro_getOption('instructions');
                $email->data["invoice_id"] = $order->code;
                $email->data["invoice_total"] = pmpro_formatPrice($order->total);
                $email->data["invoice_date"] = date(get_option('date_format'), $order->timestamp);
                $email->data["billing_name"] = $order->billing->name;
                $email->data["billing_street"] = $order->billing->street;
                $email->data["billing_city"] = $order->billing->city;
                $email->data["billing_state"] = $order->billing->state;
                $email->data["billing_zip"] = $order->billing->zip;
                $email->data["billing_country"] = $order->billing->country;
                $email->data["billing_phone"] = $order->billing->phone;
                $email->data["cardtype"] = $order->cardtype;
                $email->data["accountnumber"] = hideCardNumber($order->accountnumber);
                $email->data["expirationmonth"] = $order->expirationmonth;
                $email->data["expirationyear"] = $order->expirationyear;
                $email->data["billing_address"] = pmpro_formatAddress($order->billing->name, $order->billing->street, "", $order->billing->city, $order->billing->state, $order->billing->zip, $order->billing->country, $order->billing->phone);
                if ($order->getDiscountCode()) {
                    $email->data["discount_code"] = "<p>" . __("Discount Code", "pmpro") . ": " . $order->discount_code->code . "</p>\n";
                } else {
                    $email->data["discount_code"] = "";
                }
                //send the email
                $email->sendEmail();
            }
        }
    }
}