function ym_shortcode_ym_group_membership_control() { // @TODO: Finish global $ym_user, $ym_formgen; if ($ym_user->child_ids || $ym_user->child_accounts_allowed) { // has children $total_kids = count($ym_user->child_ids); $action = ym_post('action', false); if ($action == 'ym_add_child_user') { if ($ym_user->child_accounts_allowed > $total_kids) { $email_address = ym_post('email_address'); $username = ym_post('username', $email_address); $password = ym_post('password'); $c_password = ym_post('c_password'); if ($email_address && is_email($email_address)) { if (!empty($password) && $password != $c_password) { ym_display_message(__('Passwords do not match', 'ym'), 'error'); } $new_user = new YourMember_User(); $result = $new_user->create($email_address, false, false, $username, $password); if (is_wp_error($result)) { ym_display_message($result->get_error_message(), 'error'); } else { // apply child $data = array('parent_id' => $ym_user->ID); // package type if (count($ym_user->child_accounts_package_types) > 1) { $data['account_type'] = $ym_user->child_accounts_package_types[0]; } else { $data['account_type'] = $ym_user->account_type; } $new_user->update($data); $new_user->save(); unset($new_user); //garbage collect $child_ids = $ym_user->child_ids; $child_ids[] = $result; $ym_user->update(array('child_ids' => $child_ids)); $ym_user->save(); // all done ym_display_message(__('Child User was created successfully', 'ym')); } } else { ym_display_message(__('The Email Address was Blank or Invalid', 'ym'), 'error'); } } else { ym_display_message(__('You have reached the maximum number of accounts', 'ym'), 'error'); } } else { if ($action == 'ym_child_package_type_change') { $child_id = ym_post('child_id', false); if ($child_id) { $ym_child = new YourMember_User($child_id); if ($ym_child->parent_id = $ym_user->ID) { $ym_child->update(array('account_type' => $_POST['package_type'])); $ym_child->save(); ym_display_message(__('Child account was updated successfully', 'ym')); } else { ym_display_message(__('You are trying to update someone elses child', 'ym'), 'error'); } } } } $return .= '<table class="form-table">'; foreach ($ym_user->child_ids as $child) { // loop thru kids $ym_child = new YourMember_User($child); $return .= '<tr>'; $return .= '<td>' . $ym_child->data->user_login . '</td>'; $return .= '<td>'; $return .= $ym_child->account_type; $return .= '</td>'; $return .= '</tr>'; } $return .= '</table>'; if ($ym_user->child_accounts_allowed > $total_kids) { // can add child $return .= '<h4>' . __('Create new Group Account', 'ym') . '</h4>'; $return .= '<form action="" method="post"> <input type="hidden" name="action" value="ym_add_child_user" /> <table class="form-table"> '; $ym_formgen->return = true; $return .= $ym_formgen->render_form_table_email_row(__('Email Address', 'ym'), 'email_address'); $return .= $ym_formgen->render_form_table_text_row(__('Username', 'ym'), 'username', '', __('Leave blank to use the email address', 'ym')); $return .= $ym_formgen->render_form_table_password_row(__('Password', 'ym'), 'password', '', __('Leave blank to auto generate', 'ym')); $return .= $ym_formgen->render_form_table_password_row(__('Confirm Password', 'ym'), 'c_password'); $ym_formgen->return = false; $return .= '<tr><td colspan="2"><p class="submit"><input type="submit" class="button-primary alignright" value="' . __('Create', 'ym') . '" /></p></td></tr>'; $return .= '</table></form>'; } return $return; } else { return '<p>' . __('You do not have access to Group Management', 'ym') . '</p>'; } }
function ym_user_unsubscribe($atts = array()) { get_currentuserinfo(); global $current_user, $ym_res, $ym_user; if (!$current_user->ID) { return; } if (!$ym_user) { $ym_user = new YourMember_User($current_user->ID); } //var_dump($ym_user); $unsubscribe_text = isset($atts['unsubscribe_text']) ? $atts['unsubscribe_text'] : __('Are you sure you Wish to Unsubscribe', 'ym'); $sure_button = isset($atts['sure_button']) ? $atts['sure_button'] : __('Yes', 'ym'); $unsubscribe_button = isset($atts['unsubscribe_button']) ? $atts['unsubscribe_button'] : __('Unsubscribe', 'ym'); $action = ym_post('ym_action'); if ($action == 'unsubscribeyes') { // set user to inactive $user_status = YM_STATUS_EXPIRED; $ym_user->status_str = __('Manual UnSubscribe', 'ym'); $ym_user->status = $user_status; //update_user_meta($current_user->ID, 'ym_user', $user_data); $ym_user->save(); update_user_option($current_user->ID, 'ym_status', $user_status, true); @ym_log_transaction(YM_ACCESS_EXPIRY, time(), $current_user->ID); @ym_log_transaction(YM_USER_STATUS_UPDATE, $user_status . ' Manual Unsubscribe', $current_user->ID); // logout $html = '<p>' . $ym_res->unsubscribe_left_msg . '</p>'; $html .= '<meta http-equiv="refresh" content="5;' . site_url() . ' " />'; do_action('ym_user_self_unsubscribe'); return $html; } else { if ($action == 'unsubscribe') { $html = '<form action="" method="post"> <p>' . $unsubscribe_text . '</p> <input type="hidden" name="ym_action" value="unsubscribeyes" /> <input type="submit" value="' . $sure_button . '" /> </form>'; } else { $html = '<form action="" method="post"> <input type="hidden" name="ym_action" value="unsubscribe" /> <input type="submit" value="' . $unsubscribe_button . '" /> </form>'; } } return $html; }
list($year, $month, $date) = explode('-', $last_pay_date); $tos = mktime(0, 0, 0, $month, $date, $year); $data->last_pay_date = $tos; } $expire_date = $data->expire_date; if (strpos($expire_date, '-')) { // invalid if (strpos($expire_date, ' ')) { list($expire_date, $rubbish) = explode(' ', $expire_date); } list($year, $month, $date) = explode('-', $expire_date); $tos = mktime(0, 0, 0, $month, $date, $year); $data->expire_date = $tos; } if (!ym_superuser($user->ID)) { $data->save(); echo '.'; } else { echo '|'; } $did++; if (substr($did, -1, 1) == '0') { echo ' ' . ($user_start + $did) . '<br />'; } } if ($did == $limit) { $next = $user_start + $limit; $url = YM_ADMIN_URL . '&user_start=' . $next; echo '<p>YourMembers Update Script: Sleeping for next Run</p>'; echo '<meta http-equiv="refresh" content="5;' . $url . '" />'; } else {
} else { if ($pack['id'] == $new_pack_id) { $pack_data = $pack; } } } update_option('ym_packs', $obj); // find all users on this pack and move to new pack // get all users $sql = 'SELECT u.id AS user_id FROM ' . $wpdb->users . ' u LEFT JOIN ' . $wpdb->usermeta . ' m ON m.user_id = u.id WHERE m.meta_key = \'ym_user\''; foreach ($wpdb->get_results($sql) as $row) { $user_id = $row->user_id; if (!($user_data = (object) get_user_option('ym_user', $user_id))) { // should never hit here $user_data = new YourMember_User($user_id); $user_data->save(); } // only update is user is on the deleted pack if (isset($user_data->pack_id) && $user_data->pack_id == $id) { $user_data->pack_id = $new_pack_id; $user_data->account_type = $pack['account_type']; @ym_log_transaction(YM_ACCOUNT_TYPE_ASSIGNATION, $user_data->account_type, $user_id); update_user_option($user_id, 'ym_user', $user_data, true); update_user_meta($user_id, 'ym_account_type', $user_data->account_type); } } echo '<meta http-equiv="refresh" content="3;' . $link . '&message=deleted" />'; } else { ym_box_top(__('Deleting a Pack', 'ym')); echo '<p>' . __('Which pack would you like to put current pack members on', 'ym') . '</p>'; echo '<form action="" method="post">';
function ym_parent_child_accounts_packages() { global $current_user; get_currentuserinfo(); $user_id = $current_user->ID; if (!ym_superuser($user_id)) { echo '0'; die; } $parent_id = $_POST['parent_id']; $package_id = $_POST['package_id']; $parent = new YourMember_User($parent_id); if (in_array($package_id, $parent->child_accounts_packages)) { unset($parent->child_accounts_packages[array_search($package_id, $parent->child_accounts_packages)]); } else { $parent->child_accounts_packages[] = $package_id; } $parent->save(); echo 1; die; }
function invoice_tab() { $invoice = new ym_invoice(); global $wpdb; if (ym_post('user_id')) { $user_id = ym_post('user_id'); $op = ym_post('op', ''); $undo = ym_post('undo', FALSE); $user = new YourMember_User($user_id); if ($undo) { $data = array('status' => YM_STATUS_PENDING, 'status_str' => __('Invoice Undo', 'ym')); $user->update($data); $user->save(); $packet = array('user_id' => $user_id, 'status' => FALSE); do_action('ym_invoice_status_update', $packet); } else { if ($op == 'resend') { $invoice->generate_invoice($user, $invoice); echo '<div id="message" class="updated"><p>' . __('Inovice Resent', 'ym') . '</p></div>'; @ym_log_transaction(YM_USER_STATUS_UPDATE, __('Invoice Resent', 'ym'), $user_id); } else { if ($op == 'active') { $data = array('status' => YM_STATUS_ACTIVE, 'status_str' => __('Invoice Paid', 'ym'), 'amount' => intval(ym_post('amount', 0)), 'last_pay_date' => time()); $current_status = $user->status; if ($current_status == YM_STATUS_GRACE) { $extend = $user->last_pay_date; $packdata = ym_get_pack_by_id($user->pack_id); $data['expire_date'] = $user->expiry_time($packdata['duration'], $packdata['duration_type'], $extend); } // check for force end if (isset($packdata['force_end_date'])) { $force_end_date = $packdata['force_end_date']; if ($force_end_date > time()) { // greater than now @ym_log_transaction(YM_ACCESS_EXTENSION, 'Adjustment (Force End Date): ' . $force_end_date, $user_id); $data['expire_date'] = $force_end_date; } } $data['amount'] = preg_replace('/[^\\d\\.]/', '', $data['amount']); $data['amount'] = number_format($data['amount'], 2, '.', ''); $user->update($data, TRUE); $optional = ym_post('optional'); if (!$optional) { $optional = __('Invoice Paid', 'ym'); } @ym_log_transaction(YM_IPN, $optional, $user_id); @ym_log_transaction(YM_PAYMENT, $data['amount'], $user_id); @ym_log_transaction(YM_USER_STATUS_UPDATE, $data['status'] . ' - ' . $data['status_str'], $user_id); echo '<div id="message" class="updated"><p>' . __('Updated and Activated the User', 'ym') . '</p></div>'; $packet = array('user_id' => $user_id, 'pack_id' => $user->pack_id, 'status' => TRUE); $invoice = new ym_invoice(); $invoice->notify_user($packet); do_action('ym_invoice_status_update', $packet); } } } } echo '<div id="poststuff" class="wrap">'; ym_box_top(__('Invoice Management', 'ym')); $search = ym_post('ym_invoice_search', false); if ($search) { $query = 'SELECT u.user_id AS ID FROM ' . $wpdb->usermeta . ' u LEFT JOIN ' . $wpdb->usermeta . ' s ON s.user_id = u.user_id LEFT JOIN ' . $wpdb->users . ' us ON us.id = u.user_id WHERE u.meta_key = \'ym_payment_type\' AND u.meta_value = \'invoice\' AND s.meta_key = \'ym_status\' AND ( us.user_login LIKE \'%' . $search . '%\' OR us.user_email LIKE \'%' . $search . '%\' ) ORDER BY ID DESC '; } else { $query = 'SELECT u.user_id AS ID FROM ' . $wpdb->prefix . 'usermeta u LEFT JOIN ' . $wpdb->prefix . 'usermeta s ON s.user_id = u.user_id WHERE u.meta_key = \'ym_payment_type\' AND u.meta_value = \'invoice\' AND s.meta_key = \'ym_status\' ORDER BY ID DESC '; } $results = $wpdb->get_results($query); // quick search if ($wpdb->num_rows != 0 || $search) { // render search form echo ' <form action="" method="post" style="float: right;"> <fieldset> ' . __('Username/Email Search:', 'ym') . ' <input type="text" name="ym_invoice_search" value="' . $search . '" /> <input type="submit" value="' . __('Search', 'ym') . '" /> </fieldset> </form>'; } echo '<p>' . __('Here you can update users based on the honouring of their invoice, you can use the Info to store field to store extra IPN style info such as a Cheque Number', 'ym') . '</p>'; if ($wpdb->num_rows == 0) { echo ym_display_message(__('No Users are Invoice Pending', 'ym'), 'error'); } else { echo '<table class="widefat">'; echo '<tr> <th>' . __('Member', 'ym') . '</th> <th>' . __('Invoice Ref', 'ym') . '</th> <th>' . __('Purchasing', 'ym') . '</th> <th>' . __('Paid/Invoiced On Date', 'ym') . '</th> <th>' . __('Member Status', 'ym') . '</th> <th>' . __('Payment', 'ym') . '</th> </tr>'; foreach ($results as $row) { $user = new YourMember_User($row->ID); echo '<tr>'; echo '<td>(' . $row->ID . ') ' . $user->data->user_email; echo '<br />'; if ($user->data->user_email != $user->data->user_login) { echo $user->data->user_login . ' '; } echo $user->data->display_name; echo '</td>'; echo '<td>#' . $user->invoice_id . '</td>'; echo '<td>' . ym_get_pack_label($user->pack_id) . '</td>'; echo '<td nowrap="nowrap" style="'; // go red if overdue $limit = $user->invoiced_date + 86400 * $invoice->invoice_limit; // last pay date is invoiced on date // limit is due date for this invoice if (time() > $limit && $user->status != YM_STATUS_ACTIVE) { echo 'background: red;'; } else { if (time() < $limit && $user->status != YM_STATUS_ACTIVE) { echo 'background: #EFEFEF;'; } } echo '">'; if ($user->status != YM_STATUS_ACTIVE) { echo __('Invoiced', 'ym') . ' ' . date(YM_DATE, $user->invoiced_date); echo '<br />' . __('Due', 'ym') . ' ' . date(YM_DATE, $limit); } else { echo date(YM_DATE, $user->last_pay_date); } echo '</td>'; echo '<td>' . $user->status . ' - ' . $user->status_str . '</td>'; echo '<td> <form action="" method="post"> <table><tr><td nowrap="nowrap"> <input type="hidden" name="search" value="' . $search . '" /> <input type="hidden" name="user_id" value="' . $row->ID . '" /> '; if ($user->status == YM_STATUS_ACTIVE) { echo $user->amount; // last ipn $query = 'SELECT data FROM ' . $wpdb->prefix . 'ym_transaction WHERE action_id = ' . YM_IPN . ' AND user_id = ' . $row->ID . ' ORDER BY id DESC LIMIT 1'; $data = $wpdb->get_var($query); if (substr($data, 0, 2) != 'a:') { echo ' - '; echo $data; } echo '</td><td>'; echo '</td><td>'; echo ' <input type="hidden" name="undo" value="1" /> <input type="submit" class="button-secondary deletelink" style="float: right;" value="' . __('Undo Active', 'ym') . '" /> '; } else { echo ' <label for="amount">' . __('Payment Amount', 'ym') . '</label> <br /> <label for="optional">' . __('Info to Store', 'ym') . ' </td><td> <input type="text" name="amount" id="amount" value="" size="4" /> <br /> <input type="text" name="optional" id="optional" value="" size="4" /></label> '; echo '</td><td>'; echo ' <input type="submit" class="button-secondary deletelink" style="float: right;" value="' . __('Payment Recieved - Make Active', 'ym') . '" onclick="jQuery(\'#op_' . $row->ID . '\').val(\'active\');" /> '; echo '</td><td>'; echo ' <input type="submit" class="button-secondary" style="float: right;" value="' . __('Resend Invoice', 'ym') . '" onclick="jQuery(\'#op_' . $row->ID . '\').val(\'resend\');" /> '; } echo ' <input type="hidden" name="op" id="op_' . $row->ID . '" value="" /> </td></tr></table> </form> </td>'; echo '</tr>'; } echo '</table>'; } ym_box_bottom(); echo '</div>'; }
echo '<div class="wrap" id="poststuff">'; global $wpdb, $ym_package_types; if (ym_post('del_btn')) { $delete = ym_post('delete_package_type'); $ym_package_types->delete($delete); $to = ym_post('moveto'); // account type is exposed by default $query = 'SELECT user_id FROM ' . $wpdb->usermeta . ' WHERE meta_key = \'ym_account_type\' AND meta_value = \'' . $delete . '\''; $users = $wpdb->get_results($query); foreach ($users as $user) { $user = new YourMember_User($user->user_id); $user->account_type = $to; $user->save(); } // find and remove account type from the subscriptions // FAILS!!! global $ym_packs; foreach ($ym_packs->packs as $k => $pack) { if ($pack['account_type'] == $delete) { $ym_packs->packs[$k]['account_type'] = $to; } } update_option('ym_packs', $ym_packs); ym_display_message(__('Package Type Deleted', 'ym')); } if (ym_post('new_package_type')) { $new = strip_tags(ym_post('new_package_type')); if (empty($new)) {
function do_buy_subscription($subId, $userId, $complete = FALSE) { global $ym_sys; // assumes complete @ym_log_transaction(YM_IPN, $_REQUEST, $userId); if ($complete) { @ym_log_transaction(YM_PACKAGE_PURCHASED, $subId, $userId); $pack = ym_get_pack_by_id($subId); if (!$pack) { // unknown pack $complete = 'FALSE'; } else { $user = new YourMember_User($userId); // get current $current = $user->pack_id; $extend = FALSE; // extend // ONLY extend if same package type (ie better pack for the same type) // SO different Pack IDs // - like a switch from a monthly sub to a yearly sub // and current status is active // if been set inactivate then new sub if ($user->account_type == $pack['account_type'] && $user->pack_id != $subId && ($user->status == YM_STATUS_ACTIVE || $user->status == YM_STATUS_GRACE)) { $extend = $user->expire_date; } // check for pack ID's the same // and extend allow // make sure expire date in the future if ($user->pack_id == $subId && $ym_sys->allow_upgrade_to_same && $user->expire_date > time()) { $extend = $user->expire_date; } // patch :-P $pack['amount'] = $pack['cost']; // use magic // use an array so can pass to update // other wise direct calls to object.... $data = array(); // this is crap // TODO: takes the whole pack and stores it in the user object..... foreach ($user as $key => $value) { if (isset($pack[$key])) { $data[$key] = $pack[$key]; } } // end crap // additonal $data['pack_id'] = $subId; $data['status'] = YM_STATUS_ACTIVE; $data['reminder_email_sent'] = FALSE; if ($this->code == 'ym_gift') { $data['status_str'] = __('Gift Giving was Successful', 'ym'); } else { if ($this->code == 'ym_dropdown') { $data['status_str'] = __('DropDown was Successful', 'ym'); } else { if ($extend) { $data['status_str'] = __('Subscription Extension Successful', 'ym'); } else { $data['status_str'] = __('Last payment was successful', 'ym'); } } } $data['account_type'] = ucwords($pack['account_type']); $data['reminder_email_sent'] = FALSE; $data['gateway_used'] = $this->code; if (!$extend) { $data['account_type_join_date'] = time(); } $data['last_pay_date'] = time(); // log @ym_log_transaction(YM_ACCOUNT_TYPE_ASSIGNATION, $data['account_type'], $userId); @ym_log_transaction(YM_USER_STATUS_UPDATE, YM_STATUS_ACTIVE . ' - ' . $data['status_str'], $userId); // apply trial? $apply = FALSE; // if trial enabled and user not taken if ($pack['trial_on'] && $user->trial_taken != $subId) { // trial not taken yet then apply trial // does the Gateway Used Support a Trial? if (method_exists($this, 'enable_trial')) { $apply = TRUE; } } if ($apply) { $data['trial_on'] = TRUE; $data['expire_date'] = $user->expiry_time($data['trial_duration'], $data['trial_duration_type']); $data['trial_taken'] = $subId; } else { $data['trial_on'] = FALSE; // most important $data['expire_date'] = $user->expiry_time($data['duration'], $data['duration_type'], $extend); } @ym_log_transaction(YM_ACCESS_EXTENSION, $data['expire_date'], $userId); // check for force end if (isset($pack['force_end_date'])) { $force_end_date = $pack['force_end_date']; if ($force_end_date > time()) { // greater than now @ym_log_transaction(YM_ACCESS_EXTENSION, 'Adjustment (Force End Date): ' . $force_end_date, $userId); $data['expire_date'] = $force_end_date; } } // group membership $data['child_accounts_allowed'] = $pack['child_accounts_allowed']; $data['child_accounts_package_types'] = $pack['child_accounts_package_types']; $data['child_accounts_packages'] = $pack['child_accounts_packages']; // admin bar control $data['hide_admin_bar'] = $pack['hide_admin_bar']; $user->update($data); $user->save(); $user->updaterole($pack['role']); } } if (!$complete) { $data = array('new_status' => FALSE); if (method_exists($this, 'fail_process')) { $data = $this->fail_process(); } else { $new_status = YM_STATUS_ERROR; $status_str = sprintf(__('Last Payment Errored and No Handler Found for the Payment Gateway Response', 'ym')); $data = array('new_status' => $new_status, 'status_str' => $status_str); } if (isset($data['new_status']) && $data['new_status']) { @ym_log_transaction(YM_USER_STATUS_UPDATE, $data['new_status'] . ' - ' . $data['status_str'], $userId); if (isset($data['expiry']) && $data['expiry']) { @ym_log_transaction(YM_ACCESS_EXPIRY, $data['expiry'], $userId); } $data['status'] = $data['new_status']; unset($data['new_status']); $user = new YourMember_User($userId); $user->update($data); $user->save(); } } $packet = array('user_id' => $userId, 'pack_id' => $subId, 'status' => $complete); if ($complete) { do_action('ym_membership_transaction_success', $packet); do_action('ym_membership_transaction_success_' . $this->code, $packet); } else { do_action('ym_membership_transaction_failed', $packet); do_action('ym_membership_transaction_failed_' . $this->code, $packet); } do_action('ym_gateway_return', $packet); do_action('ym_gateway_return_' . $this->code, $packet); $this->notify_user($packet); }
function ym_register($user_id) { global $wpdb; if (!isset($_SESSION['error_on_page'])) { get_currentuserinfo(); $ym_user = new YourMember_User($user_id); $ym_user->status = YM_STATUS_NULL; $ym_user->save(); if (strpos($_SERVER['REQUEST_URI'], '/wp-admin/') === false) { // check if subscription option is in the registration form $subs_option = false; $user_pass = false; // save the custom fields if there are any $fld_obj = get_option('ym_custom_fields'); $entries = $fld_obj->entries; $order = $fld_obj->order; if (!empty($order)) { if (strpos($order, ';') !== false) { $orders = explode(';', $order); } else { $orders = array($order); } $data = array(); foreach ($orders as $order) { foreach ($entries as $entry) { if ($order == $entry['id']) { if ($entry['name'] == 'subscription_options') { $subs_option = true; } else { if ($entry['name'] == 'subscription_introduction' || $entry['name'] == 'terms_and_conditions') { continue; } else { if ($entry['name'] == 'birthdate') { if (!empty($_POST['ym_birthdate_month']) && !empty($_POST['ym_birthdate_day']) && !empty($_POST['ym_birthdate_year'])) { $data[$entry['id']] = $_POST['ym_birthdate_month'] . '-' . $_POST['ym_birthdate_day'] . '-' . $_POST['ym_birthdate_year']; } } else { if ($entry['name'] == 'country') { if (!empty($_POST['ym_country'])) { $data[$entry['id']] = $_POST['ym_country']; } } else { if ($entry['type'] == 'file') { $name = 'ym_field-' . $entry['id']; if (isset($_FILES[$name])) { $ok = FALSE; global $ym_upload_root; if ($ym_upload_root) { $dir = trailingslashit(trailingslashit($ym_upload_root) . 'ym_custom_field_' . $entry['name']); if (!is_dir($dir)) { mkdir($dir); } if (is_dir($dir)) { // all good if ($_FILES[$name]['error'] == UPLOAD_ERR_OK) { $tmp = $_FILES[$name]['tmp_name']; $target = $dir . ym_get_user_id() . '_' . $_FILES[$name]['name']; if (move_uploaded_file($tmp, $target)) { global $ym_upload_url; $data[$entry['id']] = trailingslashit($ym_upload_url) . 'ym_custom_field_' . $entry['name'] . '/' . ym_get_user_id() . '_' . $_FILES[$name]['name']; $ok = TRUE; } } } } if (!$ok) { echo '<div id="message" class="error"><p>' . __('An Error Occured whilst Uploading', 'ym') . '</p></div>'; } } } else { if ($entry['type'] == 'callback') { $callback = 'ym_callback_custom_fields_' . $entry['name'] . '_save'; if (function_exists($callback)) { $data[$entry['id']] = $callback($entry['id']); } } else { $field_name = 'ym_field-' . $entry['id']; if (in_array($entry['name'], array('first_name', 'last_name'))) { update_user_meta($user_id, $entry['name'], $_POST[$field_name]); } $data[$entry['id']] = ym_post($field_name, ''); } } } } } } } } } update_user_option($user_id, 'ym_custom_fields', $data, true); } if (!($user_pass = ym_post('ym_password'))) { $user_pass = substr(md5(uniqid(microtime())), 0, 7); } $user_pass_md5 = md5($user_pass); $wpdb->query("UPDATE {$wpdb->users} SET user_pass = '******' WHERE ID = '{$user_id}'"); wp_new_user_notification($user_id, $user_pass); // redirect to ym_subscribe $userdata = get_userdata($user_id); $redirect = add_query_arg(array('username' => $userdata->user_login, 'ym_subscribe' => 1), get_option('siteurl')); if (ym_post('ym_autologin')) { $redirect = add_query_arg(array('ym_autologin' => 1), $redirect); } $redirector = ym_post('ym_redirector', ym_post('redirect_to')); if ($redirector) { $redirect = add_query_arg(array('redirector' => $redirector), $redirect); } $another_page_needed = ym_request('another_page_needed'); if ($page = ym_request('ym_page', 1)) { $redirect = add_query_arg(array('ym_page' => $page), $redirect); if ($another_page_needed) { $redirect = add_query_arg(array('another_page_needed' => $another_page_needed), $redirect); } } if ($subs_option) { $redirect = add_query_arg(array('pack_id' => $_POST['ym_subscription']), $redirect); } if (!headers_sent()) { header('location: ' . $redirect); } else { echo '<script>document.location="' . $redirect . '";</script>'; } exit; } else { return $user_id; } } }
function do_process() { // IPN Handler $eventType = ym_request('eventType'); $acc_num = ym_request('clientAccnum'); $sub_num = ym_request('clientSubacc'); if (!$eventType) { header('HTTP/1.1 403 Forbidden'); echo 'Error in IPN. No Idea what the hell your trying to do'; exit; } if ($acc_num != $this->clientAccnum || $sub_num != $this->clientSubacc) { header('HTTP/1.1 403 Forbidden'); echo 'Error in IPN. Client Account Numbers'; exit; } global $wpdb; $subscriptionId = ym_post('subscriptionId'); switch ($eventType) { case 'NewSaleSuccess': case 'NewSaleFailure': $digest = ym_post('dynamicPricingValidationDigest', false); // got something to validate? if (ym_post('failureCode')) { // failed $validate = md5(ym_post('subscriptionId') . 0 . $this->md5salt); $complete = false; } else { // complete $validate = md5(ym_post('subscriptionId') . 1 . $this->md5salt); $complete = true; } // validate if ($digest != $validate) { header('HTTP/1.1 403 Forbidden'); echo 'Error in IPN. Bad Digest'; exit; } // initial purchase list($buy, $what, $id, $user_id) = explode('_', ym_post('X-custom')); update_user_meta($user_id, 'ym_ccbill_subscription_id', ym_post('subscriptionId')); $this->common_process(ym_post('X-custom'), ym_post('billedInitialPrice'), $complete); break; case 'Cancellation': // cancellation // load user by sub id $user_id = $wpdb->get_var('SELECT user_id FROM ' . $wpdb->usermeta . ' WHERE meta_key = \'ym_ccbill_subscription_id\' AND meta_value = \'' . $subscriptionId . '\''); if ($user_id) { $ym_user = new YourMember_User($user_id); $data = array('expire_date' => time() - 1, 'status' => YM_STATUS_CANCEL, 'status_str' => ym_post('reason')); $ym_user->update($data); // do expire check (for drop down) $ym_user->expire_check(); $ym_user->save(); @ym_log_transaction(YM_USER_STATUS_UPDATE, $data['status'] . ' - ' . $data['status_str'] . ' - ' . __('User Unsubscribe', 'ym'), $ym_user->ID); } else { // ought to error but the ccbill does nothing with the response @ym_log_transaction(YM_IPN, $_REQUEST, 0); } break; case 'RenewalSuccess': // success renewal // load user by sub id $user_id = $wpdb->get_var('SELECT user_id FROM ' . $wpdb->usermeta . ' WHERE meta_key = \'ym_ccbill_subscription_id\' AND meta_value = \'' . $subscriptionId . '\''); if ($user_id) { $pack = new YourMember_User($user_id); $code = 'buy_subscription_' . $pack->pack_id . '_' . $user_id; $this->common_process($code, ym_post('billedRecurringPrice'), true); } else { // ought to error but the ccbill does nothing with the response @ym_log_transaction(YM_IPN, $_REQUEST, 0); } break; case 'RenewalFailure': // fail renewal $user_id = $wpdb->get_var('SELECT user_id FROM ' . $wpdb->usermeta . ' WHERE meta_key = \'ym_ccbill_subscription_id\' AND meta_value = \'' . $subscriptionId . '\''); if ($user_id) { $ym_user = new YourMember_User($user_id); $data = array('expire_date' => time() - 1, 'status' => YM_STATUS_ERROR, 'status_str' => ym_post('failureReason')); $ym_user->update($data); // do expire check (for drop down) $ym_user->expire_check(); $ym_user->save(); @ym_log_transaction(YM_USER_STATUS_UPDATE, $data['status'] . ' - ' . $data['status_str'] . ' - ' . __('User Unsubscribe', 'ym'), $ym_user->ID); } else { // ought to error but the ccbill does nothing with the response @ym_log_transaction(YM_IPN, $_REQUEST, 0); } break; default: // something we dont want to handle @ym_log_transaction(YM_IPN, $_REQUEST, 0); } }
break; case 'suspend': $ym_updating_a_user = new YourMember_User($user_id); $data = array('status' => YM_STATUS_NULL, 'status_str' => __('Suspended', 'ym')); $ym_updating_a_user->update($data, TRUE); $results_count++; $result_message = __('%s Users Suspended', 'ym'); break; case 'update': $ym_updating_a_user = new YourMember_User($user_id); if ($package_apply) { // gifting if ($package_apply_skip_trial) { $data['trial_taken'] = $package_apply; $ym_updating_a_user->update($data); $ym_updating_a_user->save(); } if ($package_apply == '-') { // package Removal $data['pack_id'] = ''; $ym_updating_a_user->update($data); $ym_updating_a_user->save(); } else { $pay = new ym_payment_gateway(); $pay->code = 'ym_gift'; $pay->name = 'ym_gift'; $nomore_email = ym_post('apply_package_gift_notify', FALSE); $nomore_email = $nomore_email ? FALSE : TRUE; //invert $pay->nomore_email = $nomore_email; $pay->do_buy_subscription($package_apply, $user_id, TRUE);
function ym_group_membership_create_child($email_address, $username, $password, $c_password, $sub_id, $package_type = false, $message = FALSE, $parent_id = FALSE) { if ($parent_id) { $ym_user = new YourMember_User($parent_id); } else { global $ym_user; } $current_counts = ym_group_membership_get_counts($ym_user); if (count($ym_user->child_ids) >= $ym_user->child_accounts_allowed) { if ($message) { ym_display_message(__('You are out of Child Accounts', 'ym'), 'error'); } return FALSE; } else { if ($email_address && is_email($email_address)) { if (!empty($password) && $password != $c_password) { ym_display_message(__('Passwords do not match', 'ym'), 'error'); } if ($sub_id) { if (!in_array($sub_id, $ym_user->child_accounts_packages)) { if ($message) { ym_display_message(__('You do not have access to this pacakge', 'ym'), 'error'); } return FALSE; } $pack = ym_get_pack_by_id($sub_id); } else { if ($package_type) { $pack = array(); $pack['account_type'] = $package_type; } else { // inherit mode $pack = array(); $pack['account_type'] = $ym_user->account_type; } } $inherit = true; foreach ($ym_user->child_accounts_package_types as $type => $type_count) { if ($type_count) { $inherit = false; } } // if ($inherit) { // $pack['account_type'] = ''; // } if ($pack['account_type'] && $ym_user->child_accounts_package_types[$pack['account_type']] > $current_counts[$pack['account_type']] || $inherit && $ym_user->child_accounts_allowed > count($ym_user->child_ids)) { $new_user = new YourMember_User(); $result = $new_user->create($email_address, $sub_id, FALSE, $username, $password); if (is_wp_error($result)) { ym_display_message($result->get_error_message(), 'error'); } else { // apply child $data = array('parent_id' => $ym_user->ID, 'account_type' => $pack['account_type'], 'status_str' => __('Child Account', 'ym')); if (!$sub_id) { // the child has inherited they won't have a role! $new_user->updaterole('subscriber'); } $new_user->update($data); $new_user->save(); unset($new_user); //garbage collect $child_ids = $ym_user->child_ids; $child_ids[] = $result; $ym_user->update(array('child_ids' => $child_ids)); $ym_user->save(); @ym_log_transaction(YM_ACCOUNT_TYPE_ASSIGNATION, __('Child', 'ym') . ' ' . $data['account_type'], $result); @ym_log_transaction(YM_USER_STATUS_UPDATE, YM_STATUS_ACTIVE . ' - ' . $data['status_str'], $result); // all done if ($message) { ym_display_message(__('Child User was created successfully', 'ym')); } return TRUE; } } else { if ($message) { ym_display_message(__('Total for this package type has been reached', 'ym'), 'error'); } return FALSE; } } else { if ($message) { ym_display_message(__('The Email Address was Blank or Invalid', 'ym'), 'error'); } return FALSE; } } }
function ym_profile_unsubscribe_button($return = FALSE) { if (!$this->access_token) { return; } global $ym_user; $id = get_user_meta($ym_user->ID, 'ym_gocardless_active_subscription', TRUE); if (!$id) { return; } if (ym_post('gocardless_cancel')) { $data = $this->subscriptionCancel($id); $html = '<div style="margin-bottom: 10px;"> <h4>' . __('GoCardless UnSubscribe', 'ym') . '</h4> <div style="margin-bottom: 10px;">'; if ($data) { $html .= '<p>' . __('You have UnSubscribed Successfully', 'ym'); // fire expire $user = new YourMember_User($current_user->ID); // set time to now $data = array('expire_date' => time() - 1); $user->update($data); // do expire check (for drop down) $user->expire_check(); $user->save(); } else { $html .= '<p>' . __('An error occured whilst attempting to UnSubscribe you', 'ym') . '</p>'; } $html .= '</div></div>'; } else { $html = '<div style="margin-bottom: 10px;"> <h4>' . __('GoCardless UnSubscribe', 'ym') . '</h4> <div style="margin-bottom: 10px;">' . __('If you wish to unsubscribe you can click the following link.', 'ym') . '</div> <div> <form action="" method="post"> <input type="submit" name="gocardless_cancel" value="' . __('Cancel Subscription', 'ym') . '" class="button-secondary" /> </form> </div> </div> '; } if ($return) { return $html; } else { echo $html; } }