function pmpro_shortcode_account($atts, $content = null, $code = "")
{
    global $wpdb, $pmpro_msg, $pmpro_msgt, $pmpro_levels, $current_user, $levels;
    // $atts    ::= array of attributes
    // $content ::= text within enclosing form of shortcode element
    // $code    ::= the shortcode found, when == callback name
    // examples: [pmpro_account] [pmpro_account sections="membership,profile"/]
    extract(shortcode_atts(array('section' => '', 'sections' => 'membership,profile,invoices,links'), $atts));
    //did they use 'section' instead of 'sections'?
    if (!empty($section)) {
        $sections = $section;
    }
    //turn into an array
    $sections = explode(',', $sections);
    ob_start();
    //if a member is logged in, show them some info here (1. past invoices. 2. billing information with button to update.)
    if (pmpro_hasMembershipLevel()) {
        $ssorder = new MemberOrder();
        $ssorder->getLastMemberOrder();
        $invoices = $wpdb->get_results("SELECT *, UNIX_TIMESTAMP(timestamp) as timestamp FROM {$wpdb->pmpro_membership_orders} WHERE user_id = '{$current_user->ID}' ORDER BY timestamp DESC LIMIT 6");
        ?>
	
	<div id="pmpro_account">		
		
		<?php 
        if (in_array('membership', $sections) || in_array('memberships', $sections)) {
            ?>
			<div id="pmpro_account-membership" class="pmpro_box">
				
				<h3><?php 
            _e("My Memberships", "pmpro");
            ?>
</h3>
				<table width="100%" cellpadding="0" cellspacing="0" border="0">
					<thead>
						<tr>
							<th><?php 
            _e("Level", "pmpro");
            ?>
</th>
							<th><?php 
            _e("Billing", "pmpro");
            ?>
</th>
							<th><?php 
            _e("Expiration", "pmpro");
            ?>
</th>
						</tr>
					</thead>
					<tbody>
						<?php 
            //TODO: v2.0 will loop through levels here
            $level = $current_user->membership_level;
            ?>
						<tr>
							<td class="pmpro_account-membership-levelname">
								<?php 
            echo $current_user->membership_level->name;
            ?>
								<div class="pmpro_actionlinks">
									<?php 
            do_action("pmpro_member_action_links_before");
            ?>
									
									<?php 
            if (pmpro_isLevelExpiringSoon($current_user->membership_level)) {
                ?>
										<a href="<?php 
                echo pmpro_url("checkout", "?level=" . $current_user->membership_level->id, "https");
                ?>
"><?php 
                _e("Renew", "pmpro");
                ?>
</a>
									<?php 
            }
            ?>

									<?php 
            if (isset($ssorder->status) && $ssorder->status == "success" && (isset($ssorder->gateway) && in_array($ssorder->gateway, array("authorizenet", "paypal", "stripe", "braintree", "payflow", "cybersource")))) {
                ?>
										<a href="<?php 
                echo pmpro_url("billing", "", "https");
                ?>
"><?php 
                _e("Update Billing Info", "pmpro");
                ?>
</a>
									<?php 
            }
            ?>
									
									<?php 
            //To do: Only show CHANGE link if this level is in a group that has upgrade/downgrade rules
            if (count($pmpro_levels) > 1 && !defined("PMPRO_DEFAULT_LEVEL")) {
                ?>
										<a href="<?php 
                echo pmpro_url("levels");
                ?>
"><?php 
                _e("Change", "pmpro");
                ?>
</a>
									<?php 
            }
            ?>
									<a href="<?php 
            echo pmpro_url("cancel", "?level=" . $current_user->membership_level->id);
            ?>
"><?php 
            _e("Cancel", "pmpro");
            ?>
</a>
									<?php 
            do_action("pmpro_member_action_links_after");
            ?>
								</div> <!-- end pmpro_actionlinks -->
							</td>
							<td class="pmpro_account-membership-levelfee">
								<p><?php 
            echo pmpro_getLevelCost($level, true, true);
            ?>
</p>
							</td>
							<td class="pmpro_account-membership-expiration">
							<?php 
            if ($current_user->membership_level->enddate) {
                echo date(get_option('date_format'), $current_user->membership_level->enddate);
            } else {
                echo "---";
            }
            ?>
							</td>
						</tr>
					</tbody>
				</table>
				<?php 
            //Todo: If there are multiple levels defined that aren't all in the same group defined as upgrades/downgrades
            ?>
				<div class="pmpro_actionlinks">
					<a href="<?php 
            echo pmpro_url("levels");
            ?>
"><?php 
            _e("View all Membership Options", "pmpro");
            ?>
</a>
				</div>

			</div> <!-- end pmpro_account-membership -->
		<?php 
        }
        ?>
		
		<?php 
        if (in_array('profile', $sections)) {
            ?>
			<div id="pmpro_account-profile" class="pmpro_box">	
				<?php 
            get_currentuserinfo();
            ?>
 
				<h3><?php 
            _e("My Account", "pmpro");
            ?>
</h3>
				<?php 
            if ($current_user->user_firstname) {
                ?>
					<p><?php 
                echo $current_user->user_firstname;
                ?>
 <?php 
                echo $current_user->user_lastname;
                ?>
</p>
				<?php 
            }
            ?>
				<ul>
					<?php 
            do_action('pmpro_account_bullets_top');
            ?>
					<li><strong><?php 
            _e("Username", "pmpro");
            ?>
:</strong> <?php 
            echo $current_user->user_login;
            ?>
</li>
					<li><strong><?php 
            _e("Email", "pmpro");
            ?>
:</strong> <?php 
            echo $current_user->user_email;
            ?>
</li>
					<?php 
            do_action('pmpro_account_bullets_bottom');
            ?>
				</ul>
				<div class="pmpro_actionlinks">
					<a href="<?php 
            echo admin_url('profile.php');
            ?>
"><?php 
            _e("Edit Profile", "pmpro");
            ?>
</a>
					<a href="<?php 
            echo admin_url('profile.php');
            ?>
"><?php 
            _e('Change Password', 'pmpro');
            ?>
</a>
				</div>
			</div> <!-- end pmpro_account-profile -->
		<?php 
        }
        ?>
	
		<?php 
        if (in_array('invoices', $sections) && !empty($invoices)) {
            ?>
		
		<div id="pmpro_account-invoices" class="pmpro_box">
			<h3><?php 
            _e("Past Invoices", "pmpro");
            ?>
</h3>
			<table width="100%" cellpadding="0" cellspacing="0" border="0">
				<thead>
					<tr>
						<th><?php 
            _e("Date", "pmpro");
            ?>
</th>
						<th><?php 
            _e("Level", "pmpro");
            ?>
</th>
						<th><?php 
            _e("Amount", "pmpro");
            ?>
</th>
					</tr>
				</thead>
				<tbody>
				<?php 
            $count = 0;
            foreach ($invoices as $invoice) {
                if ($count++ > 4) {
                    break;
                }
                //get an member order object
                $invoice_id = $invoice->id;
                $invoice = new MemberOrder();
                $invoice->getMemberOrderByID($invoice_id);
                $invoice->getMembershipLevel();
                ?>
						<tr id="pmpro_account-invoice-<?php 
                echo $invoice->code;
                ?>
">
							<td><a href="<?php 
                echo pmpro_url("invoice", "?invoice=" . $invoice->code);
                ?>
"><?php 
                echo date(get_option("date_format"), $invoice->timestamp);
                ?>
</td>
							<td><?php 
                echo $invoice->membership_level->name;
                ?>
</td>
							<td><?php 
                echo pmpro_formatPrice($invoice->total);
                ?>
</td>
						</tr>
						<?php 
            }
            ?>
				</tbody>
			</table>						
			<?php 
            if ($count == 6) {
                ?>
				<div class="pmpro_actionlinks"><a href="<?php 
                echo pmpro_url("invoice");
                ?>
"><?php 
                _e("View All Invoices", "pmpro");
                ?>
</a></div>
			<?php 
            }
            ?>
		</div> <!-- end pmpro_account-invoices -->
		<?php 
        }
        ?>
		
		<?php 
        if (in_array('links', $sections) && (has_filter('pmpro_member_links_top') || has_filter('pmpro_member_links_bottom'))) {
            ?>
		<div id="pmpro_account-links" class="pmpro_box">
			<h3><?php 
            _e("Member Links", "pmpro");
            ?>
</h3>
			<ul>
				<?php 
            do_action("pmpro_member_links_top");
            ?>
				
				<?php 
            do_action("pmpro_member_links_bottom");
            ?>
			</ul>
		</div> <!-- end pmpro_account-links -->		
		<?php 
        }
        ?>
	</div> <!-- end pmpro_account -->		
	<?php 
    }
    $content = ob_get_contents();
    ob_end_clean();
    return $content;
}
    if ($current_level == $level) {
        ?>
 active<?php 
    }
    ?>
