diff --git a/languages/wp-mail-replyto.pot b/languages/wp-mail-replyto.pot index 64ee4e1..55e08f1 100644 --- a/languages/wp-mail-replyto.pot +++ b/languages/wp-mail-replyto.pot @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: Reply-To for WP_Mail\n" -"POT-Creation-Date: 2024-11-02 10:48+0100\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" @@ -10,50 +10,43 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" -"X-Generator: Poedit 3.5\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-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" -#. translators: %s: email address -#: replyto.php:36 -#, php-format -msgid "Reply-To: <%s>" -msgstr "" - -#: replyto.php:90 +#: replyto.php:97 msgid "WP Mail Reply-To Settings" msgstr "" -#: replyto.php:91 +#: replyto.php:98 msgid "Reply-To" msgstr "" -#: replyto.php:115 +#: replyto.php:130 msgid "Reply-To Configuration" msgstr "" -#: replyto.php:122 +#: replyto.php:138 msgid "Reply-To Email Address" msgstr "" -#: replyto.php:134 +#: replyto.php:154 msgid "" "Set the email address to be used in the \"Reply-To\" header of outgoing " "emails." msgstr "" -#: replyto.php:143 +#: replyto.php:169 msgid "Enter the email address to be used as \"Reply-To\"." msgstr "" -#: replyto.php:163 +#: replyto.php:194 msgid "Save Settings" msgstr "" diff --git a/readme.txt b/readme.txt index 4266e3a..83e8c1a 100644 --- a/readme.txt +++ b/readme.txt @@ -2,10 +2,10 @@ Contributors: javiercasares Tags: email, reply-to Requires at least: 4.1 -Tested up to: 6.7 -Stable tag: 1.0.2 +Tested up to: 6.8 +Stable tag: 1.0.3 Requires PHP: 5.6 -Version: 1.0.2 +Version: 1.0.3 License: GPL-2.0-or-later License URI: https://spdx.org/licenses/GPL-2.0-or-later.html @@ -23,11 +23,29 @@ Extract the contents of the ZIP and upload the contents to the `/wp-content/plug == Compatibility == -* WordPress: 4.1 - 6.7 +* WordPress: 4.1 - 6.8 * PHP: 5.6 - 8.4 == Changelog == += [1.0.3] - 2025-04-08 = + +**Changed** + +* Compatible with WordPress 6.8. +* Improved functions documentation. + +**Compatibility** + +* WordPress: 4.1 - 6.8 +* PHP: 5.6 - 8.4 + +**Tests** + +* PHP Coding Standards: 3.12.1 +* WordPress Coding Standards: 3.1.0 +* Plugin Check (PCP): 1.4.0 + = [1.0.2] - 2024-11-02 = **Fixed** diff --git a/replyto.php b/replyto.php index 3a1df97..692b3d7 100644 --- a/replyto.php +++ b/replyto.php @@ -4,7 +4,7 @@ * Description: Configure your "Reply-To:" for WP_Mail with validation and admin settings. * Requires at least: 4.1 * Requires PHP: 5.6 - * Version: 1.0.2 + * Version: 1.0.3 * Author: Javier Casares * Author URI: https://www.javiercasares.com/ * License: GPL-2.0-or-later @@ -20,36 +20,35 @@ defined( 'ABSPATH' ) || die( 'No script kiddies please!' ); /** - * Configure the "Reply-To" header for emails sent by WP Mail. + * Modifies the "Reply-To" header in emails sent using wp_mail(). * - * @param array $args Email arguments. - * @return array Modified email arguments. + * Retrieves the "Reply-To" email address from the plugin settings, validates it, + * and injects it into the email headers if appropriate. + * + * @param array $args The email arguments passed to wp_mail(). + * @return array Modified email arguments with adjusted "Reply-To" header. */ function wp_mail_replyto( $args ) { - // Get the "Reply-To" email from plugin settings. + // Retrieve the "Reply-To" email address from plugin settings. $reply_to_email = get_option( 'wp_mail_replyto_email' ); - // Define the new "Reply-To" if configured. - if ( ! empty( $reply_to_email ) ) { - $new_reply_to = sprintf( - /* translators: %s: email address */ - __( 'Reply-To: <%s>', 'replyto' ), - sanitize_email( $reply_to_email ) - ); + // Construct the new "Reply-To" header if a valid email address is set. + if ( ! empty( $reply_to_email ) && is_email( $reply_to_email ) ) { + $new_reply_to = 'Reply-To: <' . sanitize_email( $reply_to_email ) . '>'; } - // Initialize variables for "From" and existing "Reply-To". + // Initialize variables to track the "From" and existing "Reply-To" headers. $from = ''; $existing_reply_to = ''; - // Check if there are existing headers. + // Check if email headers exist. if ( ! empty( $args['headers'] ) ) { - // Normalize headers to an array. + // Normalize headers into an array if they are not already. if ( ! is_array( $args['headers'] ) ) { $args['headers'] = array_filter( explode( "\n", str_replace( "\r\n", "\n", $args['headers'] ) ) ); } - // Loop through headers to find "From" and "Reply-To". + // 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:' ) ) ); @@ -59,31 +58,39 @@ function wp_mail_replyto( $args ) { } } - // Check if "Reply-To" exists and compare with "From". + // 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 ) ) { - // If they are the same, replace "Reply-To" with the new one. - $args['headers'] = array_filter( + // Remove the existing "Reply-To" header. + $args['headers'] = array_filter( $args['headers'], function ( $header ) { return stripos( $header, 'reply-to:' ) !== 0; } ); + + // Add the new "Reply-To" header. $args['headers'][] = $new_reply_to; + } elseif ( isset( $new_reply_to ) ) { - // If "Reply-To" does not exist and new_reply_to is set, add it. + // If no conflicting "Reply-To" is found, append the new one. $args['headers'][] = $new_reply_to; } } elseif ( isset( $new_reply_to ) ) { - // If there are no headers and new_reply_to is set, create headers with "Reply-To". + // If no headers exist at all, create a new headers array with the "Reply-To". $args['headers'] = array( $new_reply_to ); } + // Return the modified email arguments. return $args; } + add_filter( 'wp_mail', 'wp_mail_replyto' ); /** - * Add a settings page to the WordPress admin menu. + * Registers a settings page for the plugin in the WordPress admin menu. + * + * Adds a new page under the "Settings" menu where administrators can configure + * the "Reply-To" email address used in outgoing emails. */ function wp_mail_replyto_add_settings_page() { add_options_page( @@ -94,12 +101,19 @@ function wp_mail_replyto_add_settings_page() { 'wp_mail_replyto_render_settings_page' ); } + add_action( 'admin_menu', 'wp_mail_replyto_add_settings_page' ); /** - * Register the plugin settings. + * Registers the plugin settings, section, and field in the WordPress Settings API. + * + * This function defines: + * - A setting for the "Reply-To" email address with sanitization. + * - A settings section with a description callback. + * - A field for entering the "Reply-To" email address. */ function wp_mail_replyto_register_settings() { + // Register the "Reply-To" email setting with sanitization. register_setting( 'wp_mail_replyto_settings_group', 'wp_mail_replyto_email', @@ -110,6 +124,7 @@ function wp_mail_replyto_register_settings() { ) ); + // Add a section to the settings page for organizing fields. add_settings_section( 'wp_mail_replyto_main_section', esc_html__( 'Reply-To Configuration', 'replyto' ), @@ -117,6 +132,7 @@ function wp_mail_replyto_register_settings() { 'replyto' ); + // Add the input field for the "Reply-To" email address. add_settings_field( 'wp_mail_replyto_email_field', esc_html__( 'Reply-To Email Address', 'replyto' ), @@ -125,39 +141,54 @@ function wp_mail_replyto_register_settings() { 'wp_mail_replyto_main_section' ); } + add_action( 'admin_init', 'wp_mail_replyto_register_settings' ); /** - * Callback for the settings section description. + * Outputs the description for the main settings section. + * + * This callback is used by the Settings API to display a description + * under the "Reply-To Configuration" section on the plugin settings page. */ function wp_mail_replyto_main_section_callback() { echo '

' . esc_html__( 'Set the email address to be used in the "Reply-To" header of outgoing emails.', 'replyto' ) . '

'; } /** - * Callback to render the email address field. + * Renders the input field for the "Reply-To" email address. + * + * This callback is used by the Settings API to display the input field + * where administrators can enter the email address to be used in the "Reply-To" header. */ function wp_mail_replyto_email_field_callback() { + // Get the current "Reply-To" email address from the plugin settings. $email = get_option( 'wp_mail_replyto_email', '' ); + + // Output the input field HTML. echo ''; echo '

' . esc_html__( 'Enter the email address to be used as "Reply-To".', 'replyto' ) . '

'; } /** - * Render the plugin settings page. + * Renders the plugin's settings page in the WordPress admin area. + * + * This function outputs the HTML structure and form elements for the plugin settings page. + * It includes the registered settings fields and sections for configuring the "Reply-To" email. */ function wp_mail_replyto_render_settings_page() { + // Check if the current user has the required capability. if ( ! current_user_can( 'manage_options' ) ) { return; } + // Display settings errors, if any. settings_errors( 'wp_mail_replyto_messages' ); ?>