• Resolved rebornishard

    (@rebornishard)


    Is that possible to give user poin on special day (valentine, newyear) and birthday ?

    thanks

Viewing 1 replies (of 1 total)
  • Plugin Author Ruben Garcia

    (@rubengc)

    Hi @rebornishard

    At this moment this is not possible to do without custom code

    But there is a small snippet where you can award points to your users that logs in on a specific date:

    // Example of award points to all users on a specific date
    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 );

    If you want to award to all users on a specific date, there is another snippet:

    // Example of award points to all users on a specific date
    function my_prefix_award_users_on_a_specific_date() {
    
        $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
    
        global $wpdb;
    
        $already_awarded = get_option( 'my_prefix_user_awarded_on_' . $date );
    
        if( ! $already_awarded ) {
    
            // Get all users stored
            $users = $wpdb->get_results( "SELECT ID FROM {$wpdb->users}" );
    
            foreach( $users as $user ) {
                // Award the points to the user
                gamipress_award_points_to_user( $user->ID, $points, $points_type );
            }
    
            update_option( 'my_prefix_user_awarded_on_' . $date, 1 );
        }
    
    }
    add_action( 'init', 'my_prefix_award_users_on_a_specific_date' );

    Just place the snippet codes on your theme functions.php, or if you do not know exactly how to do this, you can use a plugin like My Custom Functions:
    https://www.ads-software.com/plugins/my-custom-functions/

    I will mark this topic as resolved since it is not a feature that will be added to GamiPress

    Best regards

Viewing 1 replies (of 1 total)
  • The topic ‘Custom Point on Event’ is closed to new replies.