Plugin Directory

Changeset 3336571


Ignore:
Timestamp:
07/30/2025 11:26:18 AM (4 months ago)
Author:
aristath
Message:

v1.1.0

Location:
wp-mail-changer
Files:
4 added
2 edited

Legend:

Unmodified
Added
Removed
  • wp-mail-changer/trunk/readme.txt

    r797148 r3336571  
    11=== WordPress Mail Changer ===
    22Contributors: aristath
    3 Donate link: http://aristeides.com
     3Donate link: https://aristath.github.io
    44Tags: email
    5 Requires at least: 3.0.0
    6 Tested up to: 3.7.1
    7 Stable tag: 1.0
     5Requires at least: 3.0
     6Tested up to: 6.8
     7Stable tag: 1.1.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • wp-mail-changer/trunk/wp-mail-changer.php

    r797148 r3336571  
    11<?php
    2 /*
    3 Plugin Name: WordPress Mail Changer
    4 Plugin URI: http://shoestrap.org
    5 Description: A simple and easy way to change the default email address used by WordPress for generic emails.
    6 Author: Aristeides Stathopoulos
    7 Author URI: http://aristeides.com
    8 Version: 1.0.0
    9 */
     2/**
     3 * Plugin Name: WordPress Mail Changer
     4 * Plugin URI: https://aristath.github.io
     5 * Description: A simple and easy way to change the default email address used by WordPress for generic emails.
     6 * Author: Aristeides Stathopoulos
     7 * Author URI: https://aristath.github.io
     8 * Version: 1.1.0
     9 * Text Domain: wpmc
     10 */
    1011
    11 /*
    12  * Add the menu page to the "Settings" area
    13  */
    14 function wpmc_create_menu() {
    15     add_options_page( 'Mail Change', 'Mail Change', 'manage_options', 'mail-change', 'wpmc_options_page' );
    16 }
    17 add_action('admin_menu', 'wpmc_create_menu');
    18 
    19 /*
    20  * The contents of the page
    21  */
    22 function wpmc_options_page() {
    23     $mail_from      = get_option( 'wpmc_mail_from' );
    24     $mail_from_name = get_option( 'wpmc_mail_from_name' );
    25     ?>
    26     <div class="wrap">
    27         <h2><?php _e('Mail Changer Options'); ?></h2>
    28         <form method="post" action="options.php">
    29        
    30             <?php settings_fields('wpmc_options'); ?>
    31            
    32             <table class="form-table">
    33                 <tbody>
    34                     <tr valign="top">   
    35                         <th scope="row" valign="top">
    36                             <?php _e('Email Address'); ?>
    37                         </th>
    38                         <td>
    39                             <input id="wpmc_mail_from" name="wpmc_mail_from" type="text" class="email" value="<?php echo esc_attr( $mail_from ); ?>" />
    40                             <?php if ( $mail_from != '' && !filter_var( $mail_from, FILTER_VALIDATE_EMAIL ) ) : ?>
    41                                 <label class="description" for="wpmc_mail_from"><span style="color: red;"><?php _e( 'Invalid address, please enter a valid email address.' ); ?></span></label>
    42                             <?php else : ?>
    43                                 <label class="description" for="wpmc_mail_from"><?php _e( 'Enter your "from" email address' ); ?></label>
    44                             <?php endif; ?>
    45                         </td>
    46                     </tr>
    47                     <tr valign="top">   
    48                         <th scope="row" valign="top">
    49                             <?php _e('Email Name'); ?>
    50                         </th>
    51                         <td>
    52                             <input id="wpmc_mail_from_name" name="wpmc_mail_from_name" type="text" class="regular-text" value="<?php echo esc_attr( $mail_from_name ); ?>" />
    53                             <label class="description" for="mail_from_name"><?php _e( 'Enter your "from" email address' ); ?></label>
    54                         </td>
    55                     </tr>
    56                     <tr>
    57                         <td colspan="2">
    58                             Please note that in order for the name to be used, the email address will also have to be valid.
    59                         </td>
    60                     </tr>
    61                 </tbody>
    62             </table>   
    63             <?php submit_button(); ?>
    64        
    65         </form>
    66     <?php
     12// Exit if accessed directly.
     13if ( ! \defined( 'ABSPATH' ) ) {
     14    exit;
    6715}
    6816
     17// Register the settings.
     18\add_action( 'admin_init', function () {
     19    \register_setting( 'wpmc_options', 'wpmc_mail_from' );
     20    \register_setting( 'wpmc_options', 'wpmc_mail_from_name' );
     21} );
    6922
    70 /*
    71  * Creates our settings in the options table
    72  */
    73 function wpmc_register_option() {
    74     register_setting('wpmc_options', 'wpmc_mail_from' );
    75     register_setting('wpmc_options', 'wpmc_mail_from_name' );
    76 }
    77 add_action('admin_init', 'wpmc_register_option');
     23// Filter the from email address.
     24\add_filter( 'wp_mail_from', function ( $email_address ) {
     25    $value = \get_option( 'wpmc_mail_from', $email_address );
     26    return \filter_var( $value, \FILTER_VALIDATE_EMAIL ) ? $value : $email_address;
     27} );
     28
     29// Filter the from email name.
     30\add_filter( 'wp_mail_from_name', function ( $email_from ) {
     31    $value = \get_option( 'wpmc_mail_from_name', $email_from );
     32    return $value ? $value : $email_from;
     33} );
    7834
    7935
    80 /*
    81  * Change the email address
    82  */
    83 function wpmc_mail_from( $email_address ) {
    84     $mail_from = get_option( 'wpmc_mail_from' );
    85     return $mail_from;
    86 }
    87 
    88 
    89 /*
    90  * Change the email from field
    91  */
    92 function wpmc_mail_from_name( $email_from ) {
    93     $mail_from_name = get_option( 'wpmc_mail_from_name' );
    94     return $mail_from_name;
    95 }
    96 
    97 function wpmc_apply_filters() {
    98     $mail_from      = get_option( 'wpmc_mail_from' );
    99     $mail_from_name = get_option( 'wpmc_mail_from_name' );
    100     $mail_is_valid = filter_var( $mail_from, FILTER_VALIDATE_EMAIL );
    101 
    102     if ( $mail_is_valid ) :
    103         add_filter( 'wp_mail_from', 'wpmc_mail_from' );
    104 
    105         if ( $mail_from_name != '' ) :
    106             add_filter( 'wp_mail_from_name', 'wpmc_mail_from_name' );
    107         endif;
    108     endif;
    109 }
    110 add_action( 'init', 'wpmc_apply_filters' );
     36// Add the menu page to the "Settings" area.
     37\add_action( 'admin_menu', function () {
     38    \add_options_page(
     39        \esc_html__( 'Mail Change', 'wpmc' ),
     40        \esc_html__( 'Mail Change', 'wpmc' ),
     41        'manage_options',
     42        'mail-change',
     43        function () {
     44            $mail_from      = \get_option( 'wpmc_mail_from' );
     45            $mail_from_name = \get_option( 'wpmc_mail_from_name' );
     46            ?>
     47            <div class="wrap">
     48                <h2><?php \esc_html_e( 'Mail Changer Options', 'wpmc' ); ?></h2>
     49                <form method="post" action="options.php">
     50                    <?php settings_fields( 'wpmc_options' ); ?>
     51                    <table class="form-table">
     52                        <tbody>
     53                            <tr valign="top">   
     54                                <th scope="row" valign="top">
     55                                    <?php \esc_html_e( 'Email Address', 'wpmc' ); ?>
     56                                </th>
     57                                <td>
     58                                    <input id="wpmc_mail_from" name="wpmc_mail_from" type="text" class="email" value="<?php echo \esc_attr( $mail_from ); ?>" />
     59                                    <?php if ( $mail_from !== '' && ! filter_var( $mail_from, FILTER_VALIDATE_EMAIL ) ) : ?>
     60                                        <label class="description" for="wpmc_mail_from"><span style="color: red;"><?php \esc_html_e( 'Invalid address, please enter a valid email address.', 'wpmc' ); ?></span></label>
     61                                    <?php else : ?>
     62                                        <label class="description" for="wpmc_mail_from"><?php \esc_html_e( 'Enter your "from" email address', 'wpmc' ); ?></label>
     63                                    <?php endif; ?>
     64                                </td>
     65                            </tr>
     66                            <tr valign="top">   
     67                                <th scope="row" valign="top">
     68                                    <?php \esc_html_e( 'Email Name', 'wpmc' ); ?>
     69                                </th>
     70                                <td>
     71                                    <input id="wpmc_mail_from_name" name="wpmc_mail_from_name" type="text" class="regular-text" value="<?php echo \esc_attr( $mail_from_name ); ?>" />
     72                                    <label class="description" for="mail_from_name"><?php \esc_html_e( 'Enter your "from" email address', 'wpmc' ); ?></label>
     73                                </td>
     74                            </tr>
     75                            <tr>
     76                                <td colspan="2">
     77                                    <?php \esc_html_e( 'Please note that in order for the name to be used, the email address will also have to be valid.', 'wpmc' ); ?>
     78                                </td>
     79                            </tr>
     80                        </tbody>
     81                    </table>   
     82                    <?php \submit_button(); ?>
     83                </form>
     84            <?php
     85        }
     86    );
     87} );
Note: See TracChangeset for help on using the changeset viewer.