Passed
Push — master ( 72af12...8565ec )
by Brian
11:19
created
includes/class-getpaid-subscription-notification-emails.php 2 patches
Indentation   +269 added lines, -269 removed lines patch added patch discarded remove patch
@@ -13,311 +13,311 @@
 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
-		if ( empty( $subscription ) ) {
156
-			return;
157
-		}
158
-
159
-		if ( is_array( $subscription ) ) {
160
-			$subscription = current( $subscription );
161
-		}
162
-
163
-		if ( ! $subscription instanceof WPInv_Subscription ) {
164
-			return;
165
-		}
166
-
167
-		// Abort in case the parent invoice does not exist.
168
-		$invoice = $subscription->get_parent_invoice();
169
-		if ( ! $this->should_send_notification( $invoice ) ) {
170
-			return;
171
-		}
172
-
173
-		if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) {
174
-			return;
175
-		}
176
-
177
-		do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
178
-
179
-		$recipients  = $this->get_recipients( $invoice );
180
-		$mailer      = new GetPaid_Notification_Email_Sender();
181
-		$merge_tags  = $email->get_merge_tags();
182
-		$content     = $email->get_content( $merge_tags, $extra_args );
183
-		$subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
184
-		$attachments = $email->get_attachments();
185
-
186
-		$result = $mailer->send(
187
-			apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
188
-			$subject,
189
-			$content,
190
-			$attachments
191
-		);
192
-
193
-		// Maybe send a copy to the admin.
194
-		if ( $email->include_admin_bcc() ) {
195
-			$mailer->send(
196
-				wpinv_get_admin_email(),
197
-				$subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
198
-				$content,
199
-				$attachments
200
-			);
201
-		}
202
-
203
-		if ( $result ) {
204
-			$invoice->add_system_note(
205
-				sprintf(
206
-					__( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
207
-					sanitize_key( $type ),
208
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
209
-				)
210
-			);
211
-		} else {
212
-			$invoice->add_system_note(
213
-				sprintf(
214
-					__( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
215
-					sanitize_key( $type ),
216
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
217
-				)
218
-			);
219
-		}
220
-
221
-		do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
222
-
223
-	}
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
+    }
224 67
 
225 68
     /**
226
-	 * Sends a new trial notification.
227
-	 *
228
-	 * @param WPInv_Subscription $subscription
229
-	 */
230
-	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 ) {
231 75
 
232
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
233
-		$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
+        }
234 82
 
235
-	}
83
+        return $merge_tags;
236 84
 
237
-	/**
238
-	 * Sends a cancelled subscription notification.
239
-	 *
240
-	 * @param WPInv_Subscription $subscription
241
-	 */
242
-	public function subscription_cancelled( $subscription ) {
85
+    }
243 86
 
244
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
245
-		$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
+        );
246 113
 
247
-	}
114
+    }
248 115
 
249
-	/**
250
-	 * Sends a subscription expired notification.
251
-	 *
252
-	 * @param WPInv_Subscription $subscription
253
-	 */
254
-	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
+    }
255 125
 
256
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
257
-		$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() );
258 134
 
259
-	}
135
+        $cc = $invoice->get_email_cc();
260 136
 
261
-	/**
262
-	 * Sends a completed subscription notification.
263
-	 *
264
-	 * @param WPInv_Subscription $subscription
265
-	 */
266
-	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
+        }
267 141
 
268
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
269
-		$this->send_email( $subscription, $email, __FUNCTION__ );
142
+        return $recipients;
143
+    }
270 144
 
271
-	}
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
+        if ( empty( $subscription ) ) {
156
+            return;
157
+        }
158
+
159
+        if ( is_array( $subscription ) ) {
160
+            $subscription = current( $subscription );
161
+        }
162
+
163
+        if ( ! $subscription instanceof WPInv_Subscription ) {
164
+            return;
165
+        }
166
+
167
+        // Abort in case the parent invoice does not exist.
168
+        $invoice = $subscription->get_parent_invoice();
169
+        if ( ! $this->should_send_notification( $invoice ) ) {
170
+            return;
171
+        }
172
+
173
+        if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) {
174
+            return;
175
+        }
176
+
177
+        do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
178
+
179
+        $recipients  = $this->get_recipients( $invoice );
180
+        $mailer      = new GetPaid_Notification_Email_Sender();
181
+        $merge_tags  = $email->get_merge_tags();
182
+        $content     = $email->get_content( $merge_tags, $extra_args );
183
+        $subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
184
+        $attachments = $email->get_attachments();
185
+
186
+        $result = $mailer->send(
187
+            apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
188
+            $subject,
189
+            $content,
190
+            $attachments
191
+        );
192
+
193
+        // Maybe send a copy to the admin.
194
+        if ( $email->include_admin_bcc() ) {
195
+            $mailer->send(
196
+                wpinv_get_admin_email(),
197
+                $subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
198
+                $content,
199
+                $attachments
200
+            );
201
+        }
202
+
203
+        if ( $result ) {
204
+            $invoice->add_system_note(
205
+                sprintf(
206
+                    __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
207
+                    sanitize_key( $type ),
208
+                    $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
209
+                )
210
+            );
211
+        } else {
212
+            $invoice->add_system_note(
213
+                sprintf(
214
+                    __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
215
+                    sanitize_key( $type ),
216
+                    $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
217
+                )
218
+            );
219
+        }
220
+
221
+        do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
272 222
 
273
-	/**
274
-	 * Sends a subscription renewal reminder notification.
275
-	 *
276
-	 */
277
-	public function renewal_reminder() {
223
+    }
278 224
 
279
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
225
+    /**
226
+     * Sends a new trial notification.
227
+     *
228
+     * @param WPInv_Subscription $subscription
229
+     */
230
+    public function subscription_trial( $subscription ) {
280 231
 
281
-		// Fetch reminder days.
282
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
232
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
233
+        $this->send_email( $subscription, $email, __FUNCTION__ );
283 234
 
284
-		// Abort if non is set.
285
-		if ( empty( $reminder_days ) ) {
286
-			return;
287
-		}
235
+    }
288 236
 
289
-		// Fetch matching subscriptions.
237
+    /**
238
+     * Sends a cancelled subscription notification.
239
+     *
240
+     * @param WPInv_Subscription $subscription
241
+     */
242
+    public function subscription_cancelled( $subscription ) {
243
+
244
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
245
+        $this->send_email( $subscription, $email, __FUNCTION__ );
246
+
247
+    }
248
+
249
+    /**
250
+     * Sends a subscription expired notification.
251
+     *
252
+     * @param WPInv_Subscription $subscription
253
+     */
254
+    public function subscription_expired( $subscription ) {
255
+
256
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
257
+        $this->send_email( $subscription, $email, __FUNCTION__ );
258
+
259
+    }
260
+
261
+    /**
262
+     * Sends a completed subscription notification.
263
+     *
264
+     * @param WPInv_Subscription $subscription
265
+     */
266
+    public function subscription_complete( $subscription ) {
267
+
268
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
269
+        $this->send_email( $subscription, $email, __FUNCTION__ );
270
+
271
+    }
272
+
273
+    /**
274
+     * Sends a subscription renewal reminder notification.
275
+     *
276
+     */
277
+    public function renewal_reminder() {
278
+
279
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
280
+
281
+        // Fetch reminder days.
282
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
283
+
284
+        // Abort if non is set.
285
+        if ( empty( $reminder_days ) ) {
286
+            return;
287
+        }
288
+
289
+        // Fetch matching subscriptions.
290 290
         $args  = array(
291 291
             'number'             => -1,
292
-			'count_total'        => false,
293
-			'status'             => 'trialling active',
292
+            'count_total'        => false,
293
+            'status'             => 'trialling active',
294 294
             'date_expires_query' => array(
295
-				'relation' => 'OR',
295
+                'relation' => 'OR',
296 296
             ),
297
-		);
297
+        );
298 298
 
299
-		foreach ( $reminder_days as $days ) {
300
-			$date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
299
+        foreach ( $reminder_days as $days ) {
300
+            $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
301 301
 
302
-			$args['date_expires_query'][] = array(
303
-				'year'  => $date['year'],
304
-				'month' => $date['month'],
305
-				'day'   => $date['day'],
306
-			);
302
+            $args['date_expires_query'][] = array(
303
+                'year'  => $date['year'],
304
+                'month' => $date['month'],
305
+                'day'   => $date['day'],
306
+            );
307 307
 
308
-		}
308
+        }
309 309
 
310
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
310
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
311 311
 
312 312
         foreach ( $subscriptions->get_results() as $subscription ) {
313 313
 
314
-			// Skip packages.
315
-			if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) {
316
-				$email->object = $subscription;
317
-            	$this->send_email( $subscription, $email, __FUNCTION__ );
318
-			}
319
-		}
314
+            // Skip packages.
315
+            if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) {
316
+                $email->object = $subscription;
317
+                $this->send_email( $subscription, $email, __FUNCTION__ );
318
+            }
319
+        }
320 320
 
