mycred_badge_level_reached
Description
This function checks if a user has reached the badge requirements set for a given badge. If the requirements have been met, the function will return the level they should have. This function does not assign the badge to the user, it only checks if there should be one.
This function is only available if the Badges add-on is enabled.
Available since version 1.7
Returns
(bool | int) FALSE
if the user has not earned the badge yet or if incorrect parameters are provided. If the badge is earned, the badges level is returned instead.
Parameters
Param | Type | Required | Description | |
---|---|---|---|---|
function mycred_badge_level_reached( |
||||
$user_id |
int | Yes | The users numeric ID. |
|
$badge_id |
int | Yes | The badge post object ID. |
|
) { ... } |
Examples
Example 1: Check if the current user has reached level 4 of a badge.
$badge_id = 1; $user_id = get_current_user_id(); $level_requirement = 4; $level_reached = mycred_badge_level_reached( $user_id, $badge_id ); if ( $level_reached !== false && $level_reached >= $level_requirement ) { // User has earned the badge and is on level 4 or higher }