. */ defined( 'ABSPATH' ) OR exit; class APTE { /** * Add hooks */ public function add_hooks() { add_action('phpmailer_init', array( $this, 'set_plaintext_body' ) ); } /** * @param PHPMailer $phpmailer */ public function set_plaintext_body( PHPMailer $phpmailer ) { // don't run if sending plain text email already if( $phpmailer->ContentType === 'text/plain' ) { return; } // don't run if AltBody is set (by other plugin) if( ! empty( $phpmailer->AltBody ) ) { return; } // set AltBody $phpmailer->AltBody = $this->strip_html_tags( $phpmailer->Body ); } /** * Remove HTML tags, including invisible text such as style and * script code, and embedded objects. Add line breaks around * block-level tags to prevent word joining after tag removal. */ private function strip_html_tags( $text ) { $text = preg_replace( array( // Remove invisible content '@]*?>.*?@siu', '@]*?>.*?@siu', '@]*?.*?@siu', '@]*?.*?@siu', '@]*?.*?@siu', '@]*?.*?@siu', '@]*?.*?@siu', '@\t+@siu', '@\n+@siu' ), '', $text ); // replace certain elements with a line-break $text = preg_replace( array( '@add_hooks();