<?php
/**
 * Name: Footer Timezone Display
 * Description: Show current WordPress timezone timestamp in admin footer for quick reference when scheduling posts, managing events, or coordinating content across different time zones
 * Category: Admin
 * Icon: -
 * UseCases: [
 *   {
 *     "title": "Global Team Coordination",
 *     "description": "Remote team across 5 timezones can see local server time displayed in footer to coordinate scheduled posts and maintenance windows."
 *   },
 *   {
 *     "title": "Multi-Region Publishing",
 *     "description": "Content schedulers can verify they're scheduling posts in correct timezone when managing sites for international audiences."
 *   },
 *   {
 *     "title": "Hosting Migration Reference",
 *     "description": "Quickly check server timezone after migrating between hosts to ensure cron jobs and scheduled tasks run at expected times."
 *   }
 * ]
 * Added: 2025-07-12
 * Tags: footer, timezone, time, timestamp, admin
 * WhereToFind: {
 *   "location": "Admin Footer (Bottom of Page)",
 *   "url": "",
 *   "instructions": "When enabled, scroll to the bottom of any admin page to see current server time with timezone displayed in the footer.",
 *   "newTab": false
 * }
 */

// Prevent direct access
if (!defined('ABSPATH')) exit;

class SwitchboardFooterTimezone {
    
    public function __construct() {
        add_filter('admin_footer_text', [$this, 'add_timezone_to_footer'], 20);
    }
    
    public function add_timezone_to_footer($text) {
        $timezone_string = get_option('timezone_string');
        $gmt_offset = get_option('gmt_offset', 0);

        // Get timezone display
        if ($timezone_string) {
            try {
                $timezone_display = $timezone_string;
            } catch (Exception $e) {
                $timezone_display = 'UTC';
            }
        } else {
            $offset_hours = floatval($gmt_offset);
            $timezone_display = 'UTC' . ($offset_hours >= 0 ? '+' : '') . $offset_hours;
        }

        // Get current time in site timezone
        $current_time = current_time('Y-m-d H:i:s');
        
        $timezone_text = sprintf(
            '<span style="margin-left: 15px; padding-left: 15px; border-left: 1px solid #dcdcde;"><span class="dashicons dashicons-clock" style="font-size: 14px; vertical-align: middle; margin-right: 4px;"></span>%s (%s)</span>',
            esc_html($current_time),
            esc_html($timezone_display)
        );
        
        return $text . $timezone_text;
    }

    /**
     * Register data locations for cleanup system
     *
     * @return array
     */
    public function register_data_locations() {
        return [
            'options' => [],
            'option_patterns' => [],
            'tables' => [],
            'post_meta' => [],
            'user_meta' => [],
        ];
    }
}

$switchboard_instance = new SwitchboardFooterTimezone();
Switchboard_Data_Registry::get_instance()->auto_register($switchboard_instance, __FILE__);
