Changeset 3337689
- Timestamp:
- 08/01/2025 09:44:50 AM (7 months ago)
- Location:
- test-email-redirector/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (1 diff)
-
test-email-redirector.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
test-email-redirector/trunk/readme.txt
r3280923 r3337689 5 5 Tested up to: 6.8 6 6 Requires PHP: 7.2 7 Stable tag: 1. 2.07 Stable tag: 1.3.2 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html -
test-email-redirector/trunk/test-email-redirector.php
r3280923 r3337689 3 3 * Plugin Name: Test Email Redirector 4 4 * Description: Redirects all outgoing WordPress emails to a specified test address and optionally adds CC/BCC. If fields are left blank, they will be removed. Configurable in the Tools menu. 5 * Version: 1. 2.05 * Version: 1.3.2 6 6 * Author: Zaib Makda 7 7 * Author URI: https://profiles.wordpress.org/connectzaib/ … … 99 99 <td> 100 100 <input type="checkbox" name="zbet_email_forwarder_enabled" value="1" <?php checked( get_option( 'zbet_email_forwarder_enabled', false ), 1 ); ?> /> 101 <p class="description" ><?php echo esc_html__( 'Enable or disable email redirection without deactivating the plugin.', 'test-email-redirector' ); ?></p>101 <p class="description" style="display: inline-block;"><?php echo esc_html__( 'Enable or disable email redirection without deactivating the plugin.', 'test-email-redirector' ); ?></p> 102 102 </td> 103 103 </tr> … … 127 127 <td> 128 128 <input type="checkbox" name="zbet_email_forwarder_send_original_info" value="1" <?php checked( get_option( 'zbet_email_forwarder_send_original_info', false ), 1 ); ?> /> 129 <p class="description" ><?php echo esc_html__( 'Include original recipient information in the forwarded email.', 'test-email-redirector' ); ?></p>129 <p class="description" style="display: inline-block;"><?php echo esc_html__( 'Include original recipient information in the forwarded email.', 'test-email-redirector' ); ?></p> 130 130 </td> 131 131 </tr> … … 170 170 ); 171 171 172 172 173 // Modify outgoing emails. 173 174 add_filter( 174 175 'wp_mail', 175 176 function ( $args ) { 177 176 178 $enabled = get_option( 'zbet_email_forwarder_enabled', false ); 177 179 … … 185 187 } 186 188 187 $cc_emails = array_filter( array_map( 'sanitize_email', explode( ',', get_option( 'zbet_email_forwarder_cc', '' ) ) ) ); 188 $bcc_emails = array_filter( array_map( 'sanitize_email', explode( ',', get_option( 'zbet_email_forwarder_bcc', '' ) ) ) ); 189 $ovveride_bcc = get_option( 'zbet_email_forwarder_bcc', '' ); 190 $ovveride_cc = get_option( 'zbet_email_forwarder_cc', '' ); 191 192 $original_to = $args['to']; 193 $args['to'] = $test_email; 194 $args['subject'] = '[TEST REDIRECT] ' . $args['subject']; 195 189 196 $send_original_info = get_option( 'zbet_email_forwarder_send_original_info', false ); 190 197 191 $original_to = $args['to']; 192 $original_cc = isset( $args['cc'] ) ? $args['cc'] : ''; 193 $original_bcc = isset( $args['bcc'] ) ? $args['bcc'] : ''; 194 195 $args['to'] = $test_email; 196 $args['cc'] = ! empty( $cc_emails ) ? $cc_emails : array(); 197 $args['bcc'] = ! empty( $bcc_emails ) ? $bcc_emails : array(); 198 $args['subject'] = '[TEST REDIRECT] ' . $args['subject']; 199 198 $original_info = array(); 200 199 if ( $send_original_info ) { 201 $original_info = "\n\n--- Original Recipients ---\n"; 202 $original_info .= 'To: ' . implode( ', ', (array) $original_to ) . "\n"; 203 $original_info .= 'CC: ' . implode( ', ', (array) $original_cc ) . "\n"; 204 $original_info .= 'BCC: ' . implode( ', ', (array) $original_bcc ) . "\n"; 205 206 $args['message'] .= '<br><br>' . nl2br( esc_html( $original_info ) ); 200 $original_info[] = '--- Original Recipients ---'; 201 $original_info[] = 'To: ' . implode( ', ', (array) $original_to ); 202 } 203 204 if ( empty( $args['headers'] ) ) { 205 return $args; 206 } 207 208 if ( is_array( $args['headers'] ) ) { 209 210 if ( ! empty( $args['headers']['Bcc'] ) ) { 211 212 // BCC is there. 213 if ( $send_original_info ) { 214 $original_info[] = str_replace( 'Bcc: ', 'BCC: ', $args['headers']['Bcc'] ); 215 } 216 217 // Remove Original Bcc from the headers. 218 unset( $args['headers']['Bcc'] ); 219 220 // Check if we have to overided the BCC. 221 if ( ! empty( $ovveride_bcc ) ) { 222 $args['headers']['Bcc'] = "Bcc: $ovveride_bcc"; 223 } 224 } 225 226 if ( ! empty( $args['headers']['Cc'] ) ) { 227 228 // CC is there. 229 if ( $send_original_info ) { 230 $original_info[] = str_replace( 'Cc: ', 'CC: ', $args['headers']['Cc'] ); 231 } 232 233 // Remove Original Cc from the headers. 234 unset( $args['headers']['Cc'] ); 235 236 // Check if we have to overided the BCC. 237 if ( ! empty( $ovveride_cc ) ) { 238 $args['headers']['Cc'] = "Cc: $ovveride_cc"; 239 } 240 } 241 } else { 242 243 // It's a string. 244 $args['headers'] = explode( "\n", str_replace( "\r\n", "\n", $args['headers'] ) ); 245 $contains_bcc = false; 246 $contains_cc = false; 247 248 // Checked if headers contains BCC. 249 $new_headers = array(); 250 $original_bccs = array(); 251 $original_ccs = array(); 252 foreach ( $args['headers'] as $header ) { 253 254 $trimmed = trim( $header ); 255 256 if ( empty( $trimmed ) ) { 257 // Skip empty lines. 258 continue; 259 } 260 261 if ( stripos( $trimmed, 'Bcc:' ) === 0 || stripos( $trimmed, 'bcc:' ) ) { 262 // BCC is there. 263 $contains_bcc = true; 264 $original_bcc = ' ' . str_replace( array( 'bcc: ', '\\r\\n', ',' ), '', strtolower( $trimmed ) ); 265 266 if ( $send_original_info ) { 267 $original_bccs[] = $original_bcc; 268 } 269 // Skip BCC. 270 continue; 271 } 272 273 if ( stripos( $trimmed, 'Cc:' ) === 0 || stripos( $trimmed, 'cc:' ) === 0 ) { 274 // CC is there. 275 $contains_cc = true; 276 $original_cc = ' ' . str_replace( array( 'cc: ', '\\r\\n', ',' ), '', strtolower( $trimmed ) ); 277 if ( $send_original_info ) { 278 $original_ccs[] = $original_cc; 279 } 280 // Skip CC. 281 continue; 282 } 283 284 $new_headers[] = $trimmed; 285 } 286 287 if ( ! empty( $original_bccs ) ) { 288 // Add original BCCs to the message. 289 $original_info[] = 'BCC: ' . implode( ', ', array_unique( $original_bccs ) ); 290 } 291 292 if ( ! empty( $original_ccs ) ) { 293 // Add original BCCs to the message. 294 $original_info[] = 'CC: ' . implode( ', ', array_unique( $original_ccs ) ); 295 } 296 297 // Check if we have to overided the BCC. 298 if ( $contains_bcc && ! empty( $ovveride_bcc ) ) { 299 $new_headers[] = 'Bcc: ' . $ovveride_bcc; 300 } 301 302 // Check if we have to overided the CC. 303 if ( $contains_cc && ! empty( $ovveride_cc ) ) { 304 $new_headers[] = 'Cc: ' . $ovveride_cc; 305 } 306 307 $args['headers'] = $new_headers; 308 309 } 310 311 if ( $send_original_info && ! empty( $original_info ) ) { 312 $args['message'] .= '<br/><br/>'; 313 foreach ( $original_info as $value ) { 314 $args['message'] .= wp_kses_post( $value ) . '<br/>'; 315 } 207 316 } 208 317 … … 211 320 PHP_INT_MAX 212 321 ); 213 214 322 // Add settings link on the Plugins page. 215 323 add_filter( … … 222 330 ); 223 331 224 225 332 // Cleanup settings on plugin deletion. 226 333 register_uninstall_hook( __FILE__, 'zbet_email_forwarder_cleanup' ); 227 228 334 function zbet_email_forwarder_cleanup() { 229 335 delete_option( 'zbet_email_forwarder_email' );
Note: See TracChangeset
for help on using the changeset viewer.