Send Admin Notifications to Several Addresses
Delivers emails addressed to the site admin email (new users, comments, updates) to additional team members as well.
Opens WPIDE on
Code
add_filter( 'wp_mail', function ( $atts ) {
$extra = array(); // For example array( '[email protected]', '[email protected]' ).
$admin = strtolower( (string) get_option( 'admin_email' ) );
$to = array_map( 'trim', is_array( $atts['to'] ) ? $atts['to'] : explode( ',', (string) $atts['to'] ) );
if ( ! $extra || ! in_array( $admin, array_map( 'strtolower', $to ), true ) ) {
return $atts;
}
$atts['to'] = array_values( array_unique( array_merge( $to, array_filter( $extra, 'is_email' ) ) ) );
return $atts;
} );
Notes
List the extra addresses in $extra. Emails to other recipients are not changed.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.