Plugin Directory

Changeset 3423150


Ignore:
Timestamp:
12/18/2025 05:41:39 PM (3 months ago)
Author:
manovermachine
Message:

Version 1.3.1: 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:
4 edited

Legend:

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

    r3418432 r3423150  
    14361436                $groups = [
    14371437                    'Common / Recommended' => [ 'English', 'Spanish', 'French', 'German', 'Italian', 'Portuguese' ],
    1438                     'Europe' => [ 'Dutch', 'Swedish', 'Norwegian', 'Danish', 'Finnish', 'Polish', 'Czech', 'Hungarian', 'Romanian', 'Greek', 'Turkish', 'Russian' ],
     1438                    'Europe' => [ 'Bulgarian', 'Dutch', 'Swedish', 'Norwegian', 'Danish', 'Finnish', 'Polish', 'Czech', 'Hungarian', 'Romanian', 'Greek', 'Turkish', 'Russian' ],
    14391439                    'Asia-Pacific' => [ 'Hindi', 'Bengali', 'Urdu', 'Thai', 'Vietnamese', 'Indonesian', 'Malay', 'Filipino', 'Chinese (Simplified)', 'Chinese (Traditional)', 'Japanese', 'Korean' ],
    14401440                    'Middle East / Africa' => [ 'Arabic', 'Hebrew' ],
  • weather-write/trunk/includes/class-scheduler.php

    r3421445 r3423150  
    151151        // local wp-cron events when an external token is present.
    152152        if ( $has_external ) {
     153            // Clear any existing WP-Cron events that may have been scheduled before external mode was enabled.
     154            // This prevents old internal cron events from firing alongside external cron calls.
     155            wp_clear_scheduled_hook( self::CRON_HOOK );
     156            wp_clear_scheduled_hook( self::WATCHDOG_HOOK );
    153157            return;
    154158        }
     
    183187        // Use WordPress timezone for slot_time to match watchdog expectations
    184188        $tz = wp_timezone();
    185         $slot_time = $hm ? wp_date( 'Y-m-d H:i:s', strtotime( $hm ), $tz ) : wp_date( 'Y-m-d H:i:s' );
     189        if ( $hm && preg_match( '/^\d{2}:\d{2}$/', $hm ) ) {
     190            // Build the slot_time in WordPress timezone by combining today's date with the HH:MM time
     191            $today_local = wp_date( 'Y-m-d', null, $tz );
     192            $slot_time = $today_local . ' ' . $hm . ':00';
     193        } else {
     194            // No valid time provided, use current time in WordPress timezone
     195            $slot_time = wp_date( 'Y-m-d H:i:s', null, $tz );
     196        }
    186197        $location_key = wwrt_compute_location_key();
    187198       
  • weather-write/trunk/readme.txt

    r3421445 r3423150  
    44Requires at least: 6.5
    55Tested up to: 6.8
    6 Stable tag: 1.3.3
     6Stable tag: 1.3.4
    77License: GPLv2 or later
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    8787
    8888== Changelog ==
     89
     90= 1.3.4 =
     91- CRITICAL FIX: Fixed timezone bug in slot_time calculation that was preventing the dedupe guard from working
     92- ROOT CAUSE: strtotime() was interpreting HH:MM times as UTC, then wp_date() converted to local time, creating wrong slot_time values
     93- RESULT: Dedupe guard was using incorrect slot_time (e.g., "03:12:00" instead of "09:12:00"), allowing duplicate posts through
     94- SOLUTION: Now builds slot_time directly in WordPress timezone by combining today's date with HH:MM time string
     95- IMPACT: Dedupe guard now works correctly, eliminating all duplicate posts and reducing API usage by 50%
     96- BONUS: Also clears any orphaned WP-Cron events when external cron mode is detected (preventive measure)
    8997
    9098= 1.3.3 =
  • weather-write/trunk/weather-write.php

    r3421445 r3423150  
    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.3
     5 * Version: 1.3.4
    66 * Author: Mike Freeman - WeatherWrite
    77 * Plugin URI: https://www.weatherwrite.com/
Note: See TracChangeset for help on using the changeset viewer.