">
		<td><?php 
    echo $current_level ? "<strong>{$level->name}</strong>" : $level->name;
    ?>
</td>
		<td>
			<?php 
    if (pmpro_isLevelFree($level)) {
        $cost_text = "<strong>" . __("Free", "pmpro") . "</strong>";
    } else {
        $cost_text = pmpro_getLevelCost($level, true, true);
    }
    $expiration_text = pmpro_getLevelExpiration($level);
    if (!empty($cost_text) && !empty($expiration_text)) {
        echo $cost_text . "<br />" . $expiration_text;
    } elseif (!empty($cost_text)) {
        echo $cost_text;
    } elseif (!empty($expiration_text)) {
        echo $expiration_text;
    }
    ?>
		</td>
		<td>
		<?php 
    if (empty($current_user->membership_level->ID)) {
        ?>
    echo apply_filters("the_content", stripslashes($pmpro_level->description));
}
?>

				<div id="pmpro_level_cost">
					<?php 
if ($discount_code && pmpro_checkDiscountCode($discount_code)) {
    ?>
						<?php 
    printf(__('<p class="pmpro_level_discount_applied">The <strong>%s</strong> code has been applied to your order.</p>', 'pmpro'), $discount_code);
    ?>
					<?php 
}
?>
					<?php 
