function mycred_user_can_transfer($user_id = NULL, $amount = NULL, $type = 'mycred_default', $ref = NULL) { if ($user_id === NULL) { $user_id = get_current_user_id(); } if ($ref === NULL) { $ref = 'mycred_transactions'; } // Grab Settings (from main type where the settings are saved) $mycred = mycred(); $pref = $mycred->transfers; $zero = $mycred->zero(); // Get users balance $balance = $mycred->get_users_cred($user_id, $type); // Get Transfer Max $max = apply_filters('mycred_transfer_limit', $mycred->number($pref['limit']['amount']), $user_id, $amount, $pref, $mycred); // If an amount is given, deduct this amount to see if the transaction // brings us over the account limit if ($amount !== NULL) { $balance = $mycred->number($balance - $amount); } // Account Limit // The lowest amount a user can have on their account. By default, this // is zero. But you can override this via the mycred_transfer_acc_limit hook. $account_limit = $mycred->number(apply_filters('mycred_transfer_acc_limit', $zero, $type, $user_id, $ref)); // Check if users balance is below the account limit if ($balance < $account_limit) { return 'low'; } // If there are no limits, return the current balance if ($pref['limit']['limit'] == 'none') { return $balance; } // Else we have a limit to impose $now = current_time('timestamp'); $max = $mycred->number($pref['limit']['amount']); // Daily limit if ($pref['limit']['limit'] == 'daily') { $total = mycred_get_total_by_time('today', 'now', $ref, $user_id, $type); } elseif ($pref['limit']['limit'] == 'weekly') { $this_week = mktime(0, 0, 0, date('n', $now), date('j', $now) - date('n', $now) + 1); $total = mycred_get_total_by_time($this_week, 'now', $ref, $user_id, $type); } else { return apply_filters('mycred_user_can_transfer', 'limit', $user_id, $amount, $pref, $mycred); } // We are adding up point deducations. $total = abs($total); if ($amount !== NULL) { $total = $mycred->number($total + $amount); // Transfer limit reached if ($total > $max) { return 'limit'; } } else { // Transfer limit reached if ($total >= $max) { return 'limit'; } } // Return whats remaining of limit return $mycred->number($max - $total); }
/** * New Profile Update * @since 0.1 * @version 1.1 */ public function new_update($content, $user_id, $activity_id) { // Check if user is excluded if ($this->core->exclude_user($user_id)) { return; } // Limit if (isset($this->prefs['update']['daily_limit'])) { $max = $this->prefs['update']['daily_limit']; } else { $max = 2; } if ($max > 0) { $max_earning = $this->core->format_number($max * $this->prefs['update']['creds']); $earned = mycred_get_total_by_time('today', 'now', 'new_profile_update', $user_id, $this->mycred_type); if ($earned >= $max_earning) { return; } } // Make sure this is unique event if ($this->core->has_entry('new_profile_update', $activity_id, $user_id)) { return; } // Execute $this->core->add_creds('new_profile_update', $user_id, $this->prefs['update']['creds'], $this->prefs['update']['log'], $activity_id, 'bp_activity', $this->mycred_type); }