Passed
Pull Request — master (#409)
by Brian
15:26 queued 10:36
created
includes/wpinv-email-functions.php 1 patch
Spacing   +670 added lines, -670 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_init_transactional_emails() {
15
-    $email_actions = apply_filters( 'wpinv_email_actions', array(
15
+    $email_actions = apply_filters('wpinv_email_actions', array(
16 16
         'wpinv_status_wpi-pending_to_wpi-processing',
17 17
         'wpinv_status_wpi-pending_to_publish',
18 18
         'wpinv_status_wpi-pending_to_wpi-cancelled',
@@ -30,385 +30,385 @@  discard block
 block discarded – undo
30 30
         'wpinv_fully_refunded',
31 31
         'wpinv_partially_refunded',
32 32
         'wpinv_new_invoice_note'
33
-    ) );
33
+    ));
34 34
 
35
-    foreach ( $email_actions as $action ) {
36
-        add_action( $action, 'wpinv_send_transactional_email', 10, 10 );
35
+    foreach ($email_actions as $action) {
36
+        add_action($action, 'wpinv_send_transactional_email', 10, 10);
37 37
     }
38 38
 }
39
-add_action( 'init', 'wpinv_init_transactional_emails' );
39
+add_action('init', 'wpinv_init_transactional_emails');
40 40
 
41 41
 // New invoice email
42
-add_action( 'wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_new_invoice_notification' );
43
-add_action( 'wpinv_status_wpi-pending_to_publish_notification', 'wpinv_new_invoice_notification' );
44
-add_action( 'wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_new_invoice_notification' );
45
-add_action( 'wpinv_status_wpi-failed_to_wpi-processing_notification', 'wpinv_new_invoice_notification' );
46
-add_action( 'wpinv_status_wpi-failed_to_publish_notification', 'wpinv_new_invoice_notification' );
47
-add_action( 'wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_new_invoice_notification' );
42
+add_action('wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_new_invoice_notification');
43
+add_action('wpinv_status_wpi-pending_to_publish_notification', 'wpinv_new_invoice_notification');
44
+add_action('wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_new_invoice_notification');
45
+add_action('wpinv_status_wpi-failed_to_wpi-processing_notification', 'wpinv_new_invoice_notification');
46
+add_action('wpinv_status_wpi-failed_to_publish_notification', 'wpinv_new_invoice_notification');
47
+add_action('wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_new_invoice_notification');
48 48
 
49 49
 // Cancelled invoice email
50
-add_action( 'wpinv_status_wpi-pending_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification' );
51
-add_action( 'wpinv_status_wpi-onhold_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification' );
50
+add_action('wpinv_status_wpi-pending_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification');
51
+add_action('wpinv_status_wpi-onhold_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification');
52 52
 
53 53
 // Failed invoice email
54
-add_action( 'wpinv_status_wpi-pending_to_wpi-failed_notification', 'wpinv_failed_invoice_notification' );
55
-add_action( 'wpinv_status_wpi-onhold_to_wpi-failed_notification', 'wpinv_failed_invoice_notification' );
54
+add_action('wpinv_status_wpi-pending_to_wpi-failed_notification', 'wpinv_failed_invoice_notification');
55
+add_action('wpinv_status_wpi-onhold_to_wpi-failed_notification', 'wpinv_failed_invoice_notification');
56 56
 
57 57
 // On hold invoice email
58
-add_action( 'wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification' );
59
-add_action( 'wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification' );
58
+add_action('wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification');
59
+add_action('wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification');
60 60
 
61 61
 // Processing invoice email
62
-add_action( 'wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_processing_invoice_notification' );
62
+add_action('wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_processing_invoice_notification');
63 63
 
64 64
 // Paid invoice email
65
-add_action( 'wpinv_status_publish_notification', 'wpinv_completed_invoice_notification' );
65
+add_action('wpinv_status_publish_notification', 'wpinv_completed_invoice_notification');
66 66
 
67 67
 // Refunded invoice email
68
-add_action( 'wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification' );
69
-add_action( 'wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification' );
70
-add_action( 'wpinv_status_publish_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification' );
71
-add_action( 'wpinv_status_wpi-processing_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification' );
68
+add_action('wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification');
69
+add_action('wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification');
70
+add_action('wpinv_status_publish_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification');
71
+add_action('wpinv_status_wpi-processing_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification');
72 72
 
73 73
 // Invoice note
74
-add_action( 'wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification' );
74
+add_action('wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification');
75 75
 
76
-add_action( 'wpinv_email_header', 'wpinv_email_header' );
77
-add_action( 'wpinv_email_footer', 'wpinv_email_footer' );
78
-add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 );
79
-add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 );
80
-add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 );
76
+add_action('wpinv_email_header', 'wpinv_email_header');
77
+add_action('wpinv_email_footer', 'wpinv_email_footer');
78
+add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3);
79
+add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3);
80
+add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3);
81 81
 
82 82
 function wpinv_send_transactional_email() {
83 83
     $args       = func_get_args();
84 84
     $function   = current_filter() . '_notification';
85
-    do_action_ref_array( $function, $args );
85
+    do_action_ref_array($function, $args);
86 86
 }
87 87
 
88
-function wpinv_new_invoice_notification( $invoice_id, $new_status = '' ) {
88
+function wpinv_new_invoice_notification($invoice_id, $new_status = '') {
89 89
     $email_type = 'new_invoice';
90
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
90
+    if (!wpinv_email_is_enabled($email_type)) {
91 91
         return false;
92 92
     }
93 93
 
94
-    $invoice = wpinv_get_invoice( $invoice_id );
95
-    if ( empty( $invoice ) ) {
94
+    $invoice = wpinv_get_invoice($invoice_id);
95
+    if (empty($invoice)) {
96 96
         return false;
97 97
     }
98 98
 
99
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
99
+    if (!("wpi_invoice" === $invoice->post_type)) {
100 100
         return false;
101 101
     }
102 102
 
103
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
104
-    if ( !is_email( $recipient ) ) {
103
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
104
+    if (!is_email($recipient)) {
105 105
         return false;
106 106
     }
107 107
 
108
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type, true );
108
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type, true);
109 109
 
110
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
111
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
112
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
113
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
114
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
110
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
111
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
112
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
113
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
114
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
115 115
 
116
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
116
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
117 117
             'invoice'       => $invoice,
118 118
             'email_type'    => $email_type,
119 119
             'email_heading' => $email_heading,
120 120
             'sent_to_admin' => true,
121 121
             'plain_text'    => false,
122 122
             'message_body'  => $message_body,
123
-        ) );
123
+        ));
124 124
 
125
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
125
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
126 126
 
127
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type, true );
127
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type, true);
128 128
 
129 129
     return $sent;
130 130
 }
131 131
 
132
-function wpinv_cancelled_invoice_notification( $invoice_id, $new_status = '' ) {
132
+function wpinv_cancelled_invoice_notification($invoice_id, $new_status = '') {
133 133
     $email_type = 'cancelled_invoice';
134
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
134
+    if (!wpinv_email_is_enabled($email_type)) {
135 135
         return false;
136 136
     }
137 137
 
138
-    $invoice = wpinv_get_invoice( $invoice_id );
139
-    if ( empty( $invoice ) ) {
138
+    $invoice = wpinv_get_invoice($invoice_id);
139
+    if (empty($invoice)) {
140 140
         return false;
141 141
     }
142 142
 
143
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
143
+    if (!("wpi_invoice" === $invoice->post_type)) {
144 144
         return false;
145 145
     }
146 146
 
147
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
148
-    if ( !is_email( $recipient ) ) {
147
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
148
+    if (!is_email($recipient)) {
149 149
         return false;
150 150
     }
151 151
 
152
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type, true );
152
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type, true);
153 153
 
154
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
155
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
156
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
157
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
158
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
154
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
155
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
156
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
157
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
158
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
159 159
 
160
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
160
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
161 161
             'invoice'       => $invoice,
162 162
             'email_type'    => $email_type,
163 163
             'email_heading' => $email_heading,
164 164
             'sent_to_admin' => true,
165 165
             'plain_text'    => false,
166 166
             'message_body'  => $message_body,
167
-        ) );
167
+        ));
168 168
 
169
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
169
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
170 170
 
171
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type, true );
171
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type, true);
172 172
 
173 173
     return $sent;
174 174
 }
175 175
 
176
-function wpinv_failed_invoice_notification( $invoice_id, $new_status = '' ) {
176
+function wpinv_failed_invoice_notification($invoice_id, $new_status = '') {
177 177
     $email_type = 'failed_invoice';
178
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
178
+    if (!wpinv_email_is_enabled($email_type)) {
179 179
         return false;
180 180
     }
181 181
     
182
-    $invoice = wpinv_get_invoice( $invoice_id );
183
-    if ( empty( $invoice ) ) {
182
+    $invoice = wpinv_get_invoice($invoice_id);
183
+    if (empty($invoice)) {
184 184
         return false;
185 185
     }
186 186
 
187
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
187
+    if (!("wpi_invoice" === $invoice->post_type)) {
188 188
         return false;
189 189
     }
190 190
 
191
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
192
-    if ( !is_email( $recipient ) ) {
191
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
192
+    if (!is_email($recipient)) {
193 193
         return false;
194 194
     }
195 195
 
196
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type, true );
196
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type, true);
197 197
 
198
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
199
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
200
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
201
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
202
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
198
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
199
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
200
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
201
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
202
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
203 203
     
204
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
204
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
205 205
             'invoice'       => $invoice,
206 206
             'email_type'    => $email_type,
207 207
             'email_heading' => $email_heading,
208 208
             'sent_to_admin' => true,
209 209
             'plain_text'    => false,
210 210
             'message_body'  => $message_body,
211
-        ) );
211
+        ));
212 212
 
213
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
213
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
214 214
 
215
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type, true );
215
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type, true);
216 216
 
217 217
     return $sent;
218 218
 }
219 219
 
220
-function wpinv_onhold_invoice_notification( $invoice_id, $new_status = '' ) {
220
+function wpinv_onhold_invoice_notification($invoice_id, $new_status = '') {
221 221
     $email_type = 'onhold_invoice';
222
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
222
+    if (!wpinv_email_is_enabled($email_type)) {
223 223
         return false;
224 224
     }
225 225
 
226
-    $invoice = wpinv_get_invoice( $invoice_id );
227
-    if ( empty( $invoice ) ) {
226
+    $invoice = wpinv_get_invoice($invoice_id);
227
+    if (empty($invoice)) {
228 228
         return false;
229 229
     }
230 230
 
231
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
231
+    if (!("wpi_invoice" === $invoice->post_type)) {
232 232
         return false;
233 233
     }
234 234
 
235
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
236
-    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
237
-    if ( !is_email( $recipient ) ) {
235
+    $recipient      = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
236
+    $extra          = wpinv_email_get_cc_recipients($email_type, $invoice_id, $invoice);
237
+    if (!is_email($recipient)) {
238 238
         return false;
239 239
     }
240 240
 
241
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
241
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
242 242
 
243
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
244
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
245
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
246
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
247
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
243
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
244
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
245
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
246
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
247
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
248 248
     
249
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
249
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
250 250
             'invoice'       => $invoice,
251 251
             'email_type'    => $email_type,
252 252
             'email_heading' => $email_heading,
253 253
             'sent_to_admin' => false,
254 254
             'plain_text'    => false,
255 255
             'message_body'  => $message_body,
256
-        ) );
256
+        ));
257 257
     
258
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
258
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments, $extra);
259 259
     
260
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
261
-        $recipient  = wpinv_get_admin_email();
262
-        $subject    .= ' - ADMIN BCC COPY';
263
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
260
+    if (wpinv_mail_admin_bcc_active($email_type)) {
261
+        $recipient = wpinv_get_admin_email();
262
+        $subject .= ' - ADMIN BCC COPY';
263
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
264 264
     }
265 265
 
266
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
266
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
267 267
 
268 268
     return $sent;
269 269
 }
270 270
 
271
-function wpinv_processing_invoice_notification( $invoice_id, $new_status = '' ) {
271
+function wpinv_processing_invoice_notification($invoice_id, $new_status = '') {
272 272
     $email_type = 'processing_invoice';
273
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
273
+    if (!wpinv_email_is_enabled($email_type)) {
274 274
         return false;
275 275
     }
276 276
 
277
-    $invoice = wpinv_get_invoice( $invoice_id );
278
-    if ( empty( $invoice ) ) {
277
+    $invoice = wpinv_get_invoice($invoice_id);
278
+    if (empty($invoice)) {
279 279
         return false;
280 280
     }
281 281
 
282
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
282
+    if (!("wpi_invoice" === $invoice->post_type)) {
283 283
         return false;
284 284
     }
285 285
 
286
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
287
-    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
288
-    if ( !is_email( $recipient ) ) {
286
+    $recipient      = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
287
+    $extra          = wpinv_email_get_cc_recipients($email_type, $invoice_id, $invoice);
288
+    if (!is_email($recipient)) {
289 289
         return false;
290 290
     }
291 291
 
292
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
292
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
293 293
 
294 294
     $search                     = array();
295 295
     $search['invoice_number']   = '{invoice_number}';
296 296
     $search['invoice_date']     = '{invoice_date}';
297 297
     $search['name']             = '{name}';
298 298
 
299
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
300
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
301
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
302
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
303
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
299
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
300
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
301
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
302
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
303
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
304 304
     
305
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
305
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
306 306
             'invoice'       => $invoice,
307 307
             'email_type'    => $email_type,
308 308
             'email_heading' => $email_heading,
309 309
             'sent_to_admin' => false,
310 310
             'plain_text'    => false,
311 311
             'message_body'  => $message_body,
312
-        ) );
312
+        ));
313 313
 
314
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
314
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments, $extra);
315 315
 
316
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
317
-        $recipient  = wpinv_get_admin_email();
318
-        $subject    .= ' - ADMIN BCC COPY';
319
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
316
+    if (wpinv_mail_admin_bcc_active($email_type)) {
317
+        $recipient = wpinv_get_admin_email();
318
+        $subject .= ' - ADMIN BCC COPY';
319
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
320 320
     }
321 321
 
322
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
322
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
323 323
 
324 324
     return $sent;
325 325
 }
326 326
 
327
-function wpinv_completed_invoice_notification( $invoice_id, $new_status = '' ) {
327
+function wpinv_completed_invoice_notification($invoice_id, $new_status = '') {
328 328
     $email_type = 'completed_invoice';
329
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
329
+    if (!wpinv_email_is_enabled($email_type)) {
330 330
         return false;
331 331
     }
332 332
 
333
-    $invoice = wpinv_get_invoice( $invoice_id );
334
-    if ( empty( $invoice ) ) {
333
+    $invoice = wpinv_get_invoice($invoice_id);
334
+    if (empty($invoice)) {
335 335
         return false;
336 336
     }
337 337
 
338
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
338
+    if (!("wpi_invoice" === $invoice->post_type)) {
339 339
         return false;
340 340
     }
341 341
 
342
-    if($invoice->is_renewal() && wpinv_email_is_enabled( 'completed_invoice_renewal' )){
342
+    if ($invoice->is_renewal() && wpinv_email_is_enabled('completed_invoice_renewal')) {
343 343
         return false;
344 344
     }
345 345
 
346
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
347
-    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
348
-    if ( !is_email( $recipient ) ) {
346
+    $recipient      = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
347
+    $extra          = wpinv_email_get_cc_recipients($email_type, $invoice_id, $invoice);
348
+    if (!is_email($recipient)) {
349 349
         return false;
350 350
     }
351 351
 
352
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
352
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
353 353
 
354
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
355
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
356
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
357
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
358
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
354
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
355
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
356
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
357
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
358
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
359 359
 
360
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
360
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
361 361
             'invoice'       => $invoice,
362 362
             'email_type'    => $email_type,
363 363
             'email_heading' => $email_heading,
364 364
             'sent_to_admin' => false,
365 365
             'plain_text'    => false,
366 366
             'message_body'  => $message_body,
367
-        ) );
367
+        ));
368 368
 
369
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
369
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments, $extra);
370 370
 
371
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
372
-        $recipient  = wpinv_get_admin_email();
373
-        $subject    .= ' - ADMIN BCC COPY';
374
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
371
+    if (wpinv_mail_admin_bcc_active($email_type)) {
372
+        $recipient = wpinv_get_admin_email();
373
+        $subject .= ' - ADMIN BCC COPY';
374
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
375 375
     }
376 376
 
377
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
377
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
378 378
 
379 379
     return $sent;
380 380
 }
381 381
 
382
-function wpinv_fully_refunded_notification( $invoice_id, $new_status = '' ) {
382
+function wpinv_fully_refunded_notification($invoice_id, $new_status = '') {
383 383
     $email_type = 'refunded_invoice';
384
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
384
+    if (!wpinv_email_is_enabled($email_type)) {
385 385
         return false;
386 386
     }
387 387
 
388
-    $invoice = wpinv_get_invoice( $invoice_id );
389
-    if ( empty( $invoice ) ) {
388
+    $invoice = wpinv_get_invoice($invoice_id);
389
+    if (empty($invoice)) {
390 390
         return false;
391 391
     }
392 392
 
393
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
393
+    if (!("wpi_invoice" === $invoice->post_type)) {
394 394
         return false;
395 395
     }
396 396
 
397
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
398
-    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
399
-    if ( !is_email( $recipient ) ) {
397
+    $recipient      = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
398
+    $extra          = wpinv_email_get_cc_recipients($email_type, $invoice_id, $invoice);
399
+    if (!is_email($recipient)) {
400 400
         return false;
401 401
     }
402 402
 
403
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
403
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
404 404
 
405
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
406
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
407
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
408
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
409
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
405
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
406
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
407
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
408
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
409
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
410 410
 
411
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
411
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
412 412
             'invoice'           => $invoice,
413 413
             'email_type'        => $email_type,
414 414
             'email_heading'     => $email_heading,
@@ -416,51 +416,51 @@  discard block
 block discarded – undo
416 416
             'plain_text'        => false,
417 417
             'partial_refund'    => false,
418 418
             'message_body'      => $message_body,
419
-        ) );
419
+        ));
420 420
 
421
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
421
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments, $extra);
422 422
 
423
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
424
-        $recipient  = wpinv_get_admin_email();
425
-        $subject    .= ' - ADMIN BCC COPY';
426
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
423
+    if (wpinv_mail_admin_bcc_active($email_type)) {
424
+        $recipient = wpinv_get_admin_email();
425
+        $subject .= ' - ADMIN BCC COPY';
426
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
427 427
     }
428 428
 
429
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
429
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
430 430
 
431 431
     return $sent;
432 432
 }
433 433
 
434
-function wpinv_partially_refunded_notification( $invoice_id, $new_status = '' ) {
434
+function wpinv_partially_refunded_notification($invoice_id, $new_status = '') {
435 435
     $email_type = 'refunded_invoice';
436
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
436
+    if (!wpinv_email_is_enabled($email_type)) {
437 437
         return false;
438 438
     }
439 439
 
440
-    $invoice = wpinv_get_invoice( $invoice_id );
441
-    if ( empty( $invoice ) ) {
440
+    $invoice = wpinv_get_invoice($invoice_id);
441
+    if (empty($invoice)) {
442 442
         return false;
443 443
     }
444 444
 
445
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
445
+    if (!("wpi_invoice" === $invoice->post_type)) {
446 446
         return false;
447 447
     }
448 448
 
449
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
450
-    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
451
-    if ( !is_email( $recipient ) ) {
449
+    $recipient      = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
450
+    $extra          = wpinv_email_get_cc_recipients($email_type, $invoice_id, $invoice);
451
+    if (!is_email($recipient)) {
452 452
         return false;
453 453
     }
454 454
 
455
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
455
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
456 456
 
457
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
458
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
459
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
460
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
461
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
457
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
458
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
459
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
460
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
461
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
462 462
 
463
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
463
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
464 464
             'invoice'           => $invoice,
465 465
             'email_type'        => $email_type,
466 466
             'email_heading'     => $email_heading,
@@ -468,97 +468,97 @@  discard block
 block discarded – undo
468 468
             'plain_text'        => false,
469 469
             'partial_refund'    => true,
470 470
             'message_body'      => $message_body,
471
-        ) );
471
+        ));
472 472
 
473
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
473
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments, $extra);
474 474
 
475
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
476
-        $recipient  = wpinv_get_admin_email();
477
-        $subject    .= ' - ADMIN BCC COPY';
478
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
475
+    if (wpinv_mail_admin_bcc_active($email_type)) {
476
+        $recipient = wpinv_get_admin_email();
477
+        $subject .= ' - ADMIN BCC COPY';
478
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
479 479
     }
480 480
 
481
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
481
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
482 482
 
483 483
     return $sent;
484 484
 }
485 485
 
486
-function wpinv_new_invoice_note_notification( $invoice_id, $new_status = '' ) {
486
+function wpinv_new_invoice_note_notification($invoice_id, $new_status = '') {
487 487
 }
488 488
 
489
-function wpinv_user_invoice_notification( $invoice_id ) {
489
+function wpinv_user_invoice_notification($invoice_id) {
490 490
     $email_type = 'user_invoice';
491
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
491
+    if (!wpinv_email_is_enabled($email_type)) {
492 492
         return -1;
493 493
     }
494 494
 
495
-    $invoice = wpinv_get_invoice( $invoice_id );
496
-    if ( empty( $invoice ) ) {
495
+    $invoice = wpinv_get_invoice($invoice_id);
496
+    if (empty($invoice)) {
497 497
         return false;
498 498
     }
499 499
 
500
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
500
+    if (!("wpi_invoice" === $invoice->post_type)) {
501 501
         return false;
502 502
     }
503 503
 
504
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
505
-    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
506
-    if ( !is_email( $recipient ) ) {
504
+    $recipient      = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
505
+    $extra          = wpinv_email_get_cc_recipients($email_type, $invoice_id, $invoice);
506
+    if (!is_email($recipient)) {
507 507
         return false;
508 508
     }
509 509
 
510
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
510
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
511 511
 
512
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
513
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
514
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
515
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
516
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
512
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
513
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
514
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
515
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
516
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
517 517
     
518
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
518
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
519 519
             'invoice'       => $invoice,
520 520
             'email_type'    => $email_type,
521 521
             'email_heading' => $email_heading,
522 522
             'sent_to_admin' => false,
523 523
             'plain_text'    => false,
524 524
             'message_body'  => $message_body,
525
-        ) );
525
+        ));
526 526
 
527
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
527
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments, $extra);
528 528
 
529
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
530
-        $recipient  = wpinv_get_admin_email();
531
-        $subject    .= ' - ADMIN BCC COPY';
532
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
529
+    if (wpinv_mail_admin_bcc_active($email_type)) {
530
+        $recipient = wpinv_get_admin_email();
531
+        $subject .= ' - ADMIN BCC COPY';
532
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
533 533
     }
534 534
 
535
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
535
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
536 536
 
537
-    if ( $sent ) {
538
-        $note = __( 'Invoice has been emailed to the user.', 'invoicing' );
537
+    if ($sent) {
538
+        $note = __('Invoice has been emailed to the user.', 'invoicing');
539 539
     } else {
540
-        $note = __( 'Fail to send invoice to the user!', 'invoicing' );
540
+        $note = __('Fail to send invoice to the user!', 'invoicing');
541 541
     }
542 542
 
543
-    $invoice->add_note( $note, '', '', true ); // Add system note.
543
+    $invoice->add_note($note, '', '', true); // Add system note.
544 544
 
545 545
     return $sent;
546 546
 }
547 547
 
548
-function wpinv_user_note_notification( $invoice_id, $args = array() ) {
548
+function wpinv_user_note_notification($invoice_id, $args = array()) {
549 549
     $email_type = 'user_note';
550
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
550
+    if (!wpinv_email_is_enabled($email_type)) {
551 551
         return false;
552 552
     }
553 553
 
554
-    $invoice = wpinv_get_invoice( $invoice_id );
555
-    if ( empty( $invoice ) ) {
554
+    $invoice = wpinv_get_invoice($invoice_id);
555
+    if (empty($invoice)) {
556 556
         return false;
557 557
     }
558 558
 
559
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
560
-    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
561
-    if ( !is_email( $recipient ) ) {
559
+    $recipient      = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
560
+    $extra          = wpinv_email_get_cc_recipients($email_type, $invoice_id, $invoice);
561
+    if (!is_email($recipient)) {
562 562
         return false;
563 563
     }
564 564
 
@@ -566,19 +566,19 @@  discard block
 block discarded – undo
566 566
         'user_note' => ''
567 567
     );
568 568
 
569
-    $args = wp_parse_args( $args, $defaults );
569
+    $args = wp_parse_args($args, $defaults);
570 570
 
571
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
571
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
572 572
 
573
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
574
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
575
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
576
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
577
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
573
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
574
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
575
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
576
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
577
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
578 578
 
579
-    $message_body   = str_replace( '{customer_note}', $args['user_note'], $message_body );
579
+    $message_body   = str_replace('{customer_note}', $args['user_note'], $message_body);
580 580
 
581
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
581
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
582 582
             'invoice'       => $invoice,
583 583
             'email_type'    => $email_type,
584 584
             'email_heading' => $email_heading,
@@ -586,36 +586,36 @@  discard block
 block discarded – undo
586 586
             'plain_text'    => false,
587 587
             'message_body'  => $message_body,
588 588
             'customer_note' => $args['user_note']
589
-        ) );
589
+        ));
590 590
 
591
-    $content        = wpinv_email_format_text( $content, $invoice );
591
+    $content = wpinv_email_format_text($content, $invoice);
592 592
 
593
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
593
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments, $extra);
594 594
 
595
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
595
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
596 596
 
597 597
     return $sent;
598 598
 }
599 599
 
600 600
 function wpinv_mail_get_from_address() {
601
-    $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) );
602
-    return sanitize_email( $from_address );
601
+    $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from'));
602
+    return sanitize_email($from_address);
603 603
 }
604 604
 
605 605
 function wpinv_mail_get_from_name() {
606
-    $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) );
607
-    return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES );
606
+    $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name'));
607
+    return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES);
608 608
 }
609 609
 
610
-function wpinv_mail_admin_bcc_active( $mail_type = '' ) {
611
-    $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) );
612
-    return ( $active ? true : false );
610
+function wpinv_mail_admin_bcc_active($mail_type = '') {
611
+    $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc'));
612
+    return ($active ? true : false);
613 613
 }
614 614
     
615
-function wpinv_mail_get_content_type(  $content_type = 'text/html', $email_type = 'html' ) {
616
-    $email_type = apply_filters( 'wpinv_mail_content_type', $email_type );
615
+function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') {
616
+    $email_type = apply_filters('wpinv_mail_content_type', $email_type);
617 617
 
618
-    switch ( $email_type ) {
618
+    switch ($email_type) {
619 619
         case 'html' :
620 620
             $content_type = 'text/html';
621 621
             break;
@@ -630,43 +630,43 @@  discard block
 block discarded – undo
630 630
     return $content_type;
631 631
 }
632 632
     
633
-function wpinv_mail_send( $to, $subject, $message, $headers, $attachments, $cc = array() ) {
634
-    add_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
635
-    add_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
636
-    add_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
633
+function wpinv_mail_send($to, $subject, $message, $headers, $attachments, $cc = array()) {
634
+    add_filter('wp_mail_from', 'wpinv_mail_get_from_address');
635
+    add_filter('wp_mail_from_name', 'wpinv_mail_get_from_name');
636
+    add_filter('wp_mail_content_type', 'wpinv_mail_get_content_type');
637 637
 
638
-    $message = wpinv_email_style_body( $message );
639
-    $message = apply_filters( 'wpinv_mail_content', $message );
638
+    $message = wpinv_email_style_body($message);
639
+    $message = apply_filters('wpinv_mail_content', $message);
640 640
 
641
-    if ( ! empty( $cc ) && is_array( $cc ) ) {
642
-        if ( ! is_array( $to ) ) {
643
-            $to = array( $to );
641
+    if (!empty($cc) && is_array($cc)) {
642
+        if (!is_array($to)) {
643
+            $to = array($to);
644 644
         }
645 645
 
646
-        $to = array_unique( array_merge( $to, $cc ) );
646
+        $to = array_unique(array_merge($to, $cc));
647 647
     }
648 648
 
649
-    $sent  = wp_mail( $to, $subject, $message, $headers, $attachments );
649
+    $sent = wp_mail($to, $subject, $message, $headers, $attachments);
650 650
 
651
-    if ( !$sent ) {
652
-        $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), ( is_array( $to ) ? implode( ', ', $to ) : $to ), $subject );
653
-        wpinv_error_log( $log_message, __( "Email from Invoicing plugin failed to send", 'invoicing' ), __FILE__, __LINE__ );
651
+    if (!$sent) {
652
+        $log_message = wp_sprintf(__("\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), (is_array($to) ? implode(', ', $to) : $to), $subject);
653
+        wpinv_error_log($log_message, __("Email from Invoicing plugin failed to send", 'invoicing'), __FILE__, __LINE__);
654 654
     }
655 655
 
656
-    remove_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
657
-    remove_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
658
-    remove_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
656
+    remove_filter('wp_mail_from', 'wpinv_mail_get_from_address');
657
+    remove_filter('wp_mail_from_name', 'wpinv_mail_get_from_name');
658
+    remove_filter('wp_mail_content_type', 'wpinv_mail_get_content_type');
659 659
 
660 660
     return $sent;
661 661
 }
662 662
     
663 663
 function wpinv_get_emails() {
664 664
     $overdue_days_options       = array();
665
-    $overdue_days_options[0]    = __( 'On the Due Date', 'invoicing' );
666
-    $overdue_days_options[1]    = __( '1 day after Due Date', 'invoicing' );
665
+    $overdue_days_options[0]    = __('On the Due Date', 'invoicing');
666
+    $overdue_days_options[1]    = __('1 day after Due Date', 'invoicing');
667 667
 
668
-    for ( $i = 2; $i <= 10; $i++ ) {
669
-        $overdue_days_options[$i]   = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i );
668
+    for ($i = 2; $i <= 10; $i++) {
669
+        $overdue_days_options[$i] = wp_sprintf(__('%d days after Due Date', 'invoicing'), $i);
670 670
     }
671 671
 
672 672
     // Default, built-in gateways
@@ -674,39 +674,39 @@  discard block
 block discarded – undo
674 674
             'new_invoice' => array(
675 675
             'email_new_invoice_header' => array(
676 676
                 'id'   => 'email_new_invoice_header',
677
-                'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>',
678
-                'desc' => __( 'New invoice emails are sent to admin when a new invoice is received.', 'invoicing' ),
677
+                'name' => '<h3>' . __('New Invoice', 'invoicing') . '</h3>',
678
+                'desc' => __('New invoice emails are sent to admin when a new invoice is received.', 'invoicing'),
679 679
                 'type' => 'header',
680 680
             ),
681 681
             'email_new_invoice_active' => array(
682 682
                 'id'   => 'email_new_invoice_active',
683
-                'name' => __( 'Enable/Disable', 'invoicing' ),
684
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
683
+                'name' => __('Enable/Disable', 'invoicing'),
684
+                'desc' => __('Enable this email notification', 'invoicing'),
685 685
                 'type' => 'checkbox',
686 686
                 'std'  => 1
687 687
             ),
688 688
             'email_new_invoice_subject' => array(
689 689
                 'id'   => 'email_new_invoice_subject',
690
-                'name' => __( 'Subject', 'invoicing' ),
691
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
690
+                'name' => __('Subject', 'invoicing'),
691
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
692 692
                 'type' => 'text',
693
-                'std'  => __( '[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing' ),
693
+                'std'  => __('[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing'),
694 694
                 'size' => 'large'
695 695
             ),
696 696
             'email_new_invoice_heading' => array(
697 697
                 'id'   => 'email_new_invoice_heading',
698
-                'name' => __( 'Email Heading', 'invoicing' ),
699
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
698
+                'name' => __('Email Heading', 'invoicing'),
699
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
700 700
                 'type' => 'text',
701
-                'std'  => __( 'New payment invoice', 'invoicing' ),
701
+                'std'  => __('New payment invoice', 'invoicing'),
702 702
                 'size' => 'large'
703 703
             ),
704 704
             'email_new_invoice_body' => array(
705 705
                 'id'   => 'email_new_invoice_body',
706
-                'name' => __( 'Email Content', 'invoicing' ),
707
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
706
+                'name' => __('Email Content', 'invoicing'),
707
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
708 708
                 'type' => 'rich_editor',
709
-                'std'  => __( '<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing' ),
709
+                'std'  => __('<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing'),
710 710
                 'class' => 'large',
711 711
                 'size' => '10'
712 712
             ),
@@ -714,39 +714,39 @@  discard block
 block discarded – undo
714 714
         'cancelled_invoice' => array(
715 715
             'email_cancelled_invoice_header' => array(
716 716
                 'id'   => 'email_cancelled_invoice_header',
717
-                'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>',
718
-                'desc' => __( 'Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing' ),
717
+                'name' => '<h3>' . __('Cancelled Invoice', 'invoicing') . '</h3>',
718
+                'desc' => __('Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing'),
719 719
                 'type' => 'header',
720 720
             ),
721 721
             'email_cancelled_invoice_active' => array(
722 722
                 'id'   => 'email_cancelled_invoice_active',
723
-                'name' => __( 'Enable/Disable', 'invoicing' ),
724
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
723
+                'name' => __('Enable/Disable', 'invoicing'),
724
+                'desc' => __('Enable this email notification', 'invoicing'),
725 725
                 'type' => 'checkbox',
726 726
                 'std'  => 1
727 727
             ),
728 728
             'email_cancelled_invoice_subject' => array(
729 729
                 'id'   => 'email_cancelled_invoice_subject',
730
-                'name' => __( 'Subject', 'invoicing' ),
731
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
730
+                'name' => __('Subject', 'invoicing'),
731
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
732 732
                 'type' => 'text',
733
-                'std'  => __( '[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing' ),
733
+                'std'  => __('[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing'),
734 734
                 'size' => 'large'
735 735
             ),
736 736
             'email_cancelled_invoice_heading' => array(
737 737
                 'id'   => 'email_cancelled_invoice_heading',
738
-                'name' => __( 'Email Heading', 'invoicing' ),
739
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
738
+                'name' => __('Email Heading', 'invoicing'),
739
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
740 740
                 'type' => 'text',
741
-                'std'  => __( 'Cancelled invoice', 'invoicing' ),
741
+                'std'  => __('Cancelled invoice', 'invoicing'),
742 742
                 'size' => 'large'
743 743
             ),
744 744
             'email_cancelled_invoice_body' => array(
745 745
                 'id'   => 'email_cancelled_invoice_body',
746
-                'name' => __( 'Email Content', 'invoicing' ),
747
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
746
+                'name' => __('Email Content', 'invoicing'),
747
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
748 748
                 'type' => 'rich_editor',
749
-                'std'  => __( '<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing' ),
749
+                'std'  => __('<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing'),
750 750
                 'class' => 'large',
751 751
                 'size' => '10'
752 752
             ),
@@ -754,39 +754,39 @@  discard block
 block discarded – undo
754 754
         'failed_invoice' => array(
755 755
             'email_failed_invoice_header' => array(
756 756
                 'id'   => 'email_failed_invoice_header',
757
-                'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>',
758
-                'desc' => __( 'Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing' ),
757
+                'name' => '<h3>' . __('Failed Invoice', 'invoicing') . '</h3>',
758
+                'desc' => __('Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing'),
759 759
                 'type' => 'header',
760 760
             ),
761 761
             'email_failed_invoice_active' => array(
762 762
                 'id'   => 'email_failed_invoice_active',
763
-                'name' => __( 'Enable/Disable', 'invoicing' ),
764
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
763
+                'name' => __('Enable/Disable', 'invoicing'),
764
+                'desc' => __('Enable this email notification', 'invoicing'),
765 765
                 'type' => 'checkbox',
766 766
                 'std'  => 1
767 767
             ),
768 768
             'email_failed_invoice_subject' => array(
769 769
                 'id'   => 'email_failed_invoice_subject',
770
-                'name' => __( 'Subject', 'invoicing' ),
771
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
770
+                'name' => __('Subject', 'invoicing'),
771
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
772 772
                 'type' => 'text',
773
-                'std'  => __( '[{site_title}] Failed invoice ({invoice_number})', 'invoicing' ),
773
+                'std'  => __('[{site_title}] Failed invoice ({invoice_number})', 'invoicing'),
774 774
                 'size' => 'large'
775 775
             ),
776 776
             'email_failed_invoice_heading' => array(
777 777
                 'id'   => 'email_failed_invoice_heading',
778
-                'name' => __( 'Email Heading', 'invoicing' ),
779
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
778
+                'name' => __('Email Heading', 'invoicing'),
779
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
780 780
                 'type' => 'text',
781
-                'std'  => __( 'Failed invoice', 'invoicing' ),
781
+                'std'  => __('Failed invoice', 'invoicing'),
782 782
                 'size' => 'large'
783 783
             ),
784 784
             'email_failed_invoice_body' => array(
785 785
                 'id'   => 'email_failed_invoice_body',
786
-                'name' => __( 'Email Content', 'invoicing' ),
787
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
786
+                'name' => __('Email Content', 'invoicing'),
787
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
788 788
                 'type' => 'rich_editor',
789
-                'std'  => __( '<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing' ),
789
+                'std'  => __('<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing'),
790 790
                 'class' => 'large',
791 791
                 'size' => '10'
792 792
             ),
@@ -794,46 +794,46 @@  discard block
 block discarded – undo
794 794
         'onhold_invoice' => array(
795 795
             'email_onhold_invoice_header' => array(
796 796
                 'id'   => 'email_onhold_invoice_header',
797
-                'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>',
798
-                'desc' => __( 'This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing' ),
797
+                'name' => '<h3>' . __('On Hold Invoice', 'invoicing') . '</h3>',
798
+                'desc' => __('This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing'),
799 799
                 'type' => 'header',
800 800
             ),
801 801
             'email_onhold_invoice_active' => array(
802 802
                 'id'   => 'email_onhold_invoice_active',
803
-                'name' => __( 'Enable/Disable', 'invoicing' ),
804
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
803
+                'name' => __('Enable/Disable', 'invoicing'),
804
+                'desc' => __('Enable this email notification', 'invoicing'),
805 805
                 'type' => 'checkbox',
806 806
                 'std'  => 1
807 807
             ),
808 808
             'email_onhold_invoice_subject' => array(
809 809
                 'id'   => 'email_onhold_invoice_subject',
810
-                'name' => __( 'Subject', 'invoicing' ),
811
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
810
+                'name' => __('Subject', 'invoicing'),
811
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
812 812
                 'type' => 'text',
813
-                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
813
+                'std'  => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'),
814 814
                 'size' => 'large'
815 815
             ),
816 816
             'email_onhold_invoice_heading' => array(
817 817
                 'id'   => 'email_onhold_invoice_heading',
818
-                'name' => __( 'Email Heading', 'invoicing' ),
819
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
818
+                'name' => __('Email Heading', 'invoicing'),
819
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
820 820
                 'type' => 'text',
821
-                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
821
+                'std'  => __('Thank you for your invoice', 'invoicing'),
822 822
                 'size' => 'large'
823 823
             ),
824 824
             'email_onhold_invoice_admin_bcc' => array(
825 825
                 'id'   => 'email_onhold_invoice_admin_bcc',
826
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
827
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
826
+                'name' => __('Enable Admin BCC', 'invoicing'),
827
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
828 828
                 'type' => 'checkbox',
829 829
                 'std'  => 1
830 830
             ),
831 831
             'email_onhold_invoice_body' => array(
832 832
                 'id'   => 'email_onhold_invoice_body',
833
-                'name' => __( 'Email Content', 'invoicing' ),
834
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
833
+                'name' => __('Email Content', 'invoicing'),
834
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
835 835
                 'type' => 'rich_editor',
836
-                'std'  => __( '<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing' ),
836
+                'std'  => __('<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing'),
837 837
                 'class' => 'large',
838 838
                 'size' => '10'
839 839
             ),
@@ -841,46 +841,46 @@  discard block
 block discarded – undo
841 841
         'processing_invoice' => array(
842 842
             'email_processing_invoice_header' => array(
843 843
                 'id'   => 'email_processing_invoice_header',
844
-                'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>',
845
-                'desc' => __( 'This is an invoice notification sent to users containing invoice details after payment.', 'invoicing' ),
844
+                'name' => '<h3>' . __('Processing Invoice', 'invoicing') . '</h3>',
845
+                'desc' => __('This is an invoice notification sent to users containing invoice details after payment.', 'invoicing'),
846 846
                 'type' => 'header',
847 847
             ),
848 848
             'email_processing_invoice_active' => array(
849 849
                 'id'   => 'email_processing_invoice_active',
850
-                'name' => __( 'Enable/Disable', 'invoicing' ),
851
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
850
+                'name' => __('Enable/Disable', 'invoicing'),
851
+                'desc' => __('Enable this email notification', 'invoicing'),
852 852
                 'type' => 'checkbox',
853 853
                 'std'  => 1
854 854
             ),
855 855
             'email_processing_invoice_subject' => array(
856 856
                 'id'   => 'email_processing_invoice_subject',
857
-                'name' => __( 'Subject', 'invoicing' ),
858
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
857
+                'name' => __('Subject', 'invoicing'),
858
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
859 859
                 'type' => 'text',
860
-                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
860
+                'std'  => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'),
861 861
                 'size' => 'large'
862 862
             ),
863 863
             'email_processing_invoice_heading' => array(
864 864
                 'id'   => 'email_processing_invoice_heading',
865
-                'name' => __( 'Email Heading', 'invoicing' ),
866
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
865
+                'name' => __('Email Heading', 'invoicing'),
866
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
867 867
                 'type' => 'text',
868
-                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
868
+                'std'  => __('Thank you for your invoice', 'invoicing'),
869 869
                 'size' => 'large'
870 870
             ),
871 871
             'email_processing_invoice_admin_bcc' => array(
872 872
                 'id'   => 'email_processing_invoice_admin_bcc',
873
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
874
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
873
+                'name' => __('Enable Admin BCC', 'invoicing'),
874
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
875 875
                 'type' => 'checkbox',
876 876
                 'std'  => 1
877 877
             ),
878 878
             'email_processing_invoice_body' => array(
879 879
                 'id'   => 'email_processing_invoice_body',
880
-                'name' => __( 'Email Content', 'invoicing' ),
881
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
880
+                'name' => __('Email Content', 'invoicing'),
881
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
882 882
                 'type' => 'rich_editor',
883
-                'std'  => __( '<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing' ),
883
+                'std'  => __('<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing'),
884 884
                 'class' => 'large',
885 885
                 'size' => '10'
886 886
             ),
@@ -888,52 +888,52 @@  discard block
 block discarded – undo
888 888
         'completed_invoice' => array(
889 889
             'email_completed_invoice_header' => array(
890 890
                 'id'   => 'email_completed_invoice_header',
891
-                'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>',
892
-                'desc' => __( 'Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing' ),
891
+                'name' => '<h3>' . __('Paid Invoice', 'invoicing') . '</h3>',
892
+                'desc' => __('Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing'),
893 893
                 'type' => 'header',
894 894
             ),
895 895
             'email_completed_invoice_active' => array(
896 896
                 'id'   => 'email_completed_invoice_active',
897
-                'name' => __( 'Enable/Disable', 'invoicing' ),
898
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
897
+                'name' => __('Enable/Disable', 'invoicing'),
898
+                'desc' => __('Enable this email notification', 'invoicing'),
899 899
                 'type' => 'checkbox',
900 900
                 'std'  => 1
901 901
             ),
902 902
             'email_completed_invoice_renewal_active' => array(
903 903
                 'id'   => 'email_completed_invoice_renewal_active',
904
-                'name' => __( 'Enable renewal notification', 'invoicing' ),
905
-                'desc' => __( 'Enable renewal invoice email notification. This notification will be sent on renewal.', 'invoicing' ),
904
+                'name' => __('Enable renewal notification', 'invoicing'),
905
+                'desc' => __('Enable renewal invoice email notification. This notification will be sent on renewal.', 'invoicing'),
906 906
                 'type' => 'checkbox',
907 907
                 'std'  => 0
908 908
             ),
909 909
             'email_completed_invoice_subject' => array(
910 910
                 'id'   => 'email_completed_invoice_subject',
911
-                'name' => __( 'Subject', 'invoicing' ),
912
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
911
+                'name' => __('Subject', 'invoicing'),
912
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
913 913
                 'type' => 'text',
914
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ),
914
+                'std'  => __('[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing'),
915 915
                 'size' => 'large'
916 916
             ),
917 917
             'email_completed_invoice_heading' => array(
918 918
                 'id'   => 'email_completed_invoice_heading',
919
-                'name' => __( 'Email Heading', 'invoicing' ),
920
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
919
+                'name' => __('Email Heading', 'invoicing'),
920
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
921 921
                 'type' => 'text',
922
-                'std'  => __( 'Your invoice has been paid', 'invoicing' ),
922
+                'std'  => __('Your invoice has been paid', 'invoicing'),
923 923
                 'size' => 'large'
924 924
             ),
925 925
             'email_completed_invoice_admin_bcc' => array(
926 926
                 'id'   => 'email_completed_invoice_admin_bcc',
927
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
928
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
927
+                'name' => __('Enable Admin BCC', 'invoicing'),
928
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
929 929
                 'type' => 'checkbox',
930 930
             ),
931 931
             'email_completed_invoice_body' => array(
932 932
                 'id'   => 'email_completed_invoice_body',
933
-                'name' => __( 'Email Content', 'invoicing' ),
934
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
933
+                'name' => __('Email Content', 'invoicing'),
934
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
935 935
                 'type' => 'rich_editor',
936
-                'std'  => __( '<p>Hi {name},</p><p>Your recent invoice on {site_title} has been paid.</p>', 'invoicing' ),
936
+                'std'  => __('<p>Hi {name},</p><p>Your recent invoice on {site_title} has been paid.</p>', 'invoicing'),
937 937
                 'class' => 'large',
938 938
                 'size' => '10'
939 939
             ),
@@ -942,46 +942,46 @@  discard block
 block discarded – undo
942 942
         'refunded_invoice' => array(
943 943
             'email_refunded_invoice_header' => array(
944 944
                 'id'   => 'email_refunded_invoice_header',
945
-                'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>',
946
-                'desc' => __( 'Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing' ),
945
+                'name' => '<h3>' . __('Refunded Invoice', 'invoicing') . '</h3>',
946
+                'desc' => __('Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing'),
947 947
                 'type' => 'header',
948 948
             ),
949 949
             'email_refunded_invoice_active' => array(
950 950
                 'id'   => 'email_refunded_invoice_active',
951
-                'name' => __( 'Enable/Disable', 'invoicing' ),
952
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
951
+                'name' => __('Enable/Disable', 'invoicing'),
952
+                'desc' => __('Enable this email notification', 'invoicing'),
953 953
                 'type' => 'checkbox',
954 954
                 'std'  => 1
955 955
             ),
956 956
             'email_refunded_invoice_subject' => array(
957 957
                 'id'   => 'email_refunded_invoice_subject',
958
-                'name' => __( 'Subject', 'invoicing' ),
959
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
958
+                'name' => __('Subject', 'invoicing'),
959
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
960 960
                 'type' => 'text',
961
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ),
961
+                'std'  => __('[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing'),
962 962
                 'size' => 'large'
963 963
             ),
964 964
             'email_refunded_invoice_heading' => array(
965 965
                 'id'   => 'email_refunded_invoice_heading',
966
-                'name' => __( 'Email Heading', 'invoicing' ),
967
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
966
+                'name' => __('Email Heading', 'invoicing'),
967
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
968 968
                 'type' => 'text',
969
-                'std'  => __( 'Your invoice has been refunded', 'invoicing' ),
969
+                'std'  => __('Your invoice has been refunded', 'invoicing'),
970 970
                 'size' => 'large'
971 971
             ),
972 972
             'email_refunded_invoice_admin_bcc' => array(
973 973
                 'id'   => 'email_refunded_invoice_admin_bcc',
974
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
975
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
974
+                'name' => __('Enable Admin BCC', 'invoicing'),
975
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
976 976
                 'type' => 'checkbox',
977 977
                 'std'  => 1
978 978
             ),
979 979
             'email_refunded_invoice_body' => array(
980 980
                 'id'   => 'email_refunded_invoice_body',
981
-                'name' => __( 'Email Content', 'invoicing' ),
982
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
981
+                'name' => __('Email Content', 'invoicing'),
982
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
983 983
                 'type' => 'rich_editor',
984
-                'std'  => __( '<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing' ),
984
+                'std'  => __('<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing'),
985 985
                 'class' => 'large',
986 986
                 'size' => '10'
987 987
             ),
@@ -989,46 +989,46 @@  discard block
 block discarded – undo
989 989
         'user_invoice' => array(
990 990
             'email_user_invoice_header' => array(
991 991
                 'id'   => 'email_user_invoice_header',
992
-                'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>',
993
-                'desc' => __( 'Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing' ),
992
+                'name' => '<h3>' . __('Customer Invoice', 'invoicing') . '</h3>',
993
+                'desc' => __('Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing'),
994 994
                 'type' => 'header',
995 995
             ),
996 996
             'email_user_invoice_active' => array(
997 997
                 'id'   => 'email_user_invoice_active',
998
-                'name' => __( 'Enable/Disable', 'invoicing' ),
999
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
998
+                'name' => __('Enable/Disable', 'invoicing'),
999
+                'desc' => __('Enable this email notification', 'invoicing'),
1000 1000
                 'type' => 'checkbox',
1001 1001
                 'std'  => 1
1002 1002
             ),
1003 1003
             'email_user_invoice_subject' => array(
1004 1004
                 'id'   => 'email_user_invoice_subject',
1005
-                'name' => __( 'Subject', 'invoicing' ),
1006
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1005
+                'name' => __('Subject', 'invoicing'),
1006
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
1007 1007
                 'type' => 'text',
1008
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ),
1008
+                'std'  => __('[{site_title}] Your invoice from {invoice_date}', 'invoicing'),
1009 1009
                 'size' => 'large'
1010 1010
             ),
1011 1011
             'email_user_invoice_heading' => array(
1012 1012
                 'id'   => 'email_user_invoice_heading',
1013
-                'name' => __( 'Email Heading', 'invoicing' ),
1014
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
1013
+                'name' => __('Email Heading', 'invoicing'),
1014
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
1015 1015
                 'type' => 'text',
1016
-                'std'  => __( 'Your invoice {invoice_number} details', 'invoicing' ),
1016
+                'std'  => __('Your invoice {invoice_number} details', 'invoicing'),
1017 1017
                 'size' => 'large'
1018 1018
             ),
1019 1019
             'email_user_invoice_admin_bcc' => array(
1020 1020
                 'id'   => 'email_user_invoice_admin_bcc',
1021
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
1022
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
1021
+                'name' => __('Enable Admin BCC', 'invoicing'),
1022
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
1023 1023
                 'type' => 'checkbox',
1024 1024
                 'std'  => 1
1025 1025
             ),
1026 1026
             'email_user_invoice_body' => array(
1027 1027
                 'id'   => 'email_user_invoice_body',
1028
-                'name' => __( 'Email Content', 'invoicing' ),
1029
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
1028
+                'name' => __('Email Content', 'invoicing'),
1029
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
1030 1030
                 'type' => 'rich_editor',
1031
-                'std'  => __( '<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ),
1031
+                'std'  => __('<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'),
1032 1032
                 'class' => 'large',
1033 1033
                 'size' => '10'
1034 1034
             ),
@@ -1036,39 +1036,39 @@  discard block
 block discarded – undo
1036 1036
         'user_note' => array(
1037 1037
             'email_user_note_header' => array(
1038 1038
                 'id'   => 'email_user_note_header',
1039
-                'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>',
1040
-                'desc' => __( 'Customer note emails are sent when you add a note to an invoice/quote.', 'invoicing' ),
1039
+                'name' => '<h3>' . __('Customer Note', 'invoicing') . '</h3>',
1040
+                'desc' => __('Customer note emails are sent when you add a note to an invoice/quote.', 'invoicing'),
1041 1041
                 'type' => 'header',
1042 1042
             ),
1043 1043
             'email_user_note_active' => array(
1044 1044
                 'id'   => 'email_user_note_active',
1045
-                'name' => __( 'Enable/Disable', 'invoicing' ),
1046
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
1045
+                'name' => __('Enable/Disable', 'invoicing'),
1046
+                'desc' => __('Enable this email notification', 'invoicing'),
1047 1047
                 'type' => 'checkbox',
1048 1048
                 'std'  => 1
1049 1049
             ),
1050 1050
             'email_user_note_subject' => array(
1051 1051
                 'id'   => 'email_user_note_subject',
1052
-                'name' => __( 'Subject', 'invoicing' ),
1053
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1052
+                'name' => __('Subject', 'invoicing'),
1053
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
1054 1054
                 'type' => 'text',
1055
-                'std'  => __( '[{site_title}] Note added to your {invoice_label} #{invoice_number} from {invoice_date}', 'invoicing' ),
1055
+                'std'  => __('[{site_title}] Note added to your {invoice_label} #{invoice_number} from {invoice_date}', 'invoicing'),
1056 1056
                 'size' => 'large'
1057 1057
             ),
1058 1058
             'email_user_note_heading' => array(
1059 1059
                 'id'   => 'email_user_note_heading',
1060
-                'name' => __( 'Email Heading', 'invoicing' ),
1061
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1060
+                'name' => __('Email Heading', 'invoicing'),
1061
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
1062 1062
                 'type' => 'text',
1063
-                'std'  => __( 'A note has been added to your {invoice_label}', 'invoicing' ),
1063
+                'std'  => __('A note has been added to your {invoice_label}', 'invoicing'),
1064 1064
                 'size' => 'large'
1065 1065
             ),
1066 1066
             'email_user_note_body' => array(
1067 1067
                 'id'   => 'email_user_note_body',
1068
-                'name' => __( 'Email Content', 'invoicing' ),
1069
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
1068
+                'name' => __('Email Content', 'invoicing'),
1069
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
1070 1070
                 'type' => 'rich_editor',
1071
-                'std'  => __( '<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing' ),
1071
+                'std'  => __('<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing'),
1072 1072
                 'class' => 'large',
1073 1073
                 'size' => '10'
1074 1074
             ),
@@ -1077,54 +1077,54 @@  discard block
 block discarded – undo
1077 1077
         'pre_payment' => array(
1078 1078
             'email_pre_payment_header' => array(
1079 1079
                 'id'   => 'email_pre_payment_header',
1080
-                'name' => '<h3>' . __( 'Renewal Reminder', 'invoicing' ) . '</h3>',
1081
-                'desc' => __( 'Renewal reminder emails are sent to user automatically.', 'invoicing' ),
1080
+                'name' => '<h3>' . __('Renewal Reminder', 'invoicing') . '</h3>',
1081
+                'desc' => __('Renewal reminder emails are sent to user automatically.', 'invoicing'),
1082 1082
                 'type' => 'header',
1083 1083
             ),
1084 1084
             'email_pre_payment_active' => array(
1085 1085
                 'id'   => 'email_pre_payment_active',
1086
-                'name' => __( 'Enable/Disable', 'invoicing' ),
1087
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
1086
+                'name' => __('Enable/Disable', 'invoicing'),
1087
+                'desc' => __('Enable this email notification', 'invoicing'),
1088 1088
                 'type' => 'checkbox',
1089 1089
                 'std'  => 1
1090 1090
             ),
1091 1091
             'email_pre_payment_reminder_days' => array(
1092 1092
                 'id'            => 'email_pre_payment_reminder_days',
1093
-                'name'          => __( 'When to Send', 'invoicing' ),
1094
-                'desc'          => __( 'Enter a comma separated list of days before renewal when this email should be sent.', 'invoicing' ),
1093
+                'name'          => __('When to Send', 'invoicing'),
1094
+                'desc'          => __('Enter a comma separated list of days before renewal when this email should be sent.', 'invoicing'),
1095 1095
                 'default'       => '',
1096 1096
                 'type'          => 'text',
1097 1097
                 'std'           => '1,5,10',
1098 1098
             ),
1099 1099
             'email_pre_payment_subject' => array(
1100 1100
                 'id'   => 'email_pre_payment_subject',
1101
-                'name' => __( 'Subject', 'invoicing' ),
1102
-                'desc' => __( 'Enter the subject line for the email.', 'invoicing' ),
1101
+                'name' => __('Subject', 'invoicing'),
1102
+                'desc' => __('Enter the subject line for the email.', 'invoicing'),
1103 1103
                 'type' => 'text',
1104
-                'std'  => __( '[{site_title}] Renewal Reminder', 'invoicing' ),
1104
+                'std'  => __('[{site_title}] Renewal Reminder', 'invoicing'),
1105 1105
                 'size' => 'large'
1106 1106
             ),
1107 1107
             'email_pre_payment_heading' => array(
1108 1108
                 'id'   => 'email_pre_payment_heading',
1109
-                'name' => __( 'Email Heading', 'invoicing' ),
1110
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1109
+                'name' => __('Email Heading', 'invoicing'),
1110
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
1111 1111
                 'type' => 'text',
1112
-                'std'  => __( 'Upcoming renewal reminder', 'invoicing' ),
1112
+                'std'  => __('Upcoming renewal reminder', 'invoicing'),
1113 1113
                 'size' => 'large'
1114 1114
             ),
1115 1115
             'email_pre_payment_admin_bcc' => array(
1116 1116
                 'id'   => 'email_pre_payment_admin_bcc',
1117
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
1118
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
1117
+                'name' => __('Enable Admin BCC', 'invoicing'),
1118
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
1119 1119
                 'type' => 'checkbox',
1120 1120
                 'std'  => 1
1121 1121
             ),
1122 1122
             'email_pre_payment_body' => array(
1123 1123
                 'id'   => 'email_pre_payment_body',
1124
-                'name' => __( 'Email Content', 'invoicing' ),
1125
-                'desc' => __( 'The content of the email.', 'invoicing' ),
1124
+                'name' => __('Email Content', 'invoicing'),
1125
+                'desc' => __('The content of the email.', 'invoicing'),
1126 1126
                 'type' => 'rich_editor',
1127
-                'std'  => __( '<p>Hi {full_name},</p><p>Your subscription for invoice <a href="{invoice_link}">#{invoice_number}</a> will renew on {subscription_renewal_date}.</p>', 'invoicing' ),
1127
+                'std'  => __('<p>Hi {full_name},</p><p>Your subscription for invoice <a href="{invoice_link}">#{invoice_number}</a> will renew on {subscription_renewal_date}.</p>', 'invoicing'),
1128 1128
                 'class' => 'large',
1129 1129
                 'size'  => 10,
1130 1130
             ),
@@ -1133,264 +1133,264 @@  discard block
 block discarded – undo
1133 1133
         'overdue' => array(
1134 1134
             'email_overdue_header' => array(
1135 1135
                 'id'   => 'email_overdue_header',
1136
-                'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>',
1137
-                'desc' => __( 'Payment reminder emails are sent to user automatically.', 'invoicing' ),
1136
+                'name' => '<h3>' . __('Payment Reminder', 'invoicing') . '</h3>',
1137
+                'desc' => __('Payment reminder emails are sent to user automatically.', 'invoicing'),
1138 1138
                 'type' => 'header',
1139 1139
             ),
1140 1140
             'email_overdue_active' => array(
1141 1141
                 'id'   => 'email_overdue_active',
1142
-                'name' => __( 'Enable/Disable', 'invoicing' ),
1143
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
1142
+                'name' => __('Enable/Disable', 'invoicing'),
1143
+                'desc' => __('Enable this email notification', 'invoicing'),
1144 1144
                 'type' => 'checkbox',
1145 1145
                 'std'  => 1
1146 1146
             ),
1147 1147
             'email_due_reminder_days' => array(
1148 1148
                 'id'        => 'email_due_reminder_days',
1149
-                'name'      => __( 'When to Send', 'invoicing' ),
1150
-                'desc'      => __( 'Check when you would like payment reminders sent out.', 'invoicing' ),
1149
+                'name'      => __('When to Send', 'invoicing'),
1150
+                'desc'      => __('Check when you would like payment reminders sent out.', 'invoicing'),
1151 1151
                 'default'   => '',
1152 1152
                 'type'      => 'multicheck',
1153 1153
                 'options'   => $overdue_days_options,
1154 1154
             ),
1155 1155
             'email_overdue_subject' => array(
1156 1156
                 'id'   => 'email_overdue_subject',
1157
-                'name' => __( 'Subject', 'invoicing' ),
1158
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1157
+                'name' => __('Subject', 'invoicing'),
1158
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
1159 1159
                 'type' => 'text',
1160
-                'std'  => __( '[{site_title}] Payment Reminder', 'invoicing' ),
1160
+                'std'  => __('[{site_title}] Payment Reminder', 'invoicing'),
1161 1161
                 'size' => 'large'
1162 1162
             ),
1163 1163
             'email_overdue_heading' => array(
1164 1164
                 'id'   => 'email_overdue_heading',
1165
-                'name' => __( 'Email Heading', 'invoicing' ),
1166
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1165
+                'name' => __('Email Heading', 'invoicing'),
1166
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
1167 1167
                 'type' => 'text',
1168
-                'std'  => __( 'Payment reminder for your invoice', 'invoicing' ),
1168
+                'std'  => __('Payment reminder for your invoice', 'invoicing'),
1169 1169
                 'size' => 'large'
1170 1170
             ),
1171 1171
             'email_overdue_admin_bcc' => array(
1172 1172
                 'id'   => 'email_overdue_admin_bcc',
1173
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
1174
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
1173
+                'name' => __('Enable Admin BCC', 'invoicing'),
1174
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
1175 1175
                 'type' => 'checkbox',
1176 1176
                 'std'  => 1
1177 1177
             ),
1178 1178
             'email_overdue_body' => array(
1179 1179
                 'id'   => 'email_overdue_body',
1180
-                'name' => __( 'Email Content', 'invoicing' ),
1181
-                'desc' => __( 'The content of the email.', 'invoicing' ),
1180
+                'name' => __('Email Content', 'invoicing'),
1181
+                'desc' => __('The content of the email.', 'invoicing'),
1182 1182
                 'type' => 'rich_editor',
1183
-                'std'  => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ),
1183
+                'std'  => __('<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'),
1184 1184
                 'class' => 'large',
1185 1185
                 'size'  => 10,
1186 1186
             ),
1187 1187
         ),
1188 1188
     );
1189 1189
 
1190
-    return apply_filters( 'wpinv_get_emails', $emails );
1190
+    return apply_filters('wpinv_get_emails', $emails);
1191 1191
 }
1192 1192
 
1193
-function wpinv_settings_emails( $settings = array() ) {
1193
+function wpinv_settings_emails($settings = array()) {
1194 1194
     $emails = wpinv_get_emails();
1195 1195
 
1196
-    if ( !empty( $emails ) ) {
1197
-        foreach ( $emails as $key => $email ) {
1196
+    if (!empty($emails)) {
1197
+        foreach ($emails as $key => $email) {
1198 1198
             $settings[$key] = $email;
1199 1199
         }
1200 1200
     }
1201 1201
 
1202
-    return apply_filters( 'wpinv_settings_get_emails', $settings );
1202
+    return apply_filters('wpinv_settings_get_emails', $settings);
1203 1203
 }
1204
-add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 );
1204
+add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1);
1205 1205
 
1206
-function wpinv_settings_sections_emails( $settings ) {
1206
+function wpinv_settings_sections_emails($settings) {
1207 1207
     $emails = wpinv_get_emails();
1208 1208
 
1209 1209
     if (!empty($emails)) {
1210
-        foreach  ($emails as $key => $email) {
1211
-            $settings[$key] = !empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : $key;
1210
+        foreach ($emails as $key => $email) {
1211
+            $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : $key;
1212 1212
         }
1213 1213
     }
1214 1214
 
1215 1215
     return $settings;    
1216 1216
 }
1217
-add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 );
1217
+add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1);
1218 1218
 
1219
-function wpinv_email_is_enabled( $email_type ) {
1219
+function wpinv_email_is_enabled($email_type) {
1220 1220
     $emails = wpinv_get_emails();
1221
-    $enabled = isset( $emails[$email_type] ) && wpinv_get_option( 'email_'. $email_type . '_active', 0 ) ? true : false;
1221
+    $enabled = isset($emails[$email_type]) && wpinv_get_option('email_' . $email_type . '_active', 0) ? true : false;
1222 1222
 
1223
-    return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type );
1223
+    return apply_filters('wpinv_email_is_enabled', $enabled, $email_type);
1224 1224
 }
1225 1225
 
1226
-function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1227
-    switch ( $email_type ) {
1226
+function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) {
1227
+    switch ($email_type) {
1228 1228
         case 'new_invoice':
1229 1229
         case 'cancelled_invoice':
1230 1230
         case 'failed_invoice':
1231 1231
             $recipient  = wpinv_get_admin_email();
1232 1232
         break;
1233 1233
         default:
1234
-            $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1235
-            $recipient  = !empty( $invoice ) ? $invoice->get_email() : '';
1234
+            $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1235
+            $recipient  = !empty($invoice) ? $invoice->get_email() : '';
1236 1236
         break;
1237 1237
     }
1238 1238
 
1239
-    return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice );
1239
+    return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice);
1240 1240
 }
1241 1241
 
1242 1242
 /**
1243 1243
  * Returns invoice CC recipients
1244 1244
  */
1245
-function wpinv_email_get_cc_recipients( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1246
-    switch ( $email_type ) {
1245
+function wpinv_email_get_cc_recipients($email_type = '', $invoice_id = 0, $invoice = array()) {
1246
+    switch ($email_type) {
1247 1247
         case 'new_invoice':
1248 1248
         case 'cancelled_invoice':
1249 1249
         case 'failed_invoice':
1250 1250
             return array();
1251 1251
         break;
1252 1252
         default:
1253
-            $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1254
-            $recipient  = empty( $invoice ) ? '' : get_post_meta( $invoice->ID, 'wpinv_email_cc', true );
1255
-            if ( empty( $recipient ) ) {
1253
+            $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1254
+            $recipient  = empty($invoice) ? '' : get_post_meta($invoice->ID, 'wpinv_email_cc', true);
1255
+            if (empty($recipient)) {
1256 1256
                 return array();
1257 1257
             }
1258
-            return  array_filter( array_map( 'trim', explode( ',', $recipient ) ) );
1258
+            return  array_filter(array_map('trim', explode(',', $recipient)));
1259 1259
         break;
1260 1260
     }
1261 1261
 
1262 1262
 }
1263 1263
 
1264
-function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1265
-    $subject    = wpinv_get_option( 'email_' . $email_type . '_subject' );
1266
-    $subject    = __( $subject, 'invoicing' );
1264
+function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) {
1265
+    $subject    = wpinv_get_option('email_' . $email_type . '_subject');
1266
+    $subject    = __($subject, 'invoicing');
1267 1267
 
1268
-    $subject    = wpinv_email_format_text( $subject, $invoice );
1268
+    $subject    = wpinv_email_format_text($subject, $invoice);
1269 1269
 
1270
-    return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice );
1270
+    return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice);
1271 1271
 }
1272 1272
 
1273
-function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1274
-    $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' );
1275
-    $email_heading = __( $email_heading, 'invoicing' );
1273
+function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) {
1274
+    $email_heading = wpinv_get_option('email_' . $email_type . '_heading');
1275
+    $email_heading = __($email_heading, 'invoicing');
1276 1276
 
1277
-    $email_heading = wpinv_email_format_text( $email_heading, $invoice );
1277
+    $email_heading = wpinv_email_format_text($email_heading, $invoice);
1278 1278
 
1279
-    return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice );
1279
+    return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice);
1280 1280
 }
1281 1281
 
1282
-function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1283
-    $content    = wpinv_get_option( 'email_' . $email_type . '_body' );
1284
-    $content    = __( $content, 'invoicing' );
1282
+function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) {
1283
+    $content    = wpinv_get_option('email_' . $email_type . '_body');
1284
+    $content    = __($content, 'invoicing');
1285 1285
 
1286
-    $content    = wpinv_email_format_text( $content, $invoice );
1286
+    $content    = wpinv_email_format_text($content, $invoice);
1287 1287
 
1288
-    return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice );
1288
+    return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice);
1289 1289
 }
1290 1290
 
1291
-function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1291
+function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) {
1292 1292
     $from_name = wpinv_mail_get_from_address();
1293 1293
     $from_email = wpinv_mail_get_from_address();
1294 1294
     
1295
-    $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1295
+    $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1296 1296
     
1297
-    $headers    = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
1298
-    $headers    .= "Reply-To: ". $from_email . "\r\n";
1297
+    $headers    = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n";
1298
+    $headers    .= "Reply-To: " . $from_email . "\r\n";
1299 1299
     $headers    .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n";
1300 1300
     
1301
-    return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice );
1301
+    return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice);
1302 1302
 }
1303 1303
 
1304
-function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1304
+function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) {
1305 1305
     $attachments = array();
1306 1306
     
1307
-    return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice );
1307
+    return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice);
1308 1308
 }
1309 1309
 
1310 1310
 /**
1311 1311
  * Searches for and replaces certain placeholders in an email.
1312 1312
  */
1313
-function wpinv_email_format_text( $content, $invoice ) {
1313
+function wpinv_email_format_text($content, $invoice) {
1314 1314
 
1315 1315
     $replace_array = array(
1316 1316
         '{site_title}'      => wpinv_get_blogname(),
1317
-        '{date}'            => date_i18n( get_option( 'date_format' ), (int) current_time( 'timestamp' ) ),
1317
+        '{date}'            => date_i18n(get_option('date_format'), (int) current_time('timestamp')),
1318 1318
     );
1319 1319
 
1320
-    $invoice = new WPInv_Invoice( $invoice );
1320
+    $invoice = new WPInv_Invoice($invoice);
1321 1321
 
1322
-    if ( $invoice->get_id() ) {
1322
+    if ($invoice->get_id()) {
1323 1323
 
1324 1324
         $replace_array = array_merge(
1325 1325
             $replace_array, 
1326 1326
             array(
1327
-                '{name}'            => sanitize_text_field( $invoice->get_user_full_name() ),
1328
-                '{full_name}'       => sanitize_text_field( $invoice->get_user_full_name() ),
1329
-                '{first_name}'      => sanitize_text_field( $invoice->get_first_name() ),
1330
-                '{last_name}'       => sanitize_text_field( $invoice->get_last_name() ),
1331
-                '{email}'           => sanitize_email( $invoice->get_email() ),
1332
-                '{invoice_number}'  => sanitize_text_field( $invoice->get_number() ),
1333
-                '{invoice_total}'   => wpinv_price( wpinv_format_amount( $invoice->get_total( true ) ) ),
1334
-                '{invoice_link}'    => esc_url( $invoice->get_view_url() ),
1335
-                '{invoice_pay_link}'=> esc_url( $invoice->get_checkout_payment_url() ),
1336
-                '{invoice_date}'    => date( get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ),
1337
-                '{invoice_due_date}'=> date( get_option( 'date_format' ), strtotime( $invoice->get_due_date(), current_time( 'timestamp' ) ) ),
1338
-                '{invoice_quote}'   => sanitize_text_field( $invoice->get_type() ),
1339
-                '{invoice_label}'   => sanitize_text_field( ucfirst( $invoice->get_type() ) ),
1340
-                '{is_was}'          => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
1327
+                '{name}'            => sanitize_text_field($invoice->get_user_full_name()),
1328
+                '{full_name}'       => sanitize_text_field($invoice->get_user_full_name()),
1329
+                '{first_name}'      => sanitize_text_field($invoice->get_first_name()),
1330
+                '{last_name}'       => sanitize_text_field($invoice->get_last_name()),
1331
+                '{email}'           => sanitize_email($invoice->get_email()),
1332
+                '{invoice_number}'  => sanitize_text_field($invoice->get_number()),
1333
+                '{invoice_total}'   => wpinv_price(wpinv_format_amount($invoice->get_total(true))),
1334
+                '{invoice_link}'    => esc_url($invoice->get_view_url()),
1335
+                '{invoice_pay_link}'=> esc_url($invoice->get_checkout_payment_url()),
1336
+                '{invoice_date}'    => date(get_option('date_format'), strtotime($invoice->get_date_created(), current_time('timestamp'))),
1337
+                '{invoice_due_date}'=> date(get_option('date_format'), strtotime($invoice->get_due_date(), current_time('timestamp'))),
1338
+                '{invoice_quote}'   => sanitize_text_field($invoice->get_type()),
1339
+                '{invoice_label}'   => sanitize_text_field(ucfirst($invoice->get_type())),
1340
+                '{is_was}'          => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'),
1341 1341
             )
1342 1342
         );
1343 1343
 
1344 1344
     }
1345 1345
 
1346 1346
     // Let third party plugins filter the arra.
1347
-    $replace_array = apply_filters( 'wpinv_email_format_text', $replace_array, $content, $invoice );
1347
+    $replace_array = apply_filters('wpinv_email_format_text', $replace_array, $content, $invoice);
1348 1348
 
1349
-    foreach ( $replace_array as $key => $value ) {
1350
-        $content = str_replace( $key, $value, $content );
1349
+    foreach ($replace_array as $key => $value) {
1350
+        $content = str_replace($key, $value, $content);
1351 1351
     }
1352 1352
 
1353
-    return apply_filters( 'wpinv_email_content_replace', $content );
1353
+    return apply_filters('wpinv_email_content_replace', $content);
1354 1354
 }
1355 1355
 
1356
-function wpinv_email_style_body( $content ) {
1356
+function wpinv_email_style_body($content) {
1357 1357
     // make sure we only inline CSS for html emails
1358
-    if ( in_array( wpinv_mail_get_content_type(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) {
1358
+    if (in_array(wpinv_mail_get_content_type(), array('text/html', 'multipart/alternative')) && class_exists('DOMDocument')) {
1359 1359
         ob_start();
1360
-        wpinv_get_template( 'emails/wpinv-email-styles.php' );
1361
-        $css = apply_filters( 'wpinv_email_styles', ob_get_clean() );
1360
+        wpinv_get_template('emails/wpinv-email-styles.php');
1361
+        $css = apply_filters('wpinv_email_styles', ob_get_clean());
1362 1362
 
1363 1363
         // apply CSS styles inline for picky email clients
1364 1364
         try {
1365
-            $emogrifier = new Emogrifier( $content, $css );
1365
+            $emogrifier = new Emogrifier($content, $css);
1366 1366
             $content    = $emogrifier->emogrify();
1367
-        } catch ( Exception $e ) {
1368
-            wpinv_error_log( $e->getMessage(), 'emogrifier' );
1367
+        } catch (Exception $e) {
1368
+            wpinv_error_log($e->getMessage(), 'emogrifier');
1369 1369
         }
1370 1370
     }
1371 1371
     return $content;
1372 1372
 }
1373 1373
 
1374
-function wpinv_email_header( $email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1375
-    wpinv_get_template( 'emails/wpinv-email-header.php', array( 'email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1374
+function wpinv_email_header($email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false) {
1375
+    wpinv_get_template('emails/wpinv-email-header.php', array('email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1376 1376
 }
1377 1377
 
1378 1378
 /**
1379 1379
  * Get the email footer.
1380 1380
  */
1381
-function wpinv_email_footer( $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1382
-    wpinv_get_template( 'emails/wpinv-email-footer.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1381
+function wpinv_email_footer($invoice = array(), $email_type = '', $sent_to_admin = false) {
1382
+    wpinv_get_template('emails/wpinv-email-footer.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1383 1383
 }
1384 1384
 
1385
-function wpinv_email_wrap_message( $message ) {
1385
+function wpinv_email_wrap_message($message) {
1386 1386
     // Buffer
1387 1387
     ob_start();
1388 1388
 
1389
-    do_action( 'wpinv_email_header' );
1389
+    do_action('wpinv_email_header');
1390 1390
 
1391
-    echo wpautop( wptexturize( $message ) );
1391
+    echo wpautop(wptexturize($message));
1392 1392
 
1393
-    do_action( 'wpinv_email_footer' );
1393
+    do_action('wpinv_email_footer');
1394 1394
 
1395 1395
     // Get contents
1396 1396
     $message = ob_get_clean();
@@ -1398,8 +1398,8 @@  discard block
 block discarded – undo
1398 1398
     return $message;
1399 1399
 }
1400 1400
 
1401
-function wpinv_email_invoice_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1402
-    wpinv_get_template( 'emails/wpinv-email-invoice-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1401
+function wpinv_email_invoice_details($invoice, $email_type = '', $sent_to_admin = false) {
1402
+    wpinv_get_template('emails/wpinv-email-invoice-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1403 1403
 }
1404 1404
 
1405 1405
 /**
@@ -1409,102 +1409,102 @@  discard block
 block discarded – undo
1409 1409
  * @param string $email_type
1410 1410
  * @param bool $sent_to_admin
1411 1411
  */
1412
-function wpinv_email_invoice_items( $invoice, $email_type = '', $sent_to_admin = false ) {
1412
+function wpinv_email_invoice_items($invoice, $email_type = '', $sent_to_admin = false) {
1413 1413
 
1414 1414
     // Prepare the invoice.
1415
-    $invoice = new WPInv_Invoice( $invoice );
1415
+    $invoice = new WPInv_Invoice($invoice);
1416 1416
 
1417 1417
     // Abort if there is no invoice.
1418
-    if ( 0 == $invoice->get_id() ) {
1418
+    if (0 == $invoice->get_id()) {
1419 1419
         return;
1420 1420
     }
1421 1421
 
1422 1422
     // Prepare line items.
1423
-    $columns = getpaid_invoice_item_columns( $invoice );
1424
-    $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice );
1423
+    $columns = getpaid_invoice_item_columns($invoice);
1424
+    $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice);
1425 1425
 
1426 1426
     // Load the template.
1427
-    wpinv_get_template( 'emails/wpinv-email-invoice-items.php', compact( 'invoice', 'columns', 'email_type', 'sent_to_admin' ) );
1427
+    wpinv_get_template('emails/wpinv-email-invoice-items.php', compact('invoice', 'columns', 'email_type', 'sent_to_admin'));
1428 1428
 }
1429 1429
 
1430
-function wpinv_email_billing_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1431
-    wpinv_get_template( 'emails/wpinv-email-billing-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1430
+function wpinv_email_billing_details($invoice, $email_type = '', $sent_to_admin = false) {
1431
+    wpinv_get_template('emails/wpinv-email-billing-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1432 1432
 }
1433 1433
 
1434
-function wpinv_send_customer_invoice( $data = array() ) {
1435
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1434
+function wpinv_send_customer_invoice($data = array()) {
1435
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1436 1436
 
1437
-    if ( empty( $invoice_id ) ) {
1437
+    if (empty($invoice_id)) {
1438 1438
         return;
1439 1439
     }
1440 1440
 
1441
-    if ( !wpinv_current_user_can_manage_invoicing() ) {
1442
-        wp_die( __( 'You do not have permission to send invoice notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1441
+    if (!wpinv_current_user_can_manage_invoicing()) {
1442
+        wp_die(__('You do not have permission to send invoice notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
1443 1443
     }
1444 1444
     
1445
-    $sent = wpinv_user_invoice_notification( $invoice_id );
1445
+    $sent = wpinv_user_invoice_notification($invoice_id);
1446 1446
 
1447 1447
     if ( -1 === $sent ) {
1448 1448
         $status = 'email_disabled';
1449
-    } elseif ( $sent ) {
1449
+    } elseif ($sent) {
1450 1450
         $status = 'email_sent';
1451 1451
     } else {
1452 1452
         $status = 'email_fail';
1453 1453
     }
1454 1454
 
1455
-    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1456
-    wp_redirect( $redirect );
1455
+    $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false));
1456
+    wp_redirect($redirect);
1457 1457
     exit;
1458 1458
 }
1459
-add_action( 'wpinv_send_invoice', 'wpinv_send_customer_invoice' );
1459
+add_action('wpinv_send_invoice', 'wpinv_send_customer_invoice');
1460 1460
 
1461
-function wpinv_send_overdue_reminder( $data = array() ) {
1462
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1461
+function wpinv_send_overdue_reminder($data = array()) {
1462
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1463 1463
 
1464
-    if ( empty( $invoice_id ) ) {
1464
+    if (empty($invoice_id)) {
1465 1465
         return;
1466 1466
     }
1467 1467
 
1468
-    if ( !wpinv_current_user_can_manage_invoicing() ) {
1469
-        wp_die( __( 'You do not have permission to send reminder notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1468
+    if (!wpinv_current_user_can_manage_invoicing()) {
1469
+        wp_die(__('You do not have permission to send reminder notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
1470 1470
     }
1471 1471
 
1472
-    $sent = wpinv_send_payment_reminder_notification( $invoice_id );
1472
+    $sent = wpinv_send_payment_reminder_notification($invoice_id);
1473 1473
     
1474 1474
     $status = $sent ? 'email_sent' : 'email_fail';
1475 1475
 
1476
-    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1477
-    wp_redirect( $redirect );
1476
+    $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false));
1477
+    wp_redirect($redirect);
1478 1478
     exit;
1479 1479
 }
1480
-add_action( 'wpinv_send_reminder', 'wpinv_send_overdue_reminder' );
1480
+add_action('wpinv_send_reminder', 'wpinv_send_overdue_reminder');
1481 1481
 
1482
-function wpinv_send_customer_note_email( $data ) {
1483
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1482
+function wpinv_send_customer_note_email($data) {
1483
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1484 1484
 
1485
-    if ( empty( $invoice_id ) ) {
1485
+    if (empty($invoice_id)) {
1486 1486
         return;
1487 1487
     }
1488 1488
 
1489
-    $sent = wpinv_user_note_notification( $invoice_id, $data );
1489
+    $sent = wpinv_user_note_notification($invoice_id, $data);
1490 1490
 }
1491
-add_action( 'wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1 );
1491
+add_action('wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1);
1492 1492
 
1493
-function wpinv_add_notes_to_invoice_email( $invoice, $email_type, $sent_to_admin ) {
1494
-    if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) {
1495
-        $date_format = get_option( 'date_format' );
1496
-        $time_format = get_option( 'time_format' );
1493
+function wpinv_add_notes_to_invoice_email($invoice, $email_type, $sent_to_admin) {
1494
+    if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->ID, true)) {
1495
+        $date_format = get_option('date_format');
1496
+        $time_format = get_option('time_format');
1497 1497
         ?>
1498 1498
         <div id="wpinv-email-notes">
1499
-            <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3>
1499
+            <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3>
1500 1500
             <ol class="wpinv-notes-lists">
1501 1501
         <?php
1502
-        foreach ( $invoice_notes as $note ) {
1503
-            $note_time = strtotime( $note->comment_date );
1502
+        foreach ($invoice_notes as $note) {
1503
+            $note_time = strtotime($note->comment_date);
1504 1504
             ?>
1505 1505
             <li class="comment wpinv-note">
1506
-            <p class="wpinv-note-date meta"><?php printf( __( '%2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( $date_format, $note_time ), date_i18n( $time_format, $note_time ), $note_time ); ?></p>
1507
-            <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div>
1506
+            <p class="wpinv-note-date meta"><?php printf(__('%2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n($date_format, $note_time), date_i18n($time_format, $note_time), $note_time); ?></p>
1507
+            <div class="wpinv-note-desc description"><?php echo wpautop(wptexturize($note->comment_content)); ?></div>
1508 1508
             </li>
1509 1509
             <?php
1510 1510
         }
@@ -1513,7 +1513,7 @@  discard block
 block discarded – undo
1513 1513
         <?php
1514 1514
     }
1515 1515
 }
1516
-add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 );
1516
+add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3);
1517 1517
 
1518 1518
 /**
1519 1519
  * Sends renewal reminders.
@@ -1521,35 +1521,35 @@  discard block
 block discarded – undo
1521 1521
 function wpinv_email_renewal_reminders() {
1522 1522
     global $wpdb;
1523 1523
 
1524
-    if ( ! wpinv_get_option( 'email_pre_payment_active' ) ) {
1524
+    if (!wpinv_get_option('email_pre_payment_active')) {
1525 1525
         return;
1526 1526
     }
1527 1527
 
1528
-    $reminder_days = wpinv_get_option( 'email_pre_payment_reminder_days' );
1528
+    $reminder_days = wpinv_get_option('email_pre_payment_reminder_days');
1529 1529
 
1530
-    if ( empty( $reminder_days ) ) {
1530
+    if (empty($reminder_days)) {
1531 1531
         return;
1532 1532
     }
1533 1533
 
1534 1534
     // How many days before renewal should we send this email?
1535
-    $reminder_days = array_unique( array_map( 'absint', array_filter( wpinv_parse_list( $reminder_days ) ) ) );
1536
-    if ( empty( $reminder_days ) ) {
1535
+    $reminder_days = array_unique(array_map('absint', array_filter(wpinv_parse_list($reminder_days))));
1536
+    if (empty($reminder_days)) {
1537 1537
         return;
1538 1538
     }
1539 1539
 
1540
-    if ( 1 == count( $reminder_days ) ) {
1540
+    if (1 == count($reminder_days)) {
1541 1541
         $days  = $reminder_days[0];
1542
-        $date  = date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) );
1543
-        $where = $wpdb->prepare( "DATE(expiration)=%s", $date );
1542
+        $date  = date('Y-m-d', strtotime("+$days days", current_time('timestamp')));
1543
+        $where = $wpdb->prepare("DATE(expiration)=%s", $date);
1544 1544
     } else {
1545 1545
         $in    = array();
1546 1546
 
1547
-        foreach ( $reminder_days as $days ) {
1548
-            $date  = date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) );
1549
-            $in[]  = $wpdb->prepare( "%s", $date );
1547
+        foreach ($reminder_days as $days) {
1548
+            $date  = date('Y-m-d', strtotime("+$days days", current_time('timestamp')));
1549
+            $in[]  = $wpdb->prepare("%s", $date);
1550 1550
         }
1551 1551
 
1552
-        $in    = implode( ',', $in );
1552
+        $in    = implode(',', $in);
1553 1553
         $where = "DATE(expiration) IN ($in)";
1554 1554
     }
1555 1555
 
@@ -1557,20 +1557,20 @@  discard block
 block discarded – undo
1557 1557
     $table = $wpdb->prefix . 'wpinv_subscriptions';
1558 1558
 
1559 1559
     // Fetch invoices.
1560
-	$subscriptions  = $wpdb->get_results(
1560
+	$subscriptions = $wpdb->get_results(
1561 1561
 		"SELECT parent_payment_id, product_id, expiration FROM $table
1562 1562
 		WHERE
1563 1563
             $where
1564 1564
             AND status IN ( 'trialling', 'active' )");
1565 1565
 
1566
-    foreach ( $subscriptions as $subscription ) {
1566
+    foreach ($subscriptions as $subscription) {
1567 1567
 
1568 1568
         // Skip packages.
1569
-        if ( get_post_meta( $subscription->product_id, '_wpinv_type', true ) == 'package' ) {
1569
+        if (get_post_meta($subscription->product_id, '_wpinv_type', true) == 'package') {
1570 1570
             continue;
1571 1571
         }
1572 1572
 
1573
-        wpinv_send_pre_payment_reminder_notification( $subscription->parent_payment_id, $subscription->expiration );
1573
+        wpinv_send_pre_payment_reminder_notification($subscription->parent_payment_id, $subscription->expiration);
1574 1574
     }
1575 1575
 
1576 1576
 }
@@ -1578,44 +1578,44 @@  discard block
 block discarded – undo
1578 1578
 function wpinv_email_payment_reminders() {
1579 1579
     global $wpi_auto_reminder, $wpdb;
1580 1580
 
1581
-    if ( ! wpinv_get_option( 'email_overdue_active' ) ) {
1581
+    if (!wpinv_get_option('email_overdue_active')) {
1582 1582
         return;
1583 1583
     }
1584 1584
 
1585
-    if ( $reminder_days = wpinv_get_option( 'email_due_reminder_days' ) ) {
1585
+    if ($reminder_days = wpinv_get_option('email_due_reminder_days')) {
1586 1586
 
1587 1587
         // Get a list of all reminder dates.
1588
-        $reminder_days  = is_array( $reminder_days ) ? array_values( $reminder_days ) : array();
1588
+        $reminder_days  = is_array($reminder_days) ? array_values($reminder_days) : array();
1589 1589
 
1590 1590
         // Ensure we have integers.
1591
-        $reminder_days  = array_unique( array_map( 'absint', $reminder_days ) );
1591
+        $reminder_days  = array_unique(array_map('absint', $reminder_days));
1592 1592
 
1593 1593
         // Abort if non is selected.
1594
-        if ( empty( $reminder_days ) ) {
1594
+        if (empty($reminder_days)) {
1595 1595
             return;
1596 1596
         }
1597 1597
 
1598 1598
         // Fetch the max reminder day.
1599
-        $max_date = max( $reminder_days );
1599
+        $max_date = max($reminder_days);
1600 1600
 
1601 1601
         // Todays date.
1602
-        $today = date( 'Y-m-d', current_time( 'timestamp' ) );
1602
+        $today = date('Y-m-d', current_time('timestamp'));
1603 1603
 
1604
-        if ( empty( $max_date ) ) {
1605
-            $where = $wpdb->prepare( "DATE(invoices.due_date)=%s", $today );
1606
-        } else if ( 1 == count( $reminder_days ) ) {
1604
+        if (empty($max_date)) {
1605
+            $where = $wpdb->prepare("DATE(invoices.due_date)=%s", $today);
1606
+        } else if (1 == count($reminder_days)) {
1607 1607
             $days  = $reminder_days[0];
1608
-            $date  = date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) );
1609
-            $where = $wpdb->prepare( "DATE(invoices.due_date)=%s", $date );
1608
+            $date  = date('Y-m-d', strtotime("-$days days", current_time('timestamp')));
1609
+            $where = $wpdb->prepare("DATE(invoices.due_date)=%s", $date);
1610 1610
         } else {
1611 1611
             $in    = array();
1612 1612
 
1613
-            foreach ( $reminder_days as $days ) {
1614
-                $date  = date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) );
1615
-                $in[]  = $wpdb->prepare( "%s", $date );
1613
+            foreach ($reminder_days as $days) {
1614
+                $date  = date('Y-m-d', strtotime("-$days days", current_time('timestamp')));
1615
+                $in[]  = $wpdb->prepare("%s", $date);
1616 1616
             }
1617 1617
 
1618
-            $in    = implode( ',', $in );
1618
+            $in    = implode(',', $in);
1619 1619
             $where = "DATE(invoices.due_date) IN ($in)";
1620 1620
         }
1621 1621
 
@@ -1623,7 +1623,7 @@  discard block
 block discarded – undo
1623 1623
         $table = $wpdb->prefix . 'getpaid_invoices';
1624 1624
 
1625 1625
         // Fetch invoices.
1626
-		$invoices  = $wpdb->get_col(
1626
+		$invoices = $wpdb->get_col(
1627 1627
 			"SELECT posts.ID FROM $wpdb->posts as posts
1628 1628
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
1629 1629
 			WHERE
@@ -1631,174 +1631,174 @@  discard block
 block discarded – undo
1631 1631
 				AND posts.post_type = 'wpi_invoice'
1632 1632
                 AND posts.post_status = 'wpi-pending'");
1633 1633
 
1634
-        $wpi_auto_reminder  = true;
1634
+        $wpi_auto_reminder = true;
1635 1635
 
1636
-        foreach ( $invoices as $invoice ) {
1636
+        foreach ($invoices as $invoice) {
1637 1637
 
1638
-            if ( 'payment_form' != get_post_meta( $invoice, 'wpinv_created_via', true ) ) {
1639
-                do_action( 'wpinv_send_payment_reminder_notification', $invoice );
1638
+            if ('payment_form' != get_post_meta($invoice, 'wpinv_created_via', true)) {
1639
+                do_action('wpinv_send_payment_reminder_notification', $invoice);
1640 1640
             }
1641 1641
 
1642 1642
         }
1643 1643
 
1644
-        $wpi_auto_reminder  = false;
1644
+        $wpi_auto_reminder = false;
1645 1645
     }
1646 1646
 }
1647 1647
 
1648 1648
 /**
1649 1649
  * Sends an upcoming renewal notification.
1650 1650
  */
1651
-function wpinv_send_pre_payment_reminder_notification( $invoice_id, $renewal_date ) {
1651
+function wpinv_send_pre_payment_reminder_notification($invoice_id, $renewal_date) {
1652 1652
 
1653 1653
     $email_type = 'pre_payment';
1654
-    if ( ! wpinv_email_is_enabled( $email_type ) ) {
1654
+    if (!wpinv_email_is_enabled($email_type)) {
1655 1655
         return false;
1656 1656
     }
1657 1657
 
1658
-    $invoice    = wpinv_get_invoice( $invoice_id );
1659
-    if ( empty( $invoice ) ) {
1658
+    $invoice = wpinv_get_invoice($invoice_id);
1659
+    if (empty($invoice)) {
1660 1660
         return false;
1661 1661
     }
1662 1662
 
1663
-    $recipient  = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
1664
-    if ( ! is_email( $recipient ) ) {
1663
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
1664
+    if (!is_email($recipient)) {
1665 1665
         return false;
1666 1666
     }
1667 1667
 
1668
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
1669
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
1670
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
1671
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
1672
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
1668
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
1669
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
1670
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
1671
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
1672
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
1673 1673
 
1674
-    $renewal_date = date_i18n( 'Y-m-d', strtotime( $renewal_date ) );
1675
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
1674
+    $renewal_date = date_i18n('Y-m-d', strtotime($renewal_date));
1675
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
1676 1676
             'invoice'       => $invoice,
1677 1677
             'email_type'    => $email_type,
1678
-            'email_heading' => str_replace( '{subscription_renewal_date}', $renewal_date, $email_heading ),
1678
+            'email_heading' => str_replace('{subscription_renewal_date}', $renewal_date, $email_heading),
1679 1679
             'sent_to_admin' => false,
1680 1680
             'plain_text'    => false,
1681
-            'message_body'  => str_replace( '{subscription_renewal_date}', $renewal_date, $message_body )
1682
-        ) );
1681
+            'message_body'  => str_replace('{subscription_renewal_date}', $renewal_date, $message_body)
1682
+        ));
1683 1683
 
1684
-    $content        = wpinv_email_format_text( $content, $invoice );
1684
+    $content = wpinv_email_format_text($content, $invoice);
1685 1685
 
1686
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1686
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
1687 1687
 
1688
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
1689
-        $recipient  = wpinv_get_admin_email();
1690
-        $subject    .= ' - ADMIN BCC COPY';
1691
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1688
+    if (wpinv_mail_admin_bcc_active($email_type)) {
1689
+        $recipient = wpinv_get_admin_email();
1690
+        $subject .= ' - ADMIN BCC COPY';
1691
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
1692 1692
     }
1693 1693
 
1694 1694
     return $sent;
1695 1695
 
1696 1696
 }
1697 1697
 
1698
-function wpinv_send_payment_reminder_notification( $invoice_id ) {
1698
+function wpinv_send_payment_reminder_notification($invoice_id) {
1699 1699
     $email_type = 'overdue';
1700
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
1700
+    if (!wpinv_email_is_enabled($email_type)) {
1701 1701
         return false;
1702 1702
     }
1703 1703
 
1704
-    $invoice    = wpinv_get_invoice( $invoice_id );
1705
-    if ( empty( $invoice ) ) {
1704
+    $invoice = wpinv_get_invoice($invoice_id);
1705
+    if (empty($invoice)) {
1706 1706
         return false;
1707 1707
     }
1708 1708
 
1709
-    if ( !$invoice->needs_payment() ) {
1709
+    if (!$invoice->needs_payment()) {
1710 1710
         return false;
1711 1711
     }
1712 1712
 
1713
-    $recipient  = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
1714
-    if ( !is_email( $recipient ) ) {
1713
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
1714
+    if (!is_email($recipient)) {
1715 1715
         return false;
1716 1716
     }
1717 1717
 
1718
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
1718
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
1719 1719
 
1720
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
1721
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
1722
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
1723
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
1724
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
1720
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
1721
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
1722
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
1723
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
1724
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
1725 1725
 
1726
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
1726
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
1727 1727
             'invoice'       => $invoice,
1728 1728
             'email_type'    => $email_type,
1729 1729
             'email_heading' => $email_heading,
1730 1730
             'sent_to_admin' => false,
1731 1731
             'plain_text'    => false,
1732 1732
             'message_body'  => $message_body
1733
-        ) );
1733
+        ));
1734 1734
 
1735
-    $content        = wpinv_email_format_text( $content, $invoice );
1735
+    $content = wpinv_email_format_text($content, $invoice);
1736 1736
 
1737
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1738
-    if ( $sent ) {
1739
-        do_action( 'wpinv_payment_reminder_sent', $invoice_id, $invoice );
1737
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
1738
+    if ($sent) {
1739
+        do_action('wpinv_payment_reminder_sent', $invoice_id, $invoice);
1740 1740
     }
1741 1741
 
1742
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
1743
-        $recipient  = wpinv_get_admin_email();
1744
-        $subject    .= ' - ADMIN BCC COPY';
1745
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1742
+    if (wpinv_mail_admin_bcc_active($email_type)) {
1743
+        $recipient = wpinv_get_admin_email();
1744
+        $subject .= ' - ADMIN BCC COPY';
1745
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
1746 1746
     }
1747 1747
 
1748
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
1748
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
1749 1749
 
1750 1750
     return $sent;
1751 1751
 }
1752
-add_action( 'wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1 );
1752
+add_action('wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1);
1753 1753
 
1754
-function wpinv_payment_reminder_sent( $invoice_id, $invoice ) {
1754
+function wpinv_payment_reminder_sent($invoice_id, $invoice) {
1755 1755
     global $wpi_auto_reminder;
1756 1756
 
1757
-    $sent = get_post_meta( $invoice_id, '_wpinv_reminder_sent', true );
1757
+    $sent = get_post_meta($invoice_id, '_wpinv_reminder_sent', true);
1758 1758
 
1759
-    if ( empty( $sent ) ) {
1759
+    if (empty($sent)) {
1760 1760
         $sent = array();
1761 1761
     }
1762
-    $sent[] = date_i18n( 'Y-m-d' );
1762
+    $sent[] = date_i18n('Y-m-d');
1763 1763
 
1764
-    update_post_meta( $invoice_id, '_wpinv_reminder_sent', $sent );
1764
+    update_post_meta($invoice_id, '_wpinv_reminder_sent', $sent);
1765 1765
 
1766
-    if ( $wpi_auto_reminder ) { // Auto reminder note.
1767
-        $note = __( 'Automated reminder sent to the user.', 'invoicing' );
1768
-        $invoice->add_note( $note, false, false, true );
1766
+    if ($wpi_auto_reminder) { // Auto reminder note.
1767
+        $note = __('Automated reminder sent to the user.', 'invoicing');
1768
+        $invoice->add_note($note, false, false, true);
1769 1769
     } else { // Menual reminder note.
1770
-        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1771
-        $invoice->add_note( $note );
1770
+        $note = __('Manual reminder sent to the user.', 'invoicing');
1771
+        $invoice->add_note($note);
1772 1772
     }
1773 1773
 }
1774
-add_action( 'wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2 );
1774
+add_action('wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2);
1775 1775
 
1776
-function wpinv_invoice_notification_set_locale( $invoice, $email_type, $site = false ) {
1777
-    if ( empty( $invoice ) ) {
1776
+function wpinv_invoice_notification_set_locale($invoice, $email_type, $site = false) {
1777
+    if (empty($invoice)) {
1778 1778
         return;
1779 1779
     }
1780 1780
 
1781
-    if ( is_int( $invoice ) ) {
1782
-        $invoice = wpinv_get_invoice( $invoice );
1781
+    if (is_int($invoice)) {
1782
+        $invoice = wpinv_get_invoice($invoice);
1783 1783
     }
1784 1784
 
1785
-    if ( ! empty( $invoice ) && is_object( $invoice ) ) {
1786
-        if ( ! $site && function_exists( 'get_user_locale' ) ) {
1787
-            $locale = get_user_locale( $invoice->get_user_id() );
1785
+    if (!empty($invoice) && is_object($invoice)) {
1786
+        if (!$site && function_exists('get_user_locale')) {
1787
+            $locale = get_user_locale($invoice->get_user_id());
1788 1788
         } else {
1789 1789
             $locale = get_locale();
1790 1790
         }
1791 1791
 
1792
-        wpinv_switch_to_locale( $locale );
1792
+        wpinv_switch_to_locale($locale);
1793 1793
     }
1794 1794
 }
1795
-add_action( 'wpinv_pre_send_invoice_notification', 'wpinv_invoice_notification_set_locale', 10, 3 );
1795
+add_action('wpinv_pre_send_invoice_notification', 'wpinv_invoice_notification_set_locale', 10, 3);
1796 1796
 
1797
-function wpinv_invoice_notification_restore_locale( $invoice, $email_type, $site = false ) {
1798
-    if ( empty( $invoice ) ) {
1797
+function wpinv_invoice_notification_restore_locale($invoice, $email_type, $site = false) {
1798
+    if (empty($invoice)) {
1799 1799
         return;
1800 1800
     }
1801 1801
 
1802 1802
     wpinv_restore_locale();
1803 1803
 }
1804
-add_action( 'wpinv_post_send_invoice_notification', 'wpinv_invoice_notification_restore_locale', 10, 3 );
1804
+add_action('wpinv_post_send_invoice_notification', 'wpinv_invoice_notification_restore_locale', 10, 3);
Please login to merge, or discard this patch.
templates/invoice-receipt.php 1 patch
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -7,54 +7,54 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Fetch the invoice.
13
-$invoice = new WPInv_Invoice( $invoice );
13
+$invoice = new WPInv_Invoice($invoice);
14 14
 
15 15
 // @deprecated
16
-do_action( 'wpinv_success_content_before', $invoice );
17
-do_action( 'wpinv_before_receipt', $invoice );
16
+do_action('wpinv_success_content_before', $invoice);
17
+do_action('wpinv_before_receipt', $invoice);
18 18
 
19 19
 
20 20
 // Prepare header text.
21
-if ( $invoice->is_paid() ) {
21
+if ($invoice->is_paid()) {
22 22
 
23 23
     $alert = aui()->alert(
24 24
         array(
25 25
             'type'    => 'success',
26
-            'content' => __( 'Thank you for your payment!', 'invoicing' ),
26
+            'content' => __('Thank you for your payment!', 'invoicing'),
27 27
         )
28 28
     );
29 29
 
30
-} else if ( $invoice->is_refunded() ) {
30
+} else if ($invoice->is_refunded()) {
31 31
 
32 32
     $alert = aui()->alert(
33 33
         array(
34 34
             'type'    => 'info',
35
-            'content' => __( 'This invoice was refunded.', 'invoicing' ),
35
+            'content' => __('This invoice was refunded.', 'invoicing'),
36 36
         )
37 37
     );
38 38
 
39
-} else if ( $invoice->is_held() ) {
39
+} else if ($invoice->is_held()) {
40 40
 
41 41
     $alert = aui()->alert(
42 42
         array(
43 43
             'type'    => 'info',
44
-            'content' => __( 'This invoice will be processed as soon we verify your payment.', 'invoicing' ),
44
+            'content' => __('This invoice will be processed as soon we verify your payment.', 'invoicing'),
45 45
         )
46 46
     );
47 47
 
48
-} else if ( $invoice->needs_payment() ) {
48
+} else if ($invoice->needs_payment()) {
49 49
 
50
-    if ( $invoice->is_due() ) {
50
+    if ($invoice->is_due()) {
51 51
 
52 52
         $alert = aui()->alert(
53 53
             array(
54 54
                 'type'    => 'danger',
55 55
                 'content' => sprintf(
56
-                    __( 'This invoice was due on %.', 'invoicing' ),
57
-                    date_i18n( get_option( 'date_format' ), strtotime( $invoice->get_due_date() ) )
56
+                    __('This invoice was due on %.', 'invoicing'),
57
+                    date_i18n(get_option('date_format'), strtotime($invoice->get_due_date()))
58 58
                 ),
59 59
             )
60 60
         );
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
         $alert = aui()->alert(
65 65
             array(
66 66
                 'type'    => 'warning',
67
-                'content' => __( 'This invoice needs payment.', 'invoicing' ),
67
+                'content' => __('This invoice needs payment.', 'invoicing'),
68 68
             )
69 69
         );
70 70
 
@@ -79,19 +79,19 @@  discard block
 block discarded – undo
79 79
 
80 80
         'pay' => array(
81 81
             'url'   => $invoice->get_checkout_payment_url(),
82
-            'name'  => __( 'Pay For Invoice', 'invoicing' ),
82
+            'name'  => __('Pay For Invoice', 'invoicing'),
83 83
             'class' => 'btn-success',
84 84
         ),
85 85
 
86 86
         'view' => array(
87 87
             'url'   => $invoice->get_view_url(),
88
-            'name'  => __( 'View Invoice', 'invoicing' ),
88
+            'name'  => __('View Invoice', 'invoicing'),
89 89
             'class' => 'btn-primary',
90 90
         ),
91 91
 
92 92
         'history' => array(
93 93
             'url'   => wpinv_get_history_page_uri(),
94
-            'name'  => __( 'Invoice History', 'invoicing' ),
94
+            'name'  => __('Invoice History', 'invoicing'),
95 95
             'class' => 'btn-warning',
96 96
         ),
97 97
 
@@ -100,12 +100,12 @@  discard block
 block discarded – undo
100 100
 
101 101
 );
102 102
 
103
-if ( ( ! $invoice->needs_payment() || $invoice->is_held() ) && isset( $actions['pay'] ) ) {
104
-    unset( $actions['pay'] );
103
+if ((!$invoice->needs_payment() || $invoice->is_held()) && isset($actions['pay'])) {
104
+    unset($actions['pay']);
105 105
 }
106 106
 
107
-if ( ! is_user_logged_in() && isset( $actions['history'] ) ) {
108
-    unset( $actions['history'] );
107
+if (!is_user_logged_in() && isset($actions['history'])) {
108
+    unset($actions['history']);
109 109
 }
110 110
 
111 111
 ?>
@@ -114,19 +114,19 @@  discard block
 block discarded – undo
114 114
 
115 115
         <?php
116 116
         
117
-            do_action( 'wpinv_receipt_start', $invoice );
117
+            do_action('wpinv_receipt_start', $invoice);
118 118
 
119
-            if ( ! empty( $actions ) ) {
119
+            if (!empty($actions)) {
120 120
 
121 121
                 echo '<div class="wpinv-receipt-actions text-right mt-1 mb-4">';
122 122
 
123
-                foreach ( $actions as $key => $action ) {
123
+                foreach ($actions as $key => $action) {
124 124
 
125
-                    $key    = sanitize_html_class( $key );
126
-                    $class  = empty( $action['class'] ) ? 'btn-dark' : sanitize_html_class( $action['class'] );
127
-                    $url    = empty( $action['url'] ) ? '#' : esc_url( $action['url'] );
128
-                    $attrs  = empty( $action['attrs'] ) ? '' : $action['attrs'];
129
-                    $anchor = sanitize_text_field( $action['name'] );
125
+                    $key    = sanitize_html_class($key);
126
+                    $class  = empty($action['class']) ? 'btn-dark' : sanitize_html_class($action['class']);
127
+                    $url    = empty($action['url']) ? '#' : esc_url($action['url']);
128
+                    $attrs  = empty($action['attrs']) ? '' : $action['attrs'];
129
+                    $anchor = sanitize_text_field($action['name']);
130 130
 
131 131
                     echo "<a href='$url' class='btn btn-sm $class $key' $attrs>$anchor</a>";
132 132
                 }
@@ -142,20 +142,20 @@  discard block
 block discarded – undo
142 142
         <div class="wpinv-receipt-details">
143 143
 
144 144
             <h4 class="wpinv-details-t mb-3 mt-3">
145
-                <?php echo apply_filters( 'wpinv_receipt_details_title', __( 'Invoice Details', 'invoicing' ), $invoice ); ?>
145
+                <?php echo apply_filters('wpinv_receipt_details_title', __('Invoice Details', 'invoicing'), $invoice); ?>
146 146
             </h4>
147 147
 
148
-            <?php getpaid_invoice_meta( $invoice ); ?>
148
+            <?php getpaid_invoice_meta($invoice); ?>
149 149
 
150 150
         </div>
151 151
 
152 152
 
153
-        <?php do_action( 'wpinv_receipt_end', $invoice ); ?>
153
+        <?php do_action('wpinv_receipt_end', $invoice); ?>
154 154
 
155 155
     </div>
156 156
 
157 157
 <?php
158 158
 
159 159
 // @deprecated
160
-do_action( 'wpinv_success_content_after', $invoice );
161
-do_action( 'wpinv_after_receipt', $invoice );
160
+do_action('wpinv_success_content_after', $invoice);
161
+do_action('wpinv_after_receipt', $invoice);
Please login to merge, or discard this patch.
includes/class-wpinv-privacy-exporters.php 1 patch
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Personal data exporters.
4 4
  */
5 5
 
6
-defined( 'ABSPATH' ) || exit;
6
+defined('ABSPATH') || exit;
7 7
 
8 8
 /**
9 9
  * WPInv_Privacy_Exporters Class.
@@ -17,38 +17,38 @@  discard block
 block discarded – undo
17 17
      * @param int    $page  Page.
18 18
      * @return array An array of invoice data in name value pairs
19 19
      */
20
-    public static function customer_invoice_data_exporter( $email_address, $page ) {
20
+    public static function customer_invoice_data_exporter($email_address, $page) {
21 21
         $done           = false;
22 22
         $page           = (int) $page;
23 23
         $data_to_export = array();
24 24
 
25
-        $user           = get_user_by( 'email', $email_address );
26
-        if ( ! $user instanceof WP_User ) {
25
+        $user           = get_user_by('email', $email_address);
26
+        if (!$user instanceof WP_User) {
27 27
             return array(
28 28
                 'data' => $data_to_export,
29 29
                 'done' => true,
30 30
             );
31 31
         }
32 32
 
33
-        $args    = array(
33
+        $args = array(
34 34
             'limit'    => 30,
35 35
             'page'     => $page,
36 36
             'user'     => $user->ID,
37 37
         );
38 38
 
39
-        $invoices = wpinv_get_invoices( $args );
39
+        $invoices = wpinv_get_invoices($args);
40 40
 
41
-        if ( 0 < count( $invoices ) ) {
42
-            foreach ( $invoices as $invoice ) {
41
+        if (0 < count($invoices)) {
42
+            foreach ($invoices as $invoice) {
43 43
                 $data_to_export[] = array(
44 44
                     'group_id'          => 'customer_invoices',
45
-                    'group_label'       => __( 'Invoicing Data', 'invoicing' ),
46
-                    'group_description' => __( 'Customer invoicing data.', 'invoicing' ),
45
+                    'group_label'       => __('Invoicing Data', 'invoicing'),
46
+                    'group_description' => __('Customer invoicing data.', 'invoicing'),
47 47
                     'item_id'           => "wpinv-{$invoice->ID}",
48
-                    'data'              => self::get_customer_invoice_data( $invoice ),
48
+                    'data'              => self::get_customer_invoice_data($invoice),
49 49
                 );
50 50
             }
51
-            $done = 30 > count( $invoices );
51
+            $done = 30 > count($invoices);
52 52
         } else {
53 53
             $done = true;
54 54
         }
@@ -66,59 +66,59 @@  discard block
 block discarded – undo
66 66
      * @param WPInv_Invoice $invoice invoice object.
67 67
      * @return array
68 68
      */
69
-    public static function get_customer_invoice_data( $invoice ) {
69
+    public static function get_customer_invoice_data($invoice) {
70 70
         $personal_data = array();
71 71
 
72 72
         $props_to_export = array(
73
-            'number'               => __( 'Invoice Number', 'invoicing' ),
74
-            'created_date'         => __( 'Invoice Date', 'invoicing' ),
75
-            'status'               => __( 'Invoice Status', 'invoicing' ),
76
-            'total'                => __( 'Invoice Total', 'invoicing' ),
77
-            'items'                => __( 'Invoice Items', 'invoicing' ),
78
-            'first_name'           => __( 'First Name', 'invoicing' ),
79
-            'last_name'            => __( 'Last Name', 'invoicing' ),
80
-            'email'                => __( 'Email Address', 'invoicing' ),
81
-            '_wpinv_company'       => __( 'Company', 'invoicing' ),
82
-            'phone'                => __( 'Phone Number', 'invoicing' ),
83
-            'address'              => __( 'Address', 'invoicing' ),
84
-            '_wpinv_city'          => __( 'City', 'invoicing' ),
85
-            '_wpinv_country'       => __( 'Country', 'invoicing' ),
86
-            '_wpinv_state'         => __( 'State', 'invoicing' ),
87
-            '_wpinv_zip'           => __( 'Zip Code', 'invoicing' ),
73
+            'number'               => __('Invoice Number', 'invoicing'),
74
+            'created_date'         => __('Invoice Date', 'invoicing'),
75
+            'status'               => __('Invoice Status', 'invoicing'),
76
+            'total'                => __('Invoice Total', 'invoicing'),
77
+            'items'                => __('Invoice Items', 'invoicing'),
78
+            'first_name'           => __('First Name', 'invoicing'),
79
+            'last_name'            => __('Last Name', 'invoicing'),
80
+            'email'                => __('Email Address', 'invoicing'),
81
+            '_wpinv_company'       => __('Company', 'invoicing'),
82
+            'phone'                => __('Phone Number', 'invoicing'),
83
+            'address'              => __('Address', 'invoicing'),
84
+            '_wpinv_city'          => __('City', 'invoicing'),
85
+            '_wpinv_country'       => __('Country', 'invoicing'),
86
+            '_wpinv_state'         => __('State', 'invoicing'),
87
+            '_wpinv_zip'           => __('Zip Code', 'invoicing'),
88 88
         );
89 89
 
90
-        $subscription = wpinv_get_subscription( $invoice );
90
+        $subscription = wpinv_get_subscription($invoice);
91 91
         $period = $initial_amt = $bill_times = $billed = $renewal_date = '';
92 92
 
93
-        if ( $invoice->is_recurring() && !empty( $subscription ) ) {
94
-            $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->period,$subscription->frequency );
95
-            $period = wpinv_price( wpinv_format_amount( $subscription->recurring_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ) . ' / ' . $frequency;
96
-            $initial_amt = wpinv_price( wpinv_format_amount( $subscription->initial_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) );
97
-            $bill_times = $subscription->get_times_billed() . ' / ' . ( ( $subscription->bill_times == 0 ) ? __( 'Until Cancelled', 'invoicing' ) : $subscription->bill_times );
98
-            $renewal_date = ! empty( $subscription->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $subscription->expiration ) ) : __( 'N/A', 'invoicing' );
99
-
100
-            $props_to_export['period'] = __( 'Billing Cycle', 'invoicing' );
101
-            $props_to_export['initial_amount'] = __( 'Initial Amount', 'invoicing' );
102
-            $props_to_export['bill_times'] = __( 'Times Billed', 'invoicing' );
103
-            $props_to_export['renewal_date'] = __( 'Renewal Date', 'invoicing' );
93
+        if ($invoice->is_recurring() && !empty($subscription)) {
94
+            $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->period, $subscription->frequency);
95
+            $period = wpinv_price(wpinv_format_amount($subscription->recurring_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id)) . ' / ' . $frequency;
96
+            $initial_amt = wpinv_price(wpinv_format_amount($subscription->initial_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id));
97
+            $bill_times = $subscription->get_times_billed() . ' / ' . (($subscription->bill_times == 0) ? __('Until Cancelled', 'invoicing') : $subscription->bill_times);
98
+            $renewal_date = !empty($subscription->expiration) ? date_i18n(get_option('date_format'), strtotime($subscription->expiration)) : __('N/A', 'invoicing');
99
+
100
+            $props_to_export['period'] = __('Billing Cycle', 'invoicing');
101
+            $props_to_export['initial_amount'] = __('Initial Amount', 'invoicing');
102
+            $props_to_export['bill_times'] = __('Times Billed', 'invoicing');
103
+            $props_to_export['renewal_date'] = __('Renewal Date', 'invoicing');
104 104
         }
105 105
 
106
-        $props_to_export['ip'] = __( 'IP Address', 'invoicing' );
107
-        $props_to_export['view_url'] = __( 'Invoice Link', 'invoicing' );
106
+        $props_to_export['ip'] = __('IP Address', 'invoicing');
107
+        $props_to_export['view_url'] = __('Invoice Link', 'invoicing');
108 108
 
109
-        $props_to_export = apply_filters( 'wpinv_privacy_export_invoice_personal_data_props', $props_to_export, $invoice, $subscription);
109
+        $props_to_export = apply_filters('wpinv_privacy_export_invoice_personal_data_props', $props_to_export, $invoice, $subscription);
110 110
 
111
-        foreach ( $props_to_export as $prop => $name ) {
111
+        foreach ($props_to_export as $prop => $name) {
112 112
             $value = '';
113 113
 
114
-            switch ( $prop ) {
114
+            switch ($prop) {
115 115
                 case 'items':
116 116
                     $item_names = array();
117
-                    foreach ( $invoice->get_cart_details() as $key => $cart_item ) {
118
-                        $item_quantity  = $cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1;
117
+                    foreach ($invoice->get_cart_details() as $key => $cart_item) {
118
+                        $item_quantity = $cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1;
119 119
                         $item_names[] = $cart_item['name'] . ' x ' . $item_quantity;
120 120
                     }
121
-                    $value = implode( ', ', $item_names );
121
+                    $value = implode(', ', $item_names);
122 122
                     break;
123 123
                 case 'status':
124 124
                     $value = $invoice->get_status(true);
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
                     $value = $renewal_date;
140 140
                     break;
141 141
                 default:
142
-                    if ( is_callable( array( $invoice, 'get_' . $prop ) ) ) {
142
+                    if (is_callable(array($invoice, 'get_' . $prop))) {
143 143
                         $value = $invoice->{"get_$prop"}();
144 144
                     } else {
145 145
                         $value = $invoice->get_meta($prop);
@@ -147,9 +147,9 @@  discard block
 block discarded – undo
147 147
                     break;
148 148
             }
149 149
 
150
-            $value = apply_filters( 'wpi_privacy_export_invoice_personal_data_prop', $value, $prop, $invoice );
150
+            $value = apply_filters('wpi_privacy_export_invoice_personal_data_prop', $value, $prop, $invoice);
151 151
 
152
-            if ( $value ) {
152
+            if ($value) {
153 153
                 $personal_data[] = array(
154 154
                     'name'  => $name,
155 155
                     'value' => $value,
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 
159 159
         }
160 160
 
161
-        $personal_data = apply_filters( 'wpinv_privacy_export_invoice_personal_data', $personal_data, $invoice );
161
+        $personal_data = apply_filters('wpinv_privacy_export_invoice_personal_data', $personal_data, $invoice);
162 162
 
163 163
         return $personal_data;
164 164
 
Please login to merge, or discard this patch.
includes/class-wpinv-notes.php 2 patches
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -12,118 +12,118 @@
 block discarded – undo
12 12
  */
13 13
 class WPInv_Notes {
14 14
 
15
-	/**
16
-	 * Class constructor.
17
-	 */
18
-	public function __construct() {
19
-
20
-		// Filter inovice notes.
21
-		add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
22
-		add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 );
23
-
24
-		// Fires after notes are loaded.
25
-		do_action( 'wpinv_notes_init', $this );
26
-	}
27
-
28
-	/**
29
-	 * Filters invoice notes query to only include our notes.
30
-	 *
31
-	 * @param WP_Comment_Query $query
32
-	 */
33
-	public function set_invoice_note_type( $query ) {
34
-		$post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
35
-
36
-		if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) {
37
-			$query->query_vars['type'] = 'wpinv_note';
38
-		} else {
39
-
40
-			if ( empty( $query->query_vars['type__not_in'] ) ) {
41
-				$query->query_vars['type__not_in'] = array();
42
-			}
43
-
44
-			$query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] );
45
-			$query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] );
46
-		}
47
-
48
-		return $query;
49
-	}
50
-
51
-	/**
52
-	 * Exclude notes from the comments feed.
53
-	 */
54
-	function wpinv_comment_feed_where( $where ){
55
-		return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
56
-	}
57
-
58
-	/**
59
-	 * Returns an array of invoice notes.
60
-	 *
61
-	 * @param int $invoice_id The invoice ID whose notes to retrieve.
62
-	 * @param string $type Optional. Pass in customer to only return customer notes.
63
-	 * @return WP_Comment[]
64
-	 */
65
-	public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) {
66
-
67
-		// Default comment args.
68
-		$args = array(
69
-			'post_id'   => $invoice_id,
70
-			'orderby'   => 'comment_ID',
71
-			'order'     => 'ASC',
72
-		);
73
-
74
-		// Maybe only show customer comments.
75
-		if ( $type == 'customer' ) {
76
-			$args['meta_key']   = '_wpi_customer_note';
77
-			$args['meta_value'] = 1;
78
-		}
79
-
80
-		$args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
81
-
82
-		return get_comments( $args );
83
-	}
84
-
85
-	/**
86
-	 * Saves an invoice comment.
87
-	 * 
88
-	 * @param WPInv_Invoice $invoice The invoice to add the comment to.
89
-	 * @param string $note The note content.
90
-	 * @param string $note_author The name of the author of the note.
91
-	 * @param bool $for_customer Whether or not this comment is meant to be sent to the customer.
92
-	 * @return int|false The new note's ID on success, false on failure.
93
-	 */
94
-	function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ){
95
-
96
-		do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer );
97
-
98
-		/**
99
-		 * Insert the comment.
100
-		 */
101
-		$note_id = wp_insert_comment(
102
-			wp_filter_comment(
103
-				array(
104
-					'comment_post_ID'      => $invoice->get_id(),
105
-					'comment_content'      => $note,
106
-					'comment_agent'        => 'Invoicing',
107
-					'user_id'              => get_current_user_id(),
108
-					'comment_author'       => $note_author,
109
-					'comment_author_IP'    => wpinv_get_ip(),
110
-					'comment_author_email' => $author_email,
111
-					'comment_author_url'   => $invoice->get_view_url(),
112
-					'comment_type'         => 'wpinv_note',
113
-				)
114
-			)
115
-		);
116
-
117
-		do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer );
118
-
119
-		// Are we notifying the customer?
120
-		if ( empty( $note_id ) || empty( $for_customer ) ) {
121
-			return $note_id;
122
-		}
123
-
124
-		add_comment_meta( $note_id, '_wpi_customer_note', 1 );
125
-		do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $invoice->get_id(), 'user_note' => $note ) );
126
-		return $note_id;
127
-	}
15
+    /**
16
+     * Class constructor.
17
+     */
18
+    public function __construct() {
19
+
20
+        // Filter inovice notes.
21
+        add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
22
+        add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 );
23
+
24
+        // Fires after notes are loaded.
25
+        do_action( 'wpinv_notes_init', $this );
26
+    }
27
+
28
+    /**
29
+     * Filters invoice notes query to only include our notes.
30
+     *
31
+     * @param WP_Comment_Query $query
32
+     */
33
+    public function set_invoice_note_type( $query ) {
34
+        $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
35
+
36
+        if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) {
37
+            $query->query_vars['type'] = 'wpinv_note';
38
+        } else {
39
+
40
+            if ( empty( $query->query_vars['type__not_in'] ) ) {
41
+                $query->query_vars['type__not_in'] = array();
42
+            }
43
+
44
+            $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] );
45
+            $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] );
46
+        }
47
+
48
+        return $query;
49
+    }
50
+
51
+    /**
52
+     * Exclude notes from the comments feed.
53
+     */
54
+    function wpinv_comment_feed_where( $where ){
55
+        return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
56
+    }
57
+
58
+    /**
59
+     * Returns an array of invoice notes.
60
+     *
61
+     * @param int $invoice_id The invoice ID whose notes to retrieve.
62
+     * @param string $type Optional. Pass in customer to only return customer notes.
63
+     * @return WP_Comment[]
64
+     */
65
+    public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) {
66
+
67
+        // Default comment args.
68
+        $args = array(
69
+            'post_id'   => $invoice_id,
70
+            'orderby'   => 'comment_ID',
71
+            'order'     => 'ASC',
72
+        );
73
+
74
+        // Maybe only show customer comments.
75
+        if ( $type == 'customer' ) {
76
+            $args['meta_key']   = '_wpi_customer_note';
77
+            $args['meta_value'] = 1;
78
+        }
79
+
80
+        $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
81
+
82
+        return get_comments( $args );
83
+    }
84
+
85
+    /**
86
+     * Saves an invoice comment.
87
+     * 
88
+     * @param WPInv_Invoice $invoice The invoice to add the comment to.
89
+     * @param string $note The note content.
90
+     * @param string $note_author The name of the author of the note.
91
+     * @param bool $for_customer Whether or not this comment is meant to be sent to the customer.
92
+     * @return int|false The new note's ID on success, false on failure.
93
+     */
94
+    function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ){
95
+
96
+        do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer );
97
+
98
+        /**
99
+         * Insert the comment.
100
+         */
101
+        $note_id = wp_insert_comment(
102
+            wp_filter_comment(
103
+                array(
104
+                    'comment_post_ID'      => $invoice->get_id(),
105
+                    'comment_content'      => $note,
106
+                    'comment_agent'        => 'Invoicing',
107
+                    'user_id'              => get_current_user_id(),
108
+                    'comment_author'       => $note_author,
109
+                    'comment_author_IP'    => wpinv_get_ip(),
110
+                    'comment_author_email' => $author_email,
111
+                    'comment_author_url'   => $invoice->get_view_url(),
112
+                    'comment_type'         => 'wpinv_note',
113
+                )
114
+            )
115
+        );
116
+
117
+        do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer );
118
+
119
+        // Are we notifying the customer?
120
+        if ( empty( $note_id ) || empty( $for_customer ) ) {
121
+            return $note_id;
122
+        }
123
+
124
+        add_comment_meta( $note_id, '_wpi_customer_note', 1 );
125
+        do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $invoice->get_id(), 'user_note' => $note ) );
126
+        return $note_id;
127
+    }
128 128
 
129 129
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 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
  * Handles invoice notes.
@@ -18,11 +18,11 @@  discard block
 block discarded – undo
18 18
 	public function __construct() {
19 19
 
20 20
 		// Filter inovice notes.
21
-		add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
22
-		add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 );
21
+		add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1);
22
+		add_action('comment_feed_where', array($this, 'wpinv_comment_feed_where'), 10, 1);
23 23
 
24 24
 		// Fires after notes are loaded.
25
-		do_action( 'wpinv_notes_init', $this );
25
+		do_action('wpinv_notes_init', $this);
26 26
 	}
27 27
 
28 28
 	/**
@@ -30,19 +30,19 @@  discard block
 block discarded – undo
30 30
 	 *
31 31
 	 * @param WP_Comment_Query $query
32 32
 	 */
33
-	public function set_invoice_note_type( $query ) {
34
-		$post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
33
+	public function set_invoice_note_type($query) {
34
+		$post_id = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
35 35
 
36
-		if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) {
36
+		if ($post_id && getpaid_is_invoice_post_type(get_post_type($post_id))) {
37 37
 			$query->query_vars['type'] = 'wpinv_note';
38 38
 		} else {
39 39
 
40
-			if ( empty( $query->query_vars['type__not_in'] ) ) {
40
+			if (empty($query->query_vars['type__not_in'])) {
41 41
 				$query->query_vars['type__not_in'] = array();
42 42
 			}
43 43
 
44
-			$query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] );
45
-			$query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] );
44
+			$query->query_vars['type__not_in'] = wpinv_parse_list($query->query_vars['type__not_in']);
45
+			$query->query_vars['type__not_in'] = array_merge(array('wpinv_note'), $query->query_vars['type__not_in']);
46 46
 		}
47 47
 
48 48
 		return $query;
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 	/**
52 52
 	 * Exclude notes from the comments feed.
53 53
 	 */
54
-	function wpinv_comment_feed_where( $where ){
55
-		return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
54
+	function wpinv_comment_feed_where($where) {
55
+		return $where . ($where ? ' AND ' : '') . " comment_type != 'wpinv_note' ";
56 56
 	}
57 57
 
58 58
 	/**
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 * @param string $type Optional. Pass in customer to only return customer notes.
63 63
 	 * @return WP_Comment[]
64 64
 	 */
65
-	public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) {
65
+	public function get_invoice_notes($invoice_id = 0, $type = 'all') {
66 66
 
67 67
 		// Default comment args.
68 68
 		$args = array(
@@ -72,14 +72,14 @@  discard block
 block discarded – undo
72 72
 		);
73 73
 
74 74
 		// Maybe only show customer comments.
75
-		if ( $type == 'customer' ) {
75
+		if ($type == 'customer') {
76 76
 			$args['meta_key']   = '_wpi_customer_note';
77 77
 			$args['meta_value'] = 1;
78 78
 		}
79 79
 
80
-		$args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
80
+		$args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type);
81 81
 
82
-		return get_comments( $args );
82
+		return get_comments($args);
83 83
 	}
84 84
 
85 85
 	/**
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
 	 * @param bool $for_customer Whether or not this comment is meant to be sent to the customer.
92 92
 	 * @return int|false The new note's ID on success, false on failure.
93 93
 	 */
94
-	function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ){
94
+	function add_invoice_note($invoice, $note, $note_author, $author_email, $for_customer = false) {
95 95
 
96
-		do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer );
96
+		do_action('wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer);
97 97
 
98 98
 		/**
99 99
 		 * Insert the comment.
@@ -114,15 +114,15 @@  discard block
 block discarded – undo
114 114
 			)
115 115
 		);
116 116
 
117
-		do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer );
117
+		do_action('wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer);
118 118
 
119 119
 		// Are we notifying the customer?
120
-		if ( empty( $note_id ) || empty( $for_customer ) ) {
120
+		if (empty($note_id) || empty($for_customer)) {
121 121
 			return $note_id;
122 122
 		}
123 123
 
124
-		add_comment_meta( $note_id, '_wpi_customer_note', 1 );
125
-		do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $invoice->get_id(), 'user_note' => $note ) );
124
+		add_comment_meta($note_id, '_wpi_customer_note', 1);
125
+		do_action('wpinv_new_customer_note', array('invoice_id' => $invoice->get_id(), 'user_note' => $note));
126 126
 		return $note_id;
127 127
 	}
128 128
 
Please login to merge, or discard this patch.
includes/class-wpinv-item.php 2 patches
Indentation   +735 added lines, -735 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,30 +10,30 @@  discard block
 block discarded – undo
10 10
 class WPInv_Item  extends GetPaid_Data {
11 11
 
12 12
     /**
13
-	 * Which data store to load.
14
-	 *
15
-	 * @var string
16
-	 */
13
+     * Which data store to load.
14
+     *
15
+     * @var string
16
+     */
17 17
     protected $data_store_name = 'item';
18 18
 
19 19
     /**
20
-	 * This is the name of this object type.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $object_type = 'item';
20
+     * This is the name of this object type.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $object_type = 'item';
25 25
 
26 26
     /**
27
-	 * Item Data array. This is the core item data exposed in APIs.
28
-	 *
29
-	 * @since 1.0.19
30
-	 * @var array
31
-	 */
32
-	protected $data = array(
33
-		'parent_id'            => 0,
34
-		'status'               => 'draft',
35
-		'version'              => '',
36
-		'date_created'         => null,
27
+     * Item Data array. This is the core item data exposed in APIs.
28
+     *
29
+     * @since 1.0.19
30
+     * @var array
31
+     */
32
+    protected $data = array(
33
+        'parent_id'            => 0,
34
+        'status'               => 'draft',
35
+        'version'              => '',
36
+        'date_created'         => null,
37 37
         'date_modified'        => null,
38 38
         'name'                 => '',
39 39
         'description'          => '',
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
     );
59 59
 
60 60
     /**
61
-	 * Stores meta in cache for future reads.
62
-	 *
63
-	 * A group must be set to to enable caching.
64
-	 *
65
-	 * @var string
66
-	 */
67
-	protected $cache_group = 'getpaid_items';
61
+     * Stores meta in cache for future reads.
62
+     *
63
+     * A group must be set to to enable caching.
64
+     *
65
+     * @var string
66
+     */
67
+    protected $cache_group = 'getpaid_items';
68 68
 
69 69
     /**
70 70
      * Stores a reference to the original WP_Post object
@@ -74,37 +74,37 @@  discard block
 block discarded – undo
74 74
     protected $post = null;
75 75
 
76 76
     /**
77
-	 * Get the item if ID is passed, otherwise the item is new and empty.
78
-	 *
79
-	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80
-	 */
81
-	public function __construct( $item = 0 ) {
82
-		parent::__construct( $item );
83
-
84
-		if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
85
-			$this->set_id( $item );
86
-		} elseif ( $item instanceof self ) {
87
-			$this->set_id( $item->get_id() );
88
-		} elseif ( ! empty( $item->ID ) ) {
89
-			$this->set_id( $item->ID );
90
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
91
-			$this->set_id( $item_id );
92
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
93
-			$this->set_id( $item_id );
94
-		} else {
95
-			$this->set_object_read( true );
96
-		}
77
+     * Get the item if ID is passed, otherwise the item is new and empty.
78
+     *
79
+     * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80
+     */
81
+    public function __construct( $item = 0 ) {
82
+        parent::__construct( $item );
83
+
84
+        if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
85
+            $this->set_id( $item );
86
+        } elseif ( $item instanceof self ) {
87
+            $this->set_id( $item->get_id() );
88
+        } elseif ( ! empty( $item->ID ) ) {
89
+            $this->set_id( $item->ID );
90
+        } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
91
+            $this->set_id( $item_id );
92
+        } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
93
+            $this->set_id( $item_id );
94
+        } else {
95
+            $this->set_object_read( true );
96
+        }
97 97
 
98 98
         // Load the datastore.
99
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
99
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
100 100
 
101
-		if ( $this->get_id() > 0 ) {
101
+        if ( $this->get_id() > 0 ) {
102 102
             $this->post = get_post( $this->get_id() );
103 103
             $this->ID   = $this->get_id();
104
-			$this->data_store->read( $this );
104
+            $this->data_store->read( $this );
105 105
         }
106 106
 
107
-	}
107
+    }
108 108
 
109 109
     /*
110 110
 	|--------------------------------------------------------------------------
@@ -122,401 +122,401 @@  discard block
 block discarded – undo
122 122
     */
123 123
 
124 124
     /**
125
-	 * Get parent item ID.
126
-	 *
127
-	 * @since 1.0.19
128
-	 * @param  string $context View or edit context.
129
-	 * @return int
130
-	 */
131
-	public function get_parent_id( $context = 'view' ) {
132
-		return (int) $this->get_prop( 'parent_id', $context );
125
+     * Get parent item ID.
126
+     *
127
+     * @since 1.0.19
128
+     * @param  string $context View or edit context.
129
+     * @return int
130
+     */
131
+    public function get_parent_id( $context = 'view' ) {
132
+        return (int) $this->get_prop( 'parent_id', $context );
133 133
     }
134 134
 
135 135
     /**
136
-	 * Get item status.
137
-	 *
138
-	 * @since 1.0.19
139
-	 * @param  string $context View or edit context.
140
-	 * @return string
141
-	 */
142
-	public function get_status( $context = 'view' ) {
143
-		return $this->get_prop( 'status', $context );
136
+     * Get item status.
137
+     *
138
+     * @since 1.0.19
139
+     * @param  string $context View or edit context.
140
+     * @return string
141
+     */
142
+    public function get_status( $context = 'view' ) {
143
+        return $this->get_prop( 'status', $context );
144 144
     }
145 145
 
146 146
     /**
147
-	 * Get plugin version when the item was created.
148
-	 *
149
-	 * @since 1.0.19
150
-	 * @param  string $context View or edit context.
151
-	 * @return string
152
-	 */
153
-	public function get_version( $context = 'view' ) {
154
-		return $this->get_prop( 'version', $context );
147
+     * Get plugin version when the item was created.
148
+     *
149
+     * @since 1.0.19
150
+     * @param  string $context View or edit context.
151
+     * @return string
152
+     */
153
+    public function get_version( $context = 'view' ) {
154
+        return $this->get_prop( 'version', $context );
155 155
     }
156 156
 
157 157
     /**
158
-	 * Get date when the item was created.
159
-	 *
160
-	 * @since 1.0.19
161
-	 * @param  string $context View or edit context.
162
-	 * @return string
163
-	 */
164
-	public function get_date_created( $context = 'view' ) {
165
-		return $this->get_prop( 'date_created', $context );
158
+     * Get date when the item was created.
159
+     *
160
+     * @since 1.0.19
161
+     * @param  string $context View or edit context.
162
+     * @return string
163
+     */
164
+    public function get_date_created( $context = 'view' ) {
165
+        return $this->get_prop( 'date_created', $context );
166 166
     }
167 167
 
168 168
     /**
169
-	 * Get GMT date when the item was created.
170
-	 *
171
-	 * @since 1.0.19
172
-	 * @param  string $context View or edit context.
173
-	 * @return string
174
-	 */
175
-	public function get_date_created_gmt( $context = 'view' ) {
169
+     * Get GMT date when the item was created.
170
+     *
171
+     * @since 1.0.19
172
+     * @param  string $context View or edit context.
173
+     * @return string
174
+     */
175
+    public function get_date_created_gmt( $context = 'view' ) {
176 176
         $date = $this->get_date_created( $context );
177 177
 
178 178
         if ( $date ) {
179 179
             $date = get_gmt_from_date( $date );
180 180
         }
181
-		return $date;
181
+        return $date;
182 182
     }
183 183
 
184 184
     /**
185
-	 * Get date when the item was last modified.
186
-	 *
187
-	 * @since 1.0.19
188
-	 * @param  string $context View or edit context.
189
-	 * @return string
190
-	 */
191
-	public function get_date_modified( $context = 'view' ) {
192
-		return $this->get_prop( 'date_modified', $context );
185
+     * Get date when the item was last modified.
186
+     *
187
+     * @since 1.0.19
188
+     * @param  string $context View or edit context.
189
+     * @return string
190
+     */
191
+    public function get_date_modified( $context = 'view' ) {
192
+        return $this->get_prop( 'date_modified', $context );
193 193
     }
194 194
 
195 195
     /**
196
-	 * Get GMT date when the item was last modified.
197
-	 *
198
-	 * @since 1.0.19
199
-	 * @param  string $context View or edit context.
200
-	 * @return string
201
-	 */
202
-	public function get_date_modified_gmt( $context = 'view' ) {
196
+     * Get GMT date when the item was last modified.
197
+     *
198
+     * @since 1.0.19
199
+     * @param  string $context View or edit context.
200
+     * @return string
201
+     */
202
+    public function get_date_modified_gmt( $context = 'view' ) {
203 203
         $date = $this->get_date_modified( $context );
204 204
 
205 205
         if ( $date ) {
206 206
             $date = get_gmt_from_date( $date );
207 207
         }
208
-		return $date;
208
+        return $date;
209 209
     }
210 210
 
211 211
     /**
212
-	 * Get the item name.
213
-	 *
214
-	 * @since 1.0.19
215
-	 * @param  string $context View or edit context.
216
-	 * @return string
217
-	 */
218
-	public function get_name( $context = 'view' ) {
219
-		return $this->get_prop( 'name', $context );
212
+     * Get the item name.
213
+     *
214
+     * @since 1.0.19
215
+     * @param  string $context View or edit context.
216
+     * @return string
217
+     */
218
+    public function get_name( $context = 'view' ) {
219
+        return $this->get_prop( 'name', $context );
220 220
     }
221 221
 
222 222
     /**
223
-	 * Alias of self::get_name().
224
-	 *
225
-	 * @since 1.0.19
226
-	 * @param  string $context View or edit context.
227
-	 * @return string
228
-	 */
229
-	public function get_title( $context = 'view' ) {
230
-		return $this->get_name( $context );
223
+     * Alias of self::get_name().
224
+     *
225
+     * @since 1.0.19
226
+     * @param  string $context View or edit context.
227
+     * @return string
228
+     */
229
+    public function get_title( $context = 'view' ) {
230
+        return $this->get_name( $context );
231 231
     }
232 232
 
233 233
     /**
234
-	 * Get the item description.
235
-	 *
236
-	 * @since 1.0.19
237
-	 * @param  string $context View or edit context.
238
-	 * @return string
239
-	 */
240
-	public function get_description( $context = 'view' ) {
241
-		return $this->get_prop( 'description', $context );
234
+     * Get the item description.
235
+     *
236
+     * @since 1.0.19
237
+     * @param  string $context View or edit context.
238
+     * @return string
239
+     */
240
+    public function get_description( $context = 'view' ) {
241
+        return $this->get_prop( 'description', $context );
242 242
     }
243 243
 
244 244
     /**
245
-	 * Alias of self::get_description().
246
-	 *
247
-	 * @since 1.0.19
248
-	 * @param  string $context View or edit context.
249
-	 * @return string
250
-	 */
251
-	public function get_excerpt( $context = 'view' ) {
252
-		return $this->get_description( $context );
245
+     * Alias of self::get_description().
246
+     *
247
+     * @since 1.0.19
248
+     * @param  string $context View or edit context.
249
+     * @return string
250
+     */
251
+    public function get_excerpt( $context = 'view' ) {
252
+        return $this->get_description( $context );
253 253
     }
254 254
 
255 255
     /**
256
-	 * Alias of self::get_description().
257
-	 *
258
-	 * @since 1.0.19
259
-	 * @param  string $context View or edit context.
260
-	 * @return string
261
-	 */
262
-	public function get_summary( $context = 'view' ) {
263
-		return $this->get_description( $context );
256
+     * Alias of self::get_description().
257
+     *
258
+     * @since 1.0.19
259
+     * @param  string $context View or edit context.
260
+     * @return string
261
+     */
262
+    public function get_summary( $context = 'view' ) {
263
+        return $this->get_description( $context );
264 264
     }
265 265
 
266 266
     /**
267
-	 * Get the owner of the item.
268
-	 *
269
-	 * @since 1.0.19
270
-	 * @param  string $context View or edit context.
271
-	 * @return int
272
-	 */
273
-	public function get_author( $context = 'view' ) {
274
-		return (int) $this->get_prop( 'author', $context );
275
-	}
267
+     * Get the owner of the item.
268
+     *
269
+     * @since 1.0.19
270
+     * @param  string $context View or edit context.
271
+     * @return int
272
+     */
273
+    public function get_author( $context = 'view' ) {
274
+        return (int) $this->get_prop( 'author', $context );
275
+    }
276 276
 	
277
-	/**
278
-	 * Alias of self::get_author().
279
-	 *
280
-	 * @since 1.0.19
281
-	 * @param  string $context View or edit context.
282
-	 * @return int
283
-	 */
284
-	public function get_owner( $context = 'view' ) {
285
-		return $this->get_author( $context );
286
-    }
287
-
288
-    /**
289
-	 * Get the price of the item.
290
-	 *
291
-	 * @since 1.0.19
292
-	 * @param  string $context View or edit context.
293
-	 * @return float
294
-	 */
295
-	public function get_price( $context = 'view' ) {
277
+    /**
278
+     * Alias of self::get_author().
279
+     *
280
+     * @since 1.0.19
281
+     * @param  string $context View or edit context.
282
+     * @return int
283
+     */
284
+    public function get_owner( $context = 'view' ) {
285
+        return $this->get_author( $context );
286
+    }
287
+
288
+    /**
289
+     * Get the price of the item.
290
+     *
291
+     * @since 1.0.19
292
+     * @param  string $context View or edit context.
293
+     * @return float
294
+     */
295
+    public function get_price( $context = 'view' ) {
296 296
         return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
297
-	}
297
+    }
298 298
 	
299
-	/**
300
-	 * Get the inital price of the item.
301
-	 *
302
-	 * @since 1.0.19
303
-	 * @param  string $context View or edit context.
304
-	 * @return float
305
-	 */
306
-	public function get_initial_price( $context = 'view' ) {
299
+    /**
300
+     * Get the inital price of the item.
301
+     *
302
+     * @since 1.0.19
303
+     * @param  string $context View or edit context.
304
+     * @return float
305
+     */
306
+    public function get_initial_price( $context = 'view' ) {
307 307
 
308
-		$price = (float) $this->get_price( $context );
308
+        $price = (float) $this->get_price( $context );
309 309
 
310
-		if ( $this->has_free_trial() ) {
311
-			$price = 0;
312
-		}
310
+        if ( $this->has_free_trial() ) {
311
+            $price = 0;
312
+        }
313 313
 
314 314
         return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) );
315 315
     }
316 316
 
317 317
     /**
318
-	 * Returns a formated price.
319
-	 *
320
-	 * @since 1.0.19
321
-	 * @param  string $context View or edit context.
322
-	 * @return string
323
-	 */
318
+     * Returns a formated price.
319
+     *
320
+     * @since 1.0.19
321
+     * @param  string $context View or edit context.
322
+     * @return string
323
+     */
324 324
     public function get_the_price() {
325 325
         return wpinv_price( wpinv_format_amount( $this->get_price() ) );
326
-	}
327
-
328
-	/**
329
-	 * Returns the formated initial price.
330
-	 *
331
-	 * @since 1.0.19
332
-	 * @param  string $context View or edit context.
333
-	 * @return string
334
-	 */
326
+    }
327
+
328
+    /**
329
+     * Returns the formated initial price.
330
+     *
331
+     * @since 1.0.19
332
+     * @param  string $context View or edit context.
333
+     * @return string
334
+     */
335 335
     public function get_the_initial_price() {
336 336
         return wpinv_price( wpinv_format_amount( $this->get_initial_price() ) );
337 337
     }
338 338
 
339 339
     /**
340
-	 * Get the VAT rule of the item.
341
-	 *
342
-	 * @since 1.0.19
343
-	 * @param  string $context View or edit context.
344
-	 * @return string
345
-	 */
346
-	public function get_vat_rule( $context = 'view' ) {
340
+     * Get the VAT rule of the item.
341
+     *
342
+     * @since 1.0.19
343
+     * @param  string $context View or edit context.
344
+     * @return string
345
+     */
346
+    public function get_vat_rule( $context = 'view' ) {
347 347
         return $this->get_prop( 'vat_rule', $context );
348 348
     }
349 349
 
350 350
     /**
351
-	 * Get the VAT class of the item.
352
-	 *
353
-	 * @since 1.0.19
354
-	 * @param  string $context View or edit context.
355
-	 * @return string
356
-	 */
357
-	public function get_vat_class( $context = 'view' ) {
351
+     * Get the VAT class of the item.
352
+     *
353
+     * @since 1.0.19
354
+     * @param  string $context View or edit context.
355
+     * @return string
356
+     */
357
+    public function get_vat_class( $context = 'view' ) {
358 358
         return $this->get_prop( 'vat_class', $context );
359 359
     }
360 360
 
361 361
     /**
362
-	 * Get the type of the item.
363
-	 *
364
-	 * @since 1.0.19
365
-	 * @param  string $context View or edit context.
366
-	 * @return string
367
-	 */
368
-	public function get_type( $context = 'view' ) {
362
+     * Get the type of the item.
363
+     *
364
+     * @since 1.0.19
365
+     * @param  string $context View or edit context.
366
+     * @return string
367
+     */
368
+    public function get_type( $context = 'view' ) {
369 369
         return $this->get_prop( 'type', $context );
370 370
     }
371 371
 
372 372
     /**
373
-	 * Get the custom id of the item.
374
-	 *
375
-	 * @since 1.0.19
376
-	 * @param  string $context View or edit context.
377
-	 * @return string
378
-	 */
379
-	public function get_custom_id( $context = 'view' ) {
373
+     * Get the custom id of the item.
374
+     *
375
+     * @since 1.0.19
376
+     * @param  string $context View or edit context.
377
+     * @return string
378
+     */
379
+    public function get_custom_id( $context = 'view' ) {
380 380
         return $this->get_prop( 'custom_id', $context );
381 381
     }
382 382
 
383 383
     /**
384
-	 * Get the custom name of the item.
385
-	 *
386
-	 * @since 1.0.19
387
-	 * @param  string $context View or edit context.
388
-	 * @return string
389
-	 */
390
-	public function get_custom_name( $context = 'view' ) {
384
+     * Get the custom name of the item.
385
+     *
386
+     * @since 1.0.19
387
+     * @param  string $context View or edit context.
388
+     * @return string
389
+     */
390
+    public function get_custom_name( $context = 'view' ) {
391 391
         return $this->get_prop( 'custom_name', $context );
392 392
     }
393 393
 
394 394
     /**
395
-	 * Get the custom singular name of the item.
396
-	 *
397
-	 * @since 1.0.19
398
-	 * @param  string $context View or edit context.
399
-	 * @return string
400
-	 */
401
-	public function get_custom_singular_name( $context = 'view' ) {
395
+     * Get the custom singular name of the item.
396
+     *
397
+     * @since 1.0.19
398
+     * @param  string $context View or edit context.
399
+     * @return string
400
+     */
401
+    public function get_custom_singular_name( $context = 'view' ) {
402 402
         return $this->get_prop( 'custom_singular_name', $context );
403 403
     }
404 404
 
405 405
     /**
406
-	 * Checks if an item is editable..
407
-	 *
408
-	 * @since 1.0.19
409
-	 * @param  string $context View or edit context.
410
-	 * @return int
411
-	 */
412
-	public function get_is_editable( $context = 'view' ) {
406
+     * Checks if an item is editable..
407
+     *
408
+     * @since 1.0.19
409
+     * @param  string $context View or edit context.
410
+     * @return int
411
+     */
412
+    public function get_is_editable( $context = 'view' ) {
413 413
         return (int) $this->get_prop( 'is_editable', $context );
414 414
     }
415 415
 
416 416
     /**
417
-	 * Alias of self::get_is_editable().
418
-	 *
419
-	 * @since 1.0.19
420
-	 * @param  string $context View or edit context.
421
-	 * @return int
422
-	 */
423
-	public function get_editable( $context = 'view' ) {
424
-		return $this->get_is_editable( $context );
417
+     * Alias of self::get_is_editable().
418
+     *
419
+     * @since 1.0.19
420
+     * @param  string $context View or edit context.
421
+     * @return int
422
+     */
423
+    public function get_editable( $context = 'view' ) {
424
+        return $this->get_is_editable( $context );
425 425
     }
426 426
 
427 427
     /**
428
-	 * Checks if dynamic pricing is enabled.
429
-	 *
430
-	 * @since 1.0.19
431
-	 * @param  string $context View or edit context.
432
-	 * @return int
433
-	 */
434
-	public function get_is_dynamic_pricing( $context = 'view' ) {
428
+     * Checks if dynamic pricing is enabled.
429
+     *
430
+     * @since 1.0.19
431
+     * @param  string $context View or edit context.
432
+     * @return int
433
+     */
434
+    public function get_is_dynamic_pricing( $context = 'view' ) {
435 435
         return (int) $this->get_prop( 'is_dynamic_pricing', $context );
436 436
     }
437 437
 
438 438
     /**
439
-	 * Returns the minimum price if dynamic pricing is enabled.
440
-	 *
441
-	 * @since 1.0.19
442
-	 * @param  string $context View or edit context.
443
-	 * @return float
444
-	 */
445
-	public function get_minimum_price( $context = 'view' ) {
439
+     * Returns the minimum price if dynamic pricing is enabled.
440
+     *
441
+     * @since 1.0.19
442
+     * @param  string $context View or edit context.
443
+     * @return float
444
+     */
445
+    public function get_minimum_price( $context = 'view' ) {
446 446
         return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
447 447
     }
448 448
 
449 449
     /**
450
-	 * Checks if this is a recurring item.
451
-	 *
452
-	 * @since 1.0.19
453
-	 * @param  string $context View or edit context.
454
-	 * @return int
455
-	 */
456
-	public function get_is_recurring( $context = 'view' ) {
450
+     * Checks if this is a recurring item.
451
+     *
452
+     * @since 1.0.19
453
+     * @param  string $context View or edit context.
454
+     * @return int
455
+     */
456
+    public function get_is_recurring( $context = 'view' ) {
457 457
         return (int) $this->get_prop( 'is_recurring', $context );
458
-	}
458
+    }
459 459
 	
460
-	/**
461
-	 * Get the recurring price of the item.
462
-	 *
463
-	 * @since 1.0.19
464
-	 * @param  string $context View or edit context.
465
-	 * @return float
466
-	 */
467
-	public function get_recurring_price( $context = 'view' ) {
468
-		$price = $this->get_price( $context );
460
+    /**
461
+     * Get the recurring price of the item.
462
+     *
463
+     * @since 1.0.19
464
+     * @param  string $context View or edit context.
465
+     * @return float
466
+     */
467
+    public function get_recurring_price( $context = 'view' ) {
468
+        $price = $this->get_price( $context );
469 469
         return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
470
-	}
471
-
472
-	/**
473
-	 * Get the formatted recurring price of the item.
474
-	 *
475
-	 * @since 1.0.19
476
-	 * @param  string $context View or edit context.
477
-	 * @return string
478
-	 */
470
+    }
471
+
472
+    /**
473
+     * Get the formatted recurring price of the item.
474
+     *
475
+     * @since 1.0.19
476
+     * @param  string $context View or edit context.
477
+     * @return string
478
+     */
479 479
     public function get_the_recurring_price() {
480 480
         return wpinv_price( wpinv_format_amount( $this->get_recurring_price() ) );
481
-	}
482
-
483
-	/**
484
-	 * Get the first renewal date (in timestamps) of the item.
485
-	 *
486
-	 * @since 1.0.19
487
-	 * @return int
488
-	 */
489
-	public function get_first_renewal_date() {
490
-
491
-		$periods = array(
492
-			'D' => 'days',
493
-			'W' => 'weeks',
494
-			'M' => 'months',
495
-			'Y' => 'years',
496
-		);
497
-
498
-		$period   = $this->get_recurring_period();
499
-		$interval = $this->get_recurring_interval();
500
-
501
-		if ( $this->has_free_trial() ) {
502
-			$period   = $this->get_trial_period();
503
-			$interval = $this->get_trial_interval();
504
-		}
505
-
506
-		$period       = $periods[ $period ];
507
-		$interval     = empty( $interval ) ? 1 : $interval;
508
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
481
+    }
482
+
483
+    /**
484
+     * Get the first renewal date (in timestamps) of the item.
485
+     *
486
+     * @since 1.0.19
487
+     * @return int
488
+     */
489
+    public function get_first_renewal_date() {
490
+
491
+        $periods = array(
492
+            'D' => 'days',
493
+            'W' => 'weeks',
494
+            'M' => 'months',
495
+            'Y' => 'years',
496
+        );
497
+
498
+        $period   = $this->get_recurring_period();
499
+        $interval = $this->get_recurring_interval();
500
+
501
+        if ( $this->has_free_trial() ) {
502
+            $period   = $this->get_trial_period();
503
+            $interval = $this->get_trial_interval();
504
+        }
505
+
506
+        $period       = $periods[ $period ];
507
+        $interval     = empty( $interval ) ? 1 : $interval;
508
+        $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
509 509
         return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
510 510
     }
511 511
 
512 512
     /**
513
-	 * Get the recurring period.
514
-	 *
515
-	 * @since 1.0.19
516
-	 * @param  bool $full Return abbreviation or in full.
517
-	 * @return string
518
-	 */
519
-	public function get_recurring_period( $full = false ) {
513
+     * Get the recurring period.
514
+     *
515
+     * @since 1.0.19
516
+     * @param  bool $full Return abbreviation or in full.
517
+     * @return string
518
+     */
519
+    public function get_recurring_period( $full = false ) {
520 520
         $period = $this->get_prop( 'recurring_period', 'view' );
521 521
 
522 522
         if ( $full && ! is_bool( $full ) ) {
@@ -527,63 +527,63 @@  discard block
 block discarded – undo
527 527
     }
528 528
 
529 529
     /**
530
-	 * Get the recurring interval.
531
-	 *
532
-	 * @since 1.0.19
533
-	 * @param  string $context View or edit context.
534
-	 * @return int
535
-	 */
536
-	public function get_recurring_interval( $context = 'view' ) {
537
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
530
+     * Get the recurring interval.
531
+     *
532
+     * @since 1.0.19
533
+     * @param  string $context View or edit context.
534
+     * @return int
535
+     */
536
+    public function get_recurring_interval( $context = 'view' ) {
537
+        $interval = absint( $this->get_prop( 'recurring_interval', $context ) );
538 538
 
539
-		if ( $interval < 1 ) {
540
-			$interval = 1;
541
-		}
539
+        if ( $interval < 1 ) {
540
+            $interval = 1;
541
+        }
542 542
 
543 543
         return $interval;
544 544
     }
545 545
 
546 546
     /**
547
-	 * Get the recurring limit.
548
-	 *
549
-	 * @since 1.0.19
550
-	 * @param  string $context View or edit context.
551
-	 * @return int
552
-	 */
553
-	public function get_recurring_limit( $context = 'view' ) {
547
+     * Get the recurring limit.
548
+     *
549
+     * @since 1.0.19
550
+     * @param  string $context View or edit context.
551
+     * @return int
552
+     */
553
+    public function get_recurring_limit( $context = 'view' ) {
554 554
         return (int) $this->get_prop( 'recurring_limit', $context );
555 555
     }
556 556
 
557 557
     /**
558
-	 * Checks if we have a free trial.
559
-	 *
560
-	 * @since 1.0.19
561
-	 * @param  string $context View or edit context.
562
-	 * @return int
563
-	 */
564
-	public function get_is_free_trial( $context = 'view' ) {
558
+     * Checks if we have a free trial.
559
+     *
560
+     * @since 1.0.19
561
+     * @param  string $context View or edit context.
562
+     * @return int
563
+     */
564
+    public function get_is_free_trial( $context = 'view' ) {
565 565
         return (int) $this->get_prop( 'is_free_trial', $context );
566 566
     }
567 567
 
568 568
     /**
569
-	 * Alias for self::get_is_free_trial().
570
-	 *
571
-	 * @since 1.0.19
572
-	 * @param  string $context View or edit context.
573
-	 * @return int
574
-	 */
575
-	public function get_free_trial( $context = 'view' ) {
569
+     * Alias for self::get_is_free_trial().
570
+     *
571
+     * @since 1.0.19
572
+     * @param  string $context View or edit context.
573
+     * @return int
574
+     */
575
+    public function get_free_trial( $context = 'view' ) {
576 576
         return $this->get_is_free_trial( $context );
577 577
     }
578 578
 
579 579
     /**
580
-	 * Get the trial period.
581
-	 *
582
-	 * @since 1.0.19
583
-	 * @param  bool $full Return abbreviation or in full.
584
-	 * @return string
585
-	 */
586
-	public function get_trial_period( $full = false ) {
580
+     * Get the trial period.
581
+     *
582
+     * @since 1.0.19
583
+     * @param  bool $full Return abbreviation or in full.
584
+     * @return string
585
+     */
586
+    public function get_trial_period( $full = false ) {
587 587
         $period = $this->get_prop( 'trial_period', 'view' );
588 588
 
589 589
         if ( $full && ! is_bool( $full ) ) {
@@ -594,104 +594,104 @@  discard block
 block discarded – undo
594 594
     }
595 595
 
596 596
     /**
597
-	 * Get the trial interval.
598
-	 *
599
-	 * @since 1.0.19
600
-	 * @param  string $context View or edit context.
601
-	 * @return int
602
-	 */
603
-	public function get_trial_interval( $context = 'view' ) {
597
+     * Get the trial interval.
598
+     *
599
+     * @since 1.0.19
600
+     * @param  string $context View or edit context.
601
+     * @return int
602
+     */
603
+    public function get_trial_interval( $context = 'view' ) {
604 604
         return (int) $this->get_prop( 'trial_interval', $context );
605
-	}
605
+    }
606 606
 	
607
-	/**
608
-	 * Get the item's edit url.
609
-	 *
610
-	 * @since 1.0.19
611
-	 * @return string
612
-	 */
613
-	public function get_edit_url() {
607
+    /**
608
+     * Get the item's edit url.
609
+     *
610
+     * @since 1.0.19
611
+     * @return string
612
+     */
613
+    public function get_edit_url() {
614 614
         return get_edit_post_link( $this->get_id() );
615
-	}
616
-
617
-	/**
618
-	 * Given an item's name/custom id, it returns its id.
619
-	 *
620
-	 *
621
-	 * @static
622
-	 * @param string $value The item name or custom id.
623
-	 * @param string $field Either name or custom_id.
624
-	 * @param string $type in case you need to search for a given type.
625
-	 * @since 1.0.15
626
-	 * @return int
627
-	 */
628
-	public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
629
-
630
-		// Trim the value.
631
-		$value = trim( $value );
632
-
633
-		if ( empty( $value ) ) {
634
-			return 0;
635
-		}
615
+    }
616
+
617
+    /**
618
+     * Given an item's name/custom id, it returns its id.
619
+     *
620
+     *
621
+     * @static
622
+     * @param string $value The item name or custom id.
623
+     * @param string $field Either name or custom_id.
624
+     * @param string $type in case you need to search for a given type.
625
+     * @since 1.0.15
626
+     * @return int
627
+     */
628
+    public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
629
+
630
+        // Trim the value.
631
+        $value = trim( $value );
632
+
633
+        if ( empty( $value ) ) {
634
+            return 0;
635
+        }
636 636
 
637 637
         // Valid fields.
638 638
         $fields = array( 'custom_id', 'name', 'slug' );
639 639
 
640
-		// Ensure a field has been passed.
641
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
642
-			return 0;
643
-		}
644
-
645
-		if ( $field == 'name' ) {
646
-			$field = 'slug';
647
-		} 
648
-
649
-		// Maybe retrieve from the cache.
650
-		$item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
651
-		if ( ! empty( $item_id ) ) {
652
-			return $item_id;
653
-		}
654
-
655
-		// Fetch from the db.
656
-		if ( $field =='slug' ) {
657
-			$items = get_posts(
658
-				array(
659
-					'post_type'      => 'wpi_item',
660
-					'name'           => $value,
661
-					'posts_per_page' => 1,
662
-					'post_status'    => 'any',
663
-				)
664
-			);
665
-		}
666
-
667
-		if ( $field =='custom_id' ) {
668
-			$items = get_posts(
669
-				array(
670
-					'post_type'      => 'wpi_item',
671
-					'posts_per_page' => 1,
672
-					'post_status'    => 'any',
673
-					'meta_query'     => array(
674
-						array(
675
-							'key'   => '_wpinv_type',
676
-                			'value' => $type,
677
-						),
678
-						array(
679
-							'key'   => '_wpinv_custom_id',
680
-                			'value' => $type,
681
-						)
682
-					)
683
-				)
684
-			);
685
-		}
686
-
687
-		if ( empty( $items ) ) {
688
-			return 0;
689
-		}
690
-
691
-		// Update the cache with our data
692
-		wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
693
-
694
-		return $items[0]->ID;
640
+        // Ensure a field has been passed.
641
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
642
+            return 0;
643
+        }
644
+
645
+        if ( $field == 'name' ) {
646
+            $field = 'slug';
647
+        } 
648
+
649
+        // Maybe retrieve from the cache.
650
+        $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
651
+        if ( ! empty( $item_id ) ) {
652
+            return $item_id;
653
+        }
654
+
655
+        // Fetch from the db.
656
+        if ( $field =='slug' ) {
657
+            $items = get_posts(
658
+                array(
659
+                    'post_type'      => 'wpi_item',
660
+                    'name'           => $value,
661
+                    'posts_per_page' => 1,
662
+                    'post_status'    => 'any',
663
+                )
664
+            );
665
+        }
666
+
667
+        if ( $field =='custom_id' ) {
668
+            $items = get_posts(
669
+                array(
670
+                    'post_type'      => 'wpi_item',
671
+                    'posts_per_page' => 1,
672
+                    'post_status'    => 'any',
673
+                    'meta_query'     => array(
674
+                        array(
675
+                            'key'   => '_wpinv_type',
676
+                            'value' => $type,
677
+                        ),
678
+                        array(
679
+                            'key'   => '_wpinv_custom_id',
680
+                            'value' => $type,
681
+                        )
682
+                    )
683
+                )
684
+            );
685
+        }
686
+
687
+        if ( empty( $items ) ) {
688
+            return 0;
689
+        }
690
+
691
+        // Update the cache with our data
692
+        wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
693
+
694
+        return $items[0]->ID;
695 695
     }
696 696
 
697 697
     /**
@@ -724,52 +724,52 @@  discard block
 block discarded – undo
724 724
     */
725 725
 
726 726
     /**
727
-	 * Set parent order ID.
728
-	 *
729
-	 * @since 1.0.19
730
-	 */
731
-	public function set_parent_id( $value ) {
732
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
733
-			return;
734
-		}
735
-		$this->set_prop( 'parent_id', absint( $value ) );
736
-	}
737
-
738
-    /**
739
-	 * Sets item status.
740
-	 *
741
-	 * @since 1.0.19
742
-	 * @param  string $status New status.
743
-	 * @return array details of change.
744
-	 */
745
-	public function set_status( $status ) {
727
+     * Set parent order ID.
728
+     *
729
+     * @since 1.0.19
730
+     */
731
+    public function set_parent_id( $value ) {
732
+        if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
733
+            return;
734
+        }
735
+        $this->set_prop( 'parent_id', absint( $value ) );
736
+    }
737
+
738
+    /**
739
+     * Sets item status.
740
+     *
741
+     * @since 1.0.19
742
+     * @param  string $status New status.
743
+     * @return array details of change.
744
+     */
745
+    public function set_status( $status ) {
746 746
         $old_status = $this->get_status();
747 747
 
748 748
         $this->set_prop( 'status', $status );
749 749
 
750
-		return array(
751
-			'from' => $old_status,
752
-			'to'   => $status,
753
-		);
750
+        return array(
751
+            'from' => $old_status,
752
+            'to'   => $status,
753
+        );
754 754
     }
755 755
 
756 756
     /**
757
-	 * Set plugin version when the item was created.
758
-	 *
759
-	 * @since 1.0.19
760
-	 */
761
-	public function set_version( $value ) {
762
-		$this->set_prop( 'version', $value );
757
+     * Set plugin version when the item was created.
758
+     *
759
+     * @since 1.0.19
760
+     */
761
+    public function set_version( $value ) {
762
+        $this->set_prop( 'version', $value );
763 763
     }
764 764
 
765 765
     /**
766
-	 * Set date when the item was created.
767
-	 *
768
-	 * @since 1.0.19
769
-	 * @param string $value Value to set.
766
+     * Set date when the item was created.
767
+     *
768
+     * @since 1.0.19
769
+     * @param string $value Value to set.
770 770
      * @return bool Whether or not the date was set.
771
-	 */
772
-	public function set_date_created( $value ) {
771
+     */
772
+    public function set_date_created( $value ) {
773 773
         $date = strtotime( $value );
774 774
 
775 775
         if ( $date ) {
@@ -782,13 +782,13 @@  discard block
 block discarded – undo
782 782
     }
783 783
 
784 784
     /**
785
-	 * Set date when the item was last modified.
786
-	 *
787
-	 * @since 1.0.19
788
-	 * @param string $value Value to set.
785
+     * Set date when the item was last modified.
786
+     *
787
+     * @since 1.0.19
788
+     * @param string $value Value to set.
789 789
      * @return bool Whether or not the date was set.
790
-	 */
791
-	public function set_date_modified( $value ) {
790
+     */
791
+    public function set_date_modified( $value ) {
792 792
         $date = strtotime( $value );
793 793
 
794 794
         if ( $date ) {
@@ -801,115 +801,115 @@  discard block
 block discarded – undo
801 801
     }
802 802
 
803 803
     /**
804
-	 * Set the item name.
805
-	 *
806
-	 * @since 1.0.19
807
-	 * @param  string $value New name.
808
-	 */
809
-	public function set_name( $value ) {
804
+     * Set the item name.
805
+     *
806
+     * @since 1.0.19
807
+     * @param  string $value New name.
808
+     */
809
+    public function set_name( $value ) {
810 810
         $name = sanitize_text_field( $value );
811
-		$this->set_prop( 'name', $name );
811
+        $this->set_prop( 'name', $name );
812 812
     }
813 813
 
814 814
     /**
815
-	 * Alias of self::set_name().
816
-	 *
817
-	 * @since 1.0.19
818
-	 * @param  string $value New name.
819
-	 */
820
-	public function set_title( $value ) {
821
-		$this->set_name( $value );
815
+     * Alias of self::set_name().
816
+     *
817
+     * @since 1.0.19
818
+     * @param  string $value New name.
819
+     */
820
+    public function set_title( $value ) {
821
+        $this->set_name( $value );
822 822
     }
823 823
 
824 824
     /**
825
-	 * Set the item description.
826
-	 *
827
-	 * @since 1.0.19
828
-	 * @param  string $value New description.
829
-	 */
830
-	public function set_description( $value ) {
825
+     * Set the item description.
826
+     *
827
+     * @since 1.0.19
828
+     * @param  string $value New description.
829
+     */
830
+    public function set_description( $value ) {
831 831
         $description = wp_kses_post( $value );
832
-		return $this->set_prop( 'description', $description );
832
+        return $this->set_prop( 'description', $description );
833 833
     }
834 834
 
835 835
     /**
836
-	 * Alias of self::set_description().
837
-	 *
838
-	 * @since 1.0.19
839
-	 * @param  string $value New description.
840
-	 */
841
-	public function set_excerpt( $value ) {
842
-		$this->set_description( $value );
836
+     * Alias of self::set_description().
837
+     *
838
+     * @since 1.0.19
839
+     * @param  string $value New description.
840
+     */
841
+    public function set_excerpt( $value ) {
842
+        $this->set_description( $value );
843 843
     }
844 844
 
845 845
     /**
846
-	 * Alias of self::set_description().
847
-	 *
848
-	 * @since 1.0.19
849
-	 * @param  string $value New description.
850
-	 */
851
-	public function set_summary( $value ) {
852
-		$this->set_description( $value );
846
+     * Alias of self::set_description().
847
+     *
848
+     * @since 1.0.19
849
+     * @param  string $value New description.
850
+     */
851
+    public function set_summary( $value ) {
852
+        $this->set_description( $value );
853 853
     }
854 854
 
855 855
     /**
856
-	 * Set the owner of the item.
857
-	 *
858
-	 * @since 1.0.19
859
-	 * @param  int $value New author.
860
-	 */
861
-	public function set_author( $value ) {
862
-		$this->set_prop( 'author', (int) $value );
863
-	}
856
+     * Set the owner of the item.
857
+     *
858
+     * @since 1.0.19
859
+     * @param  int $value New author.
860
+     */
861
+    public function set_author( $value ) {
862
+        $this->set_prop( 'author', (int) $value );
863
+    }
864 864
 	
865
-	/**
866
-	 * Alias of self::set_author().
867
-	 *
868
-	 * @since 1.0.19
869
-	 * @param  int $value New author.
870
-	 */
871
-	public function set_owner( $value ) {
872
-		$this->set_author( $value );
873
-    }
874
-
875
-    /**
876
-	 * Set the price of the item.
877
-	 *
878
-	 * @since 1.0.19
879
-	 * @param  float $value New price.
880
-	 */
881
-	public function set_price( $value ) {
865
+    /**
866
+     * Alias of self::set_author().
867
+     *
868
+     * @since 1.0.19
869
+     * @param  int $value New author.
870
+     */
871
+    public function set_owner( $value ) {
872
+        $this->set_author( $value );
873
+    }
874
+
875
+    /**
876
+     * Set the price of the item.
877
+     *
878
+     * @since 1.0.19
879
+     * @param  float $value New price.
880
+     */
881
+    public function set_price( $value ) {
882 882
         $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
883 883
     }
884 884
 
885 885
     /**
886
-	 * Set the VAT rule of the item.
887
-	 *
888
-	 * @since 1.0.19
889
-	 * @param  string $value new rule.
890
-	 */
891
-	public function set_vat_rule( $value ) {
886
+     * Set the VAT rule of the item.
887
+     *
888
+     * @since 1.0.19
889
+     * @param  string $value new rule.
890
+     */
891
+    public function set_vat_rule( $value ) {
892 892
         $this->set_prop( 'vat_rule', $value );
893 893
     }
894 894
 
895 895
     /**
896
-	 * Set the VAT class of the item.
897
-	 *
898
-	 * @since 1.0.19
899
-	 * @param  string $value new class.
900
-	 */
901
-	public function set_vat_class( $value ) {
896
+     * Set the VAT class of the item.
897
+     *
898
+     * @since 1.0.19
899
+     * @param  string $value new class.
900
+     */
901
+    public function set_vat_class( $value ) {
902 902
         $this->set_prop( 'vat_class', $value );
903 903
     }
904 904
 
905 905
     /**
906
-	 * Set the type of the item.
907
-	 *
908
-	 * @since 1.0.19
909
-	 * @param  string $value new item type.
910
-	 * @return string
911
-	 */
912
-	public function set_type( $value ) {
906
+     * Set the type of the item.
907
+     *
908
+     * @since 1.0.19
909
+     * @param  string $value new item type.
910
+     * @return string
911
+     */
912
+    public function set_type( $value ) {
913 913
 
914 914
         if ( empty( $value ) ) {
915 915
             $value = 'custom';
@@ -919,134 +919,134 @@  discard block
 block discarded – undo
919 919
     }
920 920
 
921 921
     /**
922
-	 * Set the custom id of the item.
923
-	 *
924
-	 * @since 1.0.19
925
-	 * @param  string $value new custom id.
926
-	 */
927
-	public function set_custom_id( $value ) {
922
+     * Set the custom id of the item.
923
+     *
924
+     * @since 1.0.19
925
+     * @param  string $value new custom id.
926
+     */
927
+    public function set_custom_id( $value ) {
928 928
         $this->set_prop( 'custom_id', $value );
929 929
     }
930 930
 
931 931
     /**
932
-	 * Set the custom name of the item.
933
-	 *
934
-	 * @since 1.0.19
935
-	 * @param  string $value new custom name.
936
-	 */
937
-	public function set_custom_name( $value ) {
932
+     * Set the custom name of the item.
933
+     *
934
+     * @since 1.0.19
935
+     * @param  string $value new custom name.
936
+     */
937
+    public function set_custom_name( $value ) {
938 938
         $this->set_prop( 'custom_name', $value );
939 939
     }
940 940
 
941 941
     /**
942
-	 * Set the custom singular name of the item.
943
-	 *
944
-	 * @since 1.0.19
945
-	 * @param  string $value new custom singular name.
946
-	 */
947
-	public function set_custom_singular_name( $value ) {
942
+     * Set the custom singular name of the item.
943
+     *
944
+     * @since 1.0.19
945
+     * @param  string $value new custom singular name.
946
+     */
947
+    public function set_custom_singular_name( $value ) {
948 948
         $this->set_prop( 'custom_singular_name', $value );
949 949
     }
950 950
 
951 951
     /**
952
-	 * Sets if an item is editable..
953
-	 *
954
-	 * @since 1.0.19
955
-	 * @param  int|bool $value whether or not the item is editable.
956
-	 */
957
-	public function set_is_editable( $value ) {
958
-		if ( is_numeric( $value ) ) {
959
-			$this->set_prop( 'is_editable', (int) $value );
960
-		}
952
+     * Sets if an item is editable..
953
+     *
954
+     * @since 1.0.19
955
+     * @param  int|bool $value whether or not the item is editable.
956
+     */
957
+    public function set_is_editable( $value ) {
958
+        if ( is_numeric( $value ) ) {
959
+            $this->set_prop( 'is_editable', (int) $value );
960
+        }
961 961
     }
962 962
 
963 963
     /**
964
-	 * Sets if dynamic pricing is enabled.
965
-	 *
966
-	 * @since 1.0.19
967
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
968
-	 */
969
-	public function set_is_dynamic_pricing( $value ) {
964
+     * Sets if dynamic pricing is enabled.
965
+     *
966
+     * @since 1.0.19
967
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
968
+     */
969
+    public function set_is_dynamic_pricing( $value ) {
970 970
         $this->set_prop( 'is_dynamic_pricing', (int) $value );
971 971
     }
972 972
 
973 973
     /**
974
-	 * Sets the minimum price if dynamic pricing is enabled.
975
-	 *
976
-	 * @since 1.0.19
977
-	 * @param  float $value minimum price.
978
-	 */
979
-	public function set_minimum_price( $value ) {
974
+     * Sets the minimum price if dynamic pricing is enabled.
975
+     *
976
+     * @since 1.0.19
977
+     * @param  float $value minimum price.
978
+     */
979
+    public function set_minimum_price( $value ) {
980 980
         $this->set_prop( 'minimum_price',  (float) wpinv_sanitize_amount( $value ) );
981 981
     }
982 982
 
983 983
     /**
984
-	 * Sets if this is a recurring item.
985
-	 *
986
-	 * @since 1.0.19
987
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
988
-	 */
989
-	public function set_is_recurring( $value ) {
984
+     * Sets if this is a recurring item.
985
+     *
986
+     * @since 1.0.19
987
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
988
+     */
989
+    public function set_is_recurring( $value ) {
990 990
         $this->set_prop( 'is_recurring', (int) $value );
991 991
     }
992 992
 
993 993
     /**
994
-	 * Set the recurring period.
995
-	 *
996
-	 * @since 1.0.19
997
-	 * @param  string $value new period.
998
-	 */
999
-	public function set_recurring_period( $value ) {
994
+     * Set the recurring period.
995
+     *
996
+     * @since 1.0.19
997
+     * @param  string $value new period.
998
+     */
999
+    public function set_recurring_period( $value ) {
1000 1000
         $this->set_prop( 'recurring_period', $value );
1001 1001
     }
1002 1002
 
1003 1003
     /**
1004
-	 * Set the recurring interval.
1005
-	 *
1006
-	 * @since 1.0.19
1007
-	 * @param  int $value recurring interval.
1008
-	 */
1009
-	public function set_recurring_interval( $value ) {
1004
+     * Set the recurring interval.
1005
+     *
1006
+     * @since 1.0.19
1007
+     * @param  int $value recurring interval.
1008
+     */
1009
+    public function set_recurring_interval( $value ) {
1010 1010
         return $this->set_prop( 'recurring_interval', (int) $value );
1011 1011
     }
1012 1012
 
1013 1013
     /**
1014
-	 * Get the recurring limit.
1015
-	 * @since 1.0.19
1016
-	 * @param  int $value The recurring limit.
1017
-	 * @return int
1018
-	 */
1019
-	public function set_recurring_limit( $value ) {
1014
+     * Get the recurring limit.
1015
+     * @since 1.0.19
1016
+     * @param  int $value The recurring limit.
1017
+     * @return int
1018
+     */
1019
+    public function set_recurring_limit( $value ) {
1020 1020
         $this->set_prop( 'recurring_limit', (int) $value );
1021 1021
     }
1022 1022
 
1023 1023
     /**
1024
-	 * Checks if we have a free trial.
1025
-	 *
1026
-	 * @since 1.0.19
1027
-	 * @param  int|bool $value whether or not it has a free trial.
1028
-	 */
1029
-	public function set_is_free_trial( $value ) {
1024
+     * Checks if we have a free trial.
1025
+     *
1026
+     * @since 1.0.19
1027
+     * @param  int|bool $value whether or not it has a free trial.
1028
+     */
1029
+    public function set_is_free_trial( $value ) {
1030 1030
         $this->set_prop( 'is_free_trial', (int) $value );
1031 1031
     }
1032 1032
 
1033 1033
     /**
1034
-	 * Set the trial period.
1035
-	 *
1036
-	 * @since 1.0.19
1037
-	 * @param  string $value trial period.
1038
-	 */
1039
-	public function set_trial_period( $value ) {
1034
+     * Set the trial period.
1035
+     *
1036
+     * @since 1.0.19
1037
+     * @param  string $value trial period.
1038
+     */
1039
+    public function set_trial_period( $value ) {
1040 1040
         $this->set_prop( 'trial_period', $value );
1041 1041
     }
1042 1042
 
1043 1043
     /**
1044
-	 * Set the trial interval.
1045
-	 *
1046
-	 * @since 1.0.19
1047
-	 * @param  int $value trial interval.
1048
-	 */
1049
-	public function set_trial_interval( $value ) {
1044
+     * Set the trial interval.
1045
+     *
1046
+     * @since 1.0.19
1047
+     * @param  int $value trial interval.
1048
+     */
1049
+    public function set_trial_interval( $value ) {
1050 1050
         $this->set_prop( 'trial_interval', $value );
1051 1051
     }
1052 1052
 
@@ -1054,17 +1054,17 @@  discard block
 block discarded – undo
1054 1054
      * Create an item. For backwards compatibilty.
1055 1055
      * 
1056 1056
      * @deprecated
1057
-	 * @return int item id
1057
+     * @return int item id
1058 1058
      */
1059 1059
     public function create( $data = array() ) {
1060 1060
 
1061
-		// Set the properties.
1062
-		if ( is_array( $data ) ) {
1063
-			$this->set_props( $data );
1064
-		}
1061
+        // Set the properties.
1062
+        if ( is_array( $data ) ) {
1063
+            $this->set_props( $data );
1064
+        }
1065 1065
 
1066
-		// Save the item.
1067
-		return $this->save();
1066
+        // Save the item.
1067
+        return $this->save();
1068 1068
 
1069 1069
     }
1070 1070
 
@@ -1072,7 +1072,7 @@  discard block
 block discarded – undo
1072 1072
      * Updates an item. For backwards compatibilty.
1073 1073
      * 
1074 1074
      * @deprecated
1075
-	 * @return int item id
1075
+     * @return int item id
1076 1076
      */
1077 1077
     public function update( $data = array() ) {
1078 1078
         return $this->create( $data );
@@ -1088,84 +1088,84 @@  discard block
 block discarded – undo
1088 1088
 	*/
1089 1089
 
1090 1090
     /**
1091
-	 * Checks whether the item has enabled dynamic pricing.
1092
-	 *
1093
-	 * @since 1.0.19
1094
-	 * @return bool
1095
-	 */
1096
-	public function user_can_set_their_price() {
1091
+     * Checks whether the item has enabled dynamic pricing.
1092
+     *
1093
+     * @since 1.0.19
1094
+     * @return bool
1095
+     */
1096
+    public function user_can_set_their_price() {
1097 1097
         return (bool) $this->get_is_dynamic_pricing();
1098
-	}
1098
+    }
1099 1099
 	
1100
-	/**
1101
-	 * Checks whether the item is recurring.
1102
-	 *
1103
-	 * @since 1.0.19
1104
-	 * @return bool
1105
-	 */
1106
-	public function is_recurring() {
1100
+    /**
1101
+     * Checks whether the item is recurring.
1102
+     *
1103
+     * @since 1.0.19
1104
+     * @return bool
1105
+     */
1106
+    public function is_recurring() {
1107 1107
         return (bool) $this->get_is_recurring();
1108 1108
     }
1109 1109
 
1110 1110
     /**
1111
-	 * Checks whether the item has a free trial.
1112
-	 *
1113
-	 * @since 1.0.19
1114
-	 * @return bool
1115
-	 */
1111
+     * Checks whether the item has a free trial.
1112
+     *
1113
+     * @since 1.0.19
1114
+     * @return bool
1115
+     */
1116 1116
     public function has_free_trial() {
1117 1117
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
1118 1118
         return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
1119 1119
     }
1120 1120
 
1121 1121
     /**
1122
-	 * Checks whether the item is free.
1123
-	 *
1124
-	 * @since 1.0.19
1125
-	 * @return bool
1126
-	 */
1122
+     * Checks whether the item is free.
1123
+     *
1124
+     * @since 1.0.19
1125
+     * @return bool
1126
+     */
1127 1127
     public function is_free() {
1128 1128
         $is_free   = $this->get_price() == 0;
1129 1129
         return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
1130 1130
     }
1131 1131
 
1132 1132
     /**
1133
-	 * Checks the item status against a passed in status.
1134
-	 *
1135
-	 * @param array|string $status Status to check.
1136
-	 * @return bool
1137
-	 */
1138
-	public function has_status( $status ) {
1139
-		$has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1140
-		return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1133
+     * Checks the item status against a passed in status.
1134
+     *
1135
+     * @param array|string $status Status to check.
1136
+     * @return bool
1137
+     */
1138
+    public function has_status( $status ) {
1139
+        $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1140
+        return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1141 1141
     }
1142 1142
 
1143 1143
     /**
1144
-	 * Checks the item type against a passed in types.
1145
-	 *
1146
-	 * @param array|string $type Type to check.
1147
-	 * @return bool
1148
-	 */
1149
-	public function is_type( $type ) {
1150
-		$is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1151
-		return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1152
-	}
1144
+     * Checks the item type against a passed in types.
1145
+     *
1146
+     * @param array|string $type Type to check.
1147
+     * @return bool
1148
+     */
1149
+    public function is_type( $type ) {
1150
+        $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1151
+        return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1152
+    }
1153 1153
 
1154 1154
     /**
1155
-	 * Checks whether the item is editable.
1156
-	 *
1157
-	 * @since 1.0.19
1158
-	 * @return bool
1159
-	 */
1155
+     * Checks whether the item is editable.
1156
+     *
1157
+     * @since 1.0.19
1158
+     * @return bool
1159
+     */
1160 1160
     public function is_editable() {
1161 1161
         $is_editable = $this->get_is_editable();
1162 1162
         return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1163
-	}
1163
+    }
1164 1164
 
1165
-	/**
1166
-	 * Returns an array of cart fees.
1167
-	 */
1168
-	public function get_fees( $type = 'fee', $item_id = 0 ) {
1165
+    /**
1166
+     * Returns an array of cart fees.
1167
+     */
1168
+    public function get_fees( $type = 'fee', $item_id = 0 ) {
1169 1169
         
1170 1170
         $fees = getpaid_session()->get( 'wpi_cart_fees' );
1171 1171
 
@@ -1208,11 +1208,11 @@  discard block
 block discarded – undo
1208 1208
     }
1209 1209
 
1210 1210
     /**
1211
-	 * Checks whether the item is purchasable.
1212
-	 *
1213
-	 * @since 1.0.19
1214
-	 * @return bool
1215
-	 */
1211
+     * Checks whether the item is purchasable.
1212
+     *
1213
+     * @since 1.0.19
1214
+     * @return bool
1215
+     */
1216 1216
     public function can_purchase() {
1217 1217
         $can_purchase = null !== $this->get_id();
1218 1218
 
@@ -1224,11 +1224,11 @@  discard block
 block discarded – undo
1224 1224
     }
1225 1225
 
1226 1226
     /**
1227
-	 * Checks whether the item supports dynamic pricing.
1228
-	 *
1229
-	 * @since 1.0.19
1230
-	 * @return bool
1231
-	 */
1227
+     * Checks whether the item supports dynamic pricing.
1228
+     *
1229
+     * @since 1.0.19
1230
+     * @return bool
1231
+     */
1232 1232
     public function supports_dynamic_pricing() {
1233 1233
         return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1234 1234
     }
Please login to merge, or discard this patch.
Spacing   +229 added lines, -229 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -78,30 +78,30 @@  discard block
 block discarded – undo
78 78
 	 *
79 79
 	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80 80
 	 */
81
-	public function __construct( $item = 0 ) {
82
-		parent::__construct( $item );
83
-
84
-		if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
85
-			$this->set_id( $item );
86
-		} elseif ( $item instanceof self ) {
87
-			$this->set_id( $item->get_id() );
88
-		} elseif ( ! empty( $item->ID ) ) {
89
-			$this->set_id( $item->ID );
90
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
91
-			$this->set_id( $item_id );
92
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
93
-			$this->set_id( $item_id );
81
+	public function __construct($item = 0) {
82
+		parent::__construct($item);
83
+
84
+		if (!empty($item) && is_numeric($item) && 'wpi_item' == get_post_type($item)) {
85
+			$this->set_id($item);
86
+		} elseif ($item instanceof self) {
87
+			$this->set_id($item->get_id());
88
+		} elseif (!empty($item->ID)) {
89
+			$this->set_id($item->ID);
90
+		} elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'custom_id')) {
91
+			$this->set_id($item_id);
92
+		} elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'name')) {
93
+			$this->set_id($item_id);
94 94
 		} else {
95
-			$this->set_object_read( true );
95
+			$this->set_object_read(true);
96 96
 		}
97 97
 
98 98
         // Load the datastore.
99
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
99
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
100 100
 
101
-		if ( $this->get_id() > 0 ) {
102
-            $this->post = get_post( $this->get_id() );
101
+		if ($this->get_id() > 0) {
102
+            $this->post = get_post($this->get_id());
103 103
             $this->ID   = $this->get_id();
104
-			$this->data_store->read( $this );
104
+			$this->data_store->read($this);
105 105
         }
106 106
 
107 107
 	}
@@ -128,8 +128,8 @@  discard block
 block discarded – undo
128 128
 	 * @param  string $context View or edit context.
129 129
 	 * @return int
130 130
 	 */
131
-	public function get_parent_id( $context = 'view' ) {
132
-		return (int) $this->get_prop( 'parent_id', $context );
131
+	public function get_parent_id($context = 'view') {
132
+		return (int) $this->get_prop('parent_id', $context);
133 133
     }
134 134
 
135 135
     /**
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
 	 * @param  string $context View or edit context.
140 140
 	 * @return string
141 141
 	 */
142
-	public function get_status( $context = 'view' ) {
143
-		return $this->get_prop( 'status', $context );
142
+	public function get_status($context = 'view') {
143
+		return $this->get_prop('status', $context);
144 144
     }
145 145
 
146 146
     /**
@@ -150,8 +150,8 @@  discard block
 block discarded – undo
150 150
 	 * @param  string $context View or edit context.
151 151
 	 * @return string
152 152
 	 */
153
-	public function get_version( $context = 'view' ) {
154
-		return $this->get_prop( 'version', $context );
153
+	public function get_version($context = 'view') {
154
+		return $this->get_prop('version', $context);
155 155
     }
156 156
 
157 157
     /**
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
 	 * @param  string $context View or edit context.
162 162
 	 * @return string
163 163
 	 */
164
-	public function get_date_created( $context = 'view' ) {
165
-		return $this->get_prop( 'date_created', $context );
164
+	public function get_date_created($context = 'view') {
165
+		return $this->get_prop('date_created', $context);
166 166
     }
167 167
 
168 168
     /**
@@ -172,11 +172,11 @@  discard block
 block discarded – undo
172 172
 	 * @param  string $context View or edit context.
173 173
 	 * @return string
174 174
 	 */
175
-	public function get_date_created_gmt( $context = 'view' ) {
176
-        $date = $this->get_date_created( $context );
175
+	public function get_date_created_gmt($context = 'view') {
176
+        $date = $this->get_date_created($context);
177 177
 
178
-        if ( $date ) {
179
-            $date = get_gmt_from_date( $date );
178
+        if ($date) {
179
+            $date = get_gmt_from_date($date);
180 180
         }
181 181
 		return $date;
182 182
     }
@@ -188,8 +188,8 @@  discard block
 block discarded – undo
188 188
 	 * @param  string $context View or edit context.
189 189
 	 * @return string
190 190
 	 */
191
-	public function get_date_modified( $context = 'view' ) {
192
-		return $this->get_prop( 'date_modified', $context );
191
+	public function get_date_modified($context = 'view') {
192
+		return $this->get_prop('date_modified', $context);
193 193
     }
194 194
 
195 195
     /**
@@ -199,11 +199,11 @@  discard block
 block discarded – undo
199 199
 	 * @param  string $context View or edit context.
200 200
 	 * @return string
201 201
 	 */
202
-	public function get_date_modified_gmt( $context = 'view' ) {
203
-        $date = $this->get_date_modified( $context );
202
+	public function get_date_modified_gmt($context = 'view') {
203
+        $date = $this->get_date_modified($context);
204 204
 
205
-        if ( $date ) {
206
-            $date = get_gmt_from_date( $date );
205
+        if ($date) {
206
+            $date = get_gmt_from_date($date);
207 207
         }
208 208
 		return $date;
209 209
     }
@@ -215,8 +215,8 @@  discard block
 block discarded – undo
215 215
 	 * @param  string $context View or edit context.
216 216
 	 * @return string
217 217
 	 */
218
-	public function get_name( $context = 'view' ) {
219
-		return $this->get_prop( 'name', $context );
218
+	public function get_name($context = 'view') {
219
+		return $this->get_prop('name', $context);
220 220
     }
221 221
 
222 222
     /**
@@ -226,8 +226,8 @@  discard block
 block discarded – undo
226 226
 	 * @param  string $context View or edit context.
227 227
 	 * @return string
228 228
 	 */
229
-	public function get_title( $context = 'view' ) {
230
-		return $this->get_name( $context );
229
+	public function get_title($context = 'view') {
230
+		return $this->get_name($context);
231 231
     }
232 232
 
233 233
     /**
@@ -237,8 +237,8 @@  discard block
 block discarded – undo
237 237
 	 * @param  string $context View or edit context.
238 238
 	 * @return string
239 239
 	 */
240
-	public function get_description( $context = 'view' ) {
241
-		return $this->get_prop( 'description', $context );
240
+	public function get_description($context = 'view') {
241
+		return $this->get_prop('description', $context);
242 242
     }
243 243
 
244 244
     /**
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
 	 * @param  string $context View or edit context.
249 249
 	 * @return string
250 250
 	 */
251
-	public function get_excerpt( $context = 'view' ) {
252
-		return $this->get_description( $context );
251
+	public function get_excerpt($context = 'view') {
252
+		return $this->get_description($context);
253 253
     }
254 254
 
255 255
     /**
@@ -259,8 +259,8 @@  discard block
 block discarded – undo
259 259
 	 * @param  string $context View or edit context.
260 260
 	 * @return string
261 261
 	 */
262
-	public function get_summary( $context = 'view' ) {
263
-		return $this->get_description( $context );
262
+	public function get_summary($context = 'view') {
263
+		return $this->get_description($context);
264 264
     }
265 265
 
266 266
     /**
@@ -270,8 +270,8 @@  discard block
 block discarded – undo
270 270
 	 * @param  string $context View or edit context.
271 271
 	 * @return int
272 272
 	 */
273
-	public function get_author( $context = 'view' ) {
274
-		return (int) $this->get_prop( 'author', $context );
273
+	public function get_author($context = 'view') {
274
+		return (int) $this->get_prop('author', $context);
275 275
 	}
276 276
 	
277 277
 	/**
@@ -281,8 +281,8 @@  discard block
 block discarded – undo
281 281
 	 * @param  string $context View or edit context.
282 282
 	 * @return int
283 283
 	 */
284
-	public function get_owner( $context = 'view' ) {
285
-		return $this->get_author( $context );
284
+	public function get_owner($context = 'view') {
285
+		return $this->get_author($context);
286 286
     }
287 287
 
288 288
     /**
@@ -292,8 +292,8 @@  discard block
 block discarded – undo
292 292
 	 * @param  string $context View or edit context.
293 293
 	 * @return float
294 294
 	 */
295
-	public function get_price( $context = 'view' ) {
296
-        return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
295
+	public function get_price($context = 'view') {
296
+        return wpinv_sanitize_amount($this->get_prop('price', $context));
297 297
 	}
298 298
 	
299 299
 	/**
@@ -303,15 +303,15 @@  discard block
 block discarded – undo
303 303
 	 * @param  string $context View or edit context.
304 304
 	 * @return float
305 305
 	 */
306
-	public function get_initial_price( $context = 'view' ) {
306
+	public function get_initial_price($context = 'view') {
307 307
 
308
-		$price = (float) $this->get_price( $context );
308
+		$price = (float) $this->get_price($context);
309 309
 
310
-		if ( $this->has_free_trial() ) {
310
+		if ($this->has_free_trial()) {
311 311
 			$price = 0;
312 312
 		}
313 313
 
314
-        return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) );
314
+        return wpinv_sanitize_amount(apply_filters('wpinv_get_initial_item_price', $price, $this));
315 315
     }
316 316
 
317 317
     /**
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 	 * @return string
323 323
 	 */
324 324
     public function get_the_price() {
325
-        return wpinv_price( wpinv_format_amount( $this->get_price() ) );
325
+        return wpinv_price(wpinv_format_amount($this->get_price()));
326 326
 	}
327 327
 
328 328
 	/**
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 	 * @return string
334 334
 	 */
335 335
     public function get_the_initial_price() {
336
-        return wpinv_price( wpinv_format_amount( $this->get_initial_price() ) );
336
+        return wpinv_price(wpinv_format_amount($this->get_initial_price()));
337 337
     }
338 338
 
339 339
     /**
@@ -343,8 +343,8 @@  discard block
 block discarded – undo
343 343
 	 * @param  string $context View or edit context.
344 344
 	 * @return string
345 345
 	 */
346
-	public function get_vat_rule( $context = 'view' ) {
347
-        return $this->get_prop( 'vat_rule', $context );
346
+	public function get_vat_rule($context = 'view') {
347
+        return $this->get_prop('vat_rule', $context);
348 348
     }
349 349
 
350 350
     /**
@@ -354,8 +354,8 @@  discard block
 block discarded – undo
354 354
 	 * @param  string $context View or edit context.
355 355
 	 * @return string
356 356
 	 */
357
-	public function get_vat_class( $context = 'view' ) {
358
-        return $this->get_prop( 'vat_class', $context );
357
+	public function get_vat_class($context = 'view') {
358
+        return $this->get_prop('vat_class', $context);
359 359
     }
360 360
 
361 361
     /**
@@ -365,8 +365,8 @@  discard block
 block discarded – undo
365 365
 	 * @param  string $context View or edit context.
366 366
 	 * @return string
367 367
 	 */
368
-	public function get_type( $context = 'view' ) {
369
-        return $this->get_prop( 'type', $context );
368
+	public function get_type($context = 'view') {
369
+        return $this->get_prop('type', $context);
370 370
     }
371 371
 
372 372
     /**
@@ -376,8 +376,8 @@  discard block
 block discarded – undo
376 376
 	 * @param  string $context View or edit context.
377 377
 	 * @return string
378 378
 	 */
379
-	public function get_custom_id( $context = 'view' ) {
380
-        return $this->get_prop( 'custom_id', $context );
379
+	public function get_custom_id($context = 'view') {
380
+        return $this->get_prop('custom_id', $context);
381 381
     }
382 382
 
383 383
     /**
@@ -387,8 +387,8 @@  discard block
 block discarded – undo
387 387
 	 * @param  string $context View or edit context.
388 388
 	 * @return string
389 389
 	 */
390
-	public function get_custom_name( $context = 'view' ) {
391
-        return $this->get_prop( 'custom_name', $context );
390
+	public function get_custom_name($context = 'view') {
391
+        return $this->get_prop('custom_name', $context);
392 392
     }
393 393
 
394 394
     /**
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
 	 * @param  string $context View or edit context.
399 399
 	 * @return string
400 400
 	 */
401
-	public function get_custom_singular_name( $context = 'view' ) {
402
-        return $this->get_prop( 'custom_singular_name', $context );
401
+	public function get_custom_singular_name($context = 'view') {
402
+        return $this->get_prop('custom_singular_name', $context);
403 403
     }
404 404
 
405 405
     /**
@@ -409,8 +409,8 @@  discard block
 block discarded – undo
409 409
 	 * @param  string $context View or edit context.
410 410
 	 * @return int
411 411
 	 */
412
-	public function get_is_editable( $context = 'view' ) {
413
-        return (int) $this->get_prop( 'is_editable', $context );
412
+	public function get_is_editable($context = 'view') {
413
+        return (int) $this->get_prop('is_editable', $context);
414 414
     }
415 415
 
416 416
     /**
@@ -420,8 +420,8 @@  discard block
 block discarded – undo
420 420
 	 * @param  string $context View or edit context.
421 421
 	 * @return int
422 422
 	 */
423
-	public function get_editable( $context = 'view' ) {
424
-		return $this->get_is_editable( $context );
423
+	public function get_editable($context = 'view') {
424
+		return $this->get_is_editable($context);
425 425
     }
426 426
 
427 427
     /**
@@ -431,8 +431,8 @@  discard block
 block discarded – undo
431 431
 	 * @param  string $context View or edit context.
432 432
 	 * @return int
433 433
 	 */
434
-	public function get_is_dynamic_pricing( $context = 'view' ) {
435
-        return (int) $this->get_prop( 'is_dynamic_pricing', $context );
434
+	public function get_is_dynamic_pricing($context = 'view') {
435
+        return (int) $this->get_prop('is_dynamic_pricing', $context);
436 436
     }
437 437
 
438 438
     /**
@@ -442,8 +442,8 @@  discard block
 block discarded – undo
442 442
 	 * @param  string $context View or edit context.
443 443
 	 * @return float
444 444
 	 */
445
-	public function get_minimum_price( $context = 'view' ) {
446
-        return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
445
+	public function get_minimum_price($context = 'view') {
446
+        return wpinv_sanitize_amount($this->get_prop('minimum_price', $context));
447 447
     }
448 448
 
449 449
     /**
@@ -453,8 +453,8 @@  discard block
 block discarded – undo
453 453
 	 * @param  string $context View or edit context.
454 454
 	 * @return int
455 455
 	 */
456
-	public function get_is_recurring( $context = 'view' ) {
457
-        return (int) $this->get_prop( 'is_recurring', $context );
456
+	public function get_is_recurring($context = 'view') {
457
+        return (int) $this->get_prop('is_recurring', $context);
458 458
 	}
459 459
 	
460 460
 	/**
@@ -464,9 +464,9 @@  discard block
 block discarded – undo
464 464
 	 * @param  string $context View or edit context.
465 465
 	 * @return float
466 466
 	 */
467
-	public function get_recurring_price( $context = 'view' ) {
468
-		$price = $this->get_price( $context );
469
-        return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
467
+	public function get_recurring_price($context = 'view') {
468
+		$price = $this->get_price($context);
469
+        return wpinv_sanitize_amount(apply_filters('wpinv_get_recurring_item_price', $price, $this->ID));
470 470
 	}
471 471
 
472 472
 	/**
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 	 * @return string
478 478
 	 */
479 479
     public function get_the_recurring_price() {
480
-        return wpinv_price( wpinv_format_amount( $this->get_recurring_price() ) );
480
+        return wpinv_price(wpinv_format_amount($this->get_recurring_price()));
481 481
 	}
482 482
 
483 483
 	/**
@@ -498,15 +498,15 @@  discard block
 block discarded – undo
498 498
 		$period   = $this->get_recurring_period();
499 499
 		$interval = $this->get_recurring_interval();
500 500
 
501
-		if ( $this->has_free_trial() ) {
501
+		if ($this->has_free_trial()) {
502 502
 			$period   = $this->get_trial_period();
503 503
 			$interval = $this->get_trial_interval();
504 504
 		}
505 505
 
506
-		$period       = $periods[ $period ];
507
-		$interval     = empty( $interval ) ? 1 : $interval;
508
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
509
-        return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
506
+		$period       = $periods[$period];
507
+		$interval     = empty($interval) ? 1 : $interval;
508
+		$next_renewal = strtotime("+$interval $period", current_time('timestamp'));
509
+        return apply_filters('wpinv_get_first_renewal_date', $next_renewal, $this);
510 510
     }
511 511
 
512 512
     /**
@@ -516,14 +516,14 @@  discard block
 block discarded – undo
516 516
 	 * @param  bool $full Return abbreviation or in full.
517 517
 	 * @return string
518 518
 	 */
519
-	public function get_recurring_period( $full = false ) {
520
-        $period = $this->get_prop( 'recurring_period', 'view' );
519
+	public function get_recurring_period($full = false) {
520
+        $period = $this->get_prop('recurring_period', 'view');
521 521
 
522
-        if ( $full && ! is_bool( $full ) ) {
522
+        if ($full && !is_bool($full)) {
523 523
             $full = false;
524 524
         }
525 525
 
526
-        return getpaid_sanitize_recurring_period( $period, $full );
526
+        return getpaid_sanitize_recurring_period($period, $full);
527 527
     }
528 528
 
529 529
     /**
@@ -533,10 +533,10 @@  discard block
 block discarded – undo
533 533
 	 * @param  string $context View or edit context.
534 534
 	 * @return int
535 535
 	 */
536
-	public function get_recurring_interval( $context = 'view' ) {
537
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
536
+	public function get_recurring_interval($context = 'view') {
537
+		$interval = absint($this->get_prop('recurring_interval', $context));
538 538
 
539
-		if ( $interval < 1 ) {
539
+		if ($interval < 1) {
540 540
 			$interval = 1;
541 541
 		}
542 542
 
@@ -550,8 +550,8 @@  discard block
 block discarded – undo
550 550
 	 * @param  string $context View or edit context.
551 551
 	 * @return int
552 552
 	 */
553
-	public function get_recurring_limit( $context = 'view' ) {
554
-        return (int) $this->get_prop( 'recurring_limit', $context );
553
+	public function get_recurring_limit($context = 'view') {
554
+        return (int) $this->get_prop('recurring_limit', $context);
555 555
     }
556 556
 
557 557
     /**
@@ -561,8 +561,8 @@  discard block
 block discarded – undo
561 561
 	 * @param  string $context View or edit context.
562 562
 	 * @return int
563 563
 	 */
564
-	public function get_is_free_trial( $context = 'view' ) {
565
-        return (int) $this->get_prop( 'is_free_trial', $context );
564
+	public function get_is_free_trial($context = 'view') {
565
+        return (int) $this->get_prop('is_free_trial', $context);
566 566
     }
567 567
 
568 568
     /**
@@ -572,8 +572,8 @@  discard block
 block discarded – undo
572 572
 	 * @param  string $context View or edit context.
573 573
 	 * @return int
574 574
 	 */
575
-	public function get_free_trial( $context = 'view' ) {
576
-        return $this->get_is_free_trial( $context );
575
+	public function get_free_trial($context = 'view') {
576
+        return $this->get_is_free_trial($context);
577 577
     }
578 578
 
579 579
     /**
@@ -583,14 +583,14 @@  discard block
 block discarded – undo
583 583
 	 * @param  bool $full Return abbreviation or in full.
584 584
 	 * @return string
585 585
 	 */
586
-	public function get_trial_period( $full = false ) {
587
-        $period = $this->get_prop( 'trial_period', 'view' );
586
+	public function get_trial_period($full = false) {
587
+        $period = $this->get_prop('trial_period', 'view');
588 588
 
589
-        if ( $full && ! is_bool( $full ) ) {
589
+        if ($full && !is_bool($full)) {
590 590
             $full = false;
591 591
         }
592 592
 
593
-        return getpaid_sanitize_recurring_period( $period, $full );
593
+        return getpaid_sanitize_recurring_period($period, $full);
594 594
     }
595 595
 
596 596
     /**
@@ -600,8 +600,8 @@  discard block
 block discarded – undo
600 600
 	 * @param  string $context View or edit context.
601 601
 	 * @return int
602 602
 	 */
603
-	public function get_trial_interval( $context = 'view' ) {
604
-        return (int) $this->get_prop( 'trial_interval', $context );
603
+	public function get_trial_interval($context = 'view') {
604
+        return (int) $this->get_prop('trial_interval', $context);
605 605
 	}
606 606
 	
607 607
 	/**
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
 	 * @return string
612 612
 	 */
613 613
 	public function get_edit_url() {
614
-        return get_edit_post_link( $this->get_id() );
614
+        return get_edit_post_link($this->get_id());
615 615
 	}
616 616
 
617 617
 	/**
@@ -625,35 +625,35 @@  discard block
 block discarded – undo
625 625
 	 * @since 1.0.15
626 626
 	 * @return int
627 627
 	 */
628
-	public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
628
+	public static function get_item_id_by_field($value, $field = 'custom_id', $type = '') {
629 629
 
630 630
 		// Trim the value.
631
-		$value = trim( $value );
631
+		$value = trim($value);
632 632
 
633
-		if ( empty( $value ) ) {
633
+		if (empty($value)) {
634 634
 			return 0;
635 635
 		}
636 636
 
637 637
         // Valid fields.
638
-        $fields = array( 'custom_id', 'name', 'slug' );
638
+        $fields = array('custom_id', 'name', 'slug');
639 639
 
640 640
 		// Ensure a field has been passed.
641
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
641
+		if (empty($field) || !in_array($field, $fields)) {
642 642
 			return 0;
643 643
 		}
644 644
 
645
-		if ( $field == 'name' ) {
645
+		if ($field == 'name') {
646 646
 			$field = 'slug';
647 647
 		} 
648 648
 
649 649
 		// Maybe retrieve from the cache.
650
-		$item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
651
-		if ( ! empty( $item_id ) ) {
650
+		$item_id = wp_cache_get($value, "getpaid_{$type}_item_{$field}s_to_item_ids");
651
+		if (!empty($item_id)) {
652 652
 			return $item_id;
653 653
 		}
654 654
 
655 655
 		// Fetch from the db.
656
-		if ( $field =='slug' ) {
656
+		if ($field == 'slug') {
657 657
 			$items = get_posts(
658 658
 				array(
659 659
 					'post_type'      => 'wpi_item',
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
 			);
665 665
 		}
666 666
 
667
-		if ( $field =='custom_id' ) {
667
+		if ($field == 'custom_id') {
668 668
 			$items = get_posts(
669 669
 				array(
670 670
 					'post_type'      => 'wpi_item',
@@ -684,12 +684,12 @@  discard block
 block discarded – undo
684 684
 			);
685 685
 		}
686 686
 
687
-		if ( empty( $items ) ) {
687
+		if (empty($items)) {
688 688
 			return 0;
689 689
 		}
690 690
 
691 691
 		// Update the cache with our data
692
-		wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
692
+		wp_cache_set($value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids");
693 693
 
694 694
 		return $items[0]->ID;
695 695
     }
@@ -697,19 +697,19 @@  discard block
 block discarded – undo
697 697
     /**
698 698
      * Margic method for retrieving a property.
699 699
      */
700
-    public function __get( $key ) {
700
+    public function __get($key) {
701 701
 
702 702
         // Check if we have a helper method for that.
703
-        if ( method_exists( $this, 'get_' . $key ) ) {
704
-            return call_user_func( array( $this, 'get_' . $key ) );
703
+        if (method_exists($this, 'get_' . $key)) {
704
+            return call_user_func(array($this, 'get_' . $key));
705 705
         }
706 706
 
707 707
         // Check if the key is in the associated $post object.
708
-        if ( ! empty( $this->post ) && isset( $this->post->$key ) ) {
708
+        if (!empty($this->post) && isset($this->post->$key)) {
709 709
             return $this->post->$key;
710 710
         }
711 711
 
712
-        return $this->get_prop( $key );
712
+        return $this->get_prop($key);
713 713
 
714 714
     }
715 715
 
@@ -728,11 +728,11 @@  discard block
 block discarded – undo
728 728
 	 *
729 729
 	 * @since 1.0.19
730 730
 	 */
731
-	public function set_parent_id( $value ) {
732
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
731
+	public function set_parent_id($value) {
732
+		if ($value && ($value === $this->get_id() || !get_post($value))) {
733 733
 			return;
734 734
 		}
735
-		$this->set_prop( 'parent_id', absint( $value ) );
735
+		$this->set_prop('parent_id', absint($value));
736 736
 	}
737 737
 
738 738
     /**
@@ -742,10 +742,10 @@  discard block
 block discarded – undo
742 742
 	 * @param  string $status New status.
743 743
 	 * @return array details of change.
744 744
 	 */
745
-	public function set_status( $status ) {
745
+	public function set_status($status) {
746 746
         $old_status = $this->get_status();
747 747
 
748
-        $this->set_prop( 'status', $status );
748
+        $this->set_prop('status', $status);
749 749
 
750 750
 		return array(
751 751
 			'from' => $old_status,
@@ -758,8 +758,8 @@  discard block
 block discarded – undo
758 758
 	 *
759 759
 	 * @since 1.0.19
760 760
 	 */
761
-	public function set_version( $value ) {
762
-		$this->set_prop( 'version', $value );
761
+	public function set_version($value) {
762
+		$this->set_prop('version', $value);
763 763
     }
764 764
 
765 765
     /**
@@ -769,11 +769,11 @@  discard block
 block discarded – undo
769 769
 	 * @param string $value Value to set.
770 770
      * @return bool Whether or not the date was set.
771 771
 	 */
772
-	public function set_date_created( $value ) {
773
-        $date = strtotime( $value );
772
+	public function set_date_created($value) {
773
+        $date = strtotime($value);
774 774
 
775
-        if ( $date ) {
776
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
775
+        if ($date) {
776
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
777 777
             return true;
778 778
         }
779 779
 
@@ -788,11 +788,11 @@  discard block
 block discarded – undo
788 788
 	 * @param string $value Value to set.
789 789
      * @return bool Whether or not the date was set.
790 790
 	 */
791
-	public function set_date_modified( $value ) {
792
-        $date = strtotime( $value );
791
+	public function set_date_modified($value) {
792
+        $date = strtotime($value);
793 793
 
794
-        if ( $date ) {
795
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
794
+        if ($date) {
795
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
796 796
             return true;
797 797
         }
798 798
 
@@ -806,9 +806,9 @@  discard block
 block discarded – undo
806 806
 	 * @since 1.0.19
807 807
 	 * @param  string $value New name.
808 808
 	 */
809
-	public function set_name( $value ) {
810
-        $name = sanitize_text_field( $value );
811
-		$this->set_prop( 'name', $name );
809
+	public function set_name($value) {
810
+        $name = sanitize_text_field($value);
811
+		$this->set_prop('name', $name);
812 812
     }
813 813
 
814 814
     /**
@@ -817,8 +817,8 @@  discard block
 block discarded – undo
817 817
 	 * @since 1.0.19
818 818
 	 * @param  string $value New name.
819 819
 	 */
820
-	public function set_title( $value ) {
821
-		$this->set_name( $value );
820
+	public function set_title($value) {
821
+		$this->set_name($value);
822 822
     }
823 823
 
824 824
     /**
@@ -827,9 +827,9 @@  discard block
 block discarded – undo
827 827
 	 * @since 1.0.19
828 828
 	 * @param  string $value New description.
829 829
 	 */
830
-	public function set_description( $value ) {
831
-        $description = wp_kses_post( $value );
832
-		return $this->set_prop( 'description', $description );
830
+	public function set_description($value) {
831
+        $description = wp_kses_post($value);
832
+		return $this->set_prop('description', $description);
833 833
     }
834 834
 
835 835
     /**
@@ -838,8 +838,8 @@  discard block
 block discarded – undo
838 838
 	 * @since 1.0.19
839 839
 	 * @param  string $value New description.
840 840
 	 */
841
-	public function set_excerpt( $value ) {
842
-		$this->set_description( $value );
841
+	public function set_excerpt($value) {
842
+		$this->set_description($value);
843 843
     }
844 844
 
845 845
     /**
@@ -848,8 +848,8 @@  discard block
 block discarded – undo
848 848
 	 * @since 1.0.19
849 849
 	 * @param  string $value New description.
850 850
 	 */
851
-	public function set_summary( $value ) {
852
-		$this->set_description( $value );
851
+	public function set_summary($value) {
852
+		$this->set_description($value);
853 853
     }
854 854
 
855 855
     /**
@@ -858,8 +858,8 @@  discard block
 block discarded – undo
858 858
 	 * @since 1.0.19
859 859
 	 * @param  int $value New author.
860 860
 	 */
861
-	public function set_author( $value ) {
862
-		$this->set_prop( 'author', (int) $value );
861
+	public function set_author($value) {
862
+		$this->set_prop('author', (int) $value);
863 863
 	}
864 864
 	
865 865
 	/**
@@ -868,8 +868,8 @@  discard block
 block discarded – undo
868 868
 	 * @since 1.0.19
869 869
 	 * @param  int $value New author.
870 870
 	 */
871
-	public function set_owner( $value ) {
872
-		$this->set_author( $value );
871
+	public function set_owner($value) {
872
+		$this->set_author($value);
873 873
     }
874 874
 
875 875
     /**
@@ -878,8 +878,8 @@  discard block
 block discarded – undo
878 878
 	 * @since 1.0.19
879 879
 	 * @param  float $value New price.
880 880
 	 */
881
-	public function set_price( $value ) {
882
-        $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
881
+	public function set_price($value) {
882
+        $this->set_prop('price', (float) wpinv_sanitize_amount($value));
883 883
     }
884 884
 
885 885
     /**
@@ -888,8 +888,8 @@  discard block
 block discarded – undo
888 888
 	 * @since 1.0.19
889 889
 	 * @param  string $value new rule.
890 890
 	 */
891
-	public function set_vat_rule( $value ) {
892
-        $this->set_prop( 'vat_rule', $value );
891
+	public function set_vat_rule($value) {
892
+        $this->set_prop('vat_rule', $value);
893 893
     }
894 894
 
895 895
     /**
@@ -898,8 +898,8 @@  discard block
 block discarded – undo
898 898
 	 * @since 1.0.19
899 899
 	 * @param  string $value new class.
900 900
 	 */
901
-	public function set_vat_class( $value ) {
902
-        $this->set_prop( 'vat_class', $value );
901
+	public function set_vat_class($value) {
902
+        $this->set_prop('vat_class', $value);
903 903
     }
904 904
 
905 905
     /**
@@ -909,13 +909,13 @@  discard block
 block discarded – undo
909 909
 	 * @param  string $value new item type.
910 910
 	 * @return string
911 911
 	 */
912
-	public function set_type( $value ) {
912
+	public function set_type($value) {
913 913
 
914
-        if ( empty( $value ) ) {
914
+        if (empty($value)) {
915 915
             $value = 'custom';
916 916
         }
917 917
 
918
-        $this->set_prop( 'type', $value );
918
+        $this->set_prop('type', $value);
919 919
     }
920 920
 
921 921
     /**
@@ -924,8 +924,8 @@  discard block
 block discarded – undo
924 924
 	 * @since 1.0.19
925 925
 	 * @param  string $value new custom id.
926 926
 	 */
927
-	public function set_custom_id( $value ) {
928
-        $this->set_prop( 'custom_id', $value );
927
+	public function set_custom_id($value) {
928
+        $this->set_prop('custom_id', $value);
929 929
     }
930 930
 
931 931
     /**
@@ -934,8 +934,8 @@  discard block
 block discarded – undo
934 934
 	 * @since 1.0.19
935 935
 	 * @param  string $value new custom name.
936 936
 	 */
937
-	public function set_custom_name( $value ) {
938
-        $this->set_prop( 'custom_name', $value );
937
+	public function set_custom_name($value) {
938
+        $this->set_prop('custom_name', $value);
939 939
     }
940 940
 
941 941
     /**
@@ -944,8 +944,8 @@  discard block
 block discarded – undo
944 944
 	 * @since 1.0.19
945 945
 	 * @param  string $value new custom singular name.
946 946
 	 */
947
-	public function set_custom_singular_name( $value ) {
948
-        $this->set_prop( 'custom_singular_name', $value );
947
+	public function set_custom_singular_name($value) {
948
+        $this->set_prop('custom_singular_name', $value);
949 949
     }
950 950
 
951 951
     /**
@@ -954,9 +954,9 @@  discard block
 block discarded – undo
954 954
 	 * @since 1.0.19
955 955
 	 * @param  int|bool $value whether or not the item is editable.
956 956
 	 */
957
-	public function set_is_editable( $value ) {
958
-		if ( is_numeric( $value ) ) {
959
-			$this->set_prop( 'is_editable', (int) $value );
957
+	public function set_is_editable($value) {
958
+		if (is_numeric($value)) {
959
+			$this->set_prop('is_editable', (int) $value);
960 960
 		}
961 961
     }
962 962
 
@@ -966,8 +966,8 @@  discard block
 block discarded – undo
966 966
 	 * @since 1.0.19
967 967
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
968 968
 	 */
969
-	public function set_is_dynamic_pricing( $value ) {
970
-        $this->set_prop( 'is_dynamic_pricing', (int) $value );
969
+	public function set_is_dynamic_pricing($value) {
970
+        $this->set_prop('is_dynamic_pricing', (int) $value);
971 971
     }
972 972
 
973 973
     /**
@@ -976,8 +976,8 @@  discard block
 block discarded – undo
976 976
 	 * @since 1.0.19
977 977
 	 * @param  float $value minimum price.
978 978
 	 */
979
-	public function set_minimum_price( $value ) {
980
-        $this->set_prop( 'minimum_price',  (float) wpinv_sanitize_amount( $value ) );
979
+	public function set_minimum_price($value) {
980
+        $this->set_prop('minimum_price', (float) wpinv_sanitize_amount($value));
981 981
     }
982 982
 
983 983
     /**
@@ -986,8 +986,8 @@  discard block
 block discarded – undo
986 986
 	 * @since 1.0.19
987 987
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
988 988
 	 */
989
-	public function set_is_recurring( $value ) {
990
-        $this->set_prop( 'is_recurring', (int) $value );
989
+	public function set_is_recurring($value) {
990
+        $this->set_prop('is_recurring', (int) $value);
991 991
     }
992 992
 
993 993
     /**
@@ -996,8 +996,8 @@  discard block
 block discarded – undo
996 996
 	 * @since 1.0.19
997 997
 	 * @param  string $value new period.
998 998
 	 */
999
-	public function set_recurring_period( $value ) {
1000
-        $this->set_prop( 'recurring_period', $value );
999
+	public function set_recurring_period($value) {
1000
+        $this->set_prop('recurring_period', $value);
1001 1001
     }
1002 1002
 
1003 1003
     /**
@@ -1006,8 +1006,8 @@  discard block
 block discarded – undo
1006 1006
 	 * @since 1.0.19
1007 1007
 	 * @param  int $value recurring interval.
1008 1008
 	 */
1009
-	public function set_recurring_interval( $value ) {
1010
-        return $this->set_prop( 'recurring_interval', (int) $value );
1009
+	public function set_recurring_interval($value) {
1010
+        return $this->set_prop('recurring_interval', (int) $value);
1011 1011
     }
1012 1012
 
1013 1013
     /**
@@ -1016,8 +1016,8 @@  discard block
 block discarded – undo
1016 1016
 	 * @param  int $value The recurring limit.
1017 1017
 	 * @return int
1018 1018
 	 */
1019
-	public function set_recurring_limit( $value ) {
1020
-        $this->set_prop( 'recurring_limit', (int) $value );
1019
+	public function set_recurring_limit($value) {
1020
+        $this->set_prop('recurring_limit', (int) $value);
1021 1021
     }
1022 1022
 
1023 1023
     /**
@@ -1026,8 +1026,8 @@  discard block
 block discarded – undo
1026 1026
 	 * @since 1.0.19
1027 1027
 	 * @param  int|bool $value whether or not it has a free trial.
1028 1028
 	 */
1029
-	public function set_is_free_trial( $value ) {
1030
-        $this->set_prop( 'is_free_trial', (int) $value );
1029
+	public function set_is_free_trial($value) {
1030
+        $this->set_prop('is_free_trial', (int) $value);
1031 1031
     }
1032 1032
 
1033 1033
     /**
@@ -1036,8 +1036,8 @@  discard block
 block discarded – undo
1036 1036
 	 * @since 1.0.19
1037 1037
 	 * @param  string $value trial period.
1038 1038
 	 */
1039
-	public function set_trial_period( $value ) {
1040
-        $this->set_prop( 'trial_period', $value );
1039
+	public function set_trial_period($value) {
1040
+        $this->set_prop('trial_period', $value);
1041 1041
     }
1042 1042
 
1043 1043
     /**
@@ -1046,8 +1046,8 @@  discard block
 block discarded – undo
1046 1046
 	 * @since 1.0.19
1047 1047
 	 * @param  int $value trial interval.
1048 1048
 	 */
1049
-	public function set_trial_interval( $value ) {
1050
-        $this->set_prop( 'trial_interval', $value );
1049
+	public function set_trial_interval($value) {
1050
+        $this->set_prop('trial_interval', $value);
1051 1051
     }
1052 1052
 
1053 1053
     /**
@@ -1056,11 +1056,11 @@  discard block
 block discarded – undo
1056 1056
      * @deprecated
1057 1057
 	 * @return int item id
1058 1058
      */
1059
-    public function create( $data = array() ) {
1059
+    public function create($data = array()) {
1060 1060
 
1061 1061
 		// Set the properties.
1062
-		if ( is_array( $data ) ) {
1063
-			$this->set_props( $data );
1062
+		if (is_array($data)) {
1063
+			$this->set_props($data);
1064 1064
 		}
1065 1065
 
1066 1066
 		// Save the item.
@@ -1074,8 +1074,8 @@  discard block
 block discarded – undo
1074 1074
      * @deprecated
1075 1075
 	 * @return int item id
1076 1076
      */
1077
-    public function update( $data = array() ) {
1078
-        return $this->create( $data );
1077
+    public function update($data = array()) {
1078
+        return $this->create($data);
1079 1079
     }
1080 1080
 
1081 1081
     /*
@@ -1115,7 +1115,7 @@  discard block
 block discarded – undo
1115 1115
 	 */
1116 1116
     public function has_free_trial() {
1117 1117
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
1118
-        return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
1118
+        return (bool) apply_filters('wpinv_item_has_free_trial', $has_trial, $this->ID, $this);
1119 1119
     }
1120 1120
 
1121 1121
     /**
@@ -1125,8 +1125,8 @@  discard block
 block discarded – undo
1125 1125
 	 * @return bool
1126 1126
 	 */
1127 1127
     public function is_free() {
1128
-        $is_free   = $this->get_price() == 0;
1129
-        return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
1128
+        $is_free = $this->get_price() == 0;
1129
+        return (bool) apply_filters('wpinv_is_free_item', $is_free, $this->ID, $this);
1130 1130
     }
1131 1131
 
1132 1132
     /**
@@ -1135,9 +1135,9 @@  discard block
 block discarded – undo
1135 1135
 	 * @param array|string $status Status to check.
1136 1136
 	 * @return bool
1137 1137
 	 */
1138
-	public function has_status( $status ) {
1139
-		$has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1140
-		return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1138
+	public function has_status($status) {
1139
+		$has_status = (is_array($status) && in_array($this->get_status(), $status, true)) || $this->get_status() === $status;
1140
+		return (bool) apply_filters('getpaid_item_has_status', $has_status, $this, $status);
1141 1141
     }
1142 1142
 
1143 1143
     /**
@@ -1146,9 +1146,9 @@  discard block
 block discarded – undo
1146 1146
 	 * @param array|string $type Type to check.
1147 1147
 	 * @return bool
1148 1148
 	 */
1149
-	public function is_type( $type ) {
1150
-		$is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1151
-		return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1149
+	public function is_type($type) {
1150
+		$is_type = (is_array($type) && in_array($this->get_type(), $type, true)) || $this->get_type() === $type;
1151
+		return (bool) apply_filters('getpaid_item_is_type', $is_type, $this, $type);
1152 1152
 	}
1153 1153
 
1154 1154
     /**
@@ -1159,52 +1159,52 @@  discard block
 block discarded – undo
1159 1159
 	 */
1160 1160
     public function is_editable() {
1161 1161
         $is_editable = $this->get_is_editable();
1162
-        return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1162
+        return (bool) apply_filters('wpinv_item_is_editable', $is_editable, $this->ID, $this);
1163 1163
 	}
1164 1164
 
1165 1165
 	/**
1166 1166
 	 * Returns an array of cart fees.
1167 1167
 	 */
1168
-	public function get_fees( $type = 'fee', $item_id = 0 ) {
1168
+	public function get_fees($type = 'fee', $item_id = 0) {
1169 1169
         
1170
-        $fees = getpaid_session()->get( 'wpi_cart_fees' );
1170
+        $fees = getpaid_session()->get('wpi_cart_fees');
1171 1171
 
1172
-        if ( ! wpinv_get_cart_contents() ) {
1172
+        if (!wpinv_get_cart_contents()) {
1173 1173
             // We can only get item type fees when the cart is empty
1174 1174
             $type = 'custom';
1175 1175
         }
1176 1176
 
1177
-        if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) {
1178
-            foreach( $fees as $key => $fee ) {
1179
-                if( ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1180
-                    unset( $fees[ $key ] );
1177
+        if (!empty($fees) && !empty($type) && 'all' !== $type) {
1178
+            foreach ($fees as $key => $fee) {
1179
+                if (!empty($fee['type']) && $type != $fee['type']) {
1180
+                    unset($fees[$key]);
1181 1181
                 }
1182 1182
             }
1183 1183
         }
1184 1184
 
1185
-        if ( ! empty( $fees ) && ! empty( $item_id ) ) {
1185
+        if (!empty($fees) && !empty($item_id)) {
1186 1186
             // Remove fees that don't belong to the specified Item
1187
-            foreach ( $fees as $key => $fee ) {
1188
-                if ( (int) $item_id !== (int)$fee['custom_id'] ) {
1189
-                    unset( $fees[ $key ] );
1187
+            foreach ($fees as $key => $fee) {
1188
+                if ((int) $item_id !== (int) $fee['custom_id']) {
1189
+                    unset($fees[$key]);
1190 1190
                 }
1191 1191
             }
1192 1192
         }
1193 1193
 
1194
-        if ( ! empty( $fees ) ) {
1194
+        if (!empty($fees)) {
1195 1195
             // Remove fees that belong to a specific item but are not in the cart
1196
-            foreach( $fees as $key => $fee ) {
1197
-                if( empty( $fee['custom_id'] ) ) {
1196
+            foreach ($fees as $key => $fee) {
1197
+                if (empty($fee['custom_id'])) {
1198 1198
                     continue;
1199 1199
                 }
1200 1200
 
1201
-                if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) {
1202
-                    unset( $fees[ $key ] );
1201
+                if (!wpinv_item_in_cart($fee['custom_id'])) {
1202
+                    unset($fees[$key]);
1203 1203
                 }
1204 1204
             }
1205 1205
         }
1206 1206
 
1207
-        return ! empty( $fees ) ? $fees : array();
1207
+        return !empty($fees) ? $fees : array();
1208 1208
     }
1209 1209
 
1210 1210
     /**
@@ -1216,11 +1216,11 @@  discard block
 block discarded – undo
1216 1216
     public function can_purchase() {
1217 1217
         $can_purchase = null !== $this->get_id();
1218 1218
 
1219
-        if ( ! current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) {
1219
+        if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') {
1220 1220
             $can_purchase = false;
1221 1221
         }
1222 1222
 
1223
-        return (bool) apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );
1223
+        return (bool) apply_filters('wpinv_can_purchase_item', $can_purchase, $this);
1224 1224
     }
1225 1225
 
1226 1226
     /**
@@ -1230,6 +1230,6 @@  discard block
 block discarded – undo
1230 1230
 	 * @return bool
1231 1231
 	 */
1232 1232
     public function supports_dynamic_pricing() {
1233
-        return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1233
+        return (bool) apply_filters('wpinv_item_supports_dynamic_pricing', true, $this);
1234 1234
     }
1235 1235
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-data.php 2 patches
Indentation   +857 added lines, -857 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  */
10 10
 
11 11
 if ( ! defined( 'ABSPATH' ) ) {
12
-	exit;
12
+    exit;
13 13
 }
14 14
 
15 15
 /**
@@ -21,356 +21,356 @@  discard block
 block discarded – undo
21 21
  */
22 22
 abstract class GetPaid_Data {
23 23
 
24
-	/**
25
-	 * ID for this object.
26
-	 *
27
-	 * @since 1.0.19
28
-	 * @var int
29
-	 */
30
-	protected $id = 0;
31
-
32
-	/**
33
-	 * Core data for this object. Name value pairs (name + default value).
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array();
39
-
40
-	/**
41
-	 * Core data changes for this object.
42
-	 *
43
-	 * @since 1.0.19
44
-	 * @var array
45
-	 */
46
-	protected $changes = array();
47
-
48
-	/**
49
-	 * This is false until the object is read from the DB.
50
-	 *
51
-	 * @since 1.0.19
52
-	 * @var bool
53
-	 */
54
-	protected $object_read = false;
55
-
56
-	/**
57
-	 * This is the name of this object type.
58
-	 *
59
-	 * @since 1.0.19
60
-	 * @var string
61
-	 */
62
-	protected $object_type = 'data';
63
-
64
-	/**
65
-	 * Extra data for this object. Name value pairs (name + default value).
66
-	 * Used as a standard way for sub classes (like item types) to add
67
-	 * additional information to an inherited class.
68
-	 *
69
-	 * @since 1.0.19
70
-	 * @var array
71
-	 */
72
-	protected $extra_data = array();
73
-
74
-	/**
75
-	 * Set to _data on construct so we can track and reset data if needed.
76
-	 *
77
-	 * @since 1.0.19
78
-	 * @var array
79
-	 */
80
-	protected $default_data = array();
81
-
82
-	/**
83
-	 * Contains a reference to the data store for this class.
84
-	 *
85
-	 * @since 1.0.19
86
-	 * @var GetPaid_Data_Store
87
-	 */
88
-	protected $data_store;
89
-
90
-	/**
91
-	 * Stores meta in cache for future reads.
92
-	 * A group must be set to to enable caching.
93
-	 *
94
-	 * @since 1.0.19
95
-	 * @var string
96
-	 */
97
-	protected $cache_group = '';
98
-
99
-	/**
100
-	 * Stores the last error.
101
-	 *
102
-	 * @since 1.0.19
103
-	 * @var string
104
-	 */
105
-	public $last_error = '';
106
-
107
-	/**
108
-	 * Stores additional meta data.
109
-	 *
110
-	 * @since 1.0.19
111
-	 * @var array
112
-	 */
113
-	protected $meta_data = null;
114
-
115
-	/**
116
-	 * Default constructor.
117
-	 *
118
-	 * @param int|object|array $read ID to load from the DB (optional) or already queried data.
119
-	 */
120
-	public function __construct( $read = 0 ) {
121
-		$this->data         = array_merge( $this->data, $this->extra_data );
122
-		$this->default_data = $this->data;
123
-	}
124
-
125
-	/**
126
-	 * Only store the object ID to avoid serializing the data object instance.
127
-	 *
128
-	 * @return array
129
-	 */
130
-	public function __sleep() {
131
-		return array( 'id' );
132
-	}
133
-
134
-	/**
135
-	 * Re-run the constructor with the object ID.
136
-	 *
137
-	 * If the object no longer exists, remove the ID.
138
-	 */
139
-	public function __wakeup() {
140
-		$this->__construct( absint( $this->id ) );
141
-
142
-		if ( ! empty( $this->last_error ) ) {
143
-			$this->set_id( 0 );
144
-		}
145
-
146
-	}
147
-
148
-	/**
149
-	 * When the object is cloned, make sure meta is duplicated correctly.
150
-	 *
151
-	 * @since 1.0.19
152
-	 */
153
-	public function __clone() {
154
-		$this->maybe_read_meta_data();
155
-		if ( ! empty( $this->meta_data ) ) {
156
-			foreach ( $this->meta_data as $array_key => $meta ) {
157
-				$this->meta_data[ $array_key ] = clone $meta;
158
-				if ( ! empty( $meta->id ) ) {
159
-					$this->meta_data[ $array_key ]->id = null;
160
-				}
161
-			}
162
-		}
163
-	}
164
-
165
-	/**
166
-	 * Get the data store.
167
-	 *
168
-	 * @since  1.0.19
169
-	 * @return object
170
-	 */
171
-	public function get_data_store() {
172
-		return $this->data_store;
173
-	}
174
-
175
-	/**
176
-	 * Get the object type.
177
-	 *
178
-	 * @since  1.0.19
179
-	 * @return string
180
-	 */
181
-	public function get_object_type() {
182
-		return $this->object_type;
183
-	}
184
-
185
-	/**
186
-	 * Returns the unique ID for this object.
187
-	 *
188
-	 * @since  1.0.19
189
-	 * @return int
190
-	 */
191
-	public function get_id() {
192
-		return $this->id;
193
-	}
194
-
195
-	/**
196
-	 * Get form status.
197
-	 *
198
-	 * @since 1.0.19
199
-	 * @param  string $context View or edit context.
200
-	 * @return string
201
-	 */
202
-	public function get_status( $context = 'view' ) {
203
-		return $this->get_prop( 'status', $context );
204
-    }
205
-
206
-	/**
207
-	 * Delete an object, set the ID to 0, and return result.
208
-	 *
209
-	 * @since  1.0.19
210
-	 * @param  bool $force_delete Should the data be deleted permanently.
211
-	 * @return bool result
212
-	 */
213
-	public function delete( $force_delete = false ) {
214
-		if ( $this->data_store ) {
215
-			$this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
-			$this->set_id( 0 );
217
-			return true;
218
-		}
219
-		return false;
220
-	}
221
-
222
-	/**
223
-	 * Save should create or update based on object existence.
224
-	 *
225
-	 * @since  1.0.19
226
-	 * @return int
227
-	 */
228
-	public function save() {
229
-		if ( ! $this->data_store ) {
230
-			return $this->get_id();
231
-		}
232
-
233
-		/**
234
-		 * Trigger action before saving to the DB. Allows you to adjust object props before save.
235
-		 *
236
-		 * @param GetPaid_Data          $this The object being saved.
237
-		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238
-		 */
239
-		do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
240
-
241
-		if ( $this->get_id() ) {
242
-			$this->data_store->update( $this );
243
-		} else {
244
-			$this->data_store->create( $this );
245
-		}
246
-
247
-		/**
248
-		 * Trigger action after saving to the DB.
249
-		 *
250
-		 * @param GetPaid_Data          $this The object being saved.
251
-		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252
-		 */
253
-		do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
254
-
255
-		return $this->get_id();
256
-	}
257
-
258
-	/**
259
-	 * Change data to JSON format.
260
-	 *
261
-	 * @since  1.0.19
262
-	 * @return string Data in JSON format.
263
-	 */
264
-	public function __toString() {
265
-		return wp_json_encode( $this->get_data() );
266
-	}
267
-
268
-	/**
269
-	 * Returns all data for this object.
270
-	 *
271
-	 * @since  1.0.19
272
-	 * @return array
273
-	 */
274
-	public function get_data() {
275
-		return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
276
-	}
277
-
278
-	/**
279
-	 * Returns array of expected data keys for this object.
280
-	 *
281
-	 * @since   1.0.19
282
-	 * @return array
283
-	 */
284
-	public function get_data_keys() {
285
-		return array_keys( $this->data );
286
-	}
287
-
288
-	/**
289
-	 * Returns all "extra" data keys for an object (for sub objects like item types).
290
-	 *
291
-	 * @since  1.0.19
292
-	 * @return array
293
-	 */
294
-	public function get_extra_data_keys() {
295
-		return array_keys( $this->extra_data );
296
-	}
297
-
298
-	/**
299
-	 * Filter null meta values from array.
300
-	 *
301
-	 * @since  1.0.19
302
-	 * @param mixed $meta Meta value to check.
303
-	 * @return bool
304
-	 */
305
-	protected function filter_null_meta( $meta ) {
306
-		return ! is_null( $meta->value );
307
-	}
308
-
309
-	/**
310
-	 * Get All Meta Data.
311
-	 *
312
-	 * @since 1.0.19
313
-	 * @return array of objects.
314
-	 */
315
-	public function get_meta_data() {
316
-		$this->maybe_read_meta_data();
317
-		return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
318
-	}
319
-
320
-	/**
321
-	 * Check if the key is an internal one.
322
-	 *
323
-	 * @since  1.0.19
324
-	 * @param  string $key Key to check.
325
-	 * @return bool   true if it's an internal key, false otherwise
326
-	 */
327
-	protected function is_internal_meta_key( $key ) {
328
-		$internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
329
-
330
-		if ( ! $internal_meta_key ) {
331
-			return false;
332
-		}
333
-
334
-		$has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
335
-
336
-		if ( ! $has_setter_or_getter ) {
337
-			return false;
338
-		}
339
-
340
-		/* translators: %s: $key Key to check */
341
-		getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
342
-
343
-		return true;
344
-	}
345
-
346
-	/**
347
-	 * Magic method for setting data fields.
348
-	 *
349
-	 * This method does not update custom fields in the database.
350
-	 *
351
-	 * @since 1.0.19
352
-	 * @access public
353
-	 *
354
-	 */
355
-	public function __set( $key, $value ) {
356
-
357
-		if ( 'id' == strtolower( $key ) ) {
358
-			return $this->set_id( $value );
359
-		}
360
-
361
-		if ( method_exists( $this, "set_$key") ) {
362
-
363
-			/* translators: %s: $key Key to set */
364
-			getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
365
-
366
-			call_user_func( array( $this, "set_$key" ), $value );
367
-		} else {
368
-			$this->set_prop( $key, $value );
369
-		}
370
-
371
-	}
372
-
373
-	/**
24
+    /**
25
+     * ID for this object.
26
+     *
27
+     * @since 1.0.19
28
+     * @var int
29
+     */
30
+    protected $id = 0;
31
+
32
+    /**
33
+     * Core data for this object. Name value pairs (name + default value).
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array();
39
+
40
+    /**
41
+     * Core data changes for this object.
42
+     *
43
+     * @since 1.0.19
44
+     * @var array
45
+     */
46
+    protected $changes = array();
47
+
48
+    /**
49
+     * This is false until the object is read from the DB.
50
+     *
51
+     * @since 1.0.19
52
+     * @var bool
53
+     */
54
+    protected $object_read = false;
55
+
56
+    /**
57
+     * This is the name of this object type.
58
+     *
59
+     * @since 1.0.19
60
+     * @var string
61
+     */
62
+    protected $object_type = 'data';
63
+
64
+    /**
65
+     * Extra data for this object. Name value pairs (name + default value).
66
+     * Used as a standard way for sub classes (like item types) to add
67
+     * additional information to an inherited class.
68
+     *
69
+     * @since 1.0.19
70
+     * @var array
71
+     */
72
+    protected $extra_data = array();
73
+
74
+    /**
75
+     * Set to _data on construct so we can track and reset data if needed.
76
+     *
77
+     * @since 1.0.19
78
+     * @var array
79
+     */
80
+    protected $default_data = array();
81
+
82
+    /**
83
+     * Contains a reference to the data store for this class.
84
+     *
85
+     * @since 1.0.19
86
+     * @var GetPaid_Data_Store
87
+     */
88
+    protected $data_store;
89
+
90
+    /**
91
+     * Stores meta in cache for future reads.
92
+     * A group must be set to to enable caching.
93
+     *
94
+     * @since 1.0.19
95
+     * @var string
96
+     */
97
+    protected $cache_group = '';
98
+
99
+    /**
100
+     * Stores the last error.
101
+     *
102
+     * @since 1.0.19
103
+     * @var string
104
+     */
105
+    public $last_error = '';
106
+
107
+    /**
108
+     * Stores additional meta data.
109
+     *
110
+     * @since 1.0.19
111
+     * @var array
112
+     */
113
+    protected $meta_data = null;
114
+
115
+    /**
116
+     * Default constructor.
117
+     *
118
+     * @param int|object|array $read ID to load from the DB (optional) or already queried data.
119
+     */
120
+    public function __construct( $read = 0 ) {
121
+        $this->data         = array_merge( $this->data, $this->extra_data );
122
+        $this->default_data = $this->data;
123
+    }
124
+
125
+    /**
126
+     * Only store the object ID to avoid serializing the data object instance.
127
+     *
128
+     * @return array
129
+     */
130
+    public function __sleep() {
131
+        return array( 'id' );
132
+    }
133
+
134
+    /**
135
+     * Re-run the constructor with the object ID.
136
+     *
137
+     * If the object no longer exists, remove the ID.
138
+     */
139
+    public function __wakeup() {
140
+        $this->__construct( absint( $this->id ) );
141
+
142
+        if ( ! empty( $this->last_error ) ) {
143
+            $this->set_id( 0 );
144
+        }
145
+
146
+    }
147
+
148
+    /**
149
+     * When the object is cloned, make sure meta is duplicated correctly.
150
+     *
151
+     * @since 1.0.19
152
+     */
153
+    public function __clone() {
154
+        $this->maybe_read_meta_data();
155
+        if ( ! empty( $this->meta_data ) ) {
156
+            foreach ( $this->meta_data as $array_key => $meta ) {
157
+                $this->meta_data[ $array_key ] = clone $meta;
158
+                if ( ! empty( $meta->id ) ) {
159
+                    $this->meta_data[ $array_key ]->id = null;
160
+                }
161
+            }
162
+        }
163
+    }
164
+
165
+    /**
166
+     * Get the data store.
167
+     *
168
+     * @since  1.0.19
169
+     * @return object
170
+     */
171
+    public function get_data_store() {
172
+        return $this->data_store;
173
+    }
174
+
175
+    /**
176
+     * Get the object type.
177
+     *
178
+     * @since  1.0.19
179
+     * @return string
180
+     */
181
+    public function get_object_type() {
182
+        return $this->object_type;
183
+    }
184
+
185
+    /**
186
+     * Returns the unique ID for this object.
187
+     *
188
+     * @since  1.0.19
189
+     * @return int
190
+     */
191
+    public function get_id() {
192
+        return $this->id;
193
+    }
194
+
195
+    /**
196
+     * Get form status.
197
+     *
198
+     * @since 1.0.19
199
+     * @param  string $context View or edit context.
200
+     * @return string
201
+     */
202
+    public function get_status( $context = 'view' ) {
203
+        return $this->get_prop( 'status', $context );
204
+    }
205
+
206
+    /**
207
+     * Delete an object, set the ID to 0, and return result.
208
+     *
209
+     * @since  1.0.19
210
+     * @param  bool $force_delete Should the data be deleted permanently.
211
+     * @return bool result
212
+     */
213
+    public function delete( $force_delete = false ) {
214
+        if ( $this->data_store ) {
215
+            $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
+            $this->set_id( 0 );
217
+            return true;
218
+        }
219
+        return false;
220
+    }
221
+
222
+    /**
223
+     * Save should create or update based on object existence.
224
+     *
225
+     * @since  1.0.19
226
+     * @return int
227
+     */
228
+    public function save() {
229
+        if ( ! $this->data_store ) {
230
+            return $this->get_id();
231
+        }
232
+
233
+        /**
234
+         * Trigger action before saving to the DB. Allows you to adjust object props before save.
235
+         *
236
+         * @param GetPaid_Data          $this The object being saved.
237
+         * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238
+         */
239
+        do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
240
+
241
+        if ( $this->get_id() ) {
242
+            $this->data_store->update( $this );
243
+        } else {
244
+            $this->data_store->create( $this );
245
+        }
246
+
247
+        /**
248
+         * Trigger action after saving to the DB.
249
+         *
250
+         * @param GetPaid_Data          $this The object being saved.
251
+         * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252
+         */
253
+        do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
254
+
255
+        return $this->get_id();
256
+    }
257
+
258
+    /**
259
+     * Change data to JSON format.
260
+     *
261
+     * @since  1.0.19
262
+     * @return string Data in JSON format.
263
+     */
264
+    public function __toString() {
265
+        return wp_json_encode( $this->get_data() );
266
+    }
267
+
268
+    /**
269
+     * Returns all data for this object.
270
+     *
271
+     * @since  1.0.19
272
+     * @return array
273
+     */
274
+    public function get_data() {
275
+        return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
276
+    }
277
+
278
+    /**
279
+     * Returns array of expected data keys for this object.
280
+     *
281
+     * @since   1.0.19
282
+     * @return array
283
+     */
284
+    public function get_data_keys() {
285
+        return array_keys( $this->data );
286
+    }
287
+
288
+    /**
289
+     * Returns all "extra" data keys for an object (for sub objects like item types).
290
+     *
291
+     * @since  1.0.19
292
+     * @return array
293
+     */
294
+    public function get_extra_data_keys() {
295
+        return array_keys( $this->extra_data );
296
+    }
297
+
298
+    /**
299
+     * Filter null meta values from array.
300
+     *
301
+     * @since  1.0.19
302
+     * @param mixed $meta Meta value to check.
303
+     * @return bool
304
+     */
305
+    protected function filter_null_meta( $meta ) {
306
+        return ! is_null( $meta->value );
307
+    }
308
+
309
+    /**
310
+     * Get All Meta Data.
311
+     *
312
+     * @since 1.0.19
313
+     * @return array of objects.
314
+     */
315
+    public function get_meta_data() {
316
+        $this->maybe_read_meta_data();
317
+        return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
318
+    }
319
+
320
+    /**
321
+     * Check if the key is an internal one.
322
+     *
323
+     * @since  1.0.19
324
+     * @param  string $key Key to check.
325
+     * @return bool   true if it's an internal key, false otherwise
326
+     */
327
+    protected function is_internal_meta_key( $key ) {
328
+        $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
329
+
330
+        if ( ! $internal_meta_key ) {
331
+            return false;
332
+        }
333
+
334
+        $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
335
+
336
+        if ( ! $has_setter_or_getter ) {
337
+            return false;
338
+        }
339
+
340
+        /* translators: %s: $key Key to check */
341
+        getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
342
+
343
+        return true;
344
+    }
345
+
346
+    /**
347
+     * Magic method for setting data fields.
348
+     *
349
+     * This method does not update custom fields in the database.
350
+     *
351
+     * @since 1.0.19
352
+     * @access public
353
+     *
354
+     */
355
+    public function __set( $key, $value ) {
356
+
357
+        if ( 'id' == strtolower( $key ) ) {
358
+            return $this->set_id( $value );
359
+        }
360
+
361
+        if ( method_exists( $this, "set_$key") ) {
362
+
363
+            /* translators: %s: $key Key to set */
364
+            getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
365
+
366
+            call_user_func( array( $this, "set_$key" ), $value );
367
+        } else {
368
+            $this->set_prop( $key, $value );
369
+        }
370
+
371
+    }
372
+
373
+    /**
374 374
      * Margic method for retrieving a property.
375 375
      */
376 376
     public function __get( $key ) {
@@ -378,10 +378,10 @@  discard block
 block discarded – undo
378 378
         // Check if we have a helper method for that.
379 379
         if ( method_exists( $this, 'get_' . $key ) ) {
380 380
 
381
-			if ( 'post_type' != $key ) {
382
-				/* translators: %s: $key Key to set */
383
-				getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
384
-			}
381
+            if ( 'post_type' != $key ) {
382
+                /* translators: %s: $key Key to set */
383
+                getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
384
+            }
385 385
 
386 386
             return call_user_func( array( $this, 'get_' . $key ) );
387 387
         }
@@ -391,509 +391,509 @@  discard block
 block discarded – undo
391 391
             return $this->post->$key;
392 392
         }
393 393
 
394
-		return $this->get_prop( $key );
395
-
396
-    }
397
-
398
-	/**
399
-	 * Get Meta Data by Key.
400
-	 *
401
-	 * @since  1.0.19
402
-	 * @param  string $key Meta Key.
403
-	 * @param  bool   $single return first found meta with key, or all with $key.
404
-	 * @param  string $context What the value is for. Valid values are view and edit.
405
-	 * @return mixed
406
-	 */
407
-	public function get_meta( $key = '', $single = true, $context = 'view' ) {
408
-
409
-		// Check if this is an internal meta key.
410
-		$_key = str_replace( '_wpinv', '', $key );
411
-		$_key = str_replace( 'wpinv', '', $_key );
412
-		if ( $this->is_internal_meta_key( $_key ) ) {
413
-			$function = 'get_' . $_key;
414
-
415
-			if ( is_callable( array( $this, $function ) ) ) {
416
-				return $this->{$function}();
417
-			}
418
-		}
419
-
420
-		// Read the meta data if not yet read.
421
-		$this->maybe_read_meta_data();
422
-		$meta_data  = $this->get_meta_data();
423
-		$array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
424
-		$value      = $single ? '' : array();
425
-
426
-		if ( ! empty( $array_keys ) ) {
427
-			// We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
428
-			if ( $single ) {
429
-				$value = $meta_data[ current( $array_keys ) ]->value;
430
-			} else {
431
-				$value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
432
-			}
433
-		}
434
-
435
-		if ( 'view' === $context ) {
436
-			$value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
437
-		}
438
-
439
-		return $value;
440
-	}
441
-
442
-	/**
443
-	 * See if meta data exists, since get_meta always returns a '' or array().
444
-	 *
445
-	 * @since  1.0.19
446
-	 * @param  string $key Meta Key.
447
-	 * @return boolean
448
-	 */
449
-	public function meta_exists( $key = '' ) {
450
-		$this->maybe_read_meta_data();
451
-		$array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
452
-		return in_array( $key, $array_keys, true );
453
-	}
454
-
455
-	/**
456
-	 * Set all meta data from array.
457
-	 *
458
-	 * @since 1.0.19
459
-	 * @param array $data Key/Value pairs.
460
-	 */
461
-	public function set_meta_data( $data ) {
462
-		if ( ! empty( $data ) && is_array( $data ) ) {
463
-			$this->maybe_read_meta_data();
464
-			foreach ( $data as $meta ) {
465
-				$meta = (array) $meta;
466
-				if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
467
-					$this->meta_data[] = new GetPaid_Meta_Data(
468
-						array(
469
-							'id'    => $meta['id'],
470
-							'key'   => $meta['key'],
471
-							'value' => $meta['value'],
472
-						)
473
-					);
474
-				}
475
-			}
476
-		}
477
-	}
478
-
479
-	/**
480
-	 * Add meta data.
481
-	 *
482
-	 * @since 1.0.19
483
-	 *
484
-	 * @param string       $key Meta key.
485
-	 * @param string|array $value Meta value.
486
-	 * @param bool         $unique Should this be a unique key?.
487
-	 */
488
-	public function add_meta_data( $key, $value, $unique = false ) {
489
-		if ( $this->is_internal_meta_key( $key ) ) {
490
-			$function = 'set_' . $key;
491
-
492
-			if ( is_callable( array( $this, $function ) ) ) {
493
-				return $this->{$function}( $value );
494
-			}
495
-		}
496
-
497
-		$this->maybe_read_meta_data();
498
-		if ( $unique ) {
499
-			$this->delete_meta_data( $key );
500
-		}
501
-		$this->meta_data[] = new GetPaid_Meta_Data(
502
-			array(
503
-				'key'   => $key,
504
-				'value' => $value,
505
-			)
506
-		);
507
-	}
508
-
509
-	/**
510
-	 * Update meta data by key or ID, if provided.
511
-	 *
512
-	 * @since  1.0.19
513
-	 *
514
-	 * @param  string       $key Meta key.
515
-	 * @param  string|array $value Meta value.
516
-	 * @param  int          $meta_id Meta ID.
517
-	 */
518
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
519
-		if ( $this->is_internal_meta_key( $key ) ) {
520
-			$function = 'set_' . $key;
521
-
522
-			if ( is_callable( array( $this, $function ) ) ) {
523
-				return $this->{$function}( $value );
524
-			}
525
-		}
526
-
527
-		$this->maybe_read_meta_data();
528
-
529
-		$array_key = false;
530
-
531
-		if ( $meta_id ) {
532
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
533
-			$array_key  = $array_keys ? current( $array_keys ) : false;
534
-		} else {
535
-			// Find matches by key.
536
-			$matches = array();
537
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
538
-				if ( $meta->key === $key ) {
539
-					$matches[] = $meta_data_array_key;
540
-				}
541
-			}
542
-
543
-			if ( ! empty( $matches ) ) {
544
-				// Set matches to null so only one key gets the new value.
545
-				foreach ( $matches as $meta_data_array_key ) {
546
-					$this->meta_data[ $meta_data_array_key ]->value = null;
547
-				}
548
-				$array_key = current( $matches );
549
-			}
550
-		}
551
-
552
-		if ( false !== $array_key ) {
553
-			$meta        = $this->meta_data[ $array_key ];
554
-			$meta->key   = $key;
555
-			$meta->value = $value;
556
-		} else {
557
-			$this->add_meta_data( $key, $value, true );
558
-		}
559
-	}
560
-
561
-	/**
562
-	 * Delete meta data.
563
-	 *
564
-	 * @since 1.0.19
565
-	 * @param string $key Meta key.
566
-	 */
567
-	public function delete_meta_data( $key ) {
568
-		$this->maybe_read_meta_data();
569
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
570
-
571
-		if ( $array_keys ) {
572
-			foreach ( $array_keys as $array_key ) {
573
-				$this->meta_data[ $array_key ]->value = null;
574
-			}
575
-		}
576
-	}
577
-
578
-	/**
579
-	 * Delete meta data.
580
-	 *
581
-	 * @since 1.0.19
582
-	 * @param int $mid Meta ID.
583
-	 */
584
-	public function delete_meta_data_by_mid( $mid ) {
585
-		$this->maybe_read_meta_data();
586
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
587
-
588
-		if ( $array_keys ) {
589
-			foreach ( $array_keys as $array_key ) {
590
-				$this->meta_data[ $array_key ]->value = null;
591
-			}
592
-		}
593
-	}
594
-
595
-	/**
596
-	 * Read meta data if null.
597
-	 *
598
-	 * @since 1.0.19
599
-	 */
600
-	protected function maybe_read_meta_data() {
601
-		if ( is_null( $this->meta_data ) ) {
602
-			$this->read_meta_data();
603
-		}
604
-	}
605
-
606
-	/**
607
-	 * Read Meta Data from the database. Ignore any internal properties.
608
-	 * Uses it's own caches because get_metadata does not provide meta_ids.
609
-	 *
610
-	 * @since 1.0.19
611
-	 * @param bool $force_read True to force a new DB read (and update cache).
612
-	 */
613
-	public function read_meta_data( $force_read = false ) {
614
-		$this->meta_data = array();
615
-		$cache_loaded    = false;
616
-
617
-		if ( ! $this->get_id() ) {
618
-			return;
619
-		}
620
-
621
-		if ( ! $this->data_store ) {
622
-			return;
623
-		}
624
-
625
-		if ( ! empty( $this->cache_group ) ) {
626
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
627
-		}
628
-
629
-		if ( ! $force_read ) {
630
-			if ( ! empty( $this->cache_group ) ) {
631
-				$cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
632
-				$cache_loaded = ! empty( $cached_meta );
633
-			}
634
-		}
635
-
636
-		$raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
637
-		if ( $raw_meta_data ) {
638
-			foreach ( $raw_meta_data as $meta ) {
639
-				$this->meta_data[] = new GetPaid_Meta_Data(
640
-					array(
641
-						'id'    => (int) $meta->meta_id,
642
-						'key'   => $meta->meta_key,
643
-						'value' => maybe_unserialize( $meta->meta_value ),
644
-					)
645
-				);
646
-			}
647
-
648
-			if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
649
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
650
-			}
651
-		}
652
-	}
653
-
654
-	/**
655
-	 * Update Meta Data in the database.
656
-	 *
657
-	 * @since 1.0.19
658
-	 */
659
-	public function save_meta_data() {
660
-		if ( ! $this->data_store || is_null( $this->meta_data ) ) {
661
-			return;
662
-		}
663
-		foreach ( $this->meta_data as $array_key => $meta ) {
664
-			if ( is_null( $meta->value ) ) {
665
-				if ( ! empty( $meta->id ) ) {
666
-					$this->data_store->delete_meta( $this, $meta );
667
-					unset( $this->meta_data[ $array_key ] );
668
-				}
669
-			} elseif ( empty( $meta->id ) ) {
670
-				$meta->id = $this->data_store->add_meta( $this, $meta );
671
-				$meta->apply_changes();
672
-			} else {
673
-				if ( $meta->get_changes() ) {
674
-					$this->data_store->update_meta( $this, $meta );
675
-					$meta->apply_changes();
676
-				}
677
-			}
678
-		}
679
-		if ( ! empty( $this->cache_group ) ) {
680
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
681
-			wp_cache_delete( $cache_key, $this->cache_group );
682
-		}
683
-	}
684
-
685
-	/**
686
-	 * Set ID.
687
-	 *
688
-	 * @since 1.0.19
689
-	 * @param int $id ID.
690
-	 */
691
-	public function set_id( $id ) {
692
-		$this->id = absint( $id );
693
-	}
694
-
695
-	/**
696
-	 * Sets item status.
697
-	 *
698
-	 * @since 1.0.19
699
-	 * @param string $status New status.
700
-	 * @return array details of change.
701
-	 */
702
-	public function set_status( $status ) {
394
+        return $this->get_prop( $key );
395
+
396
+    }
397
+
398
+    /**
399
+     * Get Meta Data by Key.
400
+     *
401
+     * @since  1.0.19
402
+     * @param  string $key Meta Key.
403
+     * @param  bool   $single return first found meta with key, or all with $key.
404
+     * @param  string $context What the value is for. Valid values are view and edit.
405
+     * @return mixed
406
+     */
407
+    public function get_meta( $key = '', $single = true, $context = 'view' ) {
408
+
409
+        // Check if this is an internal meta key.
410
+        $_key = str_replace( '_wpinv', '', $key );
411
+        $_key = str_replace( 'wpinv', '', $_key );
412
+        if ( $this->is_internal_meta_key( $_key ) ) {
413
+            $function = 'get_' . $_key;
414
+
415
+            if ( is_callable( array( $this, $function ) ) ) {
416
+                return $this->{$function}();
417
+            }
418
+        }
419
+
420
+        // Read the meta data if not yet read.
421
+        $this->maybe_read_meta_data();
422
+        $meta_data  = $this->get_meta_data();
423
+        $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
424
+        $value      = $single ? '' : array();
425
+
426
+        if ( ! empty( $array_keys ) ) {
427
+            // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
428
+            if ( $single ) {
429
+                $value = $meta_data[ current( $array_keys ) ]->value;
430
+            } else {
431
+                $value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
432
+            }
433
+        }
434
+
435
+        if ( 'view' === $context ) {
436
+            $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
437
+        }
438
+
439
+        return $value;
440
+    }
441
+
442
+    /**
443
+     * See if meta data exists, since get_meta always returns a '' or array().
444
+     *
445
+     * @since  1.0.19
446
+     * @param  string $key Meta Key.
447
+     * @return boolean
448
+     */
449
+    public function meta_exists( $key = '' ) {
450
+        $this->maybe_read_meta_data();
451
+        $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
452
+        return in_array( $key, $array_keys, true );
453
+    }
454
+
455
+    /**
456
+     * Set all meta data from array.
457
+     *
458
+     * @since 1.0.19
459
+     * @param array $data Key/Value pairs.
460
+     */
461
+    public function set_meta_data( $data ) {
462
+        if ( ! empty( $data ) && is_array( $data ) ) {
463
+            $this->maybe_read_meta_data();
464
+            foreach ( $data as $meta ) {
465
+                $meta = (array) $meta;
466
+                if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
467
+                    $this->meta_data[] = new GetPaid_Meta_Data(
468
+                        array(
469
+                            'id'    => $meta['id'],
470
+                            'key'   => $meta['key'],
471
+                            'value' => $meta['value'],
472
+                        )
473
+                    );
474
+                }
475
+            }
476
+        }
477
+    }
478
+
479
+    /**
480
+     * Add meta data.
481
+     *
482
+     * @since 1.0.19
483
+     *
484
+     * @param string       $key Meta key.
485
+     * @param string|array $value Meta value.
486
+     * @param bool         $unique Should this be a unique key?.
487
+     */
488
+    public function add_meta_data( $key, $value, $unique = false ) {
489
+        if ( $this->is_internal_meta_key( $key ) ) {
490
+            $function = 'set_' . $key;
491
+
492
+            if ( is_callable( array( $this, $function ) ) ) {
493
+                return $this->{$function}( $value );
494
+            }
495
+        }
496
+
497
+        $this->maybe_read_meta_data();
498
+        if ( $unique ) {
499
+            $this->delete_meta_data( $key );
500
+        }
501
+        $this->meta_data[] = new GetPaid_Meta_Data(
502
+            array(
503
+                'key'   => $key,
504
+                'value' => $value,
505
+            )
506
+        );
507
+    }
508
+
509
+    /**
510
+     * Update meta data by key or ID, if provided.
511
+     *
512
+     * @since  1.0.19
513
+     *
514
+     * @param  string       $key Meta key.
515
+     * @param  string|array $value Meta value.
516
+     * @param  int          $meta_id Meta ID.
517
+     */
518
+    public function update_meta_data( $key, $value, $meta_id = 0 ) {
519
+        if ( $this->is_internal_meta_key( $key ) ) {
520
+            $function = 'set_' . $key;
521
+
522
+            if ( is_callable( array( $this, $function ) ) ) {
523
+                return $this->{$function}( $value );
524
+            }
525
+        }
526
+
527
+        $this->maybe_read_meta_data();
528
+
529
+        $array_key = false;
530
+
531
+        if ( $meta_id ) {
532
+            $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
533
+            $array_key  = $array_keys ? current( $array_keys ) : false;
534
+        } else {
535
+            // Find matches by key.
536
+            $matches = array();
537
+            foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
538
+                if ( $meta->key === $key ) {
539
+                    $matches[] = $meta_data_array_key;
540
+                }
541
+            }
542
+
543
+            if ( ! empty( $matches ) ) {
544
+                // Set matches to null so only one key gets the new value.
545
+                foreach ( $matches as $meta_data_array_key ) {
546
+                    $this->meta_data[ $meta_data_array_key ]->value = null;
547
+                }
548
+                $array_key = current( $matches );
549
+            }
550
+        }
551
+
552
+        if ( false !== $array_key ) {
553
+            $meta        = $this->meta_data[ $array_key ];
554
+            $meta->key   = $key;
555
+            $meta->value = $value;
556
+        } else {
557
+            $this->add_meta_data( $key, $value, true );
558
+        }
559
+    }
560
+
561
+    /**
562
+     * Delete meta data.
563
+     *
564
+     * @since 1.0.19
565
+     * @param string $key Meta key.
566
+     */
567
+    public function delete_meta_data( $key ) {
568
+        $this->maybe_read_meta_data();
569
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
570
+
571
+        if ( $array_keys ) {
572
+            foreach ( $array_keys as $array_key ) {
573
+                $this->meta_data[ $array_key ]->value = null;
574
+            }
575
+        }
576
+    }
577
+
578
+    /**
579
+     * Delete meta data.
580
+     *
581
+     * @since 1.0.19
582
+     * @param int $mid Meta ID.
583
+     */
584
+    public function delete_meta_data_by_mid( $mid ) {
585
+        $this->maybe_read_meta_data();
586
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
587
+
588
+        if ( $array_keys ) {
589
+            foreach ( $array_keys as $array_key ) {
590
+                $this->meta_data[ $array_key ]->value = null;
591
+            }
592
+        }
593
+    }
594
+
595
+    /**
596
+     * Read meta data if null.
597
+     *
598
+     * @since 1.0.19
599
+     */
600
+    protected function maybe_read_meta_data() {
601
+        if ( is_null( $this->meta_data ) ) {
602
+            $this->read_meta_data();
603
+        }
604
+    }
605
+
606
+    /**
607
+     * Read Meta Data from the database. Ignore any internal properties.
608
+     * Uses it's own caches because get_metadata does not provide meta_ids.
609
+     *
610
+     * @since 1.0.19
611
+     * @param bool $force_read True to force a new DB read (and update cache).
612
+     */
613
+    public function read_meta_data( $force_read = false ) {
614
+        $this->meta_data = array();
615
+        $cache_loaded    = false;
616
+
617
+        if ( ! $this->get_id() ) {
618
+            return;
619
+        }
620
+
621
+        if ( ! $this->data_store ) {
622
+            return;
623
+        }
624
+
625
+        if ( ! empty( $this->cache_group ) ) {
626
+            $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
627
+        }
628
+
629
+        if ( ! $force_read ) {
630
+            if ( ! empty( $this->cache_group ) ) {
631
+                $cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
632
+                $cache_loaded = ! empty( $cached_meta );
633
+            }
634
+        }
635
+
636
+        $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
637
+        if ( $raw_meta_data ) {
638
+            foreach ( $raw_meta_data as $meta ) {
639
+                $this->meta_data[] = new GetPaid_Meta_Data(
640
+                    array(
641
+                        'id'    => (int) $meta->meta_id,
642
+                        'key'   => $meta->meta_key,
643
+                        'value' => maybe_unserialize( $meta->meta_value ),
644
+                    )
645
+                );
646
+            }
647
+
648
+            if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
649
+                wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
650
+            }
651
+        }
652
+    }
653
+
654
+    /**
655
+     * Update Meta Data in the database.
656
+     *
657
+     * @since 1.0.19
658
+     */
659
+    public function save_meta_data() {
660
+        if ( ! $this->data_store || is_null( $this->meta_data ) ) {
661
+            return;
662
+        }
663
+        foreach ( $this->meta_data as $array_key => $meta ) {
664
+            if ( is_null( $meta->value ) ) {
665
+                if ( ! empty( $meta->id ) ) {
666
+                    $this->data_store->delete_meta( $this, $meta );
667
+                    unset( $this->meta_data[ $array_key ] );
668
+                }
669
+            } elseif ( empty( $meta->id ) ) {
670
+                $meta->id = $this->data_store->add_meta( $this, $meta );
671
+                $meta->apply_changes();
672
+            } else {
673
+                if ( $meta->get_changes() ) {
674
+                    $this->data_store->update_meta( $this, $meta );
675
+                    $meta->apply_changes();
676
+                }
677
+            }
678
+        }
679
+        if ( ! empty( $this->cache_group ) ) {
680
+            $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
681
+            wp_cache_delete( $cache_key, $this->cache_group );
682
+        }
683
+    }
684
+
685
+    /**
686
+     * Set ID.
687
+     *
688
+     * @since 1.0.19
689
+     * @param int $id ID.
690
+     */
691
+    public function set_id( $id ) {
692
+        $this->id = absint( $id );
693
+    }
694
+
695
+    /**
696
+     * Sets item status.
697
+     *
698
+     * @since 1.0.19
699
+     * @param string $status New status.
700
+     * @return array details of change.
701
+     */
702
+    public function set_status( $status ) {
703 703
         $old_status = $this->get_status();
704 704
 
705
-		$this->set_prop( 'status', $status );
706
-
707
-		return array(
708
-			'from' => $old_status,
709
-			'to'   => $status,
710
-		);
711
-    }
712
-
713
-	/**
714
-	 * Set all props to default values.
715
-	 *
716
-	 * @since 1.0.19
717
-	 */
718
-	public function set_defaults() {
719
-		$this->data    = $this->default_data;
720
-		$this->changes = array();
721
-		$this->set_object_read( false );
722
-	}
723
-
724
-	/**
725
-	 * Set object read property.
726
-	 *
727
-	 * @since 1.0.19
728
-	 * @param boolean $read Should read?.
729
-	 */
730
-	public function set_object_read( $read = true ) {
731
-		$this->object_read = (bool) $read;
732
-	}
733
-
734
-	/**
735
-	 * Get object read property.
736
-	 *
737
-	 * @since  1.0.19
738
-	 * @return boolean
739
-	 */
740
-	public function get_object_read() {
741
-		return (bool) $this->object_read;
742
-	}
743
-
744
-	/**
745
-	 * Set a collection of props in one go, collect any errors, and return the result.
746
-	 * Only sets using public methods.
747
-	 *
748
-	 * @since  1.0.19
749
-	 *
750
-	 * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
751
-	 * @param string $context In what context to run this.
752
-	 *
753
-	 * @return bool|WP_Error
754
-	 */
755
-	public function set_props( $props, $context = 'set' ) {
756
-		$errors = false;
757
-
758
-		foreach ( $props as $prop => $value ) {
759
-			try {
760
-				/**
761
-				 * Checks if the prop being set is allowed, and the value is not null.
762
-				 */
763
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
764
-					continue;
765
-				}
766
-				$setter = "set_$prop";
767
-
768
-				if ( is_callable( array( $this, $setter ) ) ) {
769
-					$this->{$setter}( $value );
770
-				}
771
-			} catch ( Exception $e ) {
772
-				if ( ! $errors ) {
773
-					$errors = new WP_Error();
774
-				}
775
-				$errors->add( $e->getCode(), $e->getMessage() );
776
-				$this->last_error = $e->getMessage();
777
-			}
778
-		}
779
-
780
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
781
-	}
782
-
783
-	/**
784
-	 * Sets a prop for a setter method.
785
-	 *
786
-	 * This stores changes in a special array so we can track what needs saving
787
-	 * the the DB later.
788
-	 *
789
-	 * @since 1.0.19
790
-	 * @param string $prop Name of prop to set.
791
-	 * @param mixed  $value Value of the prop.
792
-	 */
793
-	protected function set_prop( $prop, $value ) {
794
-		if ( array_key_exists( $prop, $this->data ) ) {
795
-			if ( true === $this->object_read ) {
796
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
797
-					$this->changes[ $prop ] = $value;
798
-				}
799
-			} else {
800
-				$this->data[ $prop ] = $value;
801
-			}
802
-		}
803
-	}
804
-
805
-	/**
806
-	 * Return data changes only.
807
-	 *
808
-	 * @since 1.0.19
809
-	 * @return array
810
-	 */
811
-	public function get_changes() {
812
-		return $this->changes;
813
-	}
814
-
815
-	/**
816
-	 * Merge changes with data and clear.
817
-	 *
818
-	 * @since 1.0.19
819
-	 */
820
-	public function apply_changes() {
821
-		$this->data    = array_replace_recursive( $this->data, $this->changes );
822
-		$this->changes = array();
823
-	}
824
-
825
-	/**
826
-	 * Prefix for action and filter hooks on data.
827
-	 *
828
-	 * @since  1.0.19
829
-	 * @return string
830
-	 */
831
-	protected function get_hook_prefix() {
832
-		return 'wpinv_get_' . $this->object_type . '_';
833
-	}
834
-
835
-	/**
836
-	 * Gets a prop for a getter method.
837
-	 *
838
-	 * Gets the value from either current pending changes, or the data itself.
839
-	 * Context controls what happens to the value before it's returned.
840
-	 *
841
-	 * @since  1.0.19
842
-	 * @param  string $prop Name of prop to get.
843
-	 * @param  string $context What the value is for. Valid values are view and edit.
844
-	 * @return mixed
845
-	 */
846
-	protected function get_prop( $prop, $context = 'view' ) {
847
-		$value = null;
848
-
849
-		if ( array_key_exists( $prop, $this->data ) ) {
850
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
851
-
852
-			if ( 'view' === $context ) {
853
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
854
-			}
855
-		}
856
-
857
-		return $value;
858
-	}
859
-
860
-	/**
861
-	 * Sets a date prop whilst handling formatting and datetime objects.
862
-	 *
863
-	 * @since 1.0.19
864
-	 * @param string         $prop Name of prop to set.
865
-	 * @param string|integer $value Value of the prop.
866
-	 */
867
-	protected function set_date_prop( $prop, $value ) {
868
-
869
-		if ( empty( $value ) ) {
870
-			$this->set_prop( $prop, null );
871
-			return;
872
-		}
873
-		$this->set_prop( $prop, $value );
874
-
875
-	}
876
-
877
-	/**
878
-	 * When invalid data is found, throw an exception unless reading from the DB.
879
-	 *
880
-	 * @since 1.0.19
881
-	 * @param string $code             Error code.
882
-	 * @param string $message          Error message.
883
-	 */
884
-	protected function error( $code, $message ) {
885
-		$this->last_error = $message;
886
-	}
887
-
888
-	/**
889
-	 * Checks if the object is saved in the database
890
-	 *
891
-	 * @since 1.0.19
892
-	 * @return bool
893
-	 */
894
-	public function exists() {
895
-		$id = $this->get_id();
896
-		return ! empty( $id );
897
-	}
705
+        $this->set_prop( 'status', $status );
706
+
707
+        return array(
708
+            'from' => $old_status,
709
+            'to'   => $status,
710
+        );
711
+    }
712
+
713
+    /**
714
+     * Set all props to default values.
715
+     *
716
+     * @since 1.0.19
717
+     */
718
+    public function set_defaults() {
719
+        $this->data    = $this->default_data;
720
+        $this->changes = array();
721
+        $this->set_object_read( false );
722
+    }
723
+
724
+    /**
725
+     * Set object read property.
726
+     *
727
+     * @since 1.0.19
728
+     * @param boolean $read Should read?.
729
+     */
730
+    public function set_object_read( $read = true ) {
731
+        $this->object_read = (bool) $read;
732
+    }
733
+
734
+    /**
735
+     * Get object read property.
736
+     *
737
+     * @since  1.0.19
738
+     * @return boolean
739
+     */
740
+    public function get_object_read() {
741
+        return (bool) $this->object_read;
742
+    }
743
+
744
+    /**
745
+     * Set a collection of props in one go, collect any errors, and return the result.
746
+     * Only sets using public methods.
747
+     *
748
+     * @since  1.0.19
749
+     *
750
+     * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
751
+     * @param string $context In what context to run this.
752
+     *
753
+     * @return bool|WP_Error
754
+     */
755
+    public function set_props( $props, $context = 'set' ) {
756
+        $errors = false;
757
+
758
+        foreach ( $props as $prop => $value ) {
759
+            try {
760
+                /**
761
+                 * Checks if the prop being set is allowed, and the value is not null.
762
+                 */
763
+                if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
764
+                    continue;
765
+                }
766
+                $setter = "set_$prop";
767
+
768
+                if ( is_callable( array( $this, $setter ) ) ) {
769
+                    $this->{$setter}( $value );
770
+                }
771
+            } catch ( Exception $e ) {
772
+                if ( ! $errors ) {
773
+                    $errors = new WP_Error();
774
+                }
775
+                $errors->add( $e->getCode(), $e->getMessage() );
776
+                $this->last_error = $e->getMessage();
777
+            }
778
+        }
779
+
780
+        return $errors && count( $errors->get_error_codes() ) ? $errors : true;
781
+    }
782
+
783
+    /**
784
+     * Sets a prop for a setter method.
785
+     *
786
+     * This stores changes in a special array so we can track what needs saving
787
+     * the the DB later.
788
+     *
789
+     * @since 1.0.19
790
+     * @param string $prop Name of prop to set.
791
+     * @param mixed  $value Value of the prop.
792
+     */
793
+    protected function set_prop( $prop, $value ) {
794
+        if ( array_key_exists( $prop, $this->data ) ) {
795
+            if ( true === $this->object_read ) {
796
+                if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
797
+                    $this->changes[ $prop ] = $value;
798
+                }
799
+            } else {
800
+                $this->data[ $prop ] = $value;
801
+            }
802
+        }
803
+    }
804
+
805
+    /**
806
+     * Return data changes only.
807
+     *
808
+     * @since 1.0.19
809
+     * @return array
810
+     */
811
+    public function get_changes() {
812
+        return $this->changes;
813
+    }
814
+
815
+    /**
816
+     * Merge changes with data and clear.
817
+     *
818
+     * @since 1.0.19
819
+     */
820
+    public function apply_changes() {
821
+        $this->data    = array_replace_recursive( $this->data, $this->changes );
822
+        $this->changes = array();
823
+    }
824
+
825
+    /**
826
+     * Prefix for action and filter hooks on data.
827
+     *
828
+     * @since  1.0.19
829
+     * @return string
830
+     */
831
+    protected function get_hook_prefix() {
832
+        return 'wpinv_get_' . $this->object_type . '_';
833
+    }
834
+
835
+    /**
836
+     * Gets a prop for a getter method.
837
+     *
838
+     * Gets the value from either current pending changes, or the data itself.
839
+     * Context controls what happens to the value before it's returned.
840
+     *
841
+     * @since  1.0.19
842
+     * @param  string $prop Name of prop to get.
843
+     * @param  string $context What the value is for. Valid values are view and edit.
844
+     * @return mixed
845
+     */
846
+    protected function get_prop( $prop, $context = 'view' ) {
847
+        $value = null;
848
+
849
+        if ( array_key_exists( $prop, $this->data ) ) {
850
+            $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
851
+
852
+            if ( 'view' === $context ) {
853
+                $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
854
+            }
855
+        }
856
+
857
+        return $value;
858
+    }
859
+
860
+    /**
861
+     * Sets a date prop whilst handling formatting and datetime objects.
862
+     *
863
+     * @since 1.0.19
864
+     * @param string         $prop Name of prop to set.
865
+     * @param string|integer $value Value of the prop.
866
+     */
867
+    protected function set_date_prop( $prop, $value ) {
868
+
869
+        if ( empty( $value ) ) {
870
+            $this->set_prop( $prop, null );
871
+            return;
872
+        }
873
+        $this->set_prop( $prop, $value );
874
+
875
+    }
876
+
877
+    /**
878
+     * When invalid data is found, throw an exception unless reading from the DB.
879
+     *
880
+     * @since 1.0.19
881
+     * @param string $code             Error code.
882
+     * @param string $message          Error message.
883
+     */
884
+    protected function error( $code, $message ) {
885
+        $this->last_error = $message;
886
+    }
887
+
888
+    /**
889
+     * Checks if the object is saved in the database
890
+     *
891
+     * @since 1.0.19
892
+     * @return bool
893
+     */
894
+    public function exists() {
895
+        $id = $this->get_id();
896
+        return ! empty( $id );
897
+    }
898 898
 
899 899
 }
Please login to merge, or discard this patch.
Spacing   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  *
9 9
  */
10 10
 
11
-if ( ! defined( 'ABSPATH' ) ) {
11
+if (!defined('ABSPATH')) {
12 12
 	exit;
13 13
 }
14 14
 
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
 	 *
118 118
 	 * @param int|object|array $read ID to load from the DB (optional) or already queried data.
119 119
 	 */
120
-	public function __construct( $read = 0 ) {
121
-		$this->data         = array_merge( $this->data, $this->extra_data );
120
+	public function __construct($read = 0) {
121
+		$this->data         = array_merge($this->data, $this->extra_data);
122 122
 		$this->default_data = $this->data;
123 123
 	}
124 124
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 * @return array
129 129
 	 */
130 130
 	public function __sleep() {
131
-		return array( 'id' );
131
+		return array('id');
132 132
 	}
133 133
 
134 134
 	/**
@@ -137,10 +137,10 @@  discard block
 block discarded – undo
137 137
 	 * If the object no longer exists, remove the ID.
138 138
 	 */
139 139
 	public function __wakeup() {
140
-		$this->__construct( absint( $this->id ) );
140
+		$this->__construct(absint($this->id));
141 141
 
142
-		if ( ! empty( $this->last_error ) ) {
143
-			$this->set_id( 0 );
142
+		if (!empty($this->last_error)) {
143
+			$this->set_id(0);
144 144
 		}
145 145
 
146 146
 	}
@@ -152,11 +152,11 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	public function __clone() {
154 154
 		$this->maybe_read_meta_data();
155
-		if ( ! empty( $this->meta_data ) ) {
156
-			foreach ( $this->meta_data as $array_key => $meta ) {
157
-				$this->meta_data[ $array_key ] = clone $meta;
158
-				if ( ! empty( $meta->id ) ) {
159
-					$this->meta_data[ $array_key ]->id = null;
155
+		if (!empty($this->meta_data)) {
156
+			foreach ($this->meta_data as $array_key => $meta) {
157
+				$this->meta_data[$array_key] = clone $meta;
158
+				if (!empty($meta->id)) {
159
+					$this->meta_data[$array_key]->id = null;
160 160
 				}
161 161
 			}
162 162
 		}
@@ -199,8 +199,8 @@  discard block
 block discarded – undo
199 199
 	 * @param  string $context View or edit context.
200 200
 	 * @return string
201 201
 	 */
202
-	public function get_status( $context = 'view' ) {
203
-		return $this->get_prop( 'status', $context );
202
+	public function get_status($context = 'view') {
203
+		return $this->get_prop('status', $context);
204 204
     }
205 205
 
206 206
 	/**
@@ -210,10 +210,10 @@  discard block
 block discarded – undo
210 210
 	 * @param  bool $force_delete Should the data be deleted permanently.
211 211
 	 * @return bool result
212 212
 	 */
213
-	public function delete( $force_delete = false ) {
214
-		if ( $this->data_store ) {
215
-			$this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
-			$this->set_id( 0 );
213
+	public function delete($force_delete = false) {
214
+		if ($this->data_store) {
215
+			$this->data_store->delete($this, array('force_delete' => $force_delete));
216
+			$this->set_id(0);
217 217
 			return true;
218 218
 		}
219 219
 		return false;
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 	 * @return int
227 227
 	 */
228 228
 	public function save() {
229
-		if ( ! $this->data_store ) {
229
+		if (!$this->data_store) {
230 230
 			return $this->get_id();
231 231
 		}
232 232
 
@@ -236,12 +236,12 @@  discard block
 block discarded – undo
236 236
 		 * @param GetPaid_Data          $this The object being saved.
237 237
 		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238 238
 		 */
239
-		do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
239
+		do_action('getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store);
240 240
 
241
-		if ( $this->get_id() ) {
242
-			$this->data_store->update( $this );
241
+		if ($this->get_id()) {
242
+			$this->data_store->update($this);
243 243
 		} else {
244
-			$this->data_store->create( $this );
244
+			$this->data_store->create($this);
245 245
 		}
246 246
 
247 247
 		/**
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 		 * @param GetPaid_Data          $this The object being saved.
251 251
 		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252 252
 		 */
253
-		do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
253
+		do_action('getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store);
254 254
 
255 255
 		return $this->get_id();
256 256
 	}
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 	 * @return string Data in JSON format.
263 263
 	 */
264 264
 	public function __toString() {
265
-		return wp_json_encode( $this->get_data() );
265
+		return wp_json_encode($this->get_data());
266 266
 	}
267 267
 
268 268
 	/**
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 	 * @return array
273 273
 	 */
274 274
 	public function get_data() {
275
-		return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
275
+		return array_merge(array('id' => $this->get_id()), $this->data, array('meta_data' => $this->get_meta_data()));
276 276
 	}
277 277
 
278 278
 	/**
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 	 * @return array
283 283
 	 */
284 284
 	public function get_data_keys() {
285
-		return array_keys( $this->data );
285
+		return array_keys($this->data);
286 286
 	}
287 287
 
288 288
 	/**
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 	 * @return array
293 293
 	 */
294 294
 	public function get_extra_data_keys() {
295
-		return array_keys( $this->extra_data );
295
+		return array_keys($this->extra_data);
296 296
 	}
297 297
 
298 298
 	/**
@@ -302,8 +302,8 @@  discard block
 block discarded – undo
302 302
 	 * @param mixed $meta Meta value to check.
303 303
 	 * @return bool
304 304
 	 */
305
-	protected function filter_null_meta( $meta ) {
306
-		return ! is_null( $meta->value );
305
+	protected function filter_null_meta($meta) {
306
+		return !is_null($meta->value);
307 307
 	}
308 308
 
309 309
 	/**
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 	 */
315 315
 	public function get_meta_data() {
316 316
 		$this->maybe_read_meta_data();
317
-		return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
317
+		return array_values(array_filter($this->meta_data, array($this, 'filter_null_meta')));
318 318
 	}
319 319
 
320 320
 	/**
@@ -324,21 +324,21 @@  discard block
 block discarded – undo
324 324
 	 * @param  string $key Key to check.
325 325
 	 * @return bool   true if it's an internal key, false otherwise
326 326
 	 */
327
-	protected function is_internal_meta_key( $key ) {
328
-		$internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
327
+	protected function is_internal_meta_key($key) {
328
+		$internal_meta_key = !empty($key) && $this->data_store && in_array($key, $this->data_store->get_internal_meta_keys(), true);
329 329
 
330
-		if ( ! $internal_meta_key ) {
330
+		if (!$internal_meta_key) {
331 331
 			return false;
332 332
 		}
333 333
 
334
-		$has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
334
+		$has_setter_or_getter = is_callable(array($this, 'set_' . $key)) || is_callable(array($this, 'get_' . $key));
335 335
 
336
-		if ( ! $has_setter_or_getter ) {
336
+		if (!$has_setter_or_getter) {
337 337
 			return false;
338 338
 		}
339 339
 
340 340
 		/* translators: %s: $key Key to check */
341
-		getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
341
+		getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid'), $key), '1.0.19');
342 342
 
343 343
 		return true;
344 344
 	}
@@ -352,20 +352,20 @@  discard block
 block discarded – undo
352 352
 	 * @access public
353 353
 	 *
354 354
 	 */
355
-	public function __set( $key, $value ) {
355
+	public function __set($key, $value) {
356 356
 
357
-		if ( 'id' == strtolower( $key ) ) {
358
-			return $this->set_id( $value );
357
+		if ('id' == strtolower($key)) {
358
+			return $this->set_id($value);
359 359
 		}
360 360
 
361
-		if ( method_exists( $this, "set_$key") ) {
361
+		if (method_exists($this, "set_$key")) {
362 362
 
363 363
 			/* translators: %s: $key Key to set */
364
-			getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
364
+			getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid'), $key), '1.0.19');
365 365
 
366
-			call_user_func( array( $this, "set_$key" ), $value );
366
+			call_user_func(array($this, "set_$key"), $value);
367 367
 		} else {
368
-			$this->set_prop( $key, $value );
368
+			$this->set_prop($key, $value);
369 369
 		}
370 370
 
371 371
 	}
@@ -373,25 +373,25 @@  discard block
 block discarded – undo
373 373
 	/**
374 374
      * Margic method for retrieving a property.
375 375
      */
376
-    public function __get( $key ) {
376
+    public function __get($key) {
377 377
 
378 378
         // Check if we have a helper method for that.
379
-        if ( method_exists( $this, 'get_' . $key ) ) {
379
+        if (method_exists($this, 'get_' . $key)) {
380 380
 
381
-			if ( 'post_type' != $key ) {
381
+			if ('post_type' != $key) {
382 382
 				/* translators: %s: $key Key to set */
383
-				getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
383
+				getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid'), $key), '1.0.19');
384 384
 			}
385 385
 
386
-            return call_user_func( array( $this, 'get_' . $key ) );
386
+            return call_user_func(array($this, 'get_' . $key));
387 387
         }
388 388
 
389 389
         // Check if the key is in the associated $post object.
390
-        if ( ! empty( $this->post ) && isset( $this->post->$key ) ) {
390
+        if (!empty($this->post) && isset($this->post->$key)) {
391 391
             return $this->post->$key;
392 392
         }
393 393
 
394
-		return $this->get_prop( $key );
394
+		return $this->get_prop($key);
395 395
 
396 396
     }
397 397
 
@@ -404,15 +404,15 @@  discard block
 block discarded – undo
404 404
 	 * @param  string $context What the value is for. Valid values are view and edit.
405 405
 	 * @return mixed
406 406
 	 */
407
-	public function get_meta( $key = '', $single = true, $context = 'view' ) {
407
+	public function get_meta($key = '', $single = true, $context = 'view') {
408 408
 
409 409
 		// Check if this is an internal meta key.
410
-		$_key = str_replace( '_wpinv', '', $key );
411
-		$_key = str_replace( 'wpinv', '', $_key );
412
-		if ( $this->is_internal_meta_key( $_key ) ) {
410
+		$_key = str_replace('_wpinv', '', $key);
411
+		$_key = str_replace('wpinv', '', $_key);
412
+		if ($this->is_internal_meta_key($_key)) {
413 413
 			$function = 'get_' . $_key;
414 414
 
415
-			if ( is_callable( array( $this, $function ) ) ) {
415
+			if (is_callable(array($this, $function))) {
416 416
 				return $this->{$function}();
417 417
 			}
418 418
 		}
@@ -420,20 +420,20 @@  discard block
 block discarded – undo
420 420
 		// Read the meta data if not yet read.
421 421
 		$this->maybe_read_meta_data();
422 422
 		$meta_data  = $this->get_meta_data();
423
-		$array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
423
+		$array_keys = array_keys(wp_list_pluck($meta_data, 'key'), $key, true);
424 424
 		$value      = $single ? '' : array();
425 425
 
426
-		if ( ! empty( $array_keys ) ) {
426
+		if (!empty($array_keys)) {
427 427
 			// We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
428
-			if ( $single ) {
429
-				$value = $meta_data[ current( $array_keys ) ]->value;
428
+			if ($single) {
429
+				$value = $meta_data[current($array_keys)]->value;
430 430
 			} else {
431
-				$value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
431
+				$value = array_intersect_key($meta_data, array_flip($array_keys));
432 432
 			}
433 433
 		}
434 434
 
435
-		if ( 'view' === $context ) {
436
-			$value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
435
+		if ('view' === $context) {
436
+			$value = apply_filters($this->get_hook_prefix() . $key, $value, $this);
437 437
 		}
438 438
 
439 439
 		return $value;
@@ -446,10 +446,10 @@  discard block
 block discarded – undo
446 446
 	 * @param  string $key Meta Key.
447 447
 	 * @return boolean
448 448
 	 */
449
-	public function meta_exists( $key = '' ) {
449
+	public function meta_exists($key = '') {
450 450
 		$this->maybe_read_meta_data();
451
-		$array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
452
-		return in_array( $key, $array_keys, true );
451
+		$array_keys = wp_list_pluck($this->get_meta_data(), 'key');
452
+		return in_array($key, $array_keys, true);
453 453
 	}
454 454
 
455 455
 	/**
@@ -458,12 +458,12 @@  discard block
 block discarded – undo
458 458
 	 * @since 1.0.19
459 459
 	 * @param array $data Key/Value pairs.
460 460
 	 */
461
-	public function set_meta_data( $data ) {
462
-		if ( ! empty( $data ) && is_array( $data ) ) {
461
+	public function set_meta_data($data) {
462
+		if (!empty($data) && is_array($data)) {
463 463
 			$this->maybe_read_meta_data();
464
-			foreach ( $data as $meta ) {
464
+			foreach ($data as $meta) {
465 465
 				$meta = (array) $meta;
466
-				if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
466
+				if (isset($meta['key'], $meta['value'], $meta['id'])) {
467 467
 					$this->meta_data[] = new GetPaid_Meta_Data(
468 468
 						array(
469 469
 							'id'    => $meta['id'],
@@ -485,18 +485,18 @@  discard block
 block discarded – undo
485 485
 	 * @param string|array $value Meta value.
486 486
 	 * @param bool         $unique Should this be a unique key?.
487 487
 	 */
488
-	public function add_meta_data( $key, $value, $unique = false ) {
489
-		if ( $this->is_internal_meta_key( $key ) ) {
488
+	public function add_meta_data($key, $value, $unique = false) {
489
+		if ($this->is_internal_meta_key($key)) {
490 490
 			$function = 'set_' . $key;
491 491
 
492
-			if ( is_callable( array( $this, $function ) ) ) {
493
-				return $this->{$function}( $value );
492
+			if (is_callable(array($this, $function))) {
493
+				return $this->{$function}($value);
494 494
 			}
495 495
 		}
496 496
 
497 497
 		$this->maybe_read_meta_data();
498
-		if ( $unique ) {
499
-			$this->delete_meta_data( $key );
498
+		if ($unique) {
499
+			$this->delete_meta_data($key);
500 500
 		}
501 501
 		$this->meta_data[] = new GetPaid_Meta_Data(
502 502
 			array(
@@ -515,12 +515,12 @@  discard block
 block discarded – undo
515 515
 	 * @param  string|array $value Meta value.
516 516
 	 * @param  int          $meta_id Meta ID.
517 517
 	 */
518
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
519
-		if ( $this->is_internal_meta_key( $key ) ) {
518
+	public function update_meta_data($key, $value, $meta_id = 0) {
519
+		if ($this->is_internal_meta_key($key)) {
520 520
 			$function = 'set_' . $key;
521 521
 
522
-			if ( is_callable( array( $this, $function ) ) ) {
523
-				return $this->{$function}( $value );
522
+			if (is_callable(array($this, $function))) {
523
+				return $this->{$function}($value);
524 524
 			}
525 525
 		}
526 526
 
@@ -528,33 +528,33 @@  discard block
 block discarded – undo
528 528
 
529 529
 		$array_key = false;
530 530
 
531
-		if ( $meta_id ) {
532
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
533
-			$array_key  = $array_keys ? current( $array_keys ) : false;
531
+		if ($meta_id) {
532
+			$array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), $meta_id, true);
533
+			$array_key  = $array_keys ? current($array_keys) : false;
534 534
 		} else {
535 535
 			// Find matches by key.
536 536
 			$matches = array();
537
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
538
-				if ( $meta->key === $key ) {
537
+			foreach ($this->meta_data as $meta_data_array_key => $meta) {
538
+				if ($meta->key === $key) {
539 539
 					$matches[] = $meta_data_array_key;
540 540
 				}
541 541
 			}
542 542
 
543
-			if ( ! empty( $matches ) ) {
543
+			if (!empty($matches)) {
544 544
 				// Set matches to null so only one key gets the new value.
545
-				foreach ( $matches as $meta_data_array_key ) {
546
-					$this->meta_data[ $meta_data_array_key ]->value = null;
545
+				foreach ($matches as $meta_data_array_key) {
546
+					$this->meta_data[$meta_data_array_key]->value = null;
547 547
 				}
548
-				$array_key = current( $matches );
548
+				$array_key = current($matches);
549 549
 			}
550 550
 		}
551 551
 
552
-		if ( false !== $array_key ) {
553
-			$meta        = $this->meta_data[ $array_key ];
552
+		if (false !== $array_key) {
553
+			$meta        = $this->meta_data[$array_key];
554 554
 			$meta->key   = $key;
555 555
 			$meta->value = $value;
556 556
 		} else {
557
-			$this->add_meta_data( $key, $value, true );
557
+			$this->add_meta_data($key, $value, true);
558 558
 		}
559 559
 	}
560 560
 
@@ -564,13 +564,13 @@  discard block
 block discarded – undo
564 564
 	 * @since 1.0.19
565 565
 	 * @param string $key Meta key.
566 566
 	 */
567
-	public function delete_meta_data( $key ) {
567
+	public function delete_meta_data($key) {
568 568
 		$this->maybe_read_meta_data();
569
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
569
+		$array_keys = array_keys(wp_list_pluck($this->meta_data, 'key'), $key, true);
570 570
 
571
-		if ( $array_keys ) {
572
-			foreach ( $array_keys as $array_key ) {
573
-				$this->meta_data[ $array_key ]->value = null;
571
+		if ($array_keys) {
572
+			foreach ($array_keys as $array_key) {
573
+				$this->meta_data[$array_key]->value = null;
574 574
 			}
575 575
 		}
576 576
 	}
@@ -581,13 +581,13 @@  discard block
 block discarded – undo
581 581
 	 * @since 1.0.19
582 582
 	 * @param int $mid Meta ID.
583 583
 	 */
584
-	public function delete_meta_data_by_mid( $mid ) {
584
+	public function delete_meta_data_by_mid($mid) {
585 585
 		$this->maybe_read_meta_data();
586
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
586
+		$array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), (int) $mid, true);
587 587
 
588
-		if ( $array_keys ) {
589
-			foreach ( $array_keys as $array_key ) {
590
-				$this->meta_data[ $array_key ]->value = null;
588
+		if ($array_keys) {
589
+			foreach ($array_keys as $array_key) {
590
+				$this->meta_data[$array_key]->value = null;
591 591
 			}
592 592
 		}
593 593
 	}
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
 	 * @since 1.0.19
599 599
 	 */
600 600
 	protected function maybe_read_meta_data() {
601
-		if ( is_null( $this->meta_data ) ) {
601
+		if (is_null($this->meta_data)) {
602 602
 			$this->read_meta_data();
603 603
 		}
604 604
 	}
@@ -610,43 +610,43 @@  discard block
 block discarded – undo
610 610
 	 * @since 1.0.19
611 611
 	 * @param bool $force_read True to force a new DB read (and update cache).
612 612
 	 */
613
-	public function read_meta_data( $force_read = false ) {
613
+	public function read_meta_data($force_read = false) {
614 614
 		$this->meta_data = array();
615 615
 		$cache_loaded    = false;
616 616
 
617
-		if ( ! $this->get_id() ) {
617
+		if (!$this->get_id()) {
618 618
 			return;
619 619
 		}
620 620
 
621
-		if ( ! $this->data_store ) {
621
+		if (!$this->data_store) {
622 622
 			return;
623 623
 		}
624 624
 
625
-		if ( ! empty( $this->cache_group ) ) {
626
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
625
+		if (!empty($this->cache_group)) {
626
+			$cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id();
627 627
 		}
628 628
 
629
-		if ( ! $force_read ) {
630
-			if ( ! empty( $this->cache_group ) ) {
631
-				$cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
632
-				$cache_loaded = ! empty( $cached_meta );
629
+		if (!$force_read) {
630
+			if (!empty($this->cache_group)) {
631
+				$cached_meta  = wp_cache_get($cache_key, $this->cache_group);
632
+				$cache_loaded = !empty($cached_meta);
633 633
 			}
634 634
 		}
635 635
 
636
-		$raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
637
-		if ( $raw_meta_data ) {
638
-			foreach ( $raw_meta_data as $meta ) {
636
+		$raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta($this);
637
+		if ($raw_meta_data) {
638
+			foreach ($raw_meta_data as $meta) {
639 639
 				$this->meta_data[] = new GetPaid_Meta_Data(
640 640
 					array(
641 641
 						'id'    => (int) $meta->meta_id,
642 642
 						'key'   => $meta->meta_key,
643
-						'value' => maybe_unserialize( $meta->meta_value ),
643
+						'value' => maybe_unserialize($meta->meta_value),
644 644
 					)
645 645
 				);
646 646
 			}
647 647
 
648
-			if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
649
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
648
+			if (!$cache_loaded && !empty($this->cache_group)) {
649
+				wp_cache_set($cache_key, $raw_meta_data, $this->cache_group);
650 650
 			}
651 651
 		}
652 652
 	}
@@ -657,28 +657,28 @@  discard block
 block discarded – undo
657 657
 	 * @since 1.0.19
658 658
 	 */
659 659
 	public function save_meta_data() {
660
-		if ( ! $this->data_store || is_null( $this->meta_data ) ) {
660
+		if (!$this->data_store || is_null($this->meta_data)) {
661 661
 			return;
662 662
 		}
663
-		foreach ( $this->meta_data as $array_key => $meta ) {
664
-			if ( is_null( $meta->value ) ) {
665
-				if ( ! empty( $meta->id ) ) {
666
-					$this->data_store->delete_meta( $this, $meta );
667
-					unset( $this->meta_data[ $array_key ] );
663
+		foreach ($this->meta_data as $array_key => $meta) {
664
+			if (is_null($meta->value)) {
665
+				if (!empty($meta->id)) {
666
+					$this->data_store->delete_meta($this, $meta);
667
+					unset($this->meta_data[$array_key]);
668 668
 				}
669
-			} elseif ( empty( $meta->id ) ) {
670
-				$meta->id = $this->data_store->add_meta( $this, $meta );
669
+			} elseif (empty($meta->id)) {
670
+				$meta->id = $this->data_store->add_meta($this, $meta);
671 671
 				$meta->apply_changes();
672 672
 			} else {
673
-				if ( $meta->get_changes() ) {
674
-					$this->data_store->update_meta( $this, $meta );
673
+				if ($meta->get_changes()) {
674
+					$this->data_store->update_meta($this, $meta);
675 675
 					$meta->apply_changes();
676 676
 				}
677 677
 			}
678 678
 		}
679
-		if ( ! empty( $this->cache_group ) ) {
680
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
681
-			wp_cache_delete( $cache_key, $this->cache_group );
679
+		if (!empty($this->cache_group)) {
680
+			$cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id();
681
+			wp_cache_delete($cache_key, $this->cache_group);
682 682
 		}
683 683
 	}
684 684
 
@@ -688,8 +688,8 @@  discard block
 block discarded – undo
688 688
 	 * @since 1.0.19
689 689
 	 * @param int $id ID.
690 690
 	 */
691
-	public function set_id( $id ) {
692
-		$this->id = absint( $id );
691
+	public function set_id($id) {
692
+		$this->id = absint($id);
693 693
 	}
694 694
 
695 695
 	/**
@@ -699,10 +699,10 @@  discard block
 block discarded – undo
699 699
 	 * @param string $status New status.
700 700
 	 * @return array details of change.
701 701
 	 */
702
-	public function set_status( $status ) {
702
+	public function set_status($status) {
703 703
         $old_status = $this->get_status();
704 704
 
705
-		$this->set_prop( 'status', $status );
705
+		$this->set_prop('status', $status);
706 706
 
707 707
 		return array(
708 708
 			'from' => $old_status,
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
 	public function set_defaults() {
719 719
 		$this->data    = $this->default_data;
720 720
 		$this->changes = array();
721
-		$this->set_object_read( false );
721
+		$this->set_object_read(false);
722 722
 	}
723 723
 
724 724
 	/**
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
 	 * @since 1.0.19
728 728
 	 * @param boolean $read Should read?.
729 729
 	 */
730
-	public function set_object_read( $read = true ) {
730
+	public function set_object_read($read = true) {
731 731
 		$this->object_read = (bool) $read;
732 732
 	}
733 733
 
@@ -752,32 +752,32 @@  discard block
 block discarded – undo
752 752
 	 *
753 753
 	 * @return bool|WP_Error
754 754
 	 */
755
-	public function set_props( $props, $context = 'set' ) {
755
+	public function set_props($props, $context = 'set') {
756 756
 		$errors = false;
757 757
 
758
-		foreach ( $props as $prop => $value ) {
758
+		foreach ($props as $prop => $value) {
759 759
 			try {
760 760
 				/**
761 761
 				 * Checks if the prop being set is allowed, and the value is not null.
762 762
 				 */
763
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
763
+				if (is_null($value) || in_array($prop, array('prop', 'date_prop', 'meta_data'), true)) {
764 764
 					continue;
765 765
 				}
766 766
 				$setter = "set_$prop";
767 767
 
768
-				if ( is_callable( array( $this, $setter ) ) ) {
769
-					$this->{$setter}( $value );
768
+				if (is_callable(array($this, $setter))) {
769
+					$this->{$setter}($value);
770 770
 				}
771
-			} catch ( Exception $e ) {
772
-				if ( ! $errors ) {
771
+			} catch (Exception $e) {
772
+				if (!$errors) {
773 773
 					$errors = new WP_Error();
774 774
 				}
775
-				$errors->add( $e->getCode(), $e->getMessage() );
775
+				$errors->add($e->getCode(), $e->getMessage());
776 776
 				$this->last_error = $e->getMessage();
777 777
 			}
778 778
 		}
779 779
 
780
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
780
+		return $errors && count($errors->get_error_codes()) ? $errors : true;
781 781
 	}
782 782
 
783 783
 	/**
@@ -790,14 +790,14 @@  discard block
 block discarded – undo
790 790
 	 * @param string $prop Name of prop to set.
791 791
 	 * @param mixed  $value Value of the prop.
792 792
 	 */
793
-	protected function set_prop( $prop, $value ) {
794
-		if ( array_key_exists( $prop, $this->data ) ) {
795
-			if ( true === $this->object_read ) {
796
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
797
-					$this->changes[ $prop ] = $value;
793
+	protected function set_prop($prop, $value) {
794
+		if (array_key_exists($prop, $this->data)) {
795
+			if (true === $this->object_read) {
796
+				if ($value !== $this->data[$prop] || array_key_exists($prop, $this->changes)) {
797
+					$this->changes[$prop] = $value;
798 798
 				}
799 799
 			} else {
800
-				$this->data[ $prop ] = $value;
800
+				$this->data[$prop] = $value;
801 801
 			}
802 802
 		}
803 803
 	}
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
 	 * @since 1.0.19
819 819
 	 */
820 820
 	public function apply_changes() {
821
-		$this->data    = array_replace_recursive( $this->data, $this->changes );
821
+		$this->data    = array_replace_recursive($this->data, $this->changes);
822 822
 		$this->changes = array();
823 823
 	}
824 824
 
@@ -843,14 +843,14 @@  discard block
 block discarded – undo
843 843
 	 * @param  string $context What the value is for. Valid values are view and edit.
844 844
 	 * @return mixed
845 845
 	 */
846
-	protected function get_prop( $prop, $context = 'view' ) {
846
+	protected function get_prop($prop, $context = 'view') {
847 847
 		$value = null;
848 848
 
849
-		if ( array_key_exists( $prop, $this->data ) ) {
850
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
849
+		if (array_key_exists($prop, $this->data)) {
850
+			$value = array_key_exists($prop, $this->changes) ? $this->changes[$prop] : $this->data[$prop];
851 851
 
852
-			if ( 'view' === $context ) {
853
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
852
+			if ('view' === $context) {
853
+				$value = apply_filters($this->get_hook_prefix() . $prop, $value, $this);
854 854
 			}
855 855
 		}
856 856
 
@@ -864,13 +864,13 @@  discard block
 block discarded – undo
864 864
 	 * @param string         $prop Name of prop to set.
865 865
 	 * @param string|integer $value Value of the prop.
866 866
 	 */
867
-	protected function set_date_prop( $prop, $value ) {
867
+	protected function set_date_prop($prop, $value) {
868 868
 
869
-		if ( empty( $value ) ) {
870
-			$this->set_prop( $prop, null );
869
+		if (empty($value)) {
870
+			$this->set_prop($prop, null);
871 871
 			return;
872 872
 		}
873
-		$this->set_prop( $prop, $value );
873
+		$this->set_prop($prop, $value);
874 874
 
875 875
 	}
876 876
 
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
 	 * @param string $code             Error code.
882 882
 	 * @param string $message          Error message.
883 883
 	 */
884
-	protected function error( $code, $message ) {
884
+	protected function error($code, $message) {
885 885
 		$this->last_error = $message;
886 886
 	}
887 887
 
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
 	 */
894 894
 	public function exists() {
895 895
 		$id = $this->get_id();
896
-		return ! empty( $id );
896
+		return !empty($id);
897 897
 	}
898 898
 
899 899
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-invoice-data-store.php 2 patches
Indentation   +441 added lines, -441 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,510 +15,510 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP {
17 17
 
18
-	/**
19
-	 * Data stored in meta keys, but not considered "meta" for a discount.
20
-	 *
21
-	 * @since 1.0.19
22
-	 * @var array
23
-	 */
24
-	protected $internal_meta_keys = array(
25
-		'_wpinv_subscr_profile_id',
26
-		'_wpinv_taxes',
27
-		'_wpinv_fees',
28
-		'_wpinv_discounts',
29
-		'_wpinv_submission_id',
30
-		'_wpinv_payment_form',
31
-		'_wpinv_is_viewed',
32
-		'wpinv_email_cc',
33
-		'wpinv_template'
34
-	);
35
-
36
-	/**
37
-	 * A map of meta keys to data props.
38
-	 *
39
-	 * @since 1.0.19
40
-	 *
41
-	 * @var array
42
-	 */
43
-	protected $meta_key_to_props = array(
44
-		'_wpinv_subscr_profile_id' => 'subscription_id',
45
-		'_wpinv_taxes'             => 'taxes',
46
-		'_wpinv_fees'              => 'fees',
47
-		'_wpinv_discounts'         => 'discounts',
48
-		'_wpinv_submission_id'     => 'submission_id',
49
-		'_wpinv_payment_form'      => 'payment_form',
50
-		'_wpinv_is_viewed'         => 'is_viewed',
51
-		'wpinv_email_cc'           => 'email_cc',
52
-		'wpinv_template'           => 'template',
53
-	);
54
-
55
-	/**
56
-	 * A map of database fields to data props.
57
-	 *
58
-	 * @since 1.0.19
59
-	 *
60
-	 * @var array
61
-	 */
62
-	protected $database_fields_to_props = array(
63
-		'post_id'            => 'id',
64
-		'number'             => 'number',
65
-		'currency'           => 'currency',
66
-		'key'                => 'key',
67
-		'type'               => 'type',
68
-		'mode'               => 'mode',
69
-		'user_ip'            => 'user_ip',
70
-		'first_name'         => 'first_name',
71
-		'last_name'          => 'last_name',
72
-		'address'            => 'address',
73
-		'city'               => 'city',
74
-		'state'              => 'state',
75
-		'country'            => 'country',
76
-		'zip'                => 'zip',
77
-		'zip'                => 'zip',
78
-		'adddress_confirmed' => 'address_confirmed',
79
-		'gateway'            => 'gateway',
80
-		'transaction_id'     => 'transaction_id',
81
-		'currency'           => 'currency',
82
-		'subtotal'           => 'subtotal',
83
-		'tax'                => 'total_tax',
84
-		'fees_total'         => 'total_fees',
85
-		'discount'           => 'total_discount',
86
-		'total'              => 'total',
87
-		'discount_code'      => 'discount_code',
88
-		'disable_taxes'      => 'disable_taxes',
89
-		'due_date'           => 'due_date',
90
-		'completed_date'     => 'completed_date',
91
-		'company'            => 'company',
92
-		'vat_number'         => 'vat_number',
93
-		'vat_rate'           => 'vat_rate',
94
-	);
95
-
96
-	/*
18
+    /**
19
+     * Data stored in meta keys, but not considered "meta" for a discount.
20
+     *
21
+     * @since 1.0.19
22
+     * @var array
23
+     */
24
+    protected $internal_meta_keys = array(
25
+        '_wpinv_subscr_profile_id',
26
+        '_wpinv_taxes',
27
+        '_wpinv_fees',
28
+        '_wpinv_discounts',
29
+        '_wpinv_submission_id',
30
+        '_wpinv_payment_form',
31
+        '_wpinv_is_viewed',
32
+        'wpinv_email_cc',
33
+        'wpinv_template'
34
+    );
35
+
36
+    /**
37
+     * A map of meta keys to data props.
38
+     *
39
+     * @since 1.0.19
40
+     *
41
+     * @var array
42
+     */
43
+    protected $meta_key_to_props = array(
44
+        '_wpinv_subscr_profile_id' => 'subscription_id',
45
+        '_wpinv_taxes'             => 'taxes',
46
+        '_wpinv_fees'              => 'fees',
47
+        '_wpinv_discounts'         => 'discounts',
48
+        '_wpinv_submission_id'     => 'submission_id',
49
+        '_wpinv_payment_form'      => 'payment_form',
50
+        '_wpinv_is_viewed'         => 'is_viewed',
51
+        'wpinv_email_cc'           => 'email_cc',
52
+        'wpinv_template'           => 'template',
53
+    );
54
+
55
+    /**
56
+     * A map of database fields to data props.
57
+     *
58
+     * @since 1.0.19
59
+     *
60
+     * @var array
61
+     */
62
+    protected $database_fields_to_props = array(
63
+        'post_id'            => 'id',
64
+        'number'             => 'number',
65
+        'currency'           => 'currency',
66
+        'key'                => 'key',
67
+        'type'               => 'type',
68
+        'mode'               => 'mode',
69
+        'user_ip'            => 'user_ip',
70
+        'first_name'         => 'first_name',
71
+        'last_name'          => 'last_name',
72
+        'address'            => 'address',
73
+        'city'               => 'city',
74
+        'state'              => 'state',
75
+        'country'            => 'country',
76
+        'zip'                => 'zip',
77
+        'zip'                => 'zip',
78
+        'adddress_confirmed' => 'address_confirmed',
79
+        'gateway'            => 'gateway',
80
+        'transaction_id'     => 'transaction_id',
81
+        'currency'           => 'currency',
82
+        'subtotal'           => 'subtotal',
83
+        'tax'                => 'total_tax',
84
+        'fees_total'         => 'total_fees',
85
+        'discount'           => 'total_discount',
86
+        'total'              => 'total',
87
+        'discount_code'      => 'discount_code',
88
+        'disable_taxes'      => 'disable_taxes',
89
+        'due_date'           => 'due_date',
90
+        'completed_date'     => 'completed_date',
91
+        'company'            => 'company',
92
+        'vat_number'         => 'vat_number',
93
+        'vat_rate'           => 'vat_rate',
94
+    );
95
+
96
+    /*
97 97
 	|--------------------------------------------------------------------------
98 98
 	| CRUD Methods
99 99
 	|--------------------------------------------------------------------------
100 100
 	*/
101
-	/**
102
-	 * Method to create a new invoice in the database.
103
-	 *
104
-	 * @param WPInv_Invoice $invoice Invoice object.
105
-	 */
106
-	public function create( &$invoice ) {
107
-		$invoice->set_version( WPINV_VERSION );
108
-		$invoice->set_date_created( current_time('mysql') );
109
-
110
-		// Create a new post.
111
-		$id = wp_insert_post(
112
-			apply_filters(
113
-				'getpaid_new_invoice_data',
114
-				array(
115
-					'post_date'     => $invoice->get_date_created( 'edit' ),
116
-					'post_type'     => $invoice->get_post_type( 'edit' ),
117
-					'post_status'   => $this->get_post_status( $invoice ),
118
-					'ping_status'   => 'closed',
119
-					'post_author'   => $invoice->get_user_id( 'edit' ),
120
-					'post_title'    => $invoice->get_title( 'edit' ),
121
-					'post_excerpt'  => $invoice->get_description( 'edit' ),
122
-					'post_parent'   => $invoice->get_parent_id( 'edit' ),
123
-					'post_name'     => $invoice->get_path( 'edit' ),
124
-				)
125
-			),
126
-			true
127
-		);
128
-
129
-		if ( $id && ! is_wp_error( $id ) ) {
130
-
131
-			// Update the new id and regenerate a title.
132
-			$invoice->set_id( $id );
133
-			wp_update_post( array( 'ID' => $invoice->get_id(), 'post_title' => $invoice->get_number( 'edit' ) ) );
134
-
135
-			// Ensure both the key and number are set.
136
-			$invoice->get_key();
137
-			$invoice->get_number();
138
-
139
-			// Save special fields and items.
140
-			$this->save_special_fields( $invoice );
141
-			$this->save_items( $invoice );
142
-
143
-			// Update meta data.
144
-			$this->update_post_meta( $invoice );
145
-			$invoice->save_meta_data();
146
-
147
-			// Apply changes.
148
-			$invoice->apply_changes();
149
-			$this->clear_caches( $invoice );
150
-
151
-			// Fires after a new invoice is created.
152
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
153
-			return true;
154
-		}
155
-
156
-		if ( is_wp_error( $id ) ) {
157
-			$invoice->last_error = $id->get_error_message();
158
-		}
159
-
160
-		return false;
161
-	}
162
-
163
-	/**
164
-	 * Method to read an invoice from the database.
165
-	 *
166
-	 * @param WPInv_Invoice $invoice Invoice object.
167
-	 *
168
-	 */
169
-	public function read( &$invoice ) {
170
-
171
-		$invoice->set_defaults();
172
-		$invoice_object = get_post( $invoice->get_id() );
173
-
174
-		if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
175
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
176
-			$invoice->set_id( 0 );
177
-			return false;
178
-		}
179
-
180
-		$invoice->set_props(
181
-			array(
182
-				'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
183
-				'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
184
-				'status'        => $invoice_object->post_status,
185
-				'author'        => $invoice_object->post_author,
186
-				'description'   => $invoice_object->post_excerpt,
187
-				'parent_id'     => $invoice_object->post_parent,
188
-				'name'          => $invoice_object->post_title,
189
-				'path'          => $invoice_object->post_name,
190
-				'post_type'     => $invoice_object->post_type,
191
-			)
192
-		);
193
-
194
-		$invoice->set_type( $invoice_object->post_type );
195
-
196
-		$this->read_object_data( $invoice, $invoice_object );
197
-		$this->add_special_fields( $invoice );
198
-		$this->add_items( $invoice );
199
-		$invoice->read_meta_data();
200
-		$invoice->set_object_read( true );
201
-		do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice );
202
-
203
-	}
204
-
205
-	/**
206
-	 * Method to update an invoice in the database.
207
-	 *
208
-	 * @param WPInv_Invoice $invoice Invoice object.
209
-	 */
210
-	public function update( &$invoice ) {
211
-		$invoice->save_meta_data();
212
-		$invoice->set_version( WPINV_VERSION );
213
-
214
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
215
-			$invoice->set_date_created(  current_time('mysql') );
216
-		}
217
-
218
-		// Ensure both the key and number are set.
219
-		$invoice->get_key();
220
-		$invoice->get_number();
221
-
222
-		// Grab the current status so we can compare.
223
-		$previous_status = get_post_status( $invoice->get_id() );
224
-
225
-		$changes = $invoice->get_changes();
226
-
227
-		// Only update the post when the post data changes.
228
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
229
-			$post_data = array(
230
-				'post_date'         => $invoice->get_date_created( 'edit' ),
231
-				'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
232
-				'post_status'       => $invoice->get_status( 'edit' ),
233
-				'post_title'        => $invoice->get_name( 'edit' ),
234
-				'post_author'       => $invoice->get_user_id( 'edit' ),
235
-				'post_modified'     => $invoice->get_date_modified( 'edit' ),
236
-				'post_excerpt'      => $invoice->get_description( 'edit' ),
237
-				'post_parent'       => $invoice->get_parent_id( 'edit' ),
238
-				'post_name'         => $invoice->get_path( 'edit' ),
239
-				'post_type'         => $invoice->get_post_type( 'edit' ),
240
-			);
241
-
242
-			/**
243
-			 * When updating this object, to prevent infinite loops, use $wpdb
244
-			 * to update data, since wp_update_post spawns more calls to the
245
-			 * save_post action.
246
-			 *
247
-			 * This ensures hooks are fired by either WP itself (admin screen save),
248
-			 * or an update purely from CRUD.
249
-			 */
250
-			if ( doing_action( 'save_post' ) ) {
251
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
252
-				clean_post_cache( $invoice->get_id() );
253
-			} else {
254
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
255
-			}
256
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
257
-		}
258
-
259
-		// Update meta data.
260
-		$this->update_post_meta( $invoice );
261
-
262
-		// Save special fields and items.
263
-		$this->save_special_fields( $invoice );
264
-		$this->save_items( $invoice );
265
-
266
-		// Apply the changes.
267
-		$invoice->apply_changes();
268
-
269
-		// Clear caches.
270
-		$this->clear_caches( $invoice );
271
-
272
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
273
-		$new_status = $invoice->get_status( 'edit' );
274
-
275
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
276
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
277
-		} else {
278
-			do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice );
279
-		}
280
-
281
-	}
282
-
283
-	/*
101
+    /**
102
+     * Method to create a new invoice in the database.
103
+     *
104
+     * @param WPInv_Invoice $invoice Invoice object.
105
+     */
106
+    public function create( &$invoice ) {
107
+        $invoice->set_version( WPINV_VERSION );
108
+        $invoice->set_date_created( current_time('mysql') );
109
+
110
+        // Create a new post.
111
+        $id = wp_insert_post(
112
+            apply_filters(
113
+                'getpaid_new_invoice_data',
114
+                array(
115
+                    'post_date'     => $invoice->get_date_created( 'edit' ),
116
+                    'post_type'     => $invoice->get_post_type( 'edit' ),
117
+                    'post_status'   => $this->get_post_status( $invoice ),
118
+                    'ping_status'   => 'closed',
119
+                    'post_author'   => $invoice->get_user_id( 'edit' ),
120
+                    'post_title'    => $invoice->get_title( 'edit' ),
121
+                    'post_excerpt'  => $invoice->get_description( 'edit' ),
122
+                    'post_parent'   => $invoice->get_parent_id( 'edit' ),
123
+                    'post_name'     => $invoice->get_path( 'edit' ),
124
+                )
125
+            ),
126
+            true
127
+        );
128
+
129
+        if ( $id && ! is_wp_error( $id ) ) {
130
+
131
+            // Update the new id and regenerate a title.
132
+            $invoice->set_id( $id );
133
+            wp_update_post( array( 'ID' => $invoice->get_id(), 'post_title' => $invoice->get_number( 'edit' ) ) );
134
+
135
+            // Ensure both the key and number are set.
136
+            $invoice->get_key();
137
+            $invoice->get_number();
138
+
139
+            // Save special fields and items.
140
+            $this->save_special_fields( $invoice );
141
+            $this->save_items( $invoice );
142
+
143
+            // Update meta data.
144
+            $this->update_post_meta( $invoice );
145
+            $invoice->save_meta_data();
146
+
147
+            // Apply changes.
148
+            $invoice->apply_changes();
149
+            $this->clear_caches( $invoice );
150
+
151
+            // Fires after a new invoice is created.
152
+            do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
153
+            return true;
154
+        }
155
+
156
+        if ( is_wp_error( $id ) ) {
157
+            $invoice->last_error = $id->get_error_message();
158
+        }
159
+
160
+        return false;
161
+    }
162
+
163
+    /**
164
+     * Method to read an invoice from the database.
165
+     *
166
+     * @param WPInv_Invoice $invoice Invoice object.
167
+     *
168
+     */
169
+    public function read( &$invoice ) {
170
+
171
+        $invoice->set_defaults();
172
+        $invoice_object = get_post( $invoice->get_id() );
173
+
174
+        if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
175
+            $invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
176
+            $invoice->set_id( 0 );
177
+            return false;
178
+        }
179
+
180
+        $invoice->set_props(
181
+            array(
182
+                'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
183
+                'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
184
+                'status'        => $invoice_object->post_status,
185
+                'author'        => $invoice_object->post_author,
186
+                'description'   => $invoice_object->post_excerpt,
187
+                'parent_id'     => $invoice_object->post_parent,
188
+                'name'          => $invoice_object->post_title,
189
+                'path'          => $invoice_object->post_name,
190
+                'post_type'     => $invoice_object->post_type,
191
+            )
192
+        );
193
+
194
+        $invoice->set_type( $invoice_object->post_type );
195
+
196
+        $this->read_object_data( $invoice, $invoice_object );
197
+        $this->add_special_fields( $invoice );
198
+        $this->add_items( $invoice );
199
+        $invoice->read_meta_data();
200
+        $invoice->set_object_read( true );
201
+        do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice );
202
+
203
+    }
204
+
205
+    /**
206
+     * Method to update an invoice in the database.
207
+     *
208
+     * @param WPInv_Invoice $invoice Invoice object.
209
+     */
210
+    public function update( &$invoice ) {
211
+        $invoice->save_meta_data();
212
+        $invoice->set_version( WPINV_VERSION );
213
+
214
+        if ( null === $invoice->get_date_created( 'edit' ) ) {
215
+            $invoice->set_date_created(  current_time('mysql') );
216
+        }
217
+
218
+        // Ensure both the key and number are set.
219
+        $invoice->get_key();
220
+        $invoice->get_number();
221
+
222
+        // Grab the current status so we can compare.
223
+        $previous_status = get_post_status( $invoice->get_id() );
224
+
225
+        $changes = $invoice->get_changes();
226
+
227
+        // Only update the post when the post data changes.
228
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
229
+            $post_data = array(
230
+                'post_date'         => $invoice->get_date_created( 'edit' ),
231
+                'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
232
+                'post_status'       => $invoice->get_status( 'edit' ),
233
+                'post_title'        => $invoice->get_name( 'edit' ),
234
+                'post_author'       => $invoice->get_user_id( 'edit' ),
235
+                'post_modified'     => $invoice->get_date_modified( 'edit' ),
236
+                'post_excerpt'      => $invoice->get_description( 'edit' ),
237
+                'post_parent'       => $invoice->get_parent_id( 'edit' ),
238
+                'post_name'         => $invoice->get_path( 'edit' ),
239
+                'post_type'         => $invoice->get_post_type( 'edit' ),
240
+            );
241
+
242
+            /**
243
+             * When updating this object, to prevent infinite loops, use $wpdb
244
+             * to update data, since wp_update_post spawns more calls to the
245
+             * save_post action.
246
+             *
247
+             * This ensures hooks are fired by either WP itself (admin screen save),
248
+             * or an update purely from CRUD.
249
+             */
250
+            if ( doing_action( 'save_post' ) ) {
251
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
252
+                clean_post_cache( $invoice->get_id() );
253
+            } else {
254
+                wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
255
+            }
256
+            $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
257
+        }
258
+
259
+        // Update meta data.
260
+        $this->update_post_meta( $invoice );
261
+
262
+        // Save special fields and items.
263
+        $this->save_special_fields( $invoice );
264
+        $this->save_items( $invoice );
265
+
266
+        // Apply the changes.
267
+        $invoice->apply_changes();
268
+
269
+        // Clear caches.
270
+        $this->clear_caches( $invoice );
271
+
272
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
273
+        $new_status = $invoice->get_status( 'edit' );
274
+
275
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
276
+            do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
277
+        } else {
278
+            do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice );
279
+        }
280
+
281
+    }
282
+
283
+    /*
284 284
 	|--------------------------------------------------------------------------
285 285
 	| Additional Methods
286 286
 	|--------------------------------------------------------------------------
287 287
 	*/
288 288
 
289
-	/**
289
+    /**
290 290
      * Retrieves special fields and adds to the invoice.
291
-	 *
292
-	 * @param WPInv_Invoice $invoice Invoice object.
291
+     *
292
+     * @param WPInv_Invoice $invoice Invoice object.
293 293
      */
294 294
     public function add_special_fields( &$invoice ) {
295
-		global $wpdb;
295
+        global $wpdb;
296 296
 
297
-		// Maybe retrieve from the cache.
298
-		$data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
297
+        // Maybe retrieve from the cache.
298
+        $data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
299 299
 
300
-		// If not found, retrieve from the db.
301
-		if ( false === $data ) {
302
-			$table =  $wpdb->prefix . 'getpaid_invoices';
300
+        // If not found, retrieve from the db.
301
+        if ( false === $data ) {
302
+            $table =  $wpdb->prefix . 'getpaid_invoices';
303 303
 
304
-			$data  = $wpdb->get_row(
305
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
306
-				ARRAY_A
307
-			);
304
+            $data  = $wpdb->get_row(
305
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
306
+                ARRAY_A
307
+            );
308 308
 
309
-			// Update the cache with our data
310
-			wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
309
+            // Update the cache with our data
310
+            wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
311 311
 
312
-		}
312
+        }
313 313
 
314
-		// Abort if the data does not exist.
315
-		if ( empty( $data ) ) {
316
-			$invoice->set_object_read( true );
317
-			$invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
318
-			return;
319
-		}
314
+        // Abort if the data does not exist.
315
+        if ( empty( $data ) ) {
316
+            $invoice->set_object_read( true );
317
+            $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
318
+            return;
319
+        }
320 320
 
321
-		$props = array();
321
+        $props = array();
322 322
 
323
-		foreach ( $this->database_fields_to_props as $db_field => $prop ) {
323
+        foreach ( $this->database_fields_to_props as $db_field => $prop ) {
324 324
 			
325
-			if ( $db_field == 'post_id' ) {
326
-				continue;
327
-			}
328
-
329
-			$props[ $prop ] = $data[ $db_field ];
330
-		}
331
-
332
-		$invoice->set_props( $props );
333
-
334
-	}
335
-
336
-	/**
337
-	 * Gets a list of special fields that need updated based on change state
338
-	 * or if they are present in the database or not.
339
-	 *
340
-	 * @param  WPInv_Invoice $invoice       The Invoice object.
341
-	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
342
-	 */
343
-	protected function get_special_fields_to_update( $invoice ) {
344
-		$fields_to_update = array();
345
-		$changed_props   = $invoice->get_changes();
346
-
347
-		// Props should be updated if they are a part of the $changed array or don't exist yet.
348
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
349
-			if ( array_key_exists( $prop, $changed_props ) ) {
350
-				$fields_to_update[ $database_field ] = $prop;
351
-			}
352
-		}
353
-
354
-		return $fields_to_update;
355
-	}
356
-
357
-	/**
358
-	 * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
359
-	 *
360
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
361
-	 * @since 1.0.19
362
-	 */
363
-	protected function update_special_fields( &$invoice ) {
364
-		global $wpdb;
365
-
366
-		$updated_props    = array();
367
-		$fields_to_update = $this->get_special_fields_to_update( $invoice );
368
-
369
-		foreach ( $fields_to_update as $database_field => $prop ) {
370
-			$value = $invoice->{"get_$prop"}( 'edit' );
371
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
372
-			$value = is_bool( $value ) ? ( int ) $value : $value;
373
-			$updated_props[ $database_field ] = maybe_serialize( $value );
374
-		}
375
-
376
-		if ( ! empty( $updated_props ) ) {
377
-
378
-			$table = $wpdb->prefix . 'getpaid_invoices';
379
-			$wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
380
-			wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
381
-			do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
382
-
383
-		}
384
-
385
-	}
386
-
387
-	/**
388
-	 * Helper method that inserts special fields to the database.
389
-	 *
390
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
391
-	 * @since 1.0.19
392
-	 */
393
-	protected function insert_special_fields( &$invoice ) {
394
-		global $wpdb;
395
-
396
-		$updated_props   = array();
397
-
398
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
399
-			$value = $invoice->{"get_$prop"}( 'edit' );
400
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
401
-			$value = is_bool( $value ) ? ( int ) $value : $value;
402
-			$updated_props[ $database_field ] = maybe_serialize( $value );
403
-		}
404
-
405
-		$table = $wpdb->prefix . 'getpaid_invoices';
406
-		$wpdb->insert( $table, $updated_props );
407
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
408
-		do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
409
-
410
-	}
411
-
412
-	/**
325
+            if ( $db_field == 'post_id' ) {
326
+                continue;
327
+            }
328
+
329
+            $props[ $prop ] = $data[ $db_field ];
330
+        }
331
+
332
+        $invoice->set_props( $props );
333
+
334
+    }
335
+
336
+    /**
337
+     * Gets a list of special fields that need updated based on change state
338
+     * or if they are present in the database or not.
339
+     *
340
+     * @param  WPInv_Invoice $invoice       The Invoice object.
341
+     * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
342
+     */
343
+    protected function get_special_fields_to_update( $invoice ) {
344
+        $fields_to_update = array();
345
+        $changed_props   = $invoice->get_changes();
346
+
347
+        // Props should be updated if they are a part of the $changed array or don't exist yet.
348
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
349
+            if ( array_key_exists( $prop, $changed_props ) ) {
350
+                $fields_to_update[ $database_field ] = $prop;
351
+            }
352
+        }
353
+
354
+        return $fields_to_update;
355
+    }
356
+
357
+    /**
358
+     * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
359
+     *
360
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
361
+     * @since 1.0.19
362
+     */
363
+    protected function update_special_fields( &$invoice ) {
364
+        global $wpdb;
365
+
366
+        $updated_props    = array();
367
+        $fields_to_update = $this->get_special_fields_to_update( $invoice );
368
+
369
+        foreach ( $fields_to_update as $database_field => $prop ) {
370
+            $value = $invoice->{"get_$prop"}( 'edit' );
371
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
372
+            $value = is_bool( $value ) ? ( int ) $value : $value;
373
+            $updated_props[ $database_field ] = maybe_serialize( $value );
374
+        }
375
+
376
+        if ( ! empty( $updated_props ) ) {
377
+
378
+            $table = $wpdb->prefix . 'getpaid_invoices';
379
+            $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
380
+            wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
381
+            do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
382
+
383
+        }
384
+
385
+    }
386
+
387
+    /**
388
+     * Helper method that inserts special fields to the database.
389
+     *
390
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
391
+     * @since 1.0.19
392
+     */
393
+    protected function insert_special_fields( &$invoice ) {
394
+        global $wpdb;
395
+
396
+        $updated_props   = array();
397
+
398
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
399
+            $value = $invoice->{"get_$prop"}( 'edit' );
400
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
401
+            $value = is_bool( $value ) ? ( int ) $value : $value;
402
+            $updated_props[ $database_field ] = maybe_serialize( $value );
403
+        }
404
+
405
+        $table = $wpdb->prefix . 'getpaid_invoices';
406
+        $wpdb->insert( $table, $updated_props );
407
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
408
+        do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
409
+
410
+    }
411
+
412
+    /**
413 413
      * Saves all special fields.
414
-	 *
415
-	 * @param WPInv_Invoice $invoice Invoice object.
414
+     *
415
+     * @param WPInv_Invoice $invoice Invoice object.
416 416
      */
417 417
     public function save_special_fields( $invoice ) {
418
-		global $wpdb;
418
+        global $wpdb;
419 419
 
420
-		// The invoices table.
421
-		$table = $wpdb->prefix . 'getpaid_invoices';
422
-		$id    = (int) $invoice->get_id();
420
+        // The invoices table.
421
+        $table = $wpdb->prefix . 'getpaid_invoices';
422
+        $id    = (int) $invoice->get_id();
423 423
 
424
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
424
+        if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
425 425
 
426
-			$this->update_special_fields( $invoice );
426
+            $this->update_special_fields( $invoice );
427 427
 
428
-		} else {
428
+        } else {
429 429
 
430
-			$this->insert_special_fields( $invoice );
430
+            $this->insert_special_fields( $invoice );
431 431
 
432
-		}
432
+        }
433 433
 
434
-	}
434
+    }
435 435
 
436
-	/**
436
+    /**
437 437
      * Set's up cart details.
438
-	 *
439
-	 * @param WPInv_Invoice $invoice Invoice object.
438
+     *
439
+     * @param WPInv_Invoice $invoice Invoice object.
440 440
      */
441 441
     public function add_items( &$invoice ) {
442
-		global $wpdb;
442
+        global $wpdb;
443 443
 
444
-		// Maybe retrieve from the cache.
445
-		$items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
444
+        // Maybe retrieve from the cache.
445
+        $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
446 446
 
447
-		// If not found, retrieve from the db.
448
-		if ( false === $items ) {
449
-			$table =  $wpdb->prefix . 'getpaid_invoice_items';
447
+        // If not found, retrieve from the db.
448
+        if ( false === $items ) {
449
+            $table =  $wpdb->prefix . 'getpaid_invoice_items';
450 450
 
451
-			$items = $wpdb->get_results(
452
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
453
-			);
451
+            $items = $wpdb->get_results(
452
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
453
+            );
454 454
 
455
-			// Update the cache with our data
456
-			wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
455
+            // Update the cache with our data
456
+            wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
457 457
 
458
-		}
458
+        }
459 459
 
460
-		// Abort if no items found.
460
+        // Abort if no items found.
461 461
         if ( empty( $items ) ) {
462 462
             return;
463
-		}
463
+        }
464 464
 
465
-		foreach ( $items as $item_data ) {
466
-			$item = new GetPaid_Form_Item( $item_data->item_id );
465
+        foreach ( $items as $item_data ) {
466
+            $item = new GetPaid_Form_Item( $item_data->item_id );
467 467
 
468
-			// Set item data.
469
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
470
-			$item->item_discount = wpinv_sanitize_amount( $item_data->discount );
471
-			$item->set_name( $item_data->item_name );
472
-			$item->set_description( $item_data->item_description );
473
-			$item->set_price( $item_data->item_price );
474
-			$item->set_quantity( $item_data->quantity );
475
-			$item->set_item_meta( $item_data->meta );
468
+            // Set item data.
469
+            $item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
470
+            $item->item_discount = wpinv_sanitize_amount( $item_data->discount );
471
+            $item->set_name( $item_data->item_name );
472
+            $item->set_description( $item_data->item_description );
473
+            $item->set_price( $item_data->item_price );
474
+            $item->set_quantity( $item_data->quantity );
475
+            $item->set_item_meta( $item_data->meta );
476 476
 
477
-			$invoice->add_item( $item );
478
-		}
477
+            $invoice->add_item( $item );
478
+        }
479 479
 
480
-	}
480
+    }
481 481
 
482
-	/**
482
+    /**
483 483
      * Saves cart details.
484
-	 *
485
-	 * @param WPInv_Invoice $invoice Invoice object.
484
+     *
485
+     * @param WPInv_Invoice $invoice Invoice object.
486 486
      */
487 487
     public function save_items( $invoice ) {
488 488
 
489
-		// Delete previously existing items.
490
-		$this->delete_items( $invoice );
489
+        // Delete previously existing items.
490
+        $this->delete_items( $invoice );
491 491
 
492
-		$table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
492
+        $table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
493 493
 
494
-		foreach ( $invoice->get_cart_details() as $item_data ) {
495
-			$item_data = array_map( 'maybe_serialize', $item_data );
496
-			$GLOBALS['wpdb']->insert( $table, $item_data );
497
-		}
494
+        foreach ( $invoice->get_cart_details() as $item_data ) {
495
+            $item_data = array_map( 'maybe_serialize', $item_data );
496
+            $GLOBALS['wpdb']->insert( $table, $item_data );
497
+        }
498 498
 
499
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
500
-		do_action( "getpaid_invoice_save_items", $invoice );
499
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
500
+        do_action( "getpaid_invoice_save_items", $invoice );
501 501
 
502
-	}
502
+    }
503 503
 
504
-	/**
504
+    /**
505 505
      * Deletes an invoice's cart details from the database.
506
-	 *
507
-	 * @param WPInv_Invoice $invoice Invoice object.
506
+     *
507
+     * @param WPInv_Invoice $invoice Invoice object.
508 508
      */
509 509
     public function delete_items( $invoice ) {
510
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
511
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
512
-	}
510
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
511
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
512
+    }
513 513
 
514
-	/**
514
+    /**
515 515
      * Deletes an invoice's special fields from the database.
516
-	 *
517
-	 * @param WPInv_Invoice $invoice Invoice object.
516
+     *
517
+     * @param WPInv_Invoice $invoice Invoice object.
518 518
      */
519 519
     public function delete_special_fields( $invoice ) {
520
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
521
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
520
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
521
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
522 522
     }
523 523
 
524 524
 }
Please login to merge, or discard this patch.
Spacing   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * GetPaid_Invoice_Data_Store class file.
5 5
  *
6 6
  */
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
 	exit;
9 9
 }
10 10
 
@@ -103,57 +103,57 @@  discard block
 block discarded – undo
103 103
 	 *
104 104
 	 * @param WPInv_Invoice $invoice Invoice object.
105 105
 	 */
106
-	public function create( &$invoice ) {
107
-		$invoice->set_version( WPINV_VERSION );
108
-		$invoice->set_date_created( current_time('mysql') );
106
+	public function create(&$invoice) {
107
+		$invoice->set_version(WPINV_VERSION);
108
+		$invoice->set_date_created(current_time('mysql'));
109 109
 
110 110
 		// Create a new post.
111 111
 		$id = wp_insert_post(
112 112
 			apply_filters(
113 113
 				'getpaid_new_invoice_data',
114 114
 				array(
115
-					'post_date'     => $invoice->get_date_created( 'edit' ),
116
-					'post_type'     => $invoice->get_post_type( 'edit' ),
117
-					'post_status'   => $this->get_post_status( $invoice ),
115
+					'post_date'     => $invoice->get_date_created('edit'),
116
+					'post_type'     => $invoice->get_post_type('edit'),
117
+					'post_status'   => $this->get_post_status($invoice),
118 118
 					'ping_status'   => 'closed',
119
-					'post_author'   => $invoice->get_user_id( 'edit' ),
120
-					'post_title'    => $invoice->get_title( 'edit' ),
121
-					'post_excerpt'  => $invoice->get_description( 'edit' ),
122
-					'post_parent'   => $invoice->get_parent_id( 'edit' ),
123
-					'post_name'     => $invoice->get_path( 'edit' ),
119
+					'post_author'   => $invoice->get_user_id('edit'),
120
+					'post_title'    => $invoice->get_title('edit'),
121
+					'post_excerpt'  => $invoice->get_description('edit'),
122
+					'post_parent'   => $invoice->get_parent_id('edit'),
123
+					'post_name'     => $invoice->get_path('edit'),
124 124
 				)
125 125
 			),
126 126
 			true
127 127
 		);
128 128
 
129
-		if ( $id && ! is_wp_error( $id ) ) {
129
+		if ($id && !is_wp_error($id)) {
130 130
 
131 131
 			// Update the new id and regenerate a title.
132
-			$invoice->set_id( $id );
133
-			wp_update_post( array( 'ID' => $invoice->get_id(), 'post_title' => $invoice->get_number( 'edit' ) ) );
132
+			$invoice->set_id($id);
133
+			wp_update_post(array('ID' => $invoice->get_id(), 'post_title' => $invoice->get_number('edit')));
134 134
 
135 135
 			// Ensure both the key and number are set.
136 136
 			$invoice->get_key();
137 137
 			$invoice->get_number();
138 138
 
139 139
 			// Save special fields and items.
140
-			$this->save_special_fields( $invoice );
141
-			$this->save_items( $invoice );
140
+			$this->save_special_fields($invoice);
141
+			$this->save_items($invoice);
142 142
 
143 143
 			// Update meta data.
144
-			$this->update_post_meta( $invoice );
144
+			$this->update_post_meta($invoice);
145 145
 			$invoice->save_meta_data();
146 146
 
147 147
 			// Apply changes.
148 148
 			$invoice->apply_changes();
149
-			$this->clear_caches( $invoice );
149
+			$this->clear_caches($invoice);
150 150
 
151 151
 			// Fires after a new invoice is created.
152
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
152
+			do_action('getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice);
153 153
 			return true;
154 154
 		}
155 155
 
156
-		if ( is_wp_error( $id ) ) {
156
+		if (is_wp_error($id)) {
157 157
 			$invoice->last_error = $id->get_error_message();
158 158
 		}
159 159
 
@@ -166,14 +166,14 @@  discard block
 block discarded – undo
166 166
 	 * @param WPInv_Invoice $invoice Invoice object.
167 167
 	 *
168 168
 	 */
169
-	public function read( &$invoice ) {
169
+	public function read(&$invoice) {
170 170
 
171 171
 		$invoice->set_defaults();
172
-		$invoice_object = get_post( $invoice->get_id() );
172
+		$invoice_object = get_post($invoice->get_id());
173 173
 
174
-		if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
175
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
176
-			$invoice->set_id( 0 );
174
+		if (!$invoice->get_id() || !$invoice_object || !getpaid_is_invoice_post_type($invoice_object->post_type)) {
175
+			$invoice->last_error = __('Invalid invoice.', 'invoicing');
176
+			$invoice->set_id(0);
177 177
 			return false;
178 178
 		}
179 179
 
@@ -191,14 +191,14 @@  discard block
 block discarded – undo
191 191
 			)
192 192
 		);
193 193
 
194
-		$invoice->set_type( $invoice_object->post_type );
194
+		$invoice->set_type($invoice_object->post_type);
195 195
 
196
-		$this->read_object_data( $invoice, $invoice_object );
197
-		$this->add_special_fields( $invoice );
198
-		$this->add_items( $invoice );
196
+		$this->read_object_data($invoice, $invoice_object);
197
+		$this->add_special_fields($invoice);
198
+		$this->add_items($invoice);
199 199
 		$invoice->read_meta_data();
200
-		$invoice->set_object_read( true );
201
-		do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice );
200
+		$invoice->set_object_read(true);
201
+		do_action('getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice);
202 202
 
203 203
 	}
204 204
 
@@ -207,12 +207,12 @@  discard block
 block discarded – undo
207 207
 	 *
208 208
 	 * @param WPInv_Invoice $invoice Invoice object.
209 209
 	 */
210
-	public function update( &$invoice ) {
210
+	public function update(&$invoice) {
211 211
 		$invoice->save_meta_data();
212
-		$invoice->set_version( WPINV_VERSION );
212
+		$invoice->set_version(WPINV_VERSION);
213 213
 
214
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
215
-			$invoice->set_date_created(  current_time('mysql') );
214
+		if (null === $invoice->get_date_created('edit')) {
215
+			$invoice->set_date_created(current_time('mysql'));
216 216
 		}
217 217
 
218 218
 		// Ensure both the key and number are set.
@@ -220,23 +220,23 @@  discard block
 block discarded – undo
220 220
 		$invoice->get_number();
221 221
 
222 222
 		// Grab the current status so we can compare.
223
-		$previous_status = get_post_status( $invoice->get_id() );
223
+		$previous_status = get_post_status($invoice->get_id());
224 224
 
225 225
 		$changes = $invoice->get_changes();
226 226
 
227 227
 		// Only update the post when the post data changes.
228
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
228
+		if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path'), array_keys($changes))) {
229 229
 			$post_data = array(
230
-				'post_date'         => $invoice->get_date_created( 'edit' ),
231
-				'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
232
-				'post_status'       => $invoice->get_status( 'edit' ),
233
-				'post_title'        => $invoice->get_name( 'edit' ),
234
-				'post_author'       => $invoice->get_user_id( 'edit' ),
235
-				'post_modified'     => $invoice->get_date_modified( 'edit' ),
236
-				'post_excerpt'      => $invoice->get_description( 'edit' ),
237
-				'post_parent'       => $invoice->get_parent_id( 'edit' ),
238
-				'post_name'         => $invoice->get_path( 'edit' ),
239
-				'post_type'         => $invoice->get_post_type( 'edit' ),
230
+				'post_date'         => $invoice->get_date_created('edit'),
231
+				'post_date_gmt'     => $invoice->get_date_created_gmt('edit'),
232
+				'post_status'       => $invoice->get_status('edit'),
233
+				'post_title'        => $invoice->get_name('edit'),
234
+				'post_author'       => $invoice->get_user_id('edit'),
235
+				'post_modified'     => $invoice->get_date_modified('edit'),
236
+				'post_excerpt'      => $invoice->get_description('edit'),
237
+				'post_parent'       => $invoice->get_parent_id('edit'),
238
+				'post_name'         => $invoice->get_path('edit'),
239
+				'post_type'         => $invoice->get_post_type('edit'),
240 240
 			);
241 241
 
242 242
 			/**
@@ -247,35 +247,35 @@  discard block
 block discarded – undo
247 247
 			 * This ensures hooks are fired by either WP itself (admin screen save),
248 248
 			 * or an update purely from CRUD.
249 249
 			 */
250
-			if ( doing_action( 'save_post' ) ) {
251
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
252
-				clean_post_cache( $invoice->get_id() );
250
+			if (doing_action('save_post')) {
251
+				$GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $invoice->get_id()));
252
+				clean_post_cache($invoice->get_id());
253 253
 			} else {
254
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
254
+				wp_update_post(array_merge(array('ID' => $invoice->get_id()), $post_data));
255 255
 			}
256
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
256
+			$invoice->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
257 257
 		}
258 258
 
259 259
 		// Update meta data.
260
-		$this->update_post_meta( $invoice );
260
+		$this->update_post_meta($invoice);
261 261
 
262 262
 		// Save special fields and items.
263
-		$this->save_special_fields( $invoice );
264
-		$this->save_items( $invoice );
263
+		$this->save_special_fields($invoice);
264
+		$this->save_items($invoice);
265 265
 
266 266
 		// Apply the changes.
267 267
 		$invoice->apply_changes();
268 268
 
269 269
 		// Clear caches.
270
-		$this->clear_caches( $invoice );
270
+		$this->clear_caches($invoice);
271 271
 
272 272
 		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
273
-		$new_status = $invoice->get_status( 'edit' );
273
+		$new_status = $invoice->get_status('edit');
274 274
 
275
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
276
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
275
+		if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) {
276
+			do_action('getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice);
277 277
 		} else {
278
-			do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice );
278
+			do_action('getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice);
279 279
 		}
280 280
 
281 281
 	}
@@ -291,45 +291,45 @@  discard block
 block discarded – undo
291 291
 	 *
292 292
 	 * @param WPInv_Invoice $invoice Invoice object.
293 293
      */
294
-    public function add_special_fields( &$invoice ) {
294
+    public function add_special_fields(&$invoice) {
295 295
 		global $wpdb;
296 296
 
297 297
 		// Maybe retrieve from the cache.
298
-		$data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
298
+		$data = wp_cache_get($invoice->get_id(), 'getpaid_invoice_special_fields');
299 299
 
300 300
 		// If not found, retrieve from the db.
301
-		if ( false === $data ) {
302
-			$table =  $wpdb->prefix . 'getpaid_invoices';
301
+		if (false === $data) {
302
+			$table = $wpdb->prefix . 'getpaid_invoices';
303 303
 
304 304
 			$data  = $wpdb->get_row(
305
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
305
+				$wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id()),
306 306
 				ARRAY_A
307 307
 			);
308 308
 
309 309
 			// Update the cache with our data
310
-			wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
310
+			wp_cache_set($invoice->get_id(), $data, 'getpaid_invoice_special_fields');
311 311
 
312 312
 		}
313 313
 
314 314
 		// Abort if the data does not exist.
315
-		if ( empty( $data ) ) {
316
-			$invoice->set_object_read( true );
317
-			$invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
315
+		if (empty($data)) {
316
+			$invoice->set_object_read(true);
317
+			$invoice->set_props(wpinv_get_user_address($invoice->get_user_id()));
318 318
 			return;
319 319
 		}
320 320
 
321 321
 		$props = array();
322 322
 
323
-		foreach ( $this->database_fields_to_props as $db_field => $prop ) {
323
+		foreach ($this->database_fields_to_props as $db_field => $prop) {
324 324
 			
325
-			if ( $db_field == 'post_id' ) {
325
+			if ($db_field == 'post_id') {
326 326
 				continue;
327 327
 			}
328 328
 
329
-			$props[ $prop ] = $data[ $db_field ];
329
+			$props[$prop] = $data[$db_field];
330 330
 		}
331 331
 
332
-		$invoice->set_props( $props );
332
+		$invoice->set_props($props);
333 333
 
334 334
 	}
335 335
 
@@ -340,14 +340,14 @@  discard block
 block discarded – undo
340 340
 	 * @param  WPInv_Invoice $invoice       The Invoice object.
341 341
 	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
342 342
 	 */
343
-	protected function get_special_fields_to_update( $invoice ) {
343
+	protected function get_special_fields_to_update($invoice) {
344 344
 		$fields_to_update = array();
345
-		$changed_props   = $invoice->get_changes();
345
+		$changed_props = $invoice->get_changes();
346 346
 
347 347
 		// Props should be updated if they are a part of the $changed array or don't exist yet.
348
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
349
-			if ( array_key_exists( $prop, $changed_props ) ) {
350
-				$fields_to_update[ $database_field ] = $prop;
348
+		foreach ($this->database_fields_to_props as $database_field => $prop) {
349
+			if (array_key_exists($prop, $changed_props)) {
350
+				$fields_to_update[$database_field] = $prop;
351 351
 			}
352 352
 		}
353 353
 
@@ -360,25 +360,25 @@  discard block
 block discarded – undo
360 360
 	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
361 361
 	 * @since 1.0.19
362 362
 	 */
363
-	protected function update_special_fields( &$invoice ) {
363
+	protected function update_special_fields(&$invoice) {
364 364
 		global $wpdb;
365 365
 
366 366
 		$updated_props    = array();
367
-		$fields_to_update = $this->get_special_fields_to_update( $invoice );
367
+		$fields_to_update = $this->get_special_fields_to_update($invoice);
368 368
 
369
-		foreach ( $fields_to_update as $database_field => $prop ) {
370
-			$value = $invoice->{"get_$prop"}( 'edit' );
371
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
372
-			$value = is_bool( $value ) ? ( int ) $value : $value;
373
-			$updated_props[ $database_field ] = maybe_serialize( $value );
369
+		foreach ($fields_to_update as $database_field => $prop) {
370
+			$value = $invoice->{"get_$prop"}('edit');
371
+			$value = is_string($value) ? wp_slash($value) : $value;
372
+			$value = is_bool($value) ? (int) $value : $value;
373
+			$updated_props[$database_field] = maybe_serialize($value);
374 374
 		}
375 375
 
376
-		if ( ! empty( $updated_props ) ) {
376
+		if (!empty($updated_props)) {
377 377
 
378 378
 			$table = $wpdb->prefix . 'getpaid_invoices';
379
-			$wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
380
-			wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
381
-			do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
379
+			$wpdb->update($table, $updated_props, array('post_id' => $invoice->get_id()));
380
+			wp_cache_delete($invoice->get_id(), 'getpaid_invoice_special_fields');
381
+			do_action("getpaid_invoice_update_database_fields", $invoice, $updated_props);
382 382
 
383 383
 		}
384 384
 
@@ -390,22 +390,22 @@  discard block
 block discarded – undo
390 390
 	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
391 391
 	 * @since 1.0.19
392 392
 	 */
393
-	protected function insert_special_fields( &$invoice ) {
393
+	protected function insert_special_fields(&$invoice) {
394 394
 		global $wpdb;
395 395
 
396
-		$updated_props   = array();
396
+		$updated_props = array();
397 397
 
398
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
399
-			$value = $invoice->{"get_$prop"}( 'edit' );
400
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
401
-			$value = is_bool( $value ) ? ( int ) $value : $value;
402
-			$updated_props[ $database_field ] = maybe_serialize( $value );
398
+		foreach ($this->database_fields_to_props as $database_field => $prop) {
399
+			$value = $invoice->{"get_$prop"}('edit');
400
+			$value = is_string($value) ? wp_slash($value) : $value;
401
+			$value = is_bool($value) ? (int) $value : $value;
402
+			$updated_props[$database_field] = maybe_serialize($value);
403 403
 		}
404 404
 
405 405
 		$table = $wpdb->prefix . 'getpaid_invoices';
406
-		$wpdb->insert( $table, $updated_props );
407
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
408
-		do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
406
+		$wpdb->insert($table, $updated_props);
407
+		wp_cache_delete($invoice->get_id(), 'getpaid_invoice_special_fields');
408
+		do_action("getpaid_invoice_insert_database_fields", $invoice, $updated_props);
409 409
 
410 410
 	}
411 411
 
@@ -414,20 +414,20 @@  discard block
 block discarded – undo
414 414
 	 *
415 415
 	 * @param WPInv_Invoice $invoice Invoice object.
416 416
      */
417
-    public function save_special_fields( $invoice ) {
417
+    public function save_special_fields($invoice) {
418 418
 		global $wpdb;
419 419
 
420 420
 		// The invoices table.
421 421
 		$table = $wpdb->prefix . 'getpaid_invoices';
422 422
 		$id    = (int) $invoice->get_id();
423 423
 
424
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
424
+		if ($wpdb->get_var("SELECT `post_id` FROM $table WHERE `post_id`= $id")) {
425 425
 
426
-			$this->update_special_fields( $invoice );
426
+			$this->update_special_fields($invoice);
427 427
 
428 428
 		} else {
429 429
 
430
-			$this->insert_special_fields( $invoice );
430
+			$this->insert_special_fields($invoice);
431 431
 
432 432
 		}
433 433
 
@@ -438,43 +438,43 @@  discard block
 block discarded – undo
438 438
 	 *
439 439
 	 * @param WPInv_Invoice $invoice Invoice object.
440 440
      */
441
-    public function add_items( &$invoice ) {
441
+    public function add_items(&$invoice) {
442 442
 		global $wpdb;
443 443
 
444 444
 		// Maybe retrieve from the cache.
445
-		$items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
445
+		$items = wp_cache_get($invoice->get_id(), 'getpaid_invoice_cart_details');
446 446
 
447 447
 		// If not found, retrieve from the db.
448
-		if ( false === $items ) {
449
-			$table =  $wpdb->prefix . 'getpaid_invoice_items';
448
+		if (false === $items) {
449
+			$table = $wpdb->prefix . 'getpaid_invoice_items';
450 450
 
451 451
 			$items = $wpdb->get_results(
452
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
452
+				$wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id())
453 453
 			);
454 454
 
455 455
 			// Update the cache with our data
456
-			wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
456
+			wp_cache_set($invoice->get_id(), $items, 'getpaid_invoice_cart_details');
457 457
 
458 458
 		}
459 459
 
460 460
 		// Abort if no items found.
461
-        if ( empty( $items ) ) {
461
+        if (empty($items)) {
462 462
             return;
463 463
 		}
464 464
 
465
-		foreach ( $items as $item_data ) {
466
-			$item = new GetPaid_Form_Item( $item_data->item_id );
465
+		foreach ($items as $item_data) {
466
+			$item = new GetPaid_Form_Item($item_data->item_id);
467 467
 
468 468
 			// Set item data.
469
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
470
-			$item->item_discount = wpinv_sanitize_amount( $item_data->discount );
471
-			$item->set_name( $item_data->item_name );
472
-			$item->set_description( $item_data->item_description );
473
-			$item->set_price( $item_data->item_price );
474
-			$item->set_quantity( $item_data->quantity );
475
-			$item->set_item_meta( $item_data->meta );
476
-
477
-			$invoice->add_item( $item );
469
+			$item->item_tax      = wpinv_sanitize_amount($item_data->tax);
470
+			$item->item_discount = wpinv_sanitize_amount($item_data->discount);
471
+			$item->set_name($item_data->item_name);
472
+			$item->set_description($item_data->item_description);
473
+			$item->set_price($item_data->item_price);
474
+			$item->set_quantity($item_data->quantity);
475
+			$item->set_item_meta($item_data->meta);
476
+
477
+			$invoice->add_item($item);
478 478
 		}
479 479
 
480 480
 	}
@@ -484,20 +484,20 @@  discard block
 block discarded – undo
484 484
 	 *
485 485
 	 * @param WPInv_Invoice $invoice Invoice object.
486 486
      */
487
-    public function save_items( $invoice ) {
487
+    public function save_items($invoice) {
488 488
 
489 489
 		// Delete previously existing items.
490
-		$this->delete_items( $invoice );
490
+		$this->delete_items($invoice);
491 491
 
492
-		$table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
492
+		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
493 493
 
494
-		foreach ( $invoice->get_cart_details() as $item_data ) {
495
-			$item_data = array_map( 'maybe_serialize', $item_data );
496
-			$GLOBALS['wpdb']->insert( $table, $item_data );
494
+		foreach ($invoice->get_cart_details() as $item_data) {
495
+			$item_data = array_map('maybe_serialize', $item_data);
496
+			$GLOBALS['wpdb']->insert($table, $item_data);
497 497
 		}
498 498
 
499
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
500
-		do_action( "getpaid_invoice_save_items", $invoice );
499
+		wp_cache_delete($invoice->get_id(), 'getpaid_invoice_cart_details');
500
+		do_action("getpaid_invoice_save_items", $invoice);
501 501
 
502 502
 	}
503 503
 
@@ -506,9 +506,9 @@  discard block
 block discarded – undo
506 506
 	 *
507 507
 	 * @param WPInv_Invoice $invoice Invoice object.
508 508
      */
509
-    public function delete_items( $invoice ) {
510
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
511
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
509
+    public function delete_items($invoice) {
510
+		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
511
+		return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id()));
512 512
 	}
513 513
 
514 514
 	/**
@@ -516,9 +516,9 @@  discard block
 block discarded – undo
516 516
 	 *
517 517
 	 * @param WPInv_Invoice $invoice Invoice object.
518 518
      */
519
-    public function delete_special_fields( $invoice ) {
520
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
521
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
519
+    public function delete_special_fields($invoice) {
520
+		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
521
+		return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id()));
522 522
     }
523 523
 
524 524
 }
Please login to merge, or discard this patch.
includes/error-functions.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Returns the errors as html
@@ -14,27 +14,27 @@  discard block
 block discarded – undo
14 14
  * @param clear whether or not to clear the errors.
15 15
  * @since  1.0.19
16 16
  */
17
-function getpaid_get_errors_html( $clear = true ) {
17
+function getpaid_get_errors_html($clear = true) {
18 18
 
19 19
     $errors = '';
20
-    foreach ( wpinv_get_errors() as $error_id => $error ) {
21
-        $type     = 'error';
20
+    foreach (wpinv_get_errors() as $error_id => $error) {
21
+        $type = 'error';
22 22
 
23
-        if ( is_array( $error ) ) {
23
+        if (is_array($error)) {
24 24
             $type  = $error['type'];
25 25
             $error = $error['text'];
26 26
         }
27 27
 
28 28
         $errors .= aui()->alert(
29 29
             array(
30
-                'content'     => wp_kses_post( $error ),
30
+                'content'     => wp_kses_post($error),
31 31
                 'type'        => $type,
32 32
             )
33 33
         );
34 34
 
35 35
     }
36 36
 
37
-    if ( $clear ){
37
+    if ($clear) {
38 38
         wpinv_clear_errors();
39 39
     }
40 40
 
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
  * @return array
56 56
  */
57 57
 function wpinv_get_errors() {
58
-    $errors = getpaid_session()->get( 'wpinv_errors' );
59
-    return is_array( $errors ) ? $errors : array();
58
+    $errors = getpaid_session()->get('wpinv_errors');
59
+    return is_array($errors) ? $errors : array();
60 60
 }
61 61
 
62 62
 /**
@@ -66,15 +66,15 @@  discard block
 block discarded – undo
66 66
  * @param string $error_message The error message.
67 67
  * @param string $type Either error, info, warning, primary, dark, light or success.
68 68
  */
69
-function wpinv_set_error( $error_id, $error_message, $type = 'error' ) {
69
+function wpinv_set_error($error_id, $error_message, $type = 'error') {
70 70
 
71 71
     $errors              = wpinv_get_errors();
72
-    $errors[ $error_id ] = array(
72
+    $errors[$error_id] = array(
73 73
         'type' =>  $type,
74 74
         'text' =>  $error_message,
75 75
     );
76 76
 
77
-    getpaid()->session->set( 'wpinv_errors', $errors );
77
+    getpaid()->session->set('wpinv_errors', $errors);
78 78
 }
79 79
 
80 80
 /**
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
  * 
83 83
  */
84 84
 function wpinv_has_errors() {
85
-    return count( wpinv_get_errors() ) > 0;
85
+    return count(wpinv_get_errors()) > 0;
86 86
 }
87 87
 
88 88
 /**
@@ -90,21 +90,21 @@  discard block
 block discarded – undo
90 90
  * 
91 91
  */
92 92
 function wpinv_clear_errors() {
93
-    getpaid_session()->set( 'wpinv_errors', null );
93
+    getpaid_session()->set('wpinv_errors', null);
94 94
 }
95 95
 
96 96
 /**
97 97
  * Clears a single error.
98 98
  * 
99 99
  */
100
-function wpinv_unset_error( $error_id ) {
100
+function wpinv_unset_error($error_id) {
101 101
     $errors = wpinv_get_errors();
102 102
 
103
-    if ( isset( $errors[ $error_id ] ) ) {
104
-        unset( $errors[ $error_id ] );
103
+    if (isset($errors[$error_id])) {
104
+        unset($errors[$error_id]);
105 105
     }
106 106
 
107
-    getpaid_session()->set( 'wpinv_errors', $errors );
107
+    getpaid_session()->set('wpinv_errors', $errors);
108 108
 }
109 109
 
110 110
 /**
@@ -115,15 +115,15 @@  discard block
 block discarded – undo
115 115
  * @param string $message Message to log.
116 116
  * @param string $version Version the message was added in.
117 117
  */
118
-function getpaid_doing_it_wrong( $function, $message, $version ) {
118
+function getpaid_doing_it_wrong($function, $message, $version) {
119 119
 
120 120
 	$message .= ' Backtrace: ' . wp_debug_backtrace_summary();
121 121
 
122
-	if ( is_ajax() || defined( 'REST_REQUEST' ) ) {
123
-		do_action( 'doing_it_wrong_run', $function, $message, $version );
124
-		error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." );
122
+	if (is_ajax() || defined('REST_REQUEST')) {
123
+		do_action('doing_it_wrong_run', $function, $message, $version);
124
+		error_log("{$function} was called incorrectly. {$message}. This message was added in version {$version}.");
125 125
 	} else {
126
-		_doing_it_wrong( $function, $message, $version );
126
+		_doing_it_wrong($function, $message, $version);
127 127
 	}
128 128
 
129 129
 }
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 1 patch
Spacing   +533 added lines, -533 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, watermark, 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
-    return 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
+    return 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,56 +170,56 @@  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
 	$templates[] = $slug . '.php';
185 185
 
186 186
 	// Allow template parts to be filtered
187
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
187
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
188 188
 
189 189
 	// Return the part that is found
190
-	return wpinv_locate_tmpl( $templates, $load, false );
190
+	return wpinv_locate_tmpl($templates, $load, false);
191 191
 }
192 192
 
193
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
193
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
194 194
 	// No file found yet
195 195
 	$located = false;
196 196
 
197 197
 	// Try to find a template file
198
-	foreach ( (array)$template_names as $template_name ) {
198
+	foreach ((array) $template_names as $template_name) {
199 199
 
200 200
 		// Continue if template is empty
201
-		if ( empty( $template_name ) )
201
+		if (empty($template_name))
202 202
 			continue;
203 203
 
204 204
 		// Trim off any slashes from the template name
205
-		$template_name = ltrim( $template_name, '/' );
205
+		$template_name = ltrim($template_name, '/');
206 206
 
207 207
 		// try locating this template file by looping through the template paths
208
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
208
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
209 209
 
210
-			if( file_exists( $template_path . $template_name ) ) {
210
+			if (file_exists($template_path . $template_name)) {
211 211
 				$located = $template_path . $template_name;
212 212
 				break;
213 213
 			}
214 214
 		}
215 215
 
216
-		if( !empty( $located ) ) {
216
+		if (!empty($located)) {
217 217
 			break;
218 218
 		}
219 219
 	}
220 220
 
221
-	if ( ( true == $load ) && ! empty( $located ) )
222
-		load_template( $located, $require_once );
221
+	if ((true == $load) && !empty($located))
222
+		load_template($located, $require_once);
223 223
 
224 224
 	return $located;
225 225
 }
@@ -228,155 +228,155 @@  discard block
 block discarded – undo
228 228
 	$template_dir = wpinv_get_theme_template_dir_name();
229 229
 
230 230
 	$file_paths = array(
231
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
232
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
231
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
232
+		10 => trailingslashit(get_template_directory()) . $template_dir,
233 233
 		100 => wpinv_get_templates_dir()
234 234
 	);
235 235
 
236
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
236
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
237 237
 
238 238
 	// sort the file paths based on priority
239
-	ksort( $file_paths, SORT_NUMERIC );
239
+	ksort($file_paths, SORT_NUMERIC);
240 240
 
241
-	return array_map( 'trailingslashit', $file_paths );
241
+	return array_map('trailingslashit', $file_paths);
242 242
 }
243 243
 
244 244
 function wpinv_checkout_meta_tags() {
245 245
 
246 246
 	$pages   = array();
247
-	$pages[] = wpinv_get_option( 'success_page' );
248
-	$pages[] = wpinv_get_option( 'failure_page' );
249
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
250
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
247
+	$pages[] = wpinv_get_option('success_page');
248
+	$pages[] = wpinv_get_option('failure_page');
249
+	$pages[] = wpinv_get_option('invoice_history_page');
250
+	$pages[] = wpinv_get_option('invoice_subscription_page');
251 251
 
252
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
252
+	if (!wpinv_is_checkout() && !is_page($pages)) {
253 253
 		return;
254 254
 	}
255 255
 
256 256
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
257 257
 }
258
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
258
+add_action('wp_head', 'wpinv_checkout_meta_tags');
259 259
 
260
-function wpinv_add_body_classes( $class ) {
261
-	$classes = (array)$class;
260
+function wpinv_add_body_classes($class) {
261
+	$classes = (array) $class;
262 262
 
263
-	if( wpinv_is_checkout() ) {
263
+	if (wpinv_is_checkout()) {
264 264
 		$classes[] = 'wpinv-checkout';
265 265
 		$classes[] = 'wpinv-page';
266 266
 	}
267 267
 
268
-	if( wpinv_is_success_page() ) {
268
+	if (wpinv_is_success_page()) {
269 269
 		$classes[] = 'wpinv-success';
270 270
 		$classes[] = 'wpinv-page';
271 271
 	}
272 272
 
273
-	if( wpinv_is_failed_transaction_page() ) {
273
+	if (wpinv_is_failed_transaction_page()) {
274 274
 		$classes[] = 'wpinv-failed-transaction';
275 275
 		$classes[] = 'wpinv-page';
276 276
 	}
277 277
 
278
-	if( wpinv_is_invoice_history_page() ) {
278
+	if (wpinv_is_invoice_history_page()) {
279 279
 		$classes[] = 'wpinv-history';
280 280
 		$classes[] = 'wpinv-page';
281 281
 	}
282 282
 
283
-	if( wpinv_is_subscriptions_history_page() ) {
283
+	if (wpinv_is_subscriptions_history_page()) {
284 284
 		$classes[] = 'wpinv-subscription';
285 285
 		$classes[] = 'wpinv-page';
286 286
 	}
287 287
 
288
-	if( wpinv_is_test_mode() ) {
288
+	if (wpinv_is_test_mode()) {
289 289
 		$classes[] = 'wpinv-test-mode';
290 290
 		$classes[] = 'wpinv-page';
291 291
 	}
292 292
 
293
-	return array_unique( $classes );
293
+	return array_unique($classes);
294 294
 }
295
-add_filter( 'body_class', 'wpinv_add_body_classes' );
295
+add_filter('body_class', 'wpinv_add_body_classes');
296 296
 
297
-function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) {
298
-    $args = array( 'nopaging' => true );
297
+function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') {
298
+    $args = array('nopaging' => true);
299 299
 
300
-    if ( ! empty( $status ) )
300
+    if (!empty($status))
301 301
         $args['post_status'] = $status;
302 302
 
303
-    $discounts = wpinv_get_discounts( $args );
303
+    $discounts = wpinv_get_discounts($args);
304 304
     $options   = array();
305 305
 
306
-    if ( $discounts ) {
307
-        foreach ( $discounts as $discount ) {
308
-            $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) );
306
+    if ($discounts) {
307
+        foreach ($discounts as $discount) {
308
+            $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID));
309 309
         }
310 310
     } else {
311
-        $options[0] = __( 'No discounts found', 'invoicing' );
311
+        $options[0] = __('No discounts found', 'invoicing');
312 312
     }
313 313
 
314
-    $output = wpinv_html_select( array(
314
+    $output = wpinv_html_select(array(
315 315
         'name'             => $name,
316 316
         'selected'         => $selected,
317 317
         'options'          => $options,
318 318
         'show_option_all'  => false,
319 319
         'show_option_none' => false,
320
-    ) );
320
+    ));
321 321
 
322 322
     return $output;
323 323
 }
324 324
 
325
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
326
-    $current     = date( 'Y' );
327
-    $start_year  = $current - absint( $years_before );
328
-    $end_year    = $current + absint( $years_after );
329
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
325
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
326
+    $current     = date('Y');
327
+    $start_year  = $current - absint($years_before);
328
+    $end_year    = $current + absint($years_after);
329
+    $selected    = empty($selected) ? date('Y') : $selected;
330 330
     $options     = array();
331 331
 
332
-    while ( $start_year <= $end_year ) {
333
-        $options[ absint( $start_year ) ] = $start_year;
332
+    while ($start_year <= $end_year) {
333
+        $options[absint($start_year)] = $start_year;
334 334
         $start_year++;
335 335
     }
336 336
 
337
-    $output = wpinv_html_select( array(
337
+    $output = wpinv_html_select(array(
338 338
         'name'             => $name,
339 339
         'selected'         => $selected,
340 340
         'options'          => $options,
341 341
         'show_option_all'  => false,
342 342
         'show_option_none' => false
343
-    ) );
343
+    ));
344 344
 
345 345
     return $output;
346 346
 }
347 347
 
348
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
348
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
349 349
 
350 350
     $options = array(
351
-        '1'  => __( 'January', 'invoicing' ),
352
-        '2'  => __( 'February', 'invoicing' ),
353
-        '3'  => __( 'March', 'invoicing' ),
354
-        '4'  => __( 'April', 'invoicing' ),
355
-        '5'  => __( 'May', 'invoicing' ),
356
-        '6'  => __( 'June', 'invoicing' ),
357
-        '7'  => __( 'July', 'invoicing' ),
358
-        '8'  => __( 'August', 'invoicing' ),
359
-        '9'  => __( 'September', 'invoicing' ),
360
-        '10' => __( 'October', 'invoicing' ),
361
-        '11' => __( 'November', 'invoicing' ),
362
-        '12' => __( 'December', 'invoicing' ),
351
+        '1'  => __('January', 'invoicing'),
352
+        '2'  => __('February', 'invoicing'),
353
+        '3'  => __('March', 'invoicing'),
354
+        '4'  => __('April', 'invoicing'),
355
+        '5'  => __('May', 'invoicing'),
356
+        '6'  => __('June', 'invoicing'),
357
+        '7'  => __('July', 'invoicing'),
358
+        '8'  => __('August', 'invoicing'),
359
+        '9'  => __('September', 'invoicing'),
360
+        '10' => __('October', 'invoicing'),
361
+        '11' => __('November', 'invoicing'),
362
+        '12' => __('December', 'invoicing'),
363 363
     );
364 364
 
365 365
     // If no month is selected, default to the current month
366
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
366
+    $selected = empty($selected) ? date('n') : $selected;
367 367
 
368
-    $output = wpinv_html_select( array(
368
+    $output = wpinv_html_select(array(
369 369
         'name'             => $name,
370 370
         'selected'         => $selected,
371 371
         'options'          => $options,
372 372
         'show_option_all'  => false,
373 373
         'show_option_none' => false
374
-    ) );
374
+    ));
375 375
 
376 376
     return $output;
377 377
 }
378 378
 
379
-function wpinv_html_select( $args = array() ) {
379
+function wpinv_html_select($args = array()) {
380 380
     $defaults = array(
381 381
         'options'          => array(),
382 382
         'name'             => null,
@@ -385,8 +385,8 @@  discard block
 block discarded – undo
385 385
         'selected'         => 0,
386 386
         'placeholder'      => null,
387 387
         'multiple'         => false,
388
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
389
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
388
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
389
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
390 390
         'data'             => array(),
391 391
         'onchange'         => null,
392 392
         'required'         => false,
@@ -394,74 +394,74 @@  discard block
 block discarded – undo
394 394
         'readonly'         => false,
395 395
     );
396 396
 
397
-    $args = wp_parse_args( $args, $defaults );
397
+    $args = wp_parse_args($args, $defaults);
398 398
 
399 399
     $data_elements = '';
400
-    foreach ( $args['data'] as $key => $value ) {
401
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
400
+    foreach ($args['data'] as $key => $value) {
401
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
402 402
     }
403 403
 
404
-    if( $args['multiple'] ) {
404
+    if ($args['multiple']) {
405 405
         $multiple = ' MULTIPLE';
406 406
     } else {
407 407
         $multiple = '';
408 408
     }
409 409
 
410
-    if( $args['placeholder'] ) {
410
+    if ($args['placeholder']) {
411 411
         $placeholder = $args['placeholder'];
412 412
     } else {
413 413
         $placeholder = '';
414 414
     }
415 415
     
416 416
     $options = '';
417
-    if( !empty( $args['onchange'] ) ) {
418
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
417
+    if (!empty($args['onchange'])) {
418
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
419 419
     }
420 420
     
421
-    if( !empty( $args['required'] ) ) {
421
+    if (!empty($args['required'])) {
422 422
         $options .= ' required="required"';
423 423
     }
424 424
     
425
-    if( !empty( $args['disabled'] ) ) {
425
+    if (!empty($args['disabled'])) {
426 426
         $options .= ' disabled';
427 427
     }
428 428
     
429
-    if( !empty( $args['readonly'] ) ) {
429
+    if (!empty($args['readonly'])) {
430 430
         $options .= ' readonly';
431 431
     }
432 432
 
433
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
434
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
433
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
434
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
435 435
 
436
-    if ( $args['show_option_all'] ) {
437
-        if( $args['multiple'] ) {
438
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
436
+    if ($args['show_option_all']) {
437
+        if ($args['multiple']) {
438
+            $selected = selected(true, in_array(0, $args['selected']), false);
439 439
         } else {
440
-            $selected = selected( $args['selected'], 0, false );
440
+            $selected = selected($args['selected'], 0, false);
441 441
         }
442
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
442
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
443 443
     }
444 444
 
445
-    if ( !empty( $args['options'] ) ) {
445
+    if (!empty($args['options'])) {
446 446
 
447
-        if ( $args['show_option_none'] ) {
448
-            if( $args['multiple'] ) {
449
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
447
+        if ($args['show_option_none']) {
448
+            if ($args['multiple']) {
449
+                $selected = selected(true, in_array("", $args['selected']), false);
450 450
             } else {
451
-                $selected = selected( $args['selected'] === "", true, false );
451
+                $selected = selected($args['selected'] === "", true, false);
452 452
             }
453
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
453
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
454 454
         }
455 455
 
456
-        foreach( $args['options'] as $key => $option ) {
456
+        foreach ($args['options'] as $key => $option) {
457 457
 
458
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
459
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
458
+            if ($args['multiple'] && is_array($args['selected'])) {
459
+                $selected = selected(true, (bool) in_array($key, $args['selected']), false);
460 460
             } else {
461
-                $selected = selected( $args['selected'], $key, false );
461
+                $selected = selected($args['selected'], $key, false);
462 462
             }
463 463
 
464
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
464
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
465 465
         }
466 466
     }
467 467
 
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
     return $output;
471 471
 }
472 472
 
473
-function wpinv_item_dropdown( $args = array() ) {
473
+function wpinv_item_dropdown($args = array()) {
474 474
     $defaults = array(
475 475
         'name'              => 'wpi_item',
476 476
         'id'                => 'wpi_item',
@@ -478,14 +478,14 @@  discard block
 block discarded – undo
478 478
         'multiple'          => false,
479 479
         'selected'          => 0,
480 480
         'number'            => 100,
481
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
482
-        'data'              => array( 'search-type' => 'item' ),
481
+        'placeholder'       => __('Choose a item', 'invoicing'),
482
+        'data'              => array('search-type' => 'item'),
483 483
         'show_option_all'   => false,
484 484
         'show_option_none'  => false,
485 485
         'show_recurring'    => false,
486 486
     );
487 487
 
488
-    $args = wp_parse_args( $args, $defaults );
488
+    $args = wp_parse_args($args, $defaults);
489 489
 
490 490
     $item_args = array(
491 491
         'post_type'      => 'wpi_item',
@@ -494,44 +494,44 @@  discard block
 block discarded – undo
494 494
         'posts_per_page' => $args['number']
495 495
     );
496 496
 
497
-    $item_args  = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults );
497
+    $item_args  = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults);
498 498
 
499
-    $items      = get_posts( $item_args );
499
+    $items      = get_posts($item_args);
500 500
     $options    = array();
501
-    if ( $items ) {
502
-        foreach ( $items as $item ) {
503
-            $title = esc_html( $item->post_title );
501
+    if ($items) {
502
+        foreach ($items as $item) {
503
+            $title = esc_html($item->post_title);
504 504
             
505
-            if ( !empty( $args['show_recurring'] ) ) {
506
-                $title .= wpinv_get_item_suffix( $item->ID, false );
505
+            if (!empty($args['show_recurring'])) {
506
+                $title .= wpinv_get_item_suffix($item->ID, false);
507 507
             }
508 508
             
509
-            $options[ absint( $item->ID ) ] = $title;
509
+            $options[absint($item->ID)] = $title;
510 510
         }
511 511
     }
512 512
 
513 513
     // This ensures that any selected items are included in the drop down
514
-    if( is_array( $args['selected'] ) ) {
515
-        foreach( $args['selected'] as $item ) {
516
-            if( ! in_array( $item, $options ) ) {
517
-                $title = get_the_title( $item );
518
-                if ( !empty( $args['show_recurring'] ) ) {
519
-                    $title .= wpinv_get_item_suffix( $item, false );
514
+    if (is_array($args['selected'])) {
515
+        foreach ($args['selected'] as $item) {
516
+            if (!in_array($item, $options)) {
517
+                $title = get_the_title($item);
518
+                if (!empty($args['show_recurring'])) {
519
+                    $title .= wpinv_get_item_suffix($item, false);
520 520
                 }
521 521
                 $options[$item] = $title;
522 522
             }
523 523
         }
524
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
525
-        if ( ! in_array( $args['selected'], $options ) ) {
526
-            $title = get_the_title( $args['selected'] );
527
-            if ( !empty( $args['show_recurring'] ) ) {
528
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
524
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
525
+        if (!in_array($args['selected'], $options)) {
526
+            $title = get_the_title($args['selected']);
527
+            if (!empty($args['show_recurring'])) {
528
+                $title .= wpinv_get_item_suffix($args['selected'], false);
529 529
             }
530
-            $options[$args['selected']] = get_the_title( $args['selected'] );
530
+            $options[$args['selected']] = get_the_title($args['selected']);
531 531
         }
532 532
     }
533 533
 
534
-    $output = wpinv_html_select( array(
534
+    $output = wpinv_html_select(array(
535 535
         'name'             => $args['name'],
536 536
         'selected'         => $args['selected'],
537 537
         'id'               => $args['id'],
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
         'show_option_all'  => $args['show_option_all'],
543 543
         'show_option_none' => $args['show_option_none'],
544 544
         'data'             => $args['data'],
545
-    ) );
545
+    ));
546 546
 
547 547
     return $output;
548 548
 }
@@ -562,16 +562,16 @@  discard block
 block discarded – undo
562 562
     );
563 563
 
564 564
     $options = array();
565
-    if ( $items ) {
566
-        foreach ( $items as $item ) {
567
-            $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false );
565
+    if ($items) {
566
+        foreach ($items as $item) {
567
+            $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false);
568 568
         }
569 569
     }
570 570
 
571 571
     return $options;
572 572
 }
573 573
 
574
-function wpinv_html_checkbox( $args = array() ) {
574
+function wpinv_html_checkbox($args = array()) {
575 575
     $defaults = array(
576 576
         'name'     => null,
577 577
         'current'  => null,
@@ -582,17 +582,17 @@  discard block
 block discarded – undo
582 582
         )
583 583
     );
584 584
 
585
-    $args = wp_parse_args( $args, $defaults );
585
+    $args = wp_parse_args($args, $defaults);
586 586
 
587
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
587
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
588 588
     $options = '';
589
-    if ( ! empty( $args['options']['disabled'] ) ) {
589
+    if (!empty($args['options']['disabled'])) {
590 590
         $options .= ' disabled="disabled"';
591
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
591
+    } elseif (!empty($args['options']['readonly'])) {
592 592
         $options .= ' readonly';
593 593
     }
594 594
 
595
-    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
595
+    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />';
596 596
 
597 597
     return $output;
598 598
 }
@@ -600,30 +600,30 @@  discard block
 block discarded – undo
600 600
 /**
601 601
  * Displays a hidden field.
602 602
  */
603
-function getpaid_hidden_field( $name, $value ) {
604
-    $name  = sanitize_text_field( $name );
605
-    $value = esc_attr( $value );
603
+function getpaid_hidden_field($name, $value) {
604
+    $name  = sanitize_text_field($name);
605
+    $value = esc_attr($value);
606 606
 
607 607
     echo "<input type='hidden' name='$name' value='$value' />";
608 608
 }
609 609
 
610
-function wpinv_html_text( $args = array() ) {
610
+function wpinv_html_text($args = array()) {
611 611
     // Backwards compatibility
612
-    if ( func_num_args() > 1 ) {
612
+    if (func_num_args() > 1) {
613 613
         $args = func_get_args();
614 614
 
615 615
         $name  = $args[0];
616
-        $value = isset( $args[1] ) ? $args[1] : '';
617
-        $label = isset( $args[2] ) ? $args[2] : '';
618
-        $desc  = isset( $args[3] ) ? $args[3] : '';
616
+        $value = isset($args[1]) ? $args[1] : '';
617
+        $label = isset($args[2]) ? $args[2] : '';
618
+        $desc  = isset($args[3]) ? $args[3] : '';
619 619
     }
620 620
 
621 621
     $defaults = array(
622 622
         'id'           => '',
623
-        'name'         => isset( $name )  ? $name  : 'text',
624
-        'value'        => isset( $value ) ? $value : null,
625
-        'label'        => isset( $label ) ? $label : null,
626
-        'desc'         => isset( $desc )  ? $desc  : null,
623
+        'name'         => isset($name) ? $name : 'text',
624
+        'value'        => isset($value) ? $value : null,
625
+        'label'        => isset($label) ? $label : null,
626
+        'desc'         => isset($desc) ? $desc : null,
627 627
         'placeholder'  => '',
628 628
         'class'        => 'regular-text',
629 629
         'disabled'     => false,
@@ -633,51 +633,51 @@  discard block
 block discarded – undo
633 633
         'data'         => false
634 634
     );
635 635
 
636
-    $args = wp_parse_args( $args, $defaults );
636
+    $args = wp_parse_args($args, $defaults);
637 637
 
638
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
638
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
639 639
     $options = '';
640
-    if( $args['required'] ) {
640
+    if ($args['required']) {
641 641
         $options .= ' required="required"';
642 642
     }
643
-    if( $args['readonly'] ) {
643
+    if ($args['readonly']) {
644 644
         $options .= ' readonly';
645 645
     }
646
-    if( $args['readonly'] ) {
646
+    if ($args['readonly']) {
647 647
         $options .= ' readonly';
648 648
     }
649 649
 
650 650
     $data = '';
651
-    if ( !empty( $args['data'] ) ) {
652
-        foreach ( $args['data'] as $key => $value ) {
653
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
651
+    if (!empty($args['data'])) {
652
+        foreach ($args['data'] as $key => $value) {
653
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
654 654
         }
655 655
     }
656 656
 
657
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
658
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
659
-    if ( ! empty( $args['desc'] ) ) {
660
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
657
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
658
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
659
+    if (!empty($args['desc'])) {
660
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
661 661
     }
662 662
 
663
-    $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 ) . '/>';
663
+    $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) . '/>';
664 664
 
665 665
     $output .= '</span>';
666 666
 
667 667
     return $output;
668 668
 }
669 669
 
670
-function wpinv_html_date_field( $args = array() ) {
671
-    if( empty( $args['class'] ) ) {
670
+function wpinv_html_date_field($args = array()) {
671
+    if (empty($args['class'])) {
672 672
         $args['class'] = 'wpiDatepicker';
673
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
673
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
674 674
         $args['class'] .= ' wpiDatepicker';
675 675
     }
676 676
 
677
-    return wpinv_html_text( $args );
677
+    return wpinv_html_text($args);
678 678
 }
679 679
 
680
-function wpinv_html_textarea( $args = array() ) {
680
+function wpinv_html_textarea($args = array()) {
681 681
     $defaults = array(
682 682
         'name'        => 'textarea',
683 683
         'value'       => null,
@@ -688,31 +688,31 @@  discard block
 block discarded – undo
688 688
         'placeholder' => '',
689 689
     );
690 690
 
691
-    $args = wp_parse_args( $args, $defaults );
691
+    $args = wp_parse_args($args, $defaults);
692 692
 
693
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
693
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
694 694
     $disabled = '';
695
-    if( $args['disabled'] ) {
695
+    if ($args['disabled']) {
696 696
         $disabled = ' disabled="disabled"';
697 697
     }
698 698
 
699
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
700
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
701
-    $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>';
699
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
700
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
701
+    $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>';
702 702
 
703
-    if ( ! empty( $args['desc'] ) ) {
704
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
703
+    if (!empty($args['desc'])) {
704
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
705 705
     }
706 706
     $output .= '</span>';
707 707
 
708 708
     return $output;
709 709
 }
710 710
 
711
-function wpinv_html_ajax_user_search( $args = array() ) {
711
+function wpinv_html_ajax_user_search($args = array()) {
712 712
     $defaults = array(
713 713
         'name'        => 'user_id',
714 714
         'value'       => null,
715
-        'placeholder' => __( 'Enter username', 'invoicing' ),
715
+        'placeholder' => __('Enter username', 'invoicing'),
716 716
         'label'       => null,
717 717
         'desc'        => null,
718 718
         'class'       => '',
@@ -721,13 +721,13 @@  discard block
 block discarded – undo
721 721
         'data'        => false
722 722
     );
723 723
 
724
-    $args = wp_parse_args( $args, $defaults );
724
+    $args = wp_parse_args($args, $defaults);
725 725
 
726 726
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
727 727
 
728 728
     $output  = '<span class="wpinv_user_search_wrap">';
729
-        $output .= wpinv_html_text( $args );
730
-        $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>';
729
+        $output .= wpinv_html_text($args);
730
+        $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>';
731 731
     $output .= '</span>';
732 732
 
733 733
     return $output;
@@ -743,20 +743,20 @@  discard block
 block discarded – undo
743 743
  * 
744 744
  * @param string $template the template that is currently being used.
745 745
  */
746
-function wpinv_template( $template ) {
746
+function wpinv_template($template) {
747 747
     global $post;
748 748
 
749
-    if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) {
749
+    if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) {
750 750
 
751 751
         // If the user can view this invoice, display it.
752
-        if ( wpinv_user_can_view_invoice( $post->ID ) ) {
752
+        if (wpinv_user_can_view_invoice($post->ID)) {
753 753
 
754
-            return wpinv_get_template_part( 'wpinv-invoice-print', false, false );
754
+            return wpinv_get_template_part('wpinv-invoice-print', false, false);
755 755
 
756 756
         // Else display an error message.
757 757
         } else {
758 758
 
759
-            return wpinv_get_template_part( 'wpinv-invalid-access', false, false );
759
+            return wpinv_get_template_part('wpinv-invalid-access', false, false);
760 760
 
761 761
         }
762 762
 
@@ -764,46 +764,46 @@  discard block
 block discarded – undo
764 764
 
765 765
     return $template;
766 766
 }
767
-add_filter( 'template_include', 'wpinv_template', 10, 1 );
767
+add_filter('template_include', 'wpinv_template', 10, 1);
768 768
 
769 769
 function wpinv_get_business_address() {
770 770
     $business_address   = wpinv_store_address();
771
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
771
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
772 772
     
773 773
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
774 774
     
775
-    return apply_filters( 'wpinv_get_business_address', $business_address );
775
+    return apply_filters('wpinv_get_business_address', $business_address);
776 776
 }
777 777
 
778 778
 /**
779 779
  * Displays the company address.
780 780
  */
781 781
 function wpinv_display_from_address() {
782
-    wpinv_get_template( 'invoice/company-address.php' );
782
+    wpinv_get_template('invoice/company-address.php');
783 783
 }
784
-add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 );
784
+add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10);
785 785
 
786
-function wpinv_watermark( $id = 0 ) {
787
-    $output = wpinv_get_watermark( $id );
788
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
786
+function wpinv_watermark($id = 0) {
787
+    $output = wpinv_get_watermark($id);
788
+    return apply_filters('wpinv_get_watermark', $output, $id);
789 789
 }
790 790
 
791
-function wpinv_get_watermark( $id ) {
792
-    if ( !$id > 0 ) {
791
+function wpinv_get_watermark($id) {
792
+    if (!$id > 0) {
793 793
         return NULL;
794 794
     }
795 795
 
796
-    $invoice = wpinv_get_invoice( $id );
796
+    $invoice = wpinv_get_invoice($id);
797 797
     
798
-    if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) {
799
-        if ( $invoice->is_paid() ) {
800
-            return __( 'Paid', 'invoicing' );
798
+    if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) {
799
+        if ($invoice->is_paid()) {
800
+            return __('Paid', 'invoicing');
801 801
         }
802
-        if ( $invoice->is_refunded() ) {
803
-            return __( 'Refunded', 'invoicing' );
802
+        if ($invoice->is_refunded()) {
803
+            return __('Refunded', 'invoicing');
804 804
         }
805
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
806
-            return __( 'Cancelled', 'invoicing' );
805
+        if ($invoice->has_status(array('wpi-cancelled'))) {
806
+            return __('Cancelled', 'invoicing');
807 807
         }
808 808
     }
809 809
     
@@ -813,140 +813,140 @@  discard block
 block discarded – undo
813 813
 /**
814 814
  * @deprecated
815 815
  */
816
-function wpinv_display_invoice_details( $invoice ) {
817
-    return getpaid_invoice_meta( $invoice );
816
+function wpinv_display_invoice_details($invoice) {
817
+    return getpaid_invoice_meta($invoice);
818 818
 }
819 819
 
820 820
 /**
821 821
  * Displays invoice meta.
822 822
  */
823
-function getpaid_invoice_meta( $invoice ) {
823
+function getpaid_invoice_meta($invoice) {
824 824
 
825
-    $invoice = new WPInv_Invoice( $invoice );
825
+    $invoice = new WPInv_Invoice($invoice);
826 826
 
827 827
     // Ensure that we have an invoice.
828
-    if ( 0 == $invoice->get_id() ) {
828
+    if (0 == $invoice->get_id()) {
829 829
         return;
830 830
     }
831 831
 
832 832
     // Load the invoice meta.
833
-    $meta    = array(
833
+    $meta = array(
834 834
 
835 835
         'number' => array(
836 836
             'label' => sprintf(
837
-                __( '%s Number', 'invoicing' ),
838
-                ucfirst( $invoice->get_type() )
837
+                __('%s Number', 'invoicing'),
838
+                ucfirst($invoice->get_type())
839 839
             ),
840
-            'value' => sanitize_text_field( $invoice->get_number() ),
840
+            'value' => sanitize_text_field($invoice->get_number()),
841 841
         ),
842 842
 
843 843
         'status' => array(
844 844
             'label' => sprintf(
845
-                __( '%s Status', 'invoicing' ),
846
-                ucfirst( $invoice->get_type() )
845
+                __('%s Status', 'invoicing'),
846
+                ucfirst($invoice->get_type())
847 847
             ),
848
-            'value' => sanitize_text_field( $invoice->get_status_nicename() ),
848
+            'value' => sanitize_text_field($invoice->get_status_nicename()),
849 849
         ),
850 850
 
851 851
         'date' => array(
852 852
             'label' => sprintf(
853
-                __( '%s Date', 'invoicing' ),
854
-                ucfirst( $invoice->get_type() )
853
+                __('%s Date', 'invoicing'),
854
+                ucfirst($invoice->get_type())
855 855
             ),
856
-            'value' => getpaid_format_date( $invoice->get_created_date() ),
856
+            'value' => getpaid_format_date($invoice->get_created_date()),
857 857
         ),
858 858
 
859 859
         'date_paid' => array(
860
-            'label' => __( 'Paid On', 'invoicing' ),
861
-            'value' => getpaid_format_date( $invoice->get_completed_date() ),
860
+            'label' => __('Paid On', 'invoicing'),
861
+            'value' => getpaid_format_date($invoice->get_completed_date()),
862 862
         ),
863 863
 
864 864
         'gateway'   => array(
865
-            'label' => __( 'Payment Method', 'invoicing' ),
866
-            'value' => sanitize_text_field( $invoice->get_gateway_title() ),
865
+            'label' => __('Payment Method', 'invoicing'),
866
+            'value' => sanitize_text_field($invoice->get_gateway_title()),
867 867
         ),
868 868
 
869 869
         'transaction_id' => array(
870
-            'label' => __( 'Transaction ID', 'invoicing' ),
871
-            'value' => sanitize_text_field( $invoice->get_transaction_id() ),
870
+            'label' => __('Transaction ID', 'invoicing'),
871
+            'value' => sanitize_text_field($invoice->get_transaction_id()),
872 872
         ),
873 873
 
874 874
         'due_date'  => array(
875
-            'label' => __( 'Due Date', 'invoicing' ),
876
-            'value' => getpaid_format_date( $invoice->get_due_date() ),
875
+            'label' => __('Due Date', 'invoicing'),
876
+            'value' => getpaid_format_date($invoice->get_due_date()),
877 877
         ),
878 878
 
879 879
         'vat_number' => array(
880 880
             'label' => sprintf(
881
-                __( '%s Number', 'invoicing' ),
881
+                __('%s Number', 'invoicing'),
882 882
                 getpaid_tax()->get_vat_name()
883 883
             ),
884
-            'value' => sanitize_text_field( $invoice->get_vat_number() ),
884
+            'value' => sanitize_text_field($invoice->get_vat_number()),
885 885
         ),
886 886
 
887 887
     );
888 888
 
889 889
     // If it is not paid, remove the date of payment.
890
-    if ( ! $invoice->is_paid() ) {
891
-        unset( $meta[ 'date_paid' ] );
892
-        unset( $meta[ 'transaction_id' ] );
890
+    if (!$invoice->is_paid()) {
891
+        unset($meta['date_paid']);
892
+        unset($meta['transaction_id']);
893 893
     }
894 894
 
895
-    if ( ! $invoice->is_paid() || 'none' == $invoice->get_gateway() ) {
896
-        unset( $meta[ 'gateway' ] );
895
+    if (!$invoice->is_paid() || 'none' == $invoice->get_gateway()) {
896
+        unset($meta['gateway']);
897 897
     }
898 898
 
899 899
     // Only display the due date if due dates are enabled.
900
-    if ( ! $invoice->needs_payment() || ! wpinv_get_option( 'overdue_active' ) ) {
901
-        unset( $meta[ 'due_date' ] );
900
+    if (!$invoice->needs_payment() || !wpinv_get_option('overdue_active')) {
901
+        unset($meta['due_date']);
902 902
     }
903 903
 
904 904
     // Only display the vat number if taxes are enabled.
905
-    if ( ! wpinv_use_taxes() ) {
906
-        unset( $meta[ 'vat_number' ] );
905
+    if (!wpinv_use_taxes()) {
906
+        unset($meta['vat_number']);
907 907
     }
908 908
 
909
-    if ( $invoice->is_recurring() ) {
909
+    if ($invoice->is_recurring()) {
910 910
 
911 911
         // Link to the parent invoice.
912
-        if ( $invoice->is_renewal() ) {
912
+        if ($invoice->is_renewal()) {
913 913
 
914
-            $meta[ 'parent' ] = array(
914
+            $meta['parent'] = array(
915 915
 
916 916
                 'label' => sprintf(
917
-                    __( 'Parent %s', 'invoicing' ),
918
-                    ucfirst( $invoice->get_type() )
917
+                    __('Parent %s', 'invoicing'),
918
+                    ucfirst($invoice->get_type())
919 919
                 ),
920 920
 
921
-                'value' => wpinv_invoice_link( $invoice->get_parent_id() ),
921
+                'value' => wpinv_invoice_link($invoice->get_parent_id()),
922 922
 
923 923
             );
924 924
 
925 925
         }
926 926
 
927
-        $subscription = wpinv_get_subscription( $invoice );
927
+        $subscription = wpinv_get_subscription($invoice);
928 928
 
929
-        if ( ! empty ( $subscription ) ) {
929
+        if (!empty ($subscription)) {
930 930
 
931 931
             // Display the renewal date.
932
-            if ( $subscription->is_active() && 'cancelled' != $subscription->status ) {
932
+            if ($subscription->is_active() && 'cancelled' != $subscription->status) {
933 933
 
934
-                $meta[ 'renewal_date' ] = array(
934
+                $meta['renewal_date'] = array(
935 935
 
936
-                    'label' => __( 'Renews On', 'invoicing' ),
937
-                    'value' => getpaid_format_date( $subscription->expiration ),
936
+                    'label' => __('Renews On', 'invoicing'),
937
+                    'value' => getpaid_format_date($subscription->expiration),
938 938
         
939 939
                 );
940 940
 
941 941
             }
942 942
 
943
-            if ( $invoice->is_parent() ) {
943
+            if ($invoice->is_parent()) {
944 944
 
945 945
                 // Display the recurring amount.
946
-                $meta[ 'recurring_total' ] = array(
946
+                $meta['recurring_total'] = array(
947 947
 
948
-                    'label' => __( 'Recurring Amount', 'invoicing' ),
949
-                    'value' => wpinv_price( wpinv_format_amount( $subscription->recurring_amount ), $invoice->get_currency() ),
948
+                    'label' => __('Recurring Amount', 'invoicing'),
949
+                    'value' => wpinv_price(wpinv_format_amount($subscription->recurring_amount), $invoice->get_currency()),
950 950
         
951 951
                 );
952 952
 
@@ -956,20 +956,20 @@  discard block
 block discarded – undo
956 956
     }
957 957
 
958 958
     // Add the invoice total to the meta.
959
-    $meta[ 'invoice_total' ] = array(
959
+    $meta['invoice_total'] = array(
960 960
 
961
-        'label' => __( 'Total Amount', 'invoicing' ),
962
-        'value' => wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() ),
961
+        'label' => __('Total Amount', 'invoicing'),
962
+        'value' => wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency()),
963 963
 
964 964
     );
965 965
 
966 966
     // Provide a way for third party plugins to filter the meta.
967
-    $meta = apply_filters( 'getpaid_invoice_meta_data', $meta, $invoice );
967
+    $meta = apply_filters('getpaid_invoice_meta_data', $meta, $invoice);
968 968
 
969
-    wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) );
969
+    wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta'));
970 970
 
971 971
 }
972
-add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 );
972
+add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10);
973 973
 
974 974
 /**
975 975
  * Retrieves the address markup to use on Invoices.
@@ -981,29 +981,29 @@  discard block
 block discarded – undo
981 981
  * @param  string $separator How to separate address lines.
982 982
  * @return string
983 983
  */
984
-function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) {
984
+function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') {
985 985
 
986 986
     // Retrieve the address markup...
987
-    $country= empty( $billing_details['country'] ) ? '' : $billing_details['country'];
988
-    $format = wpinv_get_full_address_format( $country );
987
+    $country = empty($billing_details['country']) ? '' : $billing_details['country'];
988
+    $format = wpinv_get_full_address_format($country);
989 989
 
990 990
     // ... and the replacements.
991
-    $replacements = wpinv_get_invoice_address_replacements( $billing_details );
991
+    $replacements = wpinv_get_invoice_address_replacements($billing_details);
992 992
 
993
-    $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format );
993
+    $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format);
994 994
     
995 995
 	// Remove unavailable tags.
996
-    $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address );
996
+    $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address);
997 997
 
998 998
     // Clean up white space.
999
-	$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
1000
-    $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
999
+	$formatted_address = preg_replace('/  +/', ' ', trim($formatted_address));
1000
+    $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address);
1001 1001
     
1002 1002
     // Break newlines apart and remove empty lines/trim commas and white space.
1003
-	$formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
1003
+	$formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address)));
1004 1004
 
1005 1005
     // Add html breaks.
1006
-	$formatted_address = implode( $separator, $formatted_address );
1006
+	$formatted_address = implode($separator, $formatted_address);
1007 1007
 
1008 1008
 	// We're done!
1009 1009
 	return $formatted_address;
@@ -1015,88 +1015,88 @@  discard block
 block discarded – undo
1015 1015
  * 
1016 1016
  * @param WPInv_Invoice $invoice
1017 1017
  */
1018
-function wpinv_display_to_address( $invoice = 0 ) {
1019
-    if ( ! empty( $invoice ) ) {
1020
-        wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) );
1018
+function wpinv_display_to_address($invoice = 0) {
1019
+    if (!empty($invoice)) {
1020
+        wpinv_get_template('invoice/billing-address.php', compact('invoice'));
1021 1021
     }
1022 1022
 }
1023
-add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 );
1023
+add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40);
1024 1024
 
1025 1025
 
1026 1026
 /**
1027 1027
  * Displays invoice line items.
1028 1028
  */
1029
-function wpinv_display_line_items( $invoice_id = 0 ) {
1029
+function wpinv_display_line_items($invoice_id = 0) {
1030 1030
 
1031 1031
     // Prepare the invoice.
1032
-    $invoice = new WPInv_Invoice( $invoice_id );
1032
+    $invoice = new WPInv_Invoice($invoice_id);
1033 1033
 
1034 1034
     // Abort if there is no invoice.
1035
-    if ( 0 == $invoice->get_id() ) {
1035
+    if (0 == $invoice->get_id()) {
1036 1036
         return;
1037 1037
     }
1038 1038
 
1039 1039
     // Line item columns.
1040
-    $columns = getpaid_invoice_item_columns( $invoice );
1041
-    $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice );
1040
+    $columns = getpaid_invoice_item_columns($invoice);
1041
+    $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice);
1042 1042
 
1043
-    wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) );
1043
+    wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns'));
1044 1044
 }
1045
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 );
1045
+add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10);
1046 1046
 
1047 1047
 /**
1048 1048
  * Displays invoice notices on invoices.
1049 1049
  */
1050 1050
 function wpinv_display_invoice_notice() {
1051 1051
 
1052
-    $label  = wpinv_get_option( 'vat_invoice_notice_label' );
1053
-    $notice = wpinv_get_option( 'vat_invoice_notice' );
1052
+    $label  = wpinv_get_option('vat_invoice_notice_label');
1053
+    $notice = wpinv_get_option('vat_invoice_notice');
1054 1054
 
1055
-    if ( empty( $label ) && empty( $notice ) ) {
1055
+    if (empty($label) && empty($notice)) {
1056 1056
         return;
1057 1057
     }
1058 1058
 
1059 1059
     echo '<div class="mt-4 mb-4 wpinv-vat-notice">';
1060 1060
 
1061
-    if ( ! empty( $label ) ) {
1062
-        $label = sanitize_text_field( $label );
1061
+    if (!empty($label)) {
1062
+        $label = sanitize_text_field($label);
1063 1063
         echo "<h5>$label</h5>";
1064 1064
     }
1065 1065
 
1066
-    if ( ! empty( $notice ) ) {
1067
-        echo '<small class="form-text text-muted">' . wpautop( wptexturize( $notice ) ) . '</small>';
1066
+    if (!empty($notice)) {
1067
+        echo '<small class="form-text text-muted">' . wpautop(wptexturize($notice)) . '</small>';
1068 1068
     }
1069 1069
 
1070 1070
     echo '</div>';
1071 1071
 }
1072
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 );
1072
+add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100);
1073 1073
 
1074 1074
 /**
1075 1075
  * @param WPInv_Invoice $invoice
1076 1076
  */
1077
-function wpinv_display_invoice_notes( $invoice ) {
1077
+function wpinv_display_invoice_notes($invoice) {
1078 1078
 
1079 1079
     // Retrieve the notes.
1080
-    $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' );
1080
+    $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer');
1081 1081
 
1082 1082
     // Abort if we have non.
1083
-    if ( empty( $notes ) ) {
1083
+    if (empty($notes)) {
1084 1084
         return;
1085 1085
     }
1086 1086
 
1087 1087
     // Echo the note.
1088 1088
     echo '<div class="getpaid-invoice-notes-wrapper border position-relative w-100 mb-4 p-0">';
1089
-    echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __( 'Notes', 'invoicing' ) .'</h3>';
1089
+    echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __('Notes', 'invoicing') . '</h3>';
1090 1090
     echo '<ul class="getpaid-invoice-notes mt-4 p-0">';
1091 1091
 
1092
-    foreach( $notes as $note ) {
1093
-        wpinv_get_invoice_note_line_item( $note );
1092
+    foreach ($notes as $note) {
1093
+        wpinv_get_invoice_note_line_item($note);
1094 1094
     }
1095 1095
 
1096 1096
     echo '</ul>';
1097 1097
     echo '</div>';
1098 1098
 }
1099
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 );
1099
+add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60);
1100 1100
 
1101 1101
 /**
1102 1102
  * Loads scripts on our invoice templates.
@@ -1104,32 +1104,32 @@  discard block
 block discarded – undo
1104 1104
 function wpinv_display_style() {
1105 1105
 
1106 1106
     // Make sure that all scripts have been loaded.
1107
-    if ( ! did_action( 'wp_enqueue_scripts' ) ) {
1108
-        do_action( 'wp_enqueue_scripts' );
1107
+    if (!did_action('wp_enqueue_scripts')) {
1108
+        do_action('wp_enqueue_scripts');
1109 1109
     }
1110 1110
 
1111 1111
     // Register the invoices style.
1112
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) );
1112
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css'));
1113 1113
 
1114 1114
     // Load required styles
1115
-    wp_print_styles( 'open-sans' );
1116
-    wp_print_styles( 'wpinv-single-style' );
1117
-    wp_print_styles( 'ayecode-ui' );
1115
+    wp_print_styles('open-sans');
1116
+    wp_print_styles('wpinv-single-style');
1117
+    wp_print_styles('ayecode-ui');
1118 1118
 
1119 1119
     // Maybe load custom css.
1120
-    $custom_css = wpinv_get_option( 'template_custom_css' );
1120
+    $custom_css = wpinv_get_option('template_custom_css');
1121 1121
 
1122
-    if ( isset( $custom_css ) && ! empty( $custom_css ) ) {
1123
-        $custom_css     = wp_kses( $custom_css, array( '\'', '\"' ) );
1124
-        $custom_css     = str_replace( '&gt;', '>', $custom_css );
1122
+    if (isset($custom_css) && !empty($custom_css)) {
1123
+        $custom_css     = wp_kses($custom_css, array('\'', '\"'));
1124
+        $custom_css     = str_replace('&gt;', '>', $custom_css);
1125 1125
         echo '<style type="text/css">';
1126 1126
         echo $custom_css;
1127 1127
         echo '</style>';
1128 1128
     }
1129 1129
 
1130 1130
 }
1131
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
1132
-add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' );
1131
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
1132
+add_action('wpinv_invalid_invoice_head', 'wpinv_display_style');
1133 1133
 
1134 1134
 
1135 1135
 /**
@@ -1141,41 +1141,41 @@  discard block
 block discarded – undo
1141 1141
     // Retrieve the current invoice.
1142 1142
     $invoice_id = getpaid_get_current_invoice_id();
1143 1143
 
1144
-    if ( empty( $invoice_id ) ) {
1144
+    if (empty($invoice_id)) {
1145 1145
 
1146 1146
         return aui()->alert(
1147 1147
             array(
1148 1148
                 'type'    => 'warning',
1149
-                'content' => __( 'Invalid invoice', 'invoicing' ),
1149
+                'content' => __('Invalid invoice', 'invoicing'),
1150 1150
             )
1151 1151
         );
1152 1152
 
1153 1153
     }
1154 1154
 
1155 1155
     // Can the user view this invoice?
1156
-    if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) {
1156
+    if (!wpinv_user_can_view_invoice($invoice_id)) {
1157 1157
 
1158 1158
         return aui()->alert(
1159 1159
             array(
1160 1160
                 'type'    => 'warning',
1161
-                'content' => __( 'You are not allowed to view this invoice', 'invoicing' ),
1161
+                'content' => __('You are not allowed to view this invoice', 'invoicing'),
1162 1162
             )
1163 1163
         );
1164 1164
 
1165 1165
     }
1166 1166
 
1167 1167
     // Ensure that it is not yet paid for.
1168
-    $invoice = new WPInv_Invoice( $invoice_id );
1168
+    $invoice = new WPInv_Invoice($invoice_id);
1169 1169
 
1170 1170
     // Maybe mark it as viewed.
1171
-    getpaid_maybe_mark_invoice_as_viewed( $invoice );
1171
+    getpaid_maybe_mark_invoice_as_viewed($invoice);
1172 1172
 
1173
-    if ( $invoice->is_paid() ) {
1173
+    if ($invoice->is_paid()) {
1174 1174
 
1175 1175
         return aui()->alert(
1176 1176
             array(
1177 1177
                 'type'    => 'success',
1178
-                'content' => __( 'This invoice has already been paid.', 'invoicing' ),
1178
+                'content' => __('This invoice has already been paid.', 'invoicing'),
1179 1179
             )
1180 1180
         );
1181 1181
 
@@ -1185,14 +1185,14 @@  discard block
 block discarded – undo
1185 1185
     $wpi_checkout_id = $invoice_id;
1186 1186
 
1187 1187
     // We'll display this invoice via the default form.
1188
-    $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1188
+    $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1189 1189
 
1190
-    if ( 0 == $form->get_id() ) {
1190
+    if (0 == $form->get_id()) {
1191 1191
 
1192 1192
         return aui()->alert(
1193 1193
             array(
1194 1194
                 'type'    => 'warning',
1195
-                'content' => __( 'Error loading the payment form', 'invoicing' ),
1195
+                'content' => __('Error loading the payment form', 'invoicing'),
1196 1196
             )
1197 1197
         );
1198 1198
 
@@ -1200,7 +1200,7 @@  discard block
 block discarded – undo
1200 1200
 
1201 1201
     // Set the invoice.
1202 1202
     $form->invoice = $invoice;
1203
-    $form->set_items( $invoice->get_items() );
1203
+    $form->set_items($invoice->get_items());
1204 1204
 
1205 1205
     // Generate the html.
1206 1206
     return $form->get_html();
@@ -1208,7 +1208,7 @@  discard block
 block discarded – undo
1208 1208
 }
1209 1209
 
1210 1210
 function wpinv_empty_cart_message() {
1211
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1211
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1212 1212
 }
1213 1213
 
1214 1214
 /**
@@ -1225,38 +1225,38 @@  discard block
 block discarded – undo
1225 1225
         )
1226 1226
     );
1227 1227
 }
1228
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1228
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1229 1229
 
1230
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1231
-    $invoice = wpinv_get_invoice( $invoice_id );
1230
+function wpinv_receipt_billing_address($invoice_id = 0) {
1231
+    $invoice = wpinv_get_invoice($invoice_id);
1232 1232
 
1233
-    if ( empty( $invoice ) ) {
1233
+    if (empty($invoice)) {
1234 1234
         return NULL;
1235 1235
     }
1236 1236
 
1237 1237
     $billing_details = $invoice->get_user_info();
1238
-    $address_row = wpinv_get_invoice_address_markup( $billing_details );
1238
+    $address_row = wpinv_get_invoice_address_markup($billing_details);
1239 1239
 
1240 1240
     ob_start();
1241 1241
     ?>
1242 1242
     <table class="table table-bordered table-sm wpi-billing-details">
1243 1243
         <tbody>
1244 1244
             <tr class="wpi-receipt-name">
1245
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1246
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1245
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1246
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1247 1247
             </tr>
1248 1248
             <tr class="wpi-receipt-email">
1249
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1250
-                <td><?php echo $billing_details['email'] ;?></td>
1249
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1250
+                <td><?php echo $billing_details['email']; ?></td>
1251 1251
             </tr>
1252 1252
             <tr class="wpi-receipt-address">
1253
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1254
-                <td><?php echo $address_row ;?></td>
1253
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1254
+                <td><?php echo $address_row; ?></td>
1255 1255
             </tr>
1256
-            <?php if ( $billing_details['phone'] ) { ?>
1256
+            <?php if ($billing_details['phone']) { ?>
1257 1257
             <tr class="wpi-receipt-phone">
1258
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1259
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1258
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1259
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1260 1260
             </tr>
1261 1261
             <?php } ?>
1262 1262
         </tbody>
@@ -1264,7 +1264,7 @@  discard block
 block discarded – undo
1264 1264
     <?php
1265 1265
     $output = ob_get_clean();
1266 1266
     
1267
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1267
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1268 1268
 
1269 1269
     echo $output;
1270 1270
 }
@@ -1272,56 +1272,56 @@  discard block
 block discarded – undo
1272 1272
 /**
1273 1273
  * Filters the receipt page.
1274 1274
  */
1275
-function wpinv_filter_success_page_content( $content ) {
1275
+function wpinv_filter_success_page_content($content) {
1276 1276
 
1277 1277
     // Ensure this is our page.
1278
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1278
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1279 1279
 
1280
-        $gateway = sanitize_text_field( $_GET['payment-confirm'] );
1281
-        return apply_filters( "wpinv_payment_confirm_$gateway", $content );
1280
+        $gateway = sanitize_text_field($_GET['payment-confirm']);
1281
+        return apply_filters("wpinv_payment_confirm_$gateway", $content);
1282 1282
 
1283 1283
     }
1284 1284
 
1285 1285
     return $content;
1286 1286
 }
1287
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1287
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1288 1288
 
1289
-function wpinv_invoice_link( $invoice_id ) {
1290
-    $invoice = wpinv_get_invoice( $invoice_id );
1289
+function wpinv_invoice_link($invoice_id) {
1290
+    $invoice = wpinv_get_invoice($invoice_id);
1291 1291
 
1292
-    if ( empty( $invoice ) ) {
1292
+    if (empty($invoice)) {
1293 1293
         return NULL;
1294 1294
     }
1295 1295
 
1296
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1296
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1297 1297
 
1298
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1298
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1299 1299
 }
1300 1300
 
1301
-function wpinv_invoice_subscription_details( $invoice ) {
1302
-    if ( !empty( $invoice ) && $invoice->is_recurring() && ! wpinv_is_subscription_payment( $invoice ) ) {
1303
-        $subscription = wpinv_get_subscription( $invoice, true );
1301
+function wpinv_invoice_subscription_details($invoice) {
1302
+    if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) {
1303
+        $subscription = wpinv_get_subscription($invoice, true);
1304 1304
 
1305
-        if ( empty( $subscription ) ) {
1305
+        if (empty($subscription)) {
1306 1306
             return;
1307 1307
         }
1308 1308
 
1309 1309
         $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->period, $subscription->frequency);
1310
-        $billing = wpinv_price(wpinv_format_amount($subscription->recurring_amount), $invoice->get_currency() ) . ' / ' . $frequency;
1311
-        $initial = wpinv_price(wpinv_format_amount($subscription->initial_amount), $invoice->get_currency() );
1310
+        $billing = wpinv_price(wpinv_format_amount($subscription->recurring_amount), $invoice->get_currency()) . ' / ' . $frequency;
1311
+        $initial = wpinv_price(wpinv_format_amount($subscription->initial_amount), $invoice->get_currency());
1312 1312
 
1313 1313
         $payments = $subscription->get_child_payments();
1314 1314
         ?>
1315 1315
         <div class="wpinv-subscriptions-details">
1316
-            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3>
1316
+            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3>
1317 1317
             <table class="table">
1318 1318
                 <thead>
1319 1319
                     <tr>
1320
-                        <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th>
1321
-                        <th><?php _e( 'Start Date', 'invoicing' ) ;?></th>
1322
-                        <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th>
1323
-                        <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th>
1324
-                        <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th>
1320
+                        <th><?php _e('Billing Cycle', 'invoicing'); ?></th>
1321
+                        <th><?php _e('Start Date', 'invoicing'); ?></th>
1322
+                        <th><?php _e('Expiration Date', 'invoicing'); ?></th>
1323
+                        <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th>
1324
+                        <th class="text-center"><?php _e('Status', 'invoicing'); ?></th>
1325 1325
                     </tr>
1326 1326
                 </thead>
1327 1327
                 <tbody>
@@ -1329,35 +1329,35 @@  discard block
 block discarded – undo
1329 1329
                         <td><?php printf(_x('%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing'), $initial, $billing); ?></td>
1330 1330
                         <td><?php echo date_i18n(get_option('date_format'), strtotime($subscription->created, current_time('timestamp'))); ?></td>
1331 1331
                         <td><?php echo date_i18n(get_option('date_format'), strtotime($subscription->expiration, current_time('timestamp'))); ?></td>
1332
-                        <td class="text-center"><?php echo $subscription->get_times_billed() . ' / ' . (($subscription->bill_times == 0) ? __( 'Until Cancelled', 'invoicing' ) : $subscription->bill_times); ?></td>
1332
+                        <td class="text-center"><?php echo $subscription->get_times_billed() . ' / ' . (($subscription->bill_times == 0) ? __('Until Cancelled', 'invoicing') : $subscription->bill_times); ?></td>
1333 1333
                         <td class="text-center wpi-sub-status"><?php echo $subscription->get_status_label(); ?></td>
1334 1334
                     </tr>
1335 1335
                 </tbody>
1336 1336
             </table>
1337 1337
         </div>
1338
-        <?php if ( !empty( $payments ) ) { ?>
1338
+        <?php if (!empty($payments)) { ?>
1339 1339
         <div class="wpinv-renewal-payments">
1340
-            <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3>
1340
+            <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3>
1341 1341
             <table class="table">
1342 1342
                 <thead>
1343 1343
                     <tr>
1344 1344
                         <th>#</th>
1345
-                        <th><?php _e( 'Invoice', 'invoicing' ) ;?></th>
1346
-                        <th><?php _e( 'Date', 'invoicing' ) ;?></th>
1347
-                        <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th>
1345
+                        <th><?php _e('Invoice', 'invoicing'); ?></th>
1346
+                        <th><?php _e('Date', 'invoicing'); ?></th>
1347
+                        <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th>
1348 1348
                     </tr>
1349 1349
                 </thead>
1350 1350
                 <tbody>
1351 1351
                     <?php
1352 1352
                         $i = 1;
1353
-                        foreach ( $payments as $payment ) {
1353
+                        foreach ($payments as $payment) {
1354 1354
                             $invoice_id = $payment->ID;
1355 1355
                     ?>
1356 1356
                     <tr>
1357
-                        <th scope="row"><?php echo $i;?></th>
1358
-                        <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td>
1357
+                        <th scope="row"><?php echo $i; ?></th>
1358
+                        <td><?php echo wpinv_invoice_link($invoice_id); ?></td>
1359 1359
                         <td><?php echo$invoice->get_date_created(); ?></td>
1360
-                        <td class="text-right"><?php echo wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() ); ?></td>
1360
+                        <td class="text-right"><?php echo wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency()); ?></td>
1361 1361
                     </tr>
1362 1362
                     <?php $i++; } ?>
1363 1363
                 </tbody>
@@ -1367,64 +1367,64 @@  discard block
 block discarded – undo
1367 1367
         <?php
1368 1368
     }
1369 1369
 }
1370
-add_action( 'getpaid_invoice_line_items', 'wpinv_invoice_subscription_details', 20 );
1370
+add_action('getpaid_invoice_line_items', 'wpinv_invoice_subscription_details', 20);
1371 1371
 
1372
-function wpinv_cart_total_label( $label, $invoice ) {
1373
-    if ( empty( $invoice ) ) {
1372
+function wpinv_cart_total_label($label, $invoice) {
1373
+    if (empty($invoice)) {
1374 1374
         return $label;
1375 1375
     }
1376 1376
 
1377 1377
     $prefix_label = '';
1378
-    if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) {
1379
-        $prefix_label   = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice );
1380
-    } else if ( $invoice->is_renewal() ) {
1381
-        $prefix_label   = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> ';        
1378
+    if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) {
1379
+        $prefix_label   = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice);
1380
+    } else if ($invoice->is_renewal()) {
1381
+        $prefix_label   = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> ';        
1382 1382
     }
1383 1383
 
1384
-    if ( $prefix_label != '' ) {
1385
-        $label  = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
1384
+    if ($prefix_label != '') {
1385
+        $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
1386 1386
     }
1387 1387
 
1388 1388
     return $label;
1389 1389
 }
1390
-add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
1391
-add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
1392
-add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
1390
+add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2);
1391
+add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2);
1392
+add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2);
1393 1393
 
1394
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
1395
-    if ( empty( $note ) ) {
1394
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
1395
+    if (empty($note)) {
1396 1396
         return NULL;
1397 1397
     }
1398 1398
 
1399
-    if ( is_int( $note ) ) {
1400
-        $note = get_comment( $note );
1399
+    if (is_int($note)) {
1400
+        $note = get_comment($note);
1401 1401
     }
1402 1402
 
1403
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
1403
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
1404 1404
         return NULL;
1405 1405
     }
1406 1406
 
1407
-    $note_classes   = array( 'note' );
1408
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
1407
+    $note_classes   = array('note');
1408
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
1409 1409
     $note_classes[] = $note->comment_author === 'System' ? 'system-note' : '';
1410
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
1411
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
1410
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
1411
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
1412 1412
 
1413 1413
     ob_start();
1414 1414
     ?>
1415
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?> mt-4 pl-3 pr-3">
1415
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mt-4 pl-3 pr-3">
1416 1416
         <div class="note_content bg-light border position-relative p-4">
1417 1417
 
1418
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
1418
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
1419 1419
 
1420
-            <?php if ( ! is_admin() ) : ?>
1420
+            <?php if (!is_admin()) : ?>
1421 1421
                 <em class="meta position-absolute form-text">
1422 1422
                     <?php
1423 1423
                         printf(
1424
-                            __( '%1$s - %2$s at %3$s', 'invoicing' ),
1424
+                            __('%1$s - %2$s at %3$s', 'invoicing'),
1425 1425
                             $note->comment_author,
1426
-                            date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ),
1427
-                            date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) )
1426
+                            date_i18n(get_option('date_format'), strtotime($note->comment_date)),
1427
+                            date_i18n(get_option('time_format'), strtotime($note->comment_date))
1428 1428
                         );
1429 1429
                     ?>
1430 1430
                 </em>
@@ -1432,12 +1432,12 @@  discard block
 block discarded – undo
1432 1432
 
1433 1433
         </div>
1434 1434
 
1435
-        <?php if ( is_admin() ) : ?>
1435
+        <?php if (is_admin()) : ?>
1436 1436
 
1437 1437
             <p class="meta px-4 py-2">
1438
-                <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr>&nbsp;&nbsp;
1439
-                <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?>
1440
-                    <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
1438
+                <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr>&nbsp;&nbsp;
1439
+                <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?>
1440
+                    <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
1441 1441
                 <?php } ?>
1442 1442
             </p>
1443 1443
 
@@ -1446,9 +1446,9 @@  discard block
 block discarded – undo
1446 1446
     </li>
1447 1447
     <?php
1448 1448
     $note_content = ob_get_clean();
1449
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
1449
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
1450 1450
 
1451
-    if ( $echo ) {
1451
+    if ($echo) {
1452 1452
         echo $note_content;
1453 1453
     } else {
1454 1454
         return $note_content;
@@ -1458,36 +1458,36 @@  discard block
 block discarded – undo
1458 1458
 function wpinv_invalid_invoice_content() {
1459 1459
     global $post;
1460 1460
 
1461
-    $invoice = wpinv_get_invoice( $post->ID );
1461
+    $invoice = wpinv_get_invoice($post->ID);
1462 1462
 
1463
-    $error = __( 'This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing' );
1464
-    if ( !empty( $invoice->get_id() ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) {
1465
-        if ( is_user_logged_in() ) {
1466
-            if ( wpinv_require_login_to_checkout() ) {
1467
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
1468
-                    $error = __( 'You are not allowed to view this invoice.', 'invoicing' );
1463
+    $error = __('This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing');
1464
+    if (!empty($invoice->get_id()) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) {
1465
+        if (is_user_logged_in()) {
1466
+            if (wpinv_require_login_to_checkout()) {
1467
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
1468
+                    $error = __('You are not allowed to view this invoice.', 'invoicing');
1469 1469
                 }
1470 1470
             }
1471 1471
         } else {
1472
-            if ( wpinv_require_login_to_checkout() ) {
1473
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
1474
-                    $error = __( 'You must be logged in to view this invoice.', 'invoicing' );
1472
+            if (wpinv_require_login_to_checkout()) {
1473
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
1474
+                    $error = __('You must be logged in to view this invoice.', 'invoicing');
1475 1475
                 }
1476 1476
             }
1477 1477
         }
1478 1478
     } else {
1479
-        $error = __( 'This invoice is deleted or does not exist.', 'invoicing' );
1479
+        $error = __('This invoice is deleted or does not exist.', 'invoicing');
1480 1480
     }
1481 1481
     ?>
1482 1482
     <div class="row wpinv-row-invalid">
1483 1483
         <div class="col-md-6 col-md-offset-3 wpinv-message error">
1484
-            <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3>
1484
+            <h3><?php _e('Access Denied', 'invoicing'); ?></h3>
1485 1485
             <p class="wpinv-msg-text"><?php echo $error; ?></p>
1486 1486
         </div>
1487 1487
     </div>
1488 1488
     <?php
1489 1489
 }
1490
-add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' );
1490
+add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content');
1491 1491
 
1492 1492
 /**
1493 1493
  * Function to get privacy policy text.
@@ -1496,21 +1496,21 @@  discard block
 block discarded – undo
1496 1496
  * @return string
1497 1497
  */
1498 1498
 function wpinv_get_policy_text() {
1499
-    $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 );
1499
+    $privacy_page_id = get_option('wp_page_for_privacy_policy', 0);
1500 1500
 
1501
-    $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]' ));
1501
+    $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]'));
1502 1502
 
1503
-    if(!$privacy_page_id){
1504
-        $privacy_page_id = wpinv_get_option( 'privacy_page', 0 );
1503
+    if (!$privacy_page_id) {
1504
+        $privacy_page_id = wpinv_get_option('privacy_page', 0);
1505 1505
     }
1506 1506
 
1507
-    $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' );
1507
+    $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');
1508 1508
 
1509 1509
     $find_replace = array(
1510 1510
         '[wpinv_privacy_policy]' => $privacy_link,
1511 1511
     );
1512 1512
 
1513
-    $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text );
1513
+    $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text);
1514 1514
 
1515 1515
     return wp_kses_post(wpautop($privacy_text));
1516 1516
 }
@@ -1518,21 +1518,21 @@  discard block
 block discarded – undo
1518 1518
 function wpinv_oxygen_fix_conflict() {
1519 1519
     global $ct_ignore_post_types;
1520 1520
 
1521
-    if ( ! is_array( $ct_ignore_post_types ) ) {
1521
+    if (!is_array($ct_ignore_post_types)) {
1522 1522
         $ct_ignore_post_types = array();
1523 1523
     }
1524 1524
 
1525
-    $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item' );
1525
+    $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item');
1526 1526
 
1527
-    foreach ( $post_types as $post_type ) {
1527
+    foreach ($post_types as $post_type) {
1528 1528
         $ct_ignore_post_types[] = $post_type;
1529 1529
 
1530 1530
         // Ignore post type
1531
-        add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 );
1531
+        add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999);
1532 1532
     }
1533 1533
 
1534
-    remove_filter( 'template_include', 'wpinv_template', 10, 1 );
1535
-    add_filter( 'template_include', 'wpinv_template', 999, 1 );
1534
+    remove_filter('template_include', 'wpinv_template', 10, 1);
1535
+    add_filter('template_include', 'wpinv_template', 999, 1);
1536 1536
 }
1537 1537
 
1538 1538
 /**
@@ -1540,10 +1540,10 @@  discard block
 block discarded – undo
1540 1540
  * 
1541 1541
  * @param GetPaid_Payment_Form $form
1542 1542
  */
1543
-function getpaid_display_payment_form( $form ) {
1543
+function getpaid_display_payment_form($form) {
1544 1544
 
1545
-    if ( is_numeric( $form ) ) {
1546
-        $form = new GetPaid_Payment_Form( $form );
1545
+    if (is_numeric($form)) {
1546
+        $form = new GetPaid_Payment_Form($form);
1547 1547
     }
1548 1548
 
1549 1549
     $form->display();
@@ -1553,16 +1553,16 @@  discard block
 block discarded – undo
1553 1553
 /**
1554 1554
  * Helper function to display a item payment form on the frontend.
1555 1555
  */
1556
-function getpaid_display_item_payment_form( $items ) {
1556
+function getpaid_display_item_payment_form($items) {
1557 1557
 
1558
-    $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1559
-    $form->set_items( $items );
1558
+    $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1559
+    $form->set_items($items);
1560 1560
 
1561
-    if ( 0 == count( $form->get_items() ) ) {
1561
+    if (0 == count($form->get_items())) {
1562 1562
         echo aui()->alert(
1563 1563
 			array(
1564 1564
 				'type'    => 'warning',
1565
-				'content' => __( 'No published items found', 'invoicing' ),
1565
+				'content' => __('No published items found', 'invoicing'),
1566 1566
 			)
1567 1567
         );
1568 1568
         return;
@@ -1574,75 +1574,75 @@  discard block
 block discarded – undo
1574 1574
 /**
1575 1575
  * Helper function to display an invoice payment form on the frontend.
1576 1576
  */
1577
-function getpaid_display_invoice_payment_form( $invoice_id ) {
1577
+function getpaid_display_invoice_payment_form($invoice_id) {
1578 1578
     global $invoicing;
1579 1579
 
1580
-    $invoice = wpinv_get_invoice( $invoice_id );
1580
+    $invoice = wpinv_get_invoice($invoice_id);
1581 1581
 
1582
-    if ( empty( $invoice ) ) {
1582
+    if (empty($invoice)) {
1583 1583
 		return aui()->alert(
1584 1584
 			array(
1585 1585
 				'type'    => 'warning',
1586
-				'content' => __( 'Invoice not found', 'invoicing' ),
1586
+				'content' => __('Invoice not found', 'invoicing'),
1587 1587
 			)
1588 1588
 		);
1589 1589
     }
1590 1590
 
1591
-    if ( $invoice->is_paid() ) {
1591
+    if ($invoice->is_paid()) {
1592 1592
 		return aui()->alert(
1593 1593
 			array(
1594 1594
 				'type'    => 'warning',
1595
-				'content' => __( 'Invoice has already been paid', 'invoicing' ),
1595
+				'content' => __('Invoice has already been paid', 'invoicing'),
1596 1596
 			)
1597 1597
 		);
1598 1598
     }
1599 1599
 
1600 1600
     // Get the form elements and items.
1601
-    $form     = wpinv_get_default_payment_form();
1602
-	$elements = $invoicing->form_elements->get_form_elements( $form );
1603
-	$items    = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice );
1601
+    $form = wpinv_get_default_payment_form();
1602
+	$elements = $invoicing->form_elements->get_form_elements($form);
1603
+	$items    = $invoicing->form_elements->convert_checkout_items($invoice->cart_details, $invoice);
1604 1604
 
1605 1605
 	ob_start();
1606 1606
 	echo "<form class='wpinv_payment_form'>";
1607
-	do_action( 'wpinv_payment_form_top' );
1607
+	do_action('wpinv_payment_form_top');
1608 1608
     echo "<input type='hidden' name='form_id' value='$form'/>";
1609 1609
     echo "<input type='hidden' name='invoice_id' value='$invoice_id'/>";
1610
-	wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
1611
-	wp_nonce_field( 'vat_validation', '_wpi_nonce' );
1610
+	wp_nonce_field('wpinv_payment_form', 'wpinv_payment_form');
1611
+	wp_nonce_field('vat_validation', '_wpi_nonce');
1612 1612
 
1613
-	foreach ( $elements as $element ) {
1614
-		do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form );
1615
-		do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form );
1613
+	foreach ($elements as $element) {
1614
+		do_action('wpinv_frontend_render_payment_form_element', $element, $items, $form);
1615
+		do_action("wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form);
1616 1616
 	}
1617 1617
 
1618 1618
 	echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
1619
-	do_action( 'wpinv_payment_form_bottom' );
1619
+	do_action('wpinv_payment_form_bottom');
1620 1620
 	echo '</form>';
1621 1621
 
1622 1622
 	$content = ob_get_clean();
1623
-	return str_replace( 'sr-only', '', $content );
1623
+	return str_replace('sr-only', '', $content);
1624 1624
 }
1625 1625
 
1626 1626
 /**
1627 1627
  * Helper function to convert item string to array.
1628 1628
  */
1629
-function getpaid_convert_items_to_array( $items ) {
1630
-    $items    = array_filter( array_map( 'trim', explode( ',', $items ) ) );
1629
+function getpaid_convert_items_to_array($items) {
1630
+    $items    = array_filter(array_map('trim', explode(',', $items)));
1631 1631
     $prepared = array();
1632 1632
 
1633
-    foreach ( $items as $item ) {
1634
-        $data = array_map( 'trim', explode( '|', $item ) );
1633
+    foreach ($items as $item) {
1634
+        $data = array_map('trim', explode('|', $item));
1635 1635
 
1636
-        if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) {
1636
+        if (empty($data[0]) || !is_numeric($data[0])) {
1637 1637
             continue;
1638 1638
         }
1639 1639
 
1640 1640
         $quantity = 1;
1641
-        if ( isset( $data[1] ) && is_numeric( $data[1] ) ) {
1641
+        if (isset($data[1]) && is_numeric($data[1])) {
1642 1642
             $quantity = (int) $data[1];
1643 1643
         }
1644 1644
 
1645
-        $prepared[ $data[0] ] = $quantity;
1645
+        $prepared[$data[0]] = $quantity;
1646 1646
 
1647 1647
     }
1648 1648
 
@@ -1652,13 +1652,13 @@  discard block
 block discarded – undo
1652 1652
 /**
1653 1653
  * Helper function to convert item array to string.
1654 1654
  */
1655
-function getpaid_convert_items_to_string( $items ) {
1655
+function getpaid_convert_items_to_string($items) {
1656 1656
     $prepared = array();
1657 1657
 
1658
-    foreach ( $items as $item => $quantity ) {
1658
+    foreach ($items as $item => $quantity) {
1659 1659
         $prepared[] = "$item|$quantity";
1660 1660
     }
1661
-    return implode( ',', $prepared );
1661
+    return implode(',', $prepared);
1662 1662
 }
1663 1663
 
1664 1664
 /**
@@ -1666,22 +1666,22 @@  discard block
 block discarded – undo
1666 1666
  * 
1667 1667
  * Provide a label and one of $form, $items or $invoice.
1668 1668
  */
1669
-function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) {
1670
-    $label = sanitize_text_field( $label );
1669
+function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) {
1670
+    $label = sanitize_text_field($label);
1671 1671
     $nonce = wp_create_nonce('getpaid_ajax_form');
1672 1672
 
1673
-    if ( ! empty( $form ) ) {
1674
-        $form  = esc_attr( $form );
1673
+    if (!empty($form)) {
1674
+        $form = esc_attr($form);
1675 1675
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-form='$form'>$label</button>"; 
1676 1676
     }
1677 1677
 	
1678
-	if ( ! empty( $items ) ) {
1679
-        $items  = esc_attr( $items );
1678
+	if (!empty($items)) {
1679
+        $items = esc_attr($items);
1680 1680
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-item='$items'>$label</button>"; 
1681 1681
     }
1682 1682
     
1683
-    if ( ! empty( $invoice ) ) {
1684
-        $invoice  = esc_attr( $invoice );
1683
+    if (!empty($invoice)) {
1684
+        $invoice = esc_attr($invoice);
1685 1685
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-invoice='$invoice'>$label</button>"; 
1686 1686
     }
1687 1687
 
@@ -1692,17 +1692,17 @@  discard block
 block discarded – undo
1692 1692
  *
1693 1693
  * @param WPInv_Invoice $invoice
1694 1694
  */
1695
-function getpaid_the_invoice_description( $invoice ) {
1695
+function getpaid_the_invoice_description($invoice) {
1696 1696
     $description = $invoice->get_description();
1697 1697
 
1698
-    if ( empty( $description ) ) {
1698
+    if (empty($description)) {
1699 1699
         return;
1700 1700
     }
1701 1701
 
1702
-    $description = wp_kses_post( $description );
1702
+    $description = wp_kses_post($description);
1703 1703
     echo "<small class='getpaid-invoice-description text-dark p-2 form-text'><em>$description</em></small>";
1704 1704
 }
1705
-add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 );
1705
+add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100);
1706 1706
 
1707 1707
 /**
1708 1708
  * Render element on a form.
@@ -1710,41 +1710,41 @@  discard block
 block discarded – undo
1710 1710
  * @param array $element
1711 1711
  * @param GetPaid_Payment_Form $form
1712 1712
  */
1713
-function getpaid_payment_form_element( $element, $form ) {
1713
+function getpaid_payment_form_element($element, $form) {
1714 1714
 
1715 1715
     // Set up the args.
1716
-    $element_type    = trim( $element['type'] );
1716
+    $element_type    = trim($element['type']);
1717 1717
     $element['form'] = $form;
1718
-    extract( $element );
1718
+    extract($element);
1719 1719
 
1720 1720
     // Try to locate the appropriate template.
1721
-    $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" );
1721
+    $located = wpinv_locate_template("payment-forms/elements/$element_type.php");
1722 1722
     
1723 1723
     // Abort if this is not our element.
1724
-    if ( empty( $located ) || ! file_exists( $located ) ) {
1724
+    if (empty($located) || !file_exists($located)) {
1725 1725
         return;
1726 1726
     }
1727 1727
 
1728 1728
     // Generate the class and id of the element.
1729
-    $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) );
1730
-    $id            = isset( $id ) ? $id : uniqid( 'gp' );
1729
+    $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type));
1730
+    $id            = isset($id) ? $id : uniqid('gp');
1731 1731
 
1732 1732
     // Echo the opening wrapper.
1733 1733
     echo "<div class='getpaid-payment-form-element $wrapper_class'>";
1734 1734
 
1735 1735
     // Fires before displaying a given element type's content.
1736
-    do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form );
1736
+    do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form);
1737 1737
 
1738 1738
     // Include the template for the element.
1739 1739
     include $located;
1740 1740
 
1741 1741
     // Fires after displaying a given element type's content.
1742
-    do_action( "getpaid_payment_form_{$element_type}_element", $element, $form );
1742
+    do_action("getpaid_payment_form_{$element_type}_element", $element, $form);
1743 1743
 
1744 1744
     // Echo the closing wrapper.
1745 1745
     echo '</div>';
1746 1746
 }
1747
-add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 );
1747
+add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2);
1748 1748
 
1749 1749
 /**
1750 1750
  * Shows a list of gateways that support recurring payments.
@@ -1752,17 +1752,17 @@  discard block
 block discarded – undo
1752 1752
 function wpinv_get_recurring_gateways_text() {
1753 1753
     $gateways = array();
1754 1754
 
1755
-    foreach ( wpinv_get_payment_gateways() as $key => $gateway ) {
1756
-        if ( wpinv_gateway_support_subscription( $key ) ) {
1757
-            $gateways[] = sanitize_text_field( $gateway['admin_label'] );
1755
+    foreach (wpinv_get_payment_gateways() as $key => $gateway) {
1756
+        if (wpinv_gateway_support_subscription($key)) {
1757
+            $gateways[] = sanitize_text_field($gateway['admin_label']);
1758 1758
         }
1759 1759
     }
1760 1760
 
1761
-    if ( empty( $gateways ) ) {
1762
-        return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) ."</span>";
1761
+    if (empty($gateways)) {
1762
+        return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . "</span>";
1763 1763
     }
1764 1764
 
1765
-    return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) ."</span>";
1765
+    return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . "</span>";
1766 1766
 
1767 1767
 }
1768 1768
 
@@ -1772,5 +1772,5 @@  discard block
 block discarded – undo
1772 1772
  * @return GetPaid_Template
1773 1773
  */
1774 1774
 function getpaid_template() {
1775
-    return getpaid()->get( 'template' );
1775
+    return getpaid()->get('template');
1776 1776
 }
Please login to merge, or discard this patch.