This commit is contained in:
Javier Casares 2026-06-05 10:57:00 +00:00
commit 6f769cf5dd
6 changed files with 222 additions and 0 deletions

BIN
assets/icon-128x128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
assets/icon-256x256.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

BIN
assets/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

24
assets/icon.svg Normal file
View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg height="800px" width="800px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 512 512" xml:space="preserve">
<g>
<polygon style="fill:#CEE8FA;" points="348.632,315.499 310.369,347.136 272.106,315.499 268.721,315.499 123.386,435.666
123.386,439.058 497.352,439.058 497.352,435.666 352.017,315.499 "/>
<polygon style="fill:#CEE8FA;" points="219.929,151.439 219.929,187.235 123.386,187.235 123.386,192.532 310.369,347.136
497.353,192.532 497.353,151.439 "/>
</g>
<path style="fill:#2D527C;" d="M506.686,203.819c3.366-2.783,5.314-6.922,5.314-11.288v-41.093c0-8.088-6.559-14.647-14.647-14.647
H234.575v-21.15c0-8.088-6.557-14.647-14.647-14.647h-82.274V72.939c0-5.504-3.086-10.543-7.988-13.046
c-4.902-2.499-10.793-2.045-15.252,1.185L6.054,139.576C2.251,142.331,0,146.743,0,151.439c0,4.696,2.251,9.107,6.054,11.862
l102.684,74.388v112.376c0,8.088,6.557,14.647,14.647,14.647s14.647-6.559,14.647-14.647V223.647L247.427,314.1L114.052,424.379
c-3.366,2.783-5.314,6.922-5.314,11.288v3.392c0,8.088,6.557,14.647,14.647,14.647H497.35l0,0l0,0
c8.088,0,14.647-6.559,14.647-14.647V281.063c0-8.088-6.559-14.647-14.647-14.647s-14.647,6.559-14.647,14.647v123.49L373.308,314.1
L506.686,203.819z M234.576,166.085h248.13v19.552L339.308,304.203c-0.003,0.003-0.006,0.004-0.009,0.007l-28.93,23.921
l-28.93-23.921c-0.001-0.001-0.003-0.003-0.004-0.004L157.683,201.885h62.245c5.561,0,10.399-3.101,12.879-7.666
c1.128-2.075,1.768-4.454,1.768-6.982v-21.151H234.576z M108.36,201.241l-68.748-49.802l68.748-49.802v14.005
c0,8.088,6.557,14.647,14.647,14.647h82.274v42.301h-81.895c-0.01,0-0.019,0.001-0.028,0.001h-0.35
c-8.089,0-14.647,6.559-14.647,14.647v14.002H108.36z M460.757,424.413H159.983l110.431-91.308l30.622,25.32
c0.338,0.28,0.687,0.542,1.043,0.787c2.493,1.714,5.392,2.572,8.29,2.572c2.899,0,5.797-0.858,8.29-2.572
c0.356-0.245,0.704-0.507,1.043-0.787l30.624-25.321L460.757,424.413z"/>
</svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

35
readme.txt Normal file
View file

@ -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.

163
replyto.php Normal file
View file

@ -0,0 +1,163 @@
<?php
/**
* Plugin Name: Reply-To for WP_Mail
* 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.0
* Author: Javier Casares
* Author URI: https://www.javiercasares.com/
* License: GPL-2.0-or-later
* License URI: https://spdx.org/licenses/GPL-2.0-or-later.html
* Text Domain: wp-mail-replyto
*
* @package wp-mail-replyto
*
* @version 1.0.0
*/
defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
/**
* Configure the "Reply-To" header for emails sent by WP Mail.
*
* @param array $args Email arguments.
* @return array Modified email arguments.
*/
function wp_mail_replyto( $args ) {
// Get the "Reply-To" email 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 = 'Reply-To: <' . sanitize_email( $reply_to_email ) . '>';
}
// 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 '<p>' . esc_html__( 'Set the email address to be used in the "Reply-To" header of outgoing emails.', 'wp-mail-replyto' ) . '</p>';
}
/**
* Callback to render the email address field.
*/
function wp_mail_replyto_email_field_callback() {
$email = get_option( 'wp_mail_replyto_email', '' );
echo '<input type="email" id="wp_mail_replyto_email" name="wp_mail_replyto_email" value="' . esc_attr( $email ) . '" size="50" />';
echo '<p class="description">' . esc_html__( 'Enter the email address to be used as "Reply-To".', 'wp-mail-replyto' ) . '</p>';
}
/**
* 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' );
?>
<div class="wrap">
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
<form action="options.php" method="post">
<?php
wp_nonce_field();
settings_fields( 'wp_mail_replyto_settings_group' );
do_settings_sections( 'wp-mail-replyto' );
submit_button( esc_html__( 'Save Settings', 'wp-mail-replyto' ) );
?>
</form>
</div>
<?php
}