Plugin Directory

Changeset 3268615


Ignore:
Timestamp:
04/08/2025 10:18:03 AM (12 months ago)
Author:
JavierCasares
Message:

# [1.0.3] - 2025-04-08

Changed

  • Compatible with WordPress 6.8.
  • Improved functions documentation.

Compatibility

Tests

  • PHP Coding Standards: 3.12.1
  • WordPress Coding Standards: 3.1.0
  • Plugin Check (PCP): 1.4.0
Location:
replyto
Files:
11 added
3 edited

Legend:

Unmodified
Added
Removed
  • replyto/trunk/languages/wp-mail-replyto.pot

    r3180313 r3268615  
    33msgstr ""
    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"
     
    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
    3124msgid "WP Mail Reply-To Settings"
    3225msgstr ""
    3326
    34 #: replyto.php:91
     27#: replyto.php:98
    3528msgid "Reply-To"
    3629msgstr ""
    3730
    38 #: replyto.php:115
     31#: replyto.php:130
    3932msgid "Reply-To Configuration"
    4033msgstr ""
    4134
    42 #: replyto.php:122
     35#: replyto.php:138
    4336msgid "Reply-To Email Address"
    4437msgstr ""
    4538
    46 #: replyto.php:134
     39#: replyto.php:154
    4740msgid ""
    4841"Set the email address to be used in the \"Reply-To\" header of outgoing "
     
    5043msgstr ""
    5144
    52 #: replyto.php:143
     45#: replyto.php:169
    5346msgid "Enter the email address to be used as \"Reply-To\"."
    5447msgstr ""
    5548
    56 #: replyto.php:163
     49#: replyto.php:194
    5750msgid "Save Settings"
    5851msgstr ""
  • replyto/trunk/readme.txt

    r3180313 r3268615  
    33Tags: email, reply-to
    44Requires at least: 4.1
    5 Tested up to: 6.7
    6 Stable tag: 1.0.2
     5Tested up to: 6.8
     6Stable tag: 1.0.3
    77Requires PHP: 5.6
    8 Version: 1.0.2
     8Version: 1.0.3
    99License: GPL-2.0-or-later
    1010License URI: https://spdx.org/licenses/GPL-2.0-or-later.html
     
    2424== Compatibility ==
    2525
    26 * WordPress: 4.1 - 6.7
     26* WordPress: 4.1 - 6.8
    2727* PHP: 5.6 - 8.4
    2828
    2929== Changelog ==
     30
     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
    3048
    3149= [1.0.2] - 2024-11-02 =
  • replyto/trunk/replyto.php

    r3180313 r3268615  
    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/
     
    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 */
    2831function 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 ) {
     
    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 ) {
     
    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
    8387add_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 */
    8895function wp_mail_replyto_add_settings_page() {
     
    95102    );
    96103}
     104
    97105add_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 */
    102115function wp_mail_replyto_register_settings() {
     116    // Register the "Reply-To" email setting with sanitization.
    103117    register_setting(
    104118        'wp_mail_replyto_settings_group',
     
    111125    );
    112126
     127    // Add a section to the settings page for organizing fields.
    113128    add_settings_section(
    114129        'wp_mail_replyto_main_section',
     
    118133    );
    119134
     135    // Add the input field for the "Reply-To" email address.
    120136    add_settings_field(
    121137        'wp_mail_replyto_email_field',
     
    126142    );
    127143}
     144
    128145add_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 */
    133153function wp_mail_replyto_main_section_callback() {
     
    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 */
    140163function 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>';
     
    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 */
    149178function 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    ?>
     
    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' );
     
    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' );
Note: See TracChangeset for help on using the changeset viewer.