/** * Run Addons * Catches all add-on activations and deactivations and loads addons * @since 0.1 * @version 1.0.1 */ public function run_addons() { $addons = $this->addons; $active = $addons['active']; $installed = $this->get(); $num = 0; // Make sure each active add-on still exists. If not delete. if (!empty($active)) { $active = array_unique($active); $_active = array(); foreach ($active as $pos => $active_id) { if (array_key_exists($active_id, $installed)) { $_active[] = $active_id; $num = $num + 1; } } unset($active); $active = $_active; $this->active = $active; } // Handle actions if (isset($_GET['addon_action']) && isset($_GET['addon_id'])) { $addon_id = $_GET['addon_id']; $action = $_GET['addon_action']; // Activation if ($action == 'activate') { $active[$num] = $addon_id; } // Deactivation if ($action == 'deactivate') { $index = array_search($addon_id, $active); if ($index !== false) { unset($active[$index]); } // Run deactivation now before the file is no longer included do_action('mycred_addon_deactivation_' . $addon_id); } $new_settings = array('installed' => $installed, 'active' => $active); if (!function_exists('update_option')) { include_once ABSPATH . 'wp-includes/option.php'; } mycred_update_option('mycred_pref_addons', $new_settings); $this->addons = $new_settings; $this->installed = $installed; $this->active = $active; } // Load addons foreach ($installed as $key => $data) { if ($this->is_active($key)) { // If path is set, load the file if (isset($data['path']) && file_exists($data['path'])) { include_once $data['path']; } // Check for activation if ($this->is_activation($key)) { do_action('mycred_addon_activation_' . $key); } } } }
function mycred_update_to_onefive($version = NULL) { if ($version === NULL) { return; } // Clean up after the 1.4.6 Email Notice bug if (version_compare($version, '1.4.7', '<')) { $cron = get_option('cron'); if (!empty($cron)) { foreach ($cron as $time => $job) { if (isset($job['mycred_send_email_notices'])) { unset($cron[$time]); } } update_option('cron', $cron); } } // 1.4 Update if (version_compare($version, '1.4', '>=')) { delete_option('mycred_update_req_settings'); delete_option('mycred_update_req_hooks'); } // 1.5 Update if (version_compare($version, '1.5', '<') && class_exists('myCRED_buyCRED_Module')) { // Update buyCRED Settings $type_set = 'mycred_default'; $setup = mycred_get_option('mycred_pref_core', false); if (isset($setup['buy_creds'])) { if (isset($setup['buy_creds']['type'])) { $type_set = $setup['buy_creds']['type']; unset($setup['buy_creds']['type']); $setup['buy_creds']['types'] = array($type_set); mycred_update_option('mycred_pref_core', $setup); } } // Update buyCRED Gateways Settings $buy_cred = mycred_get_option('mycred_pref_buycreds', false); if (isset($buy_cred['gateway_prefs'])) { foreach ($buy_cred['gateway_prefs'] as $gateway_id => $prefs) { if (!isset($prefs['exchange'])) { continue; } $buy_cred['gateway_prefs'][$gateway_id]['exchange'] = array($type_set => $prefs['exchange']); } $buy_cred['active'] = array(); mycred_update_option('mycred_pref_buycreds', $buy_cred); add_option('mycred_buycred_reset', 'true'); } // Update complted update_option('mycred_version', '1.5.4'); } else { delete_option('mycred_buycred_reset'); } }
/** * Get Hooks * @since 0.1 * @version 1.1.1 */ public function get($save = false) { $installed = array(); // Registrations $installed['registration'] = array('title' => __('%plural% for registrations', 'mycred'), 'description' => __('Award %_plural% for users joining your website.', 'mycred'), 'callback' => array('myCRED_Hook_Registration')); // Site Visits $installed['site_visit'] = array('title' => __('%plural% for daily visits', 'mycred'), 'description' => __('Award %_plural% for users visiting your website on a daily basis.', 'mycred'), 'callback' => array('myCRED_Hook_Site_Visits')); // View Content $installed['view_contents'] = array('title' => __('%plural% for viewing content', 'mycred'), 'description' => __('Award %_plural% to your users for viewing posts and / or %plural% to your authors for members viewing their content.', 'mycred'), 'callback' => array('myCRED_Hook_View_Contents')); // Logins $installed['logging_in'] = array('title' => __('%plural% for logins', 'mycred'), 'description' => __('Award %_plural% for logging in to your website. You can also set an optional limit.', 'mycred'), 'callback' => array('myCRED_Hook_Logging_In')); // Content Publishing $installed['publishing_content'] = array('title' => __('%plural% for publishing content', 'mycred'), 'description' => __('Award %_plural% for publishing content on your website. If your custom post type is not shown bellow, make sure it is set to "Public".', 'mycred'), 'callback' => array('myCRED_Hook_Publishing_Content')); // Commenting $installed['comments'] = array('title' => !function_exists('dsq_is_installed') ? __('%plural% for comments', 'mycred') : __('%plural% for Disqus comments', 'mycred'), 'description' => __('Award %_plural% for making comments.', 'mycred'), 'callback' => array('myCRED_Hook_Comments')); // Link Clicks $installed['link_click'] = array('title' => __('%plural% for clicking on links', 'mycred'), 'description' => __('Award %_plural% to users who clicks on links generated by the [mycred_link] shortcode.', 'mycred'), 'callback' => array('myCRED_Hook_Click_Links')); // Video Views $installed['video_view'] = array('title' => __('%plural% for viewing Videos', 'mycred'), 'description' => __('Award %_plural% to users who watches videos embedded using the [mycred_video] shortcode.', 'mycred'), 'callback' => array('myCRED_Hook_Video_Views')); // Affiliation $installed['affiliate'] = array('title' => __('%plural% for referrals', 'mycred'), 'description' => __('Award %_plural% to users who refer either visitors and/or new member signups.', 'mycred'), 'callback' => array('myCRED_Hook_Affiliate')); $installed = apply_filters('mycred_setup_hooks', $installed, $this->mycred_type); if ($save === true && $this->core->can_edit_plugin()) { $new_data = array('active' => $this->active, 'installed' => $installed, 'hook_prefs' => $this->hook_prefs); mycred_update_option($this->option_id, $new_data); } $this->installed = $installed; return $installed; }
/** * Save * Saves the given preference id for rates. * from the active list. * @since 1.2 * @version 1.1 */ public function save($id, $now) { if (!isset($this->prefs[$id])) { return; } $this->prefs[$id] = $now; // Get Bank settings $bank = mycred_get_option('mycred_pref_bank'); // Update settings $bank['service_prefs'][$this->id] = $this->prefs; // Save new settings mycred_update_option('mycred_pref_bank', $bank); }
/** * Process Setup Steps * @since 0.1 * @version 1.0 */ public function process_choices() { // Make sure that if we are re-loading the setup page we do not execute again $singular = get_option('mycred_temp_singular'); if ($singular == $this->step) { return; } $step = $this->step; $settings = $this->core; $ok = false; // Save step 1 formats. if ($step == 1) { $ok = true; } elseif ($step == 2) { $settings['cred_id'] = 'mycred_default'; // Decimals $settings['format']['decimals'] = (int) sanitize_text_field($_POST['myCRED-format-dec']); if (empty($settings['format']['decimals'])) { $settings['format']['decimals'] = 0; } // Separators $settings['format']['separators']['decimal'] = $_POST['myCRED-sep-dec']; $settings['format']['separators']['thousand'] = $_POST['myCRED-sep-tho']; // DB Format if ($settings['format']['decimals'] > 0) { $settings['format']['type'] = 'decimal'; } else { $settings['format']['type'] = 'bigint'; } // Install database if (!function_exists('mycred_install_log')) { require_once myCRED_INCLUDES_DIR . 'mycred-functions.php'; } mycred_install_log($settings['format']['decimals'], $this->log_table); // Name $settings['name']['singular'] = sanitize_text_field($_POST['myCRED-name-singular']); $settings['name']['plural'] = sanitize_text_field($_POST['myCRED-name-plural']); // Prefix & Suffix $settings['before'] = sanitize_text_field($_POST['myCRED-prefix']); $settings['after'] = sanitize_text_field($_POST['myCRED-suffix']); update_option('mycred_pref_core', $settings); $this->core = $settings; $ok = true; } elseif ($step == 3) { // Capabilities $settings['caps']['plugin'] = isset($_POST['myCRED-cap-plugin']) ? trim($_POST['myCRED-cap-plugin']) : 'manage_options'; $settings['caps']['creds'] = isset($_POST['myCRED-cap-creds']) ? trim($_POST['myCRED-cap-creds']) : 'export'; $settings['max'] = isset($_POST['myCRED-max']) ? trim($_POST['myCRED-max']) : 0; // Excludes $settings['exclude']['plugin_editors'] = isset($_POST['myCRED-exclude-plugin-editors']) ? true : false; $settings['exclude']['cred_editors'] = isset($_POST['myCRED-exclude-cred-editors']) ? true : false; $settings['exclude']['list'] = sanitize_text_field($_POST['myCRED-exclude-list']); if (isset($_POST['myCRED-delete-user'])) { $settings['delete_user'] = sanitize_text_field($_POST['myCRED-delete-user']); } else { $settings['delete_user'] = 0; } // Save mycred_update_option('mycred_pref_core', $settings); $this->core = $settings; $ok = true; } if ($ok) { update_option('mycred_temp_singular', $step); } }
function mycred_update_to_onesix($version = NULL) { if ($version === NULL) { return; } // 1.6 Update if (version_compare($version, '1.6', '<')) { global $wpdb; $types = mycred_get_types(); // Remove Login hook markers if (count($types) == 1) { $wpdb->delete($wpdb->usermeta, array('meta_key' => 'mycred_last_login'), array('%s')); } else { foreach ($types as $type_id => $label) { $wpdb->delete($wpdb->usermeta, array('meta_key' => 'mycred_last_login_' . $type_id), array('%s')); } } // Update email notices to support multiple point types if (class_exists('myCRED_Email_Notice_Module')) { $notices = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'mycred_email_notice' AND post_status != 'trash';"); if (!empty($notices)) { foreach ($notices as $notice_id) { update_post_meta((int) $notice_id, 'mycred_email_ctype', 'all'); } } } // Update ranks to support multiple point types if (class_exists('myCRED_Ranks_Module')) { $ranks = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'mycred_rank' AND post_status != 'trash';"); if (!empty($ranks)) { foreach ($ranks as $rank_id) { update_post_meta((int) $rank_id, 'ctype', 'mycred_default'); } } } } elseif (version_compare($version, '1.6.7', '<')) { $addons = mycred_get_option('mycred_pref_addons'); $addons = maybe_unserialize($addons); // Remove built-in add-ons Paths. if (!empty($addons['installed'])) { foreach ($addons['installed'] as $id => $info) { $addons['installed'][$id]['path'] = str_replace(myCRED_ADDONS_DIR, '', $info['path']); } mycred_update_option('mycred_pref_addons', $addons); } } // Update complted update_option('mycred_version', myCRED_VERSION); }
/** * 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; } } } } }
/** * Get Bank Services * @since 1.2 * @version 1.0 */ public function get($save = false) { // Savings $services['central'] = array('title' => __('Central Banking', 'mycred'), 'description' => __('Instead of creating %_plural% out of thin-air, all payouts are made from a nominated "Central Bank" account. Any %_plural% a user spends or loses are deposited back into this account.', 'mycred'), 'callback' => array('myCRED_Banking_Service_Central')); // Interest $services['interest'] = array('title' => __('Compound Interest', 'mycred'), 'description' => __('Apply a positive or negative interest rate on your users %_plural% balances.', 'mycred'), 'callback' => array('myCRED_Banking_Service_Interest')); // Inflation $services['payouts'] = array('title' => __('Recurring Payouts', 'mycred'), 'description' => __('Setup mass %_singular% payouts for your users.', 'mycred'), 'callback' => array('myCRED_Banking_Service_Payouts')); $services = apply_filters('mycred_setup_banking', $services); if ($save === true && $this->core->can_edit_plugin()) { $new_data = array('active' => $this->active, 'services' => $services, 'service_prefs' => $this->service_prefs); mycred_update_option($this->option_id, $new_data); } $this->services = $services; return $services; }
/** * 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; }
/** * Get Addons * @since 0.1 * @version 1.5 */ public function get($save = false) { $installed = array(); // Badges Add-on $installed['badges'] = array('name' => 'Badges', 'description' => __('Give your users badges based on their interaction with your website.', 'mycred'), 'addon_url' => 'http://mycred.me/add-ons/badges/', 'version' => '1.1', 'author' => 'Gabriel S Merovingi', 'author_url' => 'http://www.merovingi.com', 'path' => myCRED_ADDONS_DIR . 'badges/myCRED-addon-badges.php'); // Banking Add-on $installed['banking'] = array('name' => 'Banking', 'description' => __('Setup recurring payouts or offer / charge interest on user account balances.', 'mycred'), 'addon_url' => 'http://mycred.me/add-ons/banking/', 'version' => '1.2', 'author' => 'Gabriel S Merovingi', 'author_url' => 'http://www.merovingi.com', 'path' => myCRED_ADDONS_DIR . 'banking/myCRED-addon-banking.php'); // buyCRED Add-on $installed['buy-creds'] = array('name' => 'buyCRED', 'description' => __('The <strong>buy</strong>CRED Add-on allows your users to buy points using PayPal, Skrill (Moneybookers) or NETbilling. <strong>buy</strong>CRED can also let your users buy points for other members.', 'mycred'), 'addon_url' => 'http://mycred.me/add-ons/buycred/', 'version' => '1.4.1', 'author' => 'Gabriel S Merovingi', 'author_url' => 'http://www.merovingi.com', 'path' => myCRED_ADDONS_DIR . 'buy-creds/myCRED-addon-buy-creds.php'); // Coupons Add-on $installed['coupons'] = array('name' => 'Coupons', 'description' => __('The coupons add-on allows you to create coupons that users can use to add points to their accounts.', 'mycred'), 'addon_url' => 'http://mycred.me/add-ons/coupons/', 'version' => '1.1', 'author' => 'Gabriel S Merovingi', 'author_url' => 'http://www.merovingi.com', 'path' => myCRED_ADDONS_DIR . 'coupons/myCRED-addon-coupons.php'); // Email Notices Add-on $installed['email-notices'] = array('name' => 'Email Notices', 'description' => __('Create email notices for any type of myCRED instance.', 'mycred'), 'addon_url' => 'http://mycred.me/add-ons/email-notices/', 'version' => '1.3', 'author' => 'Gabriel S Merovingi', 'author_url' => 'http://www.merovingi.com', 'path' => myCRED_ADDONS_DIR . 'email-notices/myCRED-addon-email-notices.php'); // Gateway Add-on $installed['gateway'] = array('name' => 'Gateway', 'description' => __('Let your users pay using their <strong>my</strong>CRED points balance. Supported Carts: WooCommerce, MarketPress and WP E-Commerce. Supported Event Bookings: Event Espresso and Events Manager (free & pro).', 'mycred'), 'addon_url' => 'http://mycred.me/add-ons/gateway/', 'version' => '1.4', 'author' => 'Gabriel S Merovingi', 'author_url' => 'http://www.merovingi.com', 'path' => myCRED_ADDONS_DIR . 'gateway/myCRED-addon-gateway.php'); // Notifications Add-on $installed['notifications'] = array('name' => 'Notifications', 'description' => __('Create pop-up notifications for when users gain or loose points.', 'mycred'), 'addon_url' => 'http://mycred.me/add-ons/notifications/', 'version' => '1.1', 'author' => 'Gabriel S Merovingi', 'author_url' => 'http://www.merovingi.com', 'path' => myCRED_ADDONS_DIR . 'notifications/myCRED-addon-notifications.php', 'pro_url' => 'http://mycred.me/store/notifications-plus-add-on/'); // Ranks Add-on $installed['ranks'] = array('name' => 'Ranks', 'description' => __('Create ranks for users reaching a certain number of %_plural% with the option to add logos for each rank.', 'mycred'), 'addon_url' => 'http://mycred.me/add-ons/ranks/', 'version' => '1.4.1', 'author' => 'Gabriel S Merovingi', 'author_url' => 'http://www.merovingi.com', 'path' => myCRED_ADDONS_DIR . 'ranks/myCRED-addon-ranks.php'); // Sell Content Add-on $installed['sell-content'] = array('name' => 'Sell Content', 'description' => __('This add-on allows you to sell posts, pages or any public post types on your website. You can either sell the entire content or using our shortcode, sell parts of your content allowing you to offer "teasers".', 'mycred'), 'addon_url' => 'http://mycred.me/add-ons/sell-content/', 'version' => '1.4', 'author' => 'Gabriel S Merovingi', 'author_url' => 'http://www.merovingi.com', 'path' => myCRED_ADDONS_DIR . 'sell-content/myCRED-addon-sell-content.php'); // Statistics Add-on $installed['stats'] = array('name' => 'Statistics', 'description' => __('Gives you access to your myCRED Staticstics based on your users gains and loses.', 'mycred'), 'addon_url' => 'http://mycred.me/add-ons/stats/', 'version' => '1.0', 'author' => 'Gabriel S Merovingi', 'author_url' => 'http://www.merovingi.com', 'path' => myCRED_ADDONS_DIR . 'stats/myCRED-addon-stats.php'); // Transfer Add-on $installed['transfer'] = array('name' => 'Transfers', 'description' => __('Allow your users to send or "donate" points to other members by either using the mycred_transfer shortcode or the myCRED Transfer widget.', 'mycred'), 'addon_url' => 'http://mycred.me/add-ons/transfer/', 'version' => '1.2', 'author' => 'Gabriel S Merovingi', 'author_url' => 'http://www.merovingi.com', 'path' => myCRED_ADDONS_DIR . 'transfer/myCRED-addon-transfer.php'); $installed = apply_filters('mycred_setup_addons', $installed); if ($save === true && $this->core->can_edit_plugin()) { $new_data = array('active' => $this->active, 'installed' => $installed); mycred_update_option('mycred_pref_addons', $new_data); } $this->installed = $installed; return $installed; }
/** * 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; } } }
/** * Update Cycles * @since 1.5.2 * @version 1.0 */ public function update_cycles() { // Manage cycles if it's not set to unlimited if ($this->prefs['cycles'] != '-1' && $this->prefs['cycles'] != 0) { // Prep option id for this addon. $option_id = 'mycred_pref_bank'; if (!$this->is_main_type) { $option_id .= '_' . $this->mycred_type; } // Get addon settings $addon = mycred_get_option($option_id); // Deduct cycle $current_cycle = (int) $this->prefs['cycles']; $current_cycle--; $addon['service_prefs'][$this->id]['cycles'] = $current_cycle; // If we reach zero, disable this service if ($current_cycle == 0 && in_array($this->id, $addon['active'])) { $new_active = array(); foreach ($addon['active'] as $active) { if ($active == $this->id || in_array($active, $new_active)) { continue; } $new_active[] = $active; } $addon['active'] = $new_active; } // Update settings mycred_update_option($option_id, $addon); } }
/** * Save Last Run * @since 1.5.2 * @version 1.0 */ public function save_last_run($instance = '', $time = NULL) { if ($time === NULL) { $time = date_i18n('U'); } mycred_update_option('mycred_banking_' . $this->id . '_' . $instance . $this->mycred_type, $time); }
/** * Get Bank Services * @since 1.2 * @version 1.0 */ public function get($save = false) { // Savings $services['interest'] = array('title' => __('Compound Interest', 'mycred'), 'description' => __('Apply an interest rate on your users %_plural% balances. Interest rate is annual and is compounded daily as long as this service is enabled. Positive interest rate leads to users gaining %_plural% while a negative interest rate will to users loosing %_plural%.', 'mycred'), 'callback' => array('myCRED_Banking_Service_Interest')); // Inflation $services['payouts'] = array('title' => __('Recurring Payouts', 'mycred'), 'description' => __('Give your users %_plural% on a regular basis with the option to set the number of times you want this payout to run (cycles).', 'mycred'), 'callback' => array('myCRED_Banking_Service_Payouts')); $services = apply_filters('mycred_setup_banking', $services); if ($save === true && $this->core->can_edit_plugin()) { mycred_update_option('mycred_pref_bank', array('active' => $this->active, 'services' => $services, 'service_prefs' => $this->service_prefs)); } $this->services = $services; return $services; }
function mycred_render_shortcode_total_points($atts) { extract(shortcode_atts(array('type' => 'mycred_default', 'ref' => '', 'ref_id' => '', 'user_id' => '', 'formatted' => 1), $atts)); $types = mycred_get_types(); if (!array_key_exists($type, $types)) { $type = 'mycred_default'; } // First we construct the meta_key $point_type = $type; if (is_multisite() && $GLOBALS['blog_id'] > 1 && !mycred_centralize_log()) { $type .= '_' . $GLOBALS['blog_id']; } elseif (is_multisite() && $GLOBALS['blog_id'] > 1 && !mycred_override_settings()) { $type .= '_' . $GLOBALS['blog_id']; } $mycred = mycred($point_type); global $wpdb; // Simple if ($ref == '' && $ref_id == '' && $user_id == '') { // Check if cached value exists $total = mycred_get_option('mycred-cache-total-' . $point_type, false); if ($total === false) { // Add up all balances $total = $wpdb->get_var($wpdb->prepare("SELECT SUM( meta_value ) FROM {$wpdb->usermeta} WHERE meta_key = %s", $type)); if ($total !== NULL) { mycred_update_option('mycred-cache-total-' . $point_type, $total); } } } else { $wheres = array(); $wheres[] = $wpdb->prepare("ctype = %s", $point_type); $ref = sanitize_key($ref); if (strlen($ref) > 0) { // Either we have just one reference $multiple = explode(',', $ref); if (count($multiple) == 1) { $wheres[] = $wpdb->prepare("ref = %s", $ref); } else { $_clean = array(); foreach ($multiple as $ref) { $ref = sanitize_key($ref); if (strlen($ref) > 0) { $_clean[] = $ref; } } if (!empty($_clean)) { $wheres[] = "ref IN ( '" . implode("', '", $_clean) . "' )"; } } } $ref_id = sanitize_text_field($ref); if (strlen($ref_id) > 0) { $wheres[] = $wpdb->prepare("ref_id = %d", $ref_id); } $user_id = sanitize_text_field($ref); if (strlen($user_id) > 0) { $wheres[] = $wpdb->prepare("user_id = %d", $user_id); } $wheres = implode(" AND ", $wheres); $total = $wpdb->get_var("SELECT SUM( creds ) FROM {$mycred->log_table} WHERE {$wheres};"); } if ($total === NULL) { $total = 0; } if ($formatted == 1) { return $mycred->format_creds($total); } return $total; }
/** * Reset Key */ public function reset_key() { $skey = wp_generate_password(16, true, true); mycred_update_option('mycred_key', $skey); $this->skey = $skey; }