Passed
Push — master ( 618fc1...d0e164 )
by Brian
05:18
created
includes/class-getpaid-subscription-notification-emails.php 2 patches
Indentation   +257 added lines, -257 removed lines patch added patch discarded remove patch
@@ -13,300 +13,300 @@
 block discarded – undo
13 13
 class GetPaid_Subscription_Notification_Emails {
14 14
 
15 15
     /**
16
-	 * The array of subscription email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $subscription_actions;
16
+     * The array of subscription email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $subscription_actions;
21 21
 
22 22
     /**
23
-	 * Class constructor
23
+     * Class constructor
24 24
      *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->subscription_actions = apply_filters(
29
-			'getpaid_notification_email_subscription_triggers',
30
-			array(
31
-				'getpaid_subscription_trialling' => 'subscription_trial',
32
-				'getpaid_subscription_cancelled' => 'subscription_cancelled',
33
-				'getpaid_subscription_expired'   => 'subscription_expired',
34
-				'getpaid_subscription_completed' => 'subscription_complete',
35
-				'getpaid_daily_maintenance'      => 'renewal_reminder',
36
-			)
37
-		);
38
-
39
-		$this->init_hooks();
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->subscription_actions = apply_filters(
29
+            'getpaid_notification_email_subscription_triggers',
30
+            array(
31
+                'getpaid_subscription_trialling' => 'subscription_trial',
32
+                'getpaid_subscription_cancelled' => 'subscription_cancelled',
33
+                'getpaid_subscription_expired'   => 'subscription_expired',
34
+                'getpaid_subscription_completed' => 'subscription_complete',
35
+                'getpaid_daily_maintenance'      => 'renewal_reminder',
36
+            )
37
+        );
38
+
39
+        $this->init_hooks();
40 40
 
41 41
     }
42 42
 
43 43
     /**
44
-	 * Registers email hooks.
45
-	 */
46
-	public function init_hooks() {
47
-
48
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 );
49
-		foreach ( $this->subscription_actions as $hook => $email_type ) {
50
-
51
-			$email = new GetPaid_Notification_Email( $email_type );
52
-
53
-			if ( ! $email->is_active() ) {
54
-				continue;
55
-			}
56
-
57
-			if ( method_exists( $this, $email_type ) ) {
58
-				add_action( $hook, array( $this, $email_type ), 100, 2 );
59
-				continue;
60
-			}
61
-
62
-			do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook );
63
-
64
-		}
65
-
66
-	}
67
-
68
-	/**
69
-	 * Filters subscription merge tags.
70
-	 *
71
-	 * @param array $merge_tags
72
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
73
-	 */
74
-	public function subscription_merge_tags( $merge_tags, $object ) {
75
-
76
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
77
-			$merge_tags = array_merge(
78
-				$merge_tags,
79
-				$this->get_subscription_merge_tags( $object )
80
-			);
81
-		}
82
-
83
-		return $merge_tags;
84
-
85
-	}
86
-
87
-	/**
88
-	 * Generates subscription merge tags.
89
-	 *
90
-	 * @param WPInv_Subscription $subscription
91
-	 * @return array
92
-	 */
93
-	public function get_subscription_merge_tags( $subscription ) {
94
-
95
-		// Abort if it does not exist.
96
-		if ( ! $subscription->get_id() ) {
97
-			return array();
98
-		}
99
-
100
-		$invoice    = $subscription->get_parent_invoice();
101
-		return array(
102
-			'{subscription_renewal_date}'     => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ),
103
-			'{subscription_created}'          => getpaid_format_date_value( $subscription->get_date_created() ),
104
-			'{subscription_status}'           => sanitize_text_field( $subscription->get_status_label() ),
105
-			'{subscription_profile_id}'       => sanitize_text_field( $subscription->get_profile_id() ),
106
-			'{subscription_id}'               => absint( $subscription->get_id() ),
107
-			'{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ),
108
-			'{subscription_initial_amount}'   => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ),
109
-			'{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ),
110
-			'{subscription_bill_times}'       => $subscription->get_bill_times(),
111
-			'{subscription_url}'              => esc_url( $subscription->get_view_url() ),
112
-		);
113
-
114
-	}
115
-
116
-	/**
117
-	 * Checks if we should send a notification for a subscription.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return bool
121
-	 */
122
-	public function should_send_notification( $invoice ) {
123
-		return 0 != $invoice->get_id();
124
-	}
125
-
126
-	/**
127
-	 * Returns notification recipients.
128
-	 *
129
-	 * @param WPInv_Invoice $invoice
130
-	 * @return array
131
-	 */
132
-	public function get_recipients( $invoice ) {
133
-		$recipients = array( $invoice->get_email() );
134
-
135
-		$cc = $invoice->get_email_cc();
136
-
137
-		if ( ! empty( $cc ) ) {
138
-			$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
139
-			$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
140
-		}
141
-
142
-		return $recipients;
143
-	}
144
-
145
-	/**
146
-	 * Helper function to send an email.
147
-	 *
148
-	 * @param WPInv_Subscription $subscription
149
-	 * @param GetPaid_Notification_Email $email
150
-	 * @param string $type
151
-	 * @param array $extra_args Extra template args.
152
-	 */
153
-	public function send_email( $subscription, $email, $type, $extra_args = array() ) {
154
-
155
-		// Abort in case the parent invoice does not exist.
156
-		$invoice = $subscription->get_parent_invoice();
157
-		if ( ! $this->should_send_notification( $invoice ) ) {
158
-			return;
159
-		}
160
-
161
-		if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) {
162
-			return;
163
-		}
164
-
165
-		do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
166
-
167
-		$recipients  = $this->get_recipients( $invoice );
168
-		$mailer      = new GetPaid_Notification_Email_Sender();
169
-		$merge_tags  = $email->get_merge_tags();
170
-		$content     = $email->get_content( $merge_tags, $extra_args );
171
-		$subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
172
-		$attachments = $email->get_attachments();
173
-
174
-		$result = $mailer->send(
175
-			apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
176
-			$subject,
177
-			$content,
178
-			$attachments
179
-		);
180
-
181
-		// Maybe send a copy to the admin.
182
-		if ( $email->include_admin_bcc() ) {
183
-			$mailer->send(
184
-				wpinv_get_admin_email(),
185
-				$subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
186
-				$content,
187
-				$attachments
188
-			);
189
-		}
190
-
191
-		if ( $result ) {
192
-			$invoice->add_system_note(
193
-				sprintf(
194
-					__( 'Successfully sent %s notification email to %s.', 'invoicing' ),
195
-					sanitize_key( $type ),
196
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
197
-				)
198
-			);
199
-		} else {
200
-			$invoice->add_system_note(
201
-				sprintf(
202
-					__( 'Failed sending %s notification email to %s.', 'invoicing' ),
203
-					sanitize_key( $type ),
204
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
205
-				)
206
-			);	
207
-		}
208
-
209
-		do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
210
-
211
-	}
44
+     * Registers email hooks.
45
+     */
46
+    public function init_hooks() {
47
+
48
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 );
49
+        foreach ( $this->subscription_actions as $hook => $email_type ) {
50
+
51
+            $email = new GetPaid_Notification_Email( $email_type );
52
+
53
+            if ( ! $email->is_active() ) {
54
+                continue;
55
+            }
56
+
57
+            if ( method_exists( $this, $email_type ) ) {
58
+                add_action( $hook, array( $this, $email_type ), 100, 2 );
59
+                continue;
60
+            }
61
+
62
+            do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook );
63
+
64
+        }
65
+
66
+    }
212 67
 
