This function allows you to decrease a users balance by deducting a specific amount from it. This function uses mycred_add to adjust the balance but forces any value you provide to be a negative value.
(bool) true
on success or false
on declined transaction.
Param | Type | Required | Description | |
---|---|---|---|---|
function mycred_subtract( |
||||
$reference |
string | Yes | The reference to log this entry under. You can use your own custom reference or one of the built-in ones. |
|
$user_id |
int | Yes | The users numeric ID. |
|
$amount |
int or float | Yes | The point amount to deduct from the user. Positive values will be turned negative. |
|
$entry |
string | Yes | The entry to save in the log for this adjustment. |
|
$ref_id |
int | No | Optional reference ID to save with the log entry. |
|
$data |
string | No | Optional data to save with the log entry. Note that if you are supply an array, this will be serialized. |
|
$type |
string | No | The point type key. Should only be used if you are adjusting a custom point type and not the default one. |
|
) { ... } |
Example 1: Deduct 10 points from a user.
$user_id = get_current_user_id(); mycred_subtract( 'penalty', $user_id, -10, 'Points penalty' );