The following example shows how to award an amount of points to an user that logs in to the website the Valentine’s day (February 14th).
function my_prefix_award_users_on_login_on_a_specific_date( $user_login, $user ) {
$points = 100; // Amount of points to award
$points_type = 'credits'; // Points type slug
$date = '2018-02-14'; // Set the specific date in YYYY-MM-DD
$already_awarded = get_user_meta( $user->ID, '_my_prefix_user_awarded_on_' . $date );
if( date('Y-m-d') === $date && ! $already_awarded ) {
// Award the points to the user
gamipress_award_points_to_user( $user->ID, $points, $points_type );
// Store this award to prevent award it again
update_user_meta( $user->ID, '_my_prefix_user_awarded_on_' . $date, 1 );
}
}
add_action( 'wp_login', 'my_prefix_award_users_on_login_on_a_specific_date', 10, 2 );
Additional Notes
On the above snippet user is awarded with points, but if you want to award an achievement, you can use the function gamipress_award_achievement_to_user( $achievement_id, $user_id )
.
Also, If you want to award a rank, you can use the function gamipress_award_rank_to_user( $rank_id, $user_id )
.
In addition you can change the date check into a more dynamic way, like award this all years or all months using the PHP date()
function like in the next example:
// Make date matches the February 14th of all years
$date = date('Y') . '-02-14';
// Make date matches the 14th of all months of all years
$date = date('Y-m') . '-14';