• Plugin: Evergreen Countdown Timer Version: 2.1.0 Environment: WordPress 7.0, PHP 8.4.21

    Visiting any front-end page with an active countdown produces this warning:

    Warning: Undefined array key 1 in /wp-content/plugins/intelly-countdown/includes/classes/ui/CountdownUi.php on line 20

    In ICP_CountdownUi::drawDigit() (lines 17–20), the label string is split by comma and both elements are accessed unconditionally:

    $words    = explode( ',', $labels );
    $words[0] = __( $words[0], 'intelly-countdown' );
    $words[1] = __( $words[1], 'intelly-countdown' ); // ← line 20
    $labels = implode( ',', $words );

    If a countdown is configured with a label that has no comma (a single form instead of the expected singular,plural pair), explode() returns a one-element array and $words[1] is undefined. Under PHP 8+ this is no longer silent — it raises a warning on every render.

    Interestingly, the JavaScript side of the same file already handles this case gracefully:

    if (labels.length == 1) {
    labels.push(labels[0]);
    }

    The PHP side is missing the equivalent guard.

    Suggested fix

    Fall back to the singular form when the plural is missing, mirroring the JS behavior:

    $words    = explode( ',', $labels );
    $words[0] = __( $words[0], 'intelly-countdown' );
    $words[1] = __( $words[1] ?? $words[0], 'intelly-countdown' );
    $labels = implode( ',', $words );

    Alternatively, normalize the array first:

    $words = explode( ',', $labels );
    if ( count( $words ) === 1 ) {
    $words[] = $words[0];
    }
    $words[0] = __( $words[0], 'intelly-countdown' );
    $words[1] = __( $words[1], 'intelly-countdown' );
    $labels = implode( ',', $words );

    Either approach removes the warning and matches the existing JS fallback. The first is a minimal one-line change.

    Reproduction steps

    1. Run on PHP 8.0+ (reproduced on 8.4).
    2. Create a countdown where one of the label fields (Days / Hours / Minutes / Seconds) contains a single word with no comma, e.g. Days instead of Day,Days.
    3. Load any front-end page that renders the countdown shortcode.
    4. With WP_DEBUG enabled (or display_errors on at the server level), the warning appears on every page load.

    Thanks for maintaining the plugin.

You must be logged in to reply to this topic.