Plugin Extension: Answering questions after the game
-
<?php
/*
Plugin Name: Football Pool Bonus Questions Extension
Description: Extends the Football Pool plugin functionality to manage bonus questions display and timing.
Version: 1.0
Author: Your Name
*/// Function to modify bonus question parameters
function modify_bonus_question_params($params, $question, $nr, $is_user_page)
{
if (isset($params[‘closing_time’])) {
$utc_time = new DateTime($question[‘answer_before_date’], new DateTimeZone(‘UTC’));
$local_time = clone $utc_time;
$local_time->setTimezone(new DateTimeZone(get_user_timezone()));$utc_time_formatted = $utc_time->format('d/M h:i A'); $local_time_formatted = $local_time->format('d/M h:i A'); $country_name = get_user_country(); $date_changed = $utc_time->format('d/m') !== $local_time->format('d/m'); if ($params['state'] === 'open') { $closing_time = sprintf( '<div class="closing-time" title="%s">%s <br>%s <br>%s Time<br><br> <span style="font-size:12px">%s UTC</span></div>', __('answer this question before this date', 'football-pool'), __('answer before', 'football-pool'), $local_time_formatted, $country_name, $utc_time_formatted ); } else { $closing_time = sprintf( '<div class="closing-time" title="%s">%s <br>%s <br>%s Time<br><br> <span style="font-size:12px">%s UTC</span></div>', __("it's no longer possible to answer this question, or change your answer", 'football-pool'), __('closed on', 'football-pool'), $local_time_formatted, $country_name, $utc_time_formatted ); } if ($date_changed) { $closing_time .= '<span class="date-change">*</span>'; } $params['closing_time'] = $closing_time; } return $params;
}
add_filter(‘footballpool_print_bonus_question_params’, ‘modify_bonus_question_params’, 10, 4);
// Function to determine if bonus question should be shown
function should_show_bonus_question($match_timestamp)
{
$current_time = current_time(‘timestamp’);
$show_after = $match_timestamp + (90 * 60); // 90 minutes after match start
return $current_time >= $show_after;
}// Modify the function that generates bonus questions
function modify_bonus_questions($questions, $user_id, $question_ids)
{
global $pool;
$filtered_questions = array();foreach ($questions as $question) { $match_id = $question['match_id']; if ($match_id) { $match_info = $pool->matches->get_match_info($match_id); if (should_show_bonus_question($match_info['match_timestamp'])) { $filtered_questions[] = $question; } } else { // If the question is not associated with a match, we always include it $filtered_questions[] = $question; } } return $filtered_questions;
}
add_filter(‘footballpool_get_bonus_questions_for_user’, ‘modify_bonus_questions’, 10, 3);// Note: This plugin requires the functions get_user_timezone() and get_user_country()
// from the Football Pool Timezone Extension plugin
- The topic ‘Plugin Extension: Answering questions after the game’ is closed to new replies.