This commit is contained in:
Javier Casares 2026-06-05 11:32:24 +00:00
commit c73e6b6e58
9 changed files with 1040 additions and 438 deletions

186
changelog.txt Normal file
View file

@ -0,0 +1,186 @@
== Changelog ==
= 2.0.2 =
_Release date: 2026-06-05_
**Highlights**
* Translations added for Spanish (Spain) and Catalan.
* WordPress minimum version corrected to 3.6 based on actual function usage.
**Changed**
* Minimum WordPress version updated from 4.1 to 3.6 (real minimum per wp-compat analysis: wp_unslash since WP 3.6).
* Tested up to WordPress 7.1.
* POT file regenerated via WP-CLI i18n — removed dead strings, corrected line references.
* Deploy script no longer includes docs/ in the distributable ZIP.
* Deploy script skips empty vendor/ directory when no production Composer dependencies exist.
**Added**
* Spanish (Spain) translation (es_ES).
* Catalan translation (ca).
**Compatibility**
* WordPress: 3.6 - 7.1
* PHP: 5.6 - 8.5
**Tests**
* PHP Coding Standards: 3.13.5
* WordPress Coding Standards: 3.3.0
* PHPStan: 2.2.2 (level 9)
* PHPUnit: 9.6.34
= 2.0.1 =
_Release date: 2026-06-05_
**Highlights**
* Major bugfix release addressing three critical issues found during pre-deploy audit.
**Fixed**
* Context cache not resetting between emails in the same PHP process (affected WP-Cron and REST batch sends).
* Duplicate Reply-To header injected when an existing Reply-To was present in the email.
* Migration hook only running on admin_init — missed WP-CLI activations and automated deployments.
* RFC 5322 display name quoting now applied only when the name contains special characters.
**Added**
* Developer filter wp_mail_replyto_context — override the detected email context.
* Developer filter wp_mail_replyto_header — override or suppress the Reply-To header per email.
* load_plugin_textdomain() registration for translation support on WordPress < 4.6.
* DNS domain validation per context with user-friendly warning messages.
* PHPUnit test suite (27 tests).
* bin/deploy.sh build script.
**Changed**
* Admin CSS now registered via wp_register_style() + wp_add_inline_style().
* enabled flag now handles boolean true in addition to string '1'.
* Multibyte-safe name length truncation (mb_strlen/mb_substr).
* CR-only header normalization added alongside CRLF.
**Security**
* sanitize_callback added to legacy option registrations (wp_mail_replyto_email, wp_mail_replyto_name).
**Compatibility**
* WordPress: 4.1 - 6.9
* PHP: 5.6 - 8.5
**Tests**
* PHP Coding Standards: 3.13.5
* WordPress Coding Standards: 3.3.0
* PHPStan: 2.2.2 (level 9)
* PHPUnit: 9.6.34
= 2.0.0 =
_Release date: 2026-01-20_
**Highlights**
* Complete rewrite with context-based Reply-To routing.
**Added**
* Context-based Reply-To routing — configure different Reply-To addresses for different types of emails.
* Six email contexts: Default, Authentication & Security, Comments & Moderation, Users & Registration, System & Updates, WooCommerce.
* WooCommerce tab only shown when WooCommerce plugin is active.
* Intelligent context detection using debug_backtrace() with DEBUG_BACKTRACE_IGNORE_ARGS and a 20-frame limit.
* Modern tabbed admin interface using WordPress native nav-tab-wrapper.
* Visual status indicators on each tab.
* Enable/disable toggle per context (Default is always active).
* Fallback chain: specific context → Default context → legacy settings.
* Reply-To display name field with header injection prevention.
* DNS domain validation for email addresses.
* Configuration change logging for security auditing (requires WP_DEBUG_LOG).
* Automatic migration from v1.0.x — existing settings preserved in the Default context.
* uninstall.php for clean removal of all plugin options on single-site and Multisite.
**Changed**
* Settings structure changed from two individual options to a single serialized array (wp_mail_replyto_contexts).
* Settings page completely rewritten with tab-based interface.
**Security**
* Strict RFC 5322 email format validation beyond is_email().
* Defense-in-depth header injection prevention.
**Compatibility**
* WordPress: 4.1 - 6.9
* PHP: 5.6 - 8.5
**Tests**
* PHP Coding Standards: 3.13.4
* WordPress Coding Standards: 3.3.0
* Plugin Check (PCP): 1.4.0
= 1.0.3 =
_Release date: 2025-04-08_
**Changed**
* Compatible with WordPress 6.8.
* Improved function documentation.
**Compatibility**
* WordPress: 4.1 - 6.9
* PHP: 5.6 - 8.5
**Tests**
* PHP Coding Standards: 3.12.1
* WordPress Coding Standards: 3.1.0
* Plugin Check (PCP): 1.4.0
= 1.0.2 =
_Release date: 2024-11-02_
**Fixed**
* Preparation for GlotPress translation workflow.
**Compatibility**
* WordPress: 4.1 - 6.9
* PHP: 5.6 - 8.5
= 1.0.1 =
_Release date: 2024-10-31_
**Added**
* Translation ready.
**Compatibility**
* WordPress: 4.1 - 6.9
* PHP: 5.6 - 8.5
= 1.0.0 =
_Release date: 2024-10-22_
**Added**
* First version.
**Compatibility**
* WordPress: 4.1 - 4.1
* PHP: 5.6 - 8.5

BIN
languages/replyto-ca.mo Normal file

Binary file not shown.

215
languages/replyto-ca.po Normal file
View file

@ -0,0 +1,215 @@
# Translation of Reply-To for WP_Mail in Catalan
# Copyright (C) 2026 ROBOTSTXT
# This file is distributed under the GPL-3.0-or-later.
msgid ""
msgstr ""
"Project-Id-Version: Reply-To for WP_Mail 2.0.2\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/replyto\n"
"POT-Creation-Date: 2026-06-05T11:22:01+00:00\n"
"PO-Revision-Date: 2026-06-05 12:00+0100\n"
"Last-Translator: Javier Casares <javier@robotstxt.es>\n"
"Language-Team: Catalan <ca@li.org>\n"
"Language: ca\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Manual\n"
"X-Domain: replyto\n"
#. Plugin Name of the plugin
#: replyto.php
msgid "Reply-To for WP_Mail"
msgstr "Respon-A per a WP_Mail"
#. Description of the plugin
#: replyto.php
msgid "Configure your \"Reply-To:\" for WP_Mail with validation, admin settings, and context-based routing."
msgstr "Configureu el vostre «Respon-A:» per a WP_Mail amb validació, opcions d'administració i enrutament per context."
#. Author of the plugin
#: replyto.php
msgid "ROBOTSTXT"
msgstr "ROBOTSTXT"
#. Author URI of the plugin
#: replyto.php
msgid "https://www.robotstxt.es/"
msgstr "https://www.robotstxt.es/"
#: replyto.php:391
msgid "WP Mail Reply-To Settings"
msgstr "Configuració de Respon-A per a WP Mail"
#: replyto.php:392
msgid "Reply-To"
msgstr "Respon-A"
#: replyto.php:492
#: replyto.php:706
msgid "Default"
msgstr "Predeterminat"
#: replyto.php:493
msgid "Authentication"
msgstr "Autenticació"
#: replyto.php:494
msgid "Comments"
msgstr "Comentaris"
#: replyto.php:495
msgid "Users"
msgstr "Usuaris"
#: replyto.php:496
msgid "System"
msgstr "Sistema"
#: replyto.php:501
#: replyto.php:735
msgid "WooCommerce"
msgstr "WooCommerce"
#. translators: %s: context name
#: replyto.php:526
#, php-format
msgid "Invalid email address for %s context."
msgstr "Adreça de correu no vàlida per al context %s."
#. translators: %s: context name
#: replyto.php:542
#, php-format
msgid "Warning: The email domain for %s context does not appear to have valid DNS records."
msgstr "Avís: el domini de correu del context %s no sembla tenir registres DNS vàlids."
#. translators: %s: context name
#: replyto.php:557
#: replyto.php:567
#, php-format
msgid "Name for %s context was truncated to 255 characters."
msgstr "El nom del context %s s'ha truncat a 255 caràcters."
#: replyto.php:608
msgid "Reply-To configuration updated successfully."
msgstr "La configuració de Respon-A s'ha actualitzat correctament."
#: replyto.php:707
msgid "Default Reply-To used for all emails that do not match a specific context. This is the fallback when other contexts are not configured."
msgstr "Respon-A predeterminat per a tots els correus que no coincideixin amb cap context específic. És l'opció de reserva quan altres contextos no estan configurats."
#: replyto.php:708
msgid "Newsletter confirmations, general notifications, and any emails not covered by other contexts."
msgstr "Confirmacions de butlletins, notificacions generals i qualsevol correu no cobert per altres contextos."
#: replyto.php:711
msgid "Authentication & Security"
msgstr "Autenticació i seguretat"
#: replyto.php:712
msgid "Reply-To for password resets, password changes, and email address changes."
msgstr "Respon-A per a restabliments de contrasenya, canvis de contrasenya i canvis de l'adreça de correu."
#: replyto.php:713
msgid "Password reset requests, password change confirmations, email address verifications."
msgstr "Sol·licituds de restabliment de contrasenya, confirmacions de canvi de contrasenya, verificacions de l'adreça de correu."
#: replyto.php:716
msgid "Comments & Moderation"
msgstr "Comentaris i moderació"
#: replyto.php:717
msgid "Reply-To for comment notifications and moderation alerts."
msgstr "Respon-A per a notificacions de comentaris i alertes de moderació."
#: replyto.php:718
msgid "New comment notifications, comment moderation alerts, comment replies."
msgstr "Notificacions de nous comentaris, alertes de moderació de comentaris, respostes a comentaris."
#: replyto.php:721
msgid "Users & Registration"
msgstr "Usuaris i registre"
#: replyto.php:722
msgid "Reply-To for new user registrations, role changes, and user management emails."
msgstr "Respon-A per a registres de nous usuaris, canvis de rol i correus de gestió d'usuaris."
#: replyto.php:723
msgid "New user welcome emails, user role changes, account activations."
msgstr "Correus de benvinguda a nous usuaris, canvis de rol d'usuari, activacions de compte."
#: replyto.php:726
msgid "System & Updates"
msgstr "Sistema i actualitzacions"
#: replyto.php:727
msgid "Reply-To for automatic updates, system alerts, and critical site health notifications."
msgstr "Respon-A per a actualitzacions automàtiques, alertes del sistema i notificacions crítiques de salut del lloc."
#: replyto.php:728
msgid "WordPress core updates, plugin updates, theme updates, recovery mode, fatal error notifications."
msgstr "Actualitzacions del nucli de WordPress, actualitzacions de connectors, actualitzacions de temes, mode de recuperació, notificacions d'errors fatals."
#: replyto.php:736
msgid "Reply-To for WooCommerce order notifications, invoices, and customer communications."
msgstr "Respon-A per a notificacions de comandes de WooCommerce, factures i comunicacions amb clients."
#: replyto.php:737
msgid "Order confirmations, shipping notifications, invoices, customer notes."
msgstr "Confirmacions de comandes, notificacions d'enviament, factures, notes del client."
#: replyto.php:751
msgid "Configure different Reply-To addresses based on the type of email being sent. Each context can have its own email address and display name."
msgstr "Configureu adreces de resposta diferents en funció del tipus de correu enviat. Cada context pot tenir la seva pròpia adreça de correu electrònic i nom."
#: replyto.php:789
msgid "Active with email configured"
msgstr "Actiu amb correu configurat"
#: replyto.php:790
msgid "Inactive or no email configured"
msgstr "Inactiu o sense correu configurat"
#: replyto.php:806
msgid "What this context covers:"
msgstr "Què cobreix aquest context:"
#: replyto.php:808
msgid "Examples:"
msgstr "Exemples:"
#: replyto.php:819
msgid "Enable this context"
msgstr "Activar aquest context"
#: replyto.php:822
msgid "When disabled, emails in this context will use the Default Reply-To address."
msgstr "Quan està desactivat, els correus d'aquest context usaran l'adreça de Respon-A predeterminada."
#: replyto.php:832
msgid "Reply-To Email Address"
msgstr "Adreça de correu de resposta"
#: replyto.php:842
msgid "Enter the email address where replies should be sent."
msgstr "Introduïu l'adreça de correu a la qual s'enviaran les respostes."
#: replyto.php:849
msgid "Reply-To Display Name (Optional)"
msgstr "Nom de visualització de resposta (opcional)"
#: replyto.php:859
msgid "Optional: Enter a name to display with the email (e.g., \"Support Team\")."
msgstr "Opcional: introduïu un nom per mostrar amb el correu (p.&nbsp;ex., «Equip de suport»)."
#: replyto.php:868
msgid "Note:"
msgstr "Nota:"
#: replyto.php:869
msgid "The Default context is always active and acts as a fallback for all emails."
msgstr "El context predeterminat sempre està actiu i actua com a reserva per a tots els correus."
#: replyto.php:895
msgid "Save Settings"
msgstr "Desa la configuració"

