| 1 | <?php
|
|---|
| 2 | if ( !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 | */
|
|---|
| 10 | class 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}}
|
|---|
| 31 | Data Protection Services
|
|---|
| 32 |
|
|---|
| 33 | Dear,';
|
|---|
| 34 | $wp_mail['replacements']['{{FOOTER}}'] = '
|
|---|
| 35 | Regards
|
|---|
| 36 |
|
|---|
| 37 | ====================
|
|---|
| 38 |
|
|---|
| 39 | Your receive this mail because bla bla bla ...
|
|---|
| 40 | Your privacy matters and we are working hard to comply with GDPR';
|
|---|
| 41 |
|
|---|
| 42 | return $wp_mail;
|
|---|
| 43 | }
|
|---|
| 44 | }
|
|---|
| 45 | new WP_Mailer_Filter();
|
|---|
| 46 | }
|
|---|