@@ -4,7 +4,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |