function Delete_UserLevelMeta2($user_id, $level_id, $meta) { global $wpdb; $cache_key = $user_id . '_' . $level_id . '_' . $meta; $cache_group = $this->Tables->userlevel_options; $userlevel_id = $this->Get_UserLevelIndex($user_id, $level_id); if (is_array($userlevel_id)) { foreach ($userlevel_id as $k => $v) { $userlevel_id[$k] = (int) $v; } $userlevel_id = "'" . implode("','", $userlevel_id) . "'"; } else { $userlevel_id = (int) $userlevel_id; } $query = $wpdb->prepare("DELETE FROM `{$this->Tables->userlevel_options}` WHERE `userlevel_id` IN ({$user_id}) AND `option_name`=%s", $meta); $result = $wpdb->query($query); if ($result !== false) { wlm_cache_delete($cache_key, $cache_group); return true; } return false; }
/** * Set Member's Membership Levels * @global object $wpdb * @param int $id User ID * @param array $levels Level IDs * @param boolean $noautoresponder Set to TRUE to disable autoresponder * @param boolean $timestamp_noset Set to TRUE to disable setting of timestamp * @param boolean $transaction_id_noset Set to TRUE to disable setting of transaction ID * @param boolean $nosync Set to TRUE to prevent calling SyncMembership * @param boolean $nowebinar Set to TRUE to disable webinar * @param type $pendingautoresponder * @param type $keep_existing_levels Set to TRUE to keep existing levels not passed in $levels * @return boolean */ function SetMembershipLevels($id, $levels, $noautoresponder = null, $timestamp_noset = null, $transaction_id_noset = null, $nosync = null, $nowebinar = null, $pendingautoresponder = null, $keep_existing_levels = null) { global $wpdb; $id = (int) $id; if (is_object($levels)) { $levels_metas = (array) $levels->Metas; $levels = (array) $levels->Levels; } else { $levels_metas = array(); $levels = (array) $levels; } $this->SetPayPerPost($id, $levels); if (is_null($noautoresponder)) { $noautoresponder = false; } if (is_null($timestamp_noset)) { $timestamp_noset = false; } if (is_null($transaction_id_noset)) { $transaction_id_noset = false; } if (is_null($nosync)) { $nosync = false; } if (is_null($nowebinar)) { $nowebinar = false; } if (is_null($keep_existing_levels)) { $keep_existing_levels = false; } // moved setting of $wpm_levels to top of method $wpm_levels = $this->GetOption('wpm_levels'); if (count($levels)) { // we now use the ValidateLevels method to clear the $levels array of invalid Level IDs $validated = $this->ValidateLevels($levels, null, true, true); // at least one level was invalid so we stop if (!$validated) { return false; } } $current_levels = $this->GetMembershipLevels($id, null, null, true); if ($keep_existing_levels) { $levels = array_unique(array_merge($current_levels, $levels)); } $removed_levels = $new_levels = array(); $this->ArrayDiff($levels, $current_levels, $removed_levels, $new_levels); if (count($removed_levels)) { do_action('wishlistmember_pre_remove_user_levels', $id, $removed_levels); // remove from removed_levels $rlevels = "'" . implode("','", $removed_levels) . "'"; $wpdb->query("DELETE FROM `{$this->Tables->userlevels}` WHERE `user_id`={$id} AND `level_id` IN ({$rlevels})"); } // add to new levels foreach ((array) $new_levels as $level) { $data = array('user_id' => $id, 'level_id' => $level); $wpdb->insert($this->Tables->userlevels, $data); } wlm_cache_delete($id, $this->Tables->userlevels); if (count($new_levels)) { /* * update timestamps */ if ($timestamp_noset == false) { $ts = array_combine($new_levels, array_fill(0, count($new_levels), time())); $this->UserLevelTimestamps($id, $ts); } /* * end timestamps update */ /* * set initial transaction id */ if ($transaction_id_noset == false) { $txn = array_combine($new_levels, array_fill(0, count($new_levels), '')); $this->SetMembershipLevelTxnIDs($id, $txn); } /* * end setting initial transaction id */ foreach ($new_levels as $new_level) { if (isset($levels_metas[$new_level])) { foreach ((array) $levels_metas[$new_level] as $level_meta) { if (is_array($level_meta) && count($level_meta) == 2) { list($meta, $value) = $level_meta; $this->Update_UserLevelMeta($id, $new_level, $meta, $value); } } } } } // autoresponder if (!$noautoresponder) { $usr = $this->Get_UserData($id); if ($usr->ID) { // unsubscribe from autoresponder foreach ((array) $removed_levels as $rl) { $this->ARUnsubscribe($usr->first_name, $usr->last_name, $usr->user_email, $rl); } //if no flags we're set, add the member to AR list if (empty($pendingautoresponder)) { // subscribe to autoresponder foreach ((array) $new_levels as $nl) { if (!$this->LevelCancelled($nl, $id)) { $this->ARSubscribe($usr->first_name, $usr->last_name, $usr->user_email, $nl); } } } else { foreach ($pendingautoresponder as $value) { $this->Add_UserLevelMeta($id, $level, $value, 1); } } } } else { foreach ((array) $pendingautoresponder as $value) { $this->Add_UserLevelMeta($id, $level, $value, 1); } } if (!$nowebinar) { // do webinar stuff; foreach ((array) $new_levels as $nl) { $this->WebinarSubscribe($usr->first_name, $usr->last_name, $usr->user_email, $nl); } } // trigger remove_user_levels action if a user is removed from at least one level if (count($removed_levels)) { do_action('wishlistmember_remove_user_levels', $id, $removed_levels, $new_levels); } // trigger add_user_levels action if a user is added to at least one level if (count($new_levels)) { do_action('wishlistmember_add_user_levels', $id, $new_levels, $removed_levels); } wlm_cache_delete($id, $this->Tables->userlevels); if (!$nosync) { $this->SyncMembership(); } return array('added' => $new_levels, 'removed' => $removed_levels); }
/** * Adds a new option. Will not add it if the option already exists. * @param string $option Name of the option * @param string $value Value of option * @param $enc (default false) True to encrypt $value */ function AddOption($option, $value, $enc = false) { global $wpdb; $cache_key = $option; $cache_group = $this->OptionsTable; $x = $this->GetOption($option); if ($x === false) { if ($enc) { $value = $this->WLMEncrypt($value); } $data = array('option_name' => $option, 'option_value' => maybe_serialize($value)); $x = $wpdb->insert($this->OptionsTable, $data); wlm_cache_delete($cache_key, $cache_group); } return $x ? true : false; }