$uses = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->pmpro_discount_codes_uses} WHERE code_id = '" . $code->id . "'"); $levels = $wpdb->get_results("SELECT l.id, l.name, cl.initial_payment, cl.billing_amount, cl.cycle_number, cl.cycle_period, cl.billing_limit, cl.trial_amount, cl.trial_limit FROM {$wpdb->pmpro_membership_levels} l LEFT JOIN {$wpdb->pmpro_discount_codes_levels} cl ON l.id = cl.level_id WHERE cl.code_id = '" . $code->code . "'"); $temp_id = $code->id; } elseif (!empty($copy) && $copy > 0) { $code = $wpdb->get_row("SELECT *, UNIX_TIMESTAMP(starts) as starts, UNIX_TIMESTAMP(expires) as expires FROM {$wpdb->pmpro_discount_codes} WHERE id = '" . $copy . "' LIMIT 1", OBJECT); $temp_id = $level->id; $level->id = NULL; } // didn't find a discount code, let's add a new one... if (empty($code->id)) { $edit = -1; } //defaults for new codes if ($edit == -1) { $code = new stdClass(); $code->code = pmpro_getDiscountCode(); } ?> <form action="" method="post"> <input name="saveid" type="hidden" value="<?php echo $edit; ?> " /> <table class="form-table"> <tbody> <tr> <th scope="row" valign="top"><label><?php _e('ID', 'pmpro'); ?> :</label></th> <td class="pmpro_lite"><?php
$pmpro_required_user_fields = apply_filters("pmpro_required_user_fields", $pmpro_required_user_fields); //pmpro_confirmed is set to true later if payment goes through $pmpro_confirmed = false; //check their fields if they clicked continue if ($submit && $pmpro_msgt != "pmpro_error") { //make sure javascript is ok if (apply_filters("pmpro_require_javascript_for_checkout", true) && !empty($_REQUEST['checkjavascript']) && empty($_REQUEST['javascriptok'])) { pmpro_setMessage(__("There are JavaScript errors on the page. Please contact the webmaster.", "pmpro"), "pmpro_error"); } //if we're skipping the account fields and there is no user, we need to create a username and password if ($skip_account_fields && !$current_user->ID) { $username = pmpro_generateUsername($bfirstname, $blastname, $bemail); if (empty($username)) { $username = pmpro_getDiscountCode(); } $password = pmpro_getDiscountCode() . pmpro_getDiscountCode(); //using two random discount codes $password2 = $password; } //check billing fields if ($pmpro_requirebilling) { //filter foreach ($pmpro_required_billing_fields as $key => $field) { if (!$field) { $pmpro_error_fields[] = $key; } } } //check user fields if (empty($current_user->ID)) { foreach ($pmpro_required_user_fields as $key => $field) {
function pmprosm_pmpro_after_change_membership_level($level_id, $user_id) { global $wpdb; //are they cancelling? if (empty($level_id)) { //is there a discount code attached to this user? $code_id = pmprosm_getCodeByUserID($user_id); //if so find all users who signed up with that and cancel them as well if (!empty($code_id)) { $sqlQuery = "SELECT user_id FROM {$wpdb->pmpro_discount_codes_uses} WHERE code_id = '" . $code_id . "'"; $sub_user_ids = $wpdb->get_col($sqlQuery); if (!empty($sub_user_ids)) { foreach ($sub_user_ids as $sub_user_id) { //cancel their membership pmpro_changeMembershipLevel(0, $sub_user_id); } } } //remove seats from meta update_user_meta($user_id, "pmprosm_seats", ""); } elseif (pmprosm_isMainLevel($level_id)) { //get values for this sponsorship $pmprosm_values = pmprosm_getValuesByMainLevel($level_id); //check if this user already has a discount code $code_id = pmprosm_getCodeByUserID($user_id); if (empty($code_id)) { //if seats cost money and there are no seats, just return if (!empty($pmprosm_values['seat_cost']) && empty($_REQUEST['seats'])) { return; } //generate a new code. change these values if you want. if (version_compare(PMPRO_VERSION, "1.7.5") > 0) { $code = "S" . pmpro_getDiscountCode($user_id); } else { $code = "S" . pmpro_getDiscountCode(); } $starts = date("Y-m-d", current_time("timestamp")); $expires = date("Y-m-d", strtotime("+1 year", current_time("timestamp"))); //check for seats if (isset($_REQUEST['seats'])) { $uses = intval($_REQUEST['seats']); } elseif (!empty($pmprosm_values['seats'])) { $uses = $pmprosm_values['seats']; } else { $uses = ""; } $sqlQuery = "INSERT INTO {$wpdb->pmpro_discount_codes} (code, starts, expires, uses) VALUES('" . esc_sql($code) . "', '" . $starts . "', '" . $expires . "', '" . intval($uses) . "')"; if ($wpdb->query($sqlQuery) !== false) { //set code in user meta $code_id = $wpdb->insert_id; pmprosm_setCodeUserID($code_id, $user_id); //okay update levels for code if (!is_array($pmprosm_values['sponsored_level_id'])) { $sponsored_levels = array($pmprosm_values['sponsored_level_id']); } else { $sponsored_levels = $pmprosm_values['sponsored_level_id']; } foreach ($sponsored_levels as $sponsored_level) { //default values for discount code; everything free $discount_code = array('code_id' => esc_sql($code_id), 'level_id' => esc_sql($sponsored_level), 'initial_payment' => '0', 'billing_amount' => '0', 'cycle_number' => '0', 'cycle_period' => "'Month'", 'billing_limit' => '0', 'trial_amount' => '0', 'trial_limit' => '0', 'expiration_number' => '0', 'expiration_period' => "'Month'"); //allow override of the discount code values by setting it in the pmprosm_sponsored_account_levels array if (!empty($pmprosm_values['discount_code'])) { foreach ($discount_code as $col => $value) { if (isset($pmprosm_values['discount_code'][$col])) { $discount_code[$col] = $pmprosm_values['discount_code'][$col]; } } } $sqlQuery = "INSERT INTO {$wpdb->pmpro_discount_codes_levels} (code_id, \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t level_id, \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t initial_payment, \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t billing_amount, \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t cycle_number, \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t cycle_period, \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t billing_limit, \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t trial_amount, \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t trial_limit, \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t expiration_number, \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t expiration_period) \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tVALUES(" . implode(",", $discount_code) . ")"; $wpdb->query($sqlQuery); } } } elseif (!empty($pmprosm_values['sponsored_level_id'])) { //update sponsor code and sub accounts pmprosm_sponsored_account_change($level_id, $user_id); //make sure we only do it once remove_action("pmpro_after_checkout", "pmprosm_pmpro_after_checkout_sponsor_account_change", 10, 2); } } }
"password2" => $password2, "bemail" => $bemail, "bconfirmemail" => $bconfirmemail ); $pmpro_required_user_fields = apply_filters("pmpro_required_user_fields", $pmpro_required_user_fields); //check their fields if they clicked continue if($submit && $pmpro_msgt != "pmpro_error") { //if we're skipping the account fields and there is no user, we need to create a username and password if($skip_account_fields && !$current_user->ID) { $username = pmpro_generateUsername($bfirstname, $blastname, $bemail); if(empty($username)) $username = pmpro_getDiscountCode(); $password = pmpro_getDiscountCode() . pmpro_getDiscountCode(); //using two random discount codes $password2 = $password; } if($pmpro_requirebilling && $gateway != "paypalexpress" && $gateway != "paypalstandard") { //if using stripe lite, remove some fields from the required array $pmpro_stripe_lite = apply_filters("pmpro_stripe_lite", false); if($pmpro_stripe_lite && $gateway == "stripe") { //some fields to remove $remove = array('bfirstname', 'blastname', 'baddress1', 'bcity', 'bstate', 'bzipcode', 'bphone', 'bcountry', 'CardType'); //if a user is logged in, don't require bemail either if(!empty($current_user->user_email)) {