echo wpautop(pmpro_getLevelCost($pmpro_level));
?>
					<?php 
echo wpautop(pmpro_getLevelExpiration($pmpro_level));
?>
				</div>

				<?php 
do_action("pmpro_checkout_after_level_cost");
?>

				<?php 
if ($pmpro_show_discount_code) {
    ?>

					<?php 
		function sendCheckoutAdminEmail($user = NULL, $invoice = NULL)
		{
			global $wpdb, $current_user, $pmpro_currency_symbol;
			if(!$user)
				$user = $current_user;
			
			if(!$user)
				return false;
			
			//check settings
			$send = pmpro_getOption("email_admin_checkout");
			if(empty($send))
				return true;	//didn't send, but we also don't want to indicate failure because the settings say to not send
			
			$this->email = get_bloginfo("admin_email");
			$this->subject = "Member Checkout for " . $user->membership_level->name . " at " . get_option("blogname");	
			
			$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_level_name" => $user->membership_level->name,
								"membership_cost" => pmpro_getLevelCost($user->membership_level),								
								"login_link" => pmpro_url("account"),
								"display_name" => $user->display_name,
								"user_email" => $user->user_email,0								
							);						
			
			if($invoice)
			{									
				if($invoice->gateway == "paypalexpress")
					$this->template = "checkout_express_admin";
				elseif($invoice->gateway == "check")
					$this->template = "checkout_check_admin";					
				elseif(pmpro_isLevelTrial($user->membership_level))
					$this->template = "checkout_trial_admin";
				else
					$this->template = "checkout_paid_admin";
				$this->data["invoice_id"] = $invoice->code;
				$this->data["invoice_total"] = $pmpro_currency_symbol . number_format($invoice->total, 2);
				$this->data["invoice_date"] = date(get_option('date_format'), $invoice->timestamp);
				$this->data["billing_name"] = $invoice->billing->name;
				$this->data["billing_street"] = $invoice->billing->street;
				$this->data["billing_city"] = $invoice->billing->city;
				$this->data["billing_state"] = $invoice->billing->state;
				$this->data["billing_zip"] = $invoice->billing->zip;
				$this->data["billing_country"] = $invoice->billing->country;
				$this->data["billing_phone"] = $invoice->billing->phone;
				$this->data["cardtype"] = $invoice->cardtype;
				$this->data["accountnumber"] = hideCardNumber($invoice->accountnumber);
				$this->data["expirationmonth"] = $invoice->expirationmonth;
				$this->data["expirationyear"] = $invoice->expirationyear;
				
				if($invoice->getDiscountCode())
					$this->data["discount_code"] = "<p>Discount Code: " . $invoice->discount_code->code . "</p>\n";
				else
					$this->data["discount_code"] = "";
			}
			elseif(pmpro_isLevelFree($user->membership_level))
			{
				$this->template = "checkout_free_admin";		
				global $discount_code;
				if(!empty($discount_code))
					$this->data["discount_code"] = "<p>Discount Code: " . $discount_code . "</p>\n";		
				else
					$this->data["discount_code"] = "";	
			}						
			else
			{
				$this->template = "checkout_freetrial_admin";
				$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>This membership will expire on " . date(get_option('date_format'), $enddate) . ".</p>\n";
			else
				$this->data["membership_expiration"] = "";
			
			return $this->sendEmail();
		}
function pmpro_membership_level_profile_fields($user)
{
    global $current_user;
    $membership_level_capability = apply_filters("pmpro_edit_member_capability", "manage_options");
    if (!current_user_can($membership_level_capability)) {
        return false;
    }
    global $wpdb;
    /*$user->membership_level = $wpdb->get_row("SELECT l.id AS ID, l.name AS name
    		FROM {$wpdb->pmpro_membership_levels} AS l
    		JOIN {$wpdb->pmpro_memberships_users} AS mu ON (l.id = mu.membership_id)
    		WHERE mu.user_id = " . $user->ID . "
    		LIMIT 1");*/
    $user->membership_level = pmpro_getMembershipLevelForUser($user->ID);
    $levels = $wpdb->get_results("SELECT * FROM {$wpdb->pmpro_membership_levels}", OBJECT);
    if (!$levels) {
        return "";
    }
    ?>
<h3><?php 
    _e("Membership Level", "pmpro");
    ?>
</h3>
<table class="form-table">
    <?php 
    $show_membership_level = true;
    $show_membership_level = apply_filters("pmpro_profile_show_membership_level", $show_membership_level, $user);
    if ($show_membership_level) {
        ?>
		<tr>
			<th><label for="membership_level"><?php 
        _e("Current Level", "pmpro");
        ?>
</label></th>
			<td>
				<select name="membership_level">
					<option value="" <?php 
        if (empty($user->membership_level->ID)) {
            ?>
selected="selected"<?php 
        }
        ?>
>-- <?php 
        _e("None", "pmpro");
        ?>
 --</option>
				<?php 
        foreach ($levels as $level) {
            ?>
					<option value="<?php 
            echo $level->id;
            ?>
" <?php 
            selected($level->id, isset($user->membership_level->ID) ? $user->membership_level->ID : 0);
            ?>
><?php 
            echo $level->name;
            ?>
</option>
				<?php 
        }
        ?>
				</select>
                <span id="current_level_cost">
                <?php 
        $membership_values = pmpro_getMembershipLevelForUser($user->ID);
        if (empty($membership_values) || pmpro_isLevelFree($membership_values)) {
            ?>
                    <?php 
            _e("Not paying.", "pmpro");
            ?>
                <?php 
        } else {
            //we tweak the initial payment here so the text here effectively shows the recurring amount
            $membership_values->initial_payment = $membership_values->billing_amount;
            echo pmpro_getLevelCost($membership_values, true, true);
        }
        ?>
                </span>
                <p id="cancel_description" class="description hidden"><?php 
        _e("This will not change the subscription at the gateway unless the 'Cancel' checkbox is selected below.", "pmpro");
        ?>
</p>
            </td>
		</tr>
		<?php 
    }
    $show_expiration = true;
    $show_expiration = apply_filters("pmpro_profile_show_expiration", $show_expiration, $user);
    if ($show_expiration) {
        //is there an end date?
        $user->membership_level = pmpro_getMembershipLevelForUser($user->ID);
        $end_date = !empty($user->membership_level->enddate);
        //some vars for the dates
        $current_day = date("j");
        if ($end_date) {
            $selected_expires_day = date("j", $user->membership_level->enddate);
        } else {
            $selected_expires_day = $current_day;
        }
        $current_month = date("M");
        if ($end_date) {
            $selected_expires_month = date("m", $user->membership_level->enddate);
        } else {
            $selected_expires_month = date("m");
        }
        $current_year = date("Y");
        if ($end_date) {
            $selected_expires_year = date("Y", $user->membership_level->enddate);
        } else {
            $selected_expires_year = (int) $current_year + 1;
        }
        ?>
		<tr>
			<th><label for="expiration"><?php 
        _e("Expires", "pmpro");
        ?>
</label></th>
			<td>
				<select id="expires" name="expires">
					<option value="0" <?php 
        if (!$end_date) {
            ?>
selected="selected"<?php 
        }
        ?>
><?php 
        _e("No", "pmpro");
        ?>
</option>
					<option value="1" <?php 
        if ($end_date) {
            ?>
selected="selected"<?php 
        }
        ?>
><?php 
        _e("Yes", "pmpro");
        ?>
</option>
				</select>
				<span id="expires_date" <?php 
        if (!$end_date) {
            ?>
style="display: none;"<?php 
        }
        ?>
>
					on
					<select name="expires_month">
						<?php 
        for ($i = 1; $i < 13; $i++) {
            ?>
							<option value="<?php 
            echo $i;
            ?>
" <?php 
            if ($i == $selected_expires_month) {
                ?>
selected="selected"<?php 
            }
            ?>
><?php 
            echo date("M", strtotime($i . "/1/" . $current_year, current_time("timestamp")));
            ?>
</option>
							<?php 
        }
        ?>
					</select>
					<input name="expires_day" type="text" size="2" value="<?php 
        echo $selected_expires_day;
        ?>
" />
					<input name="expires_year" type="text" size="4" value="<?php 
        echo $selected_expires_year;
        ?>
" />
				</span>
				<script>
					jQuery('#expires').change(function() {
						if(jQuery(this).val() == 1)
							jQuery('#expires_date').show();
						else
							jQuery('#expires_date').hide();
					});
				</script>
			</td>
		</tr>
        <tr class="more_level_options">
            <th></th>
            <td>
                <label for="send_admin_change_email"><input value="1" id="send_admin_change_email" name="send_admin_change_email" type="checkbox"> Send the user an email about this change.</label>
            </td>
        </tr>
        <tr class="more_level_options">
            <th></th>
            <td>
                <label for="cancel_subscription"><input value="1" id="cancel_subscription" name="cancel_subscription" type="checkbox"> Cancel this user's subscription at the gateway.</label>
            </td>
        </tr>
		<?php 
    }
    ?>
</table>
    <script>
        jQuery(document).ready(function() {
            //vars for fields
			var $membership_level_select = jQuery("[name=membership_level]");
            var $expires_select = jQuery("[name=expires]");
			var $expires_month_select = jQuery("[name=expires_month]");
			var $expires_day_text = jQuery("[name=expires_day]");
			var $expires_year_text = jQuery("[name=expires_year]");
			
			//note old data to check for changes
			var old_level = $membership_level_select.val();
            var old_expires = $expires_select.val();
			var old_expires_month = $expires_month_select.val();
			var old_expires_day = $expires_day_text.val();
			var old_expires_year = $expires_year_text.val();
						
			var current_level_cost = jQuery("#current_level_cost").text();

            //hide by default
			jQuery(".more_level_options").hide();

			function pmpro_checkForLevelChangeInProfile()
			{
				//cancelling sub or not
				if($membership_level_select.val() == 0) {
                    jQuery("#cancel_subscription").attr('checked', true);
                    jQuery("#current_level_cost").text("Not paying.");
                }
                else {
                    jQuery("#cancel_subscription").attr('checked', false);
                    jQuery("#current_level_cost").text(current_level_cost);
                }
				
				//did level or expiration change?
                if(
					$membership_level_select.val() != old_level ||
					$expires_select.val() != old_expires ||
					$expires_month_select.val() != old_expires_month ||
					$expires_day_text.val() != old_expires_day ||
					$expires_year_text.val() != old_expires_year
				)
                {
                    jQuery(".more_level_options").show();
                    jQuery("#cancel_description").show();					
                }
                else
                {
                    jQuery(".more_level_options").hide();
                    jQuery("#cancel_description").hide();					
                }
			}
			
			//run check when fields change
            $membership_level_select.change(function() {
                pmpro_checkForLevelChangeInProfile();
            });
			$expires_select.change(function() {
                pmpro_checkForLevelChangeInProfile();
            });
			$expires_month_select.change(function() {
                pmpro_checkForLevelChangeInProfile();
            });
			$expires_day_text.change(function() {
                pmpro_checkForLevelChangeInProfile();
            });
			$expires_year_text.change(function() {
                pmpro_checkForLevelChangeInProfile();
            });			
			
            jQuery("#cancel_subscription").change(function() {
                if(jQuery(this).attr('checked') == 'checked')
                {
                    jQuery("#cancel_description").hide();
                    jQuery("#current_level_cost").text("Not paying.");
                }
                else
                {
                    jQuery("#current_level_cost").text(current_level_cost);
                    jQuery("#cancel_description").show();
                }
            });
        });
    </script>
<?php 
    do_action("pmpro_after_membership_level_profile_fields", $user);
}
						<a href="<?php 
        echo pmpro_url("levels");
        ?>
"><?php 
        _e("View all Membership Options", "pmpro");
        ?>
</a>
					</div>
				</div>
				<div class="col-md-4">
					<h6>Billing</h6>
					<?php 
        $level = $current_user->membership_level;
        ?>
					<p><?php 
        echo pmpro_getLevelCost($level, true, true);
        ?>
</p>
					<a href="<?php 
        echo pmpro_url("billing", "");
        ?>
"><?php 
        _e("Update Billing Info", "pmpro");
        ?>
</a>
				</div>
				<div class="col-md-4">
					<h6>Expiration</h6>
					<?php 
        if ($current_user->membership_level->enddate) {
            echo date(get_option('date_format'), $current_user->membership_level->enddate);
		jQuery('#other_discount_code_p').html('<a id="other_discount_code_a" href="javascript:void(0);"><?php 
_e('Click here to change your discount code', 'pmpro');
?>
</a>.');
		jQuery('#other_discount_code_p').show();
		
		jQuery('#other_discount_code_a').click(function() {
			jQuery('#other_discount_code_tr').show();
			jQuery('#other_discount_code_p').hide();			
		});
		
		jQuery('#pmpro_level_cost').html('<p><?php 
printf(__('The <strong>%s</strong> code has been applied to your order.', 'pmpro'), $discount_code);
?>
</p><p><?php 
echo pmpro_no_quotes(pmpro_getLevelCost($code_level), array('"', "'", "\n", "\r"));
echo pmpro_no_quotes(pmpro_getLevelExpiration($code_level), array('"', "'", "\n", "\r"));
?>
</p>');
		
		<?php 
//tell gateway javascripts whether or not to fire (e.g. no Stripe on free levels)
if (pmpro_isLevelFree($code_level)) {
    ?>
				pmpro_require_billing = false;
			<?php 
} else {
    ?>
				pmpro_require_billing = true;
			<?php 
}
"><?php 
        echo $level->name;
        ?>
</a></td>
			<td>
				<?php 
        if (pmpro_isLevelFree($level)) {
            ?>
					<?php 
            _e('FREE', 'pmpro');
            ?>
				<?php 
        } else {
            ?>
					<?php 
            echo str_replace('The price for membership is', '', pmpro_getLevelCost($level));
            ?>
				<?php 
        }
        ?>
			</td>
			<td>
				<?php 
        if (!pmpro_isLevelExpiring($level)) {
            ?>
					--
				<?php 
        } else {
            ?>
		
					<?php 
 function sendCheckoutAdminEmail($user = NULL, $invoice = NULL)
 {
     global $wpdb, $current_user;
     if (!$user) {
         $user = $current_user;
     }
     if (!$user) {
         return false;
     }
     //check settings
     $send = pmpro_getOption("email_admin_checkout");
     if (empty($send)) {
         return true;
     }
     //didn't send, but we also don't want to indicate failure because the settings say to not send
     $this->email = get_bloginfo("admin_email");
     $this->subject = sprintf(__("Member Checkout for %s at %s", "pmpro"), $user->membership_level->name, get_option("blogname"));
     $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, "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);
     if (!empty($invoice) && !pmpro_isLevelFree($user->membership_level)) {
         if ($invoice->gateway == "paypalexpress") {
             $this->template = "checkout_express_admin";
         } elseif ($invoice->gateway == "check") {
             $this->template = "checkout_check_admin";
         } elseif (pmpro_isLevelTrial($user->membership_level)) {
             $this->template = "checkout_trial_admin";
         } else {
             $this->template = "checkout_paid_admin";
         }
         $this->data["invoice_id"] = $invoice->code;
         $this->data["invoice_total"] = pmpro_formatPrice($invoice->total);
         $this->data["invoice_date"] = date_i18n(get_option('date_format'), $invoice->timestamp);
         $this->data["billing_name"] = $invoice->billing->name;
         $this->data["billing_street"] = $invoice->billing->street;
         $this->data["billing_city"] = $invoice->billing->city;
         $this->data["billing_state"] = $invoice->billing->state;
         $this->data["billing_zip"] = $invoice->billing->zip;
         $this->data["billing_country"] = $invoice->billing->country;
         $this->data["billing_phone"] = $invoice->billing->phone;
         $this->data["cardtype"] = $invoice->cardtype;
         $this->data["accountnumber"] = hideCardNumber($invoice->accountnumber);
         $this->data["expirationmonth"] = $invoice->expirationmonth;
         $this->data["expirationyear"] = $invoice->expirationyear;
         $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->code . "</p>\n";
         } else {
             $this->data["discount_code"] = "";
         }
     } elseif (pmpro_isLevelFree($user->membership_level)) {
         $this->template = "checkout_free_admin";
         global $discount_code;
         if (!empty($discount_code)) {
             $this->data["discount_code"] = "<p>" . __("Discount Code", "pmpro") . ": " . $discount_code . "</p>\n";
         } else {
             $this->data["discount_code"] = "";
         }
     } else {
         $this->template = "checkout_freetrial_admin";
         $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();
 }
function getLevels()
{
    global $current_user;
    if ($current_user->ID) {
        $current_user->membership_level = pmpro_getMembershipLevelForUser($current_user->ID);
    }
    //is there a default level to redirect to?
    if (defined("PMPRO_DEFAULT_LEVEL")) {
        $default_level = intval(PMPRO_DEFAULT_LEVEL);
    } else {
        $default_level = false;
    }
    if ($default_level) {
        wp_redirect(pmpro_url("checkout", "?level=" . $default_level));
        exit;
    }
    global $wpdb, $pmpro_msg, $pmpro_msgt;
    if (isset($_REQUEST['msg'])) {
        if ($_REQUEST['msg'] == 1) {
            $pmpro_msg = __('Your membership status has been updated - Thank you!', 'pmpro');
        } else {
            $pmpro_msg = __('Sorry, your request could not be completed - please try again in a few moments.', 'pmpro');
            $pmpro_msgt = "pmpro_error";
        }
    } else {
        $pmpro_msg = false;
    }
    global $pmpro_levels;
    $pmpro_levels = pmpro_getAllLevels(false, true);
    $pmpro_levels = apply_filters("pmpro_levels_array", $pmpro_levels);
    if ($pmpro_msg) {
        ?>
        <div class="pmpro_message <?php 
        echo $pmpro_msgt;
        ?>
"><?php 
        echo $pmpro_msg;
        ?>
</div>
        <?php 
    }
    ?>

    <div id="main" class="site-main clr">
        <div id="membership-wrapper"> 
            <?php 
    $count = 0;
    $count_levels = count($pmpro_levels);
    $tmp = 0;
    foreach ($pmpro_levels as $level) {
        if (isset($current_user->membership_level->ID)) {
            $current_level = $current_user->membership_level->ID == $level->id;
        } else {
            $current_level = false;
        }
        ?>

                <?php 
        $last = $count_levels - $tmp;
        ?>
  
                <?php 
        $tmp = $tmp + 1;
        ?>

                <div class="box-level <?php 
        if ($count++ % 2 == 0) {
            ?>
odd<?php 
        } else {
            ?>
 even<?php 
        }
        if ($current_level == $level) {
            ?>
 active<?php 
        }
        if ($last == 2 || $last == 1) {
            ?>
 last-box<?php 
        }
        ?>
">
                    <h1><?php 
        echo $current_level ? "<strong>{$level->name}</strong>" : $level->name;
        ?>
</h1>
                    <div class="copy">
                        <?php 
        if (pmpro_isLevelFree($level)) {
            $cost_text = "<strong>Free</strong>";
        } else {
            $cost_text = pmpro_getLevelCost($level, true, true);
        }
        $expiration_text = pmpro_getLevelExpiration($level);
        if (!empty($cost_text) && !empty($expiration_text)) {
            echo $cost_text . "<br />" . $expiration_text;
        } elseif (!empty($cost_text)) {
            echo $cost_text;
        } elseif (!empty($expiration_text)) {
            echo $expiration_text;
        }
        ?>
                    </div>
                    <div class="links">
                        <?php 
        if (empty($current_user->membership_level->ID)) {
            ?>
                            <a class="pmpro_btn pmpro_btn-select sign-up" href="<?php 
            echo pmpro_url("checkout", "?level=" . $level->id, "https");
            ?>
"><?php 
            _e('Sign Up', 'pmpro');
            ?>
</a>
                        <?php 
        } elseif (!$current_level) {
            ?>
     
                            <!--
                            <a class="pmpro_btn pmpro_btn-select" href="<?php 
            //echo pmpro_url("checkout", "?level=" . $level->id, "https")
            ?>
"><?php 
            //_e('Change Subscription', 'pmpro');
            ?>
</a>
                            -->
                            <a class="pmpro_btn pmpro_btn-select change-subscription" href="<?php 
            echo "/billing/subscription-checkout?level=" . $level->id;
            ?>
"><?php 
            _e('Change Subscription', 'pmpro');
            ?>
</a>
                        <?php 
        } elseif ($current_level) {
            ?>
      
                            <?php 
            //if it's a one-time-payment level, offer a link to renew
            if (!pmpro_isLevelRecurring($current_user->membership_level) && !empty($current_user->membership_level->enddate)) {
                ?>
                                <a class="pmpro_btn pmpro_btn-select renew" href="<?php 
                echo pmpro_url("checkout", "?level=" . $level->id, "https");
                ?>
"><?php 
                _e('Renew', 'pmpro');
                ?>
</a>
                                <?php 
            } else {
                ?>
                                <a class="pmpro_btn disabled your-current-level" href="<?php 
                echo pmpro_url("account");
                ?>
"><?php 
                _e('Your&nbsp;Current&nbsp;Level', 'pmpro');
                ?>
</a>
                                <?php 
            }
            ?>
                        <?php 
        }
        ?>
                    </div>
                </div>
                <?php 
    }
    ?>
            <div class="clear clearfix"></div>
            <nav id="nav-below" class="navigation" role="navigation">
                <div class="nav-previous alignleft">
                    <?php 
    if (!empty($current_user->membership_level->ID)) {
        ?>
                        <!--
                            <a href="<?php 
        echo pmpro_url("account");
        ?>
"><?php 
        _e('&larr; Return to Your Account', 'pmpro');
        ?>
</a>
                        -->
                    <?php 
    } else {
        ?>
                        <a href="<?php 
        echo home_url();
        ?>
"><?php 
        _e('&larr; Return to Home', 'pmpro');
        ?>
</a>
                    <?php 
    }
    ?>
                </div>
            </nav>
        </div>
    </div>    

    <?php 
}
		
		jQuery('#<?php echo $msgfield?>').show();
		jQuery('#<?php echo $msgfield?>').removeClass('pmpro_error');
		jQuery('#<?php echo $msgfield?>').addClass('pmpro_success');
		jQuery('#<?php echo $msgfield?>').addClass('pmpro_discount_code_msg');
		
		jQuery('#other_discount_code_tr').hide();
		jQuery('#other_discount_code_p').html('<a id="other_discount_code_a" href="javascript:void(0);">Click here to change your discount code</a>.');
		jQuery('#other_discount_code_p').show();
		
		jQuery('#other_discount_code_a').click(function() {
			jQuery('#other_discount_code_tr').show();
			jQuery('#other_discount_code_p').hide();			
		});
		
		jQuery('#pmpro_level_cost').html('The <strong><?php echo $discount_code?></strong> code has been applied to your order. <?php echo pmpro_no_quotes(pmpro_getLevelCost($code_level), array('"', "'", "\n", "\r"))?>');
		
		<?php
			//tell gateway javascripts whether or not to fire (e.g. no Stripe on free levels)
			if(pmpro_isLevelFree($code_level))
			{
			?>
				pmpro_require_billing = false;
			<?php
			}			
			else
			{
			?>
				pmpro_require_billing = true;
			<?php
			}
Exemple #12
0
	</thead>
	<tbody>                
		<tr>
			<td>				
				<p>You have selected the <strong><?php echo $pmpro_level->name?></strong> membership level.</p>
				
				<?php
					if(!empty($pmpro_level->description))
						echo apply_filters("the_content", stripslashes($pmpro_level->description));
				?>
				
				<p id="pmpro_level_cost">
					<?php if($discount_code && pmpro_checkDiscountCode($discount_code)) { ?>
						The <strong><?php echo $discount_code?></strong> code has been applied to your order.
					<?php } ?>
					<?php echo pmpro_getLevelCost($pmpro_level)?>
					<?php echo pmpro_getLevelExpiration($pmpro_level)?>
				</p>
				
				<?php do_action("pmpro_checkout_after_level_cost"); ?>				
				
				<?php if($pmpro_show_discount_code) { ?>
				
					<?php if($discount_code && !$pmpro_review) { ?>
						<p id="other_discount_code_p" class="pmpro_small"><a id="other_discount_code_a" href="#discount_code">Click here to change your discount code</a>.</p>
					<?php } elseif(!$pmpro_review) { ?>
						<p id="other_discount_code_p" class="pmpro_small">Do you have a discount code? <a id="other_discount_code_a" href="#discount_code">Click here to enter your discount code</a>.</p>
					<?php } elseif($pmpro_review && $discount_code) { ?>
						<p><strong>Discount Code:</strong> <?php echo $discount_code?></p>
					<?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();
            }
        }
    }
}
function pmprodon_pmpro_level_cost_text($text, $level)
{
    global $pmpro_pages, $pmprodon_original_initial_payment, $pmprodon_text_level_cost_updated;
    if (is_page($pmpro_pages['checkout']) && !empty($pmprodon_original_initial_payment) && empty($pmprodon_text_level_cost_updated)) {
        $olevel = $level;
        $olevel->initial_payment = $pmprodon_original_initial_payment;
        $pmprodon_text_level_cost_updated = true;
        //to prevent loops
        $text = pmpro_getLevelCost($olevel);
    }
    return $text;
}