@@ -42,7 +42,7 @@ discard block  | 
                                                    ||
| 42 | 42 | */  | 
                                                        
| 43 | 43 | protected $to;  | 
                                                        
| 44 | 44 | |
| 45 | - public function __construct( Template $template, Utility $utility )  | 
                                                        |
| 45 | + public function __construct(Template $template, Utility $utility)  | 
                                                        |
| 46 | 46 |  	{ | 
                                                        
| 47 | 47 | $this->template = $template;  | 
                                                        
| 48 | 48 | $this->utility = $utility;  | 
                                                        
@@ -51,19 +51,19 @@ discard block  | 
                                                    ||
| 51 | 51 | /**  | 
                                                        
| 52 | 52 | * @return Email  | 
                                                        
| 53 | 53 | */  | 
                                                        
| 54 | - public function compose( array $email )  | 
                                                        |
| 54 | + public function compose(array $email)  | 
                                                        |
| 55 | 55 |  	{ | 
                                                        
| 56 | - $email = $this->normalize( $email );  | 
                                                        |
| 56 | + $email = $this->normalize($email);  | 
                                                        |
| 57 | 57 | |
| 58 | 58 | $this->attachments = $email['attachments'];  | 
                                                        
| 59 | - $this->headers = $this->buildHeaders( $email );  | 
                                                        |
| 60 | - $this->message = $this->buildHtmlMessage( $email );  | 
                                                        |
| 59 | + $this->headers = $this->buildHeaders($email);  | 
                                                        |
| 60 | + $this->message = $this->buildHtmlMessage($email);  | 
                                                        |
| 61 | 61 | $this->subject = $email['subject'];  | 
                                                        
| 62 | 62 | $this->to = $email['to'];  | 
                                                        
| 63 | 63 | |
| 64 | -		add_action( 'phpmailer_init', function( PHPMailer $phpmailer ) { | 
                                                        |
| 65 | - if( $phpmailer->ContentType === 'text/plain' || !empty( $phpmailer->AltBody ))return;  | 
                                                        |
| 66 | - $phpmailer->AltBody = $this->buildPlainTextMessage( $phpmailer->Body );  | 
                                                        |
| 64 | +		add_action('phpmailer_init', function(PHPMailer $phpmailer) { | 
                                                        |
| 65 | + if ($phpmailer->ContentType === 'text/plain' || !empty($phpmailer->AltBody))return;  | 
                                                        |
| 66 | + $phpmailer->AltBody = $this->buildPlainTextMessage($phpmailer->Body);  | 
                                                        |
| 67 | 67 | });  | 
                                                        
| 68 | 68 | |
| 69 | 69 | return $this;  | 
                                                        
@@ -74,10 +74,10 @@ discard block  | 
                                                    ||
| 74 | 74 | *  | 
                                                        
| 75 | 75 | * @return string|null  | 
                                                        
| 76 | 76 | */  | 
                                                        
| 77 | - public function read( $plaintext = false )  | 
                                                        |
| 77 | + public function read($plaintext = false)  | 
                                                        |
| 78 | 78 |  	{ | 
                                                        
| 79 | 79 | return $plaintext  | 
                                                        
| 80 | - ? $this->buildPlainTextMessage( $this->message )  | 
                                                        |
| 80 | + ? $this->buildPlainTextMessage($this->message)  | 
                                                        |
| 81 | 81 | : $this->message;  | 
                                                        
| 82 | 82 | }  | 
                                                        
| 83 | 83 | |
@@ -86,7 +86,7 @@ discard block  | 
                                                    ||
| 86 | 86 | */  | 
                                                        
| 87 | 87 | public function send()  | 
                                                        
| 88 | 88 |  	{ | 
                                                        
| 89 | - if( !$this->message || !$this->subject || !$this->to )return;  | 
                                                        |
| 89 | + if (!$this->message || !$this->subject || !$this->to)return;  | 
                                                        |
| 90 | 90 | |
| 91 | 91 | $sent = wp_mail(  | 
                                                        
| 92 | 92 | $this->to,  | 
                                                        
@@ -104,7 +104,7 @@ discard block  | 
                                                    ||
| 104 | 104 | /**  | 
                                                        
| 105 | 105 | * @return array  | 
                                                        
| 106 | 106 | */  | 
                                                        
| 107 | - protected function buildHeaders( array $email )  | 
                                                        |
| 107 | + protected function buildHeaders(array $email)  | 
                                                        |
| 108 | 108 |  	{ | 
                                                        
| 109 | 109 | $allowed = [  | 
                                                        
| 110 | 110 | 'bcc',  | 
                                                        
@@ -113,34 +113,34 @@ discard block  | 
                                                    ||
| 113 | 113 | 'reply-to',  | 
                                                        
| 114 | 114 | ];  | 
                                                        
| 115 | 115 | |
| 116 | - $headers = array_intersect_key( $email, array_flip( $allowed ));  | 
                                                        |
| 117 | - $headers = array_filter( $headers );  | 
                                                        |
| 116 | + $headers = array_intersect_key($email, array_flip($allowed));  | 
                                                        |
| 117 | + $headers = array_filter($headers);  | 
                                                        |
| 118 | 118 | |
| 119 | -		foreach( $headers as $key => $value ) { | 
                                                        |
| 120 | - unset( $headers[ $key ] );  | 
                                                        |
| 121 | - $headers[] = sprintf( '%s: %s', $key, $value );  | 
                                                        |
| 119 | +		foreach ($headers as $key => $value) { | 
                                                        |
| 120 | + unset($headers[$key]);  | 
                                                        |
| 121 | +			$headers[] = sprintf('%s: %s', $key, $value); | 
                                                        |
| 122 | 122 | }  | 
                                                        
| 123 | 123 | |
| 124 | 124 | $headers[] = 'Content-Type: text/html';  | 
                                                        
| 125 | 125 | |
| 126 | - return apply_filters( 'castor/email/headers', $headers, $this );  | 
                                                        |
| 126 | +		return apply_filters('castor/email/headers', $headers, $this); | 
                                                        |
| 127 | 127 | }  | 
                                                        
| 128 | 128 | |
| 129 | 129 | /**  | 
                                                        
| 130 | 130 | * @return string  | 
                                                        
| 131 | 131 | */  | 
                                                        
| 132 | - protected function buildHtmlMessage( array $email )  | 
                                                        |
| 132 | + protected function buildHtmlMessage(array $email)  | 
                                                        |
| 133 | 133 |  	{ | 
                                                        
| 134 | - $body = $this->renderTemplate( 'email' );  | 
                                                        |
| 134 | +		$body = $this->renderTemplate('email'); | 
                                                        |
| 135 | 135 | |
| 136 | - $message = !empty( $email['template'] )  | 
                                                        |
| 137 | - ? $this->renderTemplate( $email['template'], $email['template-tags'] )  | 
                                                        |
| 136 | + $message = !empty($email['template'])  | 
                                                        |
| 137 | + ? $this->renderTemplate($email['template'], $email['template-tags'])  | 
                                                        |
| 138 | 138 | : $email['message'];  | 
                                                        
| 139 | 139 | |
| 140 | - $message = $this->filterHtml( $email['before'] . $message . $email['after'] );  | 
                                                        |
| 141 | -		$message = str_replace( '{message}', $message, $body ); | 
                                                        |
| 140 | + $message = $this->filterHtml($email['before'] . $message . $email['after']);  | 
                                                        |
| 141 | +		$message = str_replace('{message}', $message, $body); | 
                                                        |
| 142 | 142 | |
| 143 | - return apply_filters( 'castor/email/message', $message, 'html', $this );  | 
                                                        |
| 143 | +		return apply_filters('castor/email/message', $message, 'html', $this); | 
                                                        |
| 144 | 144 | }  | 
                                                        
| 145 | 145 | |
| 146 | 146 | /**  | 
                                                        
@@ -148,9 +148,9 @@ discard block  | 
                                                    ||
| 148 | 148 | *  | 
                                                        
| 149 | 149 | * @return string  | 
                                                        
| 150 | 150 | */  | 
                                                        
| 151 | - protected function buildPlainTextMessage( $message )  | 
                                                        |
| 151 | + protected function buildPlainTextMessage($message)  | 
                                                        |
| 152 | 152 |  	{ | 
                                                        
| 153 | - return apply_filters( 'castor/email/message', $this->stripHtmlTags( $message ), 'text', $this );  | 
                                                        |
| 153 | +		return apply_filters('castor/email/message', $this->stripHtmlTags($message), 'text', $this); | 
                                                        |
| 154 | 154 | }  | 
                                                        
| 155 | 155 | |
| 156 | 156 | /**  | 
                                                        
@@ -158,13 +158,13 @@ discard block  | 
                                                    ||
| 158 | 158 | *  | 
                                                        
| 159 | 159 | * @return string  | 
                                                        
| 160 | 160 | */  | 
                                                        
| 161 | - protected function filterHtml( $message )  | 
                                                        |
| 161 | + protected function filterHtml($message)  | 
                                                        |
| 162 | 162 |  	{ | 
                                                        
| 163 | - $message = strip_shortcodes( $message );  | 
                                                        |
| 164 | - $message = wptexturize( $message );  | 
                                                        |
| 165 | - $message = wpautop( $message );  | 
                                                        |
| 166 | - $message = str_replace( ['<> ', ']]>'], ['', ']]>'], $message );  | 
                                                        |
| 167 | - $message = stripslashes( $message );  | 
                                                        |
| 163 | + $message = strip_shortcodes($message);  | 
                                                        |
| 164 | + $message = wptexturize($message);  | 
                                                        |
| 165 | + $message = wpautop($message);  | 
                                                        |
| 166 | + $message = str_replace(['<> ', ']]>'], ['', ']]>'], $message);  | 
                                                        |
| 167 | + $message = stripslashes($message);  | 
                                                        |
| 168 | 168 | return $message;  | 
                                                        
| 169 | 169 | }  | 
                                                        
| 170 | 170 | |
@@ -173,16 +173,16 @@ discard block  | 
                                                    ||
| 173 | 173 | */  | 
                                                        
| 174 | 174 | protected function getDefaultFrom()  | 
                                                        
| 175 | 175 |  	{ | 
                                                        
| 176 | - return sprintf( '%s <%s>',  | 
                                                        |
| 177 | - wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ),  | 
                                                        |
| 178 | - get_option( 'admin_email' )  | 
                                                        |
| 176 | +		return sprintf('%s <%s>', | 
                                                        |
| 177 | +			wp_specialchars_decode(get_option('blogname'), ENT_QUOTES), | 
                                                        |
| 178 | +			get_option('admin_email') | 
                                                        |
| 179 | 179 | );  | 
                                                        
| 180 | 180 | }  | 
                                                        
| 181 | 181 | |
| 182 | 182 | /**  | 
                                                        
| 183 | 183 | * @return array  | 
                                                        
| 184 | 184 | */  | 
                                                        
| 185 | - protected function normalize( $email )  | 
                                                        |
| 185 | + protected function normalize($email)  | 
                                                        |
| 186 | 186 |  	{ | 
                                                        
| 187 | 187 | $defaults = [  | 
                                                        
| 188 | 188 | 'after' => '',  | 
                                                        
@@ -199,13 +199,13 @@ discard block  | 
                                                    ||
| 199 | 199 | 'to' => '',  | 
                                                        
| 200 | 200 | ];  | 
                                                        
| 201 | 201 | |
| 202 | - $email = shortcode_atts( $defaults, $email );  | 
                                                        |
| 202 | + $email = shortcode_atts($defaults, $email);  | 
                                                        |
| 203 | 203 | |
| 204 | -		if( empty( $email['reply-to'] )) { | 
                                                        |
| 204 | +		if (empty($email['reply-to'])) { | 
                                                        |
| 205 | 205 | $email['reply-to'] = $email['from'];  | 
                                                        
| 206 | 206 | }  | 
                                                        
| 207 | 207 | |
| 208 | - return apply_filters( 'castor/email/compose', $email, $this );  | 
                                                        |
| 208 | +		return apply_filters('castor/email/compose', $email, $this); | 
                                                        |
| 209 | 209 | }  | 
                                                        
| 210 | 210 | |
| 211 | 211 | /**  | 
                                                        
@@ -225,20 +225,20 @@ discard block  | 
                                                    ||
| 225 | 225 | *  | 
                                                        
| 226 | 226 | * @return void|string  | 
                                                        
| 227 | 227 | */  | 
                                                        
| 228 | - protected function renderTemplate( $templatePath, array $args = [] )  | 
                                                        |
| 228 | + protected function renderTemplate($templatePath, array $args = [])  | 
                                                        |
| 229 | 229 |  	{ | 
                                                        
| 230 | - $file = $this->template->get( sprintf( 'castor/%s', $templatePath ));  | 
                                                        |
| 230 | +		$file = $this->template->get(sprintf('castor/%s', $templatePath)); | 
                                                        |
| 231 | 231 | |
| 232 | -		if( !file_exists( $file )) { | 
                                                        |
| 233 | - $file = sprintf( '%s/templates/%s.php', dirname( __DIR__ ), $templatePath );  | 
                                                        |
| 232 | +		if (!file_exists($file)) { | 
                                                        |
| 233 | +			$file = sprintf('%s/templates/%s.php', dirname(__DIR__), $templatePath); | 
                                                        |
| 234 | 234 | }  | 
                                                        
| 235 | - if( !file_exists( $file ))return;  | 
                                                        |
| 235 | + if (!file_exists($file))return;  | 
                                                        |
| 236 | 236 | |
| 237 | 237 | ob_start();  | 
                                                        
| 238 | 238 | include $file;  | 
                                                        
| 239 | 239 | $template = ob_get_clean();  | 
                                                        
| 240 | 240 | |
| 241 | - return $this->renderTemplateString( $template, $args );  | 
                                                        |
| 241 | + return $this->renderTemplateString($template, $args);  | 
                                                        |
| 242 | 242 | }  | 
                                                        
| 243 | 243 | |
| 244 | 244 | /**  | 
                                                        
@@ -246,12 +246,12 @@ discard block  | 
                                                    ||
| 246 | 246 | *  | 
                                                        
| 247 | 247 | * @return string  | 
                                                        
| 248 | 248 | */  | 
                                                        
| 249 | - protected function renderTemplateString( $template, array $args = [] )  | 
                                                        |
| 249 | + protected function renderTemplateString($template, array $args = [])  | 
                                                        |
| 250 | 250 |  	{ | 
                                                        
| 251 | -		foreach( $args as $key => $value ) { | 
                                                        |
| 252 | -			$template = str_replace( sprintf( '{%s}', $key ), $value, $template ); | 
                                                        |
| 251 | +		foreach ($args as $key => $value) { | 
                                                        |
| 252 | +			$template = str_replace(sprintf('{%s}', $key), $value, $template); | 
                                                        |
| 253 | 253 | }  | 
                                                        
| 254 | - return trim( $template );  | 
                                                        |
| 254 | + return trim($template);  | 
                                                        |
| 255 | 255 | }  | 
                                                        
| 256 | 256 | |
| 257 | 257 | /**  | 
                                                        
@@ -262,16 +262,16 @@ discard block  | 
                                                    ||
| 262 | 262 | * - strip all remaining HTML tags  | 
                                                        
| 263 | 263 | * @return string  | 
                                                        
| 264 | 264 | */  | 
                                                        
| 265 | - protected function stripHtmlTags( $string )  | 
                                                        |
| 265 | + protected function stripHtmlTags($string)  | 
                                                        |
| 266 | 266 |  	{ | 
                                                        
| 267 | - $string = preg_replace( '@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string );  | 
                                                        |
| 268 | - $string = preg_replace( '@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string );  | 
                                                        |
| 269 | - $string = preg_replace( '@</(td|th)@iu', " \$0", $string );  | 
                                                        |
| 270 | - $string = preg_replace( '@<(li)[^>]*?>@siu', "\$0-o-^-o-", $string );  | 
                                                        |
| 271 | - $string = wp_strip_all_tags( $string );  | 
                                                        |
| 272 | - $string = wp_specialchars_decode( $string, ENT_QUOTES );  | 
                                                        |
| 273 | -		$string = preg_replace( '/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string ); | 
                                                        |
| 274 | - $string = str_replace( '-o-^-o-', ' - ', $string );  | 
                                                        |
| 275 | - return html_entity_decode( $string, ENT_QUOTES, 'UTF-8' );  | 
                                                        |
| 267 | +		$string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string); | 
                                                        |
| 268 | +		$string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string); | 
                                                        |
| 269 | +		$string = preg_replace('@</(td|th)@iu', " \$0", $string); | 
                                                        |
| 270 | +		$string = preg_replace('@<(li)[^>]*?>@siu', "\$0-o-^-o-", $string); | 
                                                        |
| 271 | + $string = wp_strip_all_tags($string);  | 
                                                        |
| 272 | + $string = wp_specialchars_decode($string, ENT_QUOTES);  | 
                                                        |
| 273 | +		$string = preg_replace('/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string); | 
                                                        |
| 274 | +		$string = str_replace('-o-^-o-', ' - ', $string); | 
                                                        |
| 275 | + return html_entity_decode($string, ENT_QUOTES, 'UTF-8');  | 
                                                        |
| 276 | 276 | }  | 
                                                        
| 277 | 277 | }  |