mycred_subtract

Description

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.

 

As of version 1.7, this function will return false if the user is set to be excluded. In previous version, this is ignored.

Available since version 1.0

Returns

(bool) true on success or false on declined transaction.

Parameters

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.

) { ... }

Examples

Example 1: Deduct 10 points from a user.

$user_id = get_current_user_id();
mycred_subtract( 'penalty', $user_id, -10, 'Points penalty' );