mycred_user_can_transfer
Description
This function checks if a user can afford or allowed to make a transfer, of a specified amount of points. The function will check to make sure:
- A users balance does not go below zero if the transaction would be approved. You can use the mycred_transfer_limit filter to adjust this and allow transfers that would bring a users balance into the negative.
- The transfer is within the users limit (if limits are enforced).
This function is only available if the Transfer add-on is enabled.
Available since version 1.0
Returns
(int | float | string) Returns TRUE
if the user can make a transfer and there is no transfer limit set. If a limit is set but the user can make the transfer, the function will return the amount remaining. Else returns an error code.
Error Codes
Error Code | Description |
---|---|
low |
The user can not afford to transfer the given amount or the users balance has reached zero. |
limit |
The set limit has been reached. |
Parameters
Param | Type | Required | Description | |
---|---|---|---|---|
function mycred_user_can_transfer( |
||||
$user_id |
int | Yes | The users numeric ID. |
|
$amount |
int or float | No | Optional amount that the user is requesting to transfer. If not set the users current balance is used to check for solvency. |
|
$point_type |
string | No | The point type key used for this transfer. Defaults to the default point type. |
|
$reference |
string | No | Optional reference to check for limits. This should only be used when a limit is being enforced. |
|
) { ... } |
Examples
Example 1: Check if the current user can make a 10 point transfer.
$user_id = get_current_user_id(); if ( mycred_user_can_transfer( $user_id, 10 ) ) { // User can transfer }