goyorondon
Forum Replies Created
-
Forum: Plugins
In reply to: [Football Pool] Dynamic Timezone in the Matches SectionReady @antoineh Thanks!
Forum: Plugins
In reply to: [Football Pool] Dynamic Timezone in the Matches SectionMy friend, I have created this to handle multiple schedules regardless of the country.
<?php
/*
Plugin Name: Football Pool Timezone Extension
Description: Extends the Football Pool plugin functionality to display match times in the user’s local timezone.
Version: 1.0
Author: Your Name
*/// Global variables for caching
$user_timezone = null;
$user_country = null;// Function to get the user’s timezone (with caching)
function get_user_timezone()
{
global $user_timezone;
if ($user_timezone === null) {
// This function requires the userip_location plugin
$timezone = do_shortcode(‘[userip_location type=”timezone”]’);
$user_timezone = empty($timezone) ? wp_timezone_string() : $timezone;
}
return $user_timezone;
}// Function to get the user’s country name (with caching)
function get_user_country()
{
global $user_country;
if ($user_country === null) {
// This function requires the userip_location plugin
$country = do_shortcode(‘[userip_location type=”country”]’);
$user_country = empty($country) ? ‘Local’ : $country;
}
return $user_country;
}// Function to add local time to match schedules
function add_local_time_to_matches($match_template_params)
{
static $user_timezone = null;if ($user_timezone === null) { $user_timezone = new DateTimeZone(get_user_timezone()); } if (isset($match_template_params['match_utcdate'])) { $utc_time = new DateTime($match_template_params['match_utcdate'], new DateTimeZone('UTC')); $local_time = clone $utc_time; $local_time->setTimezone($user_timezone); // Changed to 12-hour format with AM/PM $utc_time_formatted = $utc_time->format('h:i A'); $local_time_formatted = $local_time->format('h:i A'); $country_name = get_user_country(); $date_changed = $utc_time->format('d/m') !== $local_time->format('d/m'); $match_template_params['match_time'] = sprintf('%s %s Time<br> <span style="font-size:12px">%s UTC</span>', $local_time_formatted, $country_name, $utc_time_formatted); if ($date_changed) { $match_template_params['match_datetime_formatted'] = $local_time->format('d/m/Y'); $match_template_params['match_time'] .= '*'; } } return $match_template_params;
}
// Add hook to modify match template parameters
add_filter(‘footballpool_predictionform_match_template_params’, ‘add_local_time_to_matches’, 10, 1);
add_filter(‘footballpool_match_table_match_template_params’, ‘add_local_time_to_matches’, 10, 1);// Function to add an explanatory note about date changes
function add_date_change_note($content)
{
return $content . ‘<small>* Indicates that the local date is different due to timezone.</small>’;
}
add_filter(‘footballpool_predictionform_matches_html’, ‘add_date_change_note’);// Modify the match template to include the timestamp
function modify_match_template($template)
{
return str_replace(‘<div id=”match-%match_id%-%form_id%”‘, ‘<div id=”match-%match_id%-%form_id%” data-match-timestamp=”%match_timestamp%”‘, $template);
}
add_filter(‘footballpool_predictionform_match_template’, ‘modify_match_template’);- This reply was modified 4 months, 1 week ago by goyorondon.
Forum: Plugins
In reply to: [Football Pool] Penalties@antoineh What do you think is the best way to do it? I would love to collaborate because I feel very grateful with everything I got with the free plugin.
I mean if we had to make the adaptation to penalties, would it be an extension of the plugin or inside it?