321
-	}
321
+    }
322 322
 
323 323
 }
Please login to merge, or discard this patch.
Spacing   +73 added lines, -73 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,75 +150,75 @@  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
-		if ( empty( $subscription ) ) {
155
+		if (empty($subscription)) {
156 156
 			return;
157 157
 		}
158 158
 
159
-		if ( is_array( $subscription ) ) {
160
-			$subscription = current( $subscription );
159
+		if (is_array($subscription)) {
160
+			$subscription = current($subscription);
161 161
 		}
162 162
 
163
-		if ( ! $subscription instanceof WPInv_Subscription ) {
163
+		if (!$subscription instanceof WPInv_Subscription) {
164 164
 			return;
165 165
 		}
166 166
 
167 167
 		// Abort in case the parent invoice does not exist.
168 168
 		$invoice = $subscription->get_parent_invoice();
169
-		if ( ! $this->should_send_notification( $invoice ) ) {
169
+		if (!$this->should_send_notification($invoice)) {
170 170
 			return;
171 171
 		}
172 172
 
173
-		if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) {
173
+		if (apply_filters('getpaid_skip_subscription_email', false, $type, $subscription)) {
174 174
 			return;
175 175
 		}
176 176
 
177
-		do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
177
+		do_action('getpaid_before_send_subscription_notification', $type, $subscription, $email);
178 178
 
179
-		$recipients  = $this->get_recipients( $invoice );
179
+		$recipients  = $this->get_recipients($invoice);
180 180
 		$mailer      = new GetPaid_Notification_Email_Sender();
181 181
 		$merge_tags  = $email->get_merge_tags();
182
-		$content     = $email->get_content( $merge_tags, $extra_args );
183
-		$subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
182
+		$content     = $email->get_content($merge_tags, $extra_args);
183
+		$subject     = $email->add_merge_tags($email->get_subject(), $merge_tags);
184 184
 		$attachments = $email->get_attachments();
185 185
 
186 186
 		$result = $mailer->send(
187
-			apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
187
+			apply_filters('getpaid_subscription_email_recipients', wpinv_parse_list($recipients), $email),
188 188
 			$subject,
189 189
 			$content,
190 190
 			$attachments
191 191
 		);
192 192
 
193 193
 		// Maybe send a copy to the admin.
194
-		if ( $email->include_admin_bcc() ) {
194
+		if ($email->include_admin_bcc()) {
195 195
 			$mailer->send(
196 196
 				wpinv_get_admin_email(),
197
-				$subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
197
+				$subject . __(' - ADMIN BCC COPY', 'invoicing'),
198 198
 				$content,
199 199
 				$attachments
200 200
 			);
201 201
 		}
202 202
 
203
-		if ( $result ) {
203
+		if ($result) {
204 204
 			$invoice->add_system_note(
205 205
 				sprintf(
206
-					__( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
207
-					sanitize_key( $type ),
208
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
206
+					__('Successfully sent %1$s notification email to %2$s.', 'invoicing'),
207
+					sanitize_key($type),
208
+					$email->is_admin_email() ? __('admin') : __('the customer')
209 209
 				)
210 210
 			);
211 211
 		} else {
212 212
 			$invoice->add_system_note(
213 213
 				sprintf(
214
-					__( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
215
-					sanitize_key( $type ),
216
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
214
+					__('Failed sending %1$s notification email to %2$s.', 'invoicing'),
215
+					sanitize_key($type),
216
+					$email->is_admin_email() ? __('admin') : __('the customer')
217 217
 				)
218 218
 			);
219 219
 		}
220 220
 
221
-		do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
221
+		do_action('getpaid_after_send_subscription_notification', $type, $subscription, $email);
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_trial( $subscription ) {
230
+	public function subscription_trial($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_cancelled( $subscription ) {
242
+	public function subscription_cancelled($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_expired( $subscription ) {
254
+	public function subscription_expired($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
 
@@ -263,10 +263,10 @@  discard block
 block discarded – undo
263 263
 	 *
264 264
 	 * @param WPInv_Subscription $subscription
265 265
 	 */
266
-	public function subscription_complete( $subscription ) {
266
+	public function subscription_complete($subscription) {
267 267
 
268
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
269
-		$this->send_email( $subscription, $email, __FUNCTION__ );
268
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
269
+		$this->send_email($subscription, $email, __FUNCTION__);
270 270
 
271 271
 	}
272 272
 
@@ -276,18 +276,18 @@  discard block
 block discarded – undo
276 276
 	 */
277 277
 	public function renewal_reminder() {
278 278
 
279
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
279
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
280 280
 
281 281
 		// Fetch reminder days.
282
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
282
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
283 283
 
284 284
 		// Abort if non is set.
285
-		if ( empty( $reminder_days ) ) {
285
+		if (empty($reminder_days)) {
286 286
 			return;
287 287
 		}
288 288
 
289 289
 		// Fetch matching subscriptions.
290
-        $args  = array(
290
+        $args = array(
291 291
             'number'             => -1,
292 292
 			'count_total'        => false,
293 293
 			'status'             => 'trialling active',
@@ -296,8 +296,8 @@  discard block
 block discarded – undo
296 296
             ),
297 297
 		);
298 298
 
299
-		foreach ( $reminder_days as $days ) {
300
-			$date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
299
+		foreach ($reminder_days as $days) {
300
+			$date = date_parse(date('Y-m-d', strtotime("+$days days", current_time('timestamp'))));
301 301
 
302 302
 			$args['date_expires_query'][] = array(
303 303
 				'year'  => $date['year'],
@@ -307,14 +307,14 @@  discard block
 block discarded – undo
307 307
 
308 308
 		}
309 309
 
310
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
310
+		$subscriptions = new GetPaid_Subscriptions_Query($args);
311 311
 
312
-        foreach ( $subscriptions->get_results() as $subscription ) {
312
+        foreach ($subscriptions->get_results() as $subscription) {
313 313
 
314 314
 			// Skip packages.
315
-			if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) {
315
+			if (apply_filters('getpaid_send_subscription_renewal_reminder_email', true)) {
316 316
 				$email->object = $subscription;
317
-            	$this->send_email( $subscription, $email, __FUNCTION__ );
317
+            	$this->send_email($subscription, $email, __FUNCTION__);
318 318
 			}
319 319
 		}
320 320
 
Please login to merge, or discard this patch.
invoicing.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,16 +19,16 @@  discard block
 block discarded – undo
19 19
 
20 20
 // Define constants.
21 21
 if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) {
22
-	define( 'WPINV_PLUGIN_FILE', __FILE__ );
22
+    define( 'WPINV_PLUGIN_FILE', __FILE__ );
23 23
 }
24 24
 
25 25
 if ( ! defined( 'WPINV_VERSION' ) ) {
26
-	define( 'WPINV_VERSION', '2.6.10' );
26
+    define( 'WPINV_VERSION', '2.6.10' );
27 27
 }
28 28
 
29 29
 // Include the main Invoicing class.
30 30
 if ( ! class_exists( 'WPInv_Plugin', false ) ) {
31
-	require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php';
31
+    require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php';
32 32
 }
33 33
 
34 34
 /**
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
         $GLOBALS['invoicing'] = new WPInv_Plugin();
44 44
     }
45 45
 
46
-	return $GLOBALS['invoicing'];
46
+    return $GLOBALS['invoicing'];
47 47
 }
48 48
 
49 49
 /**
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -15,20 +15,20 @@  discard block
 block discarded – undo
15 15
  * @package GetPaid
16 16
  */
17 17
 
18
-defined( 'ABSPATH' ) || exit;
18
+defined('ABSPATH') || exit;
19 19
 
20 20
 // Define constants.
21
-if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) {
22
-	define( 'WPINV_PLUGIN_FILE', __FILE__ );
21
+if (!defined('WPINV_PLUGIN_FILE')) {
22
+	define('WPINV_PLUGIN_FILE', __FILE__);
23 23
 }
24 24
 
25
-if ( ! defined( 'WPINV_VERSION' ) ) {
26
-	define( 'WPINV_VERSION', '2.6.10' );
25
+if (!defined('WPINV_VERSION')) {
26
+	define('WPINV_VERSION', '2.6.10');
27 27
 }
28 28
 
29 29
 // Include the main Invoicing class.
30
-if ( ! class_exists( 'WPInv_Plugin', false ) ) {
31
-	require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php';
30
+if (!class_exists('WPInv_Plugin', false)) {
31
+	require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/class-wpinv.php';
32 32
 }
33 33
 
34 34
 /**
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
  */
40 40
 function getpaid() {
41 41
 
42
-    if ( empty( $GLOBALS['invoicing'] ) ) {
42
+    if (empty($GLOBALS['invoicing'])) {
43 43
         $GLOBALS['invoicing'] = new WPInv_Plugin();
44 44
     }
45 45
 
@@ -52,9 +52,9 @@  discard block
 block discarded – undo
52 52
  * @since  2.0.8
53 53
  */
54 54
 function getpaid_deactivation_hook() {
55
-    update_option( 'wpinv_flush_permalinks', 1 );
55
+    update_option('wpinv_flush_permalinks', 1);
56 56
 }
57
-register_deactivation_hook( __FILE__, 'getpaid_deactivation_hook' );
57
+register_deactivation_hook(__FILE__, 'getpaid_deactivation_hook');
58 58
 
59 59
 /**
60 60
  * @deprecated
@@ -64,4 +64,4 @@  discard block
 block discarded – undo
64 64
 }
65 65
 
66 66
 // Kickstart the plugin.
67
-add_action( 'plugins_loaded', 'getpaid', -100 );
67
+add_action('plugins_loaded', 'getpaid', -100);
Please login to merge, or discard this patch.
templates/invoice/invoice-meta.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -7,50 +7,50 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12
-$class = ! is_singular( 'page' ) ? 'px-1' : '';
12
+$class = !is_singular('page') ? 'px-1' : '';
13 13
 ?>
14 14
 
15
-        <?php do_action( 'getpaid_before_invoice_meta', $invoice ); ?>
15
+        <?php do_action('getpaid_before_invoice_meta', $invoice); ?>
16 16
         <div class="getpaid-invoice-meta-data">
17 17
 
18
-            <?php do_action( 'getpaid_before_invoice_meta_table', $invoice ); ?>
18
+            <?php do_action('getpaid_before_invoice_meta_table', $invoice); ?>
19 19
             <table class="table table-bordered">
20 20
                 <tbody>
21 21
 
22
-                    <?php do_action( 'getpaid_before_invoice_meta_rows', $invoice ); ?>
23
-                    <?php foreach ( $meta as $key => $data ) : ?>
22
+                    <?php do_action('getpaid_before_invoice_meta_rows', $invoice); ?>
23
+                    <?php foreach ($meta as $key => $data) : ?>
24 24
 
25
-                        <?php if ( ! empty( $data['value'] ) ) : ?>
25
+                        <?php if (!empty($data['value'])) : ?>
26 26
 
27
-                            <?php do_action( "getpaid_before_invoice_meta_$key", $invoice, $data ); ?>
27
+                            <?php do_action("getpaid_before_invoice_meta_$key", $invoice, $data); ?>
28 28
 
29
-                            <tr class="getpaid-invoice-meta-<?php echo esc_attr( $key ); ?>">
29
+                            <tr class="getpaid-invoice-meta-<?php echo esc_attr($key); ?>">
30 30
 
31
-                                <th class="<?php echo esc_attr( $class ); ?> font-weight-bold" style="width: 40%">
32
-                                    <?php echo esc_html( $data['label'] ); ?>
31
+                                <th class="<?php echo esc_attr($class); ?> font-weight-bold" style="width: 40%">
32
+                                    <?php echo esc_html($data['label']); ?>
33 33
                                 </th>
34 34
 
35
-                                <td class="<?php echo esc_attr( $class ); ?> <?php echo 'invoice_total' === $key ? 'font-weight-bold' : 'font-weight-normal'; ?> text-break" style="width: 60%">
36
-                                    <span class="getpaid-invoice-meta-<?php echo esc_attr( $key ); ?>-value"><?php echo wp_kses_post( $data['value'] ); ?></span>
35
+                                <td class="<?php echo esc_attr($class); ?> <?php echo 'invoice_total' === $key ? 'font-weight-bold' : 'font-weight-normal'; ?> text-break" style="width: 60%">
36
+                                    <span class="getpaid-invoice-meta-<?php echo esc_attr($key); ?>-value"><?php echo wp_kses_post($data['value']); ?></span>
37 37
                                 </td>
38 38
 
39 39
                             </tr>
40 40
 
41
-                            <?php do_action( "getpaid_after_invoice_meta_$key", $invoice, $data ); ?>
41
+                            <?php do_action("getpaid_after_invoice_meta_$key", $invoice, $data); ?>
42 42
 
43 43
                         <?php endif; ?>
44 44
 
45 45
                     <?php endforeach; ?>
46
-                    <?php do_action( 'getpaid_after_invoice_meta_rows', $invoice ); ?>
46
+                    <?php do_action('getpaid_after_invoice_meta_rows', $invoice); ?>
47 47
 
48 48
                 </tbody>
49 49
             </table>
50
-            <?php do_action( 'getpaid_after_invoice_meta_table', $invoice ); ?>
50
+            <?php do_action('getpaid_after_invoice_meta_table', $invoice); ?>
51 51
 
52 52
 
53 53
         </div>
54
-        <?php do_action( 'getpaid_after_invoice_meta', $invoice ); ?>
54
+        <?php do_action('getpaid_after_invoice_meta', $invoice); ?>
55 55
 
56 56
 <?php
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 2 patches
Indentation   +428 added lines, -428 removed lines patch added patch discarded remove patch
@@ -12,487 +12,487 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Invoice_Notification_Emails {
14 14
 
15
-	/**
16
-	 * The array of invoice email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $invoice_actions;
21
-
22
-	/**
23
-	 * Class constructor
24
-	 *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->invoice_actions = apply_filters(
29
-			'getpaid_notification_email_invoice_triggers',
30
-			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
-				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
-				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
-				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
-				'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
-				'getpaid_invoice_status_publish'        => 'completed_invoice',
37
-				'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
-				'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
-				'getpaid_new_customer_note'             => 'user_note',
40
-				'getpaid_daily_maintenance'             => 'overdue',
41
-			)
42
-		);
43
-
44
-		$this->init_hooks();
45
-
46
-	}
47
-
48
-	/**
49
-	 * Registers email hooks.
50
-	 */
51
-	public function init_hooks() {
52
-
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
-
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
58
-		}
59
-	}
60
-
61
-	/**
62
-	 * Registers an email hook for an invoice action.
63
-	 *
64
-	 * @param string $hook
65
-	 * @param string|array $email_type
66
-	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
68
-
69
-		$email_type = wpinv_parse_list( $email_type );
70
-
71
-		foreach ( $email_type as $type ) {
72
-
73
-			$email = new GetPaid_Notification_Email( $type );
74
-
75
-			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
77
-				continue;
78
-			}
79
-
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
82
-				continue;
83
-			}
84
-
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
-		}
87
-
88
-	}
89
-
90
-	/**
91
-	 * Filters invoice merge tags.
92
-	 *
93
-	 * @param array $merge_tags
94
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
-	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
97
-
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
-			return array_merge(
100
-				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
102
-			);
103
-		}
104
-
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
-			return array_merge(
107
-				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
109
-			);
110
-		}
111
-
112
-		return $merge_tags;
113
-
114
-	}
115
-
116
-	/**
117
-	 * Generates invoice merge tags.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return array
121
-	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
123
-
124
-		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
126
-			return array();
127
-		}
128
-
129
-		$merge_tags = array(
130
-			'{name}'                 => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'            => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'           => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'            => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'                => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'       => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'     => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'        => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
-			'{invoice_link}'         => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'     => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'         => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'     => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'        => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'        => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
-			'{invoice_description}'  => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'    => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'               => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
-		);
149
-
150
-		$payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
-
152
-		if ( is_array( $payment_form_data ) ) {
153
-
154
-			foreach ( $payment_form_data as $label => $value ) {
155
-
156
-				$label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
-				$value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
-
159
-				if ( is_scalar( $value ) ) {
160
-					$merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
-				}
162
-			}
163
-		}
164
-
165
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
166
-	}
167
-
168
-	/**
169
-	 * Helper function to send an email.
170
-	 *
171
-	 * @param WPInv_Invoice $invoice
172
-	 * @param GetPaid_Notification_Email $email
173
-	 * @param string $type
174
-	 * @param string|array $recipients
175
-	 * @param array $extra_args Extra template args.
176
-	 */
177
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
178
-
179
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
180
-
181
-		$skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
182
-		if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
183
-			return;
184
-		}
185
-
186
-		$mailer     = new GetPaid_Notification_Email_Sender();
187
-		$merge_tags = $email->get_merge_tags();
188
-
189
-		$result = $mailer->send(
190
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
191
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
192
-			$email->get_content( $merge_tags, $extra_args ),
193
-			$email->get_attachments()
194
-		);
195
-
196
-		// Maybe send a copy to the admin.
197
-		if ( $email->include_admin_bcc() ) {
198
-			$mailer->send(
199
-				wpinv_get_admin_email(),
200
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
201
-				$email->get_content( $merge_tags ),
202
-				$email->get_attachments()
203
-			);
204
-		}
205
-
206
-		if ( $result ) {
207
-			$invoice->add_system_note(
208
-				sprintf(
209
-					__( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
210
-					sanitize_key( $type ),
211
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
212
-				)
213
-			);
214
-		} else {
215
-			$invoice->add_system_note(
216
-				sprintf(
217
-					__( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
218
-					sanitize_key( $type ),
219
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
220
-				)
221
-			);
222
-		}
223
-
224
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
225
-
226
-		return $result;
227
-	}
228
-
229
-	/**
230
-	 * Also send emails to any cc users.
231
-	 *
232
-	 * @param array $recipients
233
-	 * @param GetPaid_Notification_Email $email
234
-	 */
235
-	public function filter_email_recipients( $recipients, $email ) {
236
-
237
-		if ( ! $email->is_admin_email() ) {
238
-			$cc   = $email->object->get_email_cc();
239
-			$cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
240
-
241
-			if ( ! empty( $cc ) ) {
242
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
243
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
244
-			}
245
-
246
-			if ( ! empty( $cc_2 ) ) {
247
-				$cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
248
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
249
-			}
15
+    /**
16
+     * The array of invoice email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $invoice_actions;
21
+
22
+    /**
23
+     * Class constructor
24
+     *
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->invoice_actions = apply_filters(
29
+            'getpaid_notification_email_invoice_triggers',
30
+            array(
31
+                'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
+                'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
+                'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
+                'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
+                'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
+                'getpaid_invoice_status_publish'        => 'completed_invoice',
37
+                'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
+                'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
+                'getpaid_new_customer_note'             => 'user_note',
40
+                'getpaid_daily_maintenance'             => 'overdue',
41
+            )
42
+        );
43
+
44
+        $this->init_hooks();
45
+
46
+    }
47
+
48
+    /**
49
+     * Registers email hooks.
50
+     */
51
+    public function init_hooks() {
52
+
53
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
+        add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
+
56
+        foreach ( $this->invoice_actions as $hook => $email_type ) {
57
+            $this->init_email_type_hook( $hook, $email_type );
58
+        }
59
+    }
60
+
61
+    /**
62
+     * Registers an email hook for an invoice action.
63
+     *
64
+     * @param string $hook
65
+     * @param string|array $email_type
66
+     */
67
+    public function init_email_type_hook( $hook, $email_type ) {
68
+
69
+        $email_type = wpinv_parse_list( $email_type );
70
+
71
+        foreach ( $email_type as $type ) {
72
+
73
+            $email = new GetPaid_Notification_Email( $type );
74
+
75
+            // Abort if it is not active.
76
+            if ( ! $email->is_active() ) {
77
+                continue;
78
+            }
79
+
80
+            if ( method_exists( $this, $type ) ) {
81
+                add_action( $hook, array( $this, $type ), 100, 2 );
82
+                continue;
83
+            }
84
+
85
+            do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
+        }
87
+
88
+    }
89
+
90
+    /**
91
+     * Filters invoice merge tags.
92
+     *
93
+     * @param array $merge_tags
94
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
+     */
96
+    public function invoice_merge_tags( $merge_tags, $object ) {
97
+
98
+        if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
+            return array_merge(
100
+                $merge_tags,
101
+                $this->get_invoice_merge_tags( $object )
102
+            );
103
+        }
104
+
105
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
+            return array_merge(
107
+                $merge_tags,
108
+                $this->get_invoice_merge_tags( $object->get_parent_payment() )
109
+            );
110
+        }
111
+
112
+        return $merge_tags;
113
+
114
+    }
115
+
116
+    /**
117
+     * Generates invoice merge tags.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return array
121
+     */
122
+    public function get_invoice_merge_tags( $invoice ) {
123
+
124
+        // Abort if it does not exist.
125
+        if ( ! $invoice->get_id() ) {
126
+            return array();
127
+        }
128
+
129
+        $merge_tags = array(
130
+            '{name}'                 => sanitize_text_field( $invoice->get_user_full_name() ),
131
+            '{full_name}'            => sanitize_text_field( $invoice->get_user_full_name() ),
132
+            '{first_name}'           => sanitize_text_field( $invoice->get_first_name() ),
133
+            '{last_name}'            => sanitize_text_field( $invoice->get_last_name() ),
134
+            '{email}'                => sanitize_email( $invoice->get_email() ),
135
+            '{invoice_number}'       => sanitize_text_field( $invoice->get_number() ),
136
+            '{invoice_currency}'     => sanitize_text_field( $invoice->get_currency() ),
137
+            '{invoice_total}'        => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
+            '{invoice_link}'         => esc_url( $invoice->get_view_url() ),
139
+            '{invoice_pay_link}'     => esc_url( $invoice->get_checkout_payment_url() ),
140
+            '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ),
141
+            '{invoice_date}'         => getpaid_format_date_value( $invoice->get_date_created() ),
142
+            '{invoice_due_date}'     => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
+            '{invoice_quote}'        => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
+            '{invoice_label}'        => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
+            '{invoice_description}'  => wp_kses_post( $invoice->get_description() ),
146
+            '{subscription_name}'    => wp_kses_post( $invoice->get_subscription_name() ),
147
+            '{is_was}'               => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
+        );
149
+
150
+        $payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
+
152
+        if ( is_array( $payment_form_data ) ) {
153
+
154
+            foreach ( $payment_form_data as $label => $value ) {
155
+
156
+                $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
+                $value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
+
159
+                if ( is_scalar( $value ) ) {
160
+                    $merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
+                }
162
+            }
163
+        }
164
+
165
+        return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
166
+    }
167
+
168
+    /**
169
+     * Helper function to send an email.
170
+     *
171
+     * @param WPInv_Invoice $invoice
172
+     * @param GetPaid_Notification_Email $email
173
+     * @param string $type
174
+     * @param string|array $recipients
175
+     * @param array $extra_args Extra template args.
176
+     */
177
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
178
+
179
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
180
+
181
+        $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
182
+        if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
183
+            return;
184
+        }
185
+
186
+        $mailer     = new GetPaid_Notification_Email_Sender();
187
+        $merge_tags = $email->get_merge_tags();
188
+
189
+        $result = $mailer->send(
190
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
191
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
192
+            $email->get_content( $merge_tags, $extra_args ),
193
+            $email->get_attachments()
194
+        );
195
+
196
+        // Maybe send a copy to the admin.
197
+        if ( $email->include_admin_bcc() ) {
198
+            $mailer->send(
199
+                wpinv_get_admin_email(),
200
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
201
+                $email->get_content( $merge_tags ),
202
+                $email->get_attachments()
203
+            );
204
+        }
205
+
206
+        if ( $result ) {
207
+            $invoice->add_system_note(
208
+                sprintf(
209
+                    __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
210
+                    sanitize_key( $type ),
211
+                    $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
212
+                )
213
+            );
214
+        } else {
215
+            $invoice->add_system_note(
216
+                sprintf(
217
+                    __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
218
+                    sanitize_key( $type ),
219
+                    $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
220
+                )
221
+            );
222
+        }
223
+
224
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
225
+
226
+        return $result;
227
+    }
228
+
229
+    /**
230
+     * Also send emails to any cc users.
231
+     *
232
+     * @param array $recipients
233
+     * @param GetPaid_Notification_Email $email
234
+     */
235
+    public function filter_email_recipients( $recipients, $email ) {
236
+
237
+        if ( ! $email->is_admin_email() ) {
238
+            $cc   = $email->object->get_email_cc();
239
+            $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
240
+
241
+            if ( ! empty( $cc ) ) {
242
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
243
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
244
+            }
245
+
246
+            if ( ! empty( $cc_2 ) ) {
247
+                $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
248
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
249
+            }
250 250
 }
251 251
 
252
-		return $recipients;
252
+        return $recipients;
253 253
 
254
-	}
254
+    }
255 255
 
256
-	/**
257
-	 * Sends a new invoice notification.
258
-	 *
259
-	 * @param WPInv_Invoice $invoice
260
-	 */
261
-	public function new_invoice( $invoice ) {
256
+    /**
257
+     * Sends a new invoice notification.
258
+     *
259
+     * @param WPInv_Invoice $invoice
260
+     */
261
+    public function new_invoice( $invoice ) {
262 262
 
263
-		// Only send this email for invoices created via the admin page.
264
-		if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
265
-			return;
266
-		}
263
+        // Only send this email for invoices created via the admin page.
264
+        if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
265
+            return;
266
+        }
267 267
 
268
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
269
-		$recipient = wpinv_get_admin_email();
268
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
269
+        $recipient = wpinv_get_admin_email();
270 270
 
271
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
271
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
272 272
 
273
-	}
273
+    }
274 274
 
275
-	/**
276
-	 * Sends a cancelled invoice notification.
277
-	 *
278
-	 * @param WPInv_Invoice $invoice
279
-	 */
280
-	public function cancelled_invoice( $invoice ) {
275
+    /**
276
+     * Sends a cancelled invoice notification.
277
+     *
278
+     * @param WPInv_Invoice $invoice
279
+     */
280
+    public function cancelled_invoice( $invoice ) {
281 281
 
282
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
283
-		$recipient = $invoice->get_email();
282
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
283
+        $recipient = $invoice->get_email();
284 284
 
285
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
286
-	}
285
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
286
+    }
287 287
 
288
-	/**
289
-	 * Sends a failed invoice notification.
290
-	 *
291
-	 * @param WPInv_Invoice $invoice
292
-	 */
293
-	public function failed_invoice( $invoice ) {
288
+    /**
289
+     * Sends a failed invoice notification.
290
+     *
291
+     * @param WPInv_Invoice $invoice
292
+     */
293
+    public function failed_invoice( $invoice ) {
294 294
 
295
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
296
-		$recipient = wpinv_get_admin_email();
295
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
296
+        $recipient = wpinv_get_admin_email();
297 297
 
298
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
298
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
299 299
 
300
-	}
300
+    }
301 301
 
302
-	/**
303
-	 * Sends a notification whenever an invoice is put on hold.
304
-	 *
305
-	 * @param WPInv_Invoice $invoice
306
-	 */
307
-	public function onhold_invoice( $invoice ) {
302
+    /**
303
+     * Sends a notification whenever an invoice is put on hold.
304
+     *
305
+     * @param WPInv_Invoice $invoice
306
+     */
307
+    public function onhold_invoice( $invoice ) {
308 308
 
309
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
310
-		$recipient = $invoice->get_email();
309
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
310
+        $recipient = $invoice->get_email();
311 311
 
312
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
312
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
313 313
 
314
-	}
314
+    }
315 315
 
316
-	/**
317
-	 * Sends a notification whenever an invoice is marked as processing payment.
318
-	 *
319
-	 * @param WPInv_Invoice $invoice
320
-	 */
321
-	public function processing_invoice( $invoice ) {
316
+    /**
317
+     * Sends a notification whenever an invoice is marked as processing payment.
318
+     *
319
+     * @param WPInv_Invoice $invoice
320
+     */
321
+    public function processing_invoice( $invoice ) {
322 322
 
323
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
324
-		$recipient = $invoice->get_email();
323
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
324
+        $recipient = $invoice->get_email();
325 325
 
326
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
326
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
327 327
 
328
-	}
328
+    }
329 329
 
330
-	/**
331
-	 * Sends a notification whenever an invoice is paid.
332
-	 *
333
-	 * @param WPInv_Invoice $invoice
334
-	 */
335
-	public function completed_invoice( $invoice ) {
330
+    /**
331
+     * Sends a notification whenever an invoice is paid.
332
+     *
333
+     * @param WPInv_Invoice $invoice
334
+     */
335
+    public function completed_invoice( $invoice ) {
336 336
 
337
-		// (Maybe) abort if it is a renewal invoice.
338
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
339
-			return;
340
-		}
337
+        // (Maybe) abort if it is a renewal invoice.
338
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
339
+            return;
340
+        }
341 341
 
342
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
343
-		$recipient = $invoice->get_email();
342
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
343
+        $recipient = $invoice->get_email();
344 344
 
345
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
345
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
346 346
 
347
-	}
347
+    }
348 348
 
349
-	/**
350
-	 * Sends a notification whenever an invoice is refunded.
351
-	 *
352
-	 * @param WPInv_Invoice $invoice
353
-	 */
354
-	public function refunded_invoice( $invoice ) {
349
+    /**
350
+     * Sends a notification whenever an invoice is refunded.
351
+     *
352
+     * @param WPInv_Invoice $invoice
353
+     */
354
+    public function refunded_invoice( $invoice ) {
355 355
 
356
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
357
-		$recipient = $invoice->get_email();
358
-
359
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
356
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
357
+        $recipient = $invoice->get_email();
358
+
359
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
360 360
 
361
-	}
361
+    }
362 362
 
363
-	/**
364
-	 * Notifies a user about new invoices
365
-	 *
366
-	 * @param WPInv_Invoice $invoice
367
-	 * @param bool $force
368
-	 */
369
-	public function user_invoice( $invoice, $force = false ) {
363
+    /**
364
+     * Notifies a user about new invoices
365
+     *
366
+     * @param WPInv_Invoice $invoice
367
+     * @param bool $force
368
+     */
369
+    public function user_invoice( $invoice, $force = false ) {
370 370
 
371
-		if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
372
-			return;
373
-		}
374
-
375
-		// Only send this email for invoices created via the admin page.
376
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
377
-			return;
378
-		}
371
+        if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
372
+            return;
373
+        }
374
+
375
+        // Only send this email for invoices created via the admin page.
376
+        if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
377
+            return;
378
+        }
379 379
 
380
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
381
-		$recipient = $invoice->get_email();
382
-
383
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
380
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
381
+        $recipient = $invoice->get_email();
382
+
383
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
384 384
 
385
-	}
386
-
387
-	/**
388
-	 * Checks if an invoice is a payment form invoice.
389
-	 *
390
-	 * @param int $invoice
391
-	 * @return bool
392
-	 */
393
-	public function is_payment_form_invoice( $invoice ) {
394
-		$is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' === get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' === get_post_meta( $invoice, 'wpinv_created_via', true ) );
395
-		return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
396
-	}
385
+    }
386
+
387
+    /**
388
+     * Checks if an invoice is a payment form invoice.
389
+     *
390
+     * @param int $invoice
391
+     * @return bool
392
+     */
393
+    public function is_payment_form_invoice( $invoice ) {
394
+        $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' === get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' === get_post_meta( $invoice, 'wpinv_created_via', true ) );
395
+        return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
396
+    }
397 397
 
398
-	/**
399
-	 * Notifies admin about new invoice notes
400
-	 *
401
-	 * @param WPInv_Invoice $invoice
402
-	 * @param string $note
403
-	 */
404
-	public function user_note( $invoice, $note ) {
405
-
406
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
407
-		$recipient = $invoice->get_email();
398
+    /**
399
+     * Notifies admin about new invoice notes
400
+     *
401
+     * @param WPInv_Invoice $invoice
402
+     * @param string $note
403
+     */
404
+    public function user_note( $invoice, $note ) {
405
+
406
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
407
+        $recipient = $invoice->get_email();
408 408
 
409
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
410
-
411
-	}
412
-
413
-	/**
414
-	 * (Force) Sends overdue notices.
415
-	 *
416
-	 * @param WPInv_Invoice $invoice
417
-	 */
418
-	public function force_send_overdue_notice( $invoice ) {
419
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
420
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
421
-	}
422
-
423
-	/**
424
-	 * Sends overdue notices.
425
-	 *
426
-	 * @TODO: Create an invoices query class.
427
-	 */
428
-	public function overdue() {
429
-		global $wpdb;
430
-
431
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
432
-
433
-		// Fetch reminder days.
434
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
435
-
436
-		// Abort if non is set.
437
-		if ( empty( $reminder_days ) ) {
438
-			return;
439
-		}
440
-
441
-		// Retrieve date query.
442
-		$date_query = $this->get_date_query( $reminder_days );
443
-
444
-		// Invoices table.
445
-		$table = $wpdb->prefix . 'getpaid_invoices';
446
-
447
-		// Fetch invoices.
448
-		$invoices  = $wpdb->get_col(
449
-			"SELECT posts.ID FROM $wpdb->posts as posts
409
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
410
+
411
+    }
412
+
413
+    /**
414
+     * (Force) Sends overdue notices.
415
+     *
416
+     * @param WPInv_Invoice $invoice
417
+     */
418
+    public function force_send_overdue_notice( $invoice ) {
419
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
420
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
421
+    }
422
+
423
+    /**
424
+     * Sends overdue notices.
425
+     *
426
+     * @TODO: Create an invoices query class.
427
+     */
428
+    public function overdue() {
429
+        global $wpdb;
430
+
431
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
432
+
433
+        // Fetch reminder days.
434
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
435
+
436
+        // Abort if non is set.
437
+        if ( empty( $reminder_days ) ) {
438
+            return;
439
+        }
440
+
441
+        // Retrieve date query.
442
+        $date_query = $this->get_date_query( $reminder_days );
443
+
444
+        // Invoices table.
445
+        $table = $wpdb->prefix . 'getpaid_invoices';
446
+
447
+        // Fetch invoices.
448
+        $invoices  = $wpdb->get_col(
449
+            "SELECT posts.ID FROM $wpdb->posts as posts
450 450
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
451 451
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"
452 452
         );
453 453
 
454
-		foreach ( $invoices as $invoice ) {
454
+        foreach ( $invoices as $invoice ) {
455 455
 
456
-			// Only send this email for invoices created via the admin page.
457
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
458
-				$invoice       = new WPInv_Invoice( $invoice );
459
-				$email->object = $invoice;
456
+            // Only send this email for invoices created via the admin page.
457
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
458
+                $invoice       = new WPInv_Invoice( $invoice );
459
+                $email->object = $invoice;
460 460
 
461
-				if ( $invoice->needs_payment() ) {
462
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
463
-				}
461
+                if ( $invoice->needs_payment() ) {
462
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
463
+                }
464 464
 }
465 465
 }
466 466
 
467
-	}
467
+    }
468 468
 
469
-	/**
470
-	 * Calculates the date query for an invoices query
471
-	 *
472
-	 * @param array $reminder_days
473
-	 * @return string
474
-	 */
475
-	public function get_date_query( $reminder_days ) {
469
+    /**
470
+     * Calculates the date query for an invoices query
471
+     *
472
+     * @param array $reminder_days
473
+     * @return string
474
+     */
475
+    public function get_date_query( $reminder_days ) {
476 476
 
477
-		$date_query = array(
478
-			'relation' => 'OR',
479
-		);
477
+        $date_query = array(
478
+            'relation' => 'OR',
479
+        );
480 480
 
481
-		foreach ( $reminder_days as $days ) {
482
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
481
+        foreach ( $reminder_days as $days ) {
482
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
483 483
 
484
-			$date_query[] = array(
485
-				'year'  => $date['year'],
486
-				'month' => $date['month'],
487
-				'day'   => $date['day'],
488
-			);
484
+            $date_query[] = array(
485
+                'year'  => $date['year'],
486
+                'month' => $date['month'],
487
+                'day'   => $date['day'],
488
+            );
489 489
 
490
-		}
490
+        }
491 491
 
492
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
492
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
493 493
 
494
-		return $date_query->get_sql();
494
+        return $date_query->get_sql();
495 495
 
496
-	}
496
+    }
497 497
 
498 498
 }
Please login to merge, or discard this patch.
Spacing   +125 added lines, -125 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 invoice notificaiton emails.
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 		$this->invoice_actions = apply_filters(
29 29
 			'getpaid_notification_email_invoice_triggers',
30 30
 			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
31
+				'getpaid_new_invoice'                   => array('new_invoice', 'user_invoice'),
32 32
 				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33 33
 				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34 34
 				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
@@ -50,11 +50,11 @@  discard block
 block discarded – undo
50 50
 	 */
51 51
 	public function init_hooks() {
52 52
 
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
53
+		add_filter('getpaid_get_email_merge_tags', array($this, 'invoice_merge_tags'), 10, 2);
54
+		add_filter('getpaid_invoice_email_recipients', array($this, 'filter_email_recipients'), 10, 2);
55 55
 
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
56
+		foreach ($this->invoice_actions as $hook => $email_type) {
57
+			$this->init_email_type_hook($hook, $email_type);
58 58
 		}
59 59
 	}
60 60
 
@@ -64,25 +64,25 @@  discard block
 block discarded – undo
64 64
 	 * @param string $hook
65 65
 	 * @param string|array $email_type
66 66
 	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
67
+	public function init_email_type_hook($hook, $email_type) {
68 68
 
69
-		$email_type = wpinv_parse_list( $email_type );
69
+		$email_type = wpinv_parse_list($email_type);
70 70
 
71
-		foreach ( $email_type as $type ) {
71
+		foreach ($email_type as $type) {
72 72
 
73
-			$email = new GetPaid_Notification_Email( $type );
73
+			$email = new GetPaid_Notification_Email($type);
74 74
 
75 75
 			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
76
+			if (!$email->is_active()) {
77 77
 				continue;
78 78
 			}
79 79
 
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
80
+			if (method_exists($this, $type)) {
81
+				add_action($hook, array($this, $type), 100, 2);
82 82
 				continue;
83 83
 			}
84 84
 
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
85
+			do_action('getpaid_invoice_init_email_type_hook', $type, $hook);
86 86
 		}
87 87
 
88 88
 	}
@@ -93,19 +93,19 @@  discard block
 block discarded – undo
93 93
 	 * @param array $merge_tags
94 94
 	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95 95
 	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
96
+	public function invoice_merge_tags($merge_tags, $object) {
97 97
 
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
98
+		if (is_a($object, 'WPInv_Invoice')) {
99 99
 			return array_merge(
100 100
 				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
101
+				$this->get_invoice_merge_tags($object)
102 102
 			);
103 103
 		}
104 104
 
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
105
+		if (is_a($object, 'WPInv_Subscription')) {
106 106
 			return array_merge(
107 107
 				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
108
+				$this->get_invoice_merge_tags($object->get_parent_payment())
109 109
 			);
110 110
 		}
111 111
 
@@ -119,50 +119,50 @@  discard block
 block discarded – undo
119 119
 	 * @param WPInv_Invoice $invoice
120 120
 	 * @return array
121 121
 	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
122
+	public function get_invoice_merge_tags($invoice) {
123 123
 
124 124
 		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
125
+		if (!$invoice->get_id()) {
126 126
 			return array();
127 127
 		}
128 128
 
129 129
 		$merge_tags = array(
130
-			'{name}'                 => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'            => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'           => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'            => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'                => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'       => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'     => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'        => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
-			'{invoice_link}'         => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'     => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'         => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'     => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'        => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'        => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
-			'{invoice_description}'  => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'    => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'               => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
130
+			'{name}'                 => sanitize_text_field($invoice->get_user_full_name()),
131
+			'{full_name}'            => sanitize_text_field($invoice->get_user_full_name()),
132
+			'{first_name}'           => sanitize_text_field($invoice->get_first_name()),
133
+			'{last_name}'            => sanitize_text_field($invoice->get_last_name()),
134
+			'{email}'                => sanitize_email($invoice->get_email()),
135
+			'{invoice_number}'       => sanitize_text_field($invoice->get_number()),
136
+			'{invoice_currency}'     => sanitize_text_field($invoice->get_currency()),
137
+			'{invoice_total}'        => sanitize_text_field(wpinv_price($invoice->get_total(), $invoice->get_currency())),
138
+			'{invoice_link}'         => esc_url($invoice->get_view_url()),
139
+			'{invoice_pay_link}'     => esc_url($invoice->get_checkout_payment_url()),
140
+			'{invoice_receipt_link}' => esc_url($invoice->get_receipt_url()),
141
+			'{invoice_date}'         => getpaid_format_date_value($invoice->get_date_created()),
142
+			'{invoice_due_date}'     => getpaid_format_date_value($invoice->get_due_date(), __('on receipt', 'invoicing')),
143
+			'{invoice_quote}'        => sanitize_text_field(strtolower($invoice->get_label())),
144
+			'{invoice_label}'        => sanitize_text_field(ucfirst($invoice->get_label())),
145
+			'{invoice_description}'  => wp_kses_post($invoice->get_description()),
146
+			'{subscription_name}'    => wp_kses_post($invoice->get_subscription_name()),
147
+			'{is_was}'               => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'),
148 148
 		);
149 149
 
150
-		$payment_form_data = $invoice->get_meta( 'payment_form_data', true );
150
+		$payment_form_data = $invoice->get_meta('payment_form_data', true);
151 151
 
152
-		if ( is_array( $payment_form_data ) ) {
152
+		if (is_array($payment_form_data)) {
153 153
 
154
-			foreach ( $payment_form_data as $label => $value ) {
154
+			foreach ($payment_form_data as $label => $value) {
155 155
 
156
-				$label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
-				$value = is_array( $value ) ? implode( ', ', $value ) : $value;
156
+				$label = preg_replace('/[^a-z0-9]+/', '_', strtolower($label));
157
+				$value = is_array($value) ? implode(', ', $value) : $value;
158 158
 
159
-				if ( is_scalar( $value ) ) {
160
-					$merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
159
+				if (is_scalar($value)) {
160
+					$merge_tags["{{$label}}"] = wp_kses_post($value);
161 161
 				}
162 162
 			}
163 163
 		}
164 164
 
165
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
165
+		return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice);
166 166
 	}
167 167
 
168 168
 	/**
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
 	 * @param string|array $recipients
175 175
 	 * @param array $extra_args Extra template args.
176 176
 	 */
177
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
177
+	public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) {
178 178
 
179
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
179
+		do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email);
180 180
 
181
-		$skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
182
-		if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
181
+		$skip = $invoice->is_free() && wpinv_get_option('skip_email_free_invoice');
182
+		if (apply_filters('getpaid_skip_invoice_email', $skip, $type, $invoice)) {
183 183
 			return;
184 184
 		}
185 185
 
@@ -187,41 +187,41 @@  discard block
 block discarded – undo
187 187
 		$merge_tags = $email->get_merge_tags();
188 188
 
189 189
 		$result = $mailer->send(
190
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
191
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
192
-			$email->get_content( $merge_tags, $extra_args ),
190
+			apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email),
191
+			$email->add_merge_tags($email->get_subject(), $merge_tags),
192
+			$email->get_content($merge_tags, $extra_args),
193 193
 			$email->get_attachments()
194 194
 		);
195 195
 
196 196
 		// Maybe send a copy to the admin.
197
-		if ( $email->include_admin_bcc() ) {
197
+		if ($email->include_admin_bcc()) {
198 198
 			$mailer->send(
199 199
 				wpinv_get_admin_email(),
200
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
201
-				$email->get_content( $merge_tags ),
200
+				$email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags),
201
+				$email->get_content($merge_tags),
202 202
 				$email->get_attachments()
203 203
 			);
204 204
 		}
205 205
 
206
-		if ( $result ) {
206
+		if ($result) {
207 207
 			$invoice->add_system_note(
208 208
 				sprintf(
209
-					__( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
210
-					sanitize_key( $type ),
211
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
209
+					__('Successfully sent %1$s notification email to %2$s.', 'invoicing'),
210
+					sanitize_key($type),
211
+					$email->is_admin_email() ? __('admin') : __('the customer')
212 212
 				)
213 213
 			);
214 214
 		} else {
215 215
 			$invoice->add_system_note(
216 216
 				sprintf(
217
-					__( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
218
-					sanitize_key( $type ),
219
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
217
+					__('Failed sending %1$s notification email to %2$s.', 'invoicing'),
218
+					sanitize_key($type),
219
+					$email->is_admin_email() ? __('admin') : __('the customer')
220 220
 				)
221 221
 			);
222 222
 		}
223 223
 
224
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
224
+		do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email);
225 225
 
226 226
 		return $result;
227 227
 	}
@@ -232,20 +232,20 @@  discard block
 block discarded – undo
232 232
 	 * @param array $recipients
233 233
 	 * @param GetPaid_Notification_Email $email
234 234
 	 */
235
-	public function filter_email_recipients( $recipients, $email ) {
235
+	public function filter_email_recipients($recipients, $email) {
236 236
 
237
-		if ( ! $email->is_admin_email() ) {
237
+		if (!$email->is_admin_email()) {
238 238
 			$cc   = $email->object->get_email_cc();
239
-			$cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
239
+			$cc_2 = get_user_meta($email->object->get_user_id(), '_wpinv_email_cc', true);
240 240
 
241
-			if ( ! empty( $cc ) ) {
242
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
243
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
241
+			if (!empty($cc)) {
242
+				$cc = array_map('sanitize_email', wpinv_parse_list($cc));
243
+				$recipients = array_filter(array_unique(array_merge($recipients, $cc)));
244 244
 			}
245 245
 
246
-			if ( ! empty( $cc_2 ) ) {
247
-				$cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
248
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
246
+			if (!empty($cc_2)) {
247
+				$cc_2 = array_map('sanitize_email', wpinv_parse_list($cc_2));
248
+				$recipients = array_filter(array_unique(array_merge($recipients, $cc_2)));
249 249
 			}
250 250
 }
251 251
 
@@ -258,17 +258,17 @@  discard block
 block discarded – undo
258 258
 	 *
259 259
 	 * @param WPInv_Invoice $invoice
260 260
 	 */
261
-	public function new_invoice( $invoice ) {
261
+	public function new_invoice($invoice) {
262 262
 
263 263
 		// Only send this email for invoices created via the admin page.
264
-		if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
264
+		if (!$invoice->is_type('invoice') || $invoice->is_paid() || $this->is_payment_form_invoice($invoice->get_id())) {
265 265
 			return;
266 266
 		}
267 267
 
268
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
268
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
269 269
 		$recipient = wpinv_get_admin_email();
270 270
 
271
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
271
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
272 272
 
273 273
 	}
274 274
 
@@ -277,12 +277,12 @@  discard block
 block discarded – undo
277 277
 	 *
278 278
 	 * @param WPInv_Invoice $invoice
279 279
 	 */
280
-	public function cancelled_invoice( $invoice ) {
280
+	public function cancelled_invoice($invoice) {
281 281
 
282
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
282
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
283 283
 		$recipient = $invoice->get_email();
284 284
 
285
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
285
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
286 286
 	}
287 287
 
288 288
 	/**
@@ -290,12 +290,12 @@  discard block
 block discarded – undo
290 290
 	 *
291 291
 	 * @param WPInv_Invoice $invoice
292 292
 	 */
293
-	public function failed_invoice( $invoice ) {
293
+	public function failed_invoice($invoice) {
294 294
 
295
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
295
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
296 296
 		$recipient = wpinv_get_admin_email();
297 297
 
298
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
298
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
299 299
 
300 300
 	}
301 301
 
@@ -304,12 +304,12 @@  discard block
 block discarded – undo
304 304
 	 *
305 305
 	 * @param WPInv_Invoice $invoice
306 306
 	 */
307
-	public function onhold_invoice( $invoice ) {
307
+	public function onhold_invoice($invoice) {
308 308
 
309
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
309
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
310 310
 		$recipient = $invoice->get_email();
311 311
 
312
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
312
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
313 313
 
314 314
 	}
315 315
 
@@ -318,12 +318,12 @@  discard block
 block discarded – undo
318 318
 	 *
319 319
 	 * @param WPInv_Invoice $invoice
320 320
 	 */
321
-	public function processing_invoice( $invoice ) {
321
+	public function processing_invoice($invoice) {
322 322
 
323
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
323
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
324 324
 		$recipient = $invoice->get_email();
325 325
 
326
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
326
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
327 327
 
328 328
 	}
329 329
 
@@ -332,17 +332,17 @@  discard block
 block discarded – undo
332 332
 	 *
333 333
 	 * @param WPInv_Invoice $invoice
334 334
 	 */
335
-	public function completed_invoice( $invoice ) {
335
+	public function completed_invoice($invoice) {
336 336
 
337 337
 		// (Maybe) abort if it is a renewal invoice.
338
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
338
+		if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) {
339 339
 			return;
340 340
 		}
341 341
 
342
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
342
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
343 343
 		$recipient = $invoice->get_email();
344 344
 
345
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
345
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
346 346
 
347 347
 	}
348 348
 
@@ -351,12 +351,12 @@  discard block
 block discarded – undo
351 351
 	 *
352 352
 	 * @param WPInv_Invoice $invoice
353 353
 	 */
354
-	public function refunded_invoice( $invoice ) {
354
+	public function refunded_invoice($invoice) {
355 355
 
356
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
356
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
357 357
 		$recipient = $invoice->get_email();
358 358
 
359
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
359
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
360 360
 
361 361
 	}
362 362
 
@@ -366,21 +366,21 @@  discard block
 block discarded – undo
366 366
 	 * @param WPInv_Invoice $invoice
367 367
 	 * @param bool $force
368 368
 	 */
369
-	public function user_invoice( $invoice, $force = false ) {
369
+	public function user_invoice($invoice, $force = false) {
370 370
 
371
-		if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
371
+		if (!$force && !empty($GLOBALS['wpinv_skip_invoice_notification'])) {
372 372
 			return;
373 373
 		}
374 374
 
375 375
 		// Only send this email for invoices created via the admin page.
376
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
376
+		if (!$invoice->is_type('invoice') || (empty($force) && $invoice->is_paid()) || (empty($force) && $this->is_payment_form_invoice($invoice->get_id()))) {
377 377
 			return;
378 378
 		}
379 379
 
380
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
380
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
381 381
 		$recipient = $invoice->get_email();
382 382
 
383
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
383
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
384 384
 
385 385
 	}
386 386
 
@@ -390,9 +390,9 @@  discard block
 block discarded – undo
390 390
 	 * @param int $invoice
391 391
 	 * @return bool
392 392
 	 */
393
-	public function is_payment_form_invoice( $invoice ) {
394
-		$is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' === get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' === get_post_meta( $invoice, 'wpinv_created_via', true ) );
395
-		return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
393
+	public function is_payment_form_invoice($invoice) {
394
+		$is_payment_form_invoice = empty($_GET['getpaid-admin-action']) && ('payment_form' === get_post_meta($invoice, 'wpinv_created_via', true) || 'geodirectory' === get_post_meta($invoice, 'wpinv_created_via', true));
395
+		return apply_filters('getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice);
396 396
 	}
397 397
 
398 398
 	/**
@@ -401,12 +401,12 @@  discard block
 block discarded – undo
401 401
 	 * @param WPInv_Invoice $invoice
402 402
 	 * @param string $note
403 403
 	 */
404
-	public function user_note( $invoice, $note ) {
404
+	public function user_note($invoice, $note) {
405 405
 
406
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
406
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
407 407
 		$recipient = $invoice->get_email();
408 408
 
409
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
409
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note));
410 410
 
411 411
 	}
412 412
 
@@ -415,9 +415,9 @@  discard block
 block discarded – undo
415 415
 	 *
416 416
 	 * @param WPInv_Invoice $invoice
417 417
 	 */
418
-	public function force_send_overdue_notice( $invoice ) {
419
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
420
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
418
+	public function force_send_overdue_notice($invoice) {
419
+		$email = new GetPaid_Notification_Email('overdue', $invoice);
420
+		return $this->send_email($invoice, $email, 'overdue', $invoice->get_email());
421 421
 	}
422 422
 
423 423
 	/**
@@ -428,38 +428,38 @@  discard block
 block discarded – undo
428 428
 	public function overdue() {
429 429
 		global $wpdb;
430 430
 
431
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
431
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
432 432
 
433 433
 		// Fetch reminder days.
434
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
434
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
435 435
 
436 436
 		// Abort if non is set.
437
-		if ( empty( $reminder_days ) ) {
437
+		if (empty($reminder_days)) {
438 438
 			return;
439 439
 		}
440 440
 
441 441
 		// Retrieve date query.
442
-		$date_query = $this->get_date_query( $reminder_days );
442
+		$date_query = $this->get_date_query($reminder_days);
443 443
 
444 444
 		// Invoices table.
445 445
 		$table = $wpdb->prefix . 'getpaid_invoices';
446 446
 
447 447
 		// Fetch invoices.
448
-		$invoices  = $wpdb->get_col(
448
+		$invoices = $wpdb->get_col(
449 449
 			"SELECT posts.ID FROM $wpdb->posts as posts
450 450
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
451 451
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"
452 452
         );
453 453
 
454
-		foreach ( $invoices as $invoice ) {
454
+		foreach ($invoices as $invoice) {
455 455
 
456 456
 			// Only send this email for invoices created via the admin page.
457
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
458
-				$invoice       = new WPInv_Invoice( $invoice );
457
+			if (!$this->is_payment_form_invoice($invoice)) {
458
+				$invoice       = new WPInv_Invoice($invoice);
459 459
 				$email->object = $invoice;
460 460
 
461
-				if ( $invoice->needs_payment() ) {
462
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
461
+				if ($invoice->needs_payment()) {
462
+					$this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email());
463 463
 				}
464 464
 }
465 465
 }
@@ -472,14 +472,14 @@  discard block
 block discarded – undo
472 472
 	 * @param array $reminder_days
473 473
 	 * @return string
474 474
 	 */
475
-	public function get_date_query( $reminder_days ) {
475
+	public function get_date_query($reminder_days) {
476 476
 
477 477
 		$date_query = array(
478 478
 			'relation' => 'OR',
479 479
 		);
480 480
 
481
-		foreach ( $reminder_days as $days ) {
482
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
481
+		foreach ($reminder_days as $days) {
482
+			$date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp'))));
483 483
 
484 484
 			$date_query[] = array(
485 485
 				'year'  => $date['year'],
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
 
490 490
 		}
491 491
 
492
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
492
+		$date_query = new WP_Date_Query($date_query, 'invoices.due_date');
493 493
 
494 494
 		return $date_query->get_sql();
495 495
 
Please login to merge, or discard this patch.
templates/invoice/line-totals.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -39,40 +39,40 @@
 block discarded – undo
39 39
                                 if ( 'tax' === $key ) {
40 40
                                     wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() );
41 41
 
42
-								if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) {
42
+                                if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) {
43 43
 
44
-									$taxes = $invoice->get_total_tax();
45
-									if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) {
46
-										echo ' <em class="text-muted small">';
47
-										_x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' );
48
-										echo '</em>';
44
+                                    $taxes = $invoice->get_total_tax();
45
+                                    if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) {
46
+                                        echo ' <em class="text-muted small">';
47
+                                        _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' );
48
+                                        echo '</em>';
49 49
                                     }
50 50
 }
51 51
 }
52 52
 
53 53
                                 // Total Fee.
54 54
                                 if ( 'fee' === $key ) {
55
-								wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() );
55
+                                wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() );
56 56
                                 }
57 57
 
58 58
                                 // Total discount.
59 59
                                 if ( 'discount' === $key ) {
60
-								wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() );
60
+                                wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() );
61 61
                                 }
62 62
 
63 63
                                 // Shipping.
64 64
                                 if ( 'shipping' === $key ) {
65
-								wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() );
65
+                                wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() );
66 66
                                 }
67 67
 
68 68
                                 // Sub total.
69 69
                                 if ( 'subtotal' === $key ) {
70
-								wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() );
70
+                                wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() );
71 71
                                 }
72 72
 
73 73
                                 // Total.
74 74
                                 if ( 'total' === $key ) {
75
-								wpinv_the_price( $invoice->get_total(), $invoice->get_currency() );
75
+                                wpinv_the_price( $invoice->get_total(), $invoice->get_currency() );
76 76
                                 }
77 77
 
78 78
                                 // Fires when printing a cart total.
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -9,26 +9,26 @@  discard block
 block discarded – undo
9 9
  * @var WPInv_Invoice $invoice
10 10
  */
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 // Totals rows.
15
-$totals = getpaid_invoice_totals_rows( $invoice );
15
+$totals = getpaid_invoice_totals_rows($invoice);
16 16
 
17
-do_action( 'getpaid_before_invoice_line_totals', $invoice, $totals );
17
+do_action('getpaid_before_invoice_line_totals', $invoice, $totals);
18 18
 
19 19
 ?>
20 20
 <div class='getpaid-invoice-line-totals'>
21 21
     <div class="row">
22 22
         <div class="col-12 offset-sm-6 col-sm-6 border-sm-left pl-sm-0">
23 23
 
24
-            <?php foreach ( $totals as $key => $label ) : ?>
24
+            <?php foreach ($totals as $key => $label) : ?>
25 25
 
26
-                <div class="getpaid-invoice-line-totals-col <?php echo esc_attr( $key ); ?>">
26
+                <div class="getpaid-invoice-line-totals-col <?php echo esc_attr($key); ?>">
27 27
 
28 28
                     <div class="form-row">
29 29
 
30 30
                         <div class="col-8 getpaid-invoice-line-totals-label">
31
-                            <?php echo esc_html( $label ); ?>
31
+                            <?php echo esc_html($label); ?>
32 32
                         </div>
33 33
 
34 34
                         <div class="col-4 getpaid-invoice-line-totals-value pl-0">
@@ -36,47 +36,47 @@  discard block
 block discarded – undo
36 36
                             <?php
37 37
 
38 38
                                 // Total tax.
39
-                                if ( 'tax' === $key ) {
40
-                                    wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() );
39
+                                if ('tax' === $key) {
40
+                                    wpinv_the_price($invoice->get_total_tax(), $invoice->get_currency());
41 41
 
42
-								if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) {
42
+								if (wpinv_use_taxes() && !$invoice->get_disable_taxes()) {
43 43
 
44 44
 									$taxes = $invoice->get_total_tax();
45
-									if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) {
45
+									if (empty($taxes) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) {
46 46
 										echo ' <em class="text-muted small">';
47
-										_x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' );
47
+										_x('(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing');
48 48
 										echo '</em>';
49 49
                                     }
50 50
 }
51 51
 }
52 52
 
53 53
                                 // Total Fee.
54
-                                if ( 'fee' === $key ) {
55
-								wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() );
54
+                                if ('fee' === $key) {
55
+								wpinv_the_price($invoice->get_total_fees(), $invoice->get_currency());
56 56
                                 }
57 57
 
58 58
                                 // Total discount.
59
-                                if ( 'discount' === $key ) {
60
-								wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() );
59
+                                if ('discount' === $key) {
60
+								wpinv_the_price($invoice->get_total_discount(), $invoice->get_currency());
61 61
                                 }
62 62
 
63 63
                                 // Shipping.
64
-                                if ( 'shipping' === $key ) {
65
-								wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() );
64
+                                if ('shipping' === $key) {
65
+								wpinv_the_price($invoice->get_shipping(), $invoice->get_currency());
66 66
                                 }
67 67
 
68 68
                                 // Sub total.
69
-                                if ( 'subtotal' === $key ) {
70
-								wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() );
69
+                                if ('subtotal' === $key) {
70
+								wpinv_the_price($invoice->get_subtotal(), $invoice->get_currency());
71 71
                                 }
72 72
 
73 73
                                 // Total.
74
-                                if ( 'total' === $key ) {
75
-								wpinv_the_price( $invoice->get_total(), $invoice->get_currency() );
74
+                                if ('total' === $key) {
75
+								wpinv_the_price($invoice->get_total(), $invoice->get_currency());
76 76
                                 }
77 77
 
78 78
                                 // Fires when printing a cart total.
79
-                                do_action( "getpaid_invoice_cart_totals_$key", $invoice );
79
+                                do_action("getpaid_invoice_cart_totals_$key", $invoice);
80 80
 
81 81
                             ?>
82 82
 
@@ -90,4 +90,4 @@  discard block
 block discarded – undo
90 90
     </div>
91 91
 </div> <!-- end .getpaid-invoice-line-totals -->
92 92
 
93
-<?php do_action( 'getpaid_after_invoice_line_totals', $invoice, $totals ); ?>
93
+<?php do_action('getpaid_after_invoice_line_totals', $invoice, $totals); ?>
Please login to merge, or discard this patch.