

Yaw Pereko

function abibitumi_get_user_points_in_period( $user_id, $days ) { global $wpdb; if ( ! function_exists( 'gamipress_get_points_types' ) ) { error_log( 'GamiPress not active for user ' . $user_id ); return 0; } $total_points = 0; $time_limit = date( 'Y-m-d H:i:s', strtotime( "-{$days} days" ) ); // Get all registered GamiPress point types $all_gamipress_point_types = gamipress_get_points_types(); // Loop through them, or explicitly define the one you need // For Abibisika points, assuming its slug is 'abibisika' (check GamiPress > Points Types) $point_types_to_sum = array(); foreach ( $all_gamipress_point_types as $slug => $data ) { // If your Abibisika points slug is 'abibisika', add it to the list if ( $slug === 'abibisika' ) { // <--- **VERIFY THIS SLUG** $point_types_to_sum[] = $slug; } // If you want to sum ALL point types, you can remove the if condition above // and just add all slugs: $point_types_to_sum[] = $slug; } foreach ( $point_types_to_sum as $point_type_slug ) { $db_post_type = 'points-' . $point_type_slug; // This is the format GamiPress uses in the database $sql = $wpdb->prepare( " SELECT SUM(meta_value) FROM {$wpdb->prefix}gamipress_user_earnings WHERE user_id = %d AND post_type = %s AND date >= %s ", $user_id, $db_post_type, $time_limit ); // error_log( 'SQL Query for ' . $db_post_type . ': ' . $sql ); // Debug: show query $results = $wpdb->get_var( $sql ); // error_log( 'Results for ' . $db_post_type . ': ' . print_r( $results, true ) ); // Debug: show results $total_points += (int) $results; } // error_log( 'Total points for user ' . $user_id . ': ' . $total_points ); // Debug: show final total return $total_points; }
Please confirm you want to block this member.
You will no longer be able to:
Please note: This action will also remove this member from your connections and send a report to the site admin. Please allow a few minutes for this process to complete.