213 68
     /**
214
-	 * Sends a new trial notification.
215
-	 *
216
-	 * @param WPInv_Subscription $subscription
217
-	 */
218
-	public function subscription_trial( $subscription ) {
69
+     * Filters subscription merge tags.
70
+     *
71
+     * @param array $merge_tags
72
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
73
+     */
74
+    public function subscription_merge_tags( $merge_tags, $object ) {
219 75
 
220
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
221
-		$this->send_email( $subscription, $email, __FUNCTION__ );
76
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
77
+            $merge_tags = array_merge(
78
+                $merge_tags,
79
+                $this->get_subscription_merge_tags( $object )
80
+            );
81
+        }
222 82
 
223
-	}
83
+        return $merge_tags;
224 84
 
225
-	/**
226
-	 * Sends a cancelled subscription notification.
227
-	 *
228
-	 * @param WPInv_Subscription $subscription
229
-	 */
230
-	public function subscription_cancelled( $subscription ) {
85
+    }
231 86
 
232
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
233
-		$this->send_email( $subscription, $email, __FUNCTION__ );
87
+    /**
88
+     * Generates subscription merge tags.
89
+     *
90
+     * @param WPInv_Subscription $subscription
91
+     * @return array
92
+     */
93
+    public function get_subscription_merge_tags( $subscription ) {
94
+
95
+        // Abort if it does not exist.
96
+        if ( ! $subscription->get_id() ) {
97
+            return array();
98
+        }
99
+
100
+        $invoice    = $subscription->get_parent_invoice();
101
+        return array(
102
+            '{subscription_renewal_date}'     => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ),
103
+            '{subscription_created}'          => getpaid_format_date_value( $subscription->get_date_created() ),
104
+            '{subscription_status}'           => sanitize_text_field( $subscription->get_status_label() ),
105
+            '{subscription_profile_id}'       => sanitize_text_field( $subscription->get_profile_id() ),
106
+            '{subscription_id}'               => absint( $subscription->get_id() ),
107
+            '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ),
108
+            '{subscription_initial_amount}'   => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ),
109
+            '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ),
110
+            '{subscription_bill_times}'       => $subscription->get_bill_times(),
111
+            '{subscription_url}'              => esc_url( $subscription->get_view_url() ),
112
+        );
234 113
 
