1. Customize
  2. Customizations
  3. Support quests visits on “Get visits on a post” event

Support quests visits on “Get visits on a post” event

GamiPress includes the “Get visits on a post” and “Get visits on a specific post” events that allows you to award a post author for receive a visit but, by default, the GamiPress awards engine only starts with logged in users which makes that “guests visitors” don’t trigger those events.

The following code snippet adds a new check when a post receives a guest visit to trigger this event:

function my_prefix_enable_guests_visits() {
    global $post;

    if( is_admin() ) {
        return;
    }

    if( is_user_logged_in() ) {
        return;
    }

    // Trigger get visits on a post
    do_action( 'gamipress_user_post_visit', $post->ID, $post->post_author, 0, $post );

    // Trigger get visits on a specific post
    do_action( 'gamipress_user_specific_post_visit', $post->ID, $post->post_author, 0, $post );
}
add_action( 'template_redirect', 'my_prefix_enable_guests_visits' );

How can we help?