[wp-trac] [WordPress Trac] #10726: Admin notifications for more than 1 email

WordPress Trac noreply at wordpress.org
Thu Mar 17 00:23:15 UTC 2016


#10726: Admin notifications for more than 1 email
----------------------------+-----------------------------
 Reporter:  novasource      |       Owner:
     Type:  enhancement     |      Status:  reopened
 Priority:  normal          |   Milestone:  Future Release
Component:  Administration  |     Version:  2.8.4
 Severity:  normal          |  Resolution:
 Keywords:                  |     Focuses:
----------------------------+-----------------------------

Comment (by tripflex):

 Whenever I wanted to do something like this it was as easy as filtering
 `wp_mail`, checking if `to` was set to the same thing as the value in
 `admin_email` and then adding any additional ones I want, and returning
 back to `wp_mail`

 Only thing missing would be check for admin email if `to` is an array, but
 I have yet to see a case of that where the plugin/theme didn't have its
 own method of adding additional emails.

 {{{
 add_filter( 'wp_mail', 'my_custom_to_admin_emails' );

 /**
 * Filter WP_Mail Function to Add Multiple Admin Emails
 *
 *
 *
 * @param array $args A compacted array of wp_mail() arguments, including
 the "to" email,
 *                    subject, message, headers, and attachments values.
 *
 * @return array
 */
 function my_custom_to_admin_emails( $args ) {

     // This assumes that admin emails are sent with only the admin email
     // used in the to argument.
     if( is_array( $args['to'] ) ) return $args;

     $admin_email = get_option( 'admin_email' );

     // Check if admin email is in string, as plugins/themes could have
 changed format (ie. Administrator <admin at domain.com> )
     if( strpos( $args['to'], $admin_email ) !== FALSE ){

         /**
         * Set the to key value to an array of emails, including original
 admin email
         *
         * All email addresses supplied to wp_mail() as the $to parameter
 must comply with RFC 2822. Some valid examples:
         * user at example.com
         * User <user at example.com>
         */
         $args['to'] = array( $args['to'], 'user at example.com', 'User
 <user at example.com>' );
     }

     return $args;
 }
 }}}

 Just thought I would add this here in case others come looking for other
 solutions.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/10726#comment:26>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list