235
-	}
114
+    }
236 115
 
237
-	/**
238
-	 * Sends a subscription expired notification.
239
-	 *
240
-	 * @param WPInv_Subscription $subscription
241
-	 */
242
-	public function subscription_expired( $subscription ) {
116
+    /**
117
+     * Checks if we should send a notification for a subscription.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return bool
121
+     */
122
+    public function should_send_notification( $invoice ) {
123
+        return 0 != $invoice->get_id();
124
+    }
243 125
 
244
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
245
-		$this->send_email( $subscription, $email, __FUNCTION__ );
126
+    /**
127
+     * Returns notification recipients.
128
+     *
129
+     * @param WPInv_Invoice $invoice
130
+     * @return array
131
+     */
132
+    public function get_recipients( $invoice ) {
133
+        $recipients = array( $invoice->get_email() );
246 134
 
247
-	}
135
+        $cc = $invoice->get_email_cc();
248 136
 
249
-	/**
250
-	 * Sends a completed subscription notification.
251
-	 *
252
-	 * @param WPInv_Subscription $subscription
253
-	 */
254
-	public function subscription_complete( $subscription ) {
137
+        if ( ! empty( $cc ) ) {
138
+            $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
139
+            $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
140
+        }
255 141
 
256
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
257
-		$this->send_email( $subscription, $email, __FUNCTION__ );
142
+        return $recipients;
143
+    }
258 144
 
259
-	}
145
+    /**
146
+     * Helper function to send an email.
147
+     *
148
+     * @param WPInv_Subscription $subscription
149
+     * @param GetPaid_Notification_Email $email
150
+     * @param string $type
151
+     * @param array $extra_args Extra template args.
152
+     */
153
+    public function send_email( $subscription, $email, $type, $extra_args = array() ) {
154
+
155
+        // Abort in case the parent invoice does not exist.
156
+        $invoice = $subscription->get_parent_invoice();
157
+        if ( ! $this->should_send_notification( $invoice ) ) {
158
+            return;
159
+        }
160
+
161
+        if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) {
162
+            return;
163
+        }
164
+
165
+        do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
166
+
167
+        $recipients  = $this->get_recipients( $invoice );
168
+        $mailer      = new GetPaid_Notification_Email_Sender();
169
+        $merge_tags  = $email->get_merge_tags();
170
+        $content     = $email->get_content( $merge_tags, $extra_args );
171
+        $subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
172
+        $attachments = $email->get_attachments();
173
+
174
+        $result = $mailer->send(
175
+            apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
176
+            $subject,
177
+            $content,
178
+            $attachments
179
+        );
180
+
181
+        // Maybe send a copy to the admin.
182
+        if ( $email->include_admin_bcc() ) {
183
+            $mailer->send(
184
+                wpinv_get_admin_email(),
185
+                $subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
186
+                $content,
187
+                $attachments
188
+            );
189
+        }
190
+
191
+        if ( $result ) {
192
+            $invoice->add_system_note(
193
+                sprintf(
194
+                    __( 'Successfully sent %s notification email to %s.', 'invoicing' ),
195
+                    sanitize_key( $type ),
196
+                    $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
197
+                )
198
+            );
199
+        } else {
200
+            $invoice->add_system_note(
201
+                sprintf(
202
+                    __( 'Failed sending %s notification email to %s.', 'invoicing' ),
203
+                    sanitize_key( $type ),
204
+                    $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
205
+                )
206
+            );	
207
+        }
208
+
209
+        do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
260 210
 
