/** * Email Notice Check * @since 1.4.6 * @version 1.1 */ public function get_events_from_instance($request, $mycred) { extract($request); $events = array('general|all'); // Events based on amount being given or taken if ($amount < $mycred->zero()) { $events[] = 'general|negative'; } else { $events[] = 'general|positive'; } // Events based on this transaction leading to the users balance // reaching or surpassing zero $users_current_balance = $mycred->get_users_balance($user_id, $type); if ($users_current_balance - $amount < $mycred->zero()) { $events[] = 'general|minus'; } elseif ($users_current_balance - $amount == $mycred->zero()) { $events[] = 'general|zero'; } // Ranks Related if (function_exists('mycred_get_users_rank')) { $rank_id = mycred_find_users_rank($user_id, false, $type); if ($rank_id !== NULL && mycred_user_got_demoted($user_id, $rank_id)) { $events[] = 'ranks|negative'; } elseif ($rank_id !== NULL && mycred_user_got_promoted($user_id, $rank_id)) { $events[] = 'ranks|positive'; } } // Let others play return apply_filters('mycred_get_email_events', $events, $request, $mycred); }
function mycred_get_users_rank_id($user_id = NULL, $type = 'mycred_default') { $end = ''; if ($type != 'mycred_default') { $end = $type; } $rank_id = mycred_get_user_meta($user_id, 'mycred_rank', $end, true); if ($rank_id == '') { $rank_id = mycred_find_users_rank($user_id, true, $type); } return $rank_id; }
/** * AJAX: Calculate Totals * @since 1.2 * @version 1.2 */ public function calculate_totals() { // Security check_ajax_referer('mycred-calc-totals', 'token'); global $wpdb; $users = $wpdb->get_results(apply_filters('mycred_ranks_calc_total', $wpdb->prepare("\n\t\t\tSELECT user_id AS ID, SUM( CASE WHEN creds > 0 OR ( creds < 0 AND ref = %s ) THEN creds ELSE 0 END ) as total\n\t\t\tFROM {$this->core->log_table} \n\t\t\tGROUP BY user_id;", 'manual'), $this)); // Get total key $total_key = 'mycred_default'; if ($this->core->is_multisite && $GLOBALS['blog_id'] > 1 && !$this->core->use_central_logging) { $total_key .= '_' . $GLOBALS['blog_id']; // Clean up old & incorrect keys $wpdb->delete($wpdb->usermeta, array('meta_key' => $total_key . '_total'), array('%s')); $wpdb->delete($wpdb->usermeta, array('meta_key' => 'mycred_default' . $GLOBALS['blog_id']), array('%s')); $wpdb->delete($wpdb->usermeta, array('meta_key' => 'mycred_default_' . $GLOBALS['blog_id'] . '_' . $GLOBALS['blog_id']), array('%s')); } $total_key .= '_total'; // Clean up old keys $wpdb->delete($wpdb->usermeta, array('meta_key' => $total_key), array('%s')); $total_key = apply_filters('mycred_ranks_total_key', $total_key, $this); $count = 0; if ($users) { foreach ($users as $user) { if ($user->total == 0) { continue; } mycred_update_user_meta($user->ID, 'mycred_default', '_total', $user->total); mycred_find_users_rank($user->ID, true, 0); $count = $count + 1; } } if ($count > 0) { die(json_encode(sprintf(__('Completed - Total of %d users effected', 'mycred'), $count))); } else { die(json_encode(__('Log is Empty', 'mycred'))); } }
/** * Balance Adjustment * Check if users rank should change. * @since 1.1 * @version 1.4 */ public function balance_adjustment($result, $request, $mycred) { // If the result was declined if ($result === false) { return $result; } // If ranks for this type is based on total and this is not a admin adjustment if (mycred_rank_based_on_total($request['type']) && $request['amount'] < 0 && $request['ref'] != 'manual') { return $result; } // Find users rank mycred_find_users_rank((int) $request['user_id'], true, $request['type']); return $result; }
function mycred_get_users_rank($user_id = NULL, $return = 'post_title', $logo_size = 'post-thumbnail', $attr = NULL) { // User ID is required if ($user_id === NULL) { return __('mycred_get_users_rank() : Missing required user id', 'mycred'); } // Get users rank $rank_id = mycred_get_user_meta($user_id, 'mycred_rank', '', true); // If empty, get the users rank now and save it if ($rank_id == '') { $rank_id = mycred_find_users_rank($user_id, true); } $reply = __('no rank', 'mycred'); // Have rank if ($rank_id != '' && $rank_id !== NULL) { // If we want to see the logo if ($return == 'logo') { $reply = mycred_get_rank_logo((int) $rank_id, $logo_size, $attr); } else { // Not using master template if (!mycred_override_settings()) { $rank = get_post((int) $rank_id); } else { $original_blog_id = get_current_blog_id(); switch_to_blog(1); $rank = get_post((int) $rank_id); switch_to_blog($original_blog_id); } // If the requested detail exists, return it if (isset($rank->{$return})) { $reply = $rank->{$return}; } } } return apply_filters('mycred_get_users_rank', $reply, $user_id, $return, $logo_size); }