<?php
if ( !class_exists( 'WP_Mailer_Filter' ) )
{
/*
	Plugin Name: WP Mailer Filter
	Description: Sample plugin filtering mail using the new filters of wp_mailer class
	Author: arena
	Version: 0
*/
class WP_Mailer_Filter
{
        const route_to_dpo = array('user_request_confirmed_email');

	function __construct() 
	{
		add_filter( 'wp_mailer_group_privacy', array( __CLASS__, 'wp_mailer_group_privacy' ), 10, 2 );
	}

	public static function wp_mailer_group_privacy( $wp_mail, $call ) 
	{
             if ( in_array( $wp_mail['id'], self::route_to_dpo ) ) 
             {
                     $wp_mail['to'] = 'dpo@mysite.org';
             }
             else
             {
                $wp_mail['headers']['From'] = '"the_dpo" <dpo@mysite.org>';
             }
                
            $wp_mail['replacements']['{{HEADER}}'] =  '{{SITENAME}}
Data Protection Services

Dear,';
            $wp_mail['replacements']['{{FOOTER}}'] = '
Regards

====================

Your receive this mail because bla bla bla ...
Your privacy matters and we are working hard to comply with GDPR';

                return $wp_mail;
	}
}
new WP_Mailer_Filter();
}