261
-	/**
262
-	 * Sends a subscription renewal reminder notification.
263
-	 *
264
-	 */
265
-	public function renewal_reminder() {
211
+    }
266 212
 
267
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
213
+    /**
214
+     * Sends a new trial notification.
215
+     *
216
+     * @param WPInv_Subscription $subscription
217
+     */
218
+    public function subscription_trial( $subscription ) {
268 219
 
269
-		// Fetch reminder days.
270
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
220
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
221
+        $this->send_email( $subscription, $email, __FUNCTION__ );
271 222
 
272
-		// Abort if non is set.
273
-		if ( empty( $reminder_days ) ) {
274
-			return;
275
-		}
223
+    }
276 224
 
277
-		// Fetch matching subscriptions.
225
+    /**
226
+     * Sends a cancelled subscription notification.
227
+     *
228
+     * @param WPInv_Subscription $subscription
229
+     */
230
+    public function subscription_cancelled( $subscription ) {
231
+
232
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
233
+        $this->send_email( $subscription, $email, __FUNCTION__ );
234
+
235
+    }
236
+
237
+    /**
238
+     * Sends a subscription expired notification.
239
+     *
240
+     * @param WPInv_Subscription $subscription
241
+     */
242
+    public function subscription_expired( $subscription ) {
243
+
244
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
245
+        $this->send_email( $subscription, $email, __FUNCTION__ );
246
+
247
+    }
248
+
249
+    /**
250
+     * Sends a completed subscription notification.
251
+     *
252
+     * @param WPInv_Subscription $subscription
253
+     */
254
+    public function subscription_complete( $subscription ) {
255
+
256
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
257
+        $this->send_email( $subscription, $email, __FUNCTION__ );
258
+
259
+    }
260
+
261
+    /**
262
+     * Sends a subscription renewal reminder notification.
263
+     *
264
+     */
265
+    public function renewal_reminder() {
266
+
267
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
268
+
269
+        // Fetch reminder days.
270
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
271
+
272
+        // Abort if non is set.
273
+        if ( empty( $reminder_days ) ) {
274
+            return;
275
+        }
276
+
277
+        // Fetch matching subscriptions.
278 278
         $args  = array(
279 279
             'number'             => -1,
280
-			'count_total'        => false,
281
-			'status'             => 'trialling active',
280
+            'count_total'        => false,
281
+            'status'             => 'trialling active',
282 282
             'date_expires_query' => array(
283
-				'relation'  => 'OR'
283
+                'relation'  => 'OR'
284 284
             ),
285
-		);
285
+        );
286 286
 
287
-		foreach ( $reminder_days as $days ) {
288
-			$date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
287
+        foreach ( $reminder_days as $days ) {
288
+            $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
289 289
 
290
-			$args['date_expires_query'][] = array(
291
-				'year'  => $date['year'],
292
-				'month' => $date['month'],
293
-				'day'   => $date['day'],
294
-			);
290
+            $args['date_expires_query'][] = array(
291
+                'year'  => $date['year'],
292
+                'month' => $date['month'],
293
+                'day'   => $date['day'],
294
+            );
295 295
 
296
-		}
296
+        }
297 297
 
298
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
298
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
299 299
 
300 300
         foreach ( $subscriptions as $subscription ) {
301 301
 
302
-			// Skip packages.
303
-			if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) {
304
-				$email->object = $subscription;
305
-            	$this->send_email( $subscription, $email, __FUNCTION__ );
306
-			}
302
+            // Skip packages.
303
+            if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) {
304
+                $email->object = $subscription;
305
+                $this->send_email( $subscription, $email, __FUNCTION__ );
306
+            }
307 307
 
308
-		}
308
+        }
309 309
 
310
-	}
310
+    }
311 311
 
312 312
 }
