Changeset 3268615
- Timestamp:
- 04/08/2025 10:18:03 AM (12 months ago)
- Location:
- replyto
- Files:
-
- 11 added
- 3 edited
-
tags/1.0.3 (added)
-
tags/1.0.3/LICENSE (added)
-
tags/1.0.3/assets (added)
-
tags/1.0.3/assets/icon-128x128.png (added)
-
tags/1.0.3/assets/icon-256x256.png (added)
-
tags/1.0.3/assets/icon.png (added)
-
tags/1.0.3/assets/icon.svg (added)
-
tags/1.0.3/languages (added)
-
tags/1.0.3/languages/wp-mail-replyto.pot (added)
-
tags/1.0.3/readme.txt (added)
-
tags/1.0.3/replyto.php (added)
-
trunk/languages/wp-mail-replyto.pot (modified) (3 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/replyto.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
replyto/trunk/languages/wp-mail-replyto.pot
r3180313 r3268615 3 3 msgstr "" 4 4 "Project-Id-Version: Reply-To for WP_Mail\n" 5 "POT-Creation-Date: 202 4-11-02 10:48+0100\n"5 "POT-Creation-Date: 2025-04-08 12:13+0200\n" 6 6 "PO-Revision-Date: 2024-10-31 08:58+0100\n" 7 7 "Last-Translator: \n" … … 11 11 "Content-Transfer-Encoding: 8bit\n" 12 12 "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" 13 "X-Generator: Poedit 3. 5\n"13 "X-Generator: Poedit 3.6\n" 14 14 "X-Poedit-Basepath: ..\n" 15 15 "X-Poedit-Flags-xgettext: --add-comments=translators:\n" 16 16 "X-Poedit-WPHeader: replyto.php\n" 17 17 "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" 21 20 "X-Poedit-SearchPath-0: .\n" 22 21 "X-Poedit-SearchPathExcluded-0: *.min.js\n" 23 22 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 31 24 msgid "WP Mail Reply-To Settings" 32 25 msgstr "" 33 26 34 #: replyto.php:9 127 #: replyto.php:98 35 28 msgid "Reply-To" 36 29 msgstr "" 37 30 38 #: replyto.php:1 1531 #: replyto.php:130 39 32 msgid "Reply-To Configuration" 40 33 msgstr "" 41 34 42 #: replyto.php:1 2235 #: replyto.php:138 43 36 msgid "Reply-To Email Address" 44 37 msgstr "" 45 38 46 #: replyto.php:1 3439 #: replyto.php:154 47 40 msgid "" 48 41 "Set the email address to be used in the \"Reply-To\" header of outgoing " … … 50 43 msgstr "" 51 44 52 #: replyto.php:1 4345 #: replyto.php:169 53 46 msgid "Enter the email address to be used as \"Reply-To\"." 54 47 msgstr "" 55 48 56 #: replyto.php:1 6349 #: replyto.php:194 57 50 msgid "Save Settings" 58 51 msgstr "" -
replyto/trunk/readme.txt
r3180313 r3268615 3 3 Tags: email, reply-to 4 4 Requires at least: 4.1 5 Tested up to: 6. 76 Stable tag: 1.0. 25 Tested up to: 6.8 6 Stable tag: 1.0.3 7 7 Requires PHP: 5.6 8 Version: 1.0. 28 Version: 1.0.3 9 9 License: GPL-2.0-or-later 10 10 License URI: https://spdx.org/licenses/GPL-2.0-or-later.html … … 24 24 == Compatibility == 25 25 26 * WordPress: 4.1 - 6. 726 * WordPress: 4.1 - 6.8 27 27 * PHP: 5.6 - 8.4 28 28 29 29 == 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 30 48 31 49 = [1.0.2] - 2024-11-02 = -
replyto/trunk/replyto.php
r3180313 r3268615 5 5 * Requires at least: 4.1 6 6 * Requires PHP: 5.6 7 * Version: 1.0. 27 * Version: 1.0.3 8 8 * Author: Javier Casares 9 9 * Author URI: https://www.javiercasares.com/ … … 21 21 22 22 /** 23 * Configure the "Reply-To" header for emails sent by WP Mail.23 * Modifies the "Reply-To" header in emails sent using wp_mail(). 24 24 * 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. 27 30 */ 28 31 function wp_mail_replyto( $args ) { 29 // Get the "Reply-To" emailfrom plugin settings.32 // Retrieve the "Reply-To" email address from plugin settings. 30 33 $reply_to_email = get_option( 'wp_mail_replyto_email' ); 31 34 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 ) . '>'; 39 38 } 40 39 41 // Initialize variables for "From" and existing "Reply-To".40 // Initialize variables to track the "From" and existing "Reply-To" headers. 42 41 $from = ''; 43 42 $existing_reply_to = ''; 44 43 45 // Check if there are existing headers.44 // Check if email headers exist. 46 45 if ( ! empty( $args['headers'] ) ) { 47 // Normalize headers to an array.46 // Normalize headers into an array if they are not already. 48 47 if ( ! is_array( $args['headers'] ) ) { 49 48 $args['headers'] = array_filter( explode( "\n", str_replace( "\r\n", "\n", $args['headers'] ) ) ); 50 49 } 51 50 52 // Loop through headers to find "From" and "Reply-To".51 // Loop through the headers to locate "From" and "Reply-To" values. 53 52 foreach ( $args['headers'] as $header ) { 54 53 if ( stripos( $header, 'from:' ) === 0 ) { … … 60 59 } 61 60 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. 63 62 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( 66 65 $args['headers'], 67 66 function ( $header ) { … … 69 68 } 70 69 ); 70 71 // Add the new "Reply-To" header. 71 72 $args['headers'][] = $new_reply_to; 73 72 74 } 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. 74 76 $args['headers'][] = $new_reply_to; 75 77 } 76 78 } 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". 78 80 $args['headers'] = array( $new_reply_to ); 79 81 } 80 82 83 // Return the modified email arguments. 81 84 return $args; 82 85 } 86 83 87 add_filter( 'wp_mail', 'wp_mail_replyto' ); 84 88 85 89 /** 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. 87 94 */ 88 95 function wp_mail_replyto_add_settings_page() { … … 95 102 ); 96 103 } 104 97 105 add_action( 'admin_menu', 'wp_mail_replyto_add_settings_page' ); 98 106 99 107 /** 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. 101 114 */ 102 115 function wp_mail_replyto_register_settings() { 116 // Register the "Reply-To" email setting with sanitization. 103 117 register_setting( 104 118 'wp_mail_replyto_settings_group', … … 111 125 ); 112 126 127 // Add a section to the settings page for organizing fields. 113 128 add_settings_section( 114 129 'wp_mail_replyto_main_section', … … 118 133 ); 119 134 135 // Add the input field for the "Reply-To" email address. 120 136 add_settings_field( 121 137 'wp_mail_replyto_email_field', … … 126 142 ); 127 143 } 144 128 145 add_action( 'admin_init', 'wp_mail_replyto_register_settings' ); 129 146 130 147 /** 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. 132 152 */ 133 153 function wp_mail_replyto_main_section_callback() { … … 136 156 137 157 /** 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. 139 162 */ 140 163 function wp_mail_replyto_email_field_callback() { 164 // Get the current "Reply-To" email address from the plugin settings. 141 165 $email = get_option( 'wp_mail_replyto_email', '' ); 166 167 // Output the input field HTML. 142 168 echo '<input type="email" id="wp_mail_replyto_email" name="wp_mail_replyto_email" value="' . esc_attr( $email ) . '" size="50" />'; 143 169 echo '<p class="description">' . esc_html__( 'Enter the email address to be used as "Reply-To".', 'replyto' ) . '</p>'; … … 145 171 146 172 /** 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. 148 177 */ 149 178 function wp_mail_replyto_render_settings_page() { 179 // Check if the current user has the required capability. 150 180 if ( ! current_user_can( 'manage_options' ) ) { 151 181 return; 152 182 } 153 183 184 // Display settings errors, if any. 154 185 settings_errors( 'wp_mail_replyto_messages' ); 155 186 ?> … … 158 189 <form action="options.php" method="post"> 159 190 <?php 160 wp_nonce_field( 'update-options' );191 // Output security fields and registered settings sections. 161 192 settings_fields( 'wp_mail_replyto_settings_group' ); 162 193 do_settings_sections( 'replyto' ); … … 167 198 <?php 168 199 } 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.