BIN
languages/replyto-es_ES.mo Normal file

Binary file not shown.

215
languages/replyto-es_ES.po Normal file
View file

@ -0,0 +1,215 @@
# Translation of Reply-To for WP_Mail in Spanish (Spain)
# Copyright (C) 2026 ROBOTSTXT
# This file is distributed under the GPL-3.0-or-later.
msgid ""
msgstr ""
"Project-Id-Version: Reply-To for WP_Mail 2.0.2\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/replyto\n"
"POT-Creation-Date: 2026-06-05T11:22:01+00:00\n"
"PO-Revision-Date: 2026-06-05 12:00+0100\n"
"Last-Translator: Javier Casares <javier@robotstxt.es>\n"
"Language-Team: Spanish (Spain) <es@li.org>\n"
"Language: es_ES\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Manual\n"
"X-Domain: replyto\n"
#. Plugin Name of the plugin
#: replyto.php
msgid "Reply-To for WP_Mail"
msgstr "Responder a para WP_Mail"
#. Description of the plugin
#: replyto.php
msgid "Configure your \"Reply-To:\" for WP_Mail with validation, admin settings, and context-based routing."
msgstr "Configure su «Responder a:» para WP_Mail con validación, ajustes de administración y enrutamiento por contexto."
#. Author of the plugin
#: replyto.php
msgid "ROBOTSTXT"
msgstr "ROBOTSTXT"
#. Author URI of the plugin
#: replyto.php
msgid "https://www.robotstxt.es/"
msgstr "https://www.robotstxt.es/"
#: replyto.php:391
msgid "WP Mail Reply-To Settings"
msgstr "Ajustes de Responder a para WP Mail"
#: replyto.php:392
msgid "Reply-To"
msgstr "Responder a"
#: replyto.php:492
#: replyto.php:706
msgid "Default"
msgstr "Predeterminado"
#: replyto.php:493
msgid "Authentication"
msgstr "Autenticación"
#: replyto.php:494
msgid "Comments"
msgstr "Comentarios"
#: replyto.php:495
msgid "Users"
msgstr "Usuarios"
#: replyto.php:496
msgid "System"
msgstr "Sistema"
#: replyto.php:501
#: replyto.php:735
msgid "WooCommerce"
msgstr "WooCommerce"
#. translators: %s: context name
#: replyto.php:526
#, php-format
msgid "Invalid email address for %s context."
msgstr "Dirección de correo no válida para el contexto %s."
#. translators: %s: context name
#: replyto.php:542
#, php-format
msgid "Warning: The email domain for %s context does not appear to have valid DNS records."
msgstr "Aviso: el dominio de correo del contexto %s no parece tener registros DNS válidos."
#. translators: %s: context name
#: replyto.php:557
#: replyto.php:567
#, php-format
msgid "Name for %s context was truncated to 255 characters."
msgstr "El nombre del contexto %s se ha truncado a 255 caracteres."
#: replyto.php:608
msgid "Reply-To configuration updated successfully."
msgstr "La configuración de Responder a se ha actualizado correctamente."
#: replyto.php:707
msgid "Default Reply-To used for all emails that do not match a specific context. This is the fallback when other contexts are not configured."
msgstr "Responder a predeterminado para todos los correos que no coincidan con un contexto específico. Es la opción alternativa cuando otros contextos no están configurados."
#: replyto.php:708
msgid "Newsletter confirmations, general notifications, and any emails not covered by other contexts."
msgstr "Confirmaciones de boletines, notificaciones generales y cualquier correo no cubierto por otros contextos."
#: replyto.php:711
msgid "Authentication & Security"
msgstr "Autenticación y seguridad"
#: replyto.php:712
msgid "Reply-To for password resets, password changes, and email address changes."
msgstr "Responder a para restablecimientos de contraseña, cambios de contraseña y cambios de dirección de correo."
#: replyto.php:713
msgid "Password reset requests, password change confirmations, email address verifications."
msgstr "Solicitudes de restablecimiento de contraseña, confirmaciones de cambio de contraseña, verificaciones de dirección de correo."
#: replyto.php:716
msgid "Comments & Moderation"
msgstr "Comentarios y moderación"
#: replyto.php:717
msgid "Reply-To for comment notifications and moderation alerts."
msgstr "Responder a para notificaciones de comentarios y alertas de moderación."
#: replyto.php:718
msgid "New comment notifications, comment moderation alerts, comment replies."
msgstr "Notificaciones de nuevos comentarios, alertas de moderación de comentarios, respuestas a comentarios."
#: replyto.php:721
msgid "Users & Registration"
msgstr "Usuarios y registro"
#: replyto.php:722
msgid "Reply-To for new user registrations, role changes, and user management emails."
msgstr "Responder a para registros de nuevos usuarios, cambios de rol y correos de gestión de usuarios."
#: replyto.php:723
msgid "New user welcome emails, user role changes, account activations."
msgstr "Correos de bienvenida a nuevos usuarios, cambios de rol de usuario, activaciones de cuenta."
#: replyto.php:726
msgid "System & Updates"
msgstr "Sistema y actualizaciones"
#: replyto.php:727
msgid "Reply-To for automatic updates, system alerts, and critical site health notifications."
msgstr "Responder a para actualizaciones automáticas, alertas del sistema y notificaciones críticas de estado del sitio."
#: replyto.php:728
msgid "WordPress core updates, plugin updates, theme updates, recovery mode, fatal error notifications."
msgstr "Actualizaciones del núcleo de WordPress, actualizaciones de plugins, actualizaciones de temas, modo de recuperación, notificaciones de errores fatales."
#: replyto.php:736
msgid "Reply-To for WooCommerce order notifications, invoices, and customer communications."
msgstr "Responder a para notificaciones de pedidos de WooCommerce, facturas y comunicaciones con clientes."
#: replyto.php:737
msgid "Order confirmations, shipping notifications, invoices, customer notes."
msgstr "Confirmaciones de pedidos, notificaciones de envío, facturas, notas del cliente."
#: replyto.php:751
msgid "Configure different Reply-To addresses based on the type of email being sent. Each context can have its own email address and display name."
msgstr "Configure diferentes direcciones de respuesta según el tipo de correo enviado. Cada contexto puede tener su propia dirección de correo electrónico y nombre."
#: replyto.php:789
msgid "Active with email configured"
msgstr "Activo con correo configurado"
#: replyto.php:790
msgid "Inactive or no email configured"
msgstr "Inactivo o sin correo configurado"
#: replyto.php:806
msgid "What this context covers:"
msgstr "Qué cubre este contexto:"
#: replyto.php:808
msgid "Examples:"
msgstr "Ejemplos:"
#: replyto.php:819
msgid "Enable this context"
msgstr "Activar este contexto"
#: replyto.php:822
msgid "When disabled, emails in this context will use the Default Reply-To address."
msgstr "Cuando está desactivado, los correos de este contexto usarán la dirección de Responder a predeterminada."
#: replyto.php:832
msgid "Reply-To Email Address"
msgstr "Dirección de correo de respuesta"
#: replyto.php:842
msgid "Enter the email address where replies should be sent."
msgstr "Introduzca la dirección de correo a la que se enviarán las respuestas."
#: replyto.php:849
msgid "Reply-To Display Name (Optional)"
msgstr "Nombre para mostrar de respuesta (opcional)"
#: replyto.php:859
msgid "Optional: Enter a name to display with the email (e.g., \"Support Team\")."
msgstr "Opcional: introduzca un nombre para mostrar junto al correo (p.&nbsp;ej., «Equipo de soporte»)."
#: replyto.php:868
msgid "Note:"
msgstr "Nota:"
#: replyto.php:869
msgid "The Default context is always active and acts as a fallback for all emails."
msgstr "El contexto predeterminado siempre está activo y actúa como alternativa para todos los correos."
#: replyto.php:895
msgid "Save Settings"
msgstr "Guardar ajustes"

