• Title: Avoid PHP warning when REMOTE_ADDR is unavailable

    The plugin logs every outgoing email through the wp_mail filter. This filter can also run outside a normal HTTP request, for example from WP-CLI, a server-side cron job, or another background process.

    In these contexts, $_SERVER['REMOTE_ADDR'] may not be defined. The current direct array access in inc/email-logging.php produces a PHP warning:

    PHP Warning: Undefined array key “REMOTE_ADDR”

    The warning occurs before sanitize_text_field() can process the value, because the array key is accessed first. Email logging itself can continue, but the warning adds unnecessary noise to the PHP error log.

    Suggested fix:

    $log['ip_address'] = sanitize_text_field( $_SERVER['REMOTE_ADDR'] ?? '' );

    Alternatively, use an explicit fallback such as UNKNOWN if the log should distinguish an unavailable address from an intentionally empty value:

    $log['ip_address'] = sanitize_text_field( $_SERVER['REMOTE_ADDR'] ?? 'UNKNOWN' );


    This preserves the IP address for regular HTTP requests while allowing email logging to work cleanly in non-HTTP execution contexts.

    • This topic was modified 2 weeks, 2 days ago by matzemuc86.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.