Plugin Directory

Changeset 3423987


Ignore:
Timestamp:
12/19/2025 09:43:29 PM (3 months ago)
Author:
manovermachine
Message:

Version 1.3.12: Critical timezone fix for watchdog alerts + time validation

CRITICAL FIX:

  • Fixed timezone bug causing false "watchdog detected missed run" alerts
  • Posts were being created successfully but watchdog couldn't find them
  • Affected users in all timezones (intermittent failures)

THE PROBLEM:

  • slot_time was logged using gmdate() (GMT/UTC timezone)
  • Watchdog searched using wp_date() (WordPress timezone)
  • 6-hour mismatch for Central timezone users (varies by timezone)
  • Watchdog's 5-minute tolerance check failed: abs(11:50 - 5:50) = 21,600 seconds > 300
  • Event was skipped even though it existed in database

WHY IT WAS INTERMITTENT:

  • Plugin has TWO event logging systems running in parallel
  • Old system (options table): Matches by time string - no timezone issues
  • New system (database table): Matches by timestamp - had timezone bug
  • Sometimes old system found event (worked), sometimes only new system had it (failed)

THE SOLUTION:

  • Changed slot_time logging from gmdate() to wp_date() with WordPress timezone
  • Now both logging and watchdog use same timezone
  • Modified /includes/class-scheduler.php line 173-175

BEFORE:

$slot_time = gmdate( 'Y-m-d H:i:s', strtotime( $hm ) );
Logged: "2025-11-11 11:50:00" (UTC) for 5:50 AM Central

AFTER:

$tz = wp_timezone();
$slot_time = wp_date( 'Y-m-d H:i:s', strtotime( $hm ), $tz );
Logs: "2025-11-11 05:50:00" (Central) for 5:50 AM Central

ADDITIONAL ENHANCEMENT:

  • Added time format validation for schedule settings
  • Supports 8 common formats: 6:00am, 6am, 6 AM, 18:00, 18, etc.
  • Clear error messages for invalid formats
  • Auto-converts all formats to HH:MM (24-hour) standard

VALIDATION EXAMPLES:

  • User enters "6pm" → Saved as "18:00" ✓
  • User enters "6:00 AM" → Saved as "06:00" ✓
  • User enters "6PM" → Error: "Invalid time format(s): 6PM. Please use formats like '6:00am', '6:00 AM', '18:00', or '6pm'" ✗

TECHNICAL CHANGES:

  • Modified /includes/class-scheduler.php: Fixed timezone in slot_time logging
  • Modified /includes/class-admin.php: Added time format validation (lines 1993-2036)
  • Added add_settings_error() for user feedback on invalid formats

BENEFITS:

  • ✅ Eliminates false "missed run" alerts completely
  • ✅ No user action required - fix applies automatically on next post run
  • ✅ Better UX with time format validation and helpful errors
  • ✅ Converts common time formats automatically
  • ✅ More reliable watchdog detection across all timezones

COMPATIBILITY:

  • Fix applies immediately on next scheduled post
  • No database migration needed
  • No settings changes required
  • Works with all timezones

USER IMPACT:

  • Users will stop receiving false watchdog alerts
  • Clear feedback when entering schedule times in invalid formats
  • More confidence in scheduled posting reliability
Location:
weather-write/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • weather-write/trunk/includes/class-cronjob.php

    r3393864 r3423987  
    3939            $title = sprintf( 'WeatherWrite %s at %02d:%02d', untrailingslashit( $base ), $H, $M );
    4040            $jobId = isset( $map[$hm] ) ? (int) $map[$hm] : 0;
    41             // Pass the time slot in the request body
    42             $body = [ 'time' => $hm ];
    43             $result = self::upsert_job( $token, $url, $tz, $H, $M, $title, $jobId, $body );
     41            // Pass the time slot in the URL query string (cron-job.org doesn't reliably send POST body)
     42            $url_with_time = add_query_arg( 'time', $hm, $url );
     43            $result = self::upsert_job( $token, $url_with_time, $tz, $H, $M, $title, $jobId );
    4444            if ( is_wp_error( $result ) ) {
    4545                // Best-effort; continue
     
    7676    }
    7777
    78     public static function upsert_job( string $token, string $url, string $timezone, int $hour, int $minute, string $title, int $jobId = 0, array $body = [] ) {
     78    public static function upsert_job( string $token, string $url, string $timezone, int $hour, int $minute, string $title, int $jobId = 0 ) {
    7979        $payload = [
    8080            'job' => [
     
    9595            ],
    9696        ];
    97        
    98         // Add request body if provided
    99         if ( ! empty( $body ) ) {
    100             $payload['job']['body'] = wp_json_encode( $body );
    101         }
    10297        if ( $jobId > 0 ) {
    10398            // Update existing job (use PATCH per API spec for deltas)
  • weather-write/trunk/readme.txt

    r3423985 r3423987  
    44Requires at least: 6.5
    55Tested up to: 6.8
    6 Stable tag: 1.3.11
     6Stable tag: 1.3.12
    77License: GPLv2 or later
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    8888== Changelog ==
    8989
     90= 1.3.12 =
     91- CRITICAL FIX: Schedule-specific tags now working - time parameter moved to URL query string
     92- Fixed cron-job.org integration to pass time in URL instead of POST body (which wasn't being sent)
     93- Keeps debug logging from 1.3.11 for verification
     94- Tags like "Morning Weather Report" or "Evening Weather Report" will now be applied correctly
     95
    9096= 1.3.11 =
    9197- DEBUG: Added comprehensive logging to trace time parameter and tag lookup
    92 - Helps diagnose why schedule-specific tags may not be applied
    93 - Temporary debug version - will be removed once issue is resolved
     98- Identified that cron-job.org was not sending POST body data
     99- Temporary debug version
    94100
    95101= 1.3.10 =
    96 - CRITICAL FIX: Schedule-specific tags now correctly applied to posts triggered by cron-job.org
    97 - Fixed REST API endpoint to properly read time parameter from JSON body
    98 - Ensures tags like "Morning Weather Report" or "Evening Weather Report" are always included
     102- Attempted fix for schedule-specific tags (read from JSON body)
     103- Did not resolve issue due to cron-job.org not sending POST body
    99104
    100105= 1.3.9 =
  • weather-write/trunk/weather-write.php

    r3423985 r3423987  
    33 * Plugin Name: Weather Write
    44 * Description: Generate and publish weather-aware posts with summaries, charts, images, alerts, SEO, and more — fully automated or on-demand.
    5  * Version: 1.3.11
     5 * Version: 1.3.12
    66 * Author: Mike Freeman - WeatherWrite
    77 * Plugin URI: https://www.weatherwrite.com/
Note: See TracChangeset for help on using the changeset viewer.