View file

@ -1,242 +1,212 @@
#, fuzzy # Copyright (C) 2026 ROBOTSTXT
# This file is distributed under the GPL-3.0-or-later.
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Reply-To for WP_Mail\n" "Project-Id-Version: Reply-To for WP_Mail 2.0.2\n"
"POT-Creation-Date: 2026-01-20 18:14+0100\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/replyto\n"
"PO-Revision-Date: 2026-01-20 18:14+0100\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Last-Translator: \n" "Language-Team: LANGUAGE <LL@li.org>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" "POT-Creation-Date: 2026-06-05T11:22:01+00:00\n"
"X-Generator: Poedit 3.8\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Poedit-Basepath: ..\n" "X-Generator: WP-CLI 2.12.0\n"
"X-Poedit-Flags-xgettext: --add-comments=translators:\n" "X-Domain: replyto\n"
"X-Poedit-WPHeader: replyto.php\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: "
"__;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPathExcluded-0: *.min.js\n"
"X-Poedit-SearchPathExcluded-1: vendor\n"
#: replyto.php:326 #. Plugin Name of the plugin
#: replyto.php
msgid "Reply-To for WP_Mail"
msgstr ""
#. Description of the plugin
#: replyto.php
msgid "Configure your \"Reply-To:\" for WP_Mail with validation, admin settings, and context-based routing."
msgstr ""
#. Author of the plugin
#: replyto.php
msgid "ROBOTSTXT"
msgstr ""
#. Author URI of the plugin
#: replyto.php
msgid "https://www.robotstxt.es/"
msgstr ""
#: replyto.php:391
msgid "WP Mail Reply-To Settings" msgid "WP Mail Reply-To Settings"
msgstr "" msgstr ""
#: replyto.php:327 #: replyto.php:392
msgid "Reply-To" msgid "Reply-To"
msgstr "" msgstr ""
#: replyto.php:390 #: replyto.php:492
msgid "The email address format is not valid. Please check and try again." #: replyto.php:706
msgstr ""
#: replyto.php:405
msgid ""
"Warning: The email domain does not appear to have valid DNS records. The "
"email may not work correctly."
msgstr ""
#: replyto.php:436
msgid "Reply-To email address updated successfully."
msgstr ""
#: replyto.php:502 replyto.php:675
msgid "Default" msgid "Default"
msgstr "" msgstr ""
#: replyto.php:503 #: replyto.php:493
msgid "Authentication" msgid "Authentication"
msgstr "" msgstr ""
#: replyto.php:504 #: replyto.php:494
msgid "Comments" msgid "Comments"
msgstr "" msgstr ""
#: replyto.php:505 #: replyto.php:495
msgid "Users" msgid "Users"
msgstr "" msgstr ""
#: replyto.php:506 #: replyto.php:496
msgid "System" msgid "System"
msgstr "" msgstr ""
#: replyto.php:511 replyto.php:704 #: replyto.php:501
#: replyto.php:735
msgid "WooCommerce" msgid "WooCommerce"
msgstr "" msgstr ""
#. translators: %s: context name #. translators: %s: context name
#: replyto.php:534 #: replyto.php:526
#, php-format #, php-format
msgid "Invalid email address for %s context." msgid "Invalid email address for %s context."
msgstr "" msgstr ""
#. translators: %s: context name #. translators: %s: context name
#: replyto.php:547 #: replyto.php:542
#, php-format
msgid "Warning: The email domain for %s context does not appear to have valid DNS records."
msgstr ""
#. translators: %s: context name
#: replyto.php:557
#: replyto.php:567
#, php-format #, php-format
msgid "Name for %s context was truncated to 255 characters." msgid "Name for %s context was truncated to 255 characters."
msgstr "" msgstr ""
#: replyto.php:584 #: replyto.php:608
msgid "Reply-To configuration updated successfully." msgid "Reply-To configuration updated successfully."
msgstr "" msgstr ""
#: replyto.php:676 #: replyto.php:707
msgid "" msgid "Default Reply-To used for all emails that do not match a specific context. This is the fallback when other contexts are not configured."
"Default Reply-To used for all emails that do not match a specific context. "
"This is the fallback when other contexts are not configured."
msgstr "" msgstr ""
#: replyto.php:677 #: replyto.php:708
msgid "" msgid "Newsletter confirmations, general notifications, and any emails not covered by other contexts."
"Newsletter confirmations, general notifications, and any emails not covered "
"by other contexts."
msgstr "" msgstr ""
#: replyto.php:680 #: replyto.php:711
msgid "Authentication & Security" msgid "Authentication & Security"
msgstr "" msgstr ""
#: replyto.php:681 #: replyto.php:712
msgid "" msgid "Reply-To for password resets, password changes, and email address changes."
"Reply-To for password resets, password changes, and email address changes."
msgstr "" msgstr ""
#: replyto.php:682 #: replyto.php:713
msgid "" msgid "Password reset requests, password change confirmations, email address verifications."
"Password reset requests, password change confirmations, email address "
"verifications."
msgstr "" msgstr ""
#: replyto.php:685 #: replyto.php:716
msgid "Comments & Moderation" msgid "Comments & Moderation"
msgstr "" msgstr ""
#: replyto.php:686 #: replyto.php:717
msgid "Reply-To for comment notifications and moderation alerts." msgid "Reply-To for comment notifications and moderation alerts."
msgstr "" msgstr ""
#: replyto.php:687 #: replyto.php:718
msgid "New comment notifications, comment moderation alerts, comment replies." msgid "New comment notifications, comment moderation alerts, comment replies."
msgstr "" msgstr ""
#: replyto.php:690 #: replyto.php:721
msgid "Users & Registration" msgid "Users & Registration"
msgstr "" msgstr ""
#: replyto.php:691 #: replyto.php:722
msgid "" msgid "Reply-To for new user registrations, role changes, and user management emails."
"Reply-To for new user registrations, role changes, and user management "
"emails."
msgstr "" msgstr ""
#: replyto.php:692 #: replyto.php:723
msgid "New user welcome emails, user role changes, account activations." msgid "New user welcome emails, user role changes, account activations."
msgstr "" msgstr ""
#: replyto.php:695 #: replyto.php:726
msgid "System & Updates" msgid "System & Updates"
msgstr "" msgstr ""
#: replyto.php:696 #: replyto.php:727
msgid "" msgid "Reply-To for automatic updates, system alerts, and critical site health notifications."
"Reply-To for automatic updates, system alerts, and critical site health "
"notifications."
msgstr "" msgstr ""
#: replyto.php:697 #: replyto.php:728
msgid "" msgid "WordPress core updates, plugin updates, theme updates, recovery mode, fatal error notifications."
"WordPress core updates, plugin updates, theme updates, recovery mode, fatal "
"error notifications."
msgstr "" msgstr ""
#: replyto.php:705 #: replyto.php:736
msgid "" msgid "Reply-To for WooCommerce order notifications, invoices, and customer communications."
"Reply-To for WooCommerce order notifications, invoices, and customer "
"communications."
msgstr "" msgstr ""
#: replyto.php:706 #: replyto.php:737
msgid "Order confirmations, shipping notifications, invoices, customer notes." msgid "Order confirmations, shipping notifications, invoices, customer notes."
msgstr "" msgstr ""
#: replyto.php:720 #: replyto.php:751
msgid "" msgid "Configure different Reply-To addresses based on the type of email being sent. Each context can have its own email address and display name."
"Configure different Reply-To addresses based on the type of email being "
"sent. Each context can have its own email address and display name."
msgstr ""
#: replyto.php:757
msgid "Active with email configured"
msgstr ""
#: replyto.php:758
msgid "Inactive or no email configured"
msgstr ""
#: replyto.php:773
msgid "What this context covers:"
msgstr ""
#: replyto.php:775
msgid "Examples:"
msgstr ""
#: replyto.php:786
msgid "Enable this context"
msgstr "" msgstr ""
#: replyto.php:789 #: replyto.php:789
msgid "" msgid "Active with email configured"
"When disabled, emails in this context will use the Default Reply-To address."
msgstr "" msgstr ""
#: replyto.php:799 #: replyto.php:790
msgid "Inactive or no email configured"
msgstr ""
#: replyto.php:806
msgid "What this context covers:"
msgstr ""
#: replyto.php:808
msgid "Examples:"
msgstr ""
#: replyto.php:819
msgid "Enable this context"
msgstr ""
#: replyto.php:822
msgid "When disabled, emails in this context will use the Default Reply-To address."
msgstr ""
#: replyto.php:832
msgid "Reply-To Email Address" msgid "Reply-To Email Address"
msgstr "" msgstr ""
#: replyto.php:809 #: replyto.php:842
msgid "Enter the email address where replies should be sent." msgid "Enter the email address where replies should be sent."
msgstr "" msgstr ""
#: replyto.php:816 #: replyto.php:849
msgid "Reply-To Display Name (Optional)" msgid "Reply-To Display Name (Optional)"
msgstr "" msgstr ""
#: replyto.php:826 #: replyto.php:859
msgid "" msgid "Optional: Enter a name to display with the email (e.g., \"Support Team\")."
"Optional: Enter a name to display with the email (e.g., \"Support Team\")."
msgstr "" msgstr ""
#: replyto.php:835 #: replyto.php:868
msgid "Note:" msgid "Note:"
msgstr "" msgstr ""
#: replyto.php:836 #: replyto.php:869
msgid "" msgid "The Default context is always active and acts as a fallback for all emails."
"The Default context is always active and acts as a fallback for all emails."
msgstr "" msgstr ""
#: replyto.php:861 #: replyto.php:895
msgid "Save Settings" msgid "Save Settings"
msgstr "" msgstr ""
#. Plugin Name of the plugin/theme
msgid "Reply-To for WP_Mail"
msgstr ""
#. Description of the plugin/theme
msgid ""
"Configure your \"Reply-To:\" for WP_Mail with validation, admin settings, "
"and context-based routing."
msgstr ""
#. Author of the plugin/theme
msgid "ROBOTSTXT"
msgstr ""
#. Author URI of the plugin/theme
msgid "https://www.robotstxt.es/"
msgstr ""

View file

@ -1,68 +0,0 @@
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Reply-To for WP_Mail\n"
"POT-Creation-Date: 2025-04-08 12:13+0200\n"
"PO-Revision-Date: 2024-10-31 08:58+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
"X-Generator: Poedit 3.6\n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-Flags-xgettext: --add-comments=translators:\n"
"X-Poedit-WPHeader: replyto.php\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: "
"__;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPathExcluded-0: *.min.js\n"
#: replyto.php:97
msgid "WP Mail Reply-To Settings"
msgstr ""
#: replyto.php:98
msgid "Reply-To"
msgstr ""
#: replyto.php:130
msgid "Reply-To Configuration"
msgstr ""
#: replyto.php:138
msgid "Reply-To Email Address"
msgstr ""
#: replyto.php:154
msgid ""
"Set the email address to be used in the \"Reply-To\" header of outgoing "
"emails."
msgstr ""
#: replyto.php:169
msgid "Enter the email address to be used as \"Reply-To\"."
msgstr ""
#: replyto.php:194
msgid "Save Settings"
msgstr ""
#. Plugin Name of the plugin/theme
msgid "Reply-To for WP_Mail"
msgstr ""
#. Description of the plugin/theme
msgid ""
"Configure your \"Reply-To:\" for WP_Mail with validation and admin settings."
msgstr ""
#. Author of the plugin/theme
msgid "Javier Casares"
msgstr ""
#. Author URI of the plugin/theme
msgid "https://www.javiercasares.com/"
msgstr ""

View file

@ -1,11 +1,11 @@
=== Reply-To for WP_Mail === === Reply-To for WP_Mail ===
Contributors: javiercasares Contributors: javiercasares
Tags: email, reply-to, mail, smtp Tags: email, reply-to, mail, smtp
Requires at least: 4.1 Requires at least: 3.6
Tested up to: 6.9 Tested up to: 7.1
Stable tag: 2.0.0 Stable tag: 2.0.2
Requires PHP: 5.6 Requires PHP: 5.6
Version: 2.0.0 Version: 2.0.2
License: GPL-3.0-or-later License: GPL-3.0-or-later
License URI: https://www.gnu.org/licenses/gpl-3.0.txt License URI: https://www.gnu.org/licenses/gpl-3.0.txt
@ -15,70 +15,131 @@ Configure different "Reply-To" addresses by email context with validation, moder
The Reply-To for WP_Mail plugin allows you to easily manage the "Reply-To" header for all emails sent from your WordPress site. With this plugin, you can specify a custom email address that recipients will use when replying to your site's emails, ensuring that responses go to the correct inbox. The Reply-To for WP_Mail plugin allows you to easily manage the "Reply-To" header for all emails sent from your WordPress site. With this plugin, you can specify a custom email address that recipients will use when replying to your site's emails, ensuring that responses go to the correct inbox.
Configure a different Reply-To address for each type of email: password resets, comment notifications, user registrations, system updates, and WooCommerce orders.
Two developer filters are available for advanced customization:
* `wp_mail_replyto_context` — override the detected email context.
* `wp_mail_replyto_header` — override or suppress the Reply-To header for a specific email.
== Installation == == Installation ==
= Automatic download =
Visit the plugin section in your WordPress admin, search for "Reply-To for WP Mail"; download and install the plugin.
= Manual download = = Manual download =
Extract the contents of the ZIP and upload the contents to the `/wp-content/plugins/replyto/` directory. Once uploaded, it will appear in your plugin list. Extract the contents of the ZIP and upload the contents to the `/wp-content/plugins/replyto/` directory. Once uploaded, it will appear in your plugin list.
== Frequently Asked Questions ==
= Will my existing Reply-To setting be preserved after upgrading from v1? =
Yes. The plugin automatically migrates your existing email address and name to the Default context on the first page load after upgrade.
= What happens if I configure a context but leave it disabled? =
Disabled contexts fall back to the Default Reply-To. If no Default is configured, no Reply-To header is added.
= Does this plugin work with WooCommerce? =
Yes. When WooCommerce is active, a dedicated WooCommerce tab appears so you can route order emails to a separate reply address.
= Does this plugin work on WordPress Multisite? =
Yes. Each site in a Multisite network maintains its own configuration. On uninstall, data is removed from all sites.
== Compatibility == == Compatibility ==
* WordPress: 4.1 - 6.9 * WordPress: 3.6 - 7.1
* PHP: 5.6 - 8.5 * PHP: 5.6 - 8.5
== Changelog == == Changelog ==
= [2.0.0] - 2026-01-20 = = 2.0.2 =
**Major Release - Context-Based Reply-To Routing** _Release date: 2026-06-05_
This major release combines multiple enhancements including context-based email routing, security improvements, and Reply-To name support. **Highlights**
**Added** * Translations added for Spanish (Spain) and Catalan.
* WordPress minimum version corrected to 3.6 based on actual function usage (wp-compat analysis).
* Context-based Reply-To routing - Configure different Reply-To addresses for different types of emails.
* Six email contexts: Default, Authentication & Security, Comments & Moderation, Users & Registration, System & Updates, WooCommerce.
* WooCommerce tab only visible when WooCommerce plugin is active.
* Intelligent context detection using backtrace analysis.
* Modern tabbed user interface using WordPress native nav-tab-wrapper.
* Visual status indicators on each tab (green = active with email, red = inactive or no email).
* Legend explaining status indicators for easy understanding.
* Enable/disable toggle for each context (except Default which is always active).
* Fallback chain: Specific context → Default context → Legacy settings.
* Detailed descriptions and examples for each context in the admin UI.
* Reply-To Name field - Now you can specify a name to display with the Reply-To email address (e.g., "Support Team <support@example.com>").
* Name sanitization with header injection prevention.
* Length validation for name field (255 characters maximum).
* Created uninstall.php for proper cleanup of plugin data on uninstallation.
* Implemented logging of configuration changes for security auditing (requires WP_DEBUG_LOG).
* Added DNS validation for email domains with user-friendly warnings.
* Enhanced email validation with additional security checks.
* Added success/error messages for better user feedback.
**Changed** **Changed**
* Complete rewrite of settings page with modern tab-based interface. * Minimum WordPress version updated from 4.1 to 3.6.
* Email detection now uses backtrace analysis for accurate context identification. * Tested up to WordPress 7.1.
* Settings structure changed from individual options to array-based configuration (wp_mail_replyto_contexts). * POT file regenerated via WP-CLI i18n.
* Improved sanitization and validation for multiple contexts.
* Enhanced logging with context information in debug mode.
* Email header construction now supports both name and email format.
* Updated sanitize callback to use custom function with enhanced validation.
* Improved security documentation and code comments.
**Security Enhancements** **Added**
* Added explicit header injection prevention with defense-in-depth validation. * Spanish (Spain) translation (es_ES).
* Implemented strict RFC 5322 email format validation. * Catalan translation (ca).
* Enhanced input sanitization with multiple validation layers.
**Technical** **Compatibility**
* New database structure: Single serialized array instead of multiple options (more efficient). * WordPress: 3.6 - 7.1
* Backward compatible: Legacy options (v1.0.x) still work during migration period. * PHP: 5.6 - 8.5
* Context detection covers: Password resets, comments, user registration, system updates, WooCommerce emails.
* Clean uninstallation: Removes all options including migration flags. **Tests**
* Automatic migration from v1.0.x - Your existing settings are preserved in the Default context.
* PHP Coding Standards: 3.13.5
* WordPress Coding Standards: 3.3.0
* PHPStan: 2.2.2 (level 9)
* PHPUnit: 9.6.34
= 2.0.1 =
_Release date: 2026-06-05_
**Highlights**
* Major bugfix release addressing three critical issues found during pre-deploy audit.
**Fixed**
* Context cache not resetting between emails in the same PHP process.
* Duplicate Reply-To header injected when an existing Reply-To was present.
* Migration hook only running on admin_init — missed WP-CLI activations.
* RFC 5322 display name quoting now applied only when the name contains special characters.
**Added**
* Developer filters: wp_mail_replyto_context and wp_mail_replyto_header.
* load_plugin_textdomain() for translation support on WordPress < 4.6.
**Security**
* sanitize_callback added to legacy option registrations.
**Compatibility**
* WordPress: 4.1 - 6.9
* PHP: 5.6 - 8.5
**Tests**
* PHP Coding Standards: 3.13.5
* WordPress Coding Standards: 3.3.0
* PHPStan: 2.2.2 (level 9)
* PHPUnit: 9.6.34
= 2.0.0 =
_Release date: 2026-01-20_
**Highlights**
* Complete rewrite with context-based Reply-To routing.
**Added**
* Six email contexts: Default, Authentication, Comments, Users, System, WooCommerce.
* Modern tabbed admin interface with visual status indicators.
* Reply-To display name field with header injection prevention.
* Automatic migration from v1.0.x settings.
* uninstall.php for clean data removal.
**Compatibility** **Compatibility**
@ -91,38 +152,27 @@ This major release combines multiple enhancements including context-based email
* WordPress Coding Standards: 3.3.0 * WordPress Coding Standards: 3.3.0
* Plugin Check (PCP): 1.4.0 * Plugin Check (PCP): 1.4.0
= [1.0.3] - 2025-04-08 = = Previous versions =
**Changed** If you want to see the full changelog, visit the [changelog.txt](https://git.robotstxt.es/ROBOTSTXT/replyto-dev/raw/branch/main/changelog.txt) file.
* Compatible with WordPress 6.8. == Upgrade Notice ==
* Improved functions documentation.
**Compatibility** = 2.0.2 =
Translations added for Spanish (Spain) and Catalan. WordPress minimum corrected to 3.6. Upgrade recommended.
* WordPress: 4.1 - 6.9 = 2.0.1 =
* PHP: 5.6 - 8.5 Bugfix release. Fixes context isolation between emails, duplicate Reply-To headers, and migration on WP-CLI. Upgrade recommended.
**Tests** = 2.0.0 =
Major release. Your existing Reply-To setting is automatically migrated to the new Default context — no manual action required.
* PHP Coding Standards: 3.12.1 == Compliance ==
* WordPress Coding Standards: 3.1.0
* Plugin Check (PCP): 1.4.0
= [1.0.2] - 2024-11-02 = This plugin adheres to the following security measures and review protocols for each version:
**Fixed** * [WordPress Plugin Handbook](https://developer.wordpress.org/plugins/)
* [WordPress Plugin Security](https://developer.wordpress.org/plugins/wordpress-org/plugin-security/)
* Preparation for GlotPress. * [WordPress APIs Security](https://developer.wordpress.org/apis/security/)
* [WordPress Coding Standards](https://github.com/WordPress/WordPress-Coding-Standards)
= [1.0.1] - 2024-10-31 = * [Plugin Check (PCP)](https://wordpress.org/plugins/plugin-check/)
**Added**
* Translation ready.
= [1.0.0] - 2024-10-22 =
**Added**
* First version.

View file

@ -2,9 +2,9 @@
/** /**
* Plugin Name: Reply-To for WP_Mail * Plugin Name: Reply-To for WP_Mail
* Description: Configure your "Reply-To:" for WP_Mail with validation, admin settings, and context-based routing. * Description: Configure your "Reply-To:" for WP_Mail with validation, admin settings, and context-based routing.
* Requires at least: 4.1 * Requires at least: 3.6
* Requires PHP: 5.6 * Requires PHP: 5.6
* Version: 2.0.0 * Version: 2.0.2
* Author: ROBOTSTXT * Author: ROBOTSTXT
* Author URI: https://www.robotstxt.es/ * Author URI: https://www.robotstxt.es/
* License: GPL-3.0-or-later * License: GPL-3.0-or-later
@ -14,18 +14,36 @@
* *
* @package replyto * @package replyto
* *
* @version 2.0.0 * @version 2.0.2
*/ */
defined( 'ABSPATH' ) || die( 'No script kiddies please!' ); defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
register_activation_hook( __FILE__, 'wp_mail_replyto_migrate_to_v200' );
/**
* Loads the plugin text domain.
*
* @since 2.0.0
*
* @return void
*/
function wp_mail_replyto_load_textdomain() {
load_plugin_textdomain( 'replyto', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
add_action( 'plugins_loaded', 'wp_mail_replyto_load_textdomain' );
add_action( 'plugins_loaded', 'wp_mail_replyto_migrate_to_v200' );
/** /**
* Performs automatic migration from v1.0.x to v2.0.0. * Performs automatic migration from v1.0.x to v2.0.0.
* *
* Migrates old single email/name options to new context-based structure. * Migrates old single email/name options to new context-based structure.
* Runs once on plugin activation or when version changes. * Runs on plugin activation, every request via plugins_loaded (idempotent).
* *
* @since 2.0.0 * @since 2.0.0
*
* @return void
*/ */
function wp_mail_replyto_migrate_to_v200() { function wp_mail_replyto_migrate_to_v200() {
// Check if migration has already been performed. // Check if migration has already been performed.
@ -35,8 +53,10 @@ function wp_mail_replyto_migrate_to_v200() {
} }
// Get old settings. // Get old settings.
$old_email = get_option( 'wp_mail_replyto_email', '' ); $old_email_raw = get_option( 'wp_mail_replyto_email', '' );
$old_name = get_option( 'wp_mail_replyto_name', '' ); $old_name_raw = get_option( 'wp_mail_replyto_name', '' );
$old_email = is_string( $old_email_raw ) ? $old_email_raw : '';
$old_name = is_string( $old_name_raw ) ? $old_name_raw : '';
// Check if old settings exist. // Check if old settings exist.
if ( ! empty( $old_email ) || ! empty( $old_name ) ) { if ( ! empty( $old_email ) || ! empty( $old_name ) ) {
@ -88,22 +108,28 @@ function wp_mail_replyto_migrate_to_v200() {
update_option( 'wp_mail_replyto_migration_v200', true ); update_option( 'wp_mail_replyto_migration_v200', true );
} }
add_action( 'admin_init', 'wp_mail_replyto_migrate_to_v200' );
/** /**
* Detects email context based on WordPress backtrace. * Detects email context based on WordPress backtrace.
* *
* Analyzes the call stack to determine what type of email is being sent * Analyzes the call stack to determine what type of email is being sent.
* and returns the appropriate context identifier. * Uses DEBUG_BACKTRACE_IGNORE_ARGS with a 20-frame limit for production safety.
* The detected value is cached in a static variable; pass $reset = true to clear
* the cache between emails (called automatically by wp_mail_replyto_reset_context).
* *
* @since 1.3.0 * @since 1.3.0
* *
* @param bool $reset If true, clears the static cache and returns without detecting.
* @return string Context: 'authentication', 'comments', 'users', 'system', 'woocommerce', or 'default'. * @return string Context: 'authentication', 'comments', 'users', 'system', 'woocommerce', or 'default'.
*/ */
function wp_mail_replyto_detect_context() { function wp_mail_replyto_detect_context( $reset = false ) {
static $context = null; static $context = null;
// Use cached value if available (for performance). if ( $reset ) {
$context = null;
return '';
}
// Use cached value if available (for performance within the same email).
if ( null !== $context ) { if ( null !== $context ) {
return $context; return $context;
} }
@ -112,6 +138,8 @@ function wp_mail_replyto_detect_context() {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace -- Not debug code: debug_backtrace() is essential for production context detection. It analyzes the call stack to identify which WordPress function is sending the email (e.g., retrieve_password, wp_notify_postauthor). This is the core functionality of the plugin, not debugging. The function is optimized with DEBUG_BACKTRACE_IGNORE_ARGS and limited to 20 frames for performance. // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace -- Not debug code: debug_backtrace() is essential for production context detection. It analyzes the call stack to identify which WordPress function is sending the email (e.g., retrieve_password, wp_notify_postauthor). This is the core functionality of the plugin, not debugging. The function is optimized with DEBUG_BACKTRACE_IGNORE_ARGS and limited to 20 frames for performance.
$backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 20 ); $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 20 );
$detected = 'default';
foreach ( $backtrace as $trace ) { foreach ( $backtrace as $trace ) {
if ( empty( $trace['function'] ) ) { if ( empty( $trace['function'] ) ) {
continue; continue;
@ -130,8 +158,8 @@ function wp_mail_replyto_detect_context() {
), ),
true true
) ) { ) ) {
$context = 'authentication'; $detected = 'authentication';
return $context; break;
} }
// Comments context. // Comments context.
@ -145,8 +173,8 @@ function wp_mail_replyto_detect_context() {
), ),
true true
) ) { ) ) {
$context = 'comments'; $detected = 'comments';
return $context; break;
} }
// Users context. // Users context.
@ -159,8 +187,8 @@ function wp_mail_replyto_detect_context() {
), ),
true true
) ) { ) ) {
$context = 'users'; $detected = 'users';
return $context; break;
} }
// System context. // System context.
@ -174,35 +202,46 @@ function wp_mail_replyto_detect_context() {
), ),
true true
) ) { ) ) {
$context = 'system'; $detected = 'system';
return $context; break;
} }
// WooCommerce context. // WooCommerce context.
if ( ! empty( $class ) && false !== strpos( $class, 'WC_Email' ) ) { if ( ! empty( $class ) && false !== strpos( $class, 'WC_Email' ) ) {
$context = 'woocommerce'; $detected = 'woocommerce';
return $context; break;
} }
} }
// Default context if no specific match. /**
$context = 'default'; * Filters the detected email context.
*
* Allows overriding the context before the Reply-To address is resolved.
* Return a custom context key to apply a different Reply-To configuration,
* or 'default' to use the fallback.
*
* @since 2.0.0
*
* @param string $detected Detected context: 'authentication', 'comments', 'users',
* 'system', 'woocommerce', or 'default'.
*/
$context = (string) apply_filters( 'wp_mail_replyto_context', $detected );
return $context; return $context;
} }
/** /**
* Resets the context cache after email is sent. * Resets the context cache after email is sent.
* *
* Ensures each email detection starts fresh. * Ensures each email detection starts fresh when multiple emails are sent
* within the same PHP process (e.g., WP-Cron, REST batch).
* *
* @since 1.3.0 * @since 1.3.0
* *
* @param array $args Email arguments. * @param array{to: string|string[], subject: string, message: string, headers: string|string[], attachments: string[]} $args Email arguments.
* @return array Unmodified email arguments. * @return array{to: string|string[], subject: string, message: string, headers: string|string[], attachments: string[]} Unmodified email arguments.
*/ */
function wp_mail_replyto_reset_context( $args ) { function wp_mail_replyto_reset_context( $args ) {
// Reset static cache in detect function. wp_mail_replyto_detect_context( true );
wp_mail_replyto_detect_context();
return $args; return $args;
} }
@ -213,37 +252,55 @@ add_filter( 'wp_mail', 'wp_mail_replyto_reset_context', 999 );
* *
* Detects email context and applies appropriate Reply-To based on configuration. * Detects email context and applies appropriate Reply-To based on configuration.
* Falls back to default context if specific context is not configured. * Falls back to default context if specific context is not configured.
* Removes any existing Reply-To header before injecting the configured value.
* *
* @since 1.3.0 Updated to support context-based Reply-To. * @since 1.3.0 Updated to support context-based Reply-To.
* *
* @param array $args The email arguments passed to wp_mail(). * @param array{to: string|string[], subject: string, message: string, headers: string|string[], attachments: string[]} $args The email arguments passed to wp_mail().
* @return array Modified email arguments with adjusted "Reply-To" header. * @return array{to: string|string[], subject: string, message: string, headers: string|string[], attachments: string[]} Modified email arguments with adjusted "Reply-To" header.
*/ */
function wp_mail_replyto( $args ) { function wp_mail_replyto( $args ) {
// Detect email context. // Detect email context.
$detected_context = wp_mail_replyto_detect_context(); $detected_context = wp_mail_replyto_detect_context();
// Get all contexts configuration. // Get all contexts configuration.
$contexts = get_option( 'wp_mail_replyto_contexts', array() ); $contexts_raw = get_option( 'wp_mail_replyto_contexts', array() );
$contexts = is_array( $contexts_raw ) ? $contexts_raw : array();
// Normalize the detected context entry.
$detected_ctx = isset( $contexts[ $detected_context ] ) && is_array( $contexts[ $detected_context ] )
? $contexts[ $detected_context ]
: array();
// Normalize the default context entry.
$default_ctx = isset( $contexts['default'] ) && is_array( $contexts['default'] )
? $contexts['default']
: array();
// Fallback chain: specific context -> default -> legacy. // Fallback chain: specific context -> default -> legacy.
$reply_to_email = ''; $reply_to_email = '';
$reply_to_name = ''; $reply_to_name = '';
// Try specific context first (if enabled). $detected_email = isset( $detected_ctx['email'] ) && is_string( $detected_ctx['email'] ) ? $detected_ctx['email'] : '';
if ( isset( $contexts[ $detected_context ] ) && $detected_enabled = ! empty( $detected_ctx['enabled'] );
! empty( $contexts[ $detected_context ]['enabled'] ) &&
! empty( $contexts[ $detected_context ]['email'] ) ) { if ( $detected_enabled && ! empty( $detected_email ) ) {
$reply_to_email = $contexts[ $detected_context ]['email']; // Specific context is configured and enabled.
$reply_to_name = $contexts[ $detected_context ]['name']; $reply_to_email = $detected_email;
} elseif ( isset( $contexts['default'] ) && ! empty( $contexts['default']['email'] ) ) { $reply_to_name = isset( $detected_ctx['name'] ) && is_string( $detected_ctx['name'] ) ? $detected_ctx['name'] : '';
// Fall back to default context.
$reply_to_email = $contexts['default']['email'];
$reply_to_name = $contexts['default']['name'];
} else { } else {
// Final fallback: legacy single option (for migration period). $default_email = isset( $default_ctx['email'] ) && is_string( $default_ctx['email'] ) ? $default_ctx['email'] : '';
$reply_to_email = get_option( 'wp_mail_replyto_email', '' ); if ( ! empty( $default_email ) ) {
$reply_to_name = get_option( 'wp_mail_replyto_name', '' ); // Fall back to default context.
$reply_to_email = $default_email;
$reply_to_name = isset( $default_ctx['name'] ) && is_string( $default_ctx['name'] ) ? $default_ctx['name'] : '';
} else {
// Final fallback: legacy single option (for migration period).
$legacy_email = get_option( 'wp_mail_replyto_email', '' );
$legacy_name = get_option( 'wp_mail_replyto_name', '' );
$reply_to_email = is_string( $legacy_email ) ? $legacy_email : '';
$reply_to_name = is_string( $legacy_name ) ? $legacy_name : '';
}
} }
// Explicit header injection prevention - defense in depth. // Explicit header injection prevention - defense in depth.
@ -256,55 +313,61 @@ function wp_mail_replyto( $args ) {
} }
// Construct the new "Reply-To" header if a valid email address is set. // Construct the new "Reply-To" header if a valid email address is set.
$new_reply_to = '';
if ( ! empty( $reply_to_email ) && is_email( $reply_to_email ) ) { if ( ! empty( $reply_to_email ) && is_email( $reply_to_email ) ) {
$safe_email = sanitize_email( $reply_to_email );
if ( ! empty( $reply_to_name ) ) { if ( ! empty( $reply_to_name ) ) {
// Include name in Reply-To header. $display_name = sanitize_text_field( $reply_to_name );
$new_reply_to = 'Reply-To: ' . sanitize_text_field( $reply_to_name ) . ' <' . sanitize_email( $reply_to_email ) . '>'; // Strip any surrounding double-quotes the user may have typed manually.
$display_name = trim( $display_name, '"' );
// RFC 5322 specials that require a quoted-string: ( ) < > [ ] : ; @ backslash comma period and double-quote.
if ( preg_match( '/[()<>\[\]:;@\\\\,."\\r\\n]/', $display_name ) ) {
$safe_name = str_replace( array( '\\', '"' ), array( '\\\\', '\\"' ), $display_name );
$new_reply_to = 'Reply-To: "' . $safe_name . '" <' . $safe_email . '>';
} else {
// Simple phrase: no quoting needed.
$new_reply_to = 'Reply-To: ' . $display_name . ' <' . $safe_email . '>';
}
} else { } else {
// Email only. // Email only.
$new_reply_to = 'Reply-To: <' . sanitize_email( $reply_to_email ) . '>'; $new_reply_to = 'Reply-To: <' . $safe_email . '>';
} }
} }
// Initialize variables to track the "From" and existing "Reply-To" headers. /**
$from = ''; * Filters the Reply-To header string before injection.
$existing_reply_to = ''; *
* Return an empty string to suppress Reply-To injection for this email.
*
* @since 2.0.0
*
* @param string $new_reply_to The constructed Reply-To header (e.g. 'Reply-To: <user@example.com>').
* @param array{to: string|string[], subject: string, message: string, headers: string|string[], attachments: string[]} $args The wp_mail arguments.
*/
$new_reply_to = (string) apply_filters( 'wp_mail_replyto_header', $new_reply_to, $args );
// Check if email headers exist. // Check if email headers exist.
if ( ! empty( $args['headers'] ) ) { if ( ! empty( $args['headers'] ) ) {
// Normalize headers into an array if they are not already. // Normalize headers into an array if they are not already.
if ( ! is_array( $args['headers'] ) ) { if ( ! is_array( $args['headers'] ) ) {
$args['headers'] = array_filter( explode( "\n", str_replace( "\r\n", "\n", $args['headers'] ) ) );
}
// Loop through the headers to locate "From" and "Reply-To" values.
foreach ( $args['headers'] as $header ) {
if ( stripos( $header, 'from:' ) === 0 ) {
$from = trim( substr( $header, strlen( 'from:' ) ) );
}
if ( stripos( $header, 'reply-to:' ) === 0 ) {
$existing_reply_to = trim( substr( $header, strlen( 'reply-to:' ) ) );
}
}
// If "Reply-To" exists and matches the "From" address, replace it with the new one.
if ( ! empty( $existing_reply_to ) && strtolower( $existing_reply_to ) === strtolower( $from ) ) {
// Remove the existing "Reply-To" header.
$args['headers'] = array_filter( $args['headers'] = array_filter(
$args['headers'], explode( "\n", str_replace( array( "\r\n", "\r" ), "\n", $args['headers'] ) )
function ( $header ) {
return stripos( $header, 'reply-to:' ) !== 0;
}
); );
}
// Add the new "Reply-To" header. if ( ! empty( $new_reply_to ) ) {
$args['headers'][] = $new_reply_to; // Remove any existing Reply-To header unconditionally (RFC 5322 allows only one).
$args['headers'] = array_values(
} elseif ( isset( $new_reply_to ) ) { array_filter(
// If no conflicting "Reply-To" is found, append the new one. $args['headers'],
function ( $header ) {
return stripos( $header, 'reply-to:' ) !== 0;
}
)
);
$args['headers'][] = $new_reply_to; $args['headers'][] = $new_reply_to;
} }
} elseif ( isset( $new_reply_to ) ) { } elseif ( ! empty( $new_reply_to ) ) {
// If no headers exist at all, create a new headers array with the "Reply-To". // If no headers exist at all, create a new headers array with the "Reply-To".
$args['headers'] = array( $new_reply_to ); $args['headers'] = array( $new_reply_to );
} }
@ -320,6 +383,8 @@ add_filter( 'wp_mail', 'wp_mail_replyto' );
* *
* Adds a new page under the "Settings" menu where administrators can configure * Adds a new page under the "Settings" menu where administrators can configure
* the "Reply-To" email address used in outgoing emails. * the "Reply-To" email address used in outgoing emails.
*
* @return void
*/ */
function wp_mail_replyto_add_settings_page() { function wp_mail_replyto_add_settings_page() {
add_options_page( add_options_page(
@ -363,91 +428,14 @@ function wp_mail_replyto_validate_email_strict( $email ) {
return true; return true;
} }
/**
* Sanitizes and logs changes to the Reply-To email setting.
*
* This function sanitizes the input email address and logs any changes
* for security auditing purposes. It's used as the sanitize_callback
* for the plugin settings.
*
* @since 1.1.0
*
* @param string $input The input email address to sanitize.
* @return string The sanitized email address.
*/
function wp_mail_replyto_sanitize_and_log( $input ) {
// Sanitize the email address.
$sanitized = sanitize_email( $input );
// Get the old value for comparison.
$old_value = get_option( 'wp_mail_replyto_email', '' );
// Perform strict validation.
if ( ! empty( $sanitized ) && ! wp_mail_replyto_validate_email_strict( $sanitized ) ) {
add_settings_error(
'wp_mail_replyto_messages',
'wp_mail_replyto_invalid_email',
esc_html__( 'The email address format is not valid. Please check and try again.', 'replyto' ),
'error'
);
// Return the old value if validation fails.
return $old_value;
}
// Check domain existence (optional validation with warning only).
if ( ! empty( $sanitized ) ) {
$domain = substr( strrchr( $sanitized, '@' ), 1 );
if ( ! empty( $domain ) && function_exists( 'checkdnsrr' ) ) {
if ( ! checkdnsrr( $domain, 'MX' ) && ! checkdnsrr( $domain, 'A' ) ) {
add_settings_error(
'wp_mail_replyto_messages',
'wp_mail_replyto_domain_warning',
esc_html__( 'Warning: The email domain does not appear to have valid DNS records. The email may not work correctly.', 'replyto' ),
'warning'
);
}
}
}
// Log changes for security auditing.
if ( $old_value !== $sanitized ) {
$user = wp_get_current_user();
// Use error_log for logging (can be configured in wp-config.php).
if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- Intentional: error_log() is used for security audit logging, not debugging. Only active when WP_DEBUG_LOG is enabled. Records configuration changes with user info and IP for security compliance and troubleshooting. This is a production feature for administrators who enable logging in wp-config.php.
error_log(
sprintf(
'[Reply-To Plugin] Email changed from "%s" to "%s" by user %s (ID: %d) from IP: %s',
$old_value,
$sanitized,
$user->user_login,
$user->ID,
isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : 'unknown'
)
);
}
// Add success message if change was successful.
if ( ! empty( $sanitized ) || ! empty( $old_value ) ) {
add_settings_error(
'wp_mail_replyto_messages',
'wp_mail_replyto_updated',
esc_html__( 'Reply-To email address updated successfully.', 'replyto' ),
'success'
);
}
}
return $sanitized;
}
/** /**
* Registers the plugin settings, section, and field in the WordPress Settings API. * Registers the plugin settings, section, and field in the WordPress Settings API.
* *
* This function defines the context-based configuration structure. * This function defines the context-based configuration structure.
* *
* @since 1.3.0 Updated to support multiple contexts. * @since 1.3.0 Updated to support multiple contexts.
*
* @return void
*/ */
function wp_mail_replyto_register_settings() { function wp_mail_replyto_register_settings() {
// Register the contexts setting. // Register the contexts setting.
@ -461,13 +449,14 @@ function wp_mail_replyto_register_settings() {
) )
); );
// Keep legacy settings registered for backward compatibility during migration. // Legacy settings kept for backward compatibility during migration.
register_setting( register_setting(
'wp_mail_replyto_settings_group', 'wp_mail_replyto_settings_group',
'wp_mail_replyto_email', 'wp_mail_replyto_email',
array( array(
'type' => 'string', 'type' => 'string',
'default' => '', 'sanitize_callback' => 'sanitize_email',
'default' => '',
) )
); );
@ -475,8 +464,9 @@ function wp_mail_replyto_register_settings() {
'wp_mail_replyto_settings_group', 'wp_mail_replyto_settings_group',
'wp_mail_replyto_name', 'wp_mail_replyto_name',
array( array(
'type' => 'string', 'type' => 'string',
'default' => '', 'sanitize_callback' => 'sanitize_text_field',
'default' => '',
) )
); );
} }
@ -486,13 +476,13 @@ add_action( 'admin_init', 'wp_mail_replyto_register_settings' );
/** /**
* Sanitizes and validates the contexts configuration. * Sanitizes and validates the contexts configuration.
* *
* Validates all context email addresses and names, provides appropriate * Validates all context email addresses and names, performs DNS validation,
* error messages, and logs changes. * provides appropriate error messages, and logs changes.
* *
* @since 1.3.0 * @since 1.3.0
* *
* @param array $input The input contexts array. * @param array<string, mixed> $input The input contexts array.
* @return array The sanitized contexts array. * @return array<string, array{email: string, name: string, enabled: bool}> The sanitized contexts array.
*/ */
function wp_mail_replyto_sanitize_contexts( $input ) { function wp_mail_replyto_sanitize_contexts( $input ) {
$sanitized = array(); $sanitized = array();
@ -513,9 +503,11 @@ function wp_mail_replyto_sanitize_contexts( $input ) {
foreach ( $available_contexts as $context_key => $context_label ) { foreach ( $available_contexts as $context_key => $context_label ) {
// Get input for this context. // Get input for this context.
$email = isset( $input[ $context_key ]['email'] ) ? sanitize_email( $input[ $context_key ]['email'] ) : ''; $ctx_input = isset( $input[ $context_key ] ) && is_array( $input[ $context_key ] ) ? $input[ $context_key ] : array();
$name = isset( $input[ $context_key ]['name'] ) ? sanitize_text_field( $input[ $context_key ]['name'] ) : ''; $email = isset( $ctx_input['email'] ) && is_string( $ctx_input['email'] ) ? sanitize_email( $ctx_input['email'] ) : '';
$enabled = isset( $input[ $context_key ]['enabled'] ) && '1' === $input[ $context_key ]['enabled']; $name = isset( $ctx_input['name'] ) && is_string( $ctx_input['name'] ) ? sanitize_text_field( $ctx_input['name'] ) : '';
$enabled_raw = isset( $ctx_input['enabled'] ) ? $ctx_input['enabled'] : '';
$enabled = '1' === $enabled_raw || true === $enabled_raw;
// Header injection prevention. // Header injection prevention.
if ( ! empty( $email ) ) { if ( ! empty( $email ) ) {
@ -537,8 +529,36 @@ function wp_mail_replyto_sanitize_contexts( $input ) {
$email = ''; $email = '';
} }
// Limit name length. // Check domain existence (optional validation with warning only).
if ( strlen( $name ) > 255 ) { if ( ! empty( $email ) && function_exists( 'checkdnsrr' ) ) {
$domain_str = strrchr( $email, '@' );
if ( false !== $domain_str ) {
$domain = substr( $domain_str, 1 );
if ( ! empty( $domain ) && ! checkdnsrr( $domain, 'MX' ) && ! checkdnsrr( $domain, 'A' ) ) {
add_settings_error(
'wp_mail_replyto_messages',
'wp_mail_replyto_domain_warning_' . $context_key,
/* translators: %s: context name */
sprintf( esc_html__( 'Warning: The email domain for %s context does not appear to have valid DNS records.', 'replyto' ), $context_label ),
'warning'
);
}
}
}
// Limit name length (multibyte-aware).
if ( function_exists( 'mb_strlen' ) ) {
if ( mb_strlen( $name, 'UTF-8' ) > 255 ) {
$name = mb_substr( $name, 0, 255, 'UTF-8' );
add_settings_error(
'wp_mail_replyto_messages',
'wp_mail_replyto_name_long_' . $context_key,
/* translators: %s: context name */
sprintf( esc_html__( 'Name for %s context was truncated to 255 characters.', 'replyto' ), $context_label ),
'warning'
);
}
} elseif ( strlen( $name ) > 255 ) {
$name = substr( $name, 0, 255 ); $name = substr( $name, 0, 255 );
add_settings_error( add_settings_error(
'wp_mail_replyto_messages', 'wp_mail_replyto_messages',
@ -565,7 +585,11 @@ function wp_mail_replyto_sanitize_contexts( $input ) {
// Log changes if in debug mode. // Log changes if in debug mode.
$old_value = get_option( 'wp_mail_replyto_contexts', array() ); $old_value = get_option( 'wp_mail_replyto_contexts', array() );
if ( $old_value !== $sanitized ) { if ( $old_value !== $sanitized ) {
$user = wp_get_current_user(); $user = wp_get_current_user();
$remote_addr = isset( $_SERVER['REMOTE_ADDR'] ) && is_string( $_SERVER['REMOTE_ADDR'] )
? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) )
: 'unknown';
if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) { if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- Intentional: error_log() is used for security audit logging, not debugging. Only active when WP_DEBUG_LOG is enabled. Records context configuration changes with user info and IP for security compliance and troubleshooting. This is a production feature for administrators who enable logging in wp-config.php. // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- Intentional: error_log() is used for security audit logging, not debugging. Only active when WP_DEBUG_LOG is enabled. Records context configuration changes with user info and IP for security compliance and troubleshooting. This is a production feature for administrators who enable logging in wp-config.php.
error_log( error_log(
@ -573,7 +597,7 @@ function wp_mail_replyto_sanitize_contexts( $input ) {
'[Reply-To Plugin] Contexts configuration updated by user %s (ID: %d) from IP: %s', '[Reply-To Plugin] Contexts configuration updated by user %s (ID: %d) from IP: %s',
$user->user_login, $user->user_login,
$user->ID, $user->ID,
isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : 'unknown' $remote_addr
) )
); );
} }
@ -595,14 +619,18 @@ function wp_mail_replyto_sanitize_contexts( $input ) {
* @since 1.3.0 * @since 1.3.0
* *
* @param string $hook The current admin page hook. * @param string $hook The current admin page hook.
* @return void
*/ */
function wp_mail_replyto_admin_styles( $hook ) { function wp_mail_replyto_admin_styles( $hook ) {
if ( 'settings_page_replyto' !== $hook ) { if ( 'settings_page_replyto' !== $hook ) {
return; return;
} }
?>
<style> wp_register_style( 'replyto-admin', false, array(), '2.0.2' );
.replyto-context-description { wp_enqueue_style( 'replyto-admin' );
wp_add_inline_style(
'replyto-admin',
'.replyto-context-description {
margin: 10px 0 20px; margin: 10px 0 20px;
padding: 10px; padding: 10px;
background: #f0f6fc; background: #f0f6fc;
@ -642,9 +670,8 @@ function wp_mail_replyto_admin_styles( $hook ) {
} }
.replyto-status-legend span { .replyto-status-legend span {
margin-right: 15px; margin-right: 15px;
} }'
</style> );
<?php
} }
add_action( 'admin_enqueue_scripts', 'wp_mail_replyto_admin_styles' ); add_action( 'admin_enqueue_scripts', 'wp_mail_replyto_admin_styles' );
@ -655,6 +682,8 @@ add_action( 'admin_enqueue_scripts', 'wp_mail_replyto_admin_styles' );
* Uses WordPress native nav-tab-wrapper for consistent admin UI. * Uses WordPress native nav-tab-wrapper for consistent admin UI.
* *
* @since 1.3.0 Completely rewritten with tabs interface. * @since 1.3.0 Completely rewritten with tabs interface.
*
* @return void
*/ */
function wp_mail_replyto_render_settings_page() { function wp_mail_replyto_render_settings_page() {
// Check if the current user has the required capability. // Check if the current user has the required capability.
@ -663,11 +692,13 @@ function wp_mail_replyto_render_settings_page() {
} }
// Get current contexts configuration. // Get current contexts configuration.
$contexts = get_option( 'wp_mail_replyto_contexts', array() ); $contexts_raw = get_option( 'wp_mail_replyto_contexts', array() );
$contexts = is_array( $contexts_raw ) ? $contexts_raw : array();
// Get active tab from URL, default to 'default'. // Get active tab from URL, default to 'default'.
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Tab parameter is for display only, not data modification. // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Tab parameter is for display only, not data modification.
$active_tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'default'; $active_tab_raw = isset( $_GET['tab'] ) && is_string( $_GET['tab'] ) ? $_GET['tab'] : 'default';
$active_tab = sanitize_key( $active_tab_raw );
// Define contexts with descriptions. // Define contexts with descriptions.
$context_config = array( $context_config = array(
@ -731,8 +762,9 @@ function wp_mail_replyto_render_settings_page() {
); );
// Determine status indicator. // Determine status indicator.
$ctx_email = isset( $contexts[ $key ]['email'] ) ? $contexts[ $key ]['email'] : ''; $ctx_data = isset( $contexts[ $key ] ) && is_array( $contexts[ $key ] ) ? $contexts[ $key ] : array();
$ctx_enabled = isset( $contexts[ $key ]['enabled'] ) ? $contexts[ $key ]['enabled'] : false; $ctx_email = isset( $ctx_data['email'] ) && is_string( $ctx_data['email'] ) ? $ctx_data['email'] : '';
$ctx_enabled = ! empty( $ctx_data['enabled'] );
// For Default context: only check if email exists (always enabled). // For Default context: only check if email exists (always enabled).
// For other contexts: check if enabled AND email exists. // For other contexts: check if enabled AND email exists.
@ -763,10 +795,11 @@ function wp_mail_replyto_render_settings_page() {
<div class="replyto-tab-content"> <div class="replyto-tab-content">
<?php <?php
$config = $context_config[ $active_tab ]; $config = isset( $context_config[ $active_tab ] ) ? $context_config[ $active_tab ] : $context_config['default'];
$email = isset( $contexts[ $active_tab ]['email'] ) ? $contexts[ $active_tab ]['email'] : ''; $active_data = isset( $contexts[ $active_tab ] ) && is_array( $contexts[ $active_tab ] ) ? $contexts[ $active_tab ] : array();
$name = isset( $contexts[ $active_tab ]['name'] ) ? $contexts[ $active_tab ]['name'] : ''; $email = isset( $active_data['email'] ) && is_string( $active_data['email'] ) ? $active_data['email'] : '';
$enabled = isset( $contexts[ $active_tab ]['enabled'] ) ? $contexts[ $active_tab ]['enabled'] : false; $name = isset( $active_data['name'] ) && is_string( $active_data['name'] ) ? $active_data['name'] : '';
$enabled = ! empty( $active_data['enabled'] );
?> ?>
<div class="replyto-context-description"> <div class="replyto-context-description">
@ -844,9 +877,10 @@ function wp_mail_replyto_render_settings_page() {
continue; continue;
} }
$ctx_email = isset( $contexts[ $key ]['email'] ) ? $contexts[ $key ]['email'] : ''; $ctx_data = isset( $contexts[ $key ] ) && is_array( $contexts[ $key ] ) ? $contexts[ $key ] : array();
$ctx_name = isset( $contexts[ $key ]['name'] ) ? $contexts[ $key ]['name'] : ''; $ctx_email = isset( $ctx_data['email'] ) && is_string( $ctx_data['email'] ) ? $ctx_data['email'] : '';
$ctx_enabled = isset( $contexts[ $key ]['enabled'] ) ? $contexts[ $key ]['enabled'] : false; $ctx_name = isset( $ctx_data['name'] ) && is_string( $ctx_data['name'] ) ? $ctx_data['name'] : '';
$ctx_enabled = ! empty( $ctx_data['enabled'] );
?> ?>
<input type="hidden" name="wp_mail_replyto_contexts[<?php echo esc_attr( $key ); ?>][email]" value="<?php echo esc_attr( $ctx_email ); ?>" /> <input type="hidden" name="wp_mail_replyto_contexts[<?php echo esc_attr( $key ); ?>][email]" value="<?php echo esc_attr( $ctx_email ); ?>" />
<input type="hidden" name="wp_mail_replyto_contexts[<?php echo esc_attr( $key ); ?>][name]" value="<?php echo esc_attr( $ctx_name ); ?>" /> <input type="hidden" name="wp_mail_replyto_contexts[<?php echo esc_attr( $key ); ?>][name]" value="<?php echo esc_attr( $ctx_name ); ?>" />