Test Failed
Push — master ( 41f28b...b64360 )
by Devin
07:53 queued 13s
created
includes/admin/emails/class-email-notifications.php 1 patch
Spacing   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 * @return static
53 53
 	 */
54 54
 	static function get_instance() {
55
-		if ( null === static::$instance ) {
55
+		if (null === static::$instance) {
56 56
 			self::$instance = new static();
57 57
 		}
58 58
 
@@ -66,31 +66,31 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function init() {
68 68
 		// Load files.
69
-		require_once GIVE_PLUGIN_DIR . 'includes/admin/emails/ajax-handler.php';
70
-		require_once GIVE_PLUGIN_DIR . 'includes/admin/emails/class-email-setting-field.php';
71
-		require_once GIVE_PLUGIN_DIR . 'includes/admin/emails/filters.php';
69
+		require_once GIVE_PLUGIN_DIR.'includes/admin/emails/ajax-handler.php';
70
+		require_once GIVE_PLUGIN_DIR.'includes/admin/emails/class-email-setting-field.php';
71
+		require_once GIVE_PLUGIN_DIR.'includes/admin/emails/filters.php';
72 72
 
73 73
 		// Load email notifications.
74 74
 		$this->add_emails_notifications();
75 75
 
76
-		add_filter( 'give_metabox_form_data_settings', array( $this, 'add_metabox_setting_fields' ), 10, 2 );
77
-		add_action( 'init', array( $this, 'preview_email' ) );
78
-		add_action( 'init', array( $this, 'send_preview_email' ) );
79
-		add_action( 'init', array( $this, 'validate_settings' ) );
76
+		add_filter('give_metabox_form_data_settings', array($this, 'add_metabox_setting_fields'), 10, 2);
77
+		add_action('init', array($this, 'preview_email'));
78
+		add_action('init', array($this, 'send_preview_email'));
79
+		add_action('init', array($this, 'validate_settings'));
80 80
 
81 81
 		/* @var Give_Email_Notification $email */
82
-		foreach ( $this->get_email_notifications() as $email ) {
82
+		foreach ($this->get_email_notifications() as $email) {
83 83
 			// Setup email section.
84
-			if( Give_Email_Notification_Util::is_show_on_emails_setting_page( $email ) ) {
85
-				add_filter( 'give_get_sections_emails', array( $email, 'add_section' ) );
86
-				add_filter( "give_hide_section_{$email->config['id']}_on_emails_page", array( $email, 'hide_section' ) );
84
+			if (Give_Email_Notification_Util::is_show_on_emails_setting_page($email)) {
85
+				add_filter('give_get_sections_emails', array($email, 'add_section'));
86
+				add_filter("give_hide_section_{$email->config['id']}_on_emails_page", array($email, 'hide_section'));
87 87
 			}
88 88
 
89 89
 			// Setup email preview.
90
-			if ( Give_Email_Notification_Util::is_email_preview_has_header( $email ) ) {
91
-				add_action( "give_{$email->config['id']}_email_preview", array( $this, 'email_preview_header' ) );
92
-				add_filter( "give_{$email->config['id']}_email_preview_data", array( $this, 'email_preview_data' ) );
93
-				add_filter( "give_{$email->config['id']}_email_preview_message", array( $this, 'email_preview_message' ), 1, 2 );
90
+			if (Give_Email_Notification_Util::is_email_preview_has_header($email)) {
91
+				add_action("give_{$email->config['id']}_email_preview", array($this, 'email_preview_header'));
92
+				add_filter("give_{$email->config['id']}_email_preview_data", array($this, 'email_preview_data'));
93
+				add_filter("give_{$email->config['id']}_email_preview_message", array($this, 'email_preview_message'), 1, 2);
94 94
 			}
95 95
 		}
96 96
 	}
@@ -107,64 +107,64 @@  discard block
 block discarded – undo
107 107
 	 *
108 108
 	 * @return array
109 109
 	 */
110
-	public function add_metabox_setting_fields( $settings, $post_id ) {
110
+	public function add_metabox_setting_fields($settings, $post_id) {
111 111
 		$emails = $this->get_email_notifications();
112 112
 
113 113
 		// Bailout.
114
-		if ( empty( $emails ) ) {
114
+		if (empty($emails)) {
115 115
 			return $settings;
116 116
 		}
117 117
 
118 118
 		// Email notification setting.
119 119
 		$settings['email_notification_options'] = array(
120 120
 			'id'         => 'email_notification_options',
121
-			'title'      => __( 'Email Notifications', 'give' ),
121
+			'title'      => __('Email Notifications', 'give'),
122 122
 			'icon-html' => '<span class="dashicons dashicons-email-alt"></span>',
123 123
 			'fields'     => array(
124 124
 				array(
125
-					'name'        => __( 'Email Options', 'give' ),
126
-					'description' => __( '', 'give' ),
125
+					'name'        => __('Email Options', 'give'),
126
+					'description' => __('', 'give'),
127 127
 					'id'          => '_give_email_options',
128 128
 					'type'        => 'radio_inline',
129 129
 					'default'     => 'global',
130 130
 					'options'     => array(
131
-						'global'   => __( 'Global Options' ),
132
-						'enabled'  => __( 'Customize', 'give' ),
131
+						'global'   => __('Global Options'),
132
+						'enabled'  => __('Customize', 'give'),
133 133
 					),
134 134
 				),
135 135
 				array(
136 136
 					'id'      => '_give_email_template',
137
-					'name'    => esc_html__( 'Email Template', 'give' ),
138
-					'desc'    => esc_html__( 'Choose your template from the available registered template types.', 'give' ),
137
+					'name'    => esc_html__('Email Template', 'give'),
138
+					'desc'    => esc_html__('Choose your template from the available registered template types.', 'give'),
139 139
 					'type'    => 'select',
140 140
 					'default' => 'default',
141 141
 					'options' => give_get_email_templates(),
142 142
 				),
143 143
 				array(
144 144
 					'id'   => '_give_email_logo',
145
-					'name' => esc_html__( 'Logo', 'give' ),
146
-					'desc' => esc_html__( 'Upload or choose a logo to be displayed at the top of the donation receipt emails. Displayed on HTML emails only.', 'give' ),
145
+					'name' => esc_html__('Logo', 'give'),
146
+					'desc' => esc_html__('Upload or choose a logo to be displayed at the top of the donation receipt emails. Displayed on HTML emails only.', 'give'),
147 147
 					'type' => 'file',
148 148
 				),
149 149
 				array(
150 150
 					'id'      => '_give_from_name',
151
-					'name'    => esc_html__( 'From Name', 'give' ),
152
-					'desc'    => esc_html__( 'The name which appears in the "From" field in all Give donation emails.', 'give' ),
153
-					'default' => get_bloginfo( 'name' ),
151
+					'name'    => esc_html__('From Name', 'give'),
152
+					'desc'    => esc_html__('The name which appears in the "From" field in all Give donation emails.', 'give'),
153
+					'default' => get_bloginfo('name'),
154 154
 					'type'    => 'text',
155 155
 				),
156 156
 				array(
157 157
 					'id'      => '_give_from_email',
158
-					'name'    => esc_html__( 'From Email', 'give' ),
159
-					'desc'    => esc_html__( 'Email address from which all Give emails are sent from. This will act as the "from" and "reply-to" email address.', 'give' ),
160
-					'default' => get_bloginfo( 'admin_email' ),
158
+					'name'    => esc_html__('From Email', 'give'),
159
+					'desc'    => esc_html__('Email address from which all Give emails are sent from. This will act as the "from" and "reply-to" email address.', 'give'),
160
+					'default' => get_bloginfo('admin_email'),
161 161
 					'type'    => 'text',
162 162
 				),
163 163
 				array(
164 164
 					'name'  => 'email_notification_docs',
165 165
 					'type'  => 'docs_link',
166 166
 					'url'   => 'http://docs.givewp.com/email-notification',
167
-					'title' => __( 'Email Notification', 'give' ),
167
+					'title' => __('Email Notification', 'give'),
168 168
 				),
169 169
 			),
170 170
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 			 *
174 174
 			 * @since 2.0
175 175
 			 */
176
-			'sub-fields' => apply_filters( 'give_email_notification_options_metabox_fields', array(), $post_id ),
176
+			'sub-fields' => apply_filters('give_email_notification_options_metabox_fields', array(), $post_id),
177 177
 		);
178 178
 
179 179
 		return $settings;
@@ -187,13 +187,13 @@  discard block
 block discarded – undo
187 187
 	 */
188 188
 	private function add_emails_notifications() {
189 189
 		$this->emails = array(
190
-			include GIVE_PLUGIN_DIR . 'includes/admin/emails/class-new-donation-email.php',
191
-			include GIVE_PLUGIN_DIR . 'includes/admin/emails/class-donation-receipt-email.php',
192
-			include GIVE_PLUGIN_DIR . 'includes/admin/emails/class-new-offline-donation-email.php',
193
-			include GIVE_PLUGIN_DIR . 'includes/admin/emails/class-offline-donation-instruction-email.php',
194
-			include GIVE_PLUGIN_DIR . 'includes/admin/emails/class-new-donor-register-email.php',
195
-			include GIVE_PLUGIN_DIR . 'includes/admin/emails/class-donor-register-email.php',
196
-			include GIVE_PLUGIN_DIR . 'includes/admin/emails/class-email-access-email.php',
190
+			include GIVE_PLUGIN_DIR.'includes/admin/emails/class-new-donation-email.php',
191
+			include GIVE_PLUGIN_DIR.'includes/admin/emails/class-donation-receipt-email.php',
192
+			include GIVE_PLUGIN_DIR.'includes/admin/emails/class-new-offline-donation-email.php',
193
+			include GIVE_PLUGIN_DIR.'includes/admin/emails/class-offline-donation-instruction-email.php',
194
+			include GIVE_PLUGIN_DIR.'includes/admin/emails/class-new-donor-register-email.php',
195
+			include GIVE_PLUGIN_DIR.'includes/admin/emails/class-donor-register-email.php',
196
+			include GIVE_PLUGIN_DIR.'includes/admin/emails/class-email-access-email.php',
197 197
 		);
198 198
 
199 199
 		/**
@@ -201,15 +201,15 @@  discard block
 block discarded – undo
201 201
 		 *
202 202
 		 * @since 2.0
203 203
 		 */
204
-		$this->emails = apply_filters( 'give_email_notifications', $this->emails, $this );
204
+		$this->emails = apply_filters('give_email_notifications', $this->emails, $this);
205 205
 
206 206
 		// Bailout.
207
-		if ( empty( $this->emails ) ) {
207
+		if (empty($this->emails)) {
208 208
 			return;
209 209
 		}
210 210
 
211 211
 		// Initiate email notifications.
212
-		foreach ( $this->emails as $email ) {
212
+		foreach ($this->emails as $email) {
213 213
 			$email->init();
214 214
 		}
215 215
 	}
@@ -236,41 +236,41 @@  discard block
 block discarded – undo
236 236
 	 */
237 237
 	public function preview_email() {
238 238
 		// Bailout.
239
-		if ( ! Give_Email_Notification_Util::can_preview_email() ) {
239
+		if ( ! Give_Email_Notification_Util::can_preview_email()) {
240 240
 			return false;
241 241
 		}
242 242
 
243 243
 		// Security check.
244
-		give_validate_nonce( $_GET['_wpnonce'], 'give-preview-email' );
244
+		give_validate_nonce($_GET['_wpnonce'], 'give-preview-email');
245 245
 
246 246
 		// Get email type.
247
-		$email_type = isset( $_GET['email_type'] ) ? esc_attr( $_GET['email_type'] ) : '';
247
+		$email_type = isset($_GET['email_type']) ? esc_attr($_GET['email_type']) : '';
248 248
 
249 249
 		/* @var Give_Email_Notification $email */
250
-		foreach ( $this->get_email_notifications() as $email ) {
251
-			if ( $email_type !== $email->config['id'] ) {
250
+		foreach ($this->get_email_notifications() as $email) {
251
+			if ($email_type !== $email->config['id']) {
252 252
 				continue;
253 253
 			}
254 254
 
255 255
 			// Set form id.
256
-			$form_id = empty( $_GET['form_id']  ) ? null : absint( $_GET['form_id'] );
256
+			$form_id = empty($_GET['form_id']) ? null : absint($_GET['form_id']);
257 257
 
258 258
 			// Call setup email data to apply filter and other thing to email.
259 259
 			$email->setup_email_data();
260 260
 
261 261
 			// Decode message.
262
-			$email_message = $email->preview_email_template_tags( $email->get_email_message( $form_id ) );
262
+			$email_message = $email->preview_email_template_tags($email->get_email_message($form_id));
263 263
 
264 264
 			// Set email template.
265
-			Give()->emails->html    = true;
266
-			Give()->emails->__set( 'template', $email->get_email_template( $form_id ) );
265
+			Give()->emails->html = true;
266
+			Give()->emails->__set('template', $email->get_email_template($form_id));
267 267
 
268
-			if ( 'text/plain' === $email->config['content_type'] ) {
268
+			if ('text/plain' === $email->config['content_type']) {
269 269
 				// Give()->emails->__set( 'html', false );
270
-				Give()->emails->__set( 'template', 'none' );
270
+				Give()->emails->__set('template', 'none');
271 271
 			}
272 272
 
273
-			if ( $email_message = Give()->emails->build_email( $email_message ) ) {
273
+			if ($email_message = Give()->emails->build_email($email_message)) {
274 274
 
275 275
 				/**
276 276
 				 * Filter the email preview data
@@ -279,14 +279,14 @@  discard block
 block discarded – undo
279 279
 				 *
280 280
 				 * @param array
281 281
 				 */
282
-				$email_preview_data = apply_filters( "give_{$email_type}_email_preview_data", array() );
282
+				$email_preview_data = apply_filters("give_{$email_type}_email_preview_data", array());
283 283
 
284 284
 				/**
285 285
 				 * Fire the give_{$email_type}_email_preview action
286 286
 				 *
287 287
 				 * @since 2.0
288 288
 				 */
289
-				do_action( "give_{$email_type}_email_preview", $email );
289
+				do_action("give_{$email_type}_email_preview", $email);
290 290
 
291 291
 				/**
292 292
 				 * Filter the email message
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
 				 * @param array                   $email_preview_data
298 298
 				 * @param Give_Email_Notification $email
299 299
 				 */
300
-				echo apply_filters( "give_{$email_type}_email_preview_message", $email_message, $email_preview_data, $email );
300
+				echo apply_filters("give_{$email_type}_email_preview_message", $email_message, $email_preview_data, $email);
301 301
 
302 302
 				exit();
303 303
 			}
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
 	 *
314 314
 	 * @param Give_Email_Notification $email
315 315
 	 */
316
-	public function email_preview_header( $email ) {
316
+	public function email_preview_header($email) {
317 317
 		/**
318 318
 		 * Filter the all email preview headers.
319 319
 		 *
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 		 *
322 322
 		 * @param Give_Email_Notification $email
323 323
 		 */
324
-		$email_preview_header = apply_filters( 'give_email_preview_header', give_get_preview_email_header(), $email );
324
+		$email_preview_header = apply_filters('give_email_preview_header', give_get_preview_email_header(), $email);
325 325
 
326 326
 		echo $email_preview_header;
327 327
 	}
@@ -336,9 +336,9 @@  discard block
 block discarded – undo
336 336
 	 *
337 337
 	 * @return array
338 338
 	 */
339
-	public function email_preview_data( $email_preview_data ) {
340
-		$email_preview_data['payment_id'] = absint( give_check_variable( give_clean( $_GET ), 'isset', 0, 'preview_id' ) );
341
-		$email_preview_data['user_id']    = absint( give_check_variable( give_clean( $_GET ), 'isset', 0, 'user_id' ) );
339
+	public function email_preview_data($email_preview_data) {
340
+		$email_preview_data['payment_id'] = absint(give_check_variable(give_clean($_GET), 'isset', 0, 'preview_id'));
341
+		$email_preview_data['user_id']    = absint(give_check_variable(give_clean($_GET), 'isset', 0, 'user_id'));
342 342
 
343 343
 		return $email_preview_data;
344 344
 	}
@@ -354,12 +354,12 @@  discard block
 block discarded – undo
354 354
 	 *
355 355
 	 * @return string
356 356
 	 */
357
-	public function email_preview_message( $email_message, $email_preview_data ) {
357
+	public function email_preview_message($email_message, $email_preview_data) {
358 358
 		if (
359
-			! empty( $email_preview_data['payment_id'] )
360
-			|| ! empty( $email_preview_data['user_id'] )
359
+			! empty($email_preview_data['payment_id'])
360
+			|| ! empty($email_preview_data['user_id'])
361 361
 		) {
362
-			$email_message = give_do_email_tags( $email_message, $email_preview_data );
362
+			$email_message = give_do_email_tags($email_message, $email_preview_data);
363 363
 		}
364 364
 
365 365
 		return $email_message;
@@ -374,26 +374,26 @@  discard block
 block discarded – undo
374 374
 	 */
375 375
 	public function send_preview_email() {
376 376
 		// Bailout.
377
-		if ( ! Give_Email_Notification_Util::can_send_preview_email() ) {
377
+		if ( ! Give_Email_Notification_Util::can_send_preview_email()) {
378 378
 			return false;
379 379
 		}
380 380
 
381 381
 		// Security check.
382
-		give_validate_nonce( $_GET['_wpnonce'], 'give-send-preview-email' );
382
+		give_validate_nonce($_GET['_wpnonce'], 'give-send-preview-email');
383 383
 
384 384
 		// Get email type.
385
-		$email_type = give_check_variable( give_clean( $_GET ), 'isset', '', 'email_type' );
385
+		$email_type = give_check_variable(give_clean($_GET), 'isset', '', 'email_type');
386 386
 
387 387
 		/* @var Give_Email_Notification $email */
388
-		foreach ( $this->get_email_notifications() as $email ) {
389
-			if ( $email_type === $email->config['id'] && Give_Email_Notification_Util::is_email_preview( $email ) ) {
388
+		foreach ($this->get_email_notifications() as $email) {
389
+			if ($email_type === $email->config['id'] && Give_Email_Notification_Util::is_email_preview($email)) {
390 390
 				$email->send_preview_email();
391 391
 				break;
392 392
 			}
393 393
 		}
394 394
 
395 395
 		// Remove the test email query arg.
396
-		wp_redirect( remove_query_arg( 'give_action' ) );
396
+		wp_redirect(remove_query_arg('give_action'));
397 397
 		exit;
398 398
 	}
399 399
 
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
 	 * @access public
406 406
 	 */
407 407
 	public function load() {
408
-		add_action( 'init', array( $this, 'init' ), -1 );
408
+		add_action('init', array($this, 'init'), -1);
409 409
 	}
410 410
 
411 411
 
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
 		if (
421 421
 			! Give_Admin_Settings::is_saving_settings() ||
422 422
 			'emails' !== give_get_current_setting_tab() ||
423
-			! isset( $_GET['section'] )
423
+			! isset($_GET['section'])
424 424
 		) {
425 425
 			return;
426 426
 		}
@@ -428,18 +428,18 @@  discard block
 block discarded – undo
428 428
 		// Get email type.
429 429
 		$email_type = give_get_current_setting_section();
430 430
 
431
-		if ( ! empty( $_POST["{$email_type}_recipient"] ) ) {
432
-			$_POST["{$email_type}_recipient"] = array_unique( array_filter( $_POST["{$email_type}_recipient"] ) );
431
+		if ( ! empty($_POST["{$email_type}_recipient"])) {
432
+			$_POST["{$email_type}_recipient"] = array_unique(array_filter($_POST["{$email_type}_recipient"]));
433 433
 		}
434 434
 	}
435 435
 }
436 436
 
437 437
 // Helper class.
438
-require_once GIVE_PLUGIN_DIR . 'includes/admin/emails/abstract-email-notification.php';
439
-require_once GIVE_PLUGIN_DIR . 'includes/admin/emails/class-email-notification-util.php';
438
+require_once GIVE_PLUGIN_DIR.'includes/admin/emails/abstract-email-notification.php';
439
+require_once GIVE_PLUGIN_DIR.'includes/admin/emails/class-email-notification-util.php';
440 440
 
441 441
 // Add backward compatibility.
442
-require_once GIVE_PLUGIN_DIR . 'includes/admin/emails/backward-compatibility.php';
442
+require_once GIVE_PLUGIN_DIR.'includes/admin/emails/backward-compatibility.php';
443 443
 
444 444
 /**
445 445
  * Initialize functionality.
Please login to merge, or discard this patch.