commit 6f769cf5dd59ad70fb553883afe89d6bb62eba95 Author: Javier Casares Date: Fri Jun 5 10:57:00 2026 +0000 v1.0.0 diff --git a/assets/icon-128x128.png b/assets/icon-128x128.png new file mode 100644 index 0000000..da44338 Binary files /dev/null and b/assets/icon-128x128.png differ diff --git a/assets/icon-256x256.png b/assets/icon-256x256.png new file mode 100644 index 0000000..fcce0ca Binary files /dev/null and b/assets/icon-256x256.png differ diff --git a/assets/icon.png b/assets/icon.png new file mode 100644 index 0000000..be6eec4 Binary files /dev/null and b/assets/icon.png differ diff --git a/assets/icon.svg b/assets/icon.svg new file mode 100644 index 0000000..157fe40 --- /dev/null +++ b/assets/icon.svg @@ -0,0 +1,24 @@ + + + + + + + + + \ No newline at end of file diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..9a65545 --- /dev/null +++ b/readme.txt @@ -0,0 +1,35 @@ +=== Reply-To for WP_Mail === +Contributors: javiercasares +Tags: email, reply-to +Requires at least: 4.1 +Tested up to: 6.7 +Stable tag: 1.0.0 +Requires PHP: 5.6 +Version: 1.0.0 +License: GPL-2.0-or-later +License URI: https://spdx.org/licenses/GPL-2.0-or-later.html + +Configure the "Reply-To" header for WordPress emails with validation and customizable admin settings. + +== Description == + +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. + +== Installation == + += 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. + +== Compatibility == + +* WordPress: 4.1 - 6.7 +* PHP: 5.6 - 8.4 + +== Changelog == + += [1.0.0] - 2024-10-22 = + +**Added** + +* First version. diff --git a/replyto.php b/replyto.php new file mode 100644 index 0000000..ae54004 --- /dev/null +++ b/replyto.php @@ -0,0 +1,163 @@ +'; + } + + // Initialize variables for "From" and existing "Reply-To". + $from = ''; + $existing_reply_to = ''; + + // Check if there are existing headers. + if ( ! empty( $args['headers'] ) ) { + // Normalize headers to an array. + 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". + 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:' ) ) ); + } + } + + // Check if "Reply-To" exists and compare with "From". + 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( + $args['headers'], + function ( $header ) { + return stripos( $header, 'reply-to:' ) !== 0; + } + ); + $args['headers'][] = $new_reply_to; + } elseif ( isset( $new_reply_to ) ) { + // If "Reply-To" does not exist and new_reply_to is set, add it. + $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". + $args['headers'] = array( $new_reply_to ); + } + + return $args; +} +add_filter( 'wp_mail', 'wp_mail_replyto' ); + +/** + * Add a settings page to the WordPress admin menu. + */ +function wp_mail_replyto_add_settings_page() { + add_options_page( + esc_html__( 'WP Mail Reply-To Settings', 'wp-mail-replyto' ), + esc_html__( 'Reply-To', 'wp-mail-replyto' ), + 'manage_options', + 'wp-mail-replyto', + 'wp_mail_replyto_render_settings_page' + ); +} +add_action( 'admin_menu', 'wp_mail_replyto_add_settings_page' ); + +/** + * Register the plugin settings. + */ +function wp_mail_replyto_register_settings() { + register_setting( + 'wp_mail_replyto_settings_group', + 'wp_mail_replyto_email', + array( + 'type' => 'string', + 'sanitize_callback' => 'sanitize_email', + 'default' => '', + ) + ); + + add_settings_section( + 'wp_mail_replyto_main_section', + esc_html__( 'Reply-To Configuration', 'wp-mail-replyto' ), + 'wp_mail_replyto_main_section_callback', + 'wp-mail-replyto' + ); + + add_settings_field( + 'wp_mail_replyto_email_field', + esc_html__( 'Reply-To Email Address', 'wp-mail-replyto' ), + 'wp_mail_replyto_email_field_callback', + 'wp-mail-replyto', + 'wp_mail_replyto_main_section' + ); +} +add_action( 'admin_init', 'wp_mail_replyto_register_settings' ); + +/** + * Callback for the settings section description. + */ +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.', 'wp-mail-replyto' ) . '

'; +} + +/** + * Callback to render the email address field. + */ +function wp_mail_replyto_email_field_callback() { + $email = get_option( 'wp_mail_replyto_email', '' ); + echo ''; + echo '

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

'; +} + +/** + * Render the plugin settings page. + */ +function wp_mail_replyto_render_settings_page() { + if ( ! current_user_can( 'manage_options' ) ) { + return; + } + + settings_errors( 'wp_mail_replyto_messages' ); + ?> +
+

+
+ +
+
+