Passed
Push — master ( 31f474...7d7341 )
by Kiran
10:27 queued 05:04
created
includes/abstracts/abstract-wpinv-privacy.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Abstract privacy class.
4 4
  */
5 5
 
6
-defined( 'ABSPATH' ) || exit;
6
+defined('ABSPATH') || exit;
7 7
 
8 8
 /**
9 9
  * Abstract class that is intended to be extended by
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      *
39 39
      * @param string $name Plugin identifier.
40 40
      */
41
-    public function __construct( $name = '' ) {
41
+    public function __construct($name = '') {
42 42
         $this->name = $name;
43 43
         $this->init();
44 44
     }
@@ -47,26 +47,26 @@  discard block
 block discarded – undo
47 47
      * Hook in events.
48 48
      */
49 49
     protected function init() {
50
-        add_action( 'admin_init', array( $this, 'add_privacy_message' ) );
50
+        add_action('admin_init', array($this, 'add_privacy_message'));
51 51
         // Register data exporters
52
-        add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'register_exporters' ), 10 );
52
+        add_filter('wp_privacy_personal_data_exporters', array($this, 'register_exporters'), 10);
53 53
         // Register data erasers
54
-        add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_erasers' ) );
54
+        add_filter('wp_privacy_personal_data_erasers', array($this, 'register_erasers'));
55 55
     }
56 56
 
57 57
     /**
58 58
      * Adds the privacy message on invoicing privacy page.
59 59
      */
60 60
     public function add_privacy_message() {
61
-        if ( function_exists( 'wp_add_privacy_policy_content' ) ) {
61
+        if (function_exists('wp_add_privacy_policy_content')) {
62 62
             $content = $this->get_privacy_message();
63 63
 
64
-            if ( $content ) {
65
-                if ( empty( $this->name ) ) {
66
-                    $this->name = __( 'GetPaid', 'invoicing' );
64
+            if ($content) {
65
+                if (empty($this->name)) {
66
+                    $this->name = __('GetPaid', 'invoicing');
67 67
                 }
68 68
 
69
-                wp_add_privacy_policy_content( $this->name, $this->get_privacy_message() );
69
+                wp_add_privacy_policy_content($this->name, $this->get_privacy_message());
70 70
             }
71 71
         }
72 72
     }
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
      * @param array $exporters List of exporter callbacks.
88 88
      * @return array
89 89
      */
90
-    public function register_exporters( $exporters = array() ) {
91
-        foreach ( $this->exporters as $id => $exporter ) {
92
-            $exporters[ $id ] = $exporter;
90
+    public function register_exporters($exporters = array()) {
91
+        foreach ($this->exporters as $id => $exporter) {
92
+            $exporters[$id] = $exporter;
93 93
         }
94 94
         return $exporters;
95 95
     }
@@ -100,9 +100,9 @@  discard block
 block discarded – undo
100 100
      * @param array $erasers List of eraser callbacks.
101 101
      * @return array
102 102
      */
103
-    public function register_erasers( $erasers = array() ) {
104
-        foreach ( $this->erasers as $id => $eraser ) {
105
-            $erasers[ $id ] = $eraser;
103
+    public function register_erasers($erasers = array()) {
104
+        foreach ($this->erasers as $id => $eraser) {
105
+            $erasers[$id] = $eraser;
106 106
         }
107 107
         return $erasers;
108 108
     }
@@ -116,8 +116,8 @@  discard block
 block discarded – undo
116 116
      *
117 117
      * @return array
118 118
      */
119
-    public function add_exporter( $id, $name, $callback ) {
120
-        $this->exporters[ $id ] = array(
119
+    public function add_exporter($id, $name, $callback) {
120
+        $this->exporters[$id] = array(
121 121
             'exporter_friendly_name' => $name,
122 122
             'callback'               => $callback,
123 123
         );
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
133 133
      *
134 134
      * @return array
135 135
      */
136
-    public function add_eraser( $id, $name, $callback ) {
137
-        $this->erasers[ $id ] = array(
136
+    public function add_eraser($id, $name, $callback) {
137
+        $this->erasers[$id] = array(
138 138
             'eraser_friendly_name' => $name,
139 139
             'callback'             => $callback,
140 140
         );
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 2 patches
Indentation   +469 added lines, -469 removed lines patch added patch discarded remove patch
@@ -12,492 +12,492 @@
 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
-		add_action( 'init', array( $this, 'init_hooks' ) );
45
-	}
46
-
47
-	/**
48
-	 * Registers email hooks.
49
-	 */
50
-	public function init_hooks() {
51
-
52
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
53
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
54
-
55
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
56
-			$this->init_email_type_hook( $hook, $email_type );
57
-		}
58
-	}
59
-
60
-	/**
61
-	 * Registers an email hook for an invoice action.
62
-	 *
63
-	 * @param string $hook
64
-	 * @param string|array $email_type
65
-	 */
66
-	public function init_email_type_hook( $hook, $email_type ) {
67
-
68
-		$email_type = wpinv_parse_list( $email_type );
69
-
70
-		foreach ( $email_type as $type ) {
71
-
72
-			$email = new GetPaid_Notification_Email( $type );
73
-
74
-			// Abort if it is not active.
75
-			if ( ! $email->is_active() ) {
76
-				continue;
77
-			}
78
-
79
-			if ( method_exists( $this, $type ) ) {
80
-				add_action( $hook, array( $this, $type ), 100, 2 );
81
-				continue;
82
-			}
83
-
84
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
85
-		}
86
-
87
-	}
88
-
89
-	/**
90
-	 * Filters invoice merge tags.
91
-	 *
92
-	 * @param array $merge_tags
93
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
94
-	 */
95
-	public function invoice_merge_tags( $merge_tags, $object ) {
96
-
97
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
98
-			return array_merge(
99
-				$merge_tags,
100
-				$this->get_invoice_merge_tags( $object )
101
-			);
102
-		}
103
-
104
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
105
-			return array_merge(
106
-				$merge_tags,
107
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
108
-			);
109
-		}
110
-
111
-		return $merge_tags;
112
-
113
-	}
114
-
115
-	/**
116
-	 * Generates invoice merge tags.
117
-	 *
118
-	 * @param WPInv_Invoice $invoice
119
-	 * @return array
120
-	 */
121
-	public function get_invoice_merge_tags( $invoice ) {
122
-
123
-		// Abort if it does not exist.
124
-		if ( ! $invoice->get_id() ) {
125
-			return array();
126
-		}
127
-
128
-		$due_date   = $invoice->get_due_date();
129
-		$due_date   = empty( $due_date ) ? time() + MINUTE_IN_SECONDS : strtotime( $due_date ) + ( (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
130
-		$merge_tags = array(
131
-			'{name}'                 => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{full_name}'            => sanitize_text_field( $invoice->get_user_full_name() ),
133
-			'{first_name}'           => sanitize_text_field( $invoice->get_first_name() ),
134
-			'{last_name}'            => sanitize_text_field( $invoice->get_last_name() ),
135
-			'{email}'                => sanitize_email( $invoice->get_email() ),
136
-			'{invoice_number}'       => sanitize_text_field( $invoice->get_number() ),
137
-			'{invoice_currency}'     => sanitize_text_field( $invoice->get_currency() ),
138
-			'{invoice_total}'        => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
139
-			'{invoice_link}'         => esc_url( $invoice->get_view_url() ),
140
-			'{invoice_pay_link}'     => esc_url( $invoice->get_checkout_payment_url() ),
141
-			'{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ),
142
-			'{invoice_date}'         => getpaid_format_date_value( $invoice->get_date_created() ),
143
-			'{invoice_due_date}'     => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
144
-			'{invoice_quote}'        => sanitize_text_field( strtolower( $invoice->get_label() ) ),
145
-			'{invoice_label}'        => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
146
-			'{invoice_description}'  => wp_kses_post( $invoice->get_description() ),
147
-			'{subscription_name}'    => wp_kses_post( $invoice->get_subscription_name() ),
148
-			'{is_was}'               => $due_date < time() ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
149
-		);
150
-
151
-		$payment_form_data = $invoice->get_meta( 'payment_form_data', true );
152
-
153
-		if ( is_array( $payment_form_data ) ) {
154
-
155
-			foreach ( $payment_form_data as $label => $value ) {
156
-
157
-				$label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
158
-				$value = is_array( $value ) ? implode( ', ', $value ) : $value;
159
-
160
-				if ( is_scalar( $value ) ) {
161
-					$merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
162
-				}
163
-			}
164
-		}
165
-
166
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
167
-	}
168
-
169
-	/**
170
-	 * Helper function to send an email.
171
-	 *
172
-	 * @param WPInv_Invoice $invoice
173
-	 * @param GetPaid_Notification_Email $email
174
-	 * @param string $type
175
-	 * @param string|array $recipients
176
-	 * @param array $extra_args Extra template args.
177
-	 */
178
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
179
-
180
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
181
-
182
-		$skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
183
-		if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
184
-			return;
185
-		}
186
-
187
-		$mailer     = new GetPaid_Notification_Email_Sender();
188
-		$merge_tags = $email->get_merge_tags();
189
-
190
-		$result = $mailer->send(
191
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
192
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
193
-			$email->get_content( $merge_tags, $extra_args ),
194
-			$email->get_attachments()
195
-		);
196
-
197
-		// Maybe send a copy to the admin.
198
-		if ( $email->include_admin_bcc() ) {
199
-			$mailer->send(
200
-				wpinv_get_admin_email(),
201
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
202
-				$email->get_content( $merge_tags ),
203
-				$email->get_attachments()
204
-			);
205
-		}
206
-
207
-		if ( $result ) {
208
-			$invoice->add_system_note(
209
-				sprintf(
210
-					// translators: %1 is the email type, %2 is the invoice recipient.
211
-					__( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
212
-					sanitize_key( $type ),
213
-					$email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
214
-				)
215
-			);
216
-		} else {
217
-			$invoice->add_system_note(
218
-				sprintf(
219
-					// translators: %1 is the email type, %2 is the invoice recipient.
220
-					__( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
221
-					sanitize_key( $type ),
222
-					$email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
223
-				)
224
-			);
225
-		}
226
-
227
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
228
-
229
-		return $result;
230
-	}
231
-
232
-	/**
233
-	 * Also send emails to any cc users.
234
-	 *
235
-	 * @param array $recipients
236
-	 * @param GetPaid_Notification_Email $email
237
-	 */
238
-	public function filter_email_recipients( $recipients, $email ) {
239
-
240
-		if ( ! $email->is_admin_email() ) {
241
-			$cc   = $email->object->get_email_cc();
242
-			$cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
243
-
244
-			if ( ! empty( $cc ) ) {
245
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
246
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
247
-			}
248
-
249
-			if ( ! empty( $cc_2 ) ) {
250
-				$cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
251
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
252
-			}
253
-		}
254
-
255
-		return $recipients;
256
-
257
-	}
258
-
259
-	/**
260
-	 * Sends a new invoice notification.
261
-	 *
262
-	 * @param WPInv_Invoice $invoice
263
-	 */
264
-	public function new_invoice( $invoice ) {
265
-
266
-		// Only send this email for invoices created via the admin page.
267
-		if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
268
-			return;
269
-		}
270
-
271
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
272
-		$recipient = wpinv_get_admin_email();
273
-
274
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
275
-
276
-	}
277
-
278
-	/**
279
-	 * Sends a cancelled invoice notification.
280
-	 *
281
-	 * @param WPInv_Invoice $invoice
282
-	 */
283
-	public function cancelled_invoice( $invoice ) {
284
-
285
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
286
-		$recipient = $invoice->get_email();
287
-
288
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
289
-	}
290
-
291
-	/**
292
-	 * Sends a failed invoice notification.
293
-	 *
294
-	 * @param WPInv_Invoice $invoice
295
-	 */
296
-	public function failed_invoice( $invoice ) {
297
-
298
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
299
-		$recipient = wpinv_get_admin_email();
300
-
301
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
302
-
303
-	}
304
-
305
-	/**
306
-	 * Sends a notification whenever an invoice is put on hold.
307
-	 *
308
-	 * @param WPInv_Invoice $invoice
309
-	 */
310
-	public function onhold_invoice( $invoice ) {
311
-
312
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
313
-		$recipient = $invoice->get_email();
314
-
315
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
316
-
317
-	}
318
-
319
-	/**
320
-	 * Sends a notification whenever an invoice is marked as processing payment.
321
-	 *
322
-	 * @param WPInv_Invoice $invoice
323
-	 */
324
-	public function processing_invoice( $invoice ) {
325
-
326
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
327
-		$recipient = $invoice->get_email();
328
-
329
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
330
-
331
-	}
332
-
333
-	/**
334
-	 * Sends a notification whenever an invoice is paid.
335
-	 *
336
-	 * @param WPInv_Invoice $invoice
337
-	 */
338
-	public function completed_invoice( $invoice ) {
339
-
340
-		// (Maybe) abort if it is a renewal invoice.
341
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
342
-			return;
343
-		}
344
-
345
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
346
-		$recipient = $invoice->get_email();
347
-
348
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
349
-
350
-	}
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
+        add_action( 'init', array( $this, 'init_hooks' ) );
45
+    }
46
+
47
+    /**
48
+     * Registers email hooks.
49
+     */
50
+    public function init_hooks() {
51
+
52
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
53
+        add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
54
+
55
+        foreach ( $this->invoice_actions as $hook => $email_type ) {
56
+            $this->init_email_type_hook( $hook, $email_type );
57
+        }
58
+    }
59
+
60
+    /**
61
+     * Registers an email hook for an invoice action.
62
+     *
63
+     * @param string $hook
64
+     * @param string|array $email_type
65
+     */
66
+    public function init_email_type_hook( $hook, $email_type ) {
67
+
68
+        $email_type = wpinv_parse_list( $email_type );
69
+
70
+        foreach ( $email_type as $type ) {
71
+
72
+            $email = new GetPaid_Notification_Email( $type );
73
+
74
+            // Abort if it is not active.
75
+            if ( ! $email->is_active() ) {
76
+                continue;
77
+            }
78
+
79
+            if ( method_exists( $this, $type ) ) {
80
+                add_action( $hook, array( $this, $type ), 100, 2 );
81
+                continue;
82
+            }
83
+
84
+            do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
85
+        }
86
+
87
+    }
88
+
89
+    /**
90
+     * Filters invoice merge tags.
91
+     *
92
+     * @param array $merge_tags
93
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
94
+     */
95
+    public function invoice_merge_tags( $merge_tags, $object ) {
96
+
97
+        if ( is_a( $object, 'WPInv_Invoice' ) ) {
98
+            return array_merge(
99
+                $merge_tags,
100
+                $this->get_invoice_merge_tags( $object )
101
+            );
102
+        }
103
+
104
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
105
+            return array_merge(
106
+                $merge_tags,
107
+                $this->get_invoice_merge_tags( $object->get_parent_payment() )
108
+            );
109
+        }
110
+
111
+        return $merge_tags;
112
+
113
+    }
114
+
115
+    /**
116
+     * Generates invoice merge tags.
117
+     *
118
+     * @param WPInv_Invoice $invoice
119
+     * @return array
120
+     */
121
+    public function get_invoice_merge_tags( $invoice ) {
122
+
123
+        // Abort if it does not exist.
124
+        if ( ! $invoice->get_id() ) {
125
+            return array();
126
+        }
127
+
128
+        $due_date   = $invoice->get_due_date();
129
+        $due_date   = empty( $due_date ) ? time() + MINUTE_IN_SECONDS : strtotime( $due_date ) + ( (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
130
+        $merge_tags = array(
131
+            '{name}'                 => sanitize_text_field( $invoice->get_user_full_name() ),
132
+            '{full_name}'            => sanitize_text_field( $invoice->get_user_full_name() ),
133
+            '{first_name}'           => sanitize_text_field( $invoice->get_first_name() ),
134
+            '{last_name}'            => sanitize_text_field( $invoice->get_last_name() ),
135
+            '{email}'                => sanitize_email( $invoice->get_email() ),
136
+            '{invoice_number}'       => sanitize_text_field( $invoice->get_number() ),
137
+            '{invoice_currency}'     => sanitize_text_field( $invoice->get_currency() ),
138
+            '{invoice_total}'        => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
139
+            '{invoice_link}'         => esc_url( $invoice->get_view_url() ),
140
+            '{invoice_pay_link}'     => esc_url( $invoice->get_checkout_payment_url() ),
141
+            '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ),
142
+            '{invoice_date}'         => getpaid_format_date_value( $invoice->get_date_created() ),
143
+            '{invoice_due_date}'     => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
144
+            '{invoice_quote}'        => sanitize_text_field( strtolower( $invoice->get_label() ) ),
145
+            '{invoice_label}'        => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
146
+            '{invoice_description}'  => wp_kses_post( $invoice->get_description() ),
147
+            '{subscription_name}'    => wp_kses_post( $invoice->get_subscription_name() ),
148
+            '{is_was}'               => $due_date < time() ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
149
+        );
150
+
151
+        $payment_form_data = $invoice->get_meta( 'payment_form_data', true );
152
+
153
+        if ( is_array( $payment_form_data ) ) {
154
+
155
+            foreach ( $payment_form_data as $label => $value ) {
156
+
157
+                $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
158
+                $value = is_array( $value ) ? implode( ', ', $value ) : $value;
159
+
160
+                if ( is_scalar( $value ) ) {
161
+                    $merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
162
+                }
163
+            }
164
+        }
165
+
166
+        return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
167
+    }
351 168
 
352
-	/**
353
-	 * Sends a notification whenever an invoice is refunded.
354
-	 *
355
-	 * @param WPInv_Invoice $invoice
356
-	 */
357
-	public function refunded_invoice( $invoice ) {
358
-
359
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
360
-		$recipient = $invoice->get_email();
361
-
362
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
363
-
364
-	}
169
+    /**
170
+     * Helper function to send an email.
171
+     *
172
+     * @param WPInv_Invoice $invoice
173
+     * @param GetPaid_Notification_Email $email
174
+     * @param string $type
175
+     * @param string|array $recipients
176
+     * @param array $extra_args Extra template args.
177
+     */
178
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
365 179
 
366
-	/**
367
-	 * Notifies a user about new invoices
368
-	 *
369
-	 * @param WPInv_Invoice $invoice
370
-	 * @param bool $force
371
-	 */
372
-	public function user_invoice( $invoice, $force = false ) {
180
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
373 181
 
374
-		if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
375
-			return;
376
-		}
377
-
378
-		// Only send this email for invoices created via the admin page.
379
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
380
-			return;
381
-		}
382
-
383
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
384
-		$recipient = $invoice->get_email();
385
-
386
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
387
-
388
-	}
389
-
390
-	/**
391
-	 * Checks if an invoice is a payment form invoice.
392
-	 *
393
-	 * @param int $invoice
394
-	 * @return bool
395
-	 */
396
-	public function is_payment_form_invoice( $invoice ) {
397
-		$created_via             = get_post_meta( $invoice, 'wpinv_created_via', true );
398
-		$is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via;
399
-		$is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
400
-		return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice;
401
-	}
402
-
403
-	/**
404
-	 * Notifies admin about new invoice notes
405
-	 *
406
-	 * @param WPInv_Invoice $invoice
407
-	 * @param string $note
408
-	 */
409
-	public function user_note( $invoice, $note ) {
410
-
411
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
412
-		$recipient = $invoice->get_email();
413
-
414
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
415
-
416
-	}
417
-
418
-	/**
419
-	 * (Force) Sends overdue notices.
420
-	 *
421
-	 * @param WPInv_Invoice $invoice
422
-	 */
423
-	public function force_send_overdue_notice( $invoice ) {
424
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
425
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
426
-	}
427
-
428
-	/**
429
-	 * Sends overdue notices.
430
-	 *
431
-	 * @TODO: Create an invoices query class.
432
-	 */
433
-	public function overdue() {
434
-		global $wpdb;
435
-
436
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
437
-
438
-		// Fetch reminder days.
439
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
440
-
441
-		// Abort if non is set.
442
-		if ( empty( $reminder_days ) ) {
443
-			return;
444
-		}
445
-
446
-		// Retrieve date query.
447
-		$date_query = $this->get_date_query( $reminder_days );
448
-
449
-		// Invoices table.
450
-		$table = $wpdb->prefix . 'getpaid_invoices';
451
-
452
-		// Fetch invoices.
453
-		$invoices  = $wpdb->get_col(
454
-			"SELECT posts.ID FROM $wpdb->posts as posts
182
+        $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
183
+        if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
184
+            return;
185
+        }
186
+
187
+        $mailer     = new GetPaid_Notification_Email_Sender();
188
+        $merge_tags = $email->get_merge_tags();
189
+
190
+        $result = $mailer->send(
191
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
192
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
193
+            $email->get_content( $merge_tags, $extra_args ),
194
+            $email->get_attachments()
195
+        );
196
+
197
+        // Maybe send a copy to the admin.
198
+        if ( $email->include_admin_bcc() ) {
199
+            $mailer->send(
200
+                wpinv_get_admin_email(),
201
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
202
+                $email->get_content( $merge_tags ),
203
+                $email->get_attachments()
204
+            );
205
+        }
206
+
207
+        if ( $result ) {
208
+            $invoice->add_system_note(
209
+                sprintf(
210
+                    // translators: %1 is the email type, %2 is the invoice recipient.
211
+                    __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
212
+                    sanitize_key( $type ),
213
+                    $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
214
+                )
215
+            );
216
+        } else {
217
+            $invoice->add_system_note(
218
+                sprintf(
219
+                    // translators: %1 is the email type, %2 is the invoice recipient.
220
+                    __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
221
+                    sanitize_key( $type ),
222
+                    $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
223
+                )
224
+            );
225
+        }
226
+
227
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
228
+
229
+        return $result;
230
+    }
231
+
232
+    /**
233
+     * Also send emails to any cc users.
234
+     *
235
+     * @param array $recipients
236
+     * @param GetPaid_Notification_Email $email
237
+     */
238
+    public function filter_email_recipients( $recipients, $email ) {
239
+
240
+        if ( ! $email->is_admin_email() ) {
241
+            $cc   = $email->object->get_email_cc();
242
+            $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
243
+
244
+            if ( ! empty( $cc ) ) {
245
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
246
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
247
+            }
248
+
249
+            if ( ! empty( $cc_2 ) ) {
250
+                $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
251
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
252
+            }
253
+        }
254
+
255
+        return $recipients;
256
+
257
+    }
258
+
259
+    /**
260
+     * Sends a new invoice notification.
261
+     *
262
+     * @param WPInv_Invoice $invoice
263
+     */
264
+    public function new_invoice( $invoice ) {
265
+
266
+        // Only send this email for invoices created via the admin page.
267
+        if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
268
+            return;
269
+        }
270
+
271
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
272
+        $recipient = wpinv_get_admin_email();
273
+
274
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
275
+
276
+    }
277
+
278
+    /**
279
+     * Sends a cancelled invoice notification.
280
+     *
281
+     * @param WPInv_Invoice $invoice
282
+     */
283
+    public function cancelled_invoice( $invoice ) {
284
+
285
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
286
+        $recipient = $invoice->get_email();
287
+
288
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
289
+    }
290
+
291
+    /**
292
+     * Sends a failed invoice notification.
293
+     *
294
+     * @param WPInv_Invoice $invoice
295
+     */
296
+    public function failed_invoice( $invoice ) {
297
+
298
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
299
+        $recipient = wpinv_get_admin_email();
300
+
301
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
302
+
303
+    }
304
+
305
+    /**
306
+     * Sends a notification whenever an invoice is put on hold.
307
+     *
308
+     * @param WPInv_Invoice $invoice
309
+     */
310
+    public function onhold_invoice( $invoice ) {
311
+
312
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
313
+        $recipient = $invoice->get_email();
314
+
315
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
316
+
317
+    }
318
+
319
+    /**
320
+     * Sends a notification whenever an invoice is marked as processing payment.
321
+     *
322
+     * @param WPInv_Invoice $invoice
323
+     */
324
+    public function processing_invoice( $invoice ) {
325
+
326
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
327
+        $recipient = $invoice->get_email();
328
+
329
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
330
+
331
+    }
332
+
333
+    /**
334
+     * Sends a notification whenever an invoice is paid.
335
+     *
336
+     * @param WPInv_Invoice $invoice
337
+     */
338
+    public function completed_invoice( $invoice ) {
339
+
340
+        // (Maybe) abort if it is a renewal invoice.
341
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
342
+            return;
343
+        }
344
+
345
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
346
+        $recipient = $invoice->get_email();
347
+
348
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
349
+
350
+    }
351
+
352
+    /**
353
+     * Sends a notification whenever an invoice is refunded.
354
+     *
355
+     * @param WPInv_Invoice $invoice
356
+     */
357
+    public function refunded_invoice( $invoice ) {
358
+
359
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
360
+        $recipient = $invoice->get_email();
361
+
362
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
363
+
364
+    }
365
+
366
+    /**
367
+     * Notifies a user about new invoices
368
+     *
369
+     * @param WPInv_Invoice $invoice
370
+     * @param bool $force
371
+     */
372
+    public function user_invoice( $invoice, $force = false ) {
373
+
374
+        if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
375
+            return;
376
+        }
377
+
378
+        // Only send this email for invoices created via the admin page.
379
+        if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
380
+            return;
381
+        }
382
+
383
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
384
+        $recipient = $invoice->get_email();
385
+
386
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
387
+
388
+    }
389
+
390
+    /**
391
+     * Checks if an invoice is a payment form invoice.
392
+     *
393
+     * @param int $invoice
394
+     * @return bool
395
+     */
396
+    public function is_payment_form_invoice( $invoice ) {
397
+        $created_via             = get_post_meta( $invoice, 'wpinv_created_via', true );
398
+        $is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via;
399
+        $is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
400
+        return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice;
401
+    }
402
+
403
+    /**
404
+     * Notifies admin about new invoice notes
405
+     *
406
+     * @param WPInv_Invoice $invoice
407
+     * @param string $note
408
+     */
409
+    public function user_note( $invoice, $note ) {
410
+
411
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
412
+        $recipient = $invoice->get_email();
413
+
414
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
415
+
416
+    }
417
+
418
+    /**
419
+     * (Force) Sends overdue notices.
420
+     *
421
+     * @param WPInv_Invoice $invoice
422
+     */
423
+    public function force_send_overdue_notice( $invoice ) {
424
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
425
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
426
+    }
427
+
428
+    /**
429
+     * Sends overdue notices.
430
+     *
431
+     * @TODO: Create an invoices query class.
432
+     */
433
+    public function overdue() {
434
+        global $wpdb;
435
+
436
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
437
+
438
+        // Fetch reminder days.
439
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
440
+
441
+        // Abort if non is set.
442
+        if ( empty( $reminder_days ) ) {
443
+            return;
444
+        }
445
+
446
+        // Retrieve date query.
447
+        $date_query = $this->get_date_query( $reminder_days );
448
+
449
+        // Invoices table.
450
+        $table = $wpdb->prefix . 'getpaid_invoices';
451
+
452
+        // Fetch invoices.
453
+        $invoices  = $wpdb->get_col(
454
+            "SELECT posts.ID FROM $wpdb->posts as posts
455 455
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
456 456
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"
457 457
         );
458 458
 
459
-		foreach ( $invoices as $invoice ) {
459
+        foreach ( $invoices as $invoice ) {
460 460
 
461
-			// Only send this email for invoices created via the admin page.
462
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
463
-				$invoice       = new WPInv_Invoice( $invoice );
464
-				$email->object = $invoice;
461
+            // Only send this email for invoices created via the admin page.
462
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
463
+                $invoice       = new WPInv_Invoice( $invoice );
464
+                $email->object = $invoice;
465 465
 
466
-				if ( $invoice->needs_payment() && ! $invoice->is_renewal() ) {
467
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
468
-				}
469
-			}
470
-		}
466
+                if ( $invoice->needs_payment() && ! $invoice->is_renewal() ) {
467
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
468
+                }
469
+            }
470
+        }
471 471
 
472
-	}
472
+    }
473 473
 
474
-	/**
475
-	 * Calculates the date query for an invoices query
476
-	 *
477
-	 * @param array $reminder_days
478
-	 * @return string
479
-	 */
480
-	public function get_date_query( $reminder_days ) {
474
+    /**
475
+     * Calculates the date query for an invoices query
476
+     *
477
+     * @param array $reminder_days
478
+     * @return string
479
+     */
480
+    public function get_date_query( $reminder_days ) {
481 481
 
482
-		$date_query = array(
483
-			'relation' => 'OR',
484
-		);
482
+        $date_query = array(
483
+            'relation' => 'OR',
484
+        );
485 485
 
486
-		foreach ( $reminder_days as $days ) {
487
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
486
+        foreach ( $reminder_days as $days ) {
487
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
488 488
 
489
-			$date_query[] = array(
490
-				'year'  => $date['year'],
491
-				'month' => $date['month'],
492
-				'day'   => $date['day'],
493
-			);
489
+            $date_query[] = array(
490
+                'year'  => $date['year'],
491
+                'month' => $date['month'],
492
+                'day'   => $date['day'],
493
+            );
494 494
 
495
-		}
495
+        }
496 496
 
497
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
497
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
498 498
 
499
-		return $date_query->get_sql();
499
+        return $date_query->get_sql();
500 500
 
501
-	}
501
+    }
502 502
 
503 503
 }
Please login to merge, or discard this patch.
Spacing   +128 added lines, -128 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',
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 			)
42 42
 		);
43 43
 
44
-		add_action( 'init', array( $this, 'init_hooks' ) );
44
+		add_action('init', array($this, 'init_hooks'));
45 45
 	}
46 46
 
47 47
 	/**
@@ -49,11 +49,11 @@  discard block
 block discarded – undo
49 49
 	 */
50 50
 	public function init_hooks() {
51 51
 
52
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
53
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
52
+		add_filter('getpaid_get_email_merge_tags', array($this, 'invoice_merge_tags'), 10, 2);
53
+		add_filter('getpaid_invoice_email_recipients', array($this, 'filter_email_recipients'), 10, 2);
54 54
 
55
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
56
-			$this->init_email_type_hook( $hook, $email_type );
55
+		foreach ($this->invoice_actions as $hook => $email_type) {
56
+			$this->init_email_type_hook($hook, $email_type);
57 57
 		}
58 58
 	}
59 59
 
@@ -63,25 +63,25 @@  discard block
 block discarded – undo
63 63
 	 * @param string $hook
64 64
 	 * @param string|array $email_type
65 65
 	 */
66
-	public function init_email_type_hook( $hook, $email_type ) {
66
+	public function init_email_type_hook($hook, $email_type) {
67 67
 
68
-		$email_type = wpinv_parse_list( $email_type );
68
+		$email_type = wpinv_parse_list($email_type);
69 69
 
70
-		foreach ( $email_type as $type ) {
70
+		foreach ($email_type as $type) {
71 71
 
72
-			$email = new GetPaid_Notification_Email( $type );
72
+			$email = new GetPaid_Notification_Email($type);
73 73
 
74 74
 			// Abort if it is not active.
75
-			if ( ! $email->is_active() ) {
75
+			if (!$email->is_active()) {
76 76
 				continue;
77 77
 			}
78 78
 
79
-			if ( method_exists( $this, $type ) ) {
80
-				add_action( $hook, array( $this, $type ), 100, 2 );
79
+			if (method_exists($this, $type)) {
80
+				add_action($hook, array($this, $type), 100, 2);
81 81
 				continue;
82 82
 			}
83 83
 
84
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
84
+			do_action('getpaid_invoice_init_email_type_hook', $type, $hook);
85 85
 		}
86 86
 
87 87
 	}
@@ -92,19 +92,19 @@  discard block
 block discarded – undo
92 92
 	 * @param array $merge_tags
93 93
 	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
94 94
 	 */
95
-	public function invoice_merge_tags( $merge_tags, $object ) {
95
+	public function invoice_merge_tags($merge_tags, $object) {
96 96
 
97
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
97
+		if (is_a($object, 'WPInv_Invoice')) {
98 98
 			return array_merge(
99 99
 				$merge_tags,
100
-				$this->get_invoice_merge_tags( $object )
100
+				$this->get_invoice_merge_tags($object)
101 101
 			);
102 102
 		}
103 103
 
104
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
104
+		if (is_a($object, 'WPInv_Subscription')) {
105 105
 			return array_merge(
106 106
 				$merge_tags,
107
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
107
+				$this->get_invoice_merge_tags($object->get_parent_payment())
108 108
 			);
109 109
 		}
110 110
 
@@ -118,52 +118,52 @@  discard block
 block discarded – undo
118 118
 	 * @param WPInv_Invoice $invoice
119 119
 	 * @return array
120 120
 	 */
121
-	public function get_invoice_merge_tags( $invoice ) {
121
+	public function get_invoice_merge_tags($invoice) {
122 122
 
123 123
 		// Abort if it does not exist.
124
-		if ( ! $invoice->get_id() ) {
124
+		if (!$invoice->get_id()) {
125 125
 			return array();
126 126
 		}
127 127
 
128 128
 		$due_date   = $invoice->get_due_date();
129
-		$due_date   = empty( $due_date ) ? time() + MINUTE_IN_SECONDS : strtotime( $due_date ) + ( (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
129
+		$due_date   = empty($due_date) ? time() + MINUTE_IN_SECONDS : strtotime($due_date) + ((int) get_option('gmt_offset') * HOUR_IN_SECONDS);
130 130
 		$merge_tags = array(
131
-			'{name}'                 => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{full_name}'            => sanitize_text_field( $invoice->get_user_full_name() ),
133
-			'{first_name}'           => sanitize_text_field( $invoice->get_first_name() ),
134
-			'{last_name}'            => sanitize_text_field( $invoice->get_last_name() ),
135
-			'{email}'                => sanitize_email( $invoice->get_email() ),
136
-			'{invoice_number}'       => sanitize_text_field( $invoice->get_number() ),
137
-			'{invoice_currency}'     => sanitize_text_field( $invoice->get_currency() ),
138
-			'{invoice_total}'        => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
139
-			'{invoice_link}'         => esc_url( $invoice->get_view_url() ),
140
-			'{invoice_pay_link}'     => esc_url( $invoice->get_checkout_payment_url() ),
141
-			'{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ),
142
-			'{invoice_date}'         => getpaid_format_date_value( $invoice->get_date_created() ),
143
-			'{invoice_due_date}'     => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
144
-			'{invoice_quote}'        => sanitize_text_field( strtolower( $invoice->get_label() ) ),
145
-			'{invoice_label}'        => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
146
-			'{invoice_description}'  => wp_kses_post( $invoice->get_description() ),
147
-			'{subscription_name}'    => wp_kses_post( $invoice->get_subscription_name() ),
148
-			'{is_was}'               => $due_date < time() ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
131
+			'{name}'                 => sanitize_text_field($invoice->get_user_full_name()),
132
+			'{full_name}'            => sanitize_text_field($invoice->get_user_full_name()),
133
+			'{first_name}'           => sanitize_text_field($invoice->get_first_name()),
134
+			'{last_name}'            => sanitize_text_field($invoice->get_last_name()),
135
+			'{email}'                => sanitize_email($invoice->get_email()),
136
+			'{invoice_number}'       => sanitize_text_field($invoice->get_number()),
137
+			'{invoice_currency}'     => sanitize_text_field($invoice->get_currency()),
138
+			'{invoice_total}'        => sanitize_text_field(wpinv_price($invoice->get_total(), $invoice->get_currency())),
139
+			'{invoice_link}'         => esc_url($invoice->get_view_url()),
140
+			'{invoice_pay_link}'     => esc_url($invoice->get_checkout_payment_url()),
141
+			'{invoice_receipt_link}' => esc_url($invoice->get_receipt_url()),
142
+			'{invoice_date}'         => getpaid_format_date_value($invoice->get_date_created()),
143
+			'{invoice_due_date}'     => getpaid_format_date_value($invoice->get_due_date(), __('on receipt', 'invoicing')),
144
+			'{invoice_quote}'        => sanitize_text_field(strtolower($invoice->get_label())),
145
+			'{invoice_label}'        => sanitize_text_field(ucfirst($invoice->get_label())),
146
+			'{invoice_description}'  => wp_kses_post($invoice->get_description()),
147
+			'{subscription_name}'    => wp_kses_post($invoice->get_subscription_name()),
148
+			'{is_was}'               => $due_date < time() ? __('was', 'invoicing') : __('is', 'invoicing'),
149 149
 		);
150 150
 
151
-		$payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
+		$payment_form_data = $invoice->get_meta('payment_form_data', true);
152 152
 
153
-		if ( is_array( $payment_form_data ) ) {
153
+		if (is_array($payment_form_data)) {
154 154
 
155
-			foreach ( $payment_form_data as $label => $value ) {
155
+			foreach ($payment_form_data as $label => $value) {
156 156
 
157
-				$label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
158
-				$value = is_array( $value ) ? implode( ', ', $value ) : $value;
157
+				$label = preg_replace('/[^a-z0-9]+/', '_', strtolower($label));
158
+				$value = is_array($value) ? implode(', ', $value) : $value;
159 159
 
160
-				if ( is_scalar( $value ) ) {
161
-					$merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
160
+				if (is_scalar($value)) {
161
+					$merge_tags["{{$label}}"] = wp_kses_post($value);
162 162
 				}
163 163
 			}
164 164
 		}
165 165
 
166
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
166
+		return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice);
167 167
 	}
168 168
 
169 169
 	/**
@@ -175,12 +175,12 @@  discard block
 block discarded – undo
175 175
 	 * @param string|array $recipients
176 176
 	 * @param array $extra_args Extra template args.
177 177
 	 */
178
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
178
+	public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) {
179 179
 
180
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
180
+		do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email);
181 181
 
182
-		$skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
183
-		if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
182
+		$skip = $invoice->is_free() && wpinv_get_option('skip_email_free_invoice');
183
+		if (apply_filters('getpaid_skip_invoice_email', $skip, $type, $invoice)) {
184 184
 			return;
185 185
 		}
186 186
 
@@ -188,43 +188,43 @@  discard block
 block discarded – undo
188 188
 		$merge_tags = $email->get_merge_tags();
189 189
 
190 190
 		$result = $mailer->send(
191
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
192
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
193
-			$email->get_content( $merge_tags, $extra_args ),
191
+			apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email),
192
+			$email->add_merge_tags($email->get_subject(), $merge_tags),
193
+			$email->get_content($merge_tags, $extra_args),
194 194
 			$email->get_attachments()
195 195
 		);
196 196
 
197 197
 		// Maybe send a copy to the admin.
198
-		if ( $email->include_admin_bcc() ) {
198
+		if ($email->include_admin_bcc()) {
199 199
 			$mailer->send(
200 200
 				wpinv_get_admin_email(),
201
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
202
-				$email->get_content( $merge_tags ),
201
+				$email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags),
202
+				$email->get_content($merge_tags),
203 203
 				$email->get_attachments()
204 204
 			);
205 205
 		}
206 206
 
207
-		if ( $result ) {
207
+		if ($result) {
208 208
 			$invoice->add_system_note(
209 209
 				sprintf(
210 210
 					// translators: %1 is the email type, %2 is the invoice recipient.
211
-					__( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
212
-					sanitize_key( $type ),
213
-					$email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
211
+					__('Successfully sent %1$s notification email to %2$s.', 'invoicing'),
212
+					sanitize_key($type),
213
+					$email->is_admin_email() ? __('admin', 'invoicing') : __('the customer', 'invoicing')
214 214
 				)
215 215
 			);
216 216
 		} else {
217 217
 			$invoice->add_system_note(
218 218
 				sprintf(
219 219
 					// translators: %1 is the email type, %2 is the invoice recipient.
220
-					__( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
221
-					sanitize_key( $type ),
222
-					$email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
220
+					__('Failed sending %1$s notification email to %2$s.', 'invoicing'),
221
+					sanitize_key($type),
222
+					$email->is_admin_email() ? __('admin', 'invoicing') : __('the customer', 'invoicing')
223 223
 				)
224 224
 			);
225 225
 		}
226 226
 
227
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
227
+		do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email);
228 228
 
229 229
 		return $result;
230 230
 	}
@@ -235,20 +235,20 @@  discard block
 block discarded – undo
235 235
 	 * @param array $recipients
236 236
 	 * @param GetPaid_Notification_Email $email
237 237
 	 */
238
-	public function filter_email_recipients( $recipients, $email ) {
238
+	public function filter_email_recipients($recipients, $email) {
239 239
 
240
-		if ( ! $email->is_admin_email() ) {
240
+		if (!$email->is_admin_email()) {
241 241
 			$cc   = $email->object->get_email_cc();
242
-			$cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
242
+			$cc_2 = get_user_meta($email->object->get_user_id(), '_wpinv_email_cc', true);
243 243
 
244
-			if ( ! empty( $cc ) ) {
245
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
246
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
244
+			if (!empty($cc)) {
245
+				$cc = array_map('sanitize_email', wpinv_parse_list($cc));
246
+				$recipients = array_filter(array_unique(array_merge($recipients, $cc)));
247 247
 			}
248 248
 
249
-			if ( ! empty( $cc_2 ) ) {
250
-				$cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
251
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
249
+			if (!empty($cc_2)) {
250
+				$cc_2 = array_map('sanitize_email', wpinv_parse_list($cc_2));
251
+				$recipients = array_filter(array_unique(array_merge($recipients, $cc_2)));
252 252
 			}
253 253
 		}
254 254
 
@@ -261,17 +261,17 @@  discard block
 block discarded – undo
261 261
 	 *
262 262
 	 * @param WPInv_Invoice $invoice
263 263
 	 */
264
-	public function new_invoice( $invoice ) {
264
+	public function new_invoice($invoice) {
265 265
 
266 266
 		// Only send this email for invoices created via the admin page.
267
-		if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
267
+		if (!$invoice->is_type('invoice') || $invoice->is_paid() || $this->is_payment_form_invoice($invoice->get_id())) {
268 268
 			return;
269 269
 		}
270 270
 
271
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
271
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
272 272
 		$recipient = wpinv_get_admin_email();
273 273
 
274
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
274
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
275 275
 
276 276
 	}
277 277
 
@@ -280,12 +280,12 @@  discard block
 block discarded – undo
280 280
 	 *
281 281
 	 * @param WPInv_Invoice $invoice
282 282
 	 */
283
-	public function cancelled_invoice( $invoice ) {
283
+	public function cancelled_invoice($invoice) {
284 284
 
285
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
285
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
286 286
 		$recipient = $invoice->get_email();
287 287
 
288
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
288
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
289 289
 	}
290 290
 
291 291
 	/**
@@ -293,12 +293,12 @@  discard block
 block discarded – undo
293 293
 	 *
294 294
 	 * @param WPInv_Invoice $invoice
295 295
 	 */
296
-	public function failed_invoice( $invoice ) {
296
+	public function failed_invoice($invoice) {
297 297
 
298
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
298
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
299 299
 		$recipient = wpinv_get_admin_email();
300 300
 
301
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
301
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
302 302
 
303 303
 	}
304 304
 
@@ -307,12 +307,12 @@  discard block
 block discarded – undo
307 307
 	 *
308 308
 	 * @param WPInv_Invoice $invoice
309 309
 	 */
310
-	public function onhold_invoice( $invoice ) {
310
+	public function onhold_invoice($invoice) {
311 311
 
312
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
312
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
313 313
 		$recipient = $invoice->get_email();
314 314
 
315
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
315
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
316 316
 
317 317
 	}
318 318
 
@@ -321,12 +321,12 @@  discard block
 block discarded – undo
321 321
 	 *
322 322
 	 * @param WPInv_Invoice $invoice
323 323
 	 */
324
-	public function processing_invoice( $invoice ) {
324
+	public function processing_invoice($invoice) {
325 325
 
326
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
326
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
327 327
 		$recipient = $invoice->get_email();
328 328
 
329
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
329
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
330 330
 
331 331
 	}
332 332
 
@@ -335,17 +335,17 @@  discard block
 block discarded – undo
335 335
 	 *
336 336
 	 * @param WPInv_Invoice $invoice
337 337
 	 */
338
-	public function completed_invoice( $invoice ) {
338
+	public function completed_invoice($invoice) {
339 339
 
340 340
 		// (Maybe) abort if it is a renewal invoice.
341
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
341
+		if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) {
342 342
 			return;
343 343
 		}
344 344
 
345
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
345
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
346 346
 		$recipient = $invoice->get_email();
347 347
 
348
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
348
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
349 349
 
350 350
 	}
351 351
 
@@ -354,12 +354,12 @@  discard block
 block discarded – undo
354 354
 	 *
355 355
 	 * @param WPInv_Invoice $invoice
356 356
 	 */
357
-	public function refunded_invoice( $invoice ) {
357
+	public function refunded_invoice($invoice) {
358 358
 
359
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
359
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
360 360
 		$recipient = $invoice->get_email();
361 361
 
362
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
362
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
363 363
 
364 364
 	}
365 365
 
@@ -369,21 +369,21 @@  discard block
 block discarded – undo
369 369
 	 * @param WPInv_Invoice $invoice
370 370
 	 * @param bool $force
371 371
 	 */
372
-	public function user_invoice( $invoice, $force = false ) {
372
+	public function user_invoice($invoice, $force = false) {
373 373
 
374
-		if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
374
+		if (!$force && !empty($GLOBALS['wpinv_skip_invoice_notification'])) {
375 375
 			return;
376 376
 		}
377 377
 
378 378
 		// Only send this email for invoices created via the admin page.
379
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
379
+		if (!$invoice->is_type('invoice') || (empty($force) && $invoice->is_paid()) || (empty($force) && $this->is_payment_form_invoice($invoice->get_id()))) {
380 380
 			return;
381 381
 		}
382 382
 
383
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
383
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
384 384
 		$recipient = $invoice->get_email();
385 385
 
386
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
386
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
387 387
 
388 388
 	}
389 389
 
@@ -393,11 +393,11 @@  discard block
 block discarded – undo
393 393
 	 * @param int $invoice
394 394
 	 * @return bool
395 395
 	 */
396
-	public function is_payment_form_invoice( $invoice ) {
397
-		$created_via             = get_post_meta( $invoice, 'wpinv_created_via', true );
396
+	public function is_payment_form_invoice($invoice) {
397
+		$created_via             = get_post_meta($invoice, 'wpinv_created_via', true);
398 398
 		$is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via;
399
-		$is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
400
-		return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice;
399
+		$is_payment_form_invoice = apply_filters('getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice);
400
+		return empty($_GET['getpaid-admin-action']) && $is_payment_form_invoice;
401 401
 	}
402 402
 
403 403
 	/**
@@ -406,12 +406,12 @@  discard block
 block discarded – undo
406 406
 	 * @param WPInv_Invoice $invoice
407 407
 	 * @param string $note
408 408
 	 */
409
-	public function user_note( $invoice, $note ) {
409
+	public function user_note($invoice, $note) {
410 410
 
411
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
411
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
412 412
 		$recipient = $invoice->get_email();
413 413
 
414
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
414
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note));
415 415
 
416 416
 	}
417 417
 
@@ -420,9 +420,9 @@  discard block
 block discarded – undo
420 420
 	 *
421 421
 	 * @param WPInv_Invoice $invoice
422 422
 	 */
423
-	public function force_send_overdue_notice( $invoice ) {
424
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
425
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
423
+	public function force_send_overdue_notice($invoice) {
424
+		$email = new GetPaid_Notification_Email('overdue', $invoice);
425
+		return $this->send_email($invoice, $email, 'overdue', $invoice->get_email());
426 426
 	}
427 427
 
428 428
 	/**
@@ -433,38 +433,38 @@  discard block
 block discarded – undo
433 433
 	public function overdue() {
434 434
 		global $wpdb;
435 435
 
436
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
436
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
437 437
 
438 438
 		// Fetch reminder days.
439
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
439
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
440 440
 
441 441
 		// Abort if non is set.
442
-		if ( empty( $reminder_days ) ) {
442
+		if (empty($reminder_days)) {
443 443
 			return;
444 444
 		}
445 445
 
446 446
 		// Retrieve date query.
447
-		$date_query = $this->get_date_query( $reminder_days );
447
+		$date_query = $this->get_date_query($reminder_days);
448 448
 
449 449
 		// Invoices table.
450 450
 		$table = $wpdb->prefix . 'getpaid_invoices';
451 451
 
452 452
 		// Fetch invoices.
453
-		$invoices  = $wpdb->get_col(
453
+		$invoices = $wpdb->get_col(
454 454
 			"SELECT posts.ID FROM $wpdb->posts as posts
455 455
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
456 456
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"
457 457
         );
458 458
 
459
-		foreach ( $invoices as $invoice ) {
459
+		foreach ($invoices as $invoice) {
460 460
 
461 461
 			// Only send this email for invoices created via the admin page.
462
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
463
-				$invoice       = new WPInv_Invoice( $invoice );
462
+			if (!$this->is_payment_form_invoice($invoice)) {
463
+				$invoice       = new WPInv_Invoice($invoice);
464 464
 				$email->object = $invoice;
465 465
 
466
-				if ( $invoice->needs_payment() && ! $invoice->is_renewal() ) {
467
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
466
+				if ($invoice->needs_payment() && !$invoice->is_renewal()) {
467
+					$this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email());
468 468
 				}
469 469
 			}
470 470
 		}
@@ -477,14 +477,14 @@  discard block
 block discarded – undo
477 477
 	 * @param array $reminder_days
478 478
 	 * @return string
479 479
 	 */
480
-	public function get_date_query( $reminder_days ) {
480
+	public function get_date_query($reminder_days) {
481 481
 
482 482
 		$date_query = array(
483 483
 			'relation' => 'OR',
484 484
 		);
485 485
 
486
-		foreach ( $reminder_days as $days ) {
487
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
486
+		foreach ($reminder_days as $days) {
487
+			$date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp'))));
488 488
 
489 489
 			$date_query[] = array(
490 490
 				'year'  => $date['year'],
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
 
495 495
 		}
496 496
 
497
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
497
+		$date_query = new WP_Date_Query($date_query, 'invoices.due_date');
498 498
 
499 499
 		return $date_query->get_sql();
500 500
 
Please login to merge, or discard this patch.
includes/class-getpaid-subscription-notification-emails.php 2 patches
Indentation   +284 added lines, -284 removed lines patch added patch discarded remove patch
@@ -13,324 +13,324 @@
 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_active'    => 'subscription_active',
32
-				'getpaid_subscription_trialling' => 'subscription_trial',
33
-				'getpaid_subscription_cancelled' => 'subscription_cancelled',
34
-				'getpaid_subscription_expired'   => 'subscription_expired',
35
-				'getpaid_subscription_completed' => 'subscription_complete',
36
-				'getpaid_daily_maintenance'      => 'renewal_reminder'
37
-			)
38
-		);
39
-
40
-		add_action( 'init', array( $this, 'init_hooks' ) );
41
-	}
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->subscription_actions = apply_filters(
29
+            'getpaid_notification_email_subscription_triggers',
30
+            array(
31
+                'getpaid_subscription_active'    => 'subscription_active',
32
+                'getpaid_subscription_trialling' => 'subscription_trial',
33
+                'getpaid_subscription_cancelled' => 'subscription_cancelled',
34
+                'getpaid_subscription_expired'   => 'subscription_expired',
35
+                'getpaid_subscription_completed' => 'subscription_complete',
36
+                'getpaid_daily_maintenance'      => 'renewal_reminder'
37
+            )
38
+        );
39
+
40
+        add_action( 'init', array( $this, 'init_hooks' ) );
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
-	}
224
-
225
-	/**
226
-	 * Sends a subscription active.
227
-	 *
228
-	 * @since 2.8.4
229
-	 *
230
-	 * @param WPInv_Subscription $subscription
231
-	 */
232
-	public function subscription_active( $subscription ) {
233
-		$email = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
234
-
235
-		$this->send_email( $subscription, $email, __FUNCTION__ );
236
-	}
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
+    }
237 67
 
238 68
     /**
239
-	 * Sends a new trial notification.
240
-	 *
241
-	 * @param WPInv_Subscription $subscription
242
-	 */
243
-	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 ) {
244 75
 
245
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
246
-		$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
+        }
247 82
 
248
-	}
83
+        return $merge_tags;
249 84
 
250
-	/**
251
-	 * Sends a cancelled subscription notification.
252
-	 *
253
-	 * @param WPInv_Subscription $subscription
254
-	 */
255
-	public function subscription_cancelled( $subscription ) {
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
+    }
256 115
 
257
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
258
-		$this->send_email( $subscription, $email, __FUNCTION__ );
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
+    }
259 125
 
260
-	}
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() );
261 134
 
262
-	/**
263
-	 * Sends a subscription expired notification.
264
-	 *
265
-	 * @param WPInv_Subscription $subscription
266
-	 */
267
-	public function subscription_expired( $subscription ) {
135
+        $cc = $invoice->get_email_cc();
268 136
 
269
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
270
-		$this->send_email( $subscription, $email, __FUNCTION__ );
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
+        }
271 141
 
272
-	}
142
+        return $recipients;
143
+    }
273 144
 
274
-	/**
275
-	 * Sends a completed subscription notification.
276
-	 *
277
-	 * @param WPInv_Subscription $subscription
278
-	 */
279
-	public function subscription_complete( $subscription ) {
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
+    }
280 224
 
281
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
282
-		$this->send_email( $subscription, $email, __FUNCTION__ );
225
+    /**
226
+     * Sends a subscription active.
227
+     *
228
+     * @since 2.8.4
229
+     *
230
+     * @param WPInv_Subscription $subscription
231
+     */
232
+    public function subscription_active( $subscription ) {
233
+        $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
283 234
 
284
-	}
235
+        $this->send_email( $subscription, $email, __FUNCTION__ );
236
+    }
285 237
 
286
-	/**
287
-	 * Sends a subscription renewal reminder notification.
288
-	 *
289
-	 */
290
-	public function renewal_reminder() {
238
+    /**
239
+     * Sends a new trial notification.
240
+     *
241
+     * @param WPInv_Subscription $subscription
242
+     */
243
+    public function subscription_trial( $subscription ) {
244
+
245
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
246
+        $this->send_email( $subscription, $email, __FUNCTION__ );
247
+
248
+    }
249
+
250
+    /**
251
+     * Sends a cancelled subscription notification.
252
+     *
253
+     * @param WPInv_Subscription $subscription
254
+     */
255
+    public function subscription_cancelled( $subscription ) {
256
+
257
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
258
+        $this->send_email( $subscription, $email, __FUNCTION__ );
259
+
260
+    }
261
+
262
+    /**
263
+     * Sends a subscription expired notification.
264
+     *
265
+     * @param WPInv_Subscription $subscription
266
+     */
267
+    public function subscription_expired( $subscription ) {
268
+
269
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
270
+        $this->send_email( $subscription, $email, __FUNCTION__ );
271
+
272
+    }
273
+
274
+    /**
275
+     * Sends a completed subscription notification.
276
+     *
277
+     * @param WPInv_Subscription $subscription
278
+     */
279
+    public function subscription_complete( $subscription ) {
280
+
281
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
282
+        $this->send_email( $subscription, $email, __FUNCTION__ );
283
+
284
+    }
285
+
286
+    /**
287
+     * Sends a subscription renewal reminder notification.
288
+     *
289
+     */
290
+    public function renewal_reminder() {
291 291
 
292
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
292
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
293 293
 
294
-		// Fetch reminder days.
295
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
294
+        // Fetch reminder days.
295
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
296 296
 
297
-		// Abort if non is set.
298
-		if ( empty( $reminder_days ) ) {
299
-			return;
300
-		}
297
+        // Abort if non is set.
298
+        if ( empty( $reminder_days ) ) {
299
+            return;
300
+        }
301 301
 
302
-		// Fetch matching subscriptions.
302
+        // Fetch matching subscriptions.
303 303
         $args  = array(
304 304
             'number'             => -1,
305
-			'count_total'        => false,
306
-			'status'             => 'trialling active',
305
+            'count_total'        => false,
306
+            'status'             => 'trialling active',
307 307
             'date_expires_query' => array(
308
-				'relation' => 'OR',
308
+                'relation' => 'OR',
309 309
             ),
310
-		);
310
+        );
311 311
 
312
-		foreach ( $reminder_days as $days ) {
313
-			$date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
312
+        foreach ( $reminder_days as $days ) {
313
+            $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
314 314
 
315
-			$args['date_expires_query'][] = array(
316
-				'year'  => $date['year'],
317
-				'month' => $date['month'],
318
-				'day'   => $date['day'],
319
-			);
315
+            $args['date_expires_query'][] = array(
316
+                'year'  => $date['year'],
317
+                'month' => $date['month'],
318
+                'day'   => $date['day'],
319
+            );
320 320
 
321
-		}
321
+        }
322 322
 
323
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
323
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
324 324
 
325 325
         foreach ( $subscriptions->get_results() as $subscription ) {
326 326
 
327
-			// Skip packages.
328
-			if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) {
329
-				$email->object = $subscription;
330
-            	$this->send_email( $subscription, $email, __FUNCTION__ );
331
-			}
332
-		}
327
+            // Skip packages.
328
+            if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) {
329
+                $email->object = $subscription;
330
+                $this->send_email( $subscription, $email, __FUNCTION__ );
331
+            }
332
+        }
333 333
 
334
-	}
334
+    }
335 335
 
336 336
 }
Please login to merge, or discard this patch.
Spacing   +77 added lines, -77 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.
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 			)
38 38
 		);
39 39
 
40
-		add_action( 'init', array( $this, 'init_hooks' ) );
40
+		add_action('init', array($this, 'init_hooks'));
41 41
 	}
42 42
 
43 43
     /**
@@ -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
 
@@ -229,10 +229,10 @@  discard block
 block discarded – undo
229 229
 	 *
230 230
 	 * @param WPInv_Subscription $subscription
231 231
 	 */
232
-	public function subscription_active( $subscription ) {
233
-		$email = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
232
+	public function subscription_active($subscription) {
233
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
234 234
 
235
-		$this->send_email( $subscription, $email, __FUNCTION__ );
235
+		$this->send_email($subscription, $email, __FUNCTION__);
236 236
 	}
237 237
 
238 238
     /**
@@ -240,10 +240,10 @@  discard block
 block discarded – undo
240 240
 	 *
241 241
 	 * @param WPInv_Subscription $subscription
242 242
 	 */
243
-	public function subscription_trial( $subscription ) {
243
+	public function subscription_trial($subscription) {
244 244
 
245
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
246
-		$this->send_email( $subscription, $email, __FUNCTION__ );
245
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
246
+		$this->send_email($subscription, $email, __FUNCTION__);
247 247
 
248 248
 	}
249 249
 
@@ -252,10 +252,10 @@  discard block
 block discarded – undo
252 252
 	 *
253 253
 	 * @param WPInv_Subscription $subscription
254 254
 	 */
255
-	public function subscription_cancelled( $subscription ) {
255
+	public function subscription_cancelled($subscription) {
256 256
 
257
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
258
-		$this->send_email( $subscription, $email, __FUNCTION__ );
257
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
258
+		$this->send_email($subscription, $email, __FUNCTION__);
259 259
 
260 260
 	}
261 261
 
@@ -264,10 +264,10 @@  discard block
 block discarded – undo
264 264
 	 *
265 265
 	 * @param WPInv_Subscription $subscription
266 266
 	 */
267
-	public function subscription_expired( $subscription ) {
267
+	public function subscription_expired($subscription) {
268 268
 
269
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
270
-		$this->send_email( $subscription, $email, __FUNCTION__ );
269
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
270
+		$this->send_email($subscription, $email, __FUNCTION__);
271 271
 
272 272
 	}
273 273
 
@@ -276,10 +276,10 @@  discard block
 block discarded – undo
276 276
 	 *
277 277
 	 * @param WPInv_Subscription $subscription
278 278
 	 */
279
-	public function subscription_complete( $subscription ) {
279
+	public function subscription_complete($subscription) {
280 280
 
281
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
282
-		$this->send_email( $subscription, $email, __FUNCTION__ );
281
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
282
+		$this->send_email($subscription, $email, __FUNCTION__);
283 283
 
284 284
 	}
285 285
 
@@ -289,18 +289,18 @@  discard block
 block discarded – undo
289 289
 	 */
290 290
 	public function renewal_reminder() {
291 291
 
292
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
292
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
293 293
 
294 294
 		// Fetch reminder days.
295
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
295
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
296 296
 
297 297
 		// Abort if non is set.
298
-		if ( empty( $reminder_days ) ) {
298
+		if (empty($reminder_days)) {
299 299
 			return;
300 300
 		}
301 301
 
302 302
 		// Fetch matching subscriptions.
303
-        $args  = array(
303
+        $args = array(
304 304
             'number'             => -1,
305 305
 			'count_total'        => false,
306 306
 			'status'             => 'trialling active',
@@ -309,8 +309,8 @@  discard block
 block discarded – undo
309 309
             ),
310 310
 		);
311 311
 
312
-		foreach ( $reminder_days as $days ) {
313
-			$date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
312
+		foreach ($reminder_days as $days) {
313
+			$date = date_parse(date('Y-m-d', strtotime("+$days days", current_time('timestamp'))));
314 314
 
315 315
 			$args['date_expires_query'][] = array(
316 316
 				'year'  => $date['year'],
@@ -320,14 +320,14 @@  discard block
 block discarded – undo
320 320
 
321 321
 		}
322 322
 
323
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
323
+		$subscriptions = new GetPaid_Subscriptions_Query($args);
324 324
 
325
-        foreach ( $subscriptions->get_results() as $subscription ) {
325
+        foreach ($subscriptions->get_results() as $subscription) {
326 326
 
327 327
 			// Skip packages.
328
-			if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) {
328
+			if (apply_filters('getpaid_send_subscription_renewal_reminder_email', true)) {
329 329
 				$email->object = $subscription;
330
-            	$this->send_email( $subscription, $email, __FUNCTION__ );
330
+            	$this->send_email($subscription, $email, __FUNCTION__);
331 331
 			}
332 332
 		}
333 333
 
Please login to merge, or discard this patch.
includes/admin/class-getpaid-anonymization-logs.php 3 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -34,12 +34,12 @@
 block discarded – undo
34 34
         // Prepare pagination
35 35
         $pagination = paginate_links(
36 36
             array(
37
-				'base'      => add_query_arg( 'paged', '%#%' ),
38
-				'format'    => '',
39
-				'prev_text' => __( '&laquo;', 'invoicing' ),
40
-				'next_text' => __( '&raquo;', 'invoicing' ),
41
-				'total'     => ceil( $total_logs / $per_page ),
42
-				'current'   => $page,
37
+                'base'      => add_query_arg( 'paged', '%#%' ),
38
+                'format'    => '',
39
+                'prev_text' => __( '&laquo;', 'invoicing' ),
40
+                'next_text' => __( '&raquo;', 'invoicing' ),
41
+                'total'     => ceil( $total_logs / $per_page ),
42
+                'current'   => $page,
43 43
             )
44 44
         );
45 45
 
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * @since 2.8.22
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 /**
13 13
  * GetPaid_Anonymization_Logs Class
@@ -19,89 +19,89 @@  discard block
 block discarded – undo
19 19
      */
20 20
     public function display_logs() {
21 21
         // Check user capabilities
22
-        if ( ! current_user_can( 'manage_options' ) ) {
22
+        if (!current_user_can('manage_options')) {
23 23
             return;
24 24
         }
25 25
 
26 26
         // Get current page number
27
-        $page = isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
27
+        $page = isset($_GET['paged']) ? absint($_GET['paged']) : 1;
28 28
         $per_page = 20;
29 29
 
30 30
         // Fetch logs
31
-        $logs = $this->get_logs( $page, $per_page );
31
+        $logs = $this->get_logs($page, $per_page);
32 32
         $total_logs = $this->get_total_logs();
33 33
 
34 34
         // Prepare pagination
35 35
         $pagination = paginate_links(
36 36
             array(
37
-				'base'      => add_query_arg( 'paged', '%#%' ),
37
+				'base'      => add_query_arg('paged', '%#%'),
38 38
 				'format'    => '',
39
-				'prev_text' => __( '&laquo;', 'invoicing' ),
40
-				'next_text' => __( '&raquo;', 'invoicing' ),
41
-				'total'     => ceil( $total_logs / $per_page ),
39
+				'prev_text' => __('&laquo;', 'invoicing'),
40
+				'next_text' => __('&raquo;', 'invoicing'),
41
+				'total'     => ceil($total_logs / $per_page),
42 42
 				'current'   => $page,
43 43
             )
44 44
         );
45 45
 
46 46
         ?>
47 47
         <div class="wrap getpaid-anonymization-logs">
48
-            <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
48
+            <h1><?php echo esc_html(get_admin_page_title()); ?></h1>
49 49
             <div class="tablenav top">
50 50
                 <div class="alignleft actions">
51 51
                     <form method="get">
52 52
                         <input type="hidden" name="page" value="wpinv-anonymization-logs">
53
-                        <label for="filter-by-date" class="screen-reader-text"><?php _e( 'Filter by date', 'invoicing' ); ?></label>
53
+                        <label for="filter-by-date" class="screen-reader-text"><?php _e('Filter by date', 'invoicing'); ?></label>
54 54
                         <select name="m" id="filter-by-date">
55
-                            <option value="0"><?php _e( 'All dates', 'invoicing' ); ?></option>
55
+                            <option value="0"><?php _e('All dates', 'invoicing'); ?></option>
56 56
                             <?php
57 57
                             $months = $this->get_log_months();
58
-                            foreach ( $months as $month ) {
59
-                                $selected = ( isset( $_GET['m'] ) && $_GET['m'] == $month->month ) ? ' selected="selected"' : '';
60
-                                echo '<option value="' . esc_attr( $month->month ) . '"' . $selected . '>' . esc_html( $month->month_name . ' ' . $month->year ) . '</option>';
58
+                            foreach ($months as $month) {
59
+                                $selected = (isset($_GET['m']) && $_GET['m'] == $month->month) ? ' selected="selected"' : '';
60
+                                echo '<option value="' . esc_attr($month->month) . '"' . $selected . '>' . esc_html($month->month_name . ' ' . $month->year) . '</option>';
61 61
                             }
62 62
                             ?>
63 63
                         </select>
64
-                        <?php submit_button( __( 'Filter', 'invoicing' ), '', 'filter_action', false ); ?>
64
+                        <?php submit_button(__('Filter', 'invoicing'), '', 'filter_action', false); ?>
65 65
                     </form>
66 66
                 </div>
67 67
             </div>
68 68
             <table class="wp-list-table widefat fixed striped">
69 69
                 <thead>
70 70
                     <tr>
71
-                        <th><?php _e( 'Log ID', 'invoicing' ); ?></th>
72
-                        <th><?php _e( 'User', 'invoicing' ); ?></th>
73
-                        <th><?php _e( 'Action', 'invoicing' ); ?></th>
74
-                        <th><?php _e( 'Date', 'invoicing' ); ?></th>
75
-                        <th><?php _e( 'Details', 'invoicing' ); ?></th>
71
+                        <th><?php _e('Log ID', 'invoicing'); ?></th>
72
+                        <th><?php _e('User', 'invoicing'); ?></th>
73
+                        <th><?php _e('Action', 'invoicing'); ?></th>
74
+                        <th><?php _e('Date', 'invoicing'); ?></th>
75
+                        <th><?php _e('Details', 'invoicing'); ?></th>
76 76
                     </tr>
77 77
                 </thead>
78 78
                 <tbody>
79
-                    <?php if ( empty( $logs ) ) : ?>
79
+                    <?php if (empty($logs)) : ?>
80 80
                         <tr>
81
-                            <td colspan="5"><?php _e( 'No anonymization logs found.', 'invoicing' ); ?></td>
81
+                            <td colspan="5"><?php _e('No anonymization logs found.', 'invoicing'); ?></td>
82 82
                         </tr>
83 83
                     <?php else : ?>
84 84
                         <?php
85
-                        foreach ( $logs as $log ) :
86
-                            $additional_info = json_decode( $log->additional_info, true );
85
+                        foreach ($logs as $log) :
86
+                            $additional_info = json_decode($log->additional_info, true);
87 87
                         ?>
88 88
                             <tr>
89
-                                <td><?php echo esc_html( $log->log_id ); ?></td>
89
+                                <td><?php echo esc_html($log->log_id); ?></td>
90 90
                                 <td>
91 91
                                     <?php
92
-                                    $user_edit_link = get_edit_user_link( $log->user_id );
93
-                                    if ( $user_edit_link ) {
94
-                                        echo '<a href="' . esc_url( $user_edit_link ) . '">' . esc_html( $log->user_id ) . '</a>';
92
+                                    $user_edit_link = get_edit_user_link($log->user_id);
93
+                                    if ($user_edit_link) {
94
+                                        echo '<a href="' . esc_url($user_edit_link) . '">' . esc_html($log->user_id) . '</a>';
95 95
                                     } else {
96
-                                        echo esc_html( $log->user_id );
96
+                                        echo esc_html($log->user_id);
97 97
                                     }
98 98
                                     ?>
99 99
                                 </td>
100
-                                <td><?php echo esc_html( ucfirst( $log->action ) ); ?></td>
101
-                                <td><?php echo esc_html( get_date_from_gmt( $log->timestamp, 'F j, Y g:i a' ) ); ?></td>
100
+                                <td><?php echo esc_html(ucfirst($log->action)); ?></td>
101
+                                <td><?php echo esc_html(get_date_from_gmt($log->timestamp, 'F j, Y g:i a')); ?></td>
102 102
                                 <td>
103 103
                                     <button class="button-link toggle-details" type="button" aria-expanded="false">
104
-                                        <span class="screen-reader-text"><?php _e( 'Show more details', 'invoicing' ); ?></span>
104
+                                        <span class="screen-reader-text"><?php _e('Show more details', 'invoicing'); ?></span>
105 105
                                         <span class="dashicons dashicons-arrow-down-alt2"></span>
106 106
                                     </button>
107 107
                                 </td>
@@ -112,19 +112,19 @@  discard block
 block discarded – undo
112 112
                                         <table class="widefat fixed">
113 113
                                             <tbody>
114 114
                                                 <tr>
115
-                                                    <th><?php _e( 'Data Type', 'invoicing' ); ?></th>
116
-                                                    <td><?php echo esc_html( $log->data_type ); ?></td>
115
+                                                    <th><?php _e('Data Type', 'invoicing'); ?></th>
116
+                                                    <td><?php echo esc_html($log->data_type); ?></td>
117 117
                                                 </tr>
118
-                                                <?php if ( is_array( $additional_info ) ) : ?>
118
+                                                <?php if (is_array($additional_info)) : ?>
119 119
                                                     <tr>
120
-                                                        <th><?php _e( 'Additional Information', 'invoicing' ); ?></th>
120
+                                                        <th><?php _e('Additional Information', 'invoicing'); ?></th>
121 121
                                                         <td>
122 122
                                                             <table class="widefat fixed">
123 123
                                                                 <tbody>
124
-                                                                    <?php foreach ( $additional_info as $key => $value ) : ?>
124
+                                                                    <?php foreach ($additional_info as $key => $value) : ?>
125 125
                                                                         <tr>
126
-                                                                            <th><?php echo esc_html( $key ); ?></th>
127
-                                                                            <td><?php echo esc_html( $value ); ?></td>
126
+                                                                            <th><?php echo esc_html($key); ?></th>
127
+                                                                            <td><?php echo esc_html($value); ?></td>
128 128
                                                                         </tr>
129 129
                                                                     <?php endforeach; ?>
130 130
                                                                 </tbody>
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
                     <?php endif; ?>
142 142
                 </tbody>
143 143
             </table>
144
-            <?php if ( $pagination ) : ?>
144
+            <?php if ($pagination) : ?>
145 145
                 <div class="tablenav bottom">
146 146
                     <div class="tablenav-pages">
147 147
                         <?php echo $pagination; ?>
@@ -159,10 +159,10 @@  discard block
 block discarded – undo
159 159
      * @param int $per_page Number of logs per page
160 160
      * @return array
161 161
      */
162
-    private function get_logs( $page, $per_page ) {
162
+    private function get_logs($page, $per_page) {
163 163
         global $wpdb;
164 164
         $table_name = $wpdb->prefix . 'getpaid_anonymization_logs';
165
-        $offset = ( $page - 1 ) * $per_page;
165
+        $offset = ($page - 1) * $per_page;
166 166
 
167 167
         $query = $wpdb->prepare(
168 168
             "SELECT * FROM $table_name ORDER BY timestamp DESC LIMIT %d OFFSET %d",
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
             $offset
171 171
         );
172 172
 
173
-        return $wpdb->get_results( $query );
173
+        return $wpdb->get_results($query);
174 174
     }
175 175
 
176 176
     /**
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
     private function get_total_logs() {
182 182
         global $wpdb;
183 183
         $table_name = $wpdb->prefix . 'getpaid_anonymization_logs';
184
-        return $wpdb->get_var( "SELECT COUNT(*) FROM $table_name" );
184
+        return $wpdb->get_var("SELECT COUNT(*) FROM $table_name");
185 185
     }
186 186
 
187 187
     /**
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -80,10 +80,12 @@
 block discarded – undo
80 80
                         <tr>
81 81
                             <td colspan="5"><?php _e( 'No anonymization logs found.', 'invoicing' ); ?></td>
82 82
                         </tr>
83
-                    <?php else : ?>
83
+                    <?php else {
84
+    : ?>
84 85
                         <?php
85 86
                         foreach ( $logs as $log ) :
86 87
                             $additional_info = json_decode( $log->additional_info, true );
88
+}
87 89
                         ?>
88 90
                             <tr>
89 91
                                 <td><?php echo esc_html( $log->log_id ); ?></td>
Please login to merge, or discard this patch.
includes/class-wpinv-data-retention.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -291,18 +291,18 @@
 block discarded – undo
291 291
 
292 292
         $user_meta_data = array(
293 293
             'nickname',
294
-			'description',
295
-			'rich_editing',
296
-			'syntax_highlighting',
297
-			'comment_shortcuts',
294
+            'description',
295
+            'rich_editing',
296
+            'syntax_highlighting',
297
+            'comment_shortcuts',
298 298
             'admin_color',
299
-			'use_ssl',
300
-			'show_admin_bar_front',
301
-			'locale',
302
-			'wp_capabilities',
299
+            'use_ssl',
300
+            'show_admin_bar_front',
301
+            'locale',
302
+            'wp_capabilities',
303 303
             'wp_user_level',
304
-			'dismissed_wp_pointers',
305
-			'show_welcome_panel',
304
+            'dismissed_wp_pointers',
305
+            'show_welcome_panel',
306 306
         );
307 307
 
308 308
         /**
Please login to merge, or discard this patch.
Spacing   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   2.8.22
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * WPInv_Data_Retention Class.
@@ -35,13 +35,13 @@  discard block
 block discarded – undo
35 35
      * Class constructor.
36 36
      */
37 37
     public function __construct() {
38
-        add_filter( 'wpinv_settings_misc', array( $this, 'add_data_retention_settings' ) );
38
+        add_filter('wpinv_settings_misc', array($this, 'add_data_retention_settings'));
39 39
 
40
-        add_action( 'wpmu_delete_user', array( $this, 'maybe_handle_user_deletion' ), 1 );
41
-        add_action( 'delete_user', array( $this, 'maybe_handle_user_deletion' ), 1 );
42
-        add_filter( 'wp_privacy_personal_data_erasure_request', array( $this, 'handle_erasure_request' ), 10, 2 );
40
+        add_action('wpmu_delete_user', array($this, 'maybe_handle_user_deletion'), 1);
41
+        add_action('delete_user', array($this, 'maybe_handle_user_deletion'), 1);
42
+        add_filter('wp_privacy_personal_data_erasure_request', array($this, 'handle_erasure_request'), 10, 2);
43 43
 
44
-        add_action( 'getpaid_daily_maintenance', array( $this, 'perform_data_retention_cleanup' ) );
44
+        add_action('getpaid_daily_maintenance', array($this, 'perform_data_retention_cleanup'));
45 45
     }
46 46
 
47 47
     /**
@@ -50,43 +50,43 @@  discard block
 block discarded – undo
50 50
      * @param array $misc_settings Existing misc settings.
51 51
      * @return array Updated misc settings.
52 52
      */
53
-    public function add_data_retention_settings( $misc_settings ) {
53
+    public function add_data_retention_settings($misc_settings) {
54 54
         $misc_settings['data_retention'] = array(
55 55
             'id'   => 'data_retention',
56
-            'name' => '<h3>' . __( 'Data Retention', 'invoicing' ) . '</h3>',
56
+            'name' => '<h3>' . __('Data Retention', 'invoicing') . '</h3>',
57 57
             'type' => 'header',
58 58
         );
59 59
 
60 60
         $misc_settings['data_retention_method'] = array(
61 61
             'id'      => 'data_retention_method',
62
-            'name'    => __( 'Data Handling', 'invoicing' ),
63
-            'desc'    => __( 'Choose how to handle user data when deletion is required.', 'invoicing' ),
62
+            'name'    => __('Data Handling', 'invoicing'),
63
+            'desc'    => __('Choose how to handle user data when deletion is required.', 'invoicing'),
64 64
             'type'    => 'select',
65 65
             'options' => array(
66
-                'anonymize' => __( 'Anonymize data', 'invoicing' ),
67
-                'delete'    => __( 'Delete data without anonymization', 'invoicing' ),
66
+                'anonymize' => __('Anonymize data', 'invoicing'),
67
+                'delete'    => __('Delete data without anonymization', 'invoicing'),
68 68
             ),
69 69
             'std'     => 'anonymize',
70
-            'tooltip' => __( 'Anonymization replaces personal data with non-identifiable information. Direct deletion removes all data permanently.', 'invoicing' ),
70
+            'tooltip' => __('Anonymization replaces personal data with non-identifiable information. Direct deletion removes all data permanently.', 'invoicing'),
71 71
         );
72 72
 
73 73
         $misc_settings['data_retention_period'] = array(
74 74
             'id'      => 'data_retention_period',
75
-            'name'    => __( 'Retention Period', 'invoicing' ),
76
-            'desc'    => __( 'Specify how long to retain customer data after processing.', 'invoicing' ),
75
+            'name'    => __('Retention Period', 'invoicing'),
76
+            'desc'    => __('Specify how long to retain customer data after processing.', 'invoicing'),
77 77
             'type'    => 'select',
78 78
             'options' => array(
79
-                'never' => __( 'Never delete (retain indefinitely)', 'invoicing' ),
80
-                '30'    => __( '30 days', 'invoicing' ),
81
-                '90'    => __( '90 days', 'invoicing' ),
82
-                '180'   => __( '6 months', 'invoicing' ),
83
-                '365'   => __( '1 year', 'invoicing' ),
84
-                '730'   => __( '2 years', 'invoicing' ),
85
-                '1825'  => __( '5 years', 'invoicing' ),
86
-                '3650'  => __( '10 years', 'invoicing' ),
79
+                'never' => __('Never delete (retain indefinitely)', 'invoicing'),
80
+                '30'    => __('30 days', 'invoicing'),
81
+                '90'    => __('90 days', 'invoicing'),
82
+                '180'   => __('6 months', 'invoicing'),
83
+                '365'   => __('1 year', 'invoicing'),
84
+                '730'   => __('2 years', 'invoicing'),
85
+                '1825'  => __('5 years', 'invoicing'),
86
+                '3650'  => __('10 years', 'invoicing'),
87 87
             ),
88 88
             'std'     => '3650',
89
-            'tooltip' => __( 'Choose how long to keep processed customer data before final action. This helps balance data minimization with business needs.', 'invoicing' ),
89
+            'tooltip' => __('Choose how long to keep processed customer data before final action. This helps balance data minimization with business needs.', 'invoicing'),
90 90
         );
91 91
 
92 92
         return $misc_settings;
@@ -97,15 +97,15 @@  discard block
 block discarded – undo
97 97
      *
98 98
      * @param int $user_id The ID of the user being deleted.
99 99
      */
100
-    public function maybe_handle_user_deletion( $user_id ) {
101
-        if ( ! $this->handle_user_deletion ) {
100
+    public function maybe_handle_user_deletion($user_id) {
101
+        if (!$this->handle_user_deletion) {
102 102
             return;
103 103
         }
104 104
 
105
-        if ( current_user_can( 'manage_options' ) ) {
106
-            $this->handle_admin_user_deletion( $user_id );
105
+        if (current_user_can('manage_options')) {
106
+            $this->handle_admin_user_deletion($user_id);
107 107
         } else {
108
-            $this->handle_self_account_deletion( $user_id );
108
+            $this->handle_self_account_deletion($user_id);
109 109
         }
110 110
     }
111 111
 
@@ -115,19 +115,19 @@  discard block
 block discarded – undo
115 115
      * @since 2.8.22
116 116
      * @param int $user_id The ID of the user being deleted.
117 117
      */
118
-    public function handle_admin_user_deletion( $user_id ) {
119
-        if ( $this->has_active_subscriptions( $user_id ) ) {
120
-            $this->prevent_user_deletion( $user_id, 'active_subscriptions' );
118
+    public function handle_admin_user_deletion($user_id) {
119
+        if ($this->has_active_subscriptions($user_id)) {
120
+            $this->prevent_user_deletion($user_id, 'active_subscriptions');
121 121
             return;
122 122
         }
123 123
 
124
-        if ( $this->has_paid_invoices( $user_id ) ) {
125
-            $retention_method = wpinv_get_option( 'data_retention_method', 'anonymize' );
126
-            if ( 'anonymize' === $retention_method ) {
127
-                $this->anonymize_user_data( $user_id );
128
-                $this->prevent_user_deletion( $user_id, 'paid_invoices' );
124
+        if ($this->has_paid_invoices($user_id)) {
125
+            $retention_method = wpinv_get_option('data_retention_method', 'anonymize');
126
+            if ('anonymize' === $retention_method) {
127
+                $this->anonymize_user_data($user_id);
128
+                $this->prevent_user_deletion($user_id, 'paid_invoices');
129 129
             } else {
130
-                $this->delete_user_data( $user_id );
130
+                $this->delete_user_data($user_id);
131 131
             }
132 132
         }
133 133
     }
@@ -138,19 +138,19 @@  discard block
 block discarded – undo
138 138
      * @since 2.8.22
139 139
      * @param int $user_id The ID of the user being deleted.
140 140
      */
141
-    public function handle_self_account_deletion( $user_id ) {
142
-        $this->cancel_active_subscriptions( $user_id );
141
+    public function handle_self_account_deletion($user_id) {
142
+        $this->cancel_active_subscriptions($user_id);
143 143
 
144
-        if ( $this->has_paid_invoices( $user_id ) ) {
145
-            $retention_method = wpinv_get_option( 'data_retention_method', 'anonymize' );
144
+        if ($this->has_paid_invoices($user_id)) {
145
+            $retention_method = wpinv_get_option('data_retention_method', 'anonymize');
146 146
 
147
-            if ( 'anonymize' === $retention_method ) {
148
-                $user = get_userdata( $user_id );
147
+            if ('anonymize' === $retention_method) {
148
+                $user = get_userdata($user_id);
149 149
 
150
-                $this->anonymize_user_data( $user_id );
150
+                $this->anonymize_user_data($user_id);
151 151
 
152
-                $message = apply_filters( 'uwp_get_account_deletion_message', '', $user );
153
-                do_action( 'uwp_send_account_deletion_emails', $user, $message );
152
+                $message = apply_filters('uwp_get_account_deletion_message', '', $user);
153
+                do_action('uwp_send_account_deletion_emails', $user, $message);
154 154
 
155 155
                 $this->end_user_session();
156 156
             }
@@ -164,15 +164,15 @@  discard block
 block discarded – undo
164 164
      * @param int $user_id The ID of the user being checked.
165 165
      * @return bool True if user has active subscriptions, false otherwise.
166 166
      */
167
-    private function has_active_subscriptions( $user_id ) {
167
+    private function has_active_subscriptions($user_id) {
168 168
         $subscriptions = getpaid_get_subscriptions(
169 169
             array(
170
-                'customer_in' => array( (int) $user_id ),
170
+                'customer_in' => array((int) $user_id),
171 171
                 'status'      => 'active',
172 172
             )
173 173
         );
174 174
 
175
-        return ! empty( $subscriptions );
175
+        return !empty($subscriptions);
176 176
     }
177 177
 
178 178
     /**
@@ -181,15 +181,15 @@  discard block
 block discarded – undo
181 181
      * @since 2.8.22
182 182
      * @param int $user_id The ID of the user.
183 183
      */
184
-    private function cancel_active_subscriptions( $user_id ) {
184
+    private function cancel_active_subscriptions($user_id) {
185 185
         $subscriptions = getpaid_get_subscriptions(
186 186
             array(
187
-                'customer_in' => array( (int) $user_id ),
187
+                'customer_in' => array((int) $user_id),
188 188
                 'status'      => 'active',
189 189
             )
190 190
         );
191 191
 
192
-        foreach ( $subscriptions as $subscription ) {
192
+        foreach ($subscriptions as $subscription) {
193 193
             $subscription->cancel();
194 194
         }
195 195
     }
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
      * @param int $user_id The ID of the user being checked.
202 202
      * @return bool True if user has paid invoices, false otherwise.
203 203
      */
204
-    private function has_paid_invoices( $user_id ) {
204
+    private function has_paid_invoices($user_id) {
205 205
         $invoices = wpinv_get_invoices(
206 206
             array(
207 207
                 'user'   => (int) $user_id,
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
             )
210 210
         );
211 211
 
212
-        return ! empty( $invoices->total );
212
+        return !empty($invoices->total);
213 213
     }
214 214
 
215 215
     /**
@@ -219,24 +219,24 @@  discard block
 block discarded – undo
219 219
      * @param int    $user_id The ID of the user being deleted.
220 220
      * @param string $reason  The reason for preventing deletion.
221 221
      */
222
-    private function prevent_user_deletion( $user_id, $reason ) {
223
-        $user = get_userdata( $user_id );
222
+    private function prevent_user_deletion($user_id, $reason) {
223
+        $user = get_userdata($user_id);
224 224
 
225
-        if ( 'active_subscriptions' === $reason ) {
225
+        if ('active_subscriptions' === $reason) {
226 226
             $this->error_message = sprintf(
227 227
                 /* translators: %s: user login */
228
-                esc_html__( 'User deletion for %s has been halted. All active subscriptions should be cancelled first.', 'invoicing' ),
228
+                esc_html__('User deletion for %s has been halted. All active subscriptions should be cancelled first.', 'invoicing'),
229 229
                 $user->user_login
230 230
             );
231 231
         } else {
232 232
             $this->error_message = sprintf(
233 233
                 /* translators: %s: user login */
234
-                esc_html__( 'User deletion for %s has been halted due to paid invoices. Data will be anonymized instead.', 'invoicing' ),
234
+                esc_html__('User deletion for %s has been halted due to paid invoices. Data will be anonymized instead.', 'invoicing'),
235 235
                 $user->user_login
236 236
             );
237 237
         }
238 238
 
239
-        wp_die( $this->error_message, esc_html__( 'User Deletion Halted', 'invoicing' ), array( 'response' => 403 ) );
239
+        wp_die($this->error_message, esc_html__('User Deletion Halted', 'invoicing'), array('response' => 403));
240 240
     }
241 241
 
242 242
     /**
@@ -246,17 +246,17 @@  discard block
 block discarded – undo
246 246
      * @param int $user_id The ID of the user to anonymize.
247 247
      * @return bool True on success, false on failure.
248 248
      */
249
-    private function anonymize_user_data( $user_id ) {
249
+    private function anonymize_user_data($user_id) {
250 250
         global $wpdb;
251 251
 
252
-        $user = get_userdata( $user_id );
253
-        if ( ! $user ) {
252
+        $user = get_userdata($user_id);
253
+        if (!$user) {
254 254
             return false;
255 255
         }
256 256
 
257 257
         $table_name    = $wpdb->prefix . 'getpaid_customers';
258
-        $deletion_date = gmdate( 'Y-m-d', strtotime( '+10 years' ) );
259
-        $hashed_email  = $this->hash_email( $user->user_email );
258
+        $deletion_date = gmdate('Y-m-d', strtotime('+10 years'));
259
+        $hashed_email  = $this->hash_email($user->user_email);
260 260
 
261 261
         $updated = $wpdb->update(
262 262
             $table_name,
@@ -267,10 +267,10 @@  discard block
 block discarded – undo
267 267
                 'email_cc'      => $hashed_email,
268 268
                 'phone'         => '',
269 269
             ),
270
-            array( 'user_id' => (int) $user->ID )
270
+            array('user_id' => (int) $user->ID)
271 271
         );
272 272
 
273
-        if ( false === $updated ) {
273
+        if (false === $updated) {
274 274
             return false;
275 275
         }
276 276
 
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
          * @since 2.8.22
288 288
          * @param int $user_id The ID of the user being anonymized.
289 289
          */
290
-        do_action( 'wpinv_anonymize_user_meta_data', $user->ID );
290
+        do_action('wpinv_anonymize_user_meta_data', $user->ID);
291 291
 
292 292
         $user_meta_data = array(
293 293
             'nickname',
@@ -312,13 +312,13 @@  discard block
 block discarded – undo
312 312
          * @param array $user_meta_data The meta fields to be anonymized.
313 313
          * @param int   $user_id          The ID of the user being anonymized.
314 314
          */
315
-        $user_meta_data = apply_filters( 'wpinv_user_meta_data_to_anonymize', $user_meta_data, $user->ID );
315
+        $user_meta_data = apply_filters('wpinv_user_meta_data_to_anonymize', $user_meta_data, $user->ID);
316 316
 
317
-        foreach ( $user_meta_data as $meta_key ) {
318
-            delete_user_meta( $user->ID, $meta_key );
317
+        foreach ($user_meta_data as $meta_key) {
318
+            delete_user_meta($user->ID, $meta_key);
319 319
         }
320 320
 
321
-        return $this->ensure_invoice_anonymization( $user->ID, 'anonymize' );
321
+        return $this->ensure_invoice_anonymization($user->ID, 'anonymize');
322 322
     }
323 323
 
324 324
     /**
@@ -327,15 +327,15 @@  discard block
 block discarded – undo
327 327
      * @param int $user_id The ID of the user to delete.
328 328
      * @return bool True on success, false on failure.
329 329
      */
330
-    private function delete_user_data( $user_id ) {
330
+    private function delete_user_data($user_id) {
331 331
         // Delete associated invoices.
332
-        $this->ensure_invoice_anonymization( $user_id, 'delete' );
332
+        $this->ensure_invoice_anonymization($user_id, 'delete');
333 333
 
334 334
         // Delete the user.
335
-        if ( is_multisite() ) {
336
-            wpmu_delete_user( $user_id );
335
+        if (is_multisite()) {
336
+            wpmu_delete_user($user_id);
337 337
         } else {
338
-            wp_delete_user( $user_id );
338
+            wp_delete_user($user_id);
339 339
         }
340 340
 
341 341
         /**
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
          * @since 2.8.22
345 345
          * @param int $user_id The ID of the user being deleted.
346 346
          */
347
-        do_action( 'wpinv_delete_user_data', $user_id );
347
+        do_action('wpinv_delete_user_data', $user_id);
348 348
 
349 349
         return true;
350 350
     }
@@ -357,8 +357,8 @@  discard block
 block discarded – undo
357 357
      * @param string $action  The action to perform (anonymize or delete).
358 358
      * @return bool True on success, false on failure.
359 359
      */
360
-    public function ensure_invoice_anonymization( $user_id, $action = 'anonymize' ) {
361
-        $invoices = wpinv_get_invoices( array( 'user' => $user_id ) );
360
+    public function ensure_invoice_anonymization($user_id, $action = 'anonymize') {
361
+        $invoices = wpinv_get_invoices(array('user' => $user_id));
362 362
 
363 363
         /**
364 364
          * Filters the invoice meta fields to be anonymized.
@@ -367,22 +367,22 @@  discard block
 block discarded – undo
367 367
          * @param array $inv_meta_data The meta fields to be anonymized.
368 368
          * @param int   $user_id         The ID of the user being processed.
369 369
          */
370
-        $inv_meta_data = apply_filters( 'wpinv_invoice_meta_data_to_anonymize', array(), $user_id );
370
+        $inv_meta_data = apply_filters('wpinv_invoice_meta_data_to_anonymize', array(), $user_id);
371 371
 
372
-        foreach ( $invoices->invoices as $invoice ) {
373
-            foreach ( $inv_meta_data as $meta_key ) {
374
-                delete_post_meta( $invoice->get_id(), $meta_key );
372
+        foreach ($invoices->invoices as $invoice) {
373
+            foreach ($inv_meta_data as $meta_key) {
374
+                delete_post_meta($invoice->get_id(), $meta_key);
375 375
             }
376 376
 
377
-            if ( 'anonymize' === $action ) {
378
-                $hashed_inv_email    = $this->hash_email( $invoice->get_email() );
379
-                $hashed_inv_email_cc = $this->hash_email( $invoice->get_email_cc() );
377
+            if ('anonymize' === $action) {
378
+                $hashed_inv_email    = $this->hash_email($invoice->get_email());
379
+                $hashed_inv_email_cc = $this->hash_email($invoice->get_email_cc());
380 380
 
381
-                $invoice->set_email( $hashed_inv_email );
382
-                $invoice->set_email_cc( $hashed_inv_email_cc );
383
-                $invoice->set_phone( '' );
384
-                $invoice->set_ip( $this->anonymize_data( $invoice->get_ip() ) );
385
-                $invoice->set_is_anonymized( 1 );
381
+                $invoice->set_email($hashed_inv_email);
382
+                $invoice->set_email_cc($hashed_inv_email_cc);
383
+                $invoice->set_phone('');
384
+                $invoice->set_ip($this->anonymize_data($invoice->get_ip()));
385
+                $invoice->set_is_anonymized(1);
386 386
 
387 387
                 /**
388 388
                  * Fires when anonymizing additional invoice data.
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
                  * @param WPInv_Invoice $invoice The invoice being anonymized.
392 392
                  * @param string        $action  The action being performed (anonymize or delete).
393 393
                  */
394
-                do_action( 'wpinv_anonymize_invoice_data', $invoice, $action );
394
+                do_action('wpinv_anonymize_invoice_data', $invoice, $action);
395 395
 
396 396
                 $invoice->save();
397 397
             } else {
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
             }
400 400
         }
401 401
 
402
-        return $this->log_deletion_action( $user_id, $invoices->invoices, $action );
402
+        return $this->log_deletion_action($user_id, $invoices->invoices, $action);
403 403
     }
404 404
 
405 405
     /**
@@ -411,11 +411,11 @@  discard block
 block discarded – undo
411 411
      * @param string $action   The action being performed (anonymize or delete).
412 412
      * @return bool True on success, false on failure.
413 413
      */
414
-    private function log_deletion_action( $user_id, $invoices, $action ) {
414
+    private function log_deletion_action($user_id, $invoices, $action) {
415 415
         global $wpdb;
416 416
 
417 417
         $table_name = $wpdb->prefix . 'getpaid_anonymization_logs';
418
-        $user_data  = get_userdata( $user_id );
418
+        $user_data  = get_userdata($user_id);
419 419
 
420 420
         $additional_info = array(
421 421
             'Username'      => $user_data ? $user_data->user_login : 'N/A',
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
             'First Name'    => $user_data ? $user_data->first_name : 'N/A',
425 425
             'Last Name'     => $user_data ? $user_data->last_name : 'N/A',
426 426
             'Registered'    => $user_data ? $user_data->user_registered : 'N/A',
427
-            'invoice_count' => count( $invoices ),
427
+            'invoice_count' => count($invoices),
428 428
         );
429 429
 
430 430
 
@@ -437,43 +437,43 @@  discard block
 block discarded – undo
437 437
          * @param array  $invoices        The invoices being processed.
438 438
          * @param string $action          The action being performed (anonymize or delete).
439 439
          */
440
-        $additional_info = apply_filters( 'wpinv_anonymization_log_additional_info', $additional_info, $user_id, $invoices, $action );
440
+        $additional_info = apply_filters('wpinv_anonymization_log_additional_info', $additional_info, $user_id, $invoices, $action);
441 441
 
442 442
         $data = array(
443 443
             'user_id'         => $user_id,
444
-            'action'          => sanitize_text_field( $action ),
444
+            'action'          => sanitize_text_field($action),
445 445
             'data_type'       => 'User Invoices',
446
-            'timestamp'       => current_time( 'mysql' ),
447
-            'additional_info' => wp_json_encode( $additional_info ),
446
+            'timestamp'       => current_time('mysql'),
447
+            'additional_info' => wp_json_encode($additional_info),
448 448
         );
449 449
 
450 450
         $format = array(
451
-            '%d',  // user_id
452
-            '%s',  // action
453
-            '%s',  // data_type
454
-            '%s',  // timestamp
455
-            '%s',  // additional_info
451
+            '%d', // user_id
452
+            '%s', // action
453
+            '%s', // data_type
454
+            '%s', // timestamp
455
+            '%s', // additional_info
456 456
         );
457 457
 
458
-        if ( ! empty( $user_id ) && ! empty( $action ) ) {
458
+        if (!empty($user_id) && !empty($action)) {
459 459
             $result = $wpdb->update(
460 460
                 $table_name,
461 461
                 $data,
462 462
                 array(
463 463
                     'user_id' => (int) $user_id,
464
-                    'action'  => sanitize_text_field( $action ),
464
+                    'action'  => sanitize_text_field($action),
465 465
                 ),
466 466
                 $format,
467
-                array( '%d', '%s' )
467
+                array('%d', '%s')
468 468
             );
469 469
 
470
-            if ( false === $result ) {
470
+            if (false === $result) {
471 471
                 // If update fails, try to insert.
472
-                $result = $wpdb->insert( $table_name, $data, $format );
472
+                $result = $wpdb->insert($table_name, $data, $format);
473 473
             }
474 474
 
475
-            if ( false === $result ) {
476
-                wpinv_error_log( sprintf( 'Failed to log anonymization action for user ID: %d. Error: %s', $user_id, $wpdb->last_error ) );
475
+            if (false === $result) {
476
+                wpinv_error_log(sprintf('Failed to log anonymization action for user ID: %d. Error: %s', $user_id, $wpdb->last_error));
477 477
                 return false;
478 478
             }
479 479
         }
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
          * @param string $action   The action being performed (anonymize or delete).
488 488
          * @param array  $data     The data that was inserted into the log.
489 489
          */
490
-        do_action( 'wpinv_after_log_deletion_action', $user_id, $invoices, $action, $data );
490
+        do_action('wpinv_after_log_deletion_action', $user_id, $invoices, $action, $data);
491 491
 
492 492
         return true;
493 493
     }
@@ -500,20 +500,20 @@  discard block
 block discarded – undo
500 500
      * @param int   $user_id  The ID of the user being erased.
501 501
      * @return array The modified response.
502 502
      */
503
-    public function handle_erasure_request( $response, $user_id ) {
504
-        if ( $this->has_active_subscriptions( $user_id ) ) {
505
-            $response['messages'][]    = esc_html__( 'User has active subscriptions. Data cannot be erased at this time.', 'invoicing' );
503
+    public function handle_erasure_request($response, $user_id) {
504
+        if ($this->has_active_subscriptions($user_id)) {
505
+            $response['messages'][]    = esc_html__('User has active subscriptions. Data cannot be erased at this time.', 'invoicing');
506 506
             $response['items_removed'] = false;
507
-        } elseif ( $this->has_paid_invoices( $user_id ) ) {
508
-            $retention_method = wpinv_get_option( 'data_retention_method', 'anonymize' );
509
-            if ( 'anonymize' === $retention_method ) {
510
-                $this->anonymize_user_data( $user_id );
511
-                $response['messages'][]     = esc_html__( 'User data has been anonymized due to existing paid invoices.', 'invoicing' );
507
+        } elseif ($this->has_paid_invoices($user_id)) {
508
+            $retention_method = wpinv_get_option('data_retention_method', 'anonymize');
509
+            if ('anonymize' === $retention_method) {
510
+                $this->anonymize_user_data($user_id);
511
+                $response['messages'][]     = esc_html__('User data has been anonymized due to existing paid invoices.', 'invoicing');
512 512
                 $response['items_removed']  = false;
513 513
                 $response['items_retained'] = true;
514 514
             } else {
515
-                $this->delete_user_data( $user_id );
516
-                $response['messages'][]     = esc_html__( 'User data has been deleted.', 'invoicing' );
515
+                $this->delete_user_data($user_id);
516
+                $response['messages'][]     = esc_html__('User data has been deleted.', 'invoicing');
517 517
                 $response['items_removed']  = true;
518 518
                 $response['items_retained'] = false;
519 519
             }
@@ -529,18 +529,18 @@  discard block
 block discarded – undo
529 529
      * @param string $email The email to hash.
530 530
      * @return string The hashed email.
531 531
      */
532
-    private function hash_email( $email ) {
532
+    private function hash_email($email) {
533 533
         $site_url = get_site_url();
534
-        $domain   = wp_parse_url( $site_url, PHP_URL_HOST );
534
+        $domain   = wp_parse_url($site_url, PHP_URL_HOST);
535 535
 
536
-        if ( empty( $domain ) ) {
536
+        if (empty($domain)) {
537 537
             return $email;
538 538
         }
539 539
 
540
-        $clean_email     = sanitize_email( strtolower( trim( $email ) ) );
541
-        $hash            = wp_hash( $clean_email );
542
-        $hash            = substr( $hash, 0, 20 );
543
-        $anonymized_email = sprintf( '%s@%s', $hash, $domain );
540
+        $clean_email     = sanitize_email(strtolower(trim($email)));
541
+        $hash            = wp_hash($clean_email);
542
+        $hash            = substr($hash, 0, 20);
543
+        $anonymized_email = sprintf('%s@%s', $hash, $domain);
544 544
 
545 545
         /**
546 546
          * Filters the anonymized email before returning.
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
          * @param string $anonymized_email The anonymized email address.
550 550
          * @param string $email            The original email address.
551 551
          */
552
-        return apply_filters( 'wpinv_anonymized_email', $anonymized_email, $email );
552
+        return apply_filters('wpinv_anonymized_email', $anonymized_email, $email);
553 553
     }
554 554
 
555 555
     /**
@@ -559,12 +559,12 @@  discard block
 block discarded – undo
559 559
      * @param string $data The data to anonymize.
560 560
      * @return string The anonymized data.
561 561
      */
562
-    private function anonymize_data( $data ) {
563
-        if ( empty( $data ) ) {
562
+    private function anonymize_data($data) {
563
+        if (empty($data)) {
564 564
             return '';
565 565
         }
566 566
 
567
-        return wp_privacy_anonymize_data( 'text', $data );
567
+        return wp_privacy_anonymize_data('text', $data);
568 568
     }
569 569
 
570 570
     /**
@@ -578,17 +578,17 @@  discard block
 block discarded – undo
578 578
     public function perform_data_retention_cleanup() {
579 579
         global $wpdb;
580 580
 
581
-        $retention_period = wpinv_get_option( 'data_retention_period', '3650' );
581
+        $retention_period = wpinv_get_option('data_retention_period', '3650');
582 582
 
583 583
         // If retention period is set to 'never', exit the function.
584
-        if ( 'never' === $retention_period ) {
584
+        if ('never' === $retention_period) {
585 585
             return;
586 586
         }
587 587
 
588 588
         $customers_table = $wpdb->prefix . 'getpaid_customers';
589 589
 
590 590
         // Calculate the cutoff date for data retention.
591
-        $cutoff_date = gmdate( 'Y-m-d', strtotime( "-$retention_period days" ) );
591
+        $cutoff_date = gmdate('Y-m-d', strtotime("-$retention_period days"));
592 592
 
593 593
         $expired_records = $wpdb->get_results(
594 594
             $wpdb->prepare(
@@ -603,18 +603,18 @@  discard block
 block discarded – undo
603 603
          * @since 2.8.22
604 604
          * @param array $expired_records Array of customer records to be processed.
605 605
          */
606
-        do_action( 'getpaid_data_retention_before_cleanup', $expired_records );
606
+        do_action('getpaid_data_retention_before_cleanup', $expired_records);
607 607
 
608
-        if ( ! empty( $expired_records ) ) {
608
+        if (!empty($expired_records)) {
609 609
             // Disable our custom user deletion handling.
610 610
             $this->handle_user_deletion = false;
611 611
 
612
-            foreach ( $expired_records as $record ) {
612
+            foreach ($expired_records as $record) {
613 613
                 // Delete associated invoices.
614
-                $this->ensure_invoice_anonymization( (int) $record->user_id, 'delete' );
614
+                $this->ensure_invoice_anonymization((int) $record->user_id, 'delete');
615 615
 
616 616
                 // Delete the user.
617
-                wp_delete_user( (int) $record->user_id );
617
+                wp_delete_user((int) $record->user_id);
618 618
 
619 619
                 /**
620 620
                  * Fires after processing each expired record during cleanup.
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
                  * @since 2.8.22
623 623
                  * @param object $record The customer record being processed.
624 624
                  */
625
-                do_action( 'getpaid_data_retention_process_record', $record );
625
+                do_action('getpaid_data_retention_process_record', $record);
626 626
             }
627 627
 
628 628
             // Re-enable our custom user deletion handling.
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
              * @since 2.8.22
635 635
              * @param array $expired_records Array of customer records that were processed.
636 636
              */
637
-            do_action( 'getpaid_data_retention_after_cleanup', $expired_records );
637
+            do_action('getpaid_data_retention_after_cleanup', $expired_records);
638 638
         }
639 639
 
640 640
         /**
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
          * @param int $retention_period The current retention period in years.
645 645
          * @param string $cutoff_date The cutoff date used for identifying expired records.
646 646
          */
647
-        do_action( 'getpaid_data_retention_cleanup_complete', $retention_period, $cutoff_date );
647
+        do_action('getpaid_data_retention_cleanup_complete', $retention_period, $cutoff_date);
648 648
     }
649 649
 
650 650
     /**
@@ -657,7 +657,7 @@  discard block
 block discarded – undo
657 657
 
658 658
         // Redirect after deletion.
659 659
         $redirect_page = home_url();
660
-        wp_safe_redirect( $redirect_page );
660
+        wp_safe_redirect($redirect_page);
661 661
         exit();
662 662
     }
663 663
 }
664 664
\ No newline at end of file
Please login to merge, or discard this patch.
vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php 3 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -7,40 +7,40 @@
 block discarded – undo
7 7
  * Bail if we are not in WP.
8 8
  */
9 9
 if ( ! defined( 'ABSPATH' ) ) {
10
-	exit;
10
+    exit;
11 11
 }
12 12
 
13 13
 /**
14 14
  * Set the version only if its the current newest while loading.
15 15
  */
16 16
 add_action('after_setup_theme', function () {
17
-	global $ayecode_ui_version,$ayecode_ui_file_key;
18
-	$this_version = "0.2.31";
19
-	if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){
20
-		$ayecode_ui_version = $this_version ;
21
-		$ayecode_ui_file_key = wp_hash( __FILE__ );
22
-	}
17
+    global $ayecode_ui_version,$ayecode_ui_file_key;
18
+    $this_version = "0.2.31";
19
+    if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){
20
+        $ayecode_ui_version = $this_version ;
21
+        $ayecode_ui_file_key = wp_hash( __FILE__ );
22
+    }
23 23
 },0);
24 24
 
25 25
 /**
26 26
  * Load this version of WP Bootstrap Settings only if the file hash is the current one.
27 27
  */
28 28
 add_action('after_setup_theme', function () {
29
-	global $ayecode_ui_file_key;
30
-	if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){
31
-		include_once( dirname( __FILE__ ) . '/includes/class-aui.php' );
32
-		include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' );
33
-	}
29
+    global $ayecode_ui_file_key;
30
+    if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){
31
+        include_once( dirname( __FILE__ ) . '/includes/class-aui.php' );
32
+        include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' );
33
+    }
34 34
 },1);
35 35
 
36 36
 /**
37 37
  * Add the function that calls the class.
38 38
  */
39 39
 if(!function_exists('aui')){
40
-	function aui(){
41
-		if(!class_exists("AUI",false)){
42
-			return false;
43
-		}
44
-		return AUI::instance();
45
-	}
40
+    function aui(){
41
+        if(!class_exists("AUI",false)){
42
+            return false;
43
+        }
44
+        return AUI::instance();
45
+    }
46 46
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -6,39 +6,39 @@
 block discarded – undo
6 6
 /**
7 7
  * Bail if we are not in WP.
8 8
  */
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if (!defined('ABSPATH')) {
10 10
 	exit;
11 11
 }
12 12
 
13 13
 /**
14 14
  * Set the version only if its the current newest while loading.
15 15
  */
16
-add_action('after_setup_theme', function () {
17
-	global $ayecode_ui_version,$ayecode_ui_file_key;
16
+add_action('after_setup_theme', function() {
17
+	global $ayecode_ui_version, $ayecode_ui_file_key;
18 18
 	$this_version = "0.2.31";
19
-	if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){
20
-		$ayecode_ui_version = $this_version ;
21
-		$ayecode_ui_file_key = wp_hash( __FILE__ );
19
+	if (empty($ayecode_ui_version) || version_compare($this_version, $ayecode_ui_version, '>')) {
20
+		$ayecode_ui_version = $this_version;
21
+		$ayecode_ui_file_key = wp_hash(__FILE__);
22 22
 	}
23 23
 },0);
24 24
 
25 25
 /**
26 26
  * Load this version of WP Bootstrap Settings only if the file hash is the current one.
27 27
  */
28
-add_action('after_setup_theme', function () {
28
+add_action('after_setup_theme', function() {
29 29
 	global $ayecode_ui_file_key;
30
-	if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){
31
-		include_once( dirname( __FILE__ ) . '/includes/class-aui.php' );
32
-		include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' );
30
+	if ($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash(__FILE__)) {
31
+		include_once(dirname(__FILE__) . '/includes/class-aui.php');
32
+		include_once(dirname(__FILE__) . '/includes/ayecode-ui-settings.php');
33 33
 	}
34 34
 },1);
35 35
 
36 36
 /**
37 37
  * Add the function that calls the class.
38 38
  */
39
-if(!function_exists('aui')){
40
-	function aui(){
41
-		if(!class_exists("AUI",false)){
39
+if (!function_exists('aui')) {
40
+	function aui() {
41
+		if (!class_exists("AUI", false)) {
42 42
 			return false;
43 43
 		}
44 44
 		return AUI::instance();
Please login to merge, or discard this patch.
Switch Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php
1
+    <?php
2 2
 /**
3 3
  * This is a file takes advantage of anonymous functions to to load the latest version of the AyeCode UI Settings.
4 4
  */
@@ -6,41 +6,41 @@  discard block
 block discarded – undo
6 6
 /**
7 7
  * Bail if we are not in WP.
8 8
  */
9
-if ( ! defined( 'ABSPATH' ) ) {
10
-	exit;
9
+    if ( ! defined( 'ABSPATH' ) ) {
10
+	    exit;
11 11
 }
12 12
 
13 13
 /**
14 14
  * Set the version only if its the current newest while loading.
15 15
  */
16
-add_action('after_setup_theme', function () {
17
-	global $ayecode_ui_version,$ayecode_ui_file_key;
18
-	$this_version = "0.2.31";
19
-	if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){
20
-		$ayecode_ui_version = $this_version ;
21
-		$ayecode_ui_file_key = wp_hash( __FILE__ );
22
-	}
16
+    add_action('after_setup_theme', function () {
17
+	    global $ayecode_ui_version,$ayecode_ui_file_key;
18
+	    $this_version = "0.2.31";
19
+	    if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){
20
+		    $ayecode_ui_version = $this_version ;
21
+		    $ayecode_ui_file_key = wp_hash( __FILE__ );
22
+	    }
23 23
 },0);
24 24
 
25 25
 /**
26 26
  * Load this version of WP Bootstrap Settings only if the file hash is the current one.
27 27
  */
28
-add_action('after_setup_theme', function () {
29
-	global $ayecode_ui_file_key;
30
-	if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){
31
-		include_once( dirname( __FILE__ ) . '/includes/class-aui.php' );
32
-		include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' );
33
-	}
28
+    add_action('after_setup_theme', function () {
29
+	    global $ayecode_ui_file_key;
30
+	    if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){
31
+		    include_once( dirname( __FILE__ ) . '/includes/class-aui.php' );
32
+		    include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' );
33
+	    }
34 34
 },1);
35 35
 
36 36
 /**
37 37
  * Add the function that calls the class.
38 38
  */
39
-if(!function_exists('aui')){
40
-	function aui(){
41
-		if(!class_exists("AUI",false)){
42
-			return false;
43
-		}
44
-		return AUI::instance();
45
-	}
39
+    if(!function_exists('aui')){
40
+	    function aui(){
41
+		    if(!class_exists("AUI",false)){
42
+			    return false;
43
+		    }
44
+		    return AUI::instance();
45
+	    }
46 46
 }
Please login to merge, or discard this patch.
includes/reports/class-getpaid-graph-downloader.php 2 patches
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -12,218 +12,218 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Graph_Downloader {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Reports_Report
17
-	 */
18
-	public $handler;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 *
23
-	 */
24
-	public function __construct() {
25
-		$this->handler = new GetPaid_Reports_Report();
26
-	}
27
-
28
-	/**
29
-	 * Prepares the datastore handler.
30
-	 *
31
-	 * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts
32
-	 */
33
-	public function prepare_handler( $graph ) {
34
-
35
-		if ( empty( $this->handler->views[ $graph ] ) ) {
36
-			wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 );
37
-		}
38
-
39
-		return new $this->handler->views[ $graph ]['class']();
40
-
41
-	}
42
-
43
-	/**
44
-	 * Prepares the output stream.
45
-	 *
46
-	 * @return resource
47
-	 */
48
-	public function prepare_output() {
49
-
50
-		$output  = fopen( 'php://output', 'w' );
51
-
52
-		if ( false === $output ) {
53
-			wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 );
54
-		}
55
-
56
-		return $output;
57
-	}
58
-
59
-	/**
60
-	 * Prepares the file type.
61
-	 *
62
-	 * @return string
63
-	 */
64
-	public function prepare_file_type( $graph ) {
65
-
66
-		$file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] );
67
-		$file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) );
68
-
69
-		header( "Content-Type:application/$file_type" );
70
-		header( "Content-Disposition:attachment;filename=$file_name.$file_type" );
71
-
72
-		return $file_type;
73
-	}
74
-
75
-	/**
76
-	 * Handles the actual download.
77
-	 *
78
-	 */
79
-	public function download( $graph ) {
80
-		global $wpdb;
81
-
82
-		$handler   = $this->prepare_handler( $graph );
83
-		$stream    = $this->prepare_output();
84
-		$stats     = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) );
85
-		$headers   = array( $handler->field, 'total', 'total_raw' );
86
-		$file_type = $this->prepare_file_type( $graph );
87
-
88
-		if ( 'csv' == $file_type ) {
89
-			$this->download_csv( $stats, $stream, $headers );
90
-		} elseif ( 'xml' == $file_type ) {
91
-			$this->download_xml( $stats, $stream, $headers );
92
-		} else {
93
-			$this->download_json( $stats, $stream, $headers );
94
-		}
95
-
96
-		fclose( $stream );
97
-		exit;
98
-	}
99
-
100
-	/**
101
-	 * Downloads graph as csv
102
-	 *
103
-	 * @param array $stats The stats being downloaded.
104
-	 * @param resource $stream The stream to output to.
105
-	 * @param array $headers The fields to stream.
106
-	 * @since       1.0.19
107
-	 */
108
-	public function download_csv( $stats, $stream, $headers ) {
109
-
110
-		// Output the csv column headers.
111
-		fputcsv( $stream, $headers );
112
-
113
-		// Loop through
114
-		foreach ( $stats as $stat ) {
115
-			$row  = array_values( $this->prepare_row( $stat, $headers ) );
116
-			$row  = array_map( 'maybe_serialize', $row );
117
-			fputcsv( $stream, $row );
118
-		}
119
-
120
-	}
121
-
122
-	/**
123
-	 * Downloads graph as json
124
-	 *
125
-	 * @param array $stats The stats being downloaded.
126
-	 * @param resource $stream The stream to output to.
127
-	 * @param array $headers The fields to stream.
128
-	 * @since       1.0.19
129
-	 */
130
-	public function download_json( $stats, $stream, $headers ) {
131
-
132
-		$prepared = array();
133
-
134
-		// Loop through
135
-		foreach ( $stats as $stat ) {
136
-			$prepared[] = $this->prepare_row( $stat, $headers );
137
-		}
138
-
139
-		fwrite( $stream, wp_json_encode( $prepared ) );
140
-
141
-	}
142
-
143
-	/**
144
-	 * Downloads graph as xml
145
-	 *
146
-	 * @param array $stats The stats being downloaded.
147
-	 * @param resource $stream The stream to output to.
148
-	 * @param array $headers The fields to stream.
149
-	 * @since       1.0.19
150
-	 */
151
-	public function download_xml( $stats, $stream, $headers ) {
152
-
153
-		$prepared = array();
154
-
155
-		// Loop through
156
-		foreach ( $stats as $stat ) {
157
-			$prepared[] = $this->prepare_row( $stat, $headers );
158
-		}
159
-
160
-		$xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' );
161
-		$this->convert_array_xml( $prepared, $xml );
162
-
163
-		fwrite( $stream, $xml->asXML() );
164
-
165
-	}
166
-
167
-	/**
168
-	 * Converts stats array to xml
169
-	 *
170
-	 * @access      public
171
-	 * @since      1.0.19
172
-	 */
173
-	public function convert_array_xml( $data, $xml ) {
174
-
175
-		// Loop through
176
-		foreach ( $data as $key => $value ) {
177
-
178
-			$key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key );
179
-
180
-			if ( is_array( $value ) ) {
181
-
182
-				if ( is_numeric( $key ) ) {
183
-					$key = 'item' . $key; //dealing with <0/>..<n/> issues
184
-				}
185
-
186
-				$subnode = $xml->addChild( $key );
187
-				$this->convert_array_xml( $value, $subnode );
188
-
189
-			} else {
190
-				$xml->addChild( $key, $value ?  htmlspecialchars( $value ) : $value );
191
-			}
15
+    /**
16
+     * @var GetPaid_Reports_Report
17
+     */
18
+    public $handler;
19
+
20
+    /**
21
+     * Class constructor.
22
+     *
23
+     */
24
+    public function __construct() {
25
+        $this->handler = new GetPaid_Reports_Report();
26
+    }
27
+
28
+    /**
29
+     * Prepares the datastore handler.
30
+     *
31
+     * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts
32
+     */
33
+    public function prepare_handler( $graph ) {
34
+
35
+        if ( empty( $this->handler->views[ $graph ] ) ) {
36
+            wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 );
37
+        }
38
+
39
+        return new $this->handler->views[ $graph ]['class']();
40
+
41
+    }
42
+
43
+    /**
44
+     * Prepares the output stream.
45
+     *
46
+     * @return resource
47
+     */
48
+    public function prepare_output() {
49
+
50
+        $output  = fopen( 'php://output', 'w' );
51
+
52
+        if ( false === $output ) {
53
+            wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 );
54
+        }
55
+
56
+        return $output;
57
+    }
58
+
59
+    /**
60
+     * Prepares the file type.
61
+     *
62
+     * @return string
63
+     */
64
+    public function prepare_file_type( $graph ) {
65
+
66
+        $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] );
67
+        $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) );
68
+
69
+        header( "Content-Type:application/$file_type" );
70
+        header( "Content-Disposition:attachment;filename=$file_name.$file_type" );
71
+
72
+        return $file_type;
73
+    }
74
+
75
+    /**
76
+     * Handles the actual download.
77
+     *
78
+     */
79
+    public function download( $graph ) {
80
+        global $wpdb;
81
+
82
+        $handler   = $this->prepare_handler( $graph );
83
+        $stream    = $this->prepare_output();
84
+        $stats     = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) );
85
+        $headers   = array( $handler->field, 'total', 'total_raw' );
86
+        $file_type = $this->prepare_file_type( $graph );
87
+
88
+        if ( 'csv' == $file_type ) {
89
+            $this->download_csv( $stats, $stream, $headers );
90
+        } elseif ( 'xml' == $file_type ) {
91
+            $this->download_xml( $stats, $stream, $headers );
92
+        } else {
93
+            $this->download_json( $stats, $stream, $headers );
94
+        }
95
+
96
+        fclose( $stream );
97
+        exit;
98
+    }
99
+
100
+    /**
101
+     * Downloads graph as csv
102
+     *
103
+     * @param array $stats The stats being downloaded.
104
+     * @param resource $stream The stream to output to.
105
+     * @param array $headers The fields to stream.
106
+     * @since       1.0.19
107
+     */
108
+    public function download_csv( $stats, $stream, $headers ) {
109
+
110
+        // Output the csv column headers.
111
+        fputcsv( $stream, $headers );
112
+
113
+        // Loop through
114
+        foreach ( $stats as $stat ) {
115
+            $row  = array_values( $this->prepare_row( $stat, $headers ) );
116
+            $row  = array_map( 'maybe_serialize', $row );
117
+            fputcsv( $stream, $row );
118
+        }
119
+
120
+    }
121
+
122
+    /**
123
+     * Downloads graph as json
124
+     *
125
+     * @param array $stats The stats being downloaded.
126
+     * @param resource $stream The stream to output to.
127
+     * @param array $headers The fields to stream.
128
+     * @since       1.0.19
129
+     */
130
+    public function download_json( $stats, $stream, $headers ) {
131
+
132
+        $prepared = array();
133
+
134
+        // Loop through
135
+        foreach ( $stats as $stat ) {
136
+            $prepared[] = $this->prepare_row( $stat, $headers );
137
+        }
138
+
139
+        fwrite( $stream, wp_json_encode( $prepared ) );
140
+
141
+    }
142
+
143
+    /**
144
+     * Downloads graph as xml
145
+     *
146
+     * @param array $stats The stats being downloaded.
147
+     * @param resource $stream The stream to output to.
148
+     * @param array $headers The fields to stream.
149
+     * @since       1.0.19
150
+     */
151
+    public function download_xml( $stats, $stream, $headers ) {
152
+
153
+        $prepared = array();
154
+
155
+        // Loop through
156
+        foreach ( $stats as $stat ) {
157
+            $prepared[] = $this->prepare_row( $stat, $headers );
158
+        }
159
+
160
+        $xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' );
161
+        $this->convert_array_xml( $prepared, $xml );
162
+
163
+        fwrite( $stream, $xml->asXML() );
164
+
165
+    }
166
+
167
+    /**
168
+     * Converts stats array to xml
169
+     *
170
+     * @access      public
171
+     * @since      1.0.19
172
+     */
173
+    public function convert_array_xml( $data, $xml ) {
174
+
175
+        // Loop through
176
+        foreach ( $data as $key => $value ) {
177
+
178
+            $key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key );
179
+
180
+            if ( is_array( $value ) ) {
181
+
182
+                if ( is_numeric( $key ) ) {
183
+                    $key = 'item' . $key; //dealing with <0/>..<n/> issues
184
+                }
185
+
186
+                $subnode = $xml->addChild( $key );
187
+                $this->convert_array_xml( $value, $subnode );
188
+
189
+            } else {
190
+                $xml->addChild( $key, $value ?  htmlspecialchars( $value ) : $value );
191
+            }
192 192
 }
193 193
 
194
-	}
194
+    }
195 195
 
196
-	/**
197
-	 * Prepares a single row for download.
198
-	 *
199
-	 * @param stdClass|array $row The row to prepare..
200
-	 * @param array $fields The fields to stream.
201
-	 * @since       1.0.19
202
-	 * @return array
203
-	 */
204
-	public function prepare_row( $row, $fields ) {
196
+    /**
197
+     * Prepares a single row for download.
198
+     *
199
+     * @param stdClass|array $row The row to prepare..
200
+     * @param array $fields The fields to stream.
201
+     * @since       1.0.19
202
+     * @return array
203
+     */
204
+    public function prepare_row( $row, $fields ) {
205 205
 
206
-		$prepared = array();
207
-		$row      = (array) $row;
206
+        $prepared = array();
207
+        $row      = (array) $row;
208 208
 
209
-		foreach ( $fields as $field ) {
209
+        foreach ( $fields as $field ) {
210 210
 
211
-			if ( $field === 'total' ) {
212
-				$prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES );
213
-				continue;
214
-			}
211
+            if ( $field === 'total' ) {
212
+                $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES );
213
+                continue;
214
+            }
215 215
 
216
-			if ( $field === 'total_raw' ) {
217
-				$prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) );
218
-				continue;
219
-			}
216
+            if ( $field === 'total_raw' ) {
217
+                $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) );
218
+                continue;
219
+            }
220 220
 
221
-			$prepared[ $field ] = strip_tags( $row[ $field ] );
221
+            $prepared[ $field ] = strip_tags( $row[ $field ] );
222 222
 
223
-		}
223
+        }
224 224
 
225
-		return $prepared;
226
-	}
225
+        return $prepared;
226
+    }
227 227
 
228 228
 
229 229
 }
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Graph_Downloader Class.
@@ -30,13 +30,13 @@  discard block
 block discarded – undo
30 30
 	 *
31 31
 	 * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts
32 32
 	 */
33
-	public function prepare_handler( $graph ) {
33
+	public function prepare_handler($graph) {
34 34
 
35
-		if ( empty( $this->handler->views[ $graph ] ) ) {
36
-			wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 );
35
+		if (empty($this->handler->views[$graph])) {
36
+			wp_die(esc_html__('Invalid Graph', 'invoicing'), 400);
37 37
 		}
38 38
 
39
-		return new $this->handler->views[ $graph ]['class']();
39
+		return new $this->handler->views[$graph]['class']();
40 40
 
41 41
 	}
42 42
 
@@ -47,10 +47,10 @@  discard block
 block discarded – undo
47 47
 	 */
48 48
 	public function prepare_output() {
49 49
 
50
-		$output  = fopen( 'php://output', 'w' );
50
+		$output = fopen('php://output', 'w');
51 51
 
52
-		if ( false === $output ) {
53
-			wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 );
52
+		if (false === $output) {
53
+			wp_die(esc_html__('Unsupported server', 'invoicing'), 500);
54 54
 		}
55 55
 
56 56
 		return $output;
@@ -61,13 +61,13 @@  discard block
 block discarded – undo
61 61
 	 *
62 62
 	 * @return string
63 63
 	 */
64
-	public function prepare_file_type( $graph ) {
64
+	public function prepare_file_type($graph) {
65 65
 
66
-		$file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] );
67
-		$file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) );
66
+		$file_type = empty($_REQUEST['file_type']) ? 'csv' : sanitize_text_field($_REQUEST['file_type']);
67
+		$file_name = wpinv_sanitize_key("getpaid-$graph-" . current_time('Y-m-d'));
68 68
 
69
-		header( "Content-Type:application/$file_type" );
70
-		header( "Content-Disposition:attachment;filename=$file_name.$file_type" );
69
+		header("Content-Type:application/$file_type");
70
+		header("Content-Disposition:attachment;filename=$file_name.$file_type");
71 71
 
72 72
 		return $file_type;
73 73
 	}
@@ -76,24 +76,24 @@  discard block
 block discarded – undo
76 76
 	 * Handles the actual download.
77 77
 	 *
78 78
 	 */
79
-	public function download( $graph ) {
79
+	public function download($graph) {
80 80
 		global $wpdb;
81 81
 
82
-		$handler   = $this->prepare_handler( $graph );
82
+		$handler   = $this->prepare_handler($graph);
83 83
 		$stream    = $this->prepare_output();
84
-		$stats     = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) );
85
-		$headers   = array( $handler->field, 'total', 'total_raw' );
86
-		$file_type = $this->prepare_file_type( $graph );
87
-
88
-		if ( 'csv' == $file_type ) {
89
-			$this->download_csv( $stats, $stream, $headers );
90
-		} elseif ( 'xml' == $file_type ) {
91
-			$this->download_xml( $stats, $stream, $headers );
84
+		$stats     = $wpdb->get_results($handler->get_sql($handler->get_range()));
85
+		$headers   = array($handler->field, 'total', 'total_raw');
86
+		$file_type = $this->prepare_file_type($graph);
87
+
88
+		if ('csv' == $file_type) {
89
+			$this->download_csv($stats, $stream, $headers);
90
+		} elseif ('xml' == $file_type) {
91
+			$this->download_xml($stats, $stream, $headers);
92 92
 		} else {
93
-			$this->download_json( $stats, $stream, $headers );
93
+			$this->download_json($stats, $stream, $headers);
94 94
 		}
95 95
 
96
-		fclose( $stream );
96
+		fclose($stream);
97 97
 		exit;
98 98
 	}
99 99
 
@@ -105,16 +105,16 @@  discard block
 block discarded – undo
105 105
 	 * @param array $headers The fields to stream.
106 106
 	 * @since       1.0.19
107 107
 	 */
108
-	public function download_csv( $stats, $stream, $headers ) {
108
+	public function download_csv($stats, $stream, $headers) {
109 109
 
110 110
 		// Output the csv column headers.
111
-		fputcsv( $stream, $headers );
111
+		fputcsv($stream, $headers);
112 112
 
113 113
 		// Loop through
114
-		foreach ( $stats as $stat ) {
115
-			$row  = array_values( $this->prepare_row( $stat, $headers ) );
116
-			$row  = array_map( 'maybe_serialize', $row );
117
-			fputcsv( $stream, $row );
114
+		foreach ($stats as $stat) {
115
+			$row  = array_values($this->prepare_row($stat, $headers));
116
+			$row  = array_map('maybe_serialize', $row);
117
+			fputcsv($stream, $row);
118 118
 		}
119 119
 
120 120
 	}
@@ -127,16 +127,16 @@  discard block
 block discarded – undo
127 127
 	 * @param array $headers The fields to stream.
128 128
 	 * @since       1.0.19
129 129
 	 */
130
-	public function download_json( $stats, $stream, $headers ) {
130
+	public function download_json($stats, $stream, $headers) {
131 131
 
132 132
 		$prepared = array();
133 133
 
134 134
 		// Loop through
135
-		foreach ( $stats as $stat ) {
136
-			$prepared[] = $this->prepare_row( $stat, $headers );
135
+		foreach ($stats as $stat) {
136
+			$prepared[] = $this->prepare_row($stat, $headers);
137 137
 		}
138 138
 
139
-		fwrite( $stream, wp_json_encode( $prepared ) );
139
+		fwrite($stream, wp_json_encode($prepared));
140 140
 
141 141
 	}
142 142
 
@@ -148,19 +148,19 @@  discard block
 block discarded – undo
148 148
 	 * @param array $headers The fields to stream.
149 149
 	 * @since       1.0.19
150 150
 	 */
151
-	public function download_xml( $stats, $stream, $headers ) {
151
+	public function download_xml($stats, $stream, $headers) {
152 152
 
153 153
 		$prepared = array();
154 154
 
155 155
 		// Loop through
156
-		foreach ( $stats as $stat ) {
157
-			$prepared[] = $this->prepare_row( $stat, $headers );
156
+		foreach ($stats as $stat) {
157
+			$prepared[] = $this->prepare_row($stat, $headers);
158 158
 		}
159 159
 
160
-		$xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' );
161
-		$this->convert_array_xml( $prepared, $xml );
160
+		$xml = new SimpleXMLElement('<?xml version="1.0"?><data></data>');
161
+		$this->convert_array_xml($prepared, $xml);
162 162
 
163
-		fwrite( $stream, $xml->asXML() );
163
+		fwrite($stream, $xml->asXML());
164 164
 
165 165
 	}
166 166
 
@@ -170,24 +170,24 @@  discard block
 block discarded – undo
170 170
 	 * @access      public
171 171
 	 * @since      1.0.19
172 172
 	 */
173
-	public function convert_array_xml( $data, $xml ) {
173
+	public function convert_array_xml($data, $xml) {
174 174
 
175 175
 		// Loop through
176
-		foreach ( $data as $key => $value ) {
176
+		foreach ($data as $key => $value) {
177 177
 
178
-			$key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key );
178
+			$key = preg_replace('/[^A-Za-z0-9_\-]/', '', $key);
179 179
 
180
-			if ( is_array( $value ) ) {
180
+			if (is_array($value)) {
181 181
 
182
-				if ( is_numeric( $key ) ) {
182
+				if (is_numeric($key)) {
183 183
 					$key = 'item' . $key; //dealing with <0/>..<n/> issues
184 184
 				}
185 185
 
186
-				$subnode = $xml->addChild( $key );
187
-				$this->convert_array_xml( $value, $subnode );
186
+				$subnode = $xml->addChild($key);
187
+				$this->convert_array_xml($value, $subnode);
188 188
 
189 189
 			} else {
190
-				$xml->addChild( $key, $value ?  htmlspecialchars( $value ) : $value );
190
+				$xml->addChild($key, $value ?  htmlspecialchars($value) : $value);
191 191
 			}
192 192
 }
193 193
 
@@ -201,24 +201,24 @@  discard block
 block discarded – undo
201 201
 	 * @since       1.0.19
202 202
 	 * @return array
203 203
 	 */
204
-	public function prepare_row( $row, $fields ) {
204
+	public function prepare_row($row, $fields) {
205 205
 
206 206
 		$prepared = array();
207 207
 		$row      = (array) $row;
208 208
 
209
-		foreach ( $fields as $field ) {
209
+		foreach ($fields as $field) {
210 210
 
211
-			if ( $field === 'total' ) {
212
-				$prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES );
211
+			if ($field === 'total') {
212
+				$prepared[$field] = html_entity_decode(strip_tags(wpinv_price($row['total'])), ENT_QUOTES);
213 213
 				continue;
214 214
 			}
215 215
 
216
-			if ( $field === 'total_raw' ) {
217
-				$prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) );
216
+			if ($field === 'total_raw') {
217
+				$prepared[$field] = wpinv_round_amount(wpinv_sanitize_amount($row['total']));
218 218
 				continue;
219 219
 			}
220 220
 
221
-			$prepared[ $field ] = strip_tags( $row[ $field ] );
221
+			$prepared[$field] = strip_tags($row[$field]);
222 222
 
223 223
 		}
224 224
 
Please login to merge, or discard this patch.
includes/reports/class-getpaid-invoice-exporter.php 2 patches
Indentation   +232 added lines, -232 removed lines patch added patch discarded remove patch
@@ -12,236 +12,236 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Invoice_Exporter extends GetPaid_Graph_Downloader {
14 14
 
15
-	/**
16
-	 * Retrieves invoices query args.
17
-	 *
18
-	 * @param string $post_type post type to retrieve.
19
-	 * @param array $args Args to search for.
20
-	 * @return array
21
-	 */
22
-	public function get_invoice_query_args( $post_type, $args ) {
23
-
24
-		$query_args = array(
25
-			'post_type'              => $post_type,
26
-			'post_status'            => array_keys( wpinv_get_invoice_statuses( true, false, $post_type ) ),
27
-			'posts_per_page'         => -1,
28
-			'no_found_rows'          => true,
29
-			'update_post_term_cache' => false,
30
-			'fields'                 => 'ids',
31
-		);
32
-
33
-		if ( ! empty( $args['status'] ) && in_array( $args['status'], $query_args['post_status'], true ) ) {
34
-			$query_args['post_status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) );
35
-		}
36
-
37
-		$date_query = array();
38
-		if ( ! empty( $args['to_date'] ) ) {
39
-			$date_query['before'] = wpinv_clean( $args['to_date'] );
40
-		}
41
-
42
-		if ( ! empty( $args['from_date'] ) ) {
43
-			$date_query['after'] = wpinv_clean( $args['from_date'] );
44
-		}
45
-
46
-		if ( ! empty( $date_query ) ) {
47
-			$date_query['inclusive']  = true;
48
-			$query_args['date_query'] = array( $date_query );
49
-		}
50
-
51
-		return $query_args;
52
-	}
53
-
54
-	/**
55
-	 * Retrieves invoices.
56
-	 *
57
-	 * @param array $query_args WP_Query args.
58
-	 * @return WPInv_Invoice[]
59
-	 */
60
-	public function get_invoices( $query_args ) {
61
-
62
-		// Get invoices.
63
-		$invoices = new WP_Query( $query_args );
64
-
65
-		// Prepare the results.
66
-		return array_map( 'wpinv_get_invoice', $invoices->posts );
67
-
68
-	}
69
-
70
-	/**
71
-	 * Handles the actual download.
72
-	 *
73
-	 */
74
-	public function export( $post_type, $args ) {
75
-
76
-		$invoices  = $this->get_invoices( $this->get_invoice_query_args( $post_type, $args ) );
77
-		$stream    = $this->prepare_output();
78
-		$headers   = $this->get_export_fields( $post_type );
79
-		$file_type = $this->prepare_file_type( strtolower( getpaid_get_post_type_label( $post_type ) ) );
80
-
81
-		if ( 'csv' == $file_type ) {
82
-			$this->download_csv( $invoices, $stream, $headers );
83
-		} elseif ( 'xml' == $file_type ) {
84
-			$this->download_xml( $invoices, $stream, $headers );
85
-		} else {
86
-			$this->download_json( $invoices, $stream, $headers );
87
-		}
88
-
89
-		fclose( $stream );
90
-		exit;
91
-	}
92
-
93
-	/**
94
-	 * Prepares a single invoice for download.
95
-	 *
96
-	 * @param WPInv_Invoice $invoice The invoice to prepare..
97
-	 * @param array $fields The fields to stream.
98
-	 * @since       1.0.19
99
-	 * @return array
100
-	 */
101
-	public function prepare_row( $invoice, $fields ) {
102
-
103
-		$prepared      = array();
104
-		$amount_fields = $this->get_amount_fields( $invoice->get_post_type() );
105
-		$meta_fields = $this->get_payment_form_meta( $invoice );
106
-
107
-		foreach ( $fields as $field ) {
108
-			$value  = '';
109
-			$method = "get_$field";
110
-
111
-			if ( method_exists( $invoice, $method ) ) {
112
-				$value  = $invoice->$method();
113
-			} else if( strpos( $field, '_' ) === 0 && isset( $meta_fields[ $field ] ) ) {
114
-				$value = $meta_fields[ $field ];
115
-			}
116
-
117
-			if ( in_array( $field, $amount_fields ) ) {
118
-				$value  = wpinv_round_amount( wpinv_sanitize_amount( $value ) );
119
-			}
120
-
121
-			$prepared[ $field ] = wpinv_clean( $value );
122
-
123
-		}
124
-
125
-		return $prepared;
126
-	}
127
-
128
-	/**
129
-	 * Retrieves export fields.
130
-	 *
131
-	 * @param string $post_type
132
-	 * @since       1.0.19
133
-	 * @return array
134
-	 */
135
-	public function get_export_fields( $post_type ) {
136
-
137
-		$fields = array(
138
-			'id',
139
-			'parent_id',
140
-			'status',
141
-			'date_created',
142
-			'date_modified',
143
-			'date_due',
144
-			'date_completed',
145
-			'number',
146
-			'key',
147
-			'description',
148
-			'post_type',
149
-			'mode',
150
-			'customer_id',
151
-			'customer_first_name',
152
-			'customer_last_name',
153
-			'customer_phone',
154
-			'customer_email',
155
-			'customer_country',
156
-			'customer_city',
157
-			'customer_state',
158
-			'customer_zip',
159
-			'customer_company',
160
-			'customer_vat_number',
161
-			'customer_address',
162
-			'subtotal',
163
-			'total_discount',
164
-			'total_tax',
165
-			'total_fees',
166
-			'fees',
167
-			'discounts',
168
-			'taxes',
169
-			'cart_details',
170
-			'item_ids',
171
-			'payment_form',
172
-			'discount_code',
173
-			'gateway',
174
-			'transaction_id',
175
-			'currency',
176
-			'disable_taxes',
177
-			'subscription_id',
178
-			'remote_subscription_id',
179
-			'is_viewed',
180
-			'email_cc',
181
-			'template',
182
-			'created_via',
183
-    	);
184
-
185
-		// Payment form meta fields.
186
-		$meta_fields = getpaid_get_payment_form_custom_fields();
187
-
188
-		if ( ! empty( $meta_fields ) ) {
189
-			foreach ( $meta_fields as $field_key => $field_label ) {
190
-				$fields[] = $field_key;
191
-			}
192
-		}
193
-
194
-		return apply_filters( 'getpaid_invoice_exporter_get_fields', $fields, $post_type );
195
-	}
196
-
197
-	/**
198
-	 * Retrieves amount fields.
199
-	 *
200
-	 * @param string $post_type
201
-	 * @since       1.0.19
202
-	 * @return array
203
-	 */
204
-	public function get_amount_fields( $post_type ) {
205
-
206
-		$fields = array(
207
-			'subtotal',
208
-			'total_discount',
209
-			'total_tax',
210
-			'total_fees',
211
-    	);
212
-
213
-		return apply_filters( 'getpaid_invoice_exporter_get_amount_fields', $fields, $post_type );
214
-	}
215
-
216
-	/**
217
-	 * Retrieves payment form meta fields.
218
-	 *
219
-	 * @since 2.8.23
220
-	 *
221
-	 * @return array
222
-	 */
223
-	public function get_payment_form_meta( $invoice ) {
224
-		// Payment form meta fields.
225
-		$field_keys = getpaid_get_payment_form_custom_fields();
226
-		$meta = get_post_meta( $invoice->get_id(), 'additional_meta_data', true );
227
-
228
-		$field_values = array();
229
-		if ( ! empty( $field_keys ) ) {
230
-			foreach ( $field_keys as $field_key => $field_label ) {
231
-				$value = '';
232
-
233
-				if ( ! empty( $meta ) ) {
234
-					foreach ( $meta as $meta_label => $meta_value ) {
235
-						if ( getpaid_strtolower( wpinv_clean( wp_unslash( $meta_label ) ) ) == getpaid_strtolower( $field_label ) ) {
236
-							$value = $meta_value;
237
-						}
238
-					}
239
-				}
240
-
241
-				$field_values[ $field_key ] = $value;
242
-			}
243
-		}
244
-
245
-		return $field_values;
246
-	}
15
+    /**
16
+     * Retrieves invoices query args.
17
+     *
18
+     * @param string $post_type post type to retrieve.
19
+     * @param array $args Args to search for.
20
+     * @return array
21
+     */
22
+    public function get_invoice_query_args( $post_type, $args ) {
23
+
24
+        $query_args = array(
25
+            'post_type'              => $post_type,
26
+            'post_status'            => array_keys( wpinv_get_invoice_statuses( true, false, $post_type ) ),
27
+            'posts_per_page'         => -1,
28
+            'no_found_rows'          => true,
29
+            'update_post_term_cache' => false,
30
+            'fields'                 => 'ids',
31
+        );
32
+
33
+        if ( ! empty( $args['status'] ) && in_array( $args['status'], $query_args['post_status'], true ) ) {
34
+            $query_args['post_status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) );
35
+        }
36
+
37
+        $date_query = array();
38
+        if ( ! empty( $args['to_date'] ) ) {
39
+            $date_query['before'] = wpinv_clean( $args['to_date'] );
40
+        }
41
+
42
+        if ( ! empty( $args['from_date'] ) ) {
43
+            $date_query['after'] = wpinv_clean( $args['from_date'] );
44
+        }
45
+
46
+        if ( ! empty( $date_query ) ) {
47
+            $date_query['inclusive']  = true;
48
+            $query_args['date_query'] = array( $date_query );
49
+        }
50
+
51
+        return $query_args;
52
+    }
53
+
54
+    /**
55
+     * Retrieves invoices.
56
+     *
57
+     * @param array $query_args WP_Query args.
58
+     * @return WPInv_Invoice[]
59
+     */
60
+    public function get_invoices( $query_args ) {
61
+
62
+        // Get invoices.
63
+        $invoices = new WP_Query( $query_args );
64
+
65
+        // Prepare the results.
66
+        return array_map( 'wpinv_get_invoice', $invoices->posts );
67
+
68
+    }
69
+
70
+    /**
71
+     * Handles the actual download.
72
+     *
73
+     */
74
+    public function export( $post_type, $args ) {
75
+
76
+        $invoices  = $this->get_invoices( $this->get_invoice_query_args( $post_type, $args ) );
77
+        $stream    = $this->prepare_output();
78
+        $headers   = $this->get_export_fields( $post_type );
79
+        $file_type = $this->prepare_file_type( strtolower( getpaid_get_post_type_label( $post_type ) ) );
80
+
81
+        if ( 'csv' == $file_type ) {
82
+            $this->download_csv( $invoices, $stream, $headers );
83
+        } elseif ( 'xml' == $file_type ) {
84
+            $this->download_xml( $invoices, $stream, $headers );
85
+        } else {
86
+            $this->download_json( $invoices, $stream, $headers );
87
+        }
88
+
89
+        fclose( $stream );
90
+        exit;
91
+    }
92
+
93
+    /**
94
+     * Prepares a single invoice for download.
95
+     *
96
+     * @param WPInv_Invoice $invoice The invoice to prepare..
97
+     * @param array $fields The fields to stream.
98
+     * @since       1.0.19
99
+     * @return array
100
+     */
101
+    public function prepare_row( $invoice, $fields ) {
102
+
103
+        $prepared      = array();
104
+        $amount_fields = $this->get_amount_fields( $invoice->get_post_type() );
105
+        $meta_fields = $this->get_payment_form_meta( $invoice );
106
+
107
+        foreach ( $fields as $field ) {
108
+            $value  = '';
109
+            $method = "get_$field";
110
+
111
+            if ( method_exists( $invoice, $method ) ) {
112
+                $value  = $invoice->$method();
113
+            } else if( strpos( $field, '_' ) === 0 && isset( $meta_fields[ $field ] ) ) {
114
+                $value = $meta_fields[ $field ];
115
+            }
116
+
117
+            if ( in_array( $field, $amount_fields ) ) {
118
+                $value  = wpinv_round_amount( wpinv_sanitize_amount( $value ) );
119
+            }
120
+
121
+            $prepared[ $field ] = wpinv_clean( $value );
122
+
123
+        }
124
+
125
+        return $prepared;
126
+    }
127
+
128
+    /**
129
+     * Retrieves export fields.
130
+     *
131
+     * @param string $post_type
132
+     * @since       1.0.19
133
+     * @return array
134
+     */
135
+    public function get_export_fields( $post_type ) {
136
+
137
+        $fields = array(
138
+            'id',
139
+            'parent_id',
140
+            'status',
141
+            'date_created',
142
+            'date_modified',
143
+            'date_due',
144
+            'date_completed',
145
+            'number',
146
+            'key',
147
+            'description',
148
+            'post_type',
149
+            'mode',
150
+            'customer_id',
151
+            'customer_first_name',
152
+            'customer_last_name',
153
+            'customer_phone',
154
+            'customer_email',
155
+            'customer_country',
156
+            'customer_city',
157
+            'customer_state',
158
+            'customer_zip',
159
+            'customer_company',
160
+            'customer_vat_number',
161
+            'customer_address',
162
+            'subtotal',
163
+            'total_discount',
164
+            'total_tax',
165
+            'total_fees',
166
+            'fees',
167
+            'discounts',
168
+            'taxes',
169
+            'cart_details',
170
+            'item_ids',
171
+            'payment_form',
172
+            'discount_code',
173
+            'gateway',
174
+            'transaction_id',
175
+            'currency',
176
+            'disable_taxes',
177
+            'subscription_id',
178
+            'remote_subscription_id',
179
+            'is_viewed',
180
+            'email_cc',
181
+            'template',
182
+            'created_via',
183
+        );
184
+
185
+        // Payment form meta fields.
186
+        $meta_fields = getpaid_get_payment_form_custom_fields();
187
+
188
+        if ( ! empty( $meta_fields ) ) {
189
+            foreach ( $meta_fields as $field_key => $field_label ) {
190
+                $fields[] = $field_key;
191
+            }
192
+        }
193
+
194
+        return apply_filters( 'getpaid_invoice_exporter_get_fields', $fields, $post_type );
195
+    }
196
+
197
+    /**
198
+     * Retrieves amount fields.
199
+     *
200
+     * @param string $post_type
201
+     * @since       1.0.19
202
+     * @return array
203
+     */
204
+    public function get_amount_fields( $post_type ) {
205
+
206
+        $fields = array(
207
+            'subtotal',
208
+            'total_discount',
209
+            'total_tax',
210
+            'total_fees',
211
+        );
212
+
213
+        return apply_filters( 'getpaid_invoice_exporter_get_amount_fields', $fields, $post_type );
214
+    }
215
+
216
+    /**
217
+     * Retrieves payment form meta fields.
218
+     *
219
+     * @since 2.8.23
220
+     *
221
+     * @return array
222
+     */
223
+    public function get_payment_form_meta( $invoice ) {
224
+        // Payment form meta fields.
225
+        $field_keys = getpaid_get_payment_form_custom_fields();
226
+        $meta = get_post_meta( $invoice->get_id(), 'additional_meta_data', true );
227
+
228
+        $field_values = array();
229
+        if ( ! empty( $field_keys ) ) {
230
+            foreach ( $field_keys as $field_key => $field_label ) {
231
+                $value = '';
232
+
233
+                if ( ! empty( $meta ) ) {
234
+                    foreach ( $meta as $meta_label => $meta_value ) {
235
+                        if ( getpaid_strtolower( wpinv_clean( wp_unslash( $meta_label ) ) ) == getpaid_strtolower( $field_label ) ) {
236
+                            $value = $meta_value;
237
+                        }
238
+                    }
239
+                }
240
+
241
+                $field_values[ $field_key ] = $value;
242
+            }
243
+        }
244
+
245
+        return $field_values;
246
+    }
247 247
 }
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Invoice_Exporter Class.
@@ -19,33 +19,33 @@  discard block
 block discarded – undo
19 19
 	 * @param array $args Args to search for.
20 20
 	 * @return array
21 21
 	 */
22
-	public function get_invoice_query_args( $post_type, $args ) {
22
+	public function get_invoice_query_args($post_type, $args) {
23 23
 
24 24
 		$query_args = array(
25 25
 			'post_type'              => $post_type,
26
-			'post_status'            => array_keys( wpinv_get_invoice_statuses( true, false, $post_type ) ),
26
+			'post_status'            => array_keys(wpinv_get_invoice_statuses(true, false, $post_type)),
27 27
 			'posts_per_page'         => -1,
28 28
 			'no_found_rows'          => true,
29 29
 			'update_post_term_cache' => false,
30 30
 			'fields'                 => 'ids',
31 31
 		);
32 32
 
33
-		if ( ! empty( $args['status'] ) && in_array( $args['status'], $query_args['post_status'], true ) ) {
34
-			$query_args['post_status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) );
33
+		if (!empty($args['status']) && in_array($args['status'], $query_args['post_status'], true)) {
34
+			$query_args['post_status'] = wpinv_clean(wpinv_parse_list($args['status']));
35 35
 		}
36 36
 
37 37
 		$date_query = array();
38
-		if ( ! empty( $args['to_date'] ) ) {
39
-			$date_query['before'] = wpinv_clean( $args['to_date'] );
38
+		if (!empty($args['to_date'])) {
39
+			$date_query['before'] = wpinv_clean($args['to_date']);
40 40
 		}
41 41
 
42
-		if ( ! empty( $args['from_date'] ) ) {
43
-			$date_query['after'] = wpinv_clean( $args['from_date'] );
42
+		if (!empty($args['from_date'])) {
43
+			$date_query['after'] = wpinv_clean($args['from_date']);
44 44
 		}
45 45
 
46
-		if ( ! empty( $date_query ) ) {
46
+		if (!empty($date_query)) {
47 47
 			$date_query['inclusive']  = true;
48
-			$query_args['date_query'] = array( $date_query );
48
+			$query_args['date_query'] = array($date_query);
49 49
 		}
50 50
 
51 51
 		return $query_args;
@@ -57,13 +57,13 @@  discard block
 block discarded – undo
57 57
 	 * @param array $query_args WP_Query args.
58 58
 	 * @return WPInv_Invoice[]
59 59
 	 */
60
-	public function get_invoices( $query_args ) {
60
+	public function get_invoices($query_args) {
61 61
 
62 62
 		// Get invoices.
63
-		$invoices = new WP_Query( $query_args );
63
+		$invoices = new WP_Query($query_args);
64 64
 
65 65
 		// Prepare the results.
66
-		return array_map( 'wpinv_get_invoice', $invoices->posts );
66
+		return array_map('wpinv_get_invoice', $invoices->posts);
67 67
 
68 68
 	}
69 69
 
@@ -71,22 +71,22 @@  discard block
 block discarded – undo
71 71
 	 * Handles the actual download.
72 72
 	 *
73 73
 	 */
74
-	public function export( $post_type, $args ) {
74
+	public function export($post_type, $args) {
75 75
 
76
-		$invoices  = $this->get_invoices( $this->get_invoice_query_args( $post_type, $args ) );
76
+		$invoices  = $this->get_invoices($this->get_invoice_query_args($post_type, $args));
77 77
 		$stream    = $this->prepare_output();
78
-		$headers   = $this->get_export_fields( $post_type );
79
-		$file_type = $this->prepare_file_type( strtolower( getpaid_get_post_type_label( $post_type ) ) );
78
+		$headers   = $this->get_export_fields($post_type);
79
+		$file_type = $this->prepare_file_type(strtolower(getpaid_get_post_type_label($post_type)));
80 80
 
81
-		if ( 'csv' == $file_type ) {
82
-			$this->download_csv( $invoices, $stream, $headers );
83
-		} elseif ( 'xml' == $file_type ) {
84
-			$this->download_xml( $invoices, $stream, $headers );
81
+		if ('csv' == $file_type) {
82
+			$this->download_csv($invoices, $stream, $headers);
83
+		} elseif ('xml' == $file_type) {
84
+			$this->download_xml($invoices, $stream, $headers);
85 85
 		} else {
86
-			$this->download_json( $invoices, $stream, $headers );
86
+			$this->download_json($invoices, $stream, $headers);
87 87
 		}
88 88
 
89
-		fclose( $stream );
89
+		fclose($stream);
90 90
 		exit;
91 91
 	}
92 92
 
@@ -98,27 +98,27 @@  discard block
 block discarded – undo
98 98
 	 * @since       1.0.19
99 99
 	 * @return array
100 100
 	 */
101
-	public function prepare_row( $invoice, $fields ) {
101
+	public function prepare_row($invoice, $fields) {
102 102
 
103 103
 		$prepared      = array();
104
-		$amount_fields = $this->get_amount_fields( $invoice->get_post_type() );
105
-		$meta_fields = $this->get_payment_form_meta( $invoice );
104
+		$amount_fields = $this->get_amount_fields($invoice->get_post_type());
105
+		$meta_fields = $this->get_payment_form_meta($invoice);
106 106
 
107
-		foreach ( $fields as $field ) {
107
+		foreach ($fields as $field) {
108 108
 			$value  = '';
109 109
 			$method = "get_$field";
110 110
 
111
-			if ( method_exists( $invoice, $method ) ) {
112
-				$value  = $invoice->$method();
113
-			} else if( strpos( $field, '_' ) === 0 && isset( $meta_fields[ $field ] ) ) {
114
-				$value = $meta_fields[ $field ];
111
+			if (method_exists($invoice, $method)) {
112
+				$value = $invoice->$method();
113
+			} else if (strpos($field, '_') === 0 && isset($meta_fields[$field])) {
114
+				$value = $meta_fields[$field];
115 115
 			}
116 116
 
117
-			if ( in_array( $field, $amount_fields ) ) {
118
-				$value  = wpinv_round_amount( wpinv_sanitize_amount( $value ) );
117
+			if (in_array($field, $amount_fields)) {
118
+				$value = wpinv_round_amount(wpinv_sanitize_amount($value));
119 119
 			}
120 120
 
121
-			$prepared[ $field ] = wpinv_clean( $value );
121
+			$prepared[$field] = wpinv_clean($value);
122 122
 
123 123
 		}
124 124
 
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 	 * @since       1.0.19
133 133
 	 * @return array
134 134
 	 */
135
-	public function get_export_fields( $post_type ) {
135
+	public function get_export_fields($post_type) {
136 136
 
137 137
 		$fields = array(
138 138
 			'id',
@@ -185,13 +185,13 @@  discard block
 block discarded – undo
185 185
 		// Payment form meta fields.
186 186
 		$meta_fields = getpaid_get_payment_form_custom_fields();
187 187
 
188
-		if ( ! empty( $meta_fields ) ) {
189
-			foreach ( $meta_fields as $field_key => $field_label ) {
188
+		if (!empty($meta_fields)) {
189
+			foreach ($meta_fields as $field_key => $field_label) {
190 190
 				$fields[] = $field_key;
191 191
 			}
192 192
 		}
193 193
 
194
-		return apply_filters( 'getpaid_invoice_exporter_get_fields', $fields, $post_type );
194
+		return apply_filters('getpaid_invoice_exporter_get_fields', $fields, $post_type);
195 195
 	}
196 196
 
197 197
 	/**
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 	 * @since       1.0.19
202 202
 	 * @return array
203 203
 	 */
204
-	public function get_amount_fields( $post_type ) {
204
+	public function get_amount_fields($post_type) {
205 205
 
206 206
 		$fields = array(
207 207
 			'subtotal',
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 			'total_fees',
211 211
     	);
212 212
 
213
-		return apply_filters( 'getpaid_invoice_exporter_get_amount_fields', $fields, $post_type );
213
+		return apply_filters('getpaid_invoice_exporter_get_amount_fields', $fields, $post_type);
214 214
 	}
215 215
 
216 216
 	/**
@@ -220,25 +220,25 @@  discard block
 block discarded – undo
220 220
 	 *
221 221
 	 * @return array
222 222
 	 */
223
-	public function get_payment_form_meta( $invoice ) {
223
+	public function get_payment_form_meta($invoice) {
224 224
 		// Payment form meta fields.
225 225
 		$field_keys = getpaid_get_payment_form_custom_fields();
226
-		$meta = get_post_meta( $invoice->get_id(), 'additional_meta_data', true );
226
+		$meta = get_post_meta($invoice->get_id(), 'additional_meta_data', true);
227 227
 
228 228
 		$field_values = array();
229
-		if ( ! empty( $field_keys ) ) {
230
-			foreach ( $field_keys as $field_key => $field_label ) {
229
+		if (!empty($field_keys)) {
230
+			foreach ($field_keys as $field_key => $field_label) {
231 231
 				$value = '';
232 232
 
233
-				if ( ! empty( $meta ) ) {
234
-					foreach ( $meta as $meta_label => $meta_value ) {
235
-						if ( getpaid_strtolower( wpinv_clean( wp_unslash( $meta_label ) ) ) == getpaid_strtolower( $field_label ) ) {
233
+				if (!empty($meta)) {
234
+					foreach ($meta as $meta_label => $meta_value) {
235
+						if (getpaid_strtolower(wpinv_clean(wp_unslash($meta_label))) == getpaid_strtolower($field_label)) {
236 236
 							$value = $meta_value;
237 237
 						}
238 238
 					}
239 239
 				}
240 240
 
241
-				$field_values[ $field_key ] = $value;
241
+				$field_values[$field_key] = $value;
242 242
 			}
243 243
 		}
244 244
 
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 2 patches
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
141 141
  */
142 142
 function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
143
-	return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path );
143
+    return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path );
144 144
 }
145 145
 
146 146
 /**
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
  * @return string
159 159
  */
160 160
 function wpinv_get_theme_template_dir_name() {
161
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
161
+    return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
162 162
 }
163 163
 
164 164
 /**
@@ -175,125 +175,125 @@  discard block
 block discarded – undo
175 175
 }
176 176
 
177 177
 function wpinv_get_template_part( $slug, $name = null, $load = true ) {
178
-	do_action( 'get_template_part_' . $slug, $slug, $name );
178
+    do_action( 'get_template_part_' . $slug, $slug, $name );
179 179
 
180
-	// Setup possible parts
181
-	$templates = array();
182
-	if ( isset( $name ) ) {
183
-		$templates[] = $slug . '-' . $name . '.php';
180
+    // Setup possible parts
181
+    $templates = array();
182
+    if ( isset( $name ) ) {
183
+        $templates[] = $slug . '-' . $name . '.php';
184 184
     }
185
-	$templates[] = $slug . '.php';
185
+    $templates[] = $slug . '.php';
186 186
 
187
-	// Allow template parts to be filtered
188
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
187
+    // Allow template parts to be filtered
188
+    $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
189 189
 
190
-	// Return the part that is found
191
-	return wpinv_locate_tmpl( $templates, $load, false );
190
+    // Return the part that is found
191
+    return wpinv_locate_tmpl( $templates, $load, false );
192 192
 }
193 193
 
194 194
 function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
195
-	// No file found yet
196
-	$located = false;
195
+    // No file found yet
196
+    $located = false;
197 197
 
198
-	// Try to find a template file
199
-	foreach ( (array)$template_names as $template_name ) {
198
+    // Try to find a template file
199
+    foreach ( (array)$template_names as $template_name ) {
200 200
 
201
-		// Continue if template is empty
202
-		if ( empty( $template_name ) ) {
203
-			continue;
201
+        // Continue if template is empty
202
+        if ( empty( $template_name ) ) {
203
+            continue;
204 204
         }
205 205
 
206
-		// Trim off any slashes from the template name
207
-		$template_name = ltrim( $template_name, '/' );
206
+        // Trim off any slashes from the template name
207
+        $template_name = ltrim( $template_name, '/' );
208 208
 
209
-		// try locating this template file by looping through the template paths
210
-		foreach ( wpinv_get_theme_template_paths() as $template_path ) {
209
+        // try locating this template file by looping through the template paths
210
+        foreach ( wpinv_get_theme_template_paths() as $template_path ) {
211 211
 
212
-			if ( file_exists( $template_path . $template_name ) ) {
213
-				$located = $template_path . $template_name;
214
-				break;
215
-			}
216
-		}
212
+            if ( file_exists( $template_path . $template_name ) ) {
213
+                $located = $template_path . $template_name;
214
+                break;
215
+            }
216
+        }
217 217
 
218
-		if ( ! empty( $located ) ) {
219
-			break;
220
-		}
221
-	}
218
+        if ( ! empty( $located ) ) {
219
+            break;
220
+        }
221
+    }
222 222
 
223
-	if ( ( true == $load ) && ! empty( $located ) ) {
224
-		load_template( $located, $require_once );
223
+    if ( ( true == $load ) && ! empty( $located ) ) {
224
+        load_template( $located, $require_once );
225 225
     }
226 226
 
227
-	return $located;
227
+    return $located;
228 228
 }
229 229
 
230 230
 function wpinv_get_theme_template_paths() {
231
-	$template_dir = wpinv_get_theme_template_dir_name();
231
+    $template_dir = wpinv_get_theme_template_dir_name();
232 232
 
233
-	$file_paths = array(
234
-		1   => trailingslashit( get_stylesheet_directory() ) . $template_dir,
235
-		10  => trailingslashit( get_template_directory() ) . $template_dir,
236
-		100 => wpinv_get_templates_dir(),
237
-	);
233
+    $file_paths = array(
234
+        1   => trailingslashit( get_stylesheet_directory() ) . $template_dir,
235
+        10  => trailingslashit( get_template_directory() ) . $template_dir,
236
+        100 => wpinv_get_templates_dir(),
237
+    );
238 238
 
239
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
239
+    $file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
240 240
 
241
-	// sort the file paths based on priority
242
-	ksort( $file_paths, SORT_NUMERIC );
241
+    // sort the file paths based on priority
242
+    ksort( $file_paths, SORT_NUMERIC );
243 243
 
244
-	return array_map( 'trailingslashit', $file_paths );
244
+    return array_map( 'trailingslashit', $file_paths );
245 245
 }
246 246
 
247 247
 function wpinv_checkout_meta_tags() {
248 248
 
249
-	$pages   = array();
250
-	$pages[] = wpinv_get_option( 'success_page' );
251
-	$pages[] = wpinv_get_option( 'failure_page' );
252
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
253
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
249
+    $pages   = array();
250
+    $pages[] = wpinv_get_option( 'success_page' );
251
+    $pages[] = wpinv_get_option( 'failure_page' );
252
+    $pages[] = wpinv_get_option( 'invoice_history_page' );
253
+    $pages[] = wpinv_get_option( 'invoice_subscription_page' );
254 254
 
255
-	if ( ! wpinv_is_checkout() && ! is_page( $pages ) ) {
256
-		return;
257
-	}
255
+    if ( ! wpinv_is_checkout() && ! is_page( $pages ) ) {
256
+        return;
257
+    }
258 258
 
259
-	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
259
+    echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
260 260
 }
261 261
 add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
262 262
 
263 263
 function wpinv_add_body_classes( $class ) {
264
-	$classes = (array)$class;
264
+    $classes = (array)$class;
265 265
 
266
-	if ( wpinv_is_checkout() ) {
267
-		$classes[] = 'wpinv-checkout';
268
-		$classes[] = 'wpinv-page';
269
-	}
266
+    if ( wpinv_is_checkout() ) {
267
+        $classes[] = 'wpinv-checkout';
268
+        $classes[] = 'wpinv-page';
269
+    }
270 270
 
271
-	if ( wpinv_is_success_page() ) {
272
-		$classes[] = 'wpinv-success';
273
-		$classes[] = 'wpinv-page';
274
-	}
271
+    if ( wpinv_is_success_page() ) {
272
+        $classes[] = 'wpinv-success';
273
+        $classes[] = 'wpinv-page';
274
+    }
275 275
 
276
-	if ( wpinv_is_failed_transaction_page() ) {
277
-		$classes[] = 'wpinv-failed-transaction';
278
-		$classes[] = 'wpinv-page';
279
-	}
276
+    if ( wpinv_is_failed_transaction_page() ) {
277
+        $classes[] = 'wpinv-failed-transaction';
278
+        $classes[] = 'wpinv-page';
279
+    }
280 280
 
281
-	if ( wpinv_is_invoice_history_page() ) {
282
-		$classes[] = 'wpinv-history';
283
-		$classes[] = 'wpinv-page';
284
-	}
281
+    if ( wpinv_is_invoice_history_page() ) {
282
+        $classes[] = 'wpinv-history';
283
+        $classes[] = 'wpinv-page';
284
+    }
285 285
 
286
-	if ( wpinv_is_subscriptions_history_page() ) {
287
-		$classes[] = 'wpinv-subscription';
288
-		$classes[] = 'wpinv-page';
289
-	}
286
+    if ( wpinv_is_subscriptions_history_page() ) {
287
+        $classes[] = 'wpinv-subscription';
288
+        $classes[] = 'wpinv-page';
289
+    }
290 290
 
291
-	if ( wpinv_is_test_mode() ) {
292
-		$classes[] = 'wpinv-test-mode';
293
-		$classes[] = 'wpinv-page';
294
-	}
291
+    if ( wpinv_is_test_mode() ) {
292
+        $classes[] = 'wpinv-test-mode';
293
+        $classes[] = 'wpinv-page';
294
+    }
295 295
 
296
-	return array_unique( $classes );
296
+    return array_unique( $classes );
297 297
 }
298 298
 add_filter( 'body_class', 'wpinv_add_body_classes' );
299 299
 
@@ -467,16 +467,16 @@  discard block
 block discarded – undo
467 467
 
468 468
     wpinv_html_select(
469 469
         array(
470
-			'name'             => $args['name'],
471
-			'selected'         => $args['selected'],
472
-			'id'               => $args['id'],
473
-			'class'            => $args['class'],
474
-			'options'          => $options,
475
-			'multiple'         => $args['multiple'],
476
-			'placeholder'      => $args['placeholder'],
477
-			'show_option_all'  => $args['show_option_all'],
478
-			'show_option_none' => $args['show_option_none'],
479
-			'data'             => $args['data'],
470
+            'name'             => $args['name'],
471
+            'selected'         => $args['selected'],
472
+            'id'               => $args['id'],
473
+            'class'            => $args['class'],
474
+            'options'          => $options,
475
+            'multiple'         => $args['multiple'],
476
+            'placeholder'      => $args['placeholder'],
477
+            'show_option_all'  => $args['show_option_all'],
478
+            'show_option_none' => $args['show_option_none'],
479
+            'data'             => $args['data'],
480 480
         )
481 481
     );
482 482
 
@@ -776,21 +776,21 @@  discard block
 block discarded – undo
776 776
 
777 777
     $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format );
778 778
 
779
-	// Remove unavailable tags.
779
+    // Remove unavailable tags.
780 780
     $formatted_address = preg_replace( '/\{\{\w+\}\}/', '', $formatted_address );
781 781
 
782 782
     // Clean up white space.
783
-	$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
783
+    $formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
784 784
     $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
785 785
 
786 786
     // Break newlines apart and remove empty lines/trim commas and white space.
787
-	$formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
787
+    $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
788 788
 
789 789
     // Add html breaks.
790
-	$formatted_address = implode( $separator, $formatted_address );
790
+    $formatted_address = implode( $separator, $formatted_address );
791 791
 
792
-	// We're done!
793
-	return $formatted_address;
792
+    // We're done!
793
+    return $formatted_address;
794 794
 
795 795
 }
796 796
 
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
 function getpaid_display_invoice_subscriptions( $invoice ) {
837 837
 
838 838
     // Subscriptions.
839
-	$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
839
+    $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
840 840
 
841 841
     if ( empty( $subscriptions ) || ! $invoice->is_recurring() ) {
842 842
         return;
@@ -1052,7 +1052,7 @@  discard block
 block discarded – undo
1052 1052
 }
1053 1053
 
1054 1054
 function wpinv_empty_cart_message() {
1055
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1055
+    return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1056 1056
 }
1057 1057
 
1058 1058
 /**
@@ -1250,9 +1250,9 @@  discard block
 block discarded – undo
1250 1250
 
1251 1251
     if ( 0 == count( $form->get_items() ) ) {
1252 1252
         aui()->alert(
1253
-			array(
1254
-				'type'    => 'warning',
1255
-				'content' => __( 'No published items found', 'invoicing' ),
1253
+            array(
1254
+                'type'    => 'warning',
1255
+                'content' => __( 'No published items found', 'invoicing' ),
1256 1256
             ),
1257 1257
             true
1258 1258
         );
@@ -1275,10 +1275,10 @@  discard block
 block discarded – undo
1275 1275
     $invoice = wpinv_get_invoice( $invoice_id );
1276 1276
 
1277 1277
     if ( empty( $invoice ) ) {
1278
-		aui()->alert(
1279
-			array(
1280
-				'type'    => 'warning',
1281
-				'content' => __( 'Invoice not found', 'invoicing' ),
1278
+        aui()->alert(
1279
+            array(
1280
+                'type'    => 'warning',
1281
+                'content' => __( 'Invoice not found', 'invoicing' ),
1282 1282
             ),
1283 1283
             true
1284 1284
         );
@@ -1286,10 +1286,10 @@  discard block
 block discarded – undo
1286 1286
     }
1287 1287
 
1288 1288
     if ( $invoice->is_paid() ) {
1289
-		aui()->alert(
1290
-			array(
1291
-				'type'    => 'warning',
1292
-				'content' => __( 'Invoice has already been paid', 'invoicing' ),
1289
+        aui()->alert(
1290
+            array(
1291
+                'type'    => 'warning',
1292
+                'content' => __( 'Invoice has already been paid', 'invoicing' ),
1293 1293
             ),
1294 1294
             true
1295 1295
         );
@@ -1354,7 +1354,7 @@  discard block
 block discarded – undo
1354 1354
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>";
1355 1355
     }
1356 1356
 
1357
-	if ( ! empty( $items ) ) {
1357
+    if ( ! empty( $items ) ) {
1358 1358
         $items  = esc_attr( $items );
1359 1359
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>";
1360 1360
     }
@@ -1554,21 +1554,21 @@  discard block
 block discarded – undo
1554 1554
 
1555 1555
         return aui()->select(
1556 1556
             array(
1557
-				'options'          => $states,
1558
-				'name'             => esc_attr( $field_name ),
1559
-				'id'               => sanitize_html_class( $field_name ) . $uniqid,
1560
-				'value'            => sanitize_text_field( $state ),
1561
-				'placeholder'      => $placeholder,
1562
-				'required'         => $required,
1563
-				'label'            => wp_kses_post( $label ),
1564
-				'label_type'       => 'vertical',
1565
-				'help_text'        => $help_text,
1566
-				'class'            => 'getpaid-address-field wpinv_state',
1567
-				'wrap_class'       => "$wrapper_class getpaid-address-field-wrapper__state",
1568
-				'label_class'      => 'getpaid-address-field-label getpaid-address-field-label__state',
1569
-				'extra_attributes' => array(
1570
-					'autocomplete' => 'address-level1',
1571
-				),
1557
+                'options'          => $states,
1558
+                'name'             => esc_attr( $field_name ),
1559
+                'id'               => sanitize_html_class( $field_name ) . $uniqid,
1560
+                'value'            => sanitize_text_field( $state ),
1561
+                'placeholder'      => $placeholder,
1562
+                'required'         => $required,
1563
+                'label'            => wp_kses_post( $label ),
1564
+                'label_type'       => 'vertical',
1565
+                'help_text'        => $help_text,
1566
+                'class'            => 'getpaid-address-field wpinv_state',
1567
+                'wrap_class'       => "$wrapper_class getpaid-address-field-wrapper__state",
1568
+                'label_class'      => 'getpaid-address-field-label getpaid-address-field-label__state',
1569
+                'extra_attributes' => array(
1570
+                    'autocomplete' => 'address-level1',
1571
+                ),
1572 1572
             ),
1573 1573
             $echo
1574 1574
         );
@@ -1664,34 +1664,34 @@  discard block
 block discarded – undo
1664 1664
  * @return array Array of custom fields.
1665 1665
  */
1666 1666
 function getpaid_get_payment_form_custom_fields() {
1667
-	global $wpdb, $payment_form_meta_fields;
1667
+    global $wpdb, $payment_form_meta_fields;
1668 1668
 
1669
-	if ( ! empty( $payment_form_meta_fields ) ) {
1670
-		return $payment_form_meta_fields;
1671
-	}
1669
+    if ( ! empty( $payment_form_meta_fields ) ) {
1670
+        return $payment_form_meta_fields;
1671
+    }
1672 1672
 
1673
-	$results = $wpdb->get_results( "SELECT `pm`.`meta_value` FROM `{$wpdb->postmeta}` AS pm LEFT JOIN `{$wpdb->posts}` AS p ON p.ID = pm.post_id WHERE `pm`.`meta_key` = 'wpinv_form_elements' AND `p`.`post_type` = 'wpi_payment_form'" );
1673
+    $results = $wpdb->get_results( "SELECT `pm`.`meta_value` FROM `{$wpdb->postmeta}` AS pm LEFT JOIN `{$wpdb->posts}` AS p ON p.ID = pm.post_id WHERE `pm`.`meta_key` = 'wpinv_form_elements' AND `p`.`post_type` = 'wpi_payment_form'" );
1674 1674
 
1675
-	$meta_fields = array();
1675
+    $meta_fields = array();
1676 1676
 
1677
-	if ( ! empty( $results ) ) {
1678
-		foreach ( $results as $row ) {
1679
-			$fields = maybe_unserialize( $row->meta_value );
1677
+    if ( ! empty( $results ) ) {
1678
+        foreach ( $results as $row ) {
1679
+            $fields = maybe_unserialize( $row->meta_value );
1680 1680
 
1681
-			if ( ! empty( $fields ) && is_array( $fields ) ) {
1682
-				foreach ( $fields as $field ) {
1683
-					$label = ! empty( $field['add_meta'] ) && ! empty( $field['label'] ) ? wpinv_clean( wp_unslash( $field['label'] ) ) : '';
1681
+            if ( ! empty( $fields ) && is_array( $fields ) ) {
1682
+                foreach ( $fields as $field ) {
1683
+                    $label = ! empty( $field['add_meta'] ) && ! empty( $field['label'] ) ? wpinv_clean( wp_unslash( $field['label'] ) ) : '';
1684 1684
 
1685
-					if ( $label ) {
1686
-						$field_key = '_' . str_replace( array( ' ', "'", '"', ',' ), array( '_', '', '', '_' ), getpaid_strtolower( $label ) );
1687
-						$meta_fields[ $field_key ] = $label;
1688
-					}
1689
-				}
1690
-			}
1691
-		}
1692
-	}
1685
+                    if ( $label ) {
1686
+                        $field_key = '_' . str_replace( array( ' ', "'", '"', ',' ), array( '_', '', '', '_' ), getpaid_strtolower( $label ) );
1687
+                        $meta_fields[ $field_key ] = $label;
1688
+                    }
1689
+                }
1690
+            }
1691
+        }
1692
+    }
1693 1693
 
1694
-	$payment_form_meta_fields = $meta_fields;
1694
+    $payment_form_meta_fields = $meta_fields;
1695 1695
 
1696
-	return $meta_fields;
1696
+    return $meta_fields;
1697 1697
 }
Please login to merge, or discard this patch.
Spacing   +462 added lines, -462 removed lines patch added patch discarded remove patch
@@ -4,99 +4,99 @@  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
  * Displays an invoice.
11 11
  *
12 12
  * @param WPInv_Invoice $invoice.
13 13
  */
14
-function getpaid_invoice( $invoice ) {
15
-    if ( ! empty( $invoice ) ) {
16
-        wpinv_get_template( 'invoice/invoice.php', compact( 'invoice' ) );
14
+function getpaid_invoice($invoice) {
15
+    if (!empty($invoice)) {
16
+        wpinv_get_template('invoice/invoice.php', compact('invoice'));
17 17
     }
18 18
 }
19
-add_action( 'getpaid_invoice', 'getpaid_invoice', 10 );
19
+add_action('getpaid_invoice', 'getpaid_invoice', 10);
20 20
 
21 21
 /**
22 22
  * Displays the invoice footer.
23 23
  */
24
-function getpaid_invoice_footer( $invoice ) {
25
-    if ( ! empty( $invoice ) ) {
26
-        wpinv_get_template( 'invoice/footer.php', compact( 'invoice' ) );
24
+function getpaid_invoice_footer($invoice) {
25
+    if (!empty($invoice)) {
26
+        wpinv_get_template('invoice/footer.php', compact('invoice'));
27 27
     }
28 28
 }
29
-add_action( 'getpaid_invoice_footer', 'getpaid_invoice_footer', 10 );
29
+add_action('getpaid_invoice_footer', 'getpaid_invoice_footer', 10);
30 30
 
31 31
 /**
32 32
  * Displays the invoice top bar.
33 33
  */
34
-function getpaid_invoice_header( $invoice ) {
35
-    if ( ! empty( $invoice ) ) {
36
-        wpinv_get_template( 'invoice/header.php', compact( 'invoice' ) );
34
+function getpaid_invoice_header($invoice) {
35
+    if (!empty($invoice)) {
36
+        wpinv_get_template('invoice/header.php', compact('invoice'));
37 37
     }
38 38
 }
39
-add_action( 'getpaid_invoice_header', 'getpaid_invoice_header', 10 );
39
+add_action('getpaid_invoice_header', 'getpaid_invoice_header', 10);
40 40
 
41 41
 /**
42 42
  * Displays actions on the left side of the header.
43 43
  */
44
-function getpaid_invoice_header_left_actions( $invoice ) {
45
-    if ( ! empty( $invoice ) ) {
46
-        wpinv_get_template( 'invoice/header-left-actions.php', compact( 'invoice' ) );
44
+function getpaid_invoice_header_left_actions($invoice) {
45
+    if (!empty($invoice)) {
46
+        wpinv_get_template('invoice/header-left-actions.php', compact('invoice'));
47 47
     }
48 48
 }
49
-add_action( 'getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10 );
49
+add_action('getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10);
50 50
 
51 51
 /**
52 52
  * Displays actions on the right side of the invoice top bar.
53 53
  */
54
-function getpaid_invoice_header_right_actions( $invoice ) {
55
-    if ( ! empty( $invoice ) ) {
56
-        wpinv_get_template( 'invoice/header-right-actions.php', compact( 'invoice' ) );
54
+function getpaid_invoice_header_right_actions($invoice) {
55
+    if (!empty($invoice)) {
56
+        wpinv_get_template('invoice/header-right-actions.php', compact('invoice'));
57 57
     }
58 58
 }
59
-add_action( 'getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10 );
59
+add_action('getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10);
60 60
 
61 61
 /**
62 62
  * Displays the invoice title, logo etc.
63 63
  */
64
-function getpaid_invoice_details_top( $invoice ) {
65
-    if ( ! empty( $invoice ) ) {
66
-        wpinv_get_template( 'invoice/details-top.php', compact( 'invoice' ) );
64
+function getpaid_invoice_details_top($invoice) {
65
+    if (!empty($invoice)) {
66
+        wpinv_get_template('invoice/details-top.php', compact('invoice'));
67 67
     }
68 68
 }
69
-add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_top', 10 );
69
+add_action('getpaid_invoice_details', 'getpaid_invoice_details_top', 10);
70 70
 
71 71
 /**
72 72
  * Displays the company logo.
73 73
  */
74
-function getpaid_invoice_logo( $invoice ) {
75
-    if ( ! empty( $invoice ) ) {
76
-        wpinv_get_template( 'invoice/invoice-logo.php', compact( 'invoice' ) );
74
+function getpaid_invoice_logo($invoice) {
75
+    if (!empty($invoice)) {
76
+        wpinv_get_template('invoice/invoice-logo.php', compact('invoice'));
77 77
     }
78 78
 }
79
-add_action( 'getpaid_invoice_details_top_left', 'getpaid_invoice_logo' );
79
+add_action('getpaid_invoice_details_top_left', 'getpaid_invoice_logo');
80 80
 
81 81
 /**
82 82
  * Displays the type of invoice.
83 83
  */
84
-function getpaid_invoice_type( $invoice ) {
85
-    if ( ! empty( $invoice ) ) {
86
-        wpinv_get_template( 'invoice/invoice-type.php', compact( 'invoice' ) );
84
+function getpaid_invoice_type($invoice) {
85
+    if (!empty($invoice)) {
86
+        wpinv_get_template('invoice/invoice-type.php', compact('invoice'));
87 87
     }
88 88
 }
89
-add_action( 'getpaid_invoice_details_top_right', 'getpaid_invoice_type' );
89
+add_action('getpaid_invoice_details_top_right', 'getpaid_invoice_type');
90 90
 
91 91
 /**
92 92
  * Displays the invoice details.
93 93
  */
94
-function getpaid_invoice_details_main( $invoice ) {
95
-    if ( ! empty( $invoice ) ) {
96
-        wpinv_get_template( 'invoice/details.php', compact( 'invoice' ) );
94
+function getpaid_invoice_details_main($invoice) {
95
+    if (!empty($invoice)) {
96
+        wpinv_get_template('invoice/details.php', compact('invoice'));
97 97
     }
98 98
 }
99
-add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_main', 50 );
99
+add_action('getpaid_invoice_details', 'getpaid_invoice_details_main', 50);
100 100
 
101 101
 /**
102 102
  * Returns a path to the templates directory.
@@ -125,8 +125,8 @@  discard block
 block discarded – undo
125 125
  * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'.
126 126
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
127 127
  */
128
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
129
-    getpaid_template()->display_template( $template_name, $args, $template_path, $default_path );
128
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
129
+    getpaid_template()->display_template($template_name, $args, $template_path, $default_path);
130 130
 }
131 131
 
132 132
 /**
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
  * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'.
140 140
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
141 141
  */
142
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
143
-	return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path );
142
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
143
+	return getpaid_template()->get_template($template_name, $args, $template_path, $default_path);
144 144
 }
145 145
 
146 146
 /**
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
  * @return string
150 150
  */
151 151
 function wpinv_template_path() {
152
-    return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() );
152
+    return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name());
153 153
 }
154 154
 
155 155
 /**
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
  * @return string
159 159
  */
160 160
 function wpinv_get_theme_template_dir_name() {
161
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
161
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing'));
162 162
 }
163 163
 
164 164
 /**
@@ -170,58 +170,58 @@  discard block
 block discarded – undo
170 170
  * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'.
171 171
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
172 172
  */
173
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
174
-    return getpaid_template()->locate_template( $template_name, $template_path, $default_path );
173
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
174
+    return getpaid_template()->locate_template($template_name, $template_path, $default_path);
175 175
 }
176 176
 
177
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
178
-	do_action( 'get_template_part_' . $slug, $slug, $name );
177
+function wpinv_get_template_part($slug, $name = null, $load = true) {
178
+	do_action('get_template_part_' . $slug, $slug, $name);
179 179
 
180 180
 	// Setup possible parts
181 181
 	$templates = array();
182
-	if ( isset( $name ) ) {
182
+	if (isset($name)) {
183 183
 		$templates[] = $slug . '-' . $name . '.php';
184 184
     }
185 185
 	$templates[] = $slug . '.php';
186 186
 
187 187
 	// Allow template parts to be filtered
188
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
188
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
189 189
 
190 190
 	// Return the part that is found
191
-	return wpinv_locate_tmpl( $templates, $load, false );
191
+	return wpinv_locate_tmpl($templates, $load, false);
192 192
 }
193 193
 
194
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
194
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
195 195
 	// No file found yet
196 196
 	$located = false;
197 197
 
198 198
 	// Try to find a template file
199
-	foreach ( (array)$template_names as $template_name ) {
199
+	foreach ((array) $template_names as $template_name) {
200 200
 
201 201
 		// Continue if template is empty
202
-		if ( empty( $template_name ) ) {
202
+		if (empty($template_name)) {
203 203
 			continue;
204 204
         }
205 205
 
206 206
 		// Trim off any slashes from the template name
207
-		$template_name = ltrim( $template_name, '/' );
207
+		$template_name = ltrim($template_name, '/');
208 208
 
209 209
 		// try locating this template file by looping through the template paths
210
-		foreach ( wpinv_get_theme_template_paths() as $template_path ) {
210
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
211 211
 
212
-			if ( file_exists( $template_path . $template_name ) ) {
212
+			if (file_exists($template_path . $template_name)) {
213 213
 				$located = $template_path . $template_name;
214 214
 				break;
215 215
 			}
216 216
 		}
217 217
 
218
-		if ( ! empty( $located ) ) {
218
+		if (!empty($located)) {
219 219
 			break;
220 220
 		}
221 221
 	}
222 222
 
223
-	if ( ( true == $load ) && ! empty( $located ) ) {
224
-		load_template( $located, $require_once );
223
+	if ((true == $load) && !empty($located)) {
224
+		load_template($located, $require_once);
225 225
     }
226 226
 
227 227
 	return $located;
@@ -231,73 +231,73 @@  discard block
 block discarded – undo
231 231
 	$template_dir = wpinv_get_theme_template_dir_name();
232 232
 
233 233
 	$file_paths = array(
234
-		1   => trailingslashit( get_stylesheet_directory() ) . $template_dir,
235
-		10  => trailingslashit( get_template_directory() ) . $template_dir,
234
+		1   => trailingslashit(get_stylesheet_directory()) . $template_dir,
235
+		10  => trailingslashit(get_template_directory()) . $template_dir,
236 236
 		100 => wpinv_get_templates_dir(),
237 237
 	);
238 238
 
239
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
239
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
240 240
 
241 241
 	// sort the file paths based on priority
242
-	ksort( $file_paths, SORT_NUMERIC );
242
+	ksort($file_paths, SORT_NUMERIC);
243 243
 
244
-	return array_map( 'trailingslashit', $file_paths );
244
+	return array_map('trailingslashit', $file_paths);
245 245
 }
246 246
 
247 247
 function wpinv_checkout_meta_tags() {
248 248
 
249 249
 	$pages   = array();
250
-	$pages[] = wpinv_get_option( 'success_page' );
251
-	$pages[] = wpinv_get_option( 'failure_page' );
252
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
253
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
250
+	$pages[] = wpinv_get_option('success_page');
251
+	$pages[] = wpinv_get_option('failure_page');
252
+	$pages[] = wpinv_get_option('invoice_history_page');
253
+	$pages[] = wpinv_get_option('invoice_subscription_page');
254 254
 
255
-	if ( ! wpinv_is_checkout() && ! is_page( $pages ) ) {
255
+	if (!wpinv_is_checkout() && !is_page($pages)) {
256 256
 		return;
257 257
 	}
258 258
 
259 259
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
260 260
 }
261
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
261
+add_action('wp_head', 'wpinv_checkout_meta_tags');
262 262
 
263
-function wpinv_add_body_classes( $class ) {
264
-	$classes = (array)$class;
263
+function wpinv_add_body_classes($class) {
264
+	$classes = (array) $class;
265 265
 
266
-	if ( wpinv_is_checkout() ) {
266
+	if (wpinv_is_checkout()) {
267 267
 		$classes[] = 'wpinv-checkout';
268 268
 		$classes[] = 'wpinv-page';
269 269
 	}
270 270
 
271
-	if ( wpinv_is_success_page() ) {
271
+	if (wpinv_is_success_page()) {
272 272
 		$classes[] = 'wpinv-success';
273 273
 		$classes[] = 'wpinv-page';
274 274
 	}
275 275
 
276
-	if ( wpinv_is_failed_transaction_page() ) {
276
+	if (wpinv_is_failed_transaction_page()) {
277 277
 		$classes[] = 'wpinv-failed-transaction';
278 278
 		$classes[] = 'wpinv-page';
279 279
 	}
280 280
 
281
-	if ( wpinv_is_invoice_history_page() ) {
281
+	if (wpinv_is_invoice_history_page()) {
282 282
 		$classes[] = 'wpinv-history';
283 283
 		$classes[] = 'wpinv-page';
284 284
 	}
285 285
 
286
-	if ( wpinv_is_subscriptions_history_page() ) {
286
+	if (wpinv_is_subscriptions_history_page()) {
287 287
 		$classes[] = 'wpinv-subscription';
288 288
 		$classes[] = 'wpinv-page';
289 289
 	}
290 290
 
291
-	if ( wpinv_is_test_mode() ) {
291
+	if (wpinv_is_test_mode()) {
292 292
 		$classes[] = 'wpinv-test-mode';
293 293
 		$classes[] = 'wpinv-page';
294 294
 	}
295 295
 
296
-	return array_unique( $classes );
296
+	return array_unique($classes);
297 297
 }
298
-add_filter( 'body_class', 'wpinv_add_body_classes' );
298
+add_filter('body_class', 'wpinv_add_body_classes');
299 299
 
300
-function wpinv_html_select( $args = array() ) {
300
+function wpinv_html_select($args = array()) {
301 301
     $defaults = array(
302 302
         'options'          => array(),
303 303
         'name'             => null,
@@ -306,8 +306,8 @@  discard block
 block discarded – undo
306 306
         'selected'         => 0,
307 307
         'placeholder'      => null,
308 308
         'multiple'         => false,
309
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
310
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
309
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
310
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
311 311
         'data'             => array(),
312 312
         'onchange'         => null,
313 313
         'required'         => false,
@@ -315,79 +315,79 @@  discard block
 block discarded – undo
315 315
         'readonly'         => false,
316 316
     );
317 317
 
318
-    $args = wp_parse_args( $args, $defaults );
318
+    $args = wp_parse_args($args, $defaults);
319 319
 
320 320
     $attrs = array(
321 321
         'name'     => $args['name'],
322 322
         'id'       => $args['id'],
323
-        'class'    => 'wpinv-select ' . implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ),
324
-        'multiple' => ! empty( $args['multiple'] ),
325
-        'readonly' => ! empty( $args['readonly'] ),
326
-        'disabled' => ! empty( $args['disabled'] ),
327
-        'required' => ! empty( $args['required'] ),
328
-        'onchange' => ! empty( $args['onchange'] ),
323
+        'class'    => 'wpinv-select ' . implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))),
324
+        'multiple' => !empty($args['multiple']),
325
+        'readonly' => !empty($args['readonly']),
326
+        'disabled' => !empty($args['disabled']),
327
+        'required' => !empty($args['required']),
328
+        'onchange' => !empty($args['onchange']),
329 329
     );
330 330
 
331
-    if ( $args['placeholder'] ) {
331
+    if ($args['placeholder']) {
332 332
         $attrs['data-placeholder'] = $args['placeholder'];
333 333
     }
334 334
 
335
-    if ( $args['onchange'] ) {
335
+    if ($args['onchange']) {
336 336
         $attrs['onchange'] = $args['onchange'];
337 337
     }
338 338
 
339
-    foreach ( $args['data'] as $key => $value ) {
339
+    foreach ($args['data'] as $key => $value) {
340 340
         $attrs["data-$key"] = $value;
341 341
     }
342 342
 
343 343
     echo '<select ';
344 344
 
345
-    foreach ( $attrs as $attr => $value ) {
345
+    foreach ($attrs as $attr => $value) {
346 346
 
347
-        if ( false === $value ) {
347
+        if (false === $value) {
348 348
             continue;
349 349
         }
350 350
 
351
-        if ( true === $value ) {
352
-            echo ' ' . esc_attr( $attr );
351
+        if (true === $value) {
352
+            echo ' ' . esc_attr($attr);
353 353
         } else {
354
-            echo ' ' . esc_attr( $attr ) . '="' . esc_attr( $value ) . '"';
354
+            echo ' ' . esc_attr($attr) . '="' . esc_attr($value) . '"';
355 355
         }
356 356
 
357 357
     }
358 358
 
359 359
     echo '>';
360 360
 
361
-    if ( $args['show_option_all'] ) {
362
-        if ( $args['multiple'] ) {
363
-            $selected = in_array( 0, $args['selected'] );
361
+    if ($args['show_option_all']) {
362
+        if ($args['multiple']) {
363
+            $selected = in_array(0, $args['selected']);
364 364
         } else {
365
-            $selected = empty( $args['selected'] );
365
+            $selected = empty($args['selected']);
366 366
         }
367
-        echo '<option value="all"' . selected( $selected, true, false ) . '>' . esc_html( $args['show_option_all'] ) . '</option>';
367
+        echo '<option value="all"' . selected($selected, true, false) . '>' . esc_html($args['show_option_all']) . '</option>';
368 368
     }
369 369
 
370
-    if ( ! empty( $args['options'] ) ) {
370
+    if (!empty($args['options'])) {
371 371
 
372
-        if ( $args['show_option_none'] ) {
373
-            if ( $args['multiple'] ) {
374
-                $selected = in_array( '', $args['selected'], true );
372
+        if ($args['show_option_none']) {
373
+            if ($args['multiple']) {
374
+                $selected = in_array('', $args['selected'], true);
375 375
             } else {
376 376
                 $selected = $args['selected'] === '';
377 377
             }
378 378
 
379
-            echo '<option value=""' . selected( $selected, true, false ) . '>' . esc_html( $args['show_option_none'] ) . '</option>';
379
+            echo '<option value=""' . selected($selected, true, false) . '>' . esc_html($args['show_option_none']) . '</option>';
380 380
         }
381 381
 
382
-        foreach ( $args['options'] as $key => $option ) {
382
+        foreach ($args['options'] as $key => $option) {
383 383
 
384
-            if ( $args['multiple'] && is_array( $args['selected'] ) ) {
385
-                $selected = in_array( $key, $args['selected'], true );
384
+            if ($args['multiple'] && is_array($args['selected'])) {
385
+                $selected = in_array($key, $args['selected'], true);
386 386
             } else {
387 387
                 $selected = $args['selected'] === $key;
388 388
             }
389 389
 
390
-            echo '<option value="' . esc_attr( $key ) . '"' . selected( $selected, true, false ) . '>' . esc_html( $option ) . '</option>';
390
+            echo '<option value="' . esc_attr($key) . '"' . selected($selected, true, false) . '>' . esc_html($option) . '</option>';
391 391
         }
392 392
     }
393 393
 
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
 
396 396
 }
397 397
 
398
-function wpinv_item_dropdown( $args = array() ) {
398
+function wpinv_item_dropdown($args = array()) {
399 399
     $defaults = array(
400 400
         'name'             => 'wpi_item',
401 401
         'id'               => 'wpi_item',
@@ -403,14 +403,14 @@  discard block
 block discarded – undo
403 403
         'multiple'         => false,
404 404
         'selected'         => 0,
405 405
         'number'           => -1,
406
-        'placeholder'      => __( 'Choose a item', 'invoicing' ),
407
-        'data'             => array( 'search-type' => 'item' ),
406
+        'placeholder'      => __('Choose a item', 'invoicing'),
407
+        'data'             => array('search-type' => 'item'),
408 408
         'show_option_all'  => false,
409 409
         'show_option_none' => false,
410 410
         'show_recurring'   => false,
411 411
     );
412 412
 
413
-    $args = wp_parse_args( $args, $defaults );
413
+    $args = wp_parse_args($args, $defaults);
414 414
 
415 415
     $item_args = array(
416 416
         'post_type'      => 'wpi_item',
@@ -428,40 +428,40 @@  discard block
 block discarded – undo
428 428
         ),
429 429
     );
430 430
 
431
-    $item_args  = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults );
431
+    $item_args  = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults);
432 432
 
433
-    $items      = get_posts( $item_args );
433
+    $items      = get_posts($item_args);
434 434
     $options    = array();
435
-    if ( $items ) {
436
-        foreach ( $items as $item ) {
437
-            $title = esc_html( $item->post_title );
435
+    if ($items) {
436
+        foreach ($items as $item) {
437
+            $title = esc_html($item->post_title);
438 438
 
439
-            if ( ! empty( $args['show_recurring'] ) ) {
440
-                $title .= wpinv_get_item_suffix( $item->ID, false );
439
+            if (!empty($args['show_recurring'])) {
440
+                $title .= wpinv_get_item_suffix($item->ID, false);
441 441
             }
442 442
 
443
-            $options[ absint( $item->ID ) ] = $title;
443
+            $options[absint($item->ID)] = $title;
444 444
         }
445 445
     }
446 446
 
447 447
     // This ensures that any selected items are included in the drop down
448
-    if ( is_array( $args['selected'] ) ) {
449
-        foreach ( $args['selected'] as $item ) {
450
-            if ( ! in_array( $item, $options ) ) {
451
-                $title = get_the_title( $item );
452
-                if ( ! empty( $args['show_recurring'] ) ) {
453
-                    $title .= wpinv_get_item_suffix( $item, false );
448
+    if (is_array($args['selected'])) {
449
+        foreach ($args['selected'] as $item) {
450
+            if (!in_array($item, $options)) {
451
+                $title = get_the_title($item);
452
+                if (!empty($args['show_recurring'])) {
453
+                    $title .= wpinv_get_item_suffix($item, false);
454 454
                 }
455
-                $options[ $item ] = $title;
455
+                $options[$item] = $title;
456 456
             }
457 457
         }
458
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
459
-        if ( ! in_array( $args['selected'], $options ) ) {
460
-            $title = get_the_title( $args['selected'] );
461
-            if ( ! empty( $args['show_recurring'] ) ) {
462
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
458
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
459
+        if (!in_array($args['selected'], $options)) {
460
+            $title = get_the_title($args['selected']);
461
+            if (!empty($args['show_recurring'])) {
462
+                $title .= wpinv_get_item_suffix($args['selected'], false);
463 463
             }
464
-            $options[ $args['selected'] ] = get_the_title( $args['selected'] );
464
+            $options[$args['selected']] = get_the_title($args['selected']);
465 465
         }
466 466
     }
467 467
 
@@ -497,16 +497,16 @@  discard block
 block discarded – undo
497 497
     );
498 498
 
499 499
     $options = array();
500
-    if ( $items ) {
501
-        foreach ( $items as $item ) {
502
-            $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false );
500
+    if ($items) {
501
+        foreach ($items as $item) {
502
+            $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false);
503 503
         }
504 504
     }
505 505
 
506 506
     return $options;
507 507
 }
508 508
 
509
-function wpinv_html_checkbox( $args = array() ) {
509
+function wpinv_html_checkbox($args = array()) {
510 510
     $defaults = array(
511 511
         'name'    => null,
512 512
         'current' => null,
@@ -517,17 +517,17 @@  discard block
 block discarded – undo
517 517
         ),
518 518
     );
519 519
 
520
-    $args = wp_parse_args( $args, $defaults );
520
+    $args = wp_parse_args($args, $defaults);
521 521
 
522
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
522
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
523 523
     $attr  = '';
524
-    if ( ! empty( $args['options']['disabled'] ) ) {
524
+    if (!empty($args['options']['disabled'])) {
525 525
         $attr .= ' disabled="disabled"';
526
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
526
+    } elseif (!empty($args['options']['readonly'])) {
527 527
         $attr .= ' readonly';
528 528
     }
529 529
 
530
-    $output = '<input type="checkbox"' . $attr . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . esc_attr( $class ) . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
530
+    $output = '<input type="checkbox"' . $attr . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . esc_attr($class) . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />';
531 531
 
532 532
     return $output;
533 533
 }
@@ -535,34 +535,34 @@  discard block
 block discarded – undo
535 535
 /**
536 536
  * Displays a hidden field.
537 537
  */
538
-function getpaid_hidden_field( $name, $value ) {
539
-    echo "<input type='hidden' name='" . esc_attr( $name ) . "' value='" . esc_attr( $value ) . "' />";
538
+function getpaid_hidden_field($name, $value) {
539
+    echo "<input type='hidden' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' />";
540 540
 }
541 541
 
542 542
 /**
543 543
  * Displays a submit field.
544 544
  */
545
-function getpaid_submit_field( $value, $name = 'submit', $class = 'btn-primary' ) {
546
-    echo "<input type='submit' name='" . esc_attr( $name ) . "' value='" . esc_attr( $value ) . "' class='btn " . esc_attr( $class ) . "' />";
545
+function getpaid_submit_field($value, $name = 'submit', $class = 'btn-primary') {
546
+    echo "<input type='submit' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' class='btn " . esc_attr($class) . "' />";
547 547
 }
548 548
 
549
-function wpinv_html_text( $args = array() ) {
549
+function wpinv_html_text($args = array()) {
550 550
     // Backwards compatibility
551
-    if ( func_num_args() > 1 ) {
551
+    if (func_num_args() > 1) {
552 552
         $args = func_get_args();
553 553
 
554 554
         $name  = $args[0];
555
-        $value = isset( $args[1] ) ? $args[1] : '';
556
-        $label = isset( $args[2] ) ? $args[2] : '';
557
-        $desc  = isset( $args[3] ) ? $args[3] : '';
555
+        $value = isset($args[1]) ? $args[1] : '';
556
+        $label = isset($args[2]) ? $args[2] : '';
557
+        $desc  = isset($args[3]) ? $args[3] : '';
558 558
     }
559 559
 
560 560
     $defaults = array(
561 561
         'id'           => '',
562
-        'name'         => isset( $name ) ? $name : 'text',
563
-        'value'        => isset( $value ) ? $value : null,
564
-        'label'        => isset( $label ) ? $label : null,
565
-        'desc'         => isset( $desc ) ? $desc : null,
562
+        'name'         => isset($name) ? $name : 'text',
563
+        'value'        => isset($value) ? $value : null,
564
+        'label'        => isset($label) ? $label : null,
565
+        'desc'         => isset($desc) ? $desc : null,
566 566
         'placeholder'  => '',
567 567
         'class'        => 'regular-text',
568 568
         'disabled'     => false,
@@ -572,41 +572,41 @@  discard block
 block discarded – undo
572 572
         'data'         => false,
573 573
     );
574 574
 
575
-    $args = wp_parse_args( $args, $defaults );
575
+    $args = wp_parse_args($args, $defaults);
576 576
 
577
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
577
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
578 578
     $options = '';
579
-    if ( $args['required'] ) {
579
+    if ($args['required']) {
580 580
         $options .= ' required="required"';
581 581
     }
582
-    if ( $args['readonly'] ) {
582
+    if ($args['readonly']) {
583 583
         $options .= ' readonly';
584 584
     }
585
-    if ( $args['readonly'] ) {
585
+    if ($args['readonly']) {
586 586
         $options .= ' readonly';
587 587
     }
588 588
 
589 589
     $data = '';
590
-    if ( ! empty( $args['data'] ) ) {
591
-        foreach ( $args['data'] as $key => $value ) {
592
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
590
+    if (!empty($args['data'])) {
591
+        foreach ($args['data'] as $key => $value) {
592
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
593 593
         }
594 594
     }
595 595
 
596
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
597
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
598
-    if ( ! empty( $args['desc'] ) ) {
599
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
596
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
597
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
598
+    if (!empty($args['desc'])) {
599
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
600 600
     }
601 601
 
602
-    $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>';
602
+    $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>';
603 603
 
604 604
     $output .= '</span>';
605 605
 
606 606
     return $output;
607 607
 }
608 608
 
609
-function wpinv_html_textarea( $args = array() ) {
609
+function wpinv_html_textarea($args = array()) {
610 610
     $defaults = array(
611 611
         'name'        => 'textarea',
612 612
         'value'       => null,
@@ -617,31 +617,31 @@  discard block
 block discarded – undo
617 617
         'placeholder' => '',
618 618
     );
619 619
 
620
-    $args = wp_parse_args( $args, $defaults );
620
+    $args = wp_parse_args($args, $defaults);
621 621
 
622
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
622
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
623 623
     $disabled = '';
624
-    if ( $args['disabled'] ) {
624
+    if ($args['disabled']) {
625 625
         $disabled = ' disabled="disabled"';
626 626
     }
627 627
 
628
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
629
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
630
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
628
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
629
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
630
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
631 631
 
632
-    if ( ! empty( $args['desc'] ) ) {
633
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
632
+    if (!empty($args['desc'])) {
633
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
634 634
     }
635 635
     $output .= '</span>';
636 636
 
637 637
     return $output;
638 638
 }
639 639
 
640
-function wpinv_html_ajax_user_search( $args = array() ) {
640
+function wpinv_html_ajax_user_search($args = array()) {
641 641
     $defaults = array(
642 642
         'name'         => 'user_id',
643 643
         'value'        => null,
644
-        'placeholder'  => __( 'Enter username', 'invoicing' ),
644
+        'placeholder'  => __('Enter username', 'invoicing'),
645 645
         'label'        => null,
646 646
         'desc'         => null,
647 647
         'class'        => '',
@@ -650,13 +650,13 @@  discard block
 block discarded – undo
650 650
         'data'         => false,
651 651
     );
652 652
 
653
-    $args = wp_parse_args( $args, $defaults );
653
+    $args = wp_parse_args($args, $defaults);
654 654
 
655 655
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
656 656
 
657 657
     $output  = '<span class="wpinv_user_search_wrap">';
658
-        $output .= wpinv_html_text( $args );
659
-        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>';
658
+        $output .= wpinv_html_text($args);
659
+        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>';
660 660
     $output .= '</span>';
661 661
 
662 662
     return $output;
@@ -667,44 +667,44 @@  discard block
 block discarded – undo
667 667
  *
668 668
  * @param string $template the template that is currently being used.
669 669
  */
670
-function wpinv_template( $template ) {
670
+function wpinv_template($template) {
671 671
     global $post;
672 672
 
673
-    if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) {
673
+    if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) {
674 674
 
675 675
         // If the user can view this invoice, display it.
676
-        if ( wpinv_user_can_view_invoice( $post->ID ) ) {
676
+        if (wpinv_user_can_view_invoice($post->ID)) {
677 677
 
678
-            return wpinv_get_template_part( 'wpinv-invoice-print', false, false );
678
+            return wpinv_get_template_part('wpinv-invoice-print', false, false);
679 679
 
680 680
         // Else display an error message.
681 681
         } else {
682 682
 
683
-            return wpinv_get_template_part( 'wpinv-invalid-access', false, false );
683
+            return wpinv_get_template_part('wpinv-invalid-access', false, false);
684 684
 
685 685
         }
686 686
 }
687 687
 
688 688
     return $template;
689 689
 }
690
-add_filter( 'template_include', 'wpinv_template', 1000, 1 );
690
+add_filter('template_include', 'wpinv_template', 1000, 1);
691 691
 
692 692
 function wpinv_get_business_address() {
693 693
     $business_address   = wpinv_store_address();
694
-    $business_address   = ! empty( $business_address ) ? wp_kses_post( wpautop( $business_address ) ) : '';
694
+    $business_address   = !empty($business_address) ? wp_kses_post(wpautop($business_address)) : '';
695 695
 
696 696
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
697 697
 
698
-    return apply_filters( 'wpinv_get_business_address', $business_address );
698
+    return apply_filters('wpinv_get_business_address', $business_address);
699 699
 }
700 700
 
701 701
 /**
702 702
  * Displays the company address.
703 703
  */
704 704
 function wpinv_display_from_address() {
705
-    wpinv_get_template( 'invoice/company-address.php' );
705
+    wpinv_get_template('invoice/company-address.php');
706 706
 }
707
-add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 );
707
+add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10);
708 708
 
709 709
 /**
710 710
  * Generates a watermark text for an invoice.
@@ -712,9 +712,9 @@  discard block
 block discarded – undo
712 712
  * @param WPInv_Invoice $invoice
713 713
  * @return string
714 714
  */
715
-function wpinv_watermark( $invoice ) {
716
-    $watermark = wpinv_get_watermark( $invoice );
717
-    return apply_filters( 'wpinv_get_watermark', $watermark, $invoice );
715
+function wpinv_watermark($invoice) {
716
+    $watermark = wpinv_get_watermark($invoice);
717
+    return apply_filters('wpinv_get_watermark', $watermark, $invoice);
718 718
 }
719 719
 
720 720
 /**
@@ -723,37 +723,37 @@  discard block
 block discarded – undo
723 723
  * @param WPInv_Invoice $invoice
724 724
  * @return string
725 725
  */
726
-function wpinv_get_watermark( $invoice ) {
726
+function wpinv_get_watermark($invoice) {
727 727
     return $invoice->get_status_nicename();
728 728
 }
729 729
 
730 730
 /**
731 731
  * @deprecated
732 732
  */
733
-function wpinv_display_invoice_details( $invoice ) {
734
-    return getpaid_invoice_meta( $invoice );
733
+function wpinv_display_invoice_details($invoice) {
734
+    return getpaid_invoice_meta($invoice);
735 735
 }
736 736
 
737 737
 /**
738 738
  * Displays invoice meta.
739 739
  */
740
-function getpaid_invoice_meta( $invoice ) {
740
+function getpaid_invoice_meta($invoice) {
741 741
 
742
-    $invoice = new WPInv_Invoice( $invoice );
742
+    $invoice = new WPInv_Invoice($invoice);
743 743
 
744 744
     // Ensure that we have an invoice.
745
-    if ( 0 == $invoice->get_id() ) {
745
+    if (0 == $invoice->get_id()) {
746 746
         return;
747 747
     }
748 748
 
749 749
     // Get the invoice meta.
750
-    $meta = getpaid_get_invoice_meta( $invoice );
750
+    $meta = getpaid_get_invoice_meta($invoice);
751 751
 
752 752
     // Display the meta.
753
-    wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) );
753
+    wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta'));
754 754
 
755 755
 }
756
-add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 );
756
+add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10);
757 757
 
758 758
 /**
759 759
  * Retrieves the address markup to use on Invoices.
@@ -765,29 +765,29 @@  discard block
 block discarded – undo
765 765
  * @param  string $separator How to separate address lines.
766 766
  * @return string
767 767
  */
768
-function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) {
768
+function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') {
769 769
 
770 770
     // Retrieve the address markup...
771
-    $country = empty( $billing_details['country'] ) ? '' : $billing_details['country'];
772
-    $format = wpinv_get_full_address_format( $country );
771
+    $country = empty($billing_details['country']) ? '' : $billing_details['country'];
772
+    $format = wpinv_get_full_address_format($country);
773 773
 
774 774
     // ... and the replacements.
775
-    $replacements = wpinv_get_invoice_address_replacements( $billing_details );
775
+    $replacements = wpinv_get_invoice_address_replacements($billing_details);
776 776
 
777
-    $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format );
777
+    $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format);
778 778
 
779 779
 	// Remove unavailable tags.
780
-    $formatted_address = preg_replace( '/\{\{\w+\}\}/', '', $formatted_address );
780
+    $formatted_address = preg_replace('/\{\{\w+\}\}/', '', $formatted_address);
781 781
 
782 782
     // Clean up white space.
783
-	$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
784
-    $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
783
+	$formatted_address = preg_replace('/  +/', ' ', trim($formatted_address));
784
+    $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address);
785 785
 
786 786
     // Break newlines apart and remove empty lines/trim commas and white space.
787
-	$formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
787
+	$formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address)));
788 788
 
789 789
     // Add html breaks.
790
-	$formatted_address = implode( $separator, $formatted_address );
790
+	$formatted_address = implode($separator, $formatted_address);
791 791
 
792 792
 	// We're done!
793 793
 	return $formatted_address;
@@ -799,118 +799,118 @@  discard block
 block discarded – undo
799 799
  *
800 800
  * @param WPInv_Invoice $invoice
801 801
  */
802
-function wpinv_display_to_address( $invoice = 0 ) {
803
-    if ( ! empty( $invoice ) ) {
804
-        wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) );
802
+function wpinv_display_to_address($invoice = 0) {
803
+    if (!empty($invoice)) {
804
+        wpinv_get_template('invoice/billing-address.php', compact('invoice'));
805 805
     }
806 806
 }
807
-add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 );
807
+add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40);
808 808
 
809 809
 
810 810
 /**
811 811
  * Displays invoice line items.
812 812
  */
813
-function wpinv_display_line_items( $invoice_id = 0 ) {
813
+function wpinv_display_line_items($invoice_id = 0) {
814 814
 
815 815
     // Prepare the invoice.
816
-    $invoice = new WPInv_Invoice( $invoice_id );
816
+    $invoice = new WPInv_Invoice($invoice_id);
817 817
 
818 818
     // Abort if there is no invoice.
819
-    if ( 0 == $invoice->get_id() ) {
819
+    if (0 == $invoice->get_id()) {
820 820
         return;
821 821
     }
822 822
 
823 823
     // Line item columns.
824
-    $columns = getpaid_invoice_item_columns( $invoice );
825
-    $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice );
824
+    $columns = getpaid_invoice_item_columns($invoice);
825
+    $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice);
826 826
 
827
-    wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) );
827
+    wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns'));
828 828
 }
829
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 );
829
+add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10);
830 830
 
831 831
 /**
832 832
  * Displays invoice subscriptions.
833 833
  *
834 834
  * @param WPInv_Invoice $invoice
835 835
  */
836
-function getpaid_display_invoice_subscriptions( $invoice ) {
836
+function getpaid_display_invoice_subscriptions($invoice) {
837 837
 
838 838
     // Subscriptions.
839
-	$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
839
+	$subscriptions = getpaid_get_invoice_subscriptions($invoice);
840 840
 
841
-    if ( empty( $subscriptions ) || ! $invoice->is_recurring() ) {
841
+    if (empty($subscriptions) || !$invoice->is_recurring()) {
842 842
         return;
843 843
     }
844 844
 
845
-    $main_subscription = getpaid_get_invoice_subscription( $invoice );
845
+    $main_subscription = getpaid_get_invoice_subscription($invoice);
846 846
 
847 847
     // Display related subscriptions.
848
-    if ( is_array( $subscriptions ) ) {
849
-        printf( '<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__( 'Related Subscriptions', 'invoicing' ) );
850
-        getpaid_admin_subscription_related_subscriptions_metabox( $main_subscription, false );
848
+    if (is_array($subscriptions)) {
849
+        printf('<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__('Related Subscriptions', 'invoicing'));
850
+        getpaid_admin_subscription_related_subscriptions_metabox($main_subscription, false);
851 851
     }
852 852
 
853
-    if ( $main_subscription->get_total_payments() > 1 ) {
854
-        printf( '<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__( 'Related Invoices', 'invoicing' ) );
855
-        getpaid_admin_subscription_invoice_details_metabox( $main_subscription, false );
853
+    if ($main_subscription->get_total_payments() > 1) {
854
+        printf('<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__('Related Invoices', 'invoicing'));
855
+        getpaid_admin_subscription_invoice_details_metabox($main_subscription, false);
856 856
     }
857 857
 
858 858
 }
859
-add_action( 'getpaid_invoice_line_items', 'getpaid_display_invoice_subscriptions', 55 );
860
-add_action( 'wpinv_receipt_end', 'getpaid_display_invoice_subscriptions', 11 );
859
+add_action('getpaid_invoice_line_items', 'getpaid_display_invoice_subscriptions', 55);
860
+add_action('wpinv_receipt_end', 'getpaid_display_invoice_subscriptions', 11);
861 861
 
862 862
 /**
863 863
  * Displays invoice notices on invoices.
864 864
  */
865 865
 function wpinv_display_invoice_notice() {
866 866
 
867
-    $label  = wpinv_get_option( 'vat_invoice_notice_label' );
868
-    $notice = wpinv_get_option( 'vat_invoice_notice' );
867
+    $label  = wpinv_get_option('vat_invoice_notice_label');
868
+    $notice = wpinv_get_option('vat_invoice_notice');
869 869
 
870
-    if ( empty( $label ) && empty( $notice ) ) {
870
+    if (empty($label) && empty($notice)) {
871 871
         return;
872 872
     }
873 873
 
874 874
     echo '<div class="mt-4 mb-4 wpinv-vat-notice">';
875 875
 
876
-    if ( ! empty( $label ) ) {
877
-        echo "<h5>" . esc_html( $label ) . "</h5>";
876
+    if (!empty($label)) {
877
+        echo "<h5>" . esc_html($label) . "</h5>";
878 878
     }
879 879
 
880
-    if ( ! empty( $notice ) ) {
881
-        echo '<small class="form-text text-muted">' . wp_kses_post( wpautop( wptexturize( $notice ) ) ) . '</small>';
880
+    if (!empty($notice)) {
881
+        echo '<small class="form-text text-muted">' . wp_kses_post(wpautop(wptexturize($notice))) . '</small>';
882 882
     }
883 883
 
884 884
     echo '</div>';
885 885
 }
886
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 );
886
+add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100);
887 887
 
888 888
 /**
889 889
  * @param WPInv_Invoice $invoice
890 890
  */
891
-function wpinv_display_invoice_notes( $invoice ) {
891
+function wpinv_display_invoice_notes($invoice) {
892 892
 
893 893
     // Retrieve the notes.
894
-    $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' );
894
+    $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer');
895 895
 
896 896
     // Abort if we have non.
897
-    if ( empty( $notes ) ) {
897
+    if (empty($notes)) {
898 898
         return;
899 899
     }
900 900
 
901 901
     // Echo the note.
902 902
     echo '<div class="getpaid-invoice-notes-wrapper position-relative my-4">';
903
-    echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . esc_html__( 'Notes', 'invoicing' ) . '</h2>';
903
+    echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . esc_html__('Notes', 'invoicing') . '</h2>';
904 904
     echo '<ul class="getpaid-invoice-notes text-break overflow-auto list-unstyled p-0 m-0">';
905 905
 
906
-    foreach ( $notes as $note ) {
907
-        wpinv_get_invoice_note_line_item( $note );
906
+    foreach ($notes as $note) {
907
+        wpinv_get_invoice_note_line_item($note);
908 908
     }
909 909
 
910 910
     echo '</ul>';
911 911
     echo '</div>';
912 912
 }
913
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 );
913
+add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60);
914 914
 
915 915
 /**
916 916
  * Loads scripts on our invoice templates.
@@ -918,37 +918,37 @@  discard block
 block discarded – undo
918 918
 function wpinv_display_style() {
919 919
 
920 920
     // Make sure that all scripts have been loaded.
921
-    if ( ! did_action( 'wp_enqueue_scripts' ) ) {
922
-        do_action( 'wp_enqueue_scripts' );
921
+    if (!did_action('wp_enqueue_scripts')) {
922
+        do_action('wp_enqueue_scripts');
923 923
     }
924 924
 
925 925
     // Add global styles.
926
-    if ( wp_is_block_theme() ) {
927
-        wp_print_styles( 'global-styles' );
926
+    if (wp_is_block_theme()) {
927
+        wp_print_styles('global-styles');
928 928
     }
929 929
 
930 930
     // Register the invoices style.
931
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) );
931
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css'));
932 932
 
933 933
     // Load required styles
934
-    wp_print_styles( 'wpinv-single-style' );
935
-    wp_print_styles( 'ayecode-ui' );
934
+    wp_print_styles('wpinv-single-style');
935
+    wp_print_styles('ayecode-ui');
936 936
 
937 937
     // Maybe load custom css.
938
-    $custom_css = wpinv_get_option( 'template_custom_css' );
938
+    $custom_css = wpinv_get_option('template_custom_css');
939 939
 
940
-    if ( isset( $custom_css ) && ! empty( $custom_css ) ) {
941
-        $custom_css     = wp_kses( $custom_css, array( '\'', '\"' ) );
942
-        $custom_css     = str_replace( '&gt;', '>', $custom_css );
940
+    if (isset($custom_css) && !empty($custom_css)) {
941
+        $custom_css     = wp_kses($custom_css, array('\'', '\"'));
942
+        $custom_css     = str_replace('&gt;', '>', $custom_css);
943 943
         echo '<style type="text/css">';
944
-        echo wp_kses_post( $custom_css );
944
+        echo wp_kses_post($custom_css);
945 945
         echo '</style>';
946 946
     }
947 947
 
948 948
     wp_site_icon();
949 949
 }
950
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
951
-add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' );
950
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
951
+add_action('wpinv_invalid_invoice_head', 'wpinv_display_style');
952 952
 
953 953
 
954 954
 /**
@@ -960,41 +960,41 @@  discard block
 block discarded – undo
960 960
     // Retrieve the current invoice.
961 961
     $invoice_id = getpaid_get_current_invoice_id();
962 962
 
963
-    if ( empty( $invoice_id ) ) {
963
+    if (empty($invoice_id)) {
964 964
 
965 965
         return aui()->alert(
966 966
             array(
967 967
                 'type'    => 'warning',
968
-                'content' => __( 'Invalid invoice', 'invoicing' ),
968
+                'content' => __('Invalid invoice', 'invoicing'),
969 969
             )
970 970
         );
971 971
 
972 972
     }
973 973
 
974 974
     // Can the user view this invoice?
975
-    if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) {
975
+    if (!wpinv_user_can_view_invoice($invoice_id)) {
976 976
 
977 977
         return aui()->alert(
978 978
             array(
979 979
                 'type'    => 'warning',
980
-                'content' => __( 'You are not allowed to view this invoice', 'invoicing' ),
980
+                'content' => __('You are not allowed to view this invoice', 'invoicing'),
981 981
             )
982 982
         );
983 983
 
984 984
     }
985 985
 
986 986
     // Ensure that it is not yet paid for.
987
-    $invoice = new WPInv_Invoice( $invoice_id );
987
+    $invoice = new WPInv_Invoice($invoice_id);
988 988
 
989 989
     // Maybe mark it as viewed.
990
-    getpaid_maybe_mark_invoice_as_viewed( $invoice );
990
+    getpaid_maybe_mark_invoice_as_viewed($invoice);
991 991
 
992
-    if ( $invoice->is_paid() ) {
992
+    if ($invoice->is_paid()) {
993 993
 
994 994
         return aui()->alert(
995 995
             array(
996 996
                 'type'    => 'success',
997
-                'content' => __( 'This invoice has already been paid.', 'invoicing' ),
997
+                'content' => __('This invoice has already been paid.', 'invoicing'),
998 998
             )
999 999
         );
1000 1000
 
@@ -1004,15 +1004,15 @@  discard block
 block discarded – undo
1004 1004
     $wpi_checkout_id = $invoice_id;
1005 1005
 
1006 1006
     // Retrieve appropriate payment form.
1007
-    $payment_form = new GetPaid_Payment_Form( wpinv_translate_post_id( $invoice->get_meta( 'force_payment_form' ) ) );
1008
-    $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1007
+    $payment_form = new GetPaid_Payment_Form(wpinv_translate_post_id($invoice->get_meta('force_payment_form')));
1008
+    $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1009 1009
 
1010
-    if ( ! $payment_form->exists() ) {
1010
+    if (!$payment_form->exists()) {
1011 1011
 
1012 1012
         return aui()->alert(
1013 1013
             array(
1014 1014
                 'type'    => 'warning',
1015
-                'content' => __( 'Error loading the payment form', 'invoicing' ),
1015
+                'content' => __('Error loading the payment form', 'invoicing'),
1016 1016
             )
1017 1017
         );
1018 1018
 
@@ -1021,29 +1021,29 @@  discard block
 block discarded – undo
1021 1021
     // Set the invoice.
1022 1022
     $payment_form->invoice = $invoice;
1023 1023
 
1024
-    if ( ! $payment_form->is_default() ) {
1024
+    if (!$payment_form->is_default()) {
1025 1025
 
1026 1026
         $items    = array();
1027 1027
         $item_ids = array();
1028 1028
 
1029
-        foreach ( $invoice->get_items() as $item ) {
1030
-            if ( ! in_array( $item->get_id(), $item_ids ) ) {
1029
+        foreach ($invoice->get_items() as $item) {
1030
+            if (!in_array($item->get_id(), $item_ids)) {
1031 1031
                 $item_ids[] = $item->get_id();
1032 1032
                 $items[]    = $item;
1033 1033
             }
1034 1034
         }
1035 1035
 
1036
-        foreach ( $payment_form->get_items() as $item ) {
1037
-            if ( ! in_array( $item->get_id(), $item_ids ) ) {
1036
+        foreach ($payment_form->get_items() as $item) {
1037
+            if (!in_array($item->get_id(), $item_ids)) {
1038 1038
                 $item_ids[] = $item->get_id();
1039 1039
                 $items[]    = $item;
1040 1040
             }
1041 1041
         }
1042 1042
 
1043
-        $payment_form->set_items( $items );
1043
+        $payment_form->set_items($items);
1044 1044
 
1045 1045
     } else {
1046
-        $payment_form->set_items( $invoice->get_items() );
1046
+        $payment_form->set_items($invoice->get_items());
1047 1047
     }
1048 1048
 
1049 1049
     // Generate the html.
@@ -1052,7 +1052,7 @@  discard block
 block discarded – undo
1052 1052
 }
1053 1053
 
1054 1054
 function wpinv_empty_cart_message() {
1055
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1055
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1056 1056
 }
1057 1057
 
1058 1058
 /**
@@ -1070,76 +1070,76 @@  discard block
 block discarded – undo
1070 1070
         true
1071 1071
     );
1072 1072
 }
1073
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1073
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1074 1074
 
1075 1075
 /**
1076 1076
  * Filters the receipt page.
1077 1077
  */
1078
-function wpinv_filter_success_page_content( $content ) {
1078
+function wpinv_filter_success_page_content($content) {
1079 1079
 
1080 1080
     // Maybe abort early.
1081
-    if ( is_admin() || ! is_singular() || ! in_the_loop() || ! is_main_query() || is_preview() ) {
1081
+    if (is_admin() || !is_singular() || !in_the_loop() || !is_main_query() || is_preview()) {
1082 1082
         return $content;
1083 1083
     }
1084 1084
 
1085 1085
     // Ensure this is our page.
1086
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1086
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1087 1087
 
1088
-        $gateway = sanitize_text_field( $_GET['payment-confirm'] );
1089
-        return apply_filters( "wpinv_payment_confirm_$gateway", $content );
1088
+        $gateway = sanitize_text_field($_GET['payment-confirm']);
1089
+        return apply_filters("wpinv_payment_confirm_$gateway", $content);
1090 1090
 
1091 1091
     }
1092 1092
 
1093 1093
     return $content;
1094 1094
 }
1095
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1095
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1096 1096
 
1097
-function wpinv_invoice_link( $invoice_id ) {
1098
-    $invoice = wpinv_get_invoice( $invoice_id );
1097
+function wpinv_invoice_link($invoice_id) {
1098
+    $invoice = wpinv_get_invoice($invoice_id);
1099 1099
 
1100
-    if ( empty( $invoice ) ) {
1100
+    if (empty($invoice)) {
1101 1101
         return null;
1102 1102
     }
1103 1103
 
1104
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1104
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1105 1105
 
1106
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1106
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1107 1107
 }
1108 1108
 
1109
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
1110
-    if ( empty( $note ) ) {
1109
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
1110
+    if (empty($note)) {
1111 1111
         return null;
1112 1112
     }
1113 1113
 
1114
-    if ( is_int( $note ) ) {
1115
-        $note = get_comment( $note );
1114
+    if (is_int($note)) {
1115
+        $note = get_comment($note);
1116 1116
     }
1117 1117
 
1118
-    if ( ! ( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
1118
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
1119 1119
         return null;
1120 1120
     }
1121 1121
 
1122
-    $note_classes   = array( 'note' );
1123
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
1122
+    $note_classes   = array('note');
1123
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
1124 1124
     $note_classes[] = $note->comment_author === 'System' ? 'system-note' : '';
1125
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
1126
-    $note_classes   = ! empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
1125
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
1126
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
1127 1127
 
1128 1128
     ob_start();
1129 1129
     ?>
1130
-    <li rel="<?php echo absint( $note->comment_ID ); ?>" class="<?php echo esc_attr( $note_classes ); ?> mb-2">
1130
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mb-2">
1131 1131
         <div class="note_content">
1132 1132
 
1133
-            <?php echo wp_kses_post( wptexturize( $note->comment_content ) ); ?>
1133
+            <?php echo wp_kses_post(wptexturize($note->comment_content)); ?>
1134 1134
 
1135
-            <?php if ( ! is_admin() ) : ?>
1135
+            <?php if (!is_admin()) : ?>
1136 1136
                 <em class="small form-text text-muted mt-0">
1137 1137
                     <?php
1138 1138
                         printf(
1139
-                            esc_html__( '%1$s - %2$s at %3$s', 'invoicing' ),
1140
-                            esc_html( $note->comment_author ),
1141
-                            esc_html( getpaid_format_date_value( $note->comment_date ) ),
1142
-                            esc_html( date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) )
1139
+                            esc_html__('%1$s - %2$s at %3$s', 'invoicing'),
1140
+                            esc_html($note->comment_author),
1141
+                            esc_html(getpaid_format_date_value($note->comment_date)),
1142
+                            esc_html(date_i18n(get_option('time_format'), strtotime($note->comment_date)))
1143 1143
                         );
1144 1144
                     ?>
1145 1145
                 </em>
@@ -1147,21 +1147,21 @@  discard block
 block discarded – undo
1147 1147
 
1148 1148
         </div>
1149 1149
 
1150
-        <?php if ( is_admin() ) : ?>
1150
+        <?php if (is_admin()) : ?>
1151 1151
 
1152 1152
             <p class="meta px-4 py-2">
1153
-                <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>">
1153
+                <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>">
1154 1154
                     <?php
1155 1155
                         printf(
1156
-                            esc_html__( '%1$s - %2$s at %3$s', 'invoicing' ),
1157
-                            esc_html( $note->comment_author ),
1158
-                            esc_html( getpaid_format_date_value( $note->comment_date ) ),
1159
-                            esc_html( date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) )
1156
+                            esc_html__('%1$s - %2$s at %3$s', 'invoicing'),
1157
+                            esc_html($note->comment_author),
1158
+                            esc_html(getpaid_format_date_value($note->comment_date)),
1159
+                            esc_html(date_i18n(get_option('time_format'), strtotime($note->comment_date)))
1160 1160
                         );
1161 1161
                     ?>
1162 1162
                 </abbr>&nbsp;&nbsp;
1163
-                <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?>
1164
-                    <a href="#" class="delete_note" data-id="<?php echo esc_attr( $note->comment_ID ); ?>"><?php esc_html_e( 'Delete note', 'invoicing' ); ?></a>
1163
+                <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?>
1164
+                    <a href="#" class="delete_note" data-id="<?php echo esc_attr($note->comment_ID); ?>"><?php esc_html_e('Delete note', 'invoicing'); ?></a>
1165 1165
                 <?php } ?>
1166 1166
             </p>
1167 1167
 
@@ -1170,10 +1170,10 @@  discard block
 block discarded – undo
1170 1170
     </li>
1171 1171
     <?php
1172 1172
     $note_content = ob_get_clean();
1173
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
1173
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
1174 1174
 
1175
-    if ( $echo ) {
1176
-        echo wp_kses_post( $note_content );
1175
+    if ($echo) {
1176
+        echo wp_kses_post($note_content);
1177 1177
     } else {
1178 1178
         return $note_content;
1179 1179
     }
@@ -1186,43 +1186,43 @@  discard block
 block discarded – undo
1186 1186
  * @return string
1187 1187
  */
1188 1188
 function wpinv_get_policy_text() {
1189
-    $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 );
1189
+    $privacy_page_id = get_option('wp_page_for_privacy_policy', 0);
1190 1190
 
1191
-    $text = wpinv_get_option( 'invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' ) );
1191
+    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]'));
1192 1192
 
1193
-    if ( ! $privacy_page_id ) {
1194
-        $privacy_page_id = wpinv_get_option( 'privacy_page', 0 );
1193
+    if (!$privacy_page_id) {
1194
+        $privacy_page_id = wpinv_get_option('privacy_page', 0);
1195 1195
     }
1196 1196
 
1197
-    $privacy_link    = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' );
1197
+    $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing');
1198 1198
 
1199 1199
     $find_replace = array(
1200 1200
         '[wpinv_privacy_policy]' => $privacy_link,
1201 1201
     );
1202 1202
 
1203
-    $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text );
1203
+    $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text);
1204 1204
 
1205
-    return wp_kses_post( wpautop( $privacy_text ) );
1205
+    return wp_kses_post(wpautop($privacy_text));
1206 1206
 }
1207 1207
 
1208 1208
 function wpinv_oxygen_fix_conflict() {
1209 1209
     global $ct_ignore_post_types;
1210 1210
 
1211
-    if ( ! is_array( $ct_ignore_post_types ) ) {
1211
+    if (!is_array($ct_ignore_post_types)) {
1212 1212
         $ct_ignore_post_types = array();
1213 1213
     }
1214 1214
 
1215
-    $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form' );
1215
+    $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form');
1216 1216
 
1217
-    foreach ( $post_types as $post_type ) {
1217
+    foreach ($post_types as $post_type) {
1218 1218
         $ct_ignore_post_types[] = $post_type;
1219 1219
 
1220 1220
         // Ignore post type
1221
-        add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 );
1221
+        add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999);
1222 1222
     }
1223 1223
 
1224
-    remove_filter( 'template_include', 'wpinv_template', 10, 1 );
1225
-    add_filter( 'template_include', 'wpinv_template', 999, 1 );
1224
+    remove_filter('template_include', 'wpinv_template', 10, 1);
1225
+    add_filter('template_include', 'wpinv_template', 999, 1);
1226 1226
 }
1227 1227
 
1228 1228
 /**
@@ -1230,10 +1230,10 @@  discard block
 block discarded – undo
1230 1230
  *
1231 1231
  * @param GetPaid_Payment_Form $form
1232 1232
  */
1233
-function getpaid_display_payment_form( $form ) {
1233
+function getpaid_display_payment_form($form) {
1234 1234
 
1235
-    if ( is_numeric( $form ) ) {
1236
-        $form = new GetPaid_Payment_Form( wpinv_translate_post_id( $form ) );
1235
+    if (is_numeric($form)) {
1236
+        $form = new GetPaid_Payment_Form(wpinv_translate_post_id($form));
1237 1237
     }
1238 1238
 
1239 1239
     $form->display();
@@ -1243,61 +1243,61 @@  discard block
 block discarded – undo
1243 1243
 /**
1244 1244
  * Helper function to display a item payment form on the frontend.
1245 1245
  */
1246
-function getpaid_display_item_payment_form( $items ) {
1246
+function getpaid_display_item_payment_form($items) {
1247 1247
 
1248
-    $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1249
-    $form->set_items( $items );
1248
+    $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1249
+    $form->set_items($items);
1250 1250
 
1251
-    if ( 0 == count( $form->get_items() ) ) {
1251
+    if (0 == count($form->get_items())) {
1252 1252
         aui()->alert(
1253 1253
 			array(
1254 1254
 				'type'    => 'warning',
1255
-				'content' => __( 'No published items found', 'invoicing' ),
1255
+				'content' => __('No published items found', 'invoicing'),
1256 1256
             ),
1257 1257
             true
1258 1258
         );
1259 1259
         return;
1260 1260
     }
1261 1261
 
1262
-    $extra_items     = esc_attr( getpaid_convert_items_to_string( $items ) );
1263
-    $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items );
1262
+    $extra_items     = esc_attr(getpaid_convert_items_to_string($items));
1263
+    $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items);
1264 1264
     $extra_items     = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />";
1265 1265
     $extra_items    .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />";
1266 1266
 
1267
-    $form->display( $extra_items );
1267
+    $form->display($extra_items);
1268 1268
 }
1269 1269
 
1270 1270
 /**
1271 1271
  * Helper function to display an invoice payment form on the frontend.
1272 1272
  */
1273
-function getpaid_display_invoice_payment_form( $invoice_id ) {
1273
+function getpaid_display_invoice_payment_form($invoice_id) {
1274 1274
 
1275
-    $invoice = wpinv_get_invoice( $invoice_id );
1275
+    $invoice = wpinv_get_invoice($invoice_id);
1276 1276
 
1277
-    if ( empty( $invoice ) ) {
1277
+    if (empty($invoice)) {
1278 1278
 		aui()->alert(
1279 1279
 			array(
1280 1280
 				'type'    => 'warning',
1281
-				'content' => __( 'Invoice not found', 'invoicing' ),
1281
+				'content' => __('Invoice not found', 'invoicing'),
1282 1282
             ),
1283 1283
             true
1284 1284
         );
1285 1285
         return;
1286 1286
     }
1287 1287
 
1288
-    if ( $invoice->is_paid() ) {
1288
+    if ($invoice->is_paid()) {
1289 1289
 		aui()->alert(
1290 1290
 			array(
1291 1291
 				'type'    => 'warning',
1292
-				'content' => __( 'Invoice has already been paid', 'invoicing' ),
1292
+				'content' => __('Invoice has already been paid', 'invoicing'),
1293 1293
             ),
1294 1294
             true
1295 1295
         );
1296 1296
         return;
1297 1297
     }
1298 1298
 
1299
-    $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1300
-    $form->set_items( $invoice->get_items() );
1299
+    $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1300
+    $form->set_items($invoice->get_items());
1301 1301
 
1302 1302
     $form->display();
1303 1303
 }
@@ -1305,24 +1305,24 @@  discard block
 block discarded – undo
1305 1305
 /**
1306 1306
  * Helper function to convert item string to array.
1307 1307
  */
1308
-function getpaid_convert_items_to_array( $items ) {
1309
-    $items    = array_filter( array_map( 'trim', explode( ',', $items ) ) );
1308
+function getpaid_convert_items_to_array($items) {
1309
+    $items    = array_filter(array_map('trim', explode(',', $items)));
1310 1310
     $prepared = array();
1311 1311
 
1312
-    foreach ( $items as $item ) {
1313
-        $data = array_map( 'trim', explode( '|', $item ) );
1312
+    foreach ($items as $item) {
1313
+        $data = array_map('trim', explode('|', $item));
1314 1314
 
1315
-        if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) {
1315
+        if (empty($data[0]) || !is_numeric($data[0])) {
1316 1316
             continue;
1317 1317
         }
1318 1318
 
1319 1319
         $quantity = 1;
1320
-        if ( isset( $data[1] ) && is_numeric( $data[1] ) ) {
1320
+        if (isset($data[1]) && is_numeric($data[1])) {
1321 1321
             $quantity = (float) $data[1];
1322 1322
         }
1323 1323
 
1324 1324
         // WPML support.
1325
-        $prepared[ wpinv_translate_post_id( $data[0] ) ] = $quantity;
1325
+        $prepared[wpinv_translate_post_id($data[0])] = $quantity;
1326 1326
 
1327 1327
     }
1328 1328
 
@@ -1332,13 +1332,13 @@  discard block
 block discarded – undo
1332 1332
 /**
1333 1333
  * Helper function to convert item array to string.
1334 1334
  */
1335
-function getpaid_convert_items_to_string( $items ) {
1335
+function getpaid_convert_items_to_string($items) {
1336 1336
     $prepared = array();
1337 1337
 
1338
-    foreach ( $items as $item => $quantity ) {
1338
+    foreach ($items as $item => $quantity) {
1339 1339
         $prepared[] = "$item|$quantity";
1340 1340
     }
1341
-    return implode( ',', $prepared );
1341
+    return implode(',', $prepared);
1342 1342
 }
1343 1343
 
1344 1344
 /**
@@ -1346,21 +1346,21 @@  discard block
 block discarded – undo
1346 1346
  *
1347 1347
  * Provide a label and one of $form, $items or $invoice.
1348 1348
  */
1349
-function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) {
1350
-    $label = sanitize_text_field( $label );
1349
+function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) {
1350
+    $label = sanitize_text_field($label);
1351 1351
 
1352
-    if ( ! empty( $form ) ) {
1353
-        $form  = esc_attr( $form );
1352
+    if (!empty($form)) {
1353
+        $form = esc_attr($form);
1354 1354
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>";
1355 1355
     }
1356 1356
 
1357
-	if ( ! empty( $items ) ) {
1358
-        $items  = esc_attr( $items );
1357
+	if (!empty($items)) {
1358
+        $items = esc_attr($items);
1359 1359
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>";
1360 1360
     }
1361 1361
 
1362
-    if ( ! empty( $invoice ) ) {
1363
-        $invoice  = esc_attr( $invoice );
1362
+    if (!empty($invoice)) {
1363
+        $invoice = esc_attr($invoice);
1364 1364
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-invoice='$invoice'>$label</button>";
1365 1365
     }
1366 1366
 
@@ -1371,17 +1371,17 @@  discard block
 block discarded – undo
1371 1371
  *
1372 1372
  * @param WPInv_Invoice $invoice
1373 1373
  */
1374
-function getpaid_the_invoice_description( $invoice ) {
1374
+function getpaid_the_invoice_description($invoice) {
1375 1375
     $description = $invoice->get_description();
1376 1376
 
1377
-    if ( empty( $description ) ) {
1377
+    if (empty($description)) {
1378 1378
         return;
1379 1379
     }
1380 1380
 
1381
-    echo "<small class='getpaid-invoice-description text-dark pl-2 ps-2 form-text' style='margin-bottom:20px;border-left:2px solid #2196F3;display:block;padding-left:.5rem'><em>" . wp_kses_post( wpautop( $description ) ) . "</em></small>";
1381
+    echo "<small class='getpaid-invoice-description text-dark pl-2 ps-2 form-text' style='margin-bottom:20px;border-left:2px solid #2196F3;display:block;padding-left:.5rem'><em>" . wp_kses_post(wpautop($description)) . "</em></small>";
1382 1382
 }
1383
-add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 );
1384
-add_action( 'wpinv_email_billing_details', 'getpaid_the_invoice_description', 100 );
1383
+add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100);
1384
+add_action('wpinv_email_billing_details', 'getpaid_the_invoice_description', 100);
1385 1385
 
1386 1386
 /**
1387 1387
  * Render element on a form.
@@ -1389,86 +1389,86 @@  discard block
 block discarded – undo
1389 1389
  * @param array $element
1390 1390
  * @param GetPaid_Payment_Form $form
1391 1391
  */
1392
-function getpaid_payment_form_element( $element, $form ) {
1393
-    $translatable = array( 'text', 'label', 'input_label', 'button_label', 'description' );
1392
+function getpaid_payment_form_element($element, $form) {
1393
+    $translatable = array('text', 'label', 'input_label', 'button_label', 'description');
1394 1394
 
1395
-    foreach ( $translatable as $string ) {
1396
-        if ( ! empty( $element[ $string ] ) && is_scalar( $element[ $string ] ) ) {
1397
-            $element[ $string ] = __( $element[ $string ], 'invoicing' );
1395
+    foreach ($translatable as $string) {
1396
+        if (!empty($element[$string]) && is_scalar($element[$string])) {
1397
+            $element[$string] = __($element[$string], 'invoicing');
1398 1398
         }
1399 1399
     }
1400 1400
 
1401 1401
     // Set up the args.
1402
-    $element_type    = trim( $element['type'] );
1402
+    $element_type    = trim($element['type']);
1403 1403
     $element['form'] = $form;
1404
-    extract( $element ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
1404
+    extract($element); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
1405 1405
 
1406 1406
     // Try to locate the appropriate template.
1407
-    $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" );
1407
+    $located = wpinv_locate_template("payment-forms/elements/$element_type.php");
1408 1408
 
1409 1409
     // Abort if this is not our element.
1410
-    if ( empty( $located ) || ! file_exists( $located ) ) {
1410
+    if (empty($located) || !file_exists($located)) {
1411 1411
         return;
1412 1412
     }
1413 1413
 
1414 1414
     // Generate the class and id of the element.
1415
-    $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) );
1416
-    $id            = isset( $id ) ? $id : uniqid( 'gp' );
1415
+    $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type));
1416
+    $id            = isset($id) ? $id : uniqid('gp');
1417 1417
 
1418
-    $element_id    = ! empty( $element['label'] ) ? sanitize_title( $element['label'] ) : $id;
1419
-    $query_value   = isset( $_GET[ $element_id ] ) ? wpinv_clean( urldecode_deep( $_GET[ $element_id ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1418
+    $element_id    = !empty($element['label']) ? sanitize_title($element['label']) : $id;
1419
+    $query_value   = isset($_GET[$element_id]) ? wpinv_clean(urldecode_deep($_GET[$element_id])) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1420 1420
 
1421 1421
     $element_id    = 'getpaid-' . $element_id;
1422
-    if ( ! empty( $GLOBALS['rendered_getpaid_forms'][ $form->get_id() ] ) ) {
1423
-        $element_id = $element_id . '-' . $GLOBALS['rendered_getpaid_forms'][ $form->get_id() ];
1422
+    if (!empty($GLOBALS['rendered_getpaid_forms'][$form->get_id()])) {
1423
+        $element_id = $element_id . '-' . $GLOBALS['rendered_getpaid_forms'][$form->get_id()];
1424 1424
     }
1425 1425
 
1426 1426
     // Echo the opening wrapper.
1427
-    echo "<div class='getpaid-payment-form-element " . esc_attr( $wrapper_class ) . "'>";
1427
+    echo "<div class='getpaid-payment-form-element " . esc_attr($wrapper_class) . "'>";
1428 1428
 
1429 1429
     // Fires before displaying a given element type's content.
1430
-    do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form );
1430
+    do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form);
1431 1431
 
1432 1432
     // Include the template for the element.
1433 1433
     include $located;
1434 1434
 
1435 1435
     // Fires after displaying a given element type's content.
1436
-    do_action( "getpaid_payment_form_{$element_type}_element", $element, $form );
1436
+    do_action("getpaid_payment_form_{$element_type}_element", $element, $form);
1437 1437
 
1438 1438
     // Echo the closing wrapper.
1439 1439
     echo '</div>';
1440 1440
 }
1441
-add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 );
1441
+add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2);
1442 1442
 
1443 1443
 /**
1444 1444
  * Render an element's edit page.
1445 1445
  *
1446 1446
  * @param WP_Post $post
1447 1447
  */
1448
-function getpaid_payment_form_edit_element_template( $post ) {
1448
+function getpaid_payment_form_edit_element_template($post) {
1449 1449
 
1450 1450
     // Retrieve all elements.
1451
-    $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' );
1451
+    $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type');
1452 1452
 
1453
-    foreach ( $all_elements as $element ) {
1453
+    foreach ($all_elements as $element) {
1454 1454
 
1455 1455
         // Try to locate the appropriate template.
1456
-        $element = esc_attr( sanitize_key( $element ) );
1457
-        $located = wpinv_locate_template( "payment-forms-admin/edit/$element.php" );
1456
+        $element = esc_attr(sanitize_key($element));
1457
+        $located = wpinv_locate_template("payment-forms-admin/edit/$element.php");
1458 1458
 
1459 1459
         // Continue if this is not our element.
1460
-        if ( empty( $located ) || ! file_exists( $located ) ) {
1460
+        if (empty($located) || !file_exists($located)) {
1461 1461
             continue;
1462 1462
         }
1463 1463
 
1464 1464
         // Include the template for the element.
1465
-        echo "<div v-if=\"active_form_element.type=='" . esc_attr( $element ) . "'\">";
1465
+        echo "<div v-if=\"active_form_element.type=='" . esc_attr($element) . "'\">";
1466 1466
         include $located;
1467 1467
         echo '</div>';
1468 1468
     }
1469 1469
 
1470 1470
 }
1471
-add_action( 'getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template' );
1471
+add_action('getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template');
1472 1472
 
1473 1473
 /**
1474 1474
  * Render an element's preview.
@@ -1477,27 +1477,27 @@  discard block
 block discarded – undo
1477 1477
 function getpaid_payment_form_render_element_preview_template() {
1478 1478
 
1479 1479
     // Retrieve all elements.
1480
-    $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' );
1480
+    $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type');
1481 1481
 
1482
-    foreach ( $all_elements as $element ) {
1482
+    foreach ($all_elements as $element) {
1483 1483
 
1484 1484
         // Try to locate the appropriate template.
1485
-        $element = sanitize_key( $element );
1486
-        $located = wpinv_locate_template( "payment-forms-admin/previews/$element.php" );
1485
+        $element = sanitize_key($element);
1486
+        $located = wpinv_locate_template("payment-forms-admin/previews/$element.php");
1487 1487
 
1488 1488
         // Continue if this is not our element.
1489
-        if ( empty( $located ) || ! file_exists( $located ) ) {
1489
+        if (empty($located) || !file_exists($located)) {
1490 1490
             continue;
1491 1491
         }
1492 1492
 
1493 1493
         // Include the template for the element.
1494
-        echo "<div v-if=\"form_element.type=='" . esc_html( $element ) . "'\">";
1494
+        echo "<div v-if=\"form_element.type=='" . esc_html($element) . "'\">";
1495 1495
         include $located;
1496 1496
         echo '</div>';
1497 1497
     }
1498 1498
 
1499 1499
 }
1500
-add_action( 'wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template' );
1500
+add_action('wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template');
1501 1501
 
1502 1502
 /**
1503 1503
  * Shows a list of gateways that support recurring payments.
@@ -1505,17 +1505,17 @@  discard block
 block discarded – undo
1505 1505
 function wpinv_get_recurring_gateways_text() {
1506 1506
     $gateways = array();
1507 1507
 
1508
-    foreach ( wpinv_get_payment_gateways() as $key => $gateway ) {
1509
-        if ( wpinv_gateway_support_subscription( $key ) ) {
1510
-            $gateways[] = sanitize_text_field( $gateway['admin_label'] );
1508
+    foreach (wpinv_get_payment_gateways() as $key => $gateway) {
1509
+        if (wpinv_gateway_support_subscription($key)) {
1510
+            $gateways[] = sanitize_text_field($gateway['admin_label']);
1511 1511
         }
1512 1512
     }
1513 1513
 
1514
-    if ( empty( $gateways ) ) {
1515
-        return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) . '</span>';
1514
+    if (empty($gateways)) {
1515
+        return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . '</span>';
1516 1516
     }
1517 1517
 
1518
-    return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) . '</span>';
1518
+    return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . '</span>';
1519 1519
 
1520 1520
 }
1521 1521
 
@@ -1525,7 +1525,7 @@  discard block
 block discarded – undo
1525 1525
  * @return GetPaid_Template
1526 1526
  */
1527 1527
 function getpaid_template() {
1528
-    return getpaid()->get( 'template' );
1528
+    return getpaid()->get('template');
1529 1529
 }
1530 1530
 
1531 1531
 /**
@@ -1534,8 +1534,8 @@  discard block
 block discarded – undo
1534 1534
  * @param array args
1535 1535
  * @return string
1536 1536
  */
1537
-function getpaid_paginate_links( $args ) {
1538
-    return str_replace( 'page-link dots', 'page-link text-dark', aui()->pagination( $args ) );
1537
+function getpaid_paginate_links($args) {
1538
+    return str_replace('page-link dots', 'page-link text-dark', aui()->pagination($args));
1539 1539
 }
1540 1540
 
1541 1541
 /**
@@ -1545,22 +1545,22 @@  discard block
 block discarded – undo
1545 1545
  * @param string state
1546 1546
  * @return string
1547 1547
  */
1548
-function getpaid_get_states_select_markup( $country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state', $echo = false ) {
1548
+function getpaid_get_states_select_markup($country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state', $echo = false) {
1549 1549
 
1550
-    $states = wpinv_get_country_states( $country );
1551
-    $uniqid = uniqid( '_' );
1550
+    $states = wpinv_get_country_states($country);
1551
+    $uniqid = uniqid('_');
1552 1552
 
1553
-    if ( ! empty( $states ) ) {
1553
+    if (!empty($states)) {
1554 1554
 
1555 1555
         return aui()->select(
1556 1556
             array(
1557 1557
 				'options'          => $states,
1558
-				'name'             => esc_attr( $field_name ),
1559
-				'id'               => sanitize_html_class( $field_name ) . $uniqid,
1560
-				'value'            => sanitize_text_field( $state ),
1558
+				'name'             => esc_attr($field_name),
1559
+				'id'               => sanitize_html_class($field_name) . $uniqid,
1560
+				'value'            => sanitize_text_field($state),
1561 1561
 				'placeholder'      => $placeholder,
1562 1562
 				'required'         => $required,
1563
-				'label'            => wp_kses_post( $label ),
1563
+				'label'            => wp_kses_post($label),
1564 1564
 				'label_type'       => 'vertical',
1565 1565
 				'help_text'        => $help_text,
1566 1566
 				'class'            => 'getpaid-address-field wpinv_state',
@@ -1577,14 +1577,14 @@  discard block
 block discarded – undo
1577 1577
 
1578 1578
     return aui()->input(
1579 1579
         array(
1580
-            'name'             => esc_attr( $field_name ),
1581
-            'id'               => sanitize_html_class( $field_name ) . $uniqid,
1580
+            'name'             => esc_attr($field_name),
1581
+            'id'               => sanitize_html_class($field_name) . $uniqid,
1582 1582
             'placeholder'      => $placeholder,
1583 1583
             'required'         => $required,
1584
-            'label'            => wp_kses_post( $label ),
1584
+            'label'            => wp_kses_post($label),
1585 1585
             'label_type'       => 'vertical',
1586 1586
             'help_text'        => $help_text,
1587
-            'value'            => sanitize_text_field( $state ),
1587
+            'value'            => sanitize_text_field($state),
1588 1588
             'class'            => 'getpaid-address-field wpinv_state',
1589 1589
             'wrap_class'       => "$wrapper_class getpaid-address-field-wrapper__state",
1590 1590
             'label_class'      => 'getpaid-address-field-label getpaid-address-field-label__state',
@@ -1603,16 +1603,16 @@  discard block
 block discarded – undo
1603 1603
  * @param array $element
1604 1604
  * @return string
1605 1605
  */
1606
-function getpaid_get_form_element_grid_class( $element ) {
1606
+function getpaid_get_form_element_grid_class($element) {
1607 1607
 
1608 1608
     $class = 'col-12';
1609
-    $width = empty( $element['grid_width'] ) ? 'full' : $element['grid_width'];
1609
+    $width = empty($element['grid_width']) ? 'full' : $element['grid_width'];
1610 1610
 
1611
-    if ( $width == 'half' ) {
1611
+    if ($width == 'half') {
1612 1612
         $class .= ' col-md-6';
1613 1613
     }
1614 1614
 
1615
-    if ( $width == 'third' ) {
1615
+    if ($width == 'third') {
1616 1616
         $class .= ' col-md-4';
1617 1617
     }
1618 1618
 
@@ -1627,15 +1627,15 @@  discard block
 block discarded – undo
1627 1627
  *
1628 1628
  * @return string
1629 1629
  */
1630
-function getpaid_embed_url( $payment_form = false, $items = false ) {
1630
+function getpaid_embed_url($payment_form = false, $items = false) {
1631 1631
 
1632 1632
     return add_query_arg(
1633 1633
         array(
1634 1634
             'getpaid_embed' => 1,
1635
-            'form'          => $payment_form ? absint( $payment_form ) : false,
1636
-            'item'          => $items ? urlencode( $items ) : false,
1635
+            'form'          => $payment_form ? absint($payment_form) : false,
1636
+            'item'          => $items ? urlencode($items) : false,
1637 1637
         ),
1638
-        home_url( 'index.php' )
1638
+        home_url('index.php')
1639 1639
     );
1640 1640
 
1641 1641
 }
@@ -1645,16 +1645,16 @@  discard block
 block discarded – undo
1645 1645
  *
1646 1646
  * @return string
1647 1647
  */
1648
-function getpaid_filter_embed_template( $template ) {
1648
+function getpaid_filter_embed_template($template) {
1649 1649
 
1650
-    if ( isset( $_GET['getpaid_embed'] ) ) {
1651
-        wpinv_get_template( 'payment-forms/embed.php' );
1650
+    if (isset($_GET['getpaid_embed'])) {
1651
+        wpinv_get_template('payment-forms/embed.php');
1652 1652
         exit;
1653 1653
     }
1654 1654
 
1655 1655
     return $template;
1656 1656
 }
1657
-add_filter( 'template_include', 'getpaid_filter_embed_template' );
1657
+add_filter('template_include', 'getpaid_filter_embed_template');
1658 1658
 
1659 1659
 /**
1660 1660
  * Get the payment forms custom fields.
@@ -1666,25 +1666,25 @@  discard block
 block discarded – undo
1666 1666
 function getpaid_get_payment_form_custom_fields() {
1667 1667
 	global $wpdb, $payment_form_meta_fields;
1668 1668
 
1669
-	if ( ! empty( $payment_form_meta_fields ) ) {
1669
+	if (!empty($payment_form_meta_fields)) {
1670 1670
 		return $payment_form_meta_fields;
1671 1671
 	}
1672 1672
 
1673
-	$results = $wpdb->get_results( "SELECT `pm`.`meta_value` FROM `{$wpdb->postmeta}` AS pm LEFT JOIN `{$wpdb->posts}` AS p ON p.ID = pm.post_id WHERE `pm`.`meta_key` = 'wpinv_form_elements' AND `p`.`post_type` = 'wpi_payment_form'" );
1673
+	$results = $wpdb->get_results("SELECT `pm`.`meta_value` FROM `{$wpdb->postmeta}` AS pm LEFT JOIN `{$wpdb->posts}` AS p ON p.ID = pm.post_id WHERE `pm`.`meta_key` = 'wpinv_form_elements' AND `p`.`post_type` = 'wpi_payment_form'");
1674 1674
 
1675 1675
 	$meta_fields = array();
1676 1676
 
1677
-	if ( ! empty( $results ) ) {
1678
-		foreach ( $results as $row ) {
1679
-			$fields = maybe_unserialize( $row->meta_value );
1677
+	if (!empty($results)) {
1678
+		foreach ($results as $row) {
1679
+			$fields = maybe_unserialize($row->meta_value);
1680 1680
 
1681
-			if ( ! empty( $fields ) && is_array( $fields ) ) {
1682
-				foreach ( $fields as $field ) {
1683
-					$label = ! empty( $field['add_meta'] ) && ! empty( $field['label'] ) ? wpinv_clean( wp_unslash( $field['label'] ) ) : '';
1681
+			if (!empty($fields) && is_array($fields)) {
1682
+				foreach ($fields as $field) {
1683
+					$label = !empty($field['add_meta']) && !empty($field['label']) ? wpinv_clean(wp_unslash($field['label'])) : '';
1684 1684
 
1685
-					if ( $label ) {
1686
-						$field_key = '_' . str_replace( array( ' ', "'", '"', ',' ), array( '_', '', '', '_' ), getpaid_strtolower( $label ) );
1687
-						$meta_fields[ $field_key ] = $label;
1685
+					if ($label) {
1686
+						$field_key = '_' . str_replace(array(' ', "'", '"', ','), array('_', '', '', '_'), getpaid_strtolower($label));
1687
+						$meta_fields[$field_key] = $label;
1688 1688
 					}
1689 1689
 				}
1690 1690
 			}
Please login to merge, or discard this patch.