/** * Verified Signup * If signups need to be verified, award points now. * @since 1.5 * @version 1.0 */ public function verified_signup($user_id) { // Check if there is a referral $referred_by = mycred_get_user_meta($user_id, 'referred_by', '', true); $referred_by_IP = mycred_get_user_meta($user_id, 'referred_by_IP', '', true); $referred_type = mycred_get_user_meta($user_id, 'referred_by_type', '', true); if ($referred_by == '' || $referred_by_IP == '' || $this->mycred_type != $referred_type) { return; } // Award $this->core->add_creds('signup_referral', $referred_by, $this->prefs['signup']['creds'], $this->prefs['signup']['log'], $user_id, $referred_by_IP, $this->mycred_type); do_action('mycred_signup_referral', $referred_by, $referred_by_IP, $user_id, $this); // Clean up mycred_delete_user_meta($user_id, 'referred_by'); mycred_delete_user_meta($user_id, 'referred_by_IP'); mycred_delete_user_meta($user_id, 'referred_by_type'); }
/** * Save Override * @since 1.5 * @version 1.1.1 */ public function save_user_override() { if (isset($_POST['mycred_adjust_users_buyrates_run']) && isset($_POST['mycred_adjust_users_buyrates'])) { $ctype = sanitize_key($_GET['ctype']); $user_id = absint($_GET['user_id']); $mycred = mycred($ctype); if ($mycred->edit_plugin_cap() && !$mycred->exclude_user($user_id)) { $new_rates = array(); foreach ((array) $_POST['mycred_adjust_users_buyrates'] as $gateway_id => $rate) { if ($rate == '') { continue; } if ($rate != 1 && in_array(substr($rate, 0, 1), array('.', ','))) { $rate = (double) '0' . $rate; } $new_rates[$gateway_id] = $rate; } if (!empty($new_rates)) { mycred_update_user_meta($user_id, 'mycred_buycred_rates_' . $ctype, '', $new_rates); } else { mycred_delete_user_meta($user_id, 'mycred_buycred_rates_' . $ctype); } wp_safe_redirect(add_query_arg(array('result' => 'buycred_rates'))); exit; } } }
/** * Profile Actions * @since 1.5 * @version 1.0.2 */ public function edit_profile_actions() { do_action('mycred_edit_profile_action'); // Update Balance if (isset($_POST['mycred_adjust_users_balance_run']) && isset($_POST['mycred_adjust_users_balance'])) { extract($_POST['mycred_adjust_users_balance']); if (wp_verify_nonce($token, 'mycred-adjust-balance')) { $ctype = sanitize_text_field($ctype); $mycred = mycred($ctype); // Enforce requirement for log entry if ($mycred->can_edit_creds() && !$mycred->can_edit_plugin() && $log == '') { wp_safe_redirect(add_query_arg(array('result' => 'log_error'))); exit; } // Make sure we can edit creds if ($mycred->can_edit_creds()) { // Prep $user_id = absint($user_id); $amount = $mycred->number($amount); $data = apply_filters('mycred_manual_change', array('ref_type' => 'user'), $this); // Run $mycred->add_creds('manual', $user_id, $amount, $log, get_current_user_id(), $data, $ctype); wp_safe_redirect(add_query_arg(array('result' => 'balance_updated'))); exit; } } } elseif (isset($_GET['page']) && $_GET['page'] == 'mycred-edit-balance' && isset($_GET['action']) && $_GET['action'] == 'exclude') { $ctype = sanitize_text_field($_GET['ctype']); $mycred = mycred($ctype); // Make sure we can edit creds if ($mycred->can_edit_creds()) { // Make sure user is not already excluded $user_id = absint($_GET['user_id']); if (!$mycred->exclude_user($user_id)) { // Get setttings $options = $mycred->core; // Get and clean up the exclude list $excludes = explode(',', $options['exclude']['list']); if (!empty($excludes)) { $_excludes = array(); foreach ($excludes as $_user_id) { $_user_id = sanitize_key($_user_id); if ($_user_id == '') { continue; } $_excludes[] = absint($_user_id); } $excludes = $_excludes; } // If user ID is not yet in list if (!in_array($user_id, $excludes)) { $excludes[] = $user_id; $options['exclude']['list'] = implode(',', $excludes); $option_id = 'mycred_pref_core'; if ($ctype != 'mycred_default') { $option_id .= '_' . $ctype; } mycred_update_option($option_id, $options); // Remove Users balance mycred_delete_user_meta($user_id, $ctype); mycred_delete_user_meta($user_id, $ctype, '_total'); global $wpdb; // Delete log entries $wpdb->delete($mycred->log_table, array('user_id' => $user_id, 'ctype' => $ctype), array('%d', '%s')); wp_safe_redirect(add_query_arg(array('user_id' => $user_id, 'result' => 'user_excluded'), admin_url('user-edit.php'))); exit; } } } } }
/** * Sanititze Settings * @filter 'mycred_save_core_prefs' * @since 0.1 * @version 1.4.1 */ public function sanitize_settings($post) { $new_data = array(); if ($this->mycred_type == 'mycred_default') { if (isset($post['types'])) { $types = array('mycred_default' => mycred_label()); foreach ($post['types'] as $item => $data) { // Make sure it is not marked as deleted if (isset($post['delete_types']) && in_array($item, $post['delete_types'])) { continue; } // Skip if empty if (empty($data['key']) || empty($data['label'])) { continue; } // Add if not in array already if (!array_key_exists($data['key'], $types)) { $key = str_replace(array(' ', '-'), '_', $data['key']); $key = sanitize_key($key); $types[$key] = sanitize_text_field($data['label']); } } mycred_update_option('mycred_types', $types); unset($post['types']); if (isset($post['delete_types'])) { unset($post['delete_types']); } } $new_data['format'] = $this->core->core['format']; if (isset($post['format']['type']) && $post['format']['type'] != '') { $new_data['format']['type'] = absint($post['format']['type']); } if (isset($post['format']['decimals'])) { $new_data['format']['decimals'] = absint($post['format']['decimals']); } } else { $main_settings = mycred_get_option('mycred_pref_core'); $new_data['format'] = $main_settings['format']; if (isset($post['format']['decimals'])) { $new_decimals = absint($post['format']['decimals']); if ($new_decimals <= $main_settings['format']['decimals']) { $new_data['format']['decimals'] = $new_decimals; } } } // Format $new_data['cred_id'] = $this->mycred_type; $new_data['format']['separators']['decimal'] = $this->maybe_whitespace($post['format']['separators']['decimal']); $new_data['format']['separators']['thousand'] = $this->maybe_whitespace($post['format']['separators']['thousand']); // Name $new_data['name'] = array('singular' => sanitize_text_field($post['name']['singular']), 'plural' => sanitize_text_field($post['name']['plural'])); // Look $new_data['before'] = sanitize_text_field($post['before']); $new_data['after'] = sanitize_text_field($post['after']); // Capabilities $new_data['caps'] = array('plugin' => sanitize_text_field($post['caps']['plugin']), 'creds' => sanitize_text_field($post['caps']['creds'])); // Max $new_data['max'] = $this->core->number($post['max']); // Make sure multisites uses capabilities that exists if (in_array($new_data['caps']['creds'], array('create_users', 'delete_themes', 'edit_plugins', 'edit_themes', 'edit_users')) && is_multisite()) { $new_data['caps']['creds'] = 'delete_users'; } // Excludes $new_data['exclude'] = array('plugin_editors' => isset($post['exclude']['plugin_editors']) ? $post['exclude']['plugin_editors'] : 0, 'cred_editors' => isset($post['exclude']['cred_editors']) ? $post['exclude']['cred_editors'] : 0, 'list' => sanitize_text_field($post['exclude']['list'])); // Remove Exclude users balances if ($new_data['exclude']['list'] != '') { $excluded_ids = explode(',', $new_data['exclude']['list']); if (!empty($excluded_ids)) { foreach ((array) $excluded_ids as $user_id) { $user_id = absint(trim($user_id)); if ($user_id == 0) { continue; } mycred_delete_user_meta($user_id, $this->mycred_type); mycred_delete_user_meta($user_id, $this->mycred_type, '_total'); } } } // User deletions $new_data['delete_user'] = isset($post['delete_user']) ? $post['delete_user'] : 0; $action_hook = ''; if (!$this->is_main_type) { $action_hook = $this->mycred_type; } $new_data = apply_filters('mycred_save_core_prefs' . $action_hook, $new_data, $post, $this); return $new_data; }
/** * Save Override * @since 1.5 * @version 1.1 */ function save_user_override() { if (isset($_POST['mycred_adjust_users_profitshare_run']) && isset($_POST['mycred_adjust_users_profitshare'])) { $ctype = sanitize_key($_GET['ctype']); $user_id = absint($_GET['user_id']); $share = $_POST['mycred_adjust_users_profitshare']['share']; if ($share != '') { if (isfloat($share)) { $share = (double) $share; } else { $share = (int) $share; } mycred_update_user_meta($user_id, 'mycred_sell_content_share_' . $ctype, '', $share); } else { mycred_delete_user_meta($user_id, 'mycred_sell_content_share_' . $ctype); } wp_safe_redirect(add_query_arg(array('result' => 'sell_content_share'))); exit; } }
/** * Save User Override * @since 1.5.2 * @version 1.0.1 */ function save_user_override() { // Save interest rate if (isset($_POST['mycred_adjust_users_interest_rate_run']) && isset($_POST['mycred_adjust_users_interest_rate'])) { $ctype = sanitize_key($_GET['ctype']); $user_id = absint($_GET['user_id']); $rate = $_POST['mycred_adjust_users_interest_rate']; if ($rate != '') { if (isfloat($rate)) { $rate = (double) $rate; } else { $rate = (int) $rate; } mycred_update_user_meta($user_id, 'mycred_banking_rate_' . $ctype, '', $rate); } else { mycred_delete_user_meta($user_id, 'mycred_banking_rate_' . $ctype); } wp_safe_redirect(add_query_arg(array('result' => 'banking_interest_rate'))); exit; } elseif (isset($_POST['mycred_exclude_users_interest_rate'])) { $ctype = sanitize_key($_GET['ctype']); $user_id = absint($_GET['user_id']); $excluded = explode(',', $this->prefs['exclude_ids']); $clean_ids = array(); if (!empty($excluded)) { foreach ($excluded as $id) { if ($id == 0) { continue; } $clean_ids[] = (int) trim($id); } } if (!in_array($user_id, $clean_ids) && $user_id != 0) { $clean_ids[] = $user_id; } $option_id = 'mycred_pref_bank'; if (!$this->is_main_type) { $option_id .= '_' . $ctype; } $data = mycred_get_option($option_id); $data['service_prefs'][$this->id]['exclude_ids'] = implode(',', $clean_ids); mycred_update_option($option_id, $data); wp_safe_redirect(add_query_arg(array('result' => 'banking_interest_excluded'))); exit; } elseif (isset($_POST['mycred_include_users_interest_rate'])) { $ctype = sanitize_key($_GET['ctype']); $user_id = absint($_GET['user_id']); $excluded = explode(',', $this->prefs['exclude_ids']); if (!empty($excluded)) { $clean_ids = array(); foreach ($excluded as $id) { $clean_id = (int) trim($id); if ($clean_id != $user_id && $user_id != 0) { $clean_ids[] = $clean_id; } } $option_id = 'mycred_pref_bank'; if (!$this->is_main_type) { $option_id .= '_' . $ctype; } $data = mycred_get_option($option_id); $data['service_prefs'][$this->id]['exclude_ids'] = implode(',', $clean_ids); mycred_update_option($option_id, $data); wp_safe_redirect(add_query_arg(array('result' => 'banking_interest_included'))); exit; } } }