mycred_find_users_rank
Description
This function will attempt to find a given users rank of a specific point type. This function can be used to just query which rank a user should have or also save this rank.
This function is only available if the Ranks add-on is enabled.
Available since version 1.1
Returns
(object | bool) Returns either FALSE
if no rank was found or an object containing the users current rank, the rank they should have and the ranks requirements.
Object example:
Std Object ( [rank_id] => 1 // The rank post object ID a user should have [minimum] => 0 // The ranks minimum point requirement [maximum] => 999 // The ranks maximum point requirement [current_id] => 1 // The rank post object ID the user currently has assigned )
Parameters
Param | Type | Required | Description | |
---|---|---|---|---|
function mycred_find_users_rank( |
||||
$user_id |
int | Yes | The users numeric ID. |
|
$point_type |
string | No | The point type key. |
|
$act |
bool | No |
|
|
) { ... } |
Examples
Example 1: Check what rank a user should have without saving the results.
$user_id = get_current_user_id(); $rank = mycred_find_users_rank( $user_id, 'mycred_default', false ); if ( $rank === false && $rank->rank_id !== $rank->current_id ) { // The user should have a new rank }