Please login to merge, or discard this patch.
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * This class handles subscription notificaiton emails.
@@ -45,21 +45,21 @@  discard block
 block discarded – undo
45 45
 	 */
46 46
 	public function init_hooks() {
47 47
 
48
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 );
49
-		foreach ( $this->subscription_actions as $hook => $email_type ) {
48
+		add_filter('getpaid_get_email_merge_tags', array($this, 'subscription_merge_tags'), 10, 2);
49
+		foreach ($this->subscription_actions as $hook => $email_type) {
50 50
 
51
-			$email = new GetPaid_Notification_Email( $email_type );
51
+			$email = new GetPaid_Notification_Email($email_type);
52 52
 
53
-			if ( ! $email->is_active() ) {
53
+			if (!$email->is_active()) {
54 54
 				continue;
55 55
 			}
56 56
 
57
-			if ( method_exists( $this, $email_type ) ) {
58
-				add_action( $hook, array( $this, $email_type ), 100, 2 );
57
+			if (method_exists($this, $email_type)) {
58
+				add_action($hook, array($this, $email_type), 100, 2);
59 59
 				continue;
60 60
 			}
61 61
 
62
-			do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook );
62
+			do_action('getpaid_subscription_notification_email_register_hook', $email_type, $hook);
63 63
 
64 64
 		}
65 65
 
@@ -71,12 +71,12 @@  discard block
 block discarded – undo
71 71
 	 * @param array $merge_tags
72 72
 	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
73 73
 	 */
74
-	public function subscription_merge_tags( $merge_tags, $object ) {
74
+	public function subscription_merge_tags($merge_tags, $object) {
75 75
 
76
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
76
+		if (is_a($object, 'WPInv_Subscription')) {
77 77
 			$merge_tags = array_merge(
78 78
 				$merge_tags,
79
-				$this->get_subscription_merge_tags( $object )
79
+				$this->get_subscription_merge_tags($object)
80 80
 			);
81 81
 		}
82 82
 
@@ -90,25 +90,25 @@  discard block
 block discarded – undo
90 90
 	 * @param WPInv_Subscription $subscription
91 91
 	 * @return array
92 92
 	 */
93
-	public function get_subscription_merge_tags( $subscription ) {
93
+	public function get_subscription_merge_tags($subscription) {
94 94
 
95 95
 		// Abort if it does not exist.
96
-		if ( ! $subscription->get_id() ) {
96
+		if (!$subscription->get_id()) {
97 97
 			return array();
98 98
 		}
99 99
 
100
-		$invoice    = $subscription->get_parent_invoice();
100
+		$invoice = $subscription->get_parent_invoice();
101 101
 		return array(
102
-			'{subscription_renewal_date}'     => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ),
103
-			'{subscription_created}'          => getpaid_format_date_value( $subscription->get_date_created() ),
104
-			'{subscription_status}'           => sanitize_text_field( $subscription->get_status_label() ),
105
-			'{subscription_profile_id}'       => sanitize_text_field( $subscription->get_profile_id() ),
106
-			'{subscription_id}'               => absint( $subscription->get_id() ),
107
-			'{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ),
108
-			'{subscription_initial_amount}'   => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ),
109
-			'{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ),
102
+			'{subscription_renewal_date}'     => getpaid_format_date_value($subscription->get_next_renewal_date(), __('Never', 'invoicing')),
103
+			'{subscription_created}'          => getpaid_format_date_value($subscription->get_date_created()),
104
+			'{subscription_status}'           => sanitize_text_field($subscription->get_status_label()),
105
+			'{subscription_profile_id}'       => sanitize_text_field($subscription->get_profile_id()),
106
+			'{subscription_id}'               => absint($subscription->get_id()),
107
+			'{subscription_recurring_amount}' => sanitize_text_field(wpinv_price($subscription->get_recurring_amount(), $invoice->get_currency())),
108
+			'{subscription_initial_amount}'   => sanitize_text_field(wpinv_price($subscription->get_initial_amount(), $invoice->get_currency())),
109
+			'{subscription_recurring_period}' => getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''),
110 110
 			'{subscription_bill_times}'       => $subscription->get_bill_times(),
111
-			'{subscription_url}'              => esc_url( $subscription->get_view_url() ),
111
+			'{subscription_url}'              => esc_url($subscription->get_view_url()),
112 112
 		);
113 113
 
114 114
 	}
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	 * @param WPInv_Invoice $invoice
120 120
 	 * @return bool
121 121
 	 */
122
-	public function should_send_notification( $invoice ) {
122
+	public function should_send_notification($invoice) {
123 123
 		return 0 != $invoice->get_id();
124 124
 	}
125 125
 
@@ -129,14 +129,14 @@  discard block
 block discarded – undo
129 129
 	 * @param WPInv_Invoice $invoice
130 130
 	 * @return array
131 131
 	 */
132
-	public function get_recipients( $invoice ) {
133
-		$recipients = array( $invoice->get_email() );
132
+	public function get_recipients($invoice) {
133
+		$recipients = array($invoice->get_email());
134 134
 
135 135
 		$cc = $invoice->get_email_cc();
136 136
 
137
-		if ( ! empty( $cc ) ) {
138
-			$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
139
-			$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
137
+		if (!empty($cc)) {
138
+			$cc = array_map('sanitize_email', wpinv_parse_list($cc));
139
+			$recipients = array_filter(array_unique(array_merge($recipients, $cc)));
140 140
 		}
141 141
 
142 142
 		return $recipients;
@@ -150,63 +150,63 @@  discard block
 block discarded – undo
150 150
 	 * @param string $type
151 151
 	 * @param array $extra_args Extra template args.
152 152
 	 */
153
-	public function send_email( $subscription, $email, $type, $extra_args = array() ) {
153
+	public function send_email($subscription, $email, $type, $extra_args = array()) {
154 154
 
155 155
 		// Abort in case the parent invoice does not exist.
156 156
 		$invoice = $subscription->get_parent_invoice();
157
-		if ( ! $this->should_send_notification( $invoice ) ) {
157
+		if (!$this->should_send_notification($invoice)) {
158 158
 			return;
159 159
 		}
160 160
 
161
-		if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) {
161
+		if (apply_filters('getpaid_skip_subscription_email', false, $type, $subscription)) {
162 162
 			return;
163 163
 		}
164 164
 
165
-		do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
165
+		do_action('getpaid_before_send_subscription_notification', $type, $subscription, $email);
166 166
 
167
-		$recipients  = $this->get_recipients( $invoice );
167
+		$recipients  = $this->get_recipients($invoice);
168 168
 		$mailer      = new GetPaid_Notification_Email_Sender();
169 169
 		$merge_tags  = $email->get_merge_tags();
170
-		$content     = $email->get_content( $merge_tags, $extra_args );
171
-		$subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
170
+		$content     = $email->get_content($merge_tags, $extra_args);
171
+		$subject     = $email->add_merge_tags($email->get_subject(), $merge_tags);
172 172
 		$attachments = $email->get_attachments();
173 173
 
174 174
 		$result = $mailer->send(
175
-			apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
175
+			apply_filters('getpaid_subscription_email_recipients', wpinv_parse_list($recipients), $email),
176 176
 			$subject,
177 177
 			$content,
178 178
 			$attachments
179 179
 		);
180 180
 
181 181
 		// Maybe send a copy to the admin.
182
-		if ( $email->include_admin_bcc() ) {
182
+		if ($email->include_admin_bcc()) {
183 183
 			$mailer->send(
184 184
 				wpinv_get_admin_email(),
185
-				$subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
185
+				$subject . __(' - ADMIN BCC COPY', 'invoicing'),
186 186
 				$content,
187 187
 				$attachments
188 188
 			);
189 189
 		}
190 190
 
191
-		if ( $result ) {
191
+		if ($result) {
192 192
 			$invoice->add_system_note(
193 193
 				sprintf(
194
-					__( 'Successfully sent %s notification email to %s.', 'invoicing' ),
195
-					sanitize_key( $type ),
196
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
194
+					__('Successfully sent %s notification email to %s.', 'invoicing'),
195
+					sanitize_key($type),
196
+					$email->is_admin_email() ? __('admin') : __('the customer')
197 197
 				)
198 198
 			);
199 199
 		} else {
200 200
 			$invoice->add_system_note(
201 201
 				sprintf(
202
-					__( 'Failed sending %s notification email to %s.', 'invoicing' ),
203
-					sanitize_key( $type ),
204
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
202
+					__('Failed sending %s notification email to %s.', 'invoicing'),
203
+					sanitize_key($type),
204
+					$email->is_admin_email() ? __('admin') : __('the customer')
205 205
 				)
206 206
 			);	
207 207
 		}
208 208
 
209
-		do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
209
+		do_action('getpaid_after_send_subscription_notification', $type, $subscription, $email);
210 210
 
211 211
 	}
212 212
 
@@ -215,10 +215,10 @@  discard block
 block discarded – undo
215 215
 	 *
216 216
 	 * @param WPInv_Subscription $subscription
217 217
 	 */
218
-	public function subscription_trial( $subscription ) {
218
+	public function subscription_trial($subscription) {
219 219
 
220
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
221
-		$this->send_email( $subscription, $email, __FUNCTION__ );
220
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
221
+		$this->send_email($subscription, $email, __FUNCTION__);
222 222
 
223 223
 	}
224 224
 
@@ -227,10 +227,10 @@  discard block
 block discarded – undo
227 227
 	 *
228 228
 	 * @param WPInv_Subscription $subscription
229 229
 	 */
230
-	public function subscription_cancelled( $subscription ) {
230
+	public function subscription_cancelled($subscription) {
231 231
 
232
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
233
-		$this->send_email( $subscription, $email, __FUNCTION__ );
232
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
233
+		$this->send_email($subscription, $email, __FUNCTION__);
234 234
 
235 235
 	}
236 236
 
@@ -239,10 +239,10 @@  discard block
 block discarded – undo
239 239
 	 *
240 240
 	 * @param WPInv_Subscription $subscription
241 241
 	 */
242
-	public function subscription_expired( $subscription ) {
242
+	public function subscription_expired($subscription) {
243 243
 
244
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
245
-		$this->send_email( $subscription, $email, __FUNCTION__ );
244
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
245
+		$this->send_email($subscription, $email, __FUNCTION__);
246 246
 
247 247
 	}
248 248
 
@@ -251,10 +251,10 @@  discard block
 block discarded – undo
251 251
 	 *
252 252
 	 * @param WPInv_Subscription $subscription
253 253
 	 */
254
-	public function subscription_complete( $subscription ) {
254
+	public function subscription_complete($subscription) {
255 255
 
256
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
257
-		$this->send_email( $subscription, $email, __FUNCTION__ );
256
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
257
+		$this->send_email($subscription, $email, __FUNCTION__);
258 258
 
259 259
 	}
260 260
 
@@ -264,18 +264,18 @@  discard block
 block discarded – undo
264 264
 	 */
265 265
 	public function renewal_reminder() {
266 266
 
267
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
267
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
268 268
 
269 269
 		// Fetch reminder days.
270
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
270
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
271 271
 
272 272
 		// Abort if non is set.
273
-		if ( empty( $reminder_days ) ) {
273
+		if (empty($reminder_days)) {
274 274
 			return;
275 275
 		}
276 276
 
277 277
 		// Fetch matching subscriptions.
278
-        $args  = array(
278
+        $args = array(
279 279
             'number'             => -1,
280 280
 			'count_total'        => false,
281 281
 			'status'             => 'trialling active',
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
             ),
285 285
 		);
286 286
 
287
-		foreach ( $reminder_days as $days ) {
288
-			$date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
287
+		foreach ($reminder_days as $days) {
288
+			$date = date_parse(date('Y-m-d', strtotime("+$days days", current_time('timestamp'))));
289 289
 
290 290
 			$args['date_expires_query'][] = array(
291 291
 				'year'  => $date['year'],
@@ -295,14 +295,14 @@  discard block
 block discarded – undo
295 295
 
296 296
 		}
297 297
 
298
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
298
+		$subscriptions = new GetPaid_Subscriptions_Query($args);
299 299
 
300
-        foreach ( $subscriptions as $subscription ) {
300
+        foreach ($subscriptions as $subscription) {
301 301
 
302 302
 			// Skip packages.
303
-			if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) {
303
+			if (apply_filters('getpaid_send_subscription_renewal_reminder_email', true)) {
304 304
 				$email->object = $subscription;
305
-            	$this->send_email( $subscription, $email, __FUNCTION__ );
305
+            	$this->send_email($subscription, $email, __FUNCTION__);
306 306
 			}
307 307
 
308 308
 		}
Please login to merge, or discard this patch.