Plugin Directory

Changeset 3423985


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

Version 1.3.11: 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-rest.php

    r3423974 r3423985  
    8585        $time = '';
    8686        $body_params = $request->get_json_params();
     87       
     88        // DEBUG: Log what we received
     89        error_log( 'WeatherWrite REST Trigger - JSON body params: ' . print_r( $body_params, true ) );
     90        error_log( 'WeatherWrite REST Trigger - Query params: ' . print_r( $request->get_query_params(), true ) );
     91       
    8792        if ( is_array( $body_params ) && isset( $body_params['time'] ) ) {
    8893            $time = sanitize_text_field( (string) $body_params['time'] );
     94            error_log( 'WeatherWrite REST Trigger - Time from JSON body: ' . $time );
    8995        }
    9096        // Fallback to query string/URL params if not in body
    9197        if ( empty( $time ) ) {
    9298            $time = sanitize_text_field( (string) $request->get_param( 'time' ) );
     99            error_log( 'WeatherWrite REST Trigger - Time from query/URL params: ' . $time );
    93100        }
     101       
     102        error_log( 'WeatherWrite REST Trigger - Final time parameter: ' . ( $time ?: '(empty)' ) );
    94103       
    95104        // Trigger the post generation directly
  • weather-write/trunk/includes/class-scheduler.php

    r3423968 r3423985  
    516516        if ( is_string( $hm ) && $hm !== '' && isset( $options['auto_times'] ) && is_array( $options['auto_times'] ) ) {
    517517            $times = array_values( array_map( 'strval', $options['auto_times'] ) );
     518            error_log( 'WeatherWrite Tag Lookup - Received time: ' . $hm );
     519            error_log( 'WeatherWrite Tag Lookup - Available times: ' . print_r( $times, true ) );
    518520            $idx = array_search( $hm, $times, true );
     521            error_log( 'WeatherWrite Tag Lookup - Found index: ' . ( $idx !== false ? $idx : 'NOT FOUND' ) );
    519522            if ( false !== $idx && isset( $options['auto_time_tags'][ $idx ] ) && is_array( $options['auto_time_tags'][ $idx ] ) ) {
     523                error_log( 'WeatherWrite Tag Lookup - Tags for this time: ' . print_r( $options['auto_time_tags'][ $idx ], true ) );
    520524                $merge_lists[] = $options['auto_time_tags'][ $idx ];
    521             }
     525            } else {
     526                error_log( 'WeatherWrite Tag Lookup - No tags found for this time slot' );
     527            }
     528        } else {
     529            error_log( 'WeatherWrite Tag Lookup - Time parameter validation failed. hm: ' . var_export( $hm, true ) );
    522530        }
    523531        // Legacy schedule-wide tags (deprecated in UI but still honored if present)
  • weather-write/trunk/readme.txt

    r3423974 r3423985  
    44Requires at least: 6.5
    55Tested up to: 6.8
    6 Stable tag: 1.3.10
     6Stable tag: 1.3.11
    77License: GPLv2 or later
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    8787
    8888== Changelog ==
     89
     90= 1.3.11 =
     91- 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
    8994
    9095= 1.3.10 =
  • weather-write/trunk/weather-write.php

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