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>'; } }
public function task($offset = 0) { global $ym_sys; if (!$ym_sys->email_reminder_enable) { echo 'Not Enabled in YM SYS'; return; } $offset = isset($_REQUEST['offset']) ? $_REQUEST['offset'] : $offset; if (is_null($offset)) { $offset = 0; } if ($offset == -1) { // no pagination $offset = 0; $this->limit = null; } $this->limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : $this->limit; // use API Exposed Element for search $users = get_users(array('offset' => $offset, 'number' => $this->limit, 'meta_key' => 'ym_status', 'meta_value' => YM_STATUS_EXPIRED, 'meta_compare' => '!=')); $current_time = time(); // set to now + days so a future $limit_date = time() + $ym_sys->email_reminder_limit * 86400; $postarray = array(); //Drip Feed Email if ($ym_sys->email_drip_reminder_enable) { global $wpdb; //Get all posts $args = array('meta_key' => '_ym_account_min_duration', 'post_status' => 'publish'); $posts = get_posts($args); foreach ($posts as $post) { $drip = get_post_meta($post->ID, '_ym_account_min_duration', true); $new_array = array(); if ($drip) { $drip = explode(';', $drip); if ($drip) { foreach ($drip as $d) { $array = explode('=', $d); $new_array[$array[0]] = $array[1]; } } } $postarray[$post->ID] = array_filter($new_array); } $postarray = array_filter($postarray); } $total = count($users); if ($total) { $counter = 0; foreach ($users as $user) { $counter++; $user = new YourMember_User($user->ID); $expire_date = $user->expire_date; // user has expire date // user has not been sent a reminder // expire_date is less that the limit date // expire date is in the future if ($user->expire_date && !$user->reminder_email_sent && $user->expire_date < $limit_date && $user->expire_date > $current_time) { // lock $user->update(array('reminder_email_sent' => true), true); // send $subject = $ym_sys->email_reminder_subject; $message = $ym_sys->email_reminder_message; $pack = ym_get_pack_by_id($user->pack_id); if ($pack['num_cycles'] != 1) { // so 0 or many ie recurring $subject = $ym_sys->email_reminder_subject_recur; $message = $ym_sys->email_reminder_message_recur; } $subject = str_replace('[site_name]', get_bloginfo(), $subject); $message = ym_apply_filter_the_content($message); ym_email($user->data->user_email, $subject, $message); @ym_log_transaction(YM_USER_STATUS_UPDATE, __('Email Reminder Sent', 'ym'), $user->ID); do_action('ym_cron_email_reminder_sent', $user->ID); echo '1'; } else { echo '.'; } if (substr($counter, -1, 1) == '0') { echo ' ' . $counter . '/' . $total . "\n"; } $reminders = array(); foreach ($postarray as $post => $type) { foreach ($type as $ac_type => $days) { if ($ac_type == $act) { $reminders[$post] = array('post_id' => $post, 'days' => $days); } } } if ($reminders) { $users_reminders = unserialize(get_user_meta($user->ID, 'drip_email_reminders', true)); if (!$users_reminders || !is_array($users_reminders)) { $users_reminders = array(); } foreach ($reminders as $reminder) { if (!in_array($reminder['post_id'], $users_reminders)) { //The post ID is not marked as already sent so we may need to send it //need to determine if we should send it. $reg = $user->data->user_registered; if ($sys->post_delay_start == 'pack_join') { if ($pack_join = $user->account_type_join_date) { $reg = date('Y-m-d', $pack_join); } } $reg = mktime(0, 0, 0, substr($reg, 5, 2), substr($reg, 8, 2), substr($reg, 0, 4)); $user_at = $reg + 86400 * $reminder['days']; if ($user_at <= time() && $user_at >= time() - 86400 * 7) { //If the time is not in the future, and no older then 10 days, we should send an email //send email $subject = $ym_sys->email_drip_subject; $message = $ym_sys->email_drip_message; $subject = str_replace('[site_name]', get_bloginfo(), $subject); $message = ym_apply_filter_the_content($message); ym_email($target, $subject, $message); $users_reminders[] = $reminder['post_id']; @ym_log_transaction(USER_STATUS_UPDATE, __('Drip Content Email for post' . $reminder['post_id'], 'ym'), $user->ID); do_action('ym_cron_email_drip_sent', $user->ID, $reminder['post_id']); } } } update_user_meta($user->ID, 'drip_email_reminders', serialize($users_reminders)); } } echo ' ' . $counter . '/' . $total . "\n"; // loop echo 'Loop Complete From ' . $offset . "\n"; if ($this->call_type == 'auto') { if ($this->limit != NULL) { echo 'Schedule Next Step' . "\n"; wp_schedule_single_event(time(), 'ym_cron_email_reminder', array($offset + $this->limit)); } else { echo 'Full Call Occured' . "\n"; } } else { // reload echo 'Sleeping' . "\n"; echo '<form action="" method="post"><input type="hidden" name="run_cron_job" value="ym_cron_email_reminder" /><input type="hidden" name="offset" value="' . ($offset + $this->limit) . '" /></form>'; echo '<script type="text/javascript">jQuery(document).ready(function() { setTimeout(\'ym_fire()\', 5000) }); function ym_fire() { jQuery(\'form\').submit(); }</script>'; } } else { echo 'Nothing to do Job Complete' . "\n"; do_action('ym_cron_email_reminder_complete'); } }
function ym_import_users_from_csv() { if (ym_post('ym_start_import')) { if ($_FILES['upload']['error'] != 4) { $time = time(); // since we don't need to keep the file, may as well leave it in tmp! $file = $_FILES['upload']['tmp_name']; $data_check = TRUE; $data_valid = FALSE; $import_array = array(); $headers = array(); $row = 0; if (($handle = fopen($file, "r")) !== FALSE) { $data_valid = TRUE; while (($data = fgetcsv($handle)) !== FALSE) { if ($data_check) { $headers = $data; $data_check = FALSE; } else { foreach ($data as $index => $item) { $import_array[$row][$headers[$index]] = $item; } $row++; } } } if (!$data_valid) { echo '<div id="message" class="error"><p>' . __('Not a Valid CSV File I can handle', 'ym') . '</p></div>'; return; } else { $total_success = 0; $total_fail = 0; $messages = ''; // user add loop foreach ($import_array as $index => $record) { $user = new YourMember_User(); // pass it to the pre built create function // no password is exported by the export function $smflag = FALSE; if ($record['smflag']) { $smflag = $record['smflag']; } $package = array(); $pack_id = ''; if (!$record['pack_id'] || !$record['package_id']) { $package = array('account_type' => $record['account_type'], 'duration' => $record['duration'], 'duration_type' => $record['duration_type']); if ($record['expire_date']) { $package['expire_date'] = $record['expire_date']; } } else { if ($record['pack_id']) { $pack_id = $record['pack_id']; } if ($record['package_id']) { $pack_id = $record['package_id']; } } $password = false; if ($record['password'] || $record['ym_password']) { if ($record['password']) { $password = $record['password']; } if ($record['ym_password']) { $password = $record['password']; } } $expire_date = false; if ($record['expire_date']) { $expire_date = $record['expire_date']; } //Setting package expiry date outside of the package /* * must be true * export does not export the password * so a new one must be generated and sent to the user */ // custom fields will ignore stuff that doens't match // run it if ($record['user_email']) { $result = $user->create($record['user_email'], $record['pack_id'], $smflag, $record['user_login'], $password, $record, $package, $expire_date); if (is_wp_error($result)) { $total_fail++; $messages .= $index . '-' . $record['user_login'] . ': ' . $result->get_error_message() . '<br />'; } else { $total_success++; } } else { $total_fail++; $messages .= 'No Email address for user, skipping user <br />'; } unset($user); } @ym_log_transaction(11, date(YM_DATE, $time) . ' User import began. added: ' . $total_success . ', failed to add: ' . $total_fail, get_current_user_id()); echo '<div id="message" class="updated"><p><strong>' . date(YM_DATE, $time) . ' User import began. added: ' . $total_success . ', failed to add: ' . $total_fail . '</strong></p></div>'; if ($messages) { echo '<div id="message" class="error"><p>' . $messages . '</p></div>'; } } // clean up unlink($file); return; } } }
unset($obj->packs[$k]); } 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>';
function ym_fbook_hidden_register() { global $facebook_client, $wpdb; $username = $facebook_client->user_data->username; $email = $facebook_client->user_data->email; if (!$email) { // logical assumption $email = $username . '@facebook.com'; } // see if user exists by email $query = 'SELECT ID FROM ' . $wpdb->prefix . 'users WHERE user_email = \'' . $email . '\''; if ($id = $wpdb->get_var($query)) { // user exists under this email $_SESSION['wordpress_user_id'] = $id; ym_fbook_dolink(); return; } // see if user name exists $query = 'SELECT ID FROM ' . $wpdb->prefix . 'users WHERE user_login = \'' . $username . '\''; if ($id = $wpdb->get_var($query)) { // user exists under this email $_SESSION['wordpress_user_id'] = $id; ym_fbook_dolink(); return; } // not found go user create $target_sub = $facebook_settings->register_with_facebook_hidden_subid; // passwordless $user = new YourMember_User(); $user_id = $user->create($email, $target_sub, FALSE, $username); if (is_int($user_id)) { $_SESSION['wordpress_user_id'] = $user_id; // ok ym_fbook_dolink(); ym_fbook_dowplogin(); if ($facebook_settings->register_with_facebook_hidden_redirect) { header('Location: ' . $facebook_settings->register_with_facebook_hidden_redirect); exit; } } else { // fail } }
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; } } }
/** Users */ if (!is_admin()) { return; // don't block if not admin so front end still runs } global $wpdb; $user_start = ym_get('user_start', '0'); if ($user_start != 'done') { $limit = 300; $did = 0; $query = 'SELECT * FROM ' . $wpdb->users . ' ORDER BY ID ASC LIMIT ' . $user_start . ',' . $limit; echo '<pre>'; foreach ($wpdb->get_results($query) as $user) { $data = new YourMember_User($user->ID); // process //last_pay_date - expire_date - $last_pay_date = $data->last_pay_date; if (strpos($last_pay_date, '-')) { // invalid if (strpos($last_pay_date, ' ')) { list($last_pay_date, $rubbish) = explode(' ', $last_pay_date); } 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
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 wp_ajax_ym_quick_activate_toggle() { ym_ajax_superuser_check(); $user_id = ym_post('ym_quick_activate_toggle_user_id'); if ($user_id) { $user = new YourMember_User($user_id); $target_status = YM_STATUS_NULL; $str = __('Suspended', 'ym'); if ($user->status == $target_status) { $target_status = YM_STATUS_ACTIVE; $str = __('Manual Update', 'ym'); } $user->update(array('status' => $target_status, 'status_str' => $str), TRUE); echo ' <script type="text/javascript"> jQuery(\'.ym_user_status_' . $user_id . '\').html(\'' . $target_status . '<br />' . $str . '\'); </script> '; } else { echo 0; } die; }
* $Date: 2012-07-18 16:56:20 +0100 (Wed, 18 Jul 2012) $ */ 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')) {
function ym_register_flow($flow_id, $pack_id = false, $widget = false) { global $current_page, $next_page, $the_flow_id, $wpdb, $ym_res, $ym_sys; global $post_data, $pack_data; $html = $form_top = ''; $payment_gateway_detected = false; if (!is_singular() && !$widget) { return __('A Register Flow Error Occurred (Type 0) Not on a Flow Page', 'ym'); } if (!$flow_id) { return __('A Register Flow Error Occurred (Type 1) No Flow Selected', 'ym'); } if (ym_post('flowcomplete')) { // complete $query = 'SELECT complete_text FROM ' . $wpdb->prefix . 'ym_register_flows WHERE flow_id = ' . $flow_id; $complete_text = $wpdb->get_var($query); if ($complete_text) { return '<p>' . $complete_text . '</p>'; } else { return '<p>' . __('Registration/Upgrade is complete', 'ym') . '</p>'; } } $flow_pages = 'SELECT flow_pages, complete_button FROM ' . $wpdb->prefix . 'ym_register_flows WHERE flow_id = ' . $flow_id; $flow_pages = $wpdb->get_row($flow_pages); if (!$flow_pages) { return __('A Register Flow Error Occurred (Type 2) Flow Not Found', 'ym'); } $complete_button = $flow_pages->complete_button; $the_flow_id = $flow_id; // have a flow $flow_pages = unserialize($flow_pages->flow_pages); $last_page = ym_post('ym_register_flow_page', 0); $current_page = ym_post('ym_register_flow_next_page', 0); $flowcomplete = ym_post('flowcomplete', 0); if (!$current_page) { $copy = $flow_pages; $current_page = array_shift($copy); } $next_page = 0; while ($next_page == 0 && count($flow_pages)) { $page = array_shift($flow_pages); if ($page == $current_page) { $next_page = array_shift($flow_pages); } } //$permalink = get_permalink(); $permalink = ''; if (ym_superuser()) { echo '<div class="ym_message"><p class="ym_message_liner">' . __('Warning, entering this flow may change your WordPress role', 'ym') . '</p></div>'; } echo ' <style type="text/css"> label { display: block; } </style> '; $form = ' <form action="' . $permalink . '" method="post" enctype="multipart/form-data" id="ym_register_flow_form"> '; $html .= $form; $form_top .= $form; $custom_data = get_option('ym_custom_fields'); $custom_data = $custom_data->entries; // required? $required_data = isset($_POST['required']) ? $_POST['required'] : array(); $ok = true; $email = true; $useremail = true; $username = true; $coupon = true; $dupepassword = true; $dont_hidden = array('email_address', 'username', 'signed_request'); // maintaint $post_data = array(); foreach ($_POST as $field => $entry) { if ($field != 'ym_register_flow_page' && $field != 'ym_register_flow_next_page' && $field != 'required' && $field != 'flowcomplete') { if (isset($required_data[$field]) && $required_data[$field] == 1 && !$entry) { $ok = false; } if ($field == 'email_address' && !is_email($entry)) { $email = false; $entry = ''; } else { if ($field == 'email_address') { // verify unique if (email_exists($entry)) { $useremail = false; } } } if ($field == 'username') { if (username_exists($entry)) { $username = false; } } if ($field == 'coupon' && $entry) { $type = ym_post('coupon_type'); if ($type == 'coupon_register') { $type = array(0); } else { if ($type == 'coupon_upgrade') { $type = array(1); } else { if (!is_int($type)) { // both $type = array(0, 1); } } } $value = false; $coupon_type = ''; foreach ($type as $t) { $value = ym_validate_coupon($entry, $t); if ($value) { $coupon_type = $t; // TODO: register coupon use break; } } if ($value) { //valid $post_data['coupon_value'] = $value; $form = '<input type="hidden" name="coupon_value" value="' . $value . '" />'; $post_data['coupon_type'] = $coupon_type; $form = '<input type="hidden" name="coupon_type" value="' . $coupon_type . '" />'; $coupon = true; } else { // not valid $coupon = false; } } //YM duplicate password check if ($field == 'ym_password') { if (ym_post('ym_password_check') || ym_post('ym_password_dupe')) { $dupepassword = false; if (ym_post('ym_password') == ym_post('ym_password_check')) { $dupepassword = true; } } } if (!isset($post_data[$field])) { $post_data[$field] = ym_post($field); //$entry; if (!in_array($field, $dont_hidden)) { $form = '<input type="hidden" name="' . $field . '" value="' . $entry . '" /> '; $html .= $form; $form_top .= $form; } } } } $call_login = 0; if ($_POST) { if (!$ok || !$email || !$useremail || !$username || !$coupon || !$dupepassword) { $next_page = $current_page; $current_page = $last_page; if (!$email) { $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_email_invalid . '</p></div>'; } if (!$useremail) { $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_email_inuse . '</p></div>'; } if (!$username) { $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_username_inuse . '</p></div>'; } if (!$ok) { $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_required_fields . '</p></div>'; } if (!$coupon) { $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_invalid_coupon . '</p></div>'; } if (!$dupepassword) { $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_invalid_password . '</p></div>'; } $ok = false; } global $current_user; get_currentuserinfo(); $username = $password = $fb_widget_ok = false; // check registation if ($ok) { if (!$current_user->ID) { $email = isset($post_data['email_address']) ? $post_data['email_address'] : ''; $username = isset($post_data['username']) ? $post_data['username'] : ''; $password = isset($post_data['password']) ? $post_data['password'] : ''; if ($email) { // minimum for registeration if (!$username) { $username = $email; } if (username_exists($username)) { // register failed $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_username_inuse . '</p></div>'; } else { // able to registers $ym_user = new YourMember_User(); $user_id = $ym_user->create($email, false, true, $username, $password); wp_set_current_user($user_id); $call_login = 1; } } else { if (ym_post('signed_request')) { $data = ym_facebook_uncode(ym_post('signed_request')); if ($data) { if ($data->registration) { // register! if (email_exists($data->registration->email) || username_exists($data->registration->email)) { $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_email_inuse . '</p></div>'; } else { $ym_user = new YourMember_User(); $user_id = $ym_user->create($data->registration->email, false, true, $data->registration->email, $data->registration->password, array('first_name' => $data->registration->first_name, 'last_name' => $data->registration->last_name)); wp_set_current_user($user_id); $call_login = 1; $fb_widget_ok = true; } } else { $html .= '<div class="ym_message"><p class="ym_message_liner">' . __('Faecbook Registration Error (2)', 'ym') . '</p></div>'; } } else { $html .= '<div class="ym_message"><p class="ym_message_liner">' . __('Faecbook Registration Error (1)', 'ym') . '</p></div>'; } } } } else { // update key user entries if (isset($post_data['username'])) { if ($username = $post_data['username']) { $query = 'UPDATE ' . $wpdb->users . ' SET user_login = \'' . $username . '\' WHERE ID = ' . $current_user->ID; $wpdb->query($query); } } if (isset($post_data['password'])) { if ($password = $post_data['password']) { $pw_hash = wp_hash_password($password); $query = 'UPDATE ' . $wpdb->users . ' SET user_pass = \'' . $pw_hash . '\' WHERE ID = ' . $current_user->ID; $wpdb->query($query); $call_login = 1; } } } // customs ym_update_custom_fields(); } } $gateway_return = ym_request('gateway_return', false); if ($gateway_return) { // return from gateway into flow // all details dropped :-( $to_remove = array('gateway_return', 'item', 'ym_register_flow_page', 'ym_register_flow_next_page', 'user_id'); $query = $_SERVER['QUERY_STRING']; foreach ($to_remove as $remove) { $query = preg_replace('/' . $remove . '\\=' . "([a-zA-Z0-9_]+)/", '', $query); } while (substr($query, -1, 1) == '&') { $query = substr($query, 0, -1); } $html = str_replace('<form action=""', '<form action="?' . $query . '"', $html); $user_id = ym_request('user_id', false); if ($user_id) { $call_login = 1; } } $ym_register_user_id = ym_request('ym_register_user_id', false); if ($ym_register_user_id) { $call_login = 1; $user_id = $ym_register_user_id; } if ($call_login) { // temp login wp_set_current_user($user_id); $html .= '<input type="hidden" name="ym_register_user_id" value="' . $user_id . '" />'; } unset($username); unset($password); $form = ' <input type="hidden" name="ym_register_flow_page" value="' . $current_page . '" /> <input type="hidden" name="ym_register_flow_next_page" value="' . $next_page . '" /> '; $html .= $form; $form_top .= $form; // data maintain whats left foreach ($post_data as $key => $item) { if (!in_array($key, $dont_hidden)) { $form = ' <input type="hidden" name="' . $key . '" value="' . $item . '" /> '; $html .= $form; $form_top .= $form; } } // load $page = 'SELECT page_fields, button_text FROM ' . $wpdb->prefix . 'ym_register_pages WHERE page_id = ' . $current_page; $page = $wpdb->get_row($page); if (!$page) { return __('A Register Flow Error Occurred (Type 3) Page Not Found', 'ym'); } $page_data = $page->page_fields; $next_button = $page->button_text; $page_data = unserialize($page_data); foreach ($page_data as $item => $field) { foreach ($field as $i => $f) { $page_data[$item][$i] = stripslashes(urldecode($f)); } } $block_logic = array(); // parse pack data $pack_data = false; if (isset($post_data['pack_id'])) { // load from form $pack_id = $post_data['pack_id']; // pass thru.... } if ($pack_id) { $pack_data = ym_get_pack_by_id($pack_id); } else { // no pack id :-( // default $pack_order = ym_get_packs(); $pack_data = array_shift($pack_order); } $first_button = true; foreach ($page_data as $index => $field_data) { $display = true; if ($field_data['iflogic']) { // block has logic $display = false; // evaulate the block logic result // is it a then or a else? switch ($field_data['iflogic']) { case 'loggedin': $match = $field_data['iflogic_quantity_loggedin']; $logged_in = is_user_logged_in(); if ($logged_in && $match) { // user is logged on and the match is for logged in $this_logic = 'then'; } else { if (!$logged_in && !$match) { $this_logic = 'then'; } else { $this_logic = 'else'; } } break; case 'buying': $match = $field_data['iflogic_quantity_pack']; if (isset($post_data['pack_id']) && $post_data['pack_id'] == $match) { $this_logic = 'then'; } else { $this_logic = 'else'; } break; case 'currentlyon': $match = $field_data['iflogic_quantity_pack']; if (is_user_logged_in()) { global $ym_user; $pack_id = $ym_user->pack_id ? $ym_user->pack_id : 0; if ($pack_id == $match) { $this_logic = 'then'; } else { $this_logic = 'else'; } } else { $this_logic = 'else'; } break; case 'accounttype': $match = $field_data['iflogic_quantity_pack']; $match = strtolower($match); if (is_user_logged_in()) { global $ym_user; $account_type = $ym_user->account_type ? $ym_user->account_type : ''; $account_type = strtolower($account_type); if ($account_type == $match) { $this_logic = 'then'; } else { $this_logic = 'else'; } } else { $this_logic = 'else'; } break; case 'filledin': // custom field $field = $field_data['iflogic_quantity_custom']; $value = $field_data['iflogic_quantity_custom_compare']; if (is_user_logged_in()) { $customs = get_user_meta($current_user->ID, 'ym_custom_fields', true); $test = $customs->{$field}; if ($test == $value) { $this_logic = 'then'; } else { $this_logic = 'else'; } } else { $this_logic = 'else'; } break; case 'servervar': case 'getvar': case 'postvar': case 'cookievar': $source = '_' . substr($field_data['iflogic'], 0, -3); $match_name = $field_data['iflogic_quantity_field']; $match_value = $field_data['iflogic_quantity_entry']; $current_value = $source[$match_name]; if ($current_value == $match_value) { $this_logic = 'then'; } else { $this_logic = 'else'; } break; case 'registeredfor': // case 'memberfor': // case 'memberfor': case 'expiresin': $match_value = $field_data['iflogic_quantity_memberfor_value']; $match_unit = $field_data['iflogic_quantity_memberfor_unit']; if (is_user_logged_in()) { global $ym_user; if ($field_data['iflogic'] == 'registeredfor') { $math_date = strtotime($current_user->user_registered); } else { if ($field_data['iflogic'] == 'expiresin') { $math_data = $ym_user->expire_date; } else { $math_date = ''; } } $seconds = ym_register_flow_date_math($match_value, $match_unit); $diff = time() - $math_date; if ($diff > $seconds) { $this_logic = 'then'; } else { $this_logic = 'else'; } } else { $this_logic = 'else'; } break; default: $this_logic = 'else'; } if ($this_logic == 'then' && $field_data['iflogic_showhide'] == 'show' || $this_logic == 'else' && $field_data['iflogic_showhide'] == 'hide') { $display = true; } else { $display = false; } } if ($field_data['label'] == 'page_logic' && ($this_logic == 'then' && $field_data['iflogic_showhide'] == 'hide' || $this_logic == 'else' && $field_data['iflogic_showhide'] == 'hide')) { $html .= ' <script type="text/javascript"> jQuery(document).ready(function() { jQuery(\'#ym_register_flow_form\').submit(); }); </script> '; $html .= '</form>'; return $html; } else { if ($field_data['label'] == 'page_logic') { // skip the IF and just skip the whole loop if should? continue; } } /** output render */ $html .= '<span class="' . $field_data['classes'] . '">'; //open class span if ($field_data['types'] == 'freetext' && $display) { $html .= '<p>' . nl2br($field_data['names']) . '</p>'; //names o.0 lol /** Customs Processor */ } else { if ($field_data['types'] == 'custom' && $display) { // LIFTED FROM ym.php line 642 // modded tooooo! if ($field_data['names'] == 'terms_and_conditions' && !empty($ym_res->tos)) { $html .= '<p> <textarea name="tos" cols="29" rows="5" readonly="readonly">' . $ym_res->tos . '</textarea>'; $html .= '</p>'; $html .= '<p> <label class="ym_label" for="terms_and_conditions"> <div><input type="checkbox" class="checkbox" name="terms_and_conditions" id="terms_and_conditions" value="1" /> ' . __('I agree to the Terms and Conditions.', 'ym') . '</div> </label> </p>' . "\n"; } else { if ($field_data['names'] == 'ym_password') { $html .= '<label for="ym_password">' . $field_data['label']; $html .= '<input type="password" name="' . $field_data['names'] . '" value="" />'; $html .= '<input type="hidden" name="required[' . $field_data['names'] . ']" value="' . $field_data['required'] . '" />'; if ($field_data['required']) { $html .= $ym_sys->required_custom_field_symbol; } $html .= '</label>'; if (!empty($field_data['options'])) { $html .= '<label for="ym_password_check">' . __('Confirm Password', 'ym'); $html .= '<input type="password" name="ym_password_check" value="" />'; $html .= '<input type="hidden" name="ym_password_dupe" value="1" />'; if ($field_data['required']) { $html .= $ym_sys->required_custom_field_symbol; } $html .= '</label>'; } } else { if ($field_data['names'] == 'subscription_introduction' && !empty($ym_res->subs_intro)) { $html .= '<div class="ym_subs_intro">' . $ym_res->subs_intro . '</div>'; } else { if ($field_data['names'] == 'subscription_options') { global $ym_packs; $upsell_from = ym_request('gateway_return', false) ? $pack_id : false; // TO DO $pack_data = false; if ($pack_id && !ym_request('gateway_return', false)) { $pack_data = ym_get_pack_by_id($pack_id); if ($pack_data) { $label = ym_get_pack_label($pack_id); $html .= '<p>' . sprintf(__('You are subscribing to <b>%s</b>', 'ym'), $label) . '</p>'; $html .= '<input type="hidden" name="pack_id" value="' . $pack_id . '" />'; } else { return __('A Register Flow Error Occurred (Type 4) Specified Pack Not Found', 'ym'); } } else { $ym_packs->packs = apply_filters('ym_packs', $ym_packs->packs); foreach ($ym_packs->packs as $pack) { if ($upsell_from == $pack['id']) { continue; } $label = ym_get_pack_label($pack['id']); $html .= '<label for="pack_id_' . $pack['id'] . '">'; $html .= '<input type="radio" name="pack_id" id="pack_id_' . $pack['id'] . '" value="' . $pack['id'] . '" />'; $html .= ' ' . $label . ' '; $html .= '</label>'; } } } else { if ($field_data['names'] == 'birthdate') { $html .= '<label for="ym_birthdate_month">' . $field_data['label']; $birthdate_fields = ym_birthdate_fields('ym_birthdate', ym_post('ym_birthdate_month', ''), ym_post('ym_birthdate_day', ''), ym_post('ym_birthdate_year', '')); $html .= $birthdate_fields; $html .= '<input type="hidden" name="required[ym_birthdate_month]" value="' . $field_data['required'] . '" />'; $html .= '<input type="hidden" name="required[ym_birthdate_day]" value="' . $field_data['required'] . '" />'; $html .= '<input type="hidden" name="required[ym_birthdate_year]" value="' . $field_data['required'] . '" />'; if ($field_data['required']) { $html .= $ym_sys->required_custom_field_symbol; } $html .= '</label>'; } else { if ($field_data['names'] == 'country') { $html .= '<label for="ym_country">' . $field_data['label']; $countries_sel = ym_countries_list('ym_country', ym_post('ym_country', false)); $html .= $countries_sel; $html .= '<input type="hidden" name="required[ym_country]" value="' . $field_data['required'] . '" />'; if ($field_data['required']) { $html .= $ym_sys->required_custom_field_symbol; } $html .= '</label>'; } else { // HERE $this_custom = ''; foreach ($custom_data as $custom) { $label = $custom['label']; if (!$label) { $label = strtolower(str_replace(' ', '_', $custom['name'])); } if ($label == $field_data['label']) { // found $this_custom = $custom; break; } } if ($this_custom) { $ro = $this_custom['readonly'] ? 'readonly="readonly"' : ''; // check for special $value = $this_custom['value']; if (strpos($value, ':') !== false) { $array = explode(':', $value); if (count($array)) { switch ($array[0]) { case 'cookie': $value = ym_cookie($array[1]); break; case 'session': $value = ym_session($array[1]); break; case 'get': $value = ym_get($array[1]); break; case 'post': $value = ym_post($array[1]); break; case 'request': case 'qs': $value = ym_request($array[1]); break; default: $value = ''; break; } $this_custom['value'] = ym_post($this_custom['name'], $value); } } else { if (is_user_logged_in()) { $this_custom['value'] = ym_custom_value($this_custom['id']); } else { $this_custom['value'] = ym_post($this_custom['name'], $this_custom['value']); } } // ro adjust for fields that should not be changed switch ($this_custom['type']) { case 'password': case 'text': $html .= '<label for="' . $this_custom['name'] . '">' . $this_custom['label']; $html .= '<input type="' . $this_custom['type'] . '" name="' . $this_custom['name'] . '" value="' . $this_custom['value'] . '" ' . $ro . ' />'; $html .= '<input type="hidden" name="required[' . $this_custom['name'] . ']" value="' . $field_data['required'] . '" />'; if ($field_data['required'] && !$ro) { $html .= $ym_sys->required_custom_field_symbol; } $html .= '</label>'; break; case 'hidden': $html .= '<input type="hidden" name="' . $this_custom['name'] . '" value="' . $this_custom['value'] . '" ' . $ro . ' />'; break; case 'yesnocheckbox': $html .= '<label for="' . $this_custom['name'] . '">' . $this_custom['label']; $html .= '<input type="checkbox" name="' . $this_custom['name'] . '" value="1" ' . ($this_custom['value'] ? 'checked="checked"' : '') . ' ' . $ro . ' />'; $html .= '<input type="hidden" name="required[' . $this_custom['name'] . ']" value="' . $field_data['required'] . '" />'; if ($field_data['required'] && !$ro) { $html .= $ym_sys->required_custom_field_symbol; } $html .= '</label>'; break; case 'yesno': case 'select': case 'multiselect': $html .= '<label for="' . $this_custom['name'] . '">' . $this_custom['label']; if ($this_custom['type'] == 'multiselect') { $html .= '<select name="' . $this_custom['name'] . '[]" multiple="multiple"'; } else { $html .= '<select name="' . $this_custom['name'] . '" '; } $html .= '>'; if ($this_custom['type'] == 'select' || $this_custom['type'] == 'multiselect') { $options = explode(';', $this_custom['available_values']); } else { $options = array(__('Yes', 'ym'), __('No', 'ym')); } foreach ($options as $option) { if (strpos($option, ':')) { list($option, $val) = explode(':', $option); $html .= '<option value="' . $option . '" ' . ($option == $this_custom['value'] ? 'selected="selected"' : '') . '>' . $val . '</option>'; } else { $html .= '<option value="' . $option . '" ' . ($option == $this_custom['value'] ? 'selected="selected"' : '') . '>' . $option . '</option>'; } } $html .= ' </select> '; $html .= '<input type="hidden" name="required[' . $this_custom['name'] . ']" value="' . $field_data['required'] . '" />'; if ($field_data['required'] && !$ro) { $html .= $ym_sys->required_custom_field_symbol; } $html .= '</label>'; break; case 'textarea': $html .= '<label for="' . $this_custom['name'] . '">' . $this_custom['label']; $html .= '<textarea name="' . $this_custom['name'] . '" cols="29" rows="5" ' . $ro . '>' . $this_custom['value'] . '</textarea>'; $html .= '<input type="hidden" name="required[' . $this_custom['name'] . ']" value="' . $field_data['required'] . '" />'; if ($field_data['required'] && !$ro) { $html .= $ym_sys->required_custom_field_symbol; } $html .= '</label>'; break; case 'file': $html .= '<label for="' . $this_custom['name'] . '">' . $this_custom['label']; $html .= '<input type="file" name="' . $this_custom['name'] . '" />'; $html .= '</label>'; break; } } } } } } } } // END LIFT /** Buttons */ } else { if (($field_data['types'] == 'payment_button' || $field_data['types'] == 'payment_action') && $display) { $payment_gateway_detected = true; add_filter('ym_additional_code', 'ym_register_flow_override_return', 10, 3); $enabled = get_option('ym_modules'); // use the ym user id function if (ym_get_user_id()) { if (in_array($field_data['names'], $enabled)) { // register flow $class = $field_data['names']; $pay = new $class(); if ($first_button) { $html .= '</form>'; $first_button = false; } $this_pack = $pack_data; // coupon check if (isset($post_data['coupon_value']) && $post_data['coupon_value']) { // stop // stash $value = ym_apply_coupon($post_data['coupon'], $post_data['coupon_type'], $this_pack['cost']); $type = ym_get_coupon_type($value); if ($type == 'percent') { // percent cost change $this_pack['cost'] = $this_pack['cost'] / 100 * $value; } else { if ($type == 'sub_pack') { // diff pack $this_pack = ym_get_pack_by_id($value); } else { // other // new cost $this_pack['cost'] = $value; } } ym_register_coupon_use($post_data['coupon'], ym_get_user_id(), 'buy_subscription_' . $pack_data['id']); if (!$this_pack['cost']) { // change to free // $field_data['names'] = 'ym_free'; // lifted from 135 of ym-register.include.php $code_to_use = 'freebie_code'; // attempt to redirect to the processor. $loc = $ym_home . '/index.php?ym_process=ym_free&' . $code_to_use . '=buy_subscription_' . $this_pack['id'] . '_' . ym_get_user_id(); if (!headers_sent()) { header('Location: ' . $loc); exit; } else { echo '<script type="text/javascript">window.location = "' . $loc . '";</script>'; } die; } } // there will always be pack data becuase I picked the default one earlier // but it will default to the default pack anyway if ($this_pack['cost']) { // && $field_data['names'] != 'ym_free') { // $gw_button_form = $pay->getButton($this_pack['id'], (isset($post_data['coupon_value']) ? $this_pack['cost'] : false)); // $html .= $gw_button_form; $gw_button_form = $pay->getButton($this_pack['id'], isset($post_data['coupon_value']) ? $this_pack['cost'] : false); if ($field_data['types'] == 'payment_action') { if (method_exists($pay, 'register_auto_payment_action')) { $html .= $pay->register_auto_payment_action($this_pack['id'], isset($post_data['coupon_value']) ? $this_pack['cost'] : false, true); } else { if ($gw_button_form) { $html .= $gw_button_form . ' <script type="text/javascript"> jQuery(document).ready(function() { jQuery(\'.' . $field_data['names'] . '_form\').submit(); }); </script> '; } } } else { if (method_exists($pay, 'register_payment_action')) { $html .= $pay->register_payment_action(true); } else { $html .= $gw_button_form; } } } else { if (!$this_pack['cost'] && $field_data['names'] == 'ym_free') { // free $gw_button_form = $pay->getButton($this_pack['id'], false); $html .= $gw_button_form; if ($field_data['types'] == 'payment_action') { if (method_exists($pay, 'register_auto_payment_action')) { $html .= $pay->register_auto_payment_action($this_pack['id'], false, true); } else { if ($gw_button_form) { $html .= ' <script type="text/javascript"> jQuery(document).ready(function() { jQuery(\'.ym_free_form\').submit(); }); </script> '; } } } else { if (method_exists($pay, 'register_payment_action')) { $html .= $pay->register_payment_action(true); } } } else { if (isset($post_data['coupon_value']) && $post_data['coupon_value']) { return __('A Register Flow Error Occurred (Type 5) Pack/Coupon Error', 'ym'); } } } } } else { // user not logged in // No User ID Determined return __('In order to continue you need to Register or Login', 'ym'); } /** Widgets */ } else { if ($field_data['types'] == 'widget' && $display) { if ($field_data['names'] == 'login') { // login form $html .= ' <input type="hidden" name="ym_register_flow_page" value="' . $current_page . '" /> <input type="hidden" name="ym_register_flow_next_page" value="' . $current_page . '" /> '; // <input type="hidden" name="ym_register_flow_do_login" value="1" />'; $html .= ym_login_form(); } else { if ($field_data['names'] == 'register_facebook') { // check for and handle a signed request if ($fb_widget_ok) { // skippy $html .= ' <script type="text/javascript"> jQuery(document).ready(function() { jQuery(\'#ym_register_flow_form\').submit(); }); </script> '; } else { $html .= ' <iframe src="https://www.facebook.com/plugins/registration? client_id=' . get_option('ym_register_flow_fb_app_id') . '& redirect_uri=' . get_permalink() . '& fields=name,email,first_name,last_name,password" scrolling="auto" frameborder="no" style="border:none" allowTransparency="true" width="100%" height="550"> </iframe> '; // no next/complete please } $payment_gateway_detected = true; } else { $html .= 'Undefined Widget: (' . $field_data['names'] . ')'; } } /** Coupon */ } else { if ($field_data['names'] == 'coupon' && $display) { $value = isset($post_data[$field_data['names']]) ? $post_data[$field_data['names']] : ''; $html .= '<label for="' . $field_data['names'] . '">' . $field_data['label']; $html .= '<input type="text" name="' . $field_data['names'] . '" id="' . $field_data['names'] . '" value="' . $value . '" />'; $html .= '<input type="hidden" name="coupon_type" value="' . $field_data['types'] . '" />'; $html .= '<input type="hidden" name="required[' . $field_data['names'] . ']" value="' . $field_data['required'] . '" />'; if ($field_data['required']) { $html .= $ym_sys->required_custom_field_symbol; } $html .= '</label>'; /** Display everything else */ } else { if ($display) { $value = isset($post_data[$field_data['names']]) ? $post_data[$field_data['names']] : ''; $html .= '<label for="' . $field_data['names'] . '">' . $field_data['label']; $html .= '<input type="' . $field_data['types'] . '" name="' . $field_data['names'] . '" id="' . $field_data['names'] . '" value="' . $value . '" />'; $html .= '<input type="hidden" name="required[' . $field_data['names'] . ']" value="' . $field_data['required'] . '" />'; if ($field_data['required']) { $html .= $ym_sys->required_custom_field_symbol; } $html .= '</label>'; } } } } } } $html .= '</span>'; //closes class span } if (!$first_button) { // kill id $html = str_replace('id="ym_register_flow_form"', '', $html); // complete? if (!$next_page) { $query = 'SELECT complete_url FROM ' . $wpdb->prefix . 'ym_register_flows WHERE flow_id = ' . $flow_id; if ($url = $wpdb->get_var($query)) { $url = site_url($url); $form_top = str_replace('<form action=""', '<form action="' . $url . '"', $form_top); } } // append the form top $html .= $form_top; // end it } // payment gateway? if (!$payment_gateway_detected) { $html .= '<p>'; if ($next_page) { $html .= '<input type="submit" value="' . $next_button . '" />'; } else { $html .= ' <input type="hidden" name="flowcomplete" value="1" /> <input type="submit" value="' . $complete_button . '" />'; } $html .= '</p>'; } $html .= '</form>'; return $html; }
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); } }
$status = ym_post('status'); if ($package) { $new_user = new YourMember_User(); $result = $new_user->create($email, $package, $smflag, $username, $password); if (is_wp_error($result)) { // error ym_display_message($result->get_error_message(), 'error'); } else { // reload $new_user = new YourMember_User($result); // ok $new_user->update(array('status_str' => __('User Create: Applied', 'ym')), TRUE); $result_message = sprintf(__('User Created, ID: %s', 'ym'), $result); } } else { $new_user = new YourMember_User(); $result = $new_user->create($email, false, $smflag, $username, $password); if (is_wp_error($result)) { // error ym_display_message($result->get_error_message(), 'error'); } else { // ok apply stuff $new_user->update(array('account_type' => $package_type, 'status' => $status, 'status_str' => __('User Create: Applied', 'ym')), TRUE); $result_message = sprintf(__('User Created, ID: %s', 'ym'), $result); } } } if (!$result_message) { break; } $_POST['filter_by_option'] = '';
function expire_check() { global $ym_sys; if (!isset($this->ID)) { return; } $ID = $this->ID; // check for parent if ($this->parent_id != FALSE) { // has a parent account $parent_user = new YourMember_User($this->parent_id); $not_expired = $parent_user->expire_check(); if ($not_expired) { // check special case expires if ($this->status == YM_STATUS_PARENT_CANCEL) { return FALSE; } // check user is is in parents child account list ie is orphaned if (!in_array($ID, $parent_user->child_ids)) { // orphaned transistion to a normal account // which is pending a sub payment $this->status = YM_STATUS_EXPIRED; //explict active set to clear child account status $this->parent_id = false; $this->save(); @ym_log_transaction(YM_USER_STATUS_UPDATE, __('Child Account Orphaned: Expired', 'ym'), $ID); return FALSE; } // if the account type is blank // and parent only allows a single package type // set the child to that package type if (!$this->account_type) { $allowed_types = count($parent_user->child_accounts_package_types); $allowed_packs = count($parent_user->child_accounts_packages); $error = FALSE; if ($allowed_types >= 1 && $allowed_packs >= 1) { // well f**k $error = TRUE; } else { if ($allowed_types == 1) { $this->account_type = $parent_user->child_accounts_package_types[0]; @ym_log_transaction(YM_ACCOUNT_TYPE_ASSIGNATION, $this->account_type, $ID); } else { if ($allowed_packs == 1) { ym_group_apply_package($parent_user->child_accounts_packages[0]); // go drop for status check..... } else { // if drop thru well deny. Account not configured $error = TRUE; } } } if ($error) { $this->status = YM_STATUS_PARENT_CONFIG; $this->save(); return FALSE; } } if ($this->status != $parent_user->status) { $this->status = $parent_user->status; @ym_log_transaction(YM_USER_STATUS_UPDATE, $this->status, $ID); } // if expose expire date to child // update expiry $this->save(); return TRUE; } // check for status update at this point the child account should be expired // but the parent account can be of any status (such as pending) if ($this->account_type != YM_STATUS_PARENT_EXPIRED) { $this->status = YM_STATUS_PARENT_EXPIRED; @ym_log_transaction(YM_USER_STATUS_UPDATE, $this->status, $ID); $this->save(); } return FALSE; } if (ym_superuser($ID)) { return TRUE; } $current_status = $this->status; if ($current_status === false) { return TRUE; } if ($current_status == YM_STATUS_EXPIRED || $current_status == YM_STATUS_TRIAL_EXPIRED) { return FALSE; } $grace_limit_user = $ym_sys->grace_limit; $grace_limit_user = apply_filters('ym_user_grace_limit_adjust', $grace_limit_user, $this); $new = FALSE; $reg_date = get_userdata($ID); $reg_date = strtotime($reg_date->user_registered); if ($reg_date > time() - 86400 * $grace_limit_user) { $new = TRUE; } if ($current_status == YM_STATUS_ACTIVE || $current_status == YM_STATUS_GRACE) { // time $expire = $this->expire_date; if ($expire > time()) { // expire is in the future // safe/not expired return TRUE; } // expired if ($this->ym_expiry_sub_dropdown_check()) { return; } if ($this->trial_on) { $user_status = YM_STATUS_TRIAL_EXPIRED; } else { $user_status = YM_STATUS_EXPIRED; } @ym_log_transaction(YM_ACCESS_EXPIRY, time(), $ID); @ym_log_transaction(YM_USER_STATUS_UPDATE, $user_status, $ID); $data = array('status' => $user_status, 'status_str' => __('User has expired', 'ym')); $data = apply_filters('ym_user_expire_check_into_expire', $data, $this); $this->update($data); $this->save(); do_action('ym_user_is_expired', $ID, $data); return FALSE; } else { if ($current_status == YM_STATUS_PENDING && $ym_sys->grace_enable && !$new) { // grace is only applied to pending users // eligable $last_pay_date = $this->last_pay_date; $limit = time() - 86400 * $grace_limit_user; if ($last_pay_date > $limit) { // lets put them into grace $data = array('status' => YM_STATUS_GRACE, 'status_str' => __('User is entering Grace', 'ym'), 'expire_date' => time() + 86400 * $grace_limit_user); @ym_log_transaction(YM_ACCESS_EXPIRY, $data['expire_date'], $ID); @ym_log_transaction(YM_USER_STATUS_UPDATE, $data['status'], $ID); $data = apply_filters('ym_user_expire_check_into_grace', $data, $this); $this->update($data); $this->save(); do_action('ym_user_is_in_grace', $ID, $data); // recheck return $this->expire_check(); } else { // not eligable return FALSE; } } } return FALSE; }
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>'; }
function ym_wp_login($user_login, $user) { global $ym_user, $ym_sys; if (!$ym_user) { $ym_user = new YourMember_User($user->data->ID); } $firstlogin = false; if (!get_user_meta($user->data->ID, 'ym_user_last_login')) { $firstlogin = true; } $ym_user->is_logging_in(); $redirect_to = FALSE; // Priority One: Request Redirect if (isset($_REQUEST['redirect_to']) && $_REQUEST['redirect_to']) { $redirect_to = $_REQUEST['redirect_to']; } //Sneaky not normal redirect if ($firstlogin) { $pack = ym_get_pack_by_id($ym_user->pack_id); if ($pack['login_redirect_url']) { $redirect_to = site_url($pack['first_login']); } } // Priority Two: Pack Login Redirect if (!$redirect_to && isset($ym_user->pack_id) && $ym_user->pack_id) { $pack = ym_get_pack_by_id($ym_user->pack_id); if ($pack['login_redirect_url']) { $redirect_to = site_url($pack['login_redirect_url']); } } // Priority Three: Default if (!$redirect_to && $ym_sys->login_redirect_url) { $redirect_to = site_url($ym_sys->login_redirect_url); } if ($redirect_to) { if (!headers_sent()) { header('Location: ' . $redirect_to); } else { echo '<script>window.location="' . $redirect_to . '";</script>'; } exit; } // Priority Four: WP-Admin }
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; } }