Skip to content

Commit bbd0cf8

Browse files
Merge pull request #3 from javiercasares/wp68preparation
WordPress 6.8
2 parents fb1f053 + 0028928 commit bbd0cf8

3 files changed

Lines changed: 91 additions & 57 deletions

File tree

languages/wp-mail-replyto.pot

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,51 @@
22
msgid ""
33
msgstr ""
44
"Project-Id-Version: Reply-To for WP_Mail\n"
5-
"POT-Creation-Date: 2024-11-02 10:48+0100\n"
5+
"POT-Creation-Date: 2025-04-08 12:13+0200\n"
66
"PO-Revision-Date: 2024-10-31 08:58+0100\n"
77
"Last-Translator: \n"
88
"Language-Team: \n"
99
"MIME-Version: 1.0\n"
1010
"Content-Type: text/plain; charset=UTF-8\n"
1111
"Content-Transfer-Encoding: 8bit\n"
1212
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
13-
"X-Generator: Poedit 3.5\n"
13+
"X-Generator: Poedit 3.6\n"
1414
"X-Poedit-Basepath: ..\n"
1515
"X-Poedit-Flags-xgettext: --add-comments=translators:\n"
1616
"X-Poedit-WPHeader: replyto.php\n"
1717
"X-Poedit-SourceCharset: UTF-8\n"
18-
"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;"
19-
"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;"
20-
"_n_noop:1,2;_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
18+
"X-Poedit-KeywordsList: "
19+
"__;_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"
2120
"X-Poedit-SearchPath-0: .\n"
2221
"X-Poedit-SearchPathExcluded-0: *.min.js\n"
2322

24-
#. translators: %s: email address
25-
#: replyto.php:36
26-
#, php-format
27-
msgid "Reply-To: <%s>"
28-
msgstr ""
29-
30-
#: replyto.php:90
23+
#: replyto.php:97
3124
msgid "WP Mail Reply-To Settings"
3225
msgstr ""
3326

34-
#: replyto.php:91
27+
#: replyto.php:98
3528
msgid "Reply-To"
3629
msgstr ""
3730

38-
#: replyto.php:115
31+
#: replyto.php:130
3932
msgid "Reply-To Configuration"
4033
msgstr ""
4134

42-
#: replyto.php:122
35+
#: replyto.php:138
4336
msgid "Reply-To Email Address"
4437
msgstr ""
4538

46-
#: replyto.php:134
39+
#: replyto.php:154
4740
msgid ""
4841
"Set the email address to be used in the \"Reply-To\" header of outgoing "
4942
"emails."
5043
msgstr ""
5144

52-
#: replyto.php:143
45+
#: replyto.php:169
5346
msgid "Enter the email address to be used as \"Reply-To\"."
5447
msgstr ""
5548

56-
#: replyto.php:163
49+
#: replyto.php:194
5750
msgid "Save Settings"
5851
msgstr ""
5952

readme.txt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
Contributors: javiercasares
33
Tags: email, reply-to
44
Requires at least: 4.1
5-
Tested up to: 6.7
6-
Stable tag: 1.0.2
5+
Tested up to: 6.8
6+
Stable tag: 1.0.3
77
Requires PHP: 5.6
8-
Version: 1.0.2
8+
Version: 1.0.3
99
License: GPL-2.0-or-later
1010
License URI: https://spdx.org/licenses/GPL-2.0-or-later.html
1111

@@ -23,11 +23,29 @@ Extract the contents of the ZIP and upload the contents to the `/wp-content/plug
2323

2424
== Compatibility ==
2525

26-
* WordPress: 4.1 - 6.7
26+
* WordPress: 4.1 - 6.8
2727
* PHP: 5.6 - 8.4
2828

2929
== Changelog ==
3030

31+
= [1.0.3] - 2025-04-08 =
32+
33+
**Changed**
34+
35+
* Compatible with WordPress 6.8.
36+
* Improved functions documentation.
37+
38+
**Compatibility**
39+
40+
* WordPress: 4.1 - 6.8
41+
* PHP: 5.6 - 8.4
42+
43+
**Tests**
44+
45+
* PHP Coding Standards: 3.12.1
46+
* WordPress Coding Standards: 3.1.0
47+
* Plugin Check (PCP): 1.4.0
48+
3149
= [1.0.2] - 2024-11-02 =
3250

3351
**Fixed**

replyto.php

Lines changed: 58 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Description: Configure your "Reply-To:" for WP_Mail with validation and admin settings.
55
* Requires at least: 4.1
66
* Requires PHP: 5.6
7-
* Version: 1.0.2
7+
* Version: 1.0.3
88
* Author: Javier Casares
99
* Author URI: https://www.javiercasares.com/
1010
* License: GPL-2.0-or-later
@@ -20,36 +20,35 @@
2020
defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
2121

2222
/**
23-
* Configure the "Reply-To" header for emails sent by WP Mail.
23+
* Modifies the "Reply-To" header in emails sent using wp_mail().
2424
*
25-
* @param array $args Email arguments.
26-
* @return array Modified email arguments.
25+
* Retrieves the "Reply-To" email address from the plugin settings, validates it,
26+
* and injects it into the email headers if appropriate.
27+
*
28+
* @param array $args The email arguments passed to wp_mail().
29+
* @return array Modified email arguments with adjusted "Reply-To" header.
2730
*/
2831
function wp_mail_replyto( $args ) {
29-
// Get the "Reply-To" email from plugin settings.
32+
// Retrieve the "Reply-To" email address from plugin settings.
3033
$reply_to_email = get_option( 'wp_mail_replyto_email' );
3134

32-
// Define the new "Reply-To" if configured.
33-
if ( ! empty( $reply_to_email ) ) {
34-
$new_reply_to = sprintf(
35-
/* translators: %s: email address */
36-
__( 'Reply-To: <%s>', 'replyto' ),
37-
sanitize_email( $reply_to_email )
38-
);
35+
// Construct the new "Reply-To" header if a valid email address is set.
36+
if ( ! empty( $reply_to_email ) && is_email( $reply_to_email ) ) {
37+
$new_reply_to = 'Reply-To: <' . sanitize_email( $reply_to_email ) . '>';
3938
}
4039

41-
// Initialize variables for "From" and existing "Reply-To".
40+
// Initialize variables to track the "From" and existing "Reply-To" headers.
4241
$from = '';
4342
$existing_reply_to = '';
4443

45-
// Check if there are existing headers.
44+
// Check if email headers exist.
4645
if ( ! empty( $args['headers'] ) ) {
47-
// Normalize headers to an array.
46+
// Normalize headers into an array if they are not already.
4847
if ( ! is_array( $args['headers'] ) ) {
4948
$args['headers'] = array_filter( explode( "\n", str_replace( "\r\n", "\n", $args['headers'] ) ) );
5049
}
5150

52-
// Loop through headers to find "From" and "Reply-To".
51+
// Loop through the headers to locate "From" and "Reply-To" values.
5352
foreach ( $args['headers'] as $header ) {
5453
if ( stripos( $header, 'from:' ) === 0 ) {
5554
$from = trim( substr( $header, strlen( 'from:' ) ) );
@@ -59,31 +58,39 @@ function wp_mail_replyto( $args ) {
5958
}
6059
}
6160

62-
// Check if "Reply-To" exists and compare with "From".
61+
// If "Reply-To" exists and matches the "From" address, replace it with the new one.
6362
if ( ! empty( $existing_reply_to ) && strtolower( $existing_reply_to ) === strtolower( $from ) ) {
64-
// If they are the same, replace "Reply-To" with the new one.
65-
$args['headers'] = array_filter(
63+
// Remove the existing "Reply-To" header.
64+
$args['headers'] = array_filter(
6665
$args['headers'],
6766
function ( $header ) {
6867
return stripos( $header, 'reply-to:' ) !== 0;
6968
}
7069
);
70+
71+
// Add the new "Reply-To" header.
7172
$args['headers'][] = $new_reply_to;
73+
7274
} elseif ( isset( $new_reply_to ) ) {
73-
// If "Reply-To" does not exist and new_reply_to is set, add it.
75+
// If no conflicting "Reply-To" is found, append the new one.
7476
$args['headers'][] = $new_reply_to;
7577
}
7678
} elseif ( isset( $new_reply_to ) ) {
77-
// If there are no headers and new_reply_to is set, create headers with "Reply-To".
79+
// If no headers exist at all, create a new headers array with the "Reply-To".
7880
$args['headers'] = array( $new_reply_to );
7981
}
8082

83+
// Return the modified email arguments.
8184
return $args;
8285
}
86+
8387
add_filter( 'wp_mail', 'wp_mail_replyto' );
8488

8589
/**
86-
* Add a settings page to the WordPress admin menu.
90+
* Registers a settings page for the plugin in the WordPress admin menu.
91+
*
92+
* Adds a new page under the "Settings" menu where administrators can configure
93+
* the "Reply-To" email address used in outgoing emails.
8794
*/
8895
function wp_mail_replyto_add_settings_page() {
8996
add_options_page(
@@ -94,12 +101,19 @@ function wp_mail_replyto_add_settings_page() {
94101
'wp_mail_replyto_render_settings_page'
95102
);
96103
}
104+
97105
add_action( 'admin_menu', 'wp_mail_replyto_add_settings_page' );
98106

99107
/**
100-
* Register the plugin settings.
108+
* Registers the plugin settings, section, and field in the WordPress Settings API.
109+
*
110+
* This function defines:
111+
* - A setting for the "Reply-To" email address with sanitization.
112+
* - A settings section with a description callback.
113+
* - A field for entering the "Reply-To" email address.
101114
*/
102115
function wp_mail_replyto_register_settings() {
116+
// Register the "Reply-To" email setting with sanitization.
103117
register_setting(
104118
'wp_mail_replyto_settings_group',
105119
'wp_mail_replyto_email',
@@ -110,13 +124,15 @@ function wp_mail_replyto_register_settings() {
110124
)
111125
);
112126

127+
// Add a section to the settings page for organizing fields.
113128
add_settings_section(
114129
'wp_mail_replyto_main_section',
115130
esc_html__( 'Reply-To Configuration', 'replyto' ),
116131
'wp_mail_replyto_main_section_callback',
117132
'replyto'
118133
);
119134

135+
// Add the input field for the "Reply-To" email address.
120136
add_settings_field(
121137
'wp_mail_replyto_email_field',
122138
esc_html__( 'Reply-To Email Address', 'replyto' ),
@@ -125,39 +141,54 @@ function wp_mail_replyto_register_settings() {
125141
'wp_mail_replyto_main_section'
126142
);
127143
}
144+
128145
add_action( 'admin_init', 'wp_mail_replyto_register_settings' );
129146

130147
/**
131-
* Callback for the settings section description.
148+
* Outputs the description for the main settings section.
149+
*
150+
* This callback is used by the Settings API to display a description
151+
* under the "Reply-To Configuration" section on the plugin settings page.
132152
*/
133153
function wp_mail_replyto_main_section_callback() {
134154
echo '<p>' . esc_html__( 'Set the email address to be used in the "Reply-To" header of outgoing emails.', 'replyto' ) . '</p>';
135155
}
136156

137157
/**
138-
* Callback to render the email address field.
158+
* Renders the input field for the "Reply-To" email address.
159+
*
160+
* This callback is used by the Settings API to display the input field
161+
* where administrators can enter the email address to be used in the "Reply-To" header.
139162
*/
140163
function wp_mail_replyto_email_field_callback() {
164+
// Get the current "Reply-To" email address from the plugin settings.
141165
$email = get_option( 'wp_mail_replyto_email', '' );
166+
167+
// Output the input field HTML.
142168
echo '<input type="email" id="wp_mail_replyto_email" name="wp_mail_replyto_email" value="' . esc_attr( $email ) . '" size="50" />';
143169
echo '<p class="description">' . esc_html__( 'Enter the email address to be used as "Reply-To".', 'replyto' ) . '</p>';
144170
}
145171

146172
/**
147-
* Render the plugin settings page.
173+
* Renders the plugin's settings page in the WordPress admin area.
174+
*
175+
* This function outputs the HTML structure and form elements for the plugin settings page.
176+
* It includes the registered settings fields and sections for configuring the "Reply-To" email.
148177
*/
149178
function wp_mail_replyto_render_settings_page() {
179+
// Check if the current user has the required capability.
150180
if ( ! current_user_can( 'manage_options' ) ) {
151181
return;
152182
}
153183

184+
// Display settings errors, if any.
154185
settings_errors( 'wp_mail_replyto_messages' );
155186
?>
156187
<div class="wrap">
157188
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
158189
<form action="options.php" method="post">
159190
<?php
160-
wp_nonce_field( 'update-options' );
191+
// Output security fields and registered settings sections.
161192
settings_fields( 'wp_mail_replyto_settings_group' );
162193
do_settings_sections( 'replyto' );
163194
submit_button( esc_html__( 'Save Settings', 'replyto' ) );
@@ -166,11 +197,3 @@ function wp_mail_replyto_render_settings_page() {
166197
</div>
167198
<?php
168199
}
169-
170-
/**
171-
* Load plugin textdomain for translations.
172-
*/
173-
function wp_mail_replyto_load_textdomain() {
174-
load_plugin_textdomain( 'replyto', false, basename( __DIR__ ) . '/languages' );
175-
}
176-
add_action( 'plugins_loaded', 'wp_mail_replyto_load_textdomain' );

0 commit comments

Comments
 (0)