Make WordPress Core

Ticket #49661: wp_mailer_filter.php

File wp_mailer_filter.php, 1.2 KB (added by arena, 7 years ago)

wp_mailer_filter

Line 
1<?php
2if ( !class_exists( 'WP_Mailer_Filter' ) )
3{
4/*
5 Plugin Name: WP Mailer Filter
6 Description: Sample plugin filtering mail using the new filters of wp_mailer class
7 Author: arena
8 Version: 0
9*/
10class WP_Mailer_Filter
11{
12 const route_to_dpo = array('user_request_confirmed_email');
13
14 function __construct()
15 {
16 add_filter( 'wp_mailer_group_privacy', array( __CLASS__, 'wp_mailer_group_privacy' ), 10, 2 );
17 }
18
19 public static function wp_mailer_group_privacy( $wp_mail, $call )
20 {
21 if ( in_array( $wp_mail['id'], self::route_to_dpo ) )
22 {
23 $wp_mail['to'] = 'dpo@mysite.org';
24 }
25 else
26 {
27 $wp_mail['headers']['From'] = '"the_dpo" <dpo@mysite.org>';
28 }
29
30 $wp_mail['replacements']['{{HEADER}}'] = '{{SITENAME}}
31Data Protection Services
32
33Dear,';
34 $wp_mail['replacements']['{{FOOTER}}'] = '
35Regards
36
37====================
38
39Your receive this mail because bla bla bla ...
40Your privacy matters and we are working hard to comply with GDPR';
41
42 return $wp_mail;
43 }
44}
45new WP_Mailer_Filter();
46}