By default, GamiPress just will award an achievement or a rank to the user that meets all requirements (sequentially or not, depending of its configuration).
A desired workflow on some gamification environments is the ability to allow users to earn an achievement or rank if they complete a simple requirement of the list of requirements.
Enabling OR steps for achievements
With the following snippet, you will enable the “OR steps” to the achievement you want:
function my_prefix_award_achievement_if_any_step_completed( $user_id = 0, $step_id = 0 ) {
// Achievement IDs you want to allow to be earned by completing just one of their steps
$achievement_ids = array( 123, 456, 789 );
if( get_post_type( $step_id ) === 'step' ) {
$achievement = gamipress_get_step_achievement( $step_id );
// Check if user has not been already earned this achievement
if( in_array( $achievement->ID, $achievement_ids ) && ! gamipress_has_user_earned_achievement( $achievement->ID, $user_id ) ) {
// Award the achievement to the user
gamipress_award_achievement_to_user( $achievement->ID, $user_id );
}
}
}
add_action( 'gamipress_award_achievement', 'my_prefix_award_achievement_if_any_step_completed', 10, 2 );
Enabling OR requirements for ranks
There is a similar snippet to the previous one but focused to enable the “OR requirements” to a specific rank:
function my_prefix_award_rank_if_any_requirement_completed( $user_id = 0, $requirement_id = 0 ) {
// Rank IDs you want to allow to be earned by completing just one of their requirements
$rank_id = array( 123, 456, 789 );
if( get_post_type( $requirement_id ) === 'rank-requirement' ) {
$rank = gamipress_get_rank_requirement_rank( $requirement_id );
// Check if user has not been already earned this rank
if( in_array( $rank->ID, $rank_ids ) && ! gamipress_has_user_earned_rank( $rank->ID, $user_id ) ) {
// Award the rank to the user
gamipress_award_rank_to_user( $rank->ID, $user_id );
}
}
}
add_action( 'gamipress_award_achievement', 'my_prefix_award_rank_if_any_requirement_completed', 10, 2 );