Passed
Pull Request — master (#275)
by Brian
06:25
created
includes/gateways/authorizenet/anet_php_sdk/lib/AuthorizeNetAIM.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -77,19 +77,19 @@  discard block
 block discarded – undo
77 77
      * A list of all fields in the AIM API.
78 78
      * Used to warn user if they try to set a field not offered in the API.
79 79
      */
80
-    private $_all_aim_fields = array("address","allow_partial_auth","amount",
81
-        "auth_code","authentication_indicator", "bank_aba_code","bank_acct_name",
82
-        "bank_acct_num","bank_acct_type","bank_check_number","bank_name",
83
-        "card_code","card_num","cardholder_authentication_value","city","company",
84
-        "country","cust_id","customer_ip","delim_char","delim_data","description",
85
-        "duplicate_window","duty","echeck_type","email","email_customer",
86
-        "encap_char","exp_date","fax","first_name","footer_email_receipt",
87
-        "freight","header_email_receipt","invoice_num","last_name","line_item",
88
-        "login","method","phone","po_num","recurring_billing","relay_response",
89
-        "ship_to_address","ship_to_city","ship_to_company","ship_to_country",
90
-        "ship_to_first_name","ship_to_last_name","ship_to_state","ship_to_zip",
91
-        "split_tender_id","state","tax","tax_exempt","test_request","tran_key",
92
-        "trans_id","type","version","zip"
80
+    private $_all_aim_fields = array("address", "allow_partial_auth", "amount",
81
+        "auth_code", "authentication_indicator", "bank_aba_code", "bank_acct_name",
82
+        "bank_acct_num", "bank_acct_type", "bank_check_number", "bank_name",
83
+        "card_code", "card_num", "cardholder_authentication_value", "city", "company",
84
+        "country", "cust_id", "customer_ip", "delim_char", "delim_data", "description",
85
+        "duplicate_window", "duty", "echeck_type", "email", "email_customer",
86
+        "encap_char", "exp_date", "fax", "first_name", "footer_email_receipt",
87
+        "freight", "header_email_receipt", "invoice_num", "last_name", "line_item",
88
+        "login", "method", "phone", "po_num", "recurring_billing", "relay_response",
89
+        "ship_to_address", "ship_to_city", "ship_to_company", "ship_to_country",
90
+        "ship_to_first_name", "ship_to_last_name", "ship_to_state", "ship_to_zip",
91
+        "split_tender_id", "state", "tax", "tax_exempt", "test_request", "tran_key",
92
+        "trans_id", "type", "version", "zip"
93 93
         );
94 94
     
95 95
     /**
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
      */
235 235
     public function setFields($fields)
236 236
     {
237
-        $array = (array)$fields;
237
+        $array = (array) $fields;
238 238
         foreach ($array as $key => $value) {
239 239
             $this->setField($key, $value);
240 240
         }
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
      */
248 248
     public function setCustomFields($fields)
249 249
     {
250
-        $array = (array)$fields;
250
+        $array = (array) $fields;
251 251
         foreach ($array as $key => $value) {
252 252
             $this->setCustomField($key, $value);
253 253
         }
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
             // Split Array
404 404
             $this->response = $response;
405 405
             if ($encap_char) {
406
-                $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1));
406
+                $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1));
407 407
             } else {
408 408
                 $this->_response_array = explode($delimiter, $response);
409 409
             }
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
             $this->duty                 = $this->_response_array[33];
458 458
             $this->freight              = $this->_response_array[34];
459 459
             $this->tax_exempt           = $this->_response_array[35];
460
-            $this->purchase_order_number= $this->_response_array[36];
460
+            $this->purchase_order_number = $this->_response_array[36];
461 461
             $this->md5_hash             = $this->_response_array[37];
462 462
             $this->card_code_response   = $this->_response_array[38];
463 463
             $this->cavv_response        = $this->_response_array[39];
@@ -484,10 +484,10 @@  discard block
 block discarded – undo
484 484
             
485 485
             if ($this->error) {
486 486
                 $this->error_message = "AuthorizeNet Error:
487
-                Response Code: ".$this->response_code."
488
-                Response Subcode: ".$this->response_subcode."
489
-                Response Reason Code: ".$this->response_reason_code."
490
-                Response Reason Text: ".$this->response_reason_text."
487
+                Response Code: ".$this->response_code . "
488
+                Response Subcode: ".$this->response_subcode . "
489
+                Response Reason Code: ".$this->response_reason_code . "
490
+                Response Reason Text: ".$this->response_reason_text . "
491 491
                 ";
492 492
             }
493 493
         } else {
Please login to merge, or discard this patch.
includes/gateways/authorizenet/anet_php_sdk/lib/AuthorizeNetCP.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -116,27 +116,27 @@  discard block
 block discarded – undo
116 116
                 
117 117
                 $this->xml = @simplexml_load_string($response);
118 118
                 // Set all fields
119
-                $this->version              = array_pop(array_slice(explode('"', $response), 1,1));
120
-                $this->response_code        = (string)$this->xml->ResponseCode;
119
+                $this->version              = array_pop(array_slice(explode('"', $response), 1, 1));
120
+                $this->response_code        = (string) $this->xml->ResponseCode;
121 121
                 
122 122
                 if ($this->response_code == 1) {
123
-                    $this->response_reason_code = (string)$this->xml->Messages->Message->Code;
124
-                    $this->response_reason_text = (string)$this->xml->Messages->Message->Description;
123
+                    $this->response_reason_code = (string) $this->xml->Messages->Message->Code;
124
+                    $this->response_reason_text = (string) $this->xml->Messages->Message->Description;
125 125
                 } else {
126
-                    $this->response_reason_code = (string)$this->xml->Errors->Error->ErrorCode;
127
-                    $this->response_reason_text = (string)$this->xml->Errors->Error->ErrorText;
126
+                    $this->response_reason_code = (string) $this->xml->Errors->Error->ErrorCode;
127
+                    $this->response_reason_text = (string) $this->xml->Errors->Error->ErrorText;
128 128
                 }
129 129
                 
130
-                $this->authorization_code   = (string)$this->xml->AuthCode;
131
-                $this->avs_code             = (string)$this->xml->AVSResultCode;
132
-                $this->card_code_response   = (string)$this->xml->CVVResultCode;
133
-                $this->transaction_id       = (string)$this->xml->TransID;
134
-                $this->md5_hash             = (string)$this->xml->TransHash;
135
-                $this->user_ref             = (string)$this->xml->UserRef;
136
-                $this->card_num             = (string)$this->xml->AccountNumber;
137
-                $this->card_type            = (string)$this->xml->AccountType;
138
-                $this->test_mode            = (string)$this->xml->TestMode;
139
-                $this->ref_trans_id         = (string)$this->xml->RefTransID;
130
+                $this->authorization_code   = (string) $this->xml->AuthCode;
131
+                $this->avs_code             = (string) $this->xml->AVSResultCode;
132
+                $this->card_code_response   = (string) $this->xml->CVVResultCode;
133
+                $this->transaction_id       = (string) $this->xml->TransID;
134
+                $this->md5_hash             = (string) $this->xml->TransHash;
135
+                $this->user_ref             = (string) $this->xml->UserRef;
136
+                $this->card_num             = (string) $this->xml->AccountNumber;
137
+                $this->card_type            = (string) $this->xml->AccountType;
138
+                $this->test_mode            = (string) $this->xml->TestMode;
139
+                $this->ref_trans_id         = (string) $this->xml->RefTransID;
140 140
                 
141 141
                 
142 142
             } else { // If it's an NVP response
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
                 // Split Array
145 145
                 $this->response = $response;
146 146
                 if ($encap_char) {
147
-                    $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1));
147
+                    $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1));
148 148
                 } else {
149 149
                     $this->_response_array = explode($delimiter, $response);
150 150
                 }
@@ -190,9 +190,9 @@  discard block
 block discarded – undo
190 190
             
191 191
             if ($this->error) {
192 192
                 $this->error_message = "AuthorizeNet Error:
193
-                Response Code: ".$this->response_code."
194
-                Response Reason Code: ".$this->response_reason_code."
195
-                Response Reason Text: ".$this->response_reason_text."
193
+                Response Code: ".$this->response_code . "
194
+                Response Reason Code: ".$this->response_reason_code . "
195
+                Response Reason Text: ".$this->response_reason_text . "
196 196
                 ";
197 197
             }
198 198
             
Please login to merge, or discard this patch.
includes/wpinv-email-functions.php 1 patch
Spacing   +582 added lines, -582 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,381 +30,381 @@  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
-    if ( !is_email( $recipient ) ) {
235
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
236
+    if (!is_email($recipient)) {
237 237
         return false;
238 238
     }
239 239
 
240
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
240
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
241 241
 
242
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
243
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
244
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
245
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
246
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
242
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
243
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
244
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
245
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
246
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
247 247
     
248
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
248
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
249 249
             'invoice'       => $invoice,
250 250
             'email_type'    => $email_type,
251 251
             'email_heading' => $email_heading,
252 252
             'sent_to_admin' => false,
253 253
             'plain_text'    => false,
254 254
             'message_body'  => $message_body,
255
-        ) );
255
+        ));
256 256
     
257
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
257
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
258 258
     
259
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
260
-        $recipient  = wpinv_get_admin_email();
261
-        $subject    .= ' - ADMIN BCC COPY';
262
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
259
+    if (wpinv_mail_admin_bcc_active($email_type)) {
260
+        $recipient = wpinv_get_admin_email();
261
+        $subject .= ' - ADMIN BCC COPY';
262
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
263 263
     }
264 264
 
265
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
265
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
266 266
 
267 267
     return $sent;
268 268
 }
269 269
 
270
-function wpinv_processing_invoice_notification( $invoice_id, $new_status = '' ) {
270
+function wpinv_processing_invoice_notification($invoice_id, $new_status = '') {
271 271
     $email_type = 'processing_invoice';
272
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
272
+    if (!wpinv_email_is_enabled($email_type)) {
273 273
         return false;
274 274
     }
275 275
 
276
-    $invoice = wpinv_get_invoice( $invoice_id );
277
-    if ( empty( $invoice ) ) {
276
+    $invoice = wpinv_get_invoice($invoice_id);
277
+    if (empty($invoice)) {
278 278
         return false;
279 279
     }
280 280
 
281
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
281
+    if (!("wpi_invoice" === $invoice->post_type)) {
282 282
         return false;
283 283
     }
284 284
 
285
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
286
-    if ( !is_email( $recipient ) ) {
285
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
286
+    if (!is_email($recipient)) {
287 287
         return false;
288 288
     }
289 289
 
290
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
290
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
291 291
 
292 292
     $search                     = array();
293 293
     $search['invoice_number']   = '{invoice_number}';
294 294
     $search['invoice_date']     = '{invoice_date}';
295 295
     $search['name']             = '{name}';
296 296
 
297
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
298
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
299
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
300
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
301
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
297
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
298
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
299
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
300
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
301
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
302 302
     
303
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
303
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
304 304
             'invoice'       => $invoice,
305 305
             'email_type'    => $email_type,
306 306
             'email_heading' => $email_heading,
307 307
             'sent_to_admin' => false,
308 308
             'plain_text'    => false,
309 309
             'message_body'  => $message_body,
310
-        ) );
310
+        ));
311 311
 
312
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
312
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
313 313
 
314
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
315
-        $recipient  = wpinv_get_admin_email();
316
-        $subject    .= ' - ADMIN BCC COPY';
317
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
314
+    if (wpinv_mail_admin_bcc_active($email_type)) {
315
+        $recipient = wpinv_get_admin_email();
316
+        $subject .= ' - ADMIN BCC COPY';
317
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
318 318
     }
319 319
 
320
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
320
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
321 321
 
322 322
     return $sent;
323 323
 }
324 324
 
325
-function wpinv_completed_invoice_notification( $invoice_id, $new_status = '' ) {
325
+function wpinv_completed_invoice_notification($invoice_id, $new_status = '') {
326 326
     $email_type = 'completed_invoice';
327
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
327
+    if (!wpinv_email_is_enabled($email_type)) {
328 328
         return false;
329 329
     }
330 330
 
331
-    $invoice = wpinv_get_invoice( $invoice_id );
332
-    if ( empty( $invoice ) ) {
331
+    $invoice = wpinv_get_invoice($invoice_id);
332
+    if (empty($invoice)) {
333 333
         return false;
334 334
     }
335 335
 
336
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
336
+    if (!("wpi_invoice" === $invoice->post_type)) {
337 337
         return false;
338 338
     }
339 339
 
340
-    if($invoice->is_renewal() && wpinv_email_is_enabled( 'completed_invoice_renewal' )){
340
+    if ($invoice->is_renewal() && wpinv_email_is_enabled('completed_invoice_renewal')) {
341 341
         return false;
342 342
     }
343 343
 
344
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
345
-    if ( !is_email( $recipient ) ) {
344
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
345
+    if (!is_email($recipient)) {
346 346
         return false;
347 347
     }
348 348
 
349
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
349
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
350 350
 
351
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
352
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
353
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
354
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
355
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
351
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
352
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
353
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
354
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
355
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
356 356
 
357
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
357
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
358 358
             'invoice'       => $invoice,
359 359
             'email_type'    => $email_type,
360 360
             'email_heading' => $email_heading,
361 361
             'sent_to_admin' => false,
362 362
             'plain_text'    => false,
363 363
             'message_body'  => $message_body,
364
-        ) );
364
+        ));
365 365
 
366
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
366
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
367 367
 
368
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
369
-        $recipient  = wpinv_get_admin_email();
370
-        $subject    .= ' - ADMIN BCC COPY';
371
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
368
+    if (wpinv_mail_admin_bcc_active($email_type)) {
369
+        $recipient = wpinv_get_admin_email();
370
+        $subject .= ' - ADMIN BCC COPY';
371
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
372 372
     }
373 373
 
374
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
374
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
375 375
 
376 376
     return $sent;
377 377
 }
378 378
 
379
-function wpinv_fully_refunded_notification( $invoice_id, $new_status = '' ) {
379
+function wpinv_fully_refunded_notification($invoice_id, $new_status = '') {
380 380
     $email_type = 'refunded_invoice';
381
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
381
+    if (!wpinv_email_is_enabled($email_type)) {
382 382
         return false;
383 383
     }
384 384
 
385
-    $invoice = wpinv_get_invoice( $invoice_id );
386
-    if ( empty( $invoice ) ) {
385
+    $invoice = wpinv_get_invoice($invoice_id);
386
+    if (empty($invoice)) {
387 387
         return false;
388 388
     }
389 389
 
390
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
390
+    if (!("wpi_invoice" === $invoice->post_type)) {
391 391
         return false;
392 392
     }
393 393
 
394
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
395
-    if ( !is_email( $recipient ) ) {
394
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
395
+    if (!is_email($recipient)) {
396 396
         return false;
397 397
     }
398 398
 
399
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
399
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
400 400
 
401
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
402
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
403
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
404
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
405
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
401
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
402
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
403
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
404
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
405
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
406 406
 
407
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
407
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
408 408
             'invoice'           => $invoice,
409 409
             'email_type'        => $email_type,
410 410
             'email_heading'     => $email_heading,
@@ -412,50 +412,50 @@  discard block
 block discarded – undo
412 412
             'plain_text'        => false,
413 413
             'partial_refund'    => false,
414 414
             'message_body'      => $message_body,
415
-        ) );
415
+        ));
416 416
 
417
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
417
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
418 418
 
419
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
420
-        $recipient  = wpinv_get_admin_email();
421
-        $subject    .= ' - ADMIN BCC COPY';
422
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
419
+    if (wpinv_mail_admin_bcc_active($email_type)) {
420
+        $recipient = wpinv_get_admin_email();
421
+        $subject .= ' - ADMIN BCC COPY';
422
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
423 423
     }
424 424
 
425
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
425
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
426 426
 
427 427
     return $sent;
428 428
 }
429 429
 
430
-function wpinv_partially_refunded_notification( $invoice_id, $new_status = '' ) {
430
+function wpinv_partially_refunded_notification($invoice_id, $new_status = '') {
431 431
     $email_type = 'refunded_invoice';
432
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
432
+    if (!wpinv_email_is_enabled($email_type)) {
433 433
         return false;
434 434
     }
435 435
 
436
-    $invoice = wpinv_get_invoice( $invoice_id );
437
-    if ( empty( $invoice ) ) {
436
+    $invoice = wpinv_get_invoice($invoice_id);
437
+    if (empty($invoice)) {
438 438
         return false;
439 439
     }
440 440
 
441
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
441
+    if (!("wpi_invoice" === $invoice->post_type)) {
442 442
         return false;
443 443
     }
444 444
 
445
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
446
-    if ( !is_email( $recipient ) ) {
445
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
446
+    if (!is_email($recipient)) {
447 447
         return false;
448 448
     }
449 449
 
450
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
450
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
451 451
 
452
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
453
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
454
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
455
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
456
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
452
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
453
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
454
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
455
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
456
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
457 457
 
458
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
458
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
459 459
             'invoice'           => $invoice,
460 460
             'email_type'        => $email_type,
461 461
             'email_heading'     => $email_heading,
@@ -463,95 +463,95 @@  discard block
 block discarded – undo
463 463
             'plain_text'        => false,
464 464
             'partial_refund'    => true,
465 465
             'message_body'      => $message_body,
466
-        ) );
466
+        ));
467 467
 
468
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
468
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
469 469
 
470
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
471
-        $recipient  = wpinv_get_admin_email();
472
-        $subject    .= ' - ADMIN BCC COPY';
473
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
470
+    if (wpinv_mail_admin_bcc_active($email_type)) {
471
+        $recipient = wpinv_get_admin_email();
472
+        $subject .= ' - ADMIN BCC COPY';
473
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
474 474
     }
475 475
 
476
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
476
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
477 477
 
478 478
     return $sent;
479 479
 }
480 480
 
481
-function wpinv_new_invoice_note_notification( $invoice_id, $new_status = '' ) {
481
+function wpinv_new_invoice_note_notification($invoice_id, $new_status = '') {
482 482
 }
483 483
 
484
-function wpinv_user_invoice_notification( $invoice_id ) {
484
+function wpinv_user_invoice_notification($invoice_id) {
485 485
     $email_type = 'user_invoice';
486
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
486
+    if (!wpinv_email_is_enabled($email_type)) {
487 487
         return -1;
488 488
     }
489 489
 
490
-    $invoice = wpinv_get_invoice( $invoice_id );
491
-    if ( empty( $invoice ) ) {
490
+    $invoice = wpinv_get_invoice($invoice_id);
491
+    if (empty($invoice)) {
492 492
         return false;
493 493
     }
494 494
 
495
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
495
+    if (!("wpi_invoice" === $invoice->post_type)) {
496 496
         return false;
497 497
     }
498 498
 
499
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
500
-    if ( !is_email( $recipient ) ) {
499
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
500
+    if (!is_email($recipient)) {
501 501
         return false;
502 502
     }
503 503
 
504
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
504
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
505 505
 
506
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
507
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
508
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
509
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
510
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
506
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
507
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
508
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
509
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
510
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
511 511
     
512
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
512
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
513 513
             'invoice'       => $invoice,
514 514
             'email_type'    => $email_type,
515 515
             'email_heading' => $email_heading,
516 516
             'sent_to_admin' => false,
517 517
             'plain_text'    => false,
518 518
             'message_body'  => $message_body,
519
-        ) );
519
+        ));
520 520
 
521
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
521
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
522 522
 
523
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
524
-        $recipient  = wpinv_get_admin_email();
525
-        $subject    .= ' - ADMIN BCC COPY';
526
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
523
+    if (wpinv_mail_admin_bcc_active($email_type)) {
524
+        $recipient = wpinv_get_admin_email();
525
+        $subject .= ' - ADMIN BCC COPY';
526
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
527 527
     }
528 528
 
529
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
529
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
530 530
 
531
-    if ( $sent ) {
532
-        $note = __( 'Invoice has been emailed to the user.', 'invoicing' );
531
+    if ($sent) {
532
+        $note = __('Invoice has been emailed to the user.', 'invoicing');
533 533
     } else {
534
-        $note = __( 'Fail to send invoice to the user!', 'invoicing' );
534
+        $note = __('Fail to send invoice to the user!', 'invoicing');
535 535
     }
536 536
 
537
-    $invoice->add_note( $note, '', '', true ); // Add system note.
537
+    $invoice->add_note($note, '', '', true); // Add system note.
538 538
 
539 539
     return $sent;
540 540
 }
541 541
 
542
-function wpinv_user_note_notification( $invoice_id, $args = array() ) {
542
+function wpinv_user_note_notification($invoice_id, $args = array()) {
543 543
     $email_type = 'user_note';
544
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
544
+    if (!wpinv_email_is_enabled($email_type)) {
545 545
         return false;
546 546
     }
547 547
 
548
-    $invoice = wpinv_get_invoice( $invoice_id );
549
-    if ( empty( $invoice ) ) {
548
+    $invoice = wpinv_get_invoice($invoice_id);
549
+    if (empty($invoice)) {
550 550
         return false;
551 551
     }
552 552
 
553
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
554
-    if ( !is_email( $recipient ) ) {
553
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
554
+    if (!is_email($recipient)) {
555 555
         return false;
556 556
     }
557 557
 
@@ -559,19 +559,19 @@  discard block
 block discarded – undo
559 559
         'user_note' => ''
560 560
     );
561 561
 
562
-    $args = wp_parse_args( $args, $defaults );
562
+    $args = wp_parse_args($args, $defaults);
563 563
 
564
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
564
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
565 565
 
566
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
567
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
568
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
569
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
570
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
566
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
567
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
568
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
569
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
570
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
571 571
 
572
-    $message_body   = str_replace( '{customer_note}', $args['user_note'], $message_body );
572
+    $message_body   = str_replace('{customer_note}', $args['user_note'], $message_body);
573 573
 
574
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
574
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
575 575
             'invoice'       => $invoice,
576 576
             'email_type'    => $email_type,
577 577
             'email_heading' => $email_heading,
@@ -579,36 +579,36 @@  discard block
 block discarded – undo
579 579
             'plain_text'    => false,
580 580
             'message_body'  => $message_body,
581 581
             'customer_note' => $args['user_note']
582
-        ) );
582
+        ));
583 583
 
584
-    $content        = wpinv_email_format_text( $content, $invoice );
584
+    $content = wpinv_email_format_text($content, $invoice);
585 585
 
586
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
586
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
587 587
 
588
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
588
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
589 589
 
590 590
     return $sent;
591 591
 }
592 592
 
593 593
 function wpinv_mail_get_from_address() {
594
-    $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) );
595
-    return sanitize_email( $from_address );
594
+    $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from'));
595
+    return sanitize_email($from_address);
596 596
 }
597 597
 
598 598
 function wpinv_mail_get_from_name() {
599
-    $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) );
600
-    return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES );
599
+    $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name'));
600
+    return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES);
601 601
 }
602 602
 
603
-function wpinv_mail_admin_bcc_active( $mail_type = '' ) {
604
-    $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) );
605
-    return ( $active ? true : false );
603
+function wpinv_mail_admin_bcc_active($mail_type = '') {
604
+    $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc'));
605
+    return ($active ? true : false);
606 606
 }
607 607
     
608
-function wpinv_mail_get_content_type(  $content_type = 'text/html', $email_type = 'html' ) {
609
-    $email_type = apply_filters( 'wpinv_mail_content_type', $email_type );
608
+function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') {
609
+    $email_type = apply_filters('wpinv_mail_content_type', $email_type);
610 610
 
611
-    switch ( $email_type ) {
611
+    switch ($email_type) {
612 612
         case 'html' :
613 613
             $content_type = 'text/html';
614 614
             break;
@@ -623,35 +623,35 @@  discard block
 block discarded – undo
623 623
     return $content_type;
624 624
 }
625 625
     
626
-function wpinv_mail_send( $to, $subject, $message, $headers, $attachments ) {
627
-    add_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
628
-    add_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
629
-    add_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
626
+function wpinv_mail_send($to, $subject, $message, $headers, $attachments) {
627
+    add_filter('wp_mail_from', 'wpinv_mail_get_from_address');
628
+    add_filter('wp_mail_from_name', 'wpinv_mail_get_from_name');
629
+    add_filter('wp_mail_content_type', 'wpinv_mail_get_content_type');
630 630
 
631
-    $message = wpinv_email_style_body( $message );
632
-    $message = apply_filters( 'wpinv_mail_content', $message );
631
+    $message = wpinv_email_style_body($message);
632
+    $message = apply_filters('wpinv_mail_content', $message);
633 633
 
634
-    $sent  = wp_mail( $to, $subject, $message, $headers, $attachments );
634
+    $sent = wp_mail($to, $subject, $message, $headers, $attachments);
635 635
 
636
-    if ( !$sent ) {
637
-        $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 );
638
-        wpinv_error_log( $log_message, __( "Email from Invoicing plugin failed to send", 'invoicing' ), __FILE__, __LINE__ );
636
+    if (!$sent) {
637
+        $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);
638
+        wpinv_error_log($log_message, __("Email from Invoicing plugin failed to send", 'invoicing'), __FILE__, __LINE__);
639 639
     }
640 640
 
641
-    remove_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
642
-    remove_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
643
-    remove_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
641
+    remove_filter('wp_mail_from', 'wpinv_mail_get_from_address');
642
+    remove_filter('wp_mail_from_name', 'wpinv_mail_get_from_name');
643
+    remove_filter('wp_mail_content_type', 'wpinv_mail_get_content_type');
644 644
 
645 645
     return $sent;
646 646
 }
647 647
     
648 648
 function wpinv_get_emails() {
649 649
     $overdue_days_options       = array();
650
-    $overdue_days_options[0]    = __( 'On the Due Date', 'invoicing' );
651
-    $overdue_days_options[1]    = __( '1 day after Due Date', 'invoicing' );
650
+    $overdue_days_options[0]    = __('On the Due Date', 'invoicing');
651
+    $overdue_days_options[1]    = __('1 day after Due Date', 'invoicing');
652 652
 
653
-    for ( $i = 2; $i <= 10; $i++ ) {
654
-        $overdue_days_options[$i]   = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i );
653
+    for ($i = 2; $i <= 10; $i++) {
654
+        $overdue_days_options[$i] = wp_sprintf(__('%d days after Due Date', 'invoicing'), $i);
655 655
     }
656 656
 
657 657
     // Default, built-in gateways
@@ -659,39 +659,39 @@  discard block
 block discarded – undo
659 659
             'new_invoice' => array(
660 660
             'email_new_invoice_header' => array(
661 661
                 'id'   => 'email_new_invoice_header',
662
-                'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>',
663
-                'desc' => __( 'New invoice emails are sent to admin when a new invoice is received.', 'invoicing' ),
662
+                'name' => '<h3>' . __('New Invoice', 'invoicing') . '</h3>',
663
+                'desc' => __('New invoice emails are sent to admin when a new invoice is received.', 'invoicing'),
664 664
                 'type' => 'header',
665 665
             ),
666 666
             'email_new_invoice_active' => array(
667 667
                 'id'   => 'email_new_invoice_active',
668
-                'name' => __( 'Enable/Disable', 'invoicing' ),
669
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
668
+                'name' => __('Enable/Disable', 'invoicing'),
669
+                'desc' => __('Enable this email notification', 'invoicing'),
670 670
                 'type' => 'checkbox',
671 671
                 'std'  => 1
672 672
             ),
673 673
             'email_new_invoice_subject' => array(
674 674
                 'id'   => 'email_new_invoice_subject',
675
-                'name' => __( 'Subject', 'invoicing' ),
676
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
675
+                'name' => __('Subject', 'invoicing'),
676
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
677 677
                 'type' => 'text',
678
-                'std'  => __( '[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing' ),
678
+                'std'  => __('[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing'),
679 679
                 'size' => 'large'
680 680
             ),
681 681
             'email_new_invoice_heading' => array(
682 682
                 'id'   => 'email_new_invoice_heading',
683
-                'name' => __( 'Email Heading', 'invoicing' ),
684
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
683
+                'name' => __('Email Heading', 'invoicing'),
684
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
685 685
                 'type' => 'text',
686
-                'std'  => __( 'New payment invoice', 'invoicing' ),
686
+                'std'  => __('New payment invoice', 'invoicing'),
687 687
                 'size' => 'large'
688 688
             ),
689 689
             'email_new_invoice_body' => array(
690 690
                 'id'   => 'email_new_invoice_body',
691
-                'name' => __( 'Email Content', 'invoicing' ),
692
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
691
+                'name' => __('Email Content', 'invoicing'),
692
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
693 693
                 'type' => 'rich_editor',
694
-                'std'  => __( '<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing' ),
694
+                'std'  => __('<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing'),
695 695
                 'class' => 'large',
696 696
                 'size' => '10'
697 697
             ),
@@ -699,39 +699,39 @@  discard block
 block discarded – undo
699 699
         'cancelled_invoice' => array(
700 700
             'email_cancelled_invoice_header' => array(
701 701
                 'id'   => 'email_cancelled_invoice_header',
702
-                'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>',
703
-                'desc' => __( 'Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing' ),
702
+                'name' => '<h3>' . __('Cancelled Invoice', 'invoicing') . '</h3>',
703
+                'desc' => __('Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing'),
704 704
                 'type' => 'header',
705 705
             ),
706 706
             'email_cancelled_invoice_active' => array(
707 707
                 'id'   => 'email_cancelled_invoice_active',
708
-                'name' => __( 'Enable/Disable', 'invoicing' ),
709
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
708
+                'name' => __('Enable/Disable', 'invoicing'),
709
+                'desc' => __('Enable this email notification', 'invoicing'),
710 710
                 'type' => 'checkbox',
711 711
                 'std'  => 1
712 712
             ),
713 713
             'email_cancelled_invoice_subject' => array(
714 714
                 'id'   => 'email_cancelled_invoice_subject',
715
-                'name' => __( 'Subject', 'invoicing' ),
716
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
715
+                'name' => __('Subject', 'invoicing'),
716
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
717 717
                 'type' => 'text',
718
-                'std'  => __( '[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing' ),
718
+                'std'  => __('[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing'),
719 719
                 'size' => 'large'
720 720
             ),
721 721
             'email_cancelled_invoice_heading' => array(
722 722
                 'id'   => 'email_cancelled_invoice_heading',
723
-                'name' => __( 'Email Heading', 'invoicing' ),
724
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
723
+                'name' => __('Email Heading', 'invoicing'),
724
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
725 725
                 'type' => 'text',
726
-                'std'  => __( 'Cancelled invoice', 'invoicing' ),
726
+                'std'  => __('Cancelled invoice', 'invoicing'),
727 727
                 'size' => 'large'
728 728
             ),
729 729
             'email_cancelled_invoice_body' => array(
730 730
                 'id'   => 'email_cancelled_invoice_body',
731
-                'name' => __( 'Email Content', 'invoicing' ),
732
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
731
+                'name' => __('Email Content', 'invoicing'),
732
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
733 733
                 'type' => 'rich_editor',
734
-                'std'  => __( '<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing' ),
734
+                'std'  => __('<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing'),
735 735
                 'class' => 'large',
736 736
                 'size' => '10'
737 737
             ),
@@ -739,39 +739,39 @@  discard block
 block discarded – undo
739 739
         'failed_invoice' => array(
740 740
             'email_failed_invoice_header' => array(
741 741
                 'id'   => 'email_failed_invoice_header',
742
-                'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>',
743
-                'desc' => __( 'Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing' ),
742
+                'name' => '<h3>' . __('Failed Invoice', 'invoicing') . '</h3>',
743
+                'desc' => __('Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing'),
744 744
                 'type' => 'header',
745 745
             ),
746 746
             'email_failed_invoice_active' => array(
747 747
                 'id'   => 'email_failed_invoice_active',
748
-                'name' => __( 'Enable/Disable', 'invoicing' ),
749
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
748
+                'name' => __('Enable/Disable', 'invoicing'),
749
+                'desc' => __('Enable this email notification', 'invoicing'),
750 750
                 'type' => 'checkbox',
751 751
                 'std'  => 1
752 752
             ),
753 753
             'email_failed_invoice_subject' => array(
754 754
                 'id'   => 'email_failed_invoice_subject',
755
-                'name' => __( 'Subject', 'invoicing' ),
756
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
755
+                'name' => __('Subject', 'invoicing'),
756
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
757 757
                 'type' => 'text',
758
-                'std'  => __( '[{site_title}] Failed invoice ({invoice_number})', 'invoicing' ),
758
+                'std'  => __('[{site_title}] Failed invoice ({invoice_number})', 'invoicing'),
759 759
                 'size' => 'large'
760 760
             ),
761 761
             'email_failed_invoice_heading' => array(
762 762
                 'id'   => 'email_failed_invoice_heading',
763
-                'name' => __( 'Email Heading', 'invoicing' ),
764
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
763
+                'name' => __('Email Heading', 'invoicing'),
764
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
765 765
                 'type' => 'text',
766
-                'std'  => __( 'Failed invoice', 'invoicing' ),
766
+                'std'  => __('Failed invoice', 'invoicing'),
767 767
                 'size' => 'large'
768 768
             ),
769 769
             'email_failed_invoice_body' => array(
770 770
                 'id'   => 'email_failed_invoice_body',
771
-                'name' => __( 'Email Content', 'invoicing' ),
772
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
771
+                'name' => __('Email Content', 'invoicing'),
772
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
773 773
                 'type' => 'rich_editor',
774
-                'std'  => __( '<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing' ),
774
+                'std'  => __('<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing'),
775 775
                 'class' => 'large',
776 776
                 'size' => '10'
777 777
             ),
@@ -779,46 +779,46 @@  discard block
 block discarded – undo
779 779
         'onhold_invoice' => array(
780 780
             'email_onhold_invoice_header' => array(
781 781
                 'id'   => 'email_onhold_invoice_header',
782
-                'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>',
783
-                'desc' => __( 'This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing' ),
782
+                'name' => '<h3>' . __('On Hold Invoice', 'invoicing') . '</h3>',
783
+                'desc' => __('This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing'),
784 784
                 'type' => 'header',
785 785
             ),
786 786
             'email_onhold_invoice_active' => array(
787 787
                 'id'   => 'email_onhold_invoice_active',
788
-                'name' => __( 'Enable/Disable', 'invoicing' ),
789
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
788
+                'name' => __('Enable/Disable', 'invoicing'),
789
+                'desc' => __('Enable this email notification', 'invoicing'),
790 790
                 'type' => 'checkbox',
791 791
                 'std'  => 1
792 792
             ),
793 793
             'email_onhold_invoice_subject' => array(
794 794
                 'id'   => 'email_onhold_invoice_subject',
795
-                'name' => __( 'Subject', 'invoicing' ),
796
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
795
+                'name' => __('Subject', 'invoicing'),
796
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
797 797
                 'type' => 'text',
798
-                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
798
+                'std'  => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'),
799 799
                 'size' => 'large'
800 800
             ),
801 801
             'email_onhold_invoice_heading' => array(
802 802
                 'id'   => 'email_onhold_invoice_heading',
803
-                'name' => __( 'Email Heading', 'invoicing' ),
804
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
803
+                'name' => __('Email Heading', 'invoicing'),
804
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
805 805
                 'type' => 'text',
806
-                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
806
+                'std'  => __('Thank you for your invoice', 'invoicing'),
807 807
                 'size' => 'large'
808 808
             ),
809 809
             'email_onhold_invoice_admin_bcc' => array(
810 810
                 'id'   => 'email_onhold_invoice_admin_bcc',
811
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
812
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
811
+                'name' => __('Enable Admin BCC', 'invoicing'),
812
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
813 813
                 'type' => 'checkbox',
814 814
                 'std'  => 1
815 815
             ),
816 816
             'email_onhold_invoice_body' => array(
817 817
                 'id'   => 'email_onhold_invoice_body',
818
-                'name' => __( 'Email Content', 'invoicing' ),
819
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
818
+                'name' => __('Email Content', 'invoicing'),
819
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
820 820
                 'type' => 'rich_editor',
821
-                'std'  => __( '<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing' ),
821
+                'std'  => __('<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing'),
822 822
                 'class' => 'large',
823 823
                 'size' => '10'
824 824
             ),
@@ -826,46 +826,46 @@  discard block
 block discarded – undo
826 826
         'processing_invoice' => array(
827 827
             'email_processing_invoice_header' => array(
828 828
                 'id'   => 'email_processing_invoice_header',
829
-                'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>',
830
-                'desc' => __( 'This is an invoice notification sent to users containing invoice details after payment.', 'invoicing' ),
829
+                'name' => '<h3>' . __('Processing Invoice', 'invoicing') . '</h3>',
830
+                'desc' => __('This is an invoice notification sent to users containing invoice details after payment.', 'invoicing'),
831 831
                 'type' => 'header',
832 832
             ),
833 833
             'email_processing_invoice_active' => array(
834 834
                 'id'   => 'email_processing_invoice_active',
835
-                'name' => __( 'Enable/Disable', 'invoicing' ),
836
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
835
+                'name' => __('Enable/Disable', 'invoicing'),
836
+                'desc' => __('Enable this email notification', 'invoicing'),
837 837
                 'type' => 'checkbox',
838 838
                 'std'  => 1
839 839
             ),
840 840
             'email_processing_invoice_subject' => array(
841 841
                 'id'   => 'email_processing_invoice_subject',
842
-                'name' => __( 'Subject', 'invoicing' ),
843
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
842
+                'name' => __('Subject', 'invoicing'),
843
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
844 844
                 'type' => 'text',
845
-                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
845
+                'std'  => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'),
846 846
                 'size' => 'large'
847 847
             ),
848 848
             'email_processing_invoice_heading' => array(
849 849
                 'id'   => 'email_processing_invoice_heading',
850
-                'name' => __( 'Email Heading', 'invoicing' ),
851
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
850
+                'name' => __('Email Heading', 'invoicing'),
851
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
852 852
                 'type' => 'text',
853
-                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
853
+                'std'  => __('Thank you for your invoice', 'invoicing'),
854 854
                 'size' => 'large'
855 855
             ),
856 856
             'email_processing_invoice_admin_bcc' => array(
857 857
                 'id'   => 'email_processing_invoice_admin_bcc',
858
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
859
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
858
+                'name' => __('Enable Admin BCC', 'invoicing'),
859
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
860 860
                 'type' => 'checkbox',
861 861
                 'std'  => 1
862 862
             ),
863 863
             'email_processing_invoice_body' => array(
864 864
                 'id'   => 'email_processing_invoice_body',
865
-                'name' => __( 'Email Content', 'invoicing' ),
866
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
865
+                'name' => __('Email Content', 'invoicing'),
866
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
867 867
                 'type' => 'rich_editor',
868
-                'std'  => __( '<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing' ),
868
+                'std'  => __('<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing'),
869 869
                 'class' => 'large',
870 870
                 'size' => '10'
871 871
             ),
@@ -873,52 +873,52 @@  discard block
 block discarded – undo
873 873
         'completed_invoice' => array(
874 874
             'email_completed_invoice_header' => array(
875 875
                 'id'   => 'email_completed_invoice_header',
876
-                'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>',
877
-                'desc' => __( 'Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing' ),
876
+                'name' => '<h3>' . __('Paid Invoice', 'invoicing') . '</h3>',
877
+                'desc' => __('Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing'),
878 878
                 'type' => 'header',
879 879
             ),
880 880
             'email_completed_invoice_active' => array(
881 881
                 'id'   => 'email_completed_invoice_active',
882
-                'name' => __( 'Enable/Disable', 'invoicing' ),
883
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
882
+                'name' => __('Enable/Disable', 'invoicing'),
883
+                'desc' => __('Enable this email notification', 'invoicing'),
884 884
                 'type' => 'checkbox',
885 885
                 'std'  => 1
886 886
             ),
887 887
             'email_completed_invoice_renewal_active' => array(
888 888
                 'id'   => 'email_completed_invoice_renewal_active',
889
-                'name' => __( 'Enable renewal notification', 'invoicing' ),
890
-                'desc' => __( 'Enable renewal invoice email notification. This notification will be sent on renewal.', 'invoicing' ),
889
+                'name' => __('Enable renewal notification', 'invoicing'),
890
+                'desc' => __('Enable renewal invoice email notification. This notification will be sent on renewal.', 'invoicing'),
891 891
                 'type' => 'checkbox',
892 892
                 'std'  => 0
893 893
             ),
894 894
             'email_completed_invoice_subject' => array(
895 895
                 'id'   => 'email_completed_invoice_subject',
896
-                'name' => __( 'Subject', 'invoicing' ),
897
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
896
+                'name' => __('Subject', 'invoicing'),
897
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
898 898
                 'type' => 'text',
899
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ),
899
+                'std'  => __('[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing'),
900 900
                 'size' => 'large'
901 901
             ),
902 902
             'email_completed_invoice_heading' => array(
903 903
                 'id'   => 'email_completed_invoice_heading',
904
-                'name' => __( 'Email Heading', 'invoicing' ),
905
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
904
+                'name' => __('Email Heading', 'invoicing'),
905
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
906 906
                 'type' => 'text',
907
-                'std'  => __( 'Your invoice has been paid', 'invoicing' ),
907
+                'std'  => __('Your invoice has been paid', 'invoicing'),
908 908
                 'size' => 'large'
909 909
             ),
910 910
             'email_completed_invoice_admin_bcc' => array(
911 911
                 'id'   => 'email_completed_invoice_admin_bcc',
912
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
913
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
912
+                'name' => __('Enable Admin BCC', 'invoicing'),
913
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
914 914
                 'type' => 'checkbox',
915 915
             ),
916 916
             'email_completed_invoice_body' => array(
917 917
                 'id'   => 'email_completed_invoice_body',
918
-                'name' => __( 'Email Content', 'invoicing' ),
919
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
918
+                'name' => __('Email Content', 'invoicing'),
919
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
920 920
                 'type' => 'rich_editor',
921
-                'std'  => __( '<p>Hi {name},</p><p>Your recent invoice on {site_title} has been paid.</p>', 'invoicing' ),
921
+                'std'  => __('<p>Hi {name},</p><p>Your recent invoice on {site_title} has been paid.</p>', 'invoicing'),
922 922
                 'class' => 'large',
923 923
                 'size' => '10'
924 924
             ),
@@ -927,46 +927,46 @@  discard block
 block discarded – undo
927 927
         'refunded_invoice' => array(
928 928
             'email_refunded_invoice_header' => array(
929 929
                 'id'   => 'email_refunded_invoice_header',
930
-                'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>',
931
-                'desc' => __( 'Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing' ),
930
+                'name' => '<h3>' . __('Refunded Invoice', 'invoicing') . '</h3>',
931
+                'desc' => __('Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing'),
932 932
                 'type' => 'header',
933 933
             ),
934 934
             'email_refunded_invoice_active' => array(
935 935
                 'id'   => 'email_refunded_invoice_active',
936
-                'name' => __( 'Enable/Disable', 'invoicing' ),
937
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
936
+                'name' => __('Enable/Disable', 'invoicing'),
937
+                'desc' => __('Enable this email notification', 'invoicing'),
938 938
                 'type' => 'checkbox',
939 939
                 'std'  => 1
940 940
             ),
941 941
             'email_refunded_invoice_subject' => array(
942 942
                 'id'   => 'email_refunded_invoice_subject',
943
-                'name' => __( 'Subject', 'invoicing' ),
944
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
943
+                'name' => __('Subject', 'invoicing'),
944
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
945 945
                 'type' => 'text',
946
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ),
946
+                'std'  => __('[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing'),
947 947
                 'size' => 'large'
948 948
             ),
949 949
             'email_refunded_invoice_heading' => array(
950 950
                 'id'   => 'email_refunded_invoice_heading',
951
-                'name' => __( 'Email Heading', 'invoicing' ),
952
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
951
+                'name' => __('Email Heading', 'invoicing'),
952
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
953 953
                 'type' => 'text',
954
-                'std'  => __( 'Your invoice has been refunded', 'invoicing' ),
954
+                'std'  => __('Your invoice has been refunded', 'invoicing'),
955 955
                 'size' => 'large'
956 956
             ),
957 957
             'email_refunded_invoice_admin_bcc' => array(
958 958
                 'id'   => 'email_refunded_invoice_admin_bcc',
959
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
960
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
959
+                'name' => __('Enable Admin BCC', 'invoicing'),
960
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
961 961
                 'type' => 'checkbox',
962 962
                 'std'  => 1
963 963
             ),
964 964
             'email_refunded_invoice_body' => array(
965 965
                 'id'   => 'email_refunded_invoice_body',
966
-                'name' => __( 'Email Content', 'invoicing' ),
967
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
966
+                'name' => __('Email Content', 'invoicing'),
967
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
968 968
                 'type' => 'rich_editor',
969
-                'std'  => __( '<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing' ),
969
+                'std'  => __('<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing'),
970 970
                 'class' => 'large',
971 971
                 'size' => '10'
972 972
             ),
@@ -974,46 +974,46 @@  discard block
 block discarded – undo
974 974
         'user_invoice' => array(
975 975
             'email_user_invoice_header' => array(
976 976
                 'id'   => 'email_user_invoice_header',
977
-                'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>',
978
-                'desc' => __( 'Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing' ),
977
+                'name' => '<h3>' . __('Customer Invoice', 'invoicing') . '</h3>',
978
+                'desc' => __('Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing'),
979 979
                 'type' => 'header',
980 980
             ),
981 981
             'email_user_invoice_active' => array(
982 982
                 'id'   => 'email_user_invoice_active',
983
-                'name' => __( 'Enable/Disable', 'invoicing' ),
984
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
983
+                'name' => __('Enable/Disable', 'invoicing'),
984
+                'desc' => __('Enable this email notification', 'invoicing'),
985 985
                 'type' => 'checkbox',
986 986
                 'std'  => 1
987 987
             ),
988 988
             'email_user_invoice_subject' => array(
989 989
                 'id'   => 'email_user_invoice_subject',
990
-                'name' => __( 'Subject', 'invoicing' ),
991
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
990
+                'name' => __('Subject', 'invoicing'),
991
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
992 992
                 'type' => 'text',
993
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ),
993
+                'std'  => __('[{site_title}] Your invoice from {invoice_date}', 'invoicing'),
994 994
                 'size' => 'large'
995 995
             ),
996 996
             'email_user_invoice_heading' => array(
997 997
                 'id'   => 'email_user_invoice_heading',
998
-                'name' => __( 'Email Heading', 'invoicing' ),
999
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
998
+                'name' => __('Email Heading', 'invoicing'),
999
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
1000 1000
                 'type' => 'text',
1001
-                'std'  => __( 'Your invoice {invoice_number} details', 'invoicing' ),
1001
+                'std'  => __('Your invoice {invoice_number} details', 'invoicing'),
1002 1002
                 'size' => 'large'
1003 1003
             ),
1004 1004
             'email_user_invoice_admin_bcc' => array(
1005 1005
                 'id'   => 'email_user_invoice_admin_bcc',
1006
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
1007
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
1006
+                'name' => __('Enable Admin BCC', 'invoicing'),
1007
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
1008 1008
                 'type' => 'checkbox',
1009 1009
                 'std'  => 1
1010 1010
             ),
1011 1011
             'email_user_invoice_body' => array(
1012 1012
                 'id'   => 'email_user_invoice_body',
1013
-                'name' => __( 'Email Content', 'invoicing' ),
1014
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
1013
+                'name' => __('Email Content', 'invoicing'),
1014
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
1015 1015
                 'type' => 'rich_editor',
1016
-                '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' ),
1016
+                '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'),
1017 1017
                 'class' => 'large',
1018 1018
                 'size' => '10'
1019 1019
             ),
@@ -1021,39 +1021,39 @@  discard block
 block discarded – undo
1021 1021
         'user_note' => array(
1022 1022
             'email_user_note_header' => array(
1023 1023
                 'id'   => 'email_user_note_header',
1024
-                'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>',
1025
-                'desc' => __( 'Customer note emails are sent when you add a note to an invoice/quote.', 'invoicing' ),
1024
+                'name' => '<h3>' . __('Customer Note', 'invoicing') . '</h3>',
1025
+                'desc' => __('Customer note emails are sent when you add a note to an invoice/quote.', 'invoicing'),
1026 1026
                 'type' => 'header',
1027 1027
             ),
1028 1028
             'email_user_note_active' => array(
1029 1029
                 'id'   => 'email_user_note_active',
1030
-                'name' => __( 'Enable/Disable', 'invoicing' ),
1031
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
1030
+                'name' => __('Enable/Disable', 'invoicing'),
1031
+                'desc' => __('Enable this email notification', 'invoicing'),
1032 1032
                 'type' => 'checkbox',
1033 1033
                 'std'  => 1
1034 1034
             ),
1035 1035
             'email_user_note_subject' => array(
1036 1036
                 'id'   => 'email_user_note_subject',
1037
-                'name' => __( 'Subject', 'invoicing' ),
1038
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1037
+                'name' => __('Subject', 'invoicing'),
1038
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
1039 1039
                 'type' => 'text',
1040
-                'std'  => __( '[{site_title}] Note added to your {invoice_label} #{invoice_number} from {invoice_date}', 'invoicing' ),
1040
+                'std'  => __('[{site_title}] Note added to your {invoice_label} #{invoice_number} from {invoice_date}', 'invoicing'),
1041 1041
                 'size' => 'large'
1042 1042
             ),
1043 1043
             'email_user_note_heading' => array(
1044 1044
                 'id'   => 'email_user_note_heading',
1045
-                'name' => __( 'Email Heading', 'invoicing' ),
1046
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1045
+                'name' => __('Email Heading', 'invoicing'),
1046
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
1047 1047
                 'type' => 'text',
1048
-                'std'  => __( 'A note has been added to your {invoice_label}', 'invoicing' ),
1048
+                'std'  => __('A note has been added to your {invoice_label}', 'invoicing'),
1049 1049
                 'size' => 'large'
1050 1050
             ),
1051 1051
             'email_user_note_body' => array(
1052 1052
                 'id'   => 'email_user_note_body',
1053
-                'name' => __( 'Email Content', 'invoicing' ),
1054
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
1053
+                'name' => __('Email Content', 'invoicing'),
1054
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
1055 1055
                 'type' => 'rich_editor',
1056
-                'std'  => __( '<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing' ),
1056
+                'std'  => __('<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing'),
1057 1057
                 'class' => 'large',
1058 1058
                 'size' => '10'
1059 1059
             ),
@@ -1061,158 +1061,158 @@  discard block
 block discarded – undo
1061 1061
         'overdue' => array(
1062 1062
             'email_overdue_header' => array(
1063 1063
                 'id'   => 'email_overdue_header',
1064
-                'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>',
1065
-                'desc' => __( 'Payment reminder emails are sent to user automatically.', 'invoicing' ),
1064
+                'name' => '<h3>' . __('Payment Reminder', 'invoicing') . '</h3>',
1065
+                'desc' => __('Payment reminder emails are sent to user automatically.', 'invoicing'),
1066 1066
                 'type' => 'header',
1067 1067
             ),
1068 1068
             'email_overdue_active' => array(
1069 1069
                 'id'   => 'email_overdue_active',
1070
-                'name' => __( 'Enable/Disable', 'invoicing' ),
1071
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
1070
+                'name' => __('Enable/Disable', 'invoicing'),
1071
+                'desc' => __('Enable this email notification', 'invoicing'),
1072 1072
                 'type' => 'checkbox',
1073 1073
                 'std'  => 1
1074 1074
             ),
1075 1075
             'email_due_reminder_days' => array(
1076 1076
                 'id'        => 'email_due_reminder_days',
1077
-                'name'      => __( 'When to Send', 'invoicing' ),
1078
-                'desc'      => __( 'Check when you would like payment reminders sent out.', 'invoicing' ),
1077
+                'name'      => __('When to Send', 'invoicing'),
1078
+                'desc'      => __('Check when you would like payment reminders sent out.', 'invoicing'),
1079 1079
                 'default'   => '',
1080 1080
                 'type'      => 'multicheck',
1081 1081
                 'options'   => $overdue_days_options,
1082 1082
             ),
1083 1083
             'email_overdue_subject' => array(
1084 1084
                 'id'   => 'email_overdue_subject',
1085
-                'name' => __( 'Subject', 'invoicing' ),
1086
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1085
+                'name' => __('Subject', 'invoicing'),
1086
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
1087 1087
                 'type' => 'text',
1088
-                'std'  => __( '[{site_title}] Payment Reminder', 'invoicing' ),
1088
+                'std'  => __('[{site_title}] Payment Reminder', 'invoicing'),
1089 1089
                 'size' => 'large'
1090 1090
             ),
1091 1091
             'email_overdue_heading' => array(
1092 1092
                 'id'   => 'email_overdue_heading',
1093
-                'name' => __( 'Email Heading', 'invoicing' ),
1094
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1093
+                'name' => __('Email Heading', 'invoicing'),
1094
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
1095 1095
                 'type' => 'text',
1096
-                'std'  => __( 'Payment reminder for your invoice', 'invoicing' ),
1096
+                'std'  => __('Payment reminder for your invoice', 'invoicing'),
1097 1097
                 'size' => 'large'
1098 1098
             ),
1099 1099
             'email_overdue_body' => array(
1100 1100
                 'id'   => 'email_overdue_body',
1101
-                'name' => __( 'Email Content', 'invoicing' ),
1102
-                'desc' => __( 'The content of the email.', 'invoicing' ),
1101
+                'name' => __('Email Content', 'invoicing'),
1102
+                'desc' => __('The content of the email.', 'invoicing'),
1103 1103
                 'type' => 'rich_editor',
1104
-                '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' ),
1104
+                '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'),
1105 1105
                 'class' => 'large',
1106 1106
                 'size'  => 10,
1107 1107
             ),
1108 1108
         ),
1109 1109
     );
1110 1110
 
1111
-    return apply_filters( 'wpinv_get_emails', $emails );
1111
+    return apply_filters('wpinv_get_emails', $emails);
1112 1112
 }
1113 1113
 
1114
-function wpinv_settings_emails( $settings = array() ) {
1114
+function wpinv_settings_emails($settings = array()) {
1115 1115
     $emails = wpinv_get_emails();
1116 1116
 
1117
-    if ( !empty( $emails ) ) {
1118
-        foreach ( $emails as $key => $email ) {
1117
+    if (!empty($emails)) {
1118
+        foreach ($emails as $key => $email) {
1119 1119
             $settings[$key] = $email;
1120 1120
         }
1121 1121
     }
1122 1122
 
1123
-    return apply_filters( 'wpinv_settings_get_emails', $settings );
1123
+    return apply_filters('wpinv_settings_get_emails', $settings);
1124 1124
 }
1125
-add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 );
1125
+add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1);
1126 1126
 
1127
-function wpinv_settings_sections_emails( $settings ) {
1127
+function wpinv_settings_sections_emails($settings) {
1128 1128
     $emails = wpinv_get_emails();
1129 1129
 
1130 1130
     if (!empty($emails)) {
1131
-        foreach  ($emails as $key => $email) {
1132
-            $settings[$key] = !empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : $key;
1131
+        foreach ($emails as $key => $email) {
1132
+            $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : $key;
1133 1133
         }
1134 1134
     }
1135 1135
 
1136 1136
     return $settings;    
1137 1137
 }
1138
-add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 );
1138
+add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1);
1139 1139
 
1140
-function wpinv_email_is_enabled( $email_type ) {
1140
+function wpinv_email_is_enabled($email_type) {
1141 1141
     $emails = wpinv_get_emails();
1142
-    $enabled = isset( $emails[$email_type] ) && wpinv_get_option( 'email_'. $email_type . '_active', 0 ) ? true : false;
1142
+    $enabled = isset($emails[$email_type]) && wpinv_get_option('email_' . $email_type . '_active', 0) ? true : false;
1143 1143
 
1144
-    return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type );
1144
+    return apply_filters('wpinv_email_is_enabled', $enabled, $email_type);
1145 1145
 }
1146 1146
 
1147
-function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1148
-    switch ( $email_type ) {
1147
+function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) {
1148
+    switch ($email_type) {
1149 1149
         case 'new_invoice':
1150 1150
         case 'cancelled_invoice':
1151 1151
         case 'failed_invoice':
1152 1152
             $recipient  = wpinv_get_admin_email();
1153 1153
         break;
1154 1154
         default:
1155
-            $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1156
-            $recipient  = !empty( $invoice ) ? $invoice->get_email() : '';
1155
+            $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1156
+            $recipient  = !empty($invoice) ? $invoice->get_email() : '';
1157 1157
         break;
1158 1158
     }
1159 1159
 
1160
-    return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice );
1160
+    return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice);
1161 1161
 }
1162 1162
 
1163
-function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1164
-    $subject    = wpinv_get_option( 'email_' . $email_type . '_subject' );
1165
-    $subject    = __( $subject, 'invoicing' );
1163
+function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) {
1164
+    $subject    = wpinv_get_option('email_' . $email_type . '_subject');
1165
+    $subject    = __($subject, 'invoicing');
1166 1166
 
1167
-    $subject    = wpinv_email_format_text( $subject, $invoice );
1167
+    $subject    = wpinv_email_format_text($subject, $invoice);
1168 1168
 
1169
-    return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice );
1169
+    return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice);
1170 1170
 }
1171 1171
 
1172
-function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1173
-    $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' );
1174
-    $email_heading = __( $email_heading, 'invoicing' );
1172
+function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) {
1173
+    $email_heading = wpinv_get_option('email_' . $email_type . '_heading');
1174
+    $email_heading = __($email_heading, 'invoicing');
1175 1175
 
1176
-    $email_heading = wpinv_email_format_text( $email_heading, $invoice );
1176
+    $email_heading = wpinv_email_format_text($email_heading, $invoice);
1177 1177
 
1178
-    return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice );
1178
+    return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice);
1179 1179
 }
1180 1180
 
1181
-function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1182
-    $content    = wpinv_get_option( 'email_' . $email_type . '_body' );
1183
-    $content    = __( $content, 'invoicing' );
1181
+function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) {
1182
+    $content    = wpinv_get_option('email_' . $email_type . '_body');
1183
+    $content    = __($content, 'invoicing');
1184 1184
 
1185
-    $content    = wpinv_email_format_text( $content, $invoice );
1185
+    $content    = wpinv_email_format_text($content, $invoice);
1186 1186
 
1187
-    return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice );
1187
+    return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice);
1188 1188
 }
1189 1189
 
1190
-function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1190
+function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) {
1191 1191
     $from_name = wpinv_mail_get_from_address();
1192 1192
     $from_email = wpinv_mail_get_from_address();
1193 1193
     
1194
-    $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1194
+    $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1195 1195
     
1196
-    $headers    = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
1197
-    $headers    .= "Reply-To: ". $from_email . "\r\n";
1196
+    $headers    = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n";
1197
+    $headers    .= "Reply-To: " . $from_email . "\r\n";
1198 1198
     $headers    .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n";
1199 1199
     
1200
-    return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice );
1200
+    return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice);
1201 1201
 }
1202 1202
 
1203
-function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1203
+function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) {
1204 1204
     $attachments = array();
1205 1205
     
1206
-    return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice );
1206
+    return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice);
1207 1207
 }
1208 1208
 
1209
-function wpinv_email_format_text( $content, $invoice ) {
1209
+function wpinv_email_format_text($content, $invoice) {
1210 1210
     $replace_array = array(
1211 1211
         '{site_title}'      => wpinv_get_blogname(),
1212
-        '{date}'            => date_i18n( get_option( 'date_format' ), (int) current_time( 'timestamp' ) ),
1212
+        '{date}'            => date_i18n(get_option('date_format'), (int) current_time('timestamp')),
1213 1213
     );
1214 1214
     
1215
-    if ( !empty( $invoice->ID ) ) {
1215
+    if (!empty($invoice->ID)) {
1216 1216
         $replace_array = array_merge(
1217 1217
             $replace_array, 
1218 1218
             array(
@@ -1222,65 +1222,65 @@  discard block
 block discarded – undo
1222 1222
                 '{last_name}'       => $invoice->get_last_name(),
1223 1223
                 '{email}'           => $invoice->get_email(),
1224 1224
                 '{invoice_number}'  => $invoice->get_number(),
1225
-                '{invoice_total}'   => $invoice->get_total( true ),
1226
-                '{invoice_link}'    => $invoice->get_view_url( true ),
1227
-                '{invoice_pay_link}'=> $invoice->get_view_url( true ),
1228
-                '{invoice_date}'    => $invoice->get_invoice_date( true ),
1229
-                '{invoice_due_date}'=> $invoice->get_due_date( true ),
1230
-                '{invoice_quote}'   => $invoice->get_invoice_quote_type( $invoice->ID ),
1231
-                '{invoice_label}'   => $invoice->get_invoice_quote_type( $invoice->ID ),
1232
-                '{is_was}'          => strtotime( $invoice->get_due_date() ) < strtotime( date_i18n( 'Y-m-d' ) ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
1225
+                '{invoice_total}'   => $invoice->get_total(true),
1226
+                '{invoice_link}'    => $invoice->get_view_url(true),
1227
+                '{invoice_pay_link}'=> $invoice->get_view_url(true),
1228
+                '{invoice_date}'    => $invoice->get_invoice_date(true),
1229
+                '{invoice_due_date}'=> $invoice->get_due_date(true),
1230
+                '{invoice_quote}'   => $invoice->get_invoice_quote_type($invoice->ID),
1231
+                '{invoice_label}'   => $invoice->get_invoice_quote_type($invoice->ID),
1232
+                '{is_was}'          => strtotime($invoice->get_due_date()) < strtotime(date_i18n('Y-m-d')) ? __('was', 'invoicing') : __('is', 'invoicing'),
1233 1233
             )
1234 1234
         );
1235 1235
     }
1236 1236
 
1237
-    $replace_array = apply_filters( 'wpinv_email_format_text', $replace_array, $content, $invoice );
1237
+    $replace_array = apply_filters('wpinv_email_format_text', $replace_array, $content, $invoice);
1238 1238
 
1239
-    foreach ( $replace_array as $key => $value ) {
1240
-        $content = str_replace( $key, $value, $content );
1239
+    foreach ($replace_array as $key => $value) {
1240
+        $content = str_replace($key, $value, $content);
1241 1241
     }
1242 1242
 
1243
-    return apply_filters( 'wpinv_email_content_replace', $content );
1243
+    return apply_filters('wpinv_email_content_replace', $content);
1244 1244
 }
1245 1245
 
1246
-function wpinv_email_style_body( $content ) {
1246
+function wpinv_email_style_body($content) {
1247 1247
     // make sure we only inline CSS for html emails
1248
-    if ( in_array( wpinv_mail_get_content_type(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) {
1248
+    if (in_array(wpinv_mail_get_content_type(), array('text/html', 'multipart/alternative')) && class_exists('DOMDocument')) {
1249 1249
         ob_start();
1250
-        wpinv_get_template( 'emails/wpinv-email-styles.php' );
1251
-        $css = apply_filters( 'wpinv_email_styles', ob_get_clean() );
1250
+        wpinv_get_template('emails/wpinv-email-styles.php');
1251
+        $css = apply_filters('wpinv_email_styles', ob_get_clean());
1252 1252
 
1253 1253
         // apply CSS styles inline for picky email clients
1254 1254
         try {
1255
-            $emogrifier = new Emogrifier( $content, $css );
1255
+            $emogrifier = new Emogrifier($content, $css);
1256 1256
             $content    = $emogrifier->emogrify();
1257
-        } catch ( Exception $e ) {
1258
-            wpinv_error_log( $e->getMessage(), 'emogrifier' );
1257
+        } catch (Exception $e) {
1258
+            wpinv_error_log($e->getMessage(), 'emogrifier');
1259 1259
         }
1260 1260
     }
1261 1261
     return $content;
1262 1262
 }
1263 1263
 
1264
-function wpinv_email_header( $email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1265
-    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 ) );
1264
+function wpinv_email_header($email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false) {
1265
+    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));
1266 1266
 }
1267 1267
 
1268 1268
 /**
1269 1269
  * Get the email footer.
1270 1270
  */
1271
-function wpinv_email_footer( $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1272
-    wpinv_get_template( 'emails/wpinv-email-footer.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1271
+function wpinv_email_footer($invoice = array(), $email_type = '', $sent_to_admin = false) {
1272
+    wpinv_get_template('emails/wpinv-email-footer.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1273 1273
 }
1274 1274
 
1275
-function wpinv_email_wrap_message( $message ) {
1275
+function wpinv_email_wrap_message($message) {
1276 1276
     // Buffer
1277 1277
     ob_start();
1278 1278
 
1279
-    do_action( 'wpinv_email_header' );
1279
+    do_action('wpinv_email_header');
1280 1280
 
1281
-    echo wpautop( wptexturize( $message ) );
1281
+    echo wpautop(wptexturize($message));
1282 1282
 
1283
-    do_action( 'wpinv_email_footer' );
1283
+    do_action('wpinv_email_footer');
1284 1284
 
1285 1285
     // Get contents
1286 1286
     $message = ob_get_clean();
@@ -1288,92 +1288,92 @@  discard block
 block discarded – undo
1288 1288
     return $message;
1289 1289
 }
1290 1290
 
1291
-function wpinv_email_invoice_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1292
-    wpinv_get_template( 'emails/wpinv-email-invoice-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1291
+function wpinv_email_invoice_details($invoice, $email_type = '', $sent_to_admin = false) {
1292
+    wpinv_get_template('emails/wpinv-email-invoice-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1293 1293
 }
1294 1294
 
1295
-function wpinv_email_invoice_items( $invoice, $email_type = '', $sent_to_admin = false ) {
1296
-    wpinv_get_template( 'emails/wpinv-email-invoice-items.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1295
+function wpinv_email_invoice_items($invoice, $email_type = '', $sent_to_admin = false) {
1296
+    wpinv_get_template('emails/wpinv-email-invoice-items.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1297 1297
 }
1298 1298
 
1299
-function wpinv_email_billing_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1300
-    wpinv_get_template( 'emails/wpinv-email-billing-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1299
+function wpinv_email_billing_details($invoice, $email_type = '', $sent_to_admin = false) {
1300
+    wpinv_get_template('emails/wpinv-email-billing-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1301 1301
 }
1302 1302
 
1303
-function wpinv_send_customer_invoice( $data = array() ) {
1304
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1303
+function wpinv_send_customer_invoice($data = array()) {
1304
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1305 1305
 
1306
-    if ( empty( $invoice_id ) ) {
1306
+    if (empty($invoice_id)) {
1307 1307
         return;
1308 1308
     }
1309 1309
 
1310
-    if ( !wpinv_current_user_can_manage_invoicing() ) {
1311
-        wp_die( __( 'You do not have permission to send invoice notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1310
+    if (!wpinv_current_user_can_manage_invoicing()) {
1311
+        wp_die(__('You do not have permission to send invoice notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
1312 1312
     }
1313 1313
     
1314
-    $sent = wpinv_user_invoice_notification( $invoice_id );
1314
+    $sent = wpinv_user_invoice_notification($invoice_id);
1315 1315
 
1316 1316
     if ( -1 === $sent ) {
1317 1317
         $status = 'email_disabled';
1318
-    } elseif ( $sent ) {
1318
+    } elseif ($sent) {
1319 1319
         $status = 'email_sent';
1320 1320
     } else {
1321 1321
         $status = 'email_fail';
1322 1322
     }
1323 1323
 
1324
-    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1325
-    wp_redirect( $redirect );
1324
+    $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false));
1325
+    wp_redirect($redirect);
1326 1326
     exit;
1327 1327
 }
1328
-add_action( 'wpinv_send_invoice', 'wpinv_send_customer_invoice' );
1328
+add_action('wpinv_send_invoice', 'wpinv_send_customer_invoice');
1329 1329
 
1330
-function wpinv_send_overdue_reminder( $data = array() ) {
1331
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1330
+function wpinv_send_overdue_reminder($data = array()) {
1331
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1332 1332
 
1333
-    if ( empty( $invoice_id ) ) {
1333
+    if (empty($invoice_id)) {
1334 1334
         return;
1335 1335
     }
1336 1336
 
1337
-    if ( !wpinv_current_user_can_manage_invoicing() ) {
1338
-        wp_die( __( 'You do not have permission to send reminder notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1337
+    if (!wpinv_current_user_can_manage_invoicing()) {
1338
+        wp_die(__('You do not have permission to send reminder notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
1339 1339
     }
1340 1340
 
1341
-    $sent = wpinv_send_payment_reminder_notification( $invoice_id );
1341
+    $sent = wpinv_send_payment_reminder_notification($invoice_id);
1342 1342
     
1343 1343
     $status = $sent ? 'email_sent' : 'email_fail';
1344 1344
 
1345
-    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1346
-    wp_redirect( $redirect );
1345
+    $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false));
1346
+    wp_redirect($redirect);
1347 1347
     exit;
1348 1348
 }
1349
-add_action( 'wpinv_send_reminder', 'wpinv_send_overdue_reminder' );
1349
+add_action('wpinv_send_reminder', 'wpinv_send_overdue_reminder');
1350 1350
 
1351
-function wpinv_send_customer_note_email( $data ) {
1352
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1351
+function wpinv_send_customer_note_email($data) {
1352
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1353 1353
 
1354
-    if ( empty( $invoice_id ) ) {
1354
+    if (empty($invoice_id)) {
1355 1355
         return;
1356 1356
     }
1357 1357
 
1358
-    $sent = wpinv_user_note_notification( $invoice_id, $data );
1358
+    $sent = wpinv_user_note_notification($invoice_id, $data);
1359 1359
 }
1360
-add_action( 'wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1 );
1360
+add_action('wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1);
1361 1361
 
1362
-function wpinv_add_notes_to_invoice_email( $invoice, $email_type, $sent_to_admin ) {
1363
-    if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) {
1364
-        $date_format = get_option( 'date_format' );
1365
-        $time_format = get_option( 'time_format' );
1362
+function wpinv_add_notes_to_invoice_email($invoice, $email_type, $sent_to_admin) {
1363
+    if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->ID, true)) {
1364
+        $date_format = get_option('date_format');
1365
+        $time_format = get_option('time_format');
1366 1366
         ?>
1367 1367
         <div id="wpinv-email-notes">
1368
-            <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3>
1368
+            <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3>
1369 1369
             <ol class="wpinv-notes-lists">
1370 1370
         <?php
1371
-        foreach ( $invoice_notes as $note ) {
1372
-            $note_time = strtotime( $note->comment_date );
1371
+        foreach ($invoice_notes as $note) {
1372
+            $note_time = strtotime($note->comment_date);
1373 1373
             ?>
1374 1374
             <li class="comment wpinv-note">
1375
-            <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>
1376
-            <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div>
1375
+            <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>
1376
+            <div class="wpinv-note-desc description"><?php echo wpautop(wptexturize($note->comment_content)); ?></div>
1377 1377
             </li>
1378 1378
             <?php
1379 1379
         }
@@ -1382,21 +1382,21 @@  discard block
 block discarded – undo
1382 1382
         <?php
1383 1383
     }
1384 1384
 }
1385
-add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 );
1385
+add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3);
1386 1386
 
1387 1387
 function wpinv_email_payment_reminders() {
1388 1388
     global $wpi_auto_reminder;
1389
-    if ( !wpinv_get_option( 'email_overdue_active' ) ) {
1389
+    if (!wpinv_get_option('email_overdue_active')) {
1390 1390
         return;
1391 1391
     }
1392 1392
 
1393
-    if ( $reminder_days = wpinv_get_option( 'email_due_reminder_days' ) ) {
1394
-        $reminder_days  = is_array( $reminder_days ) ? array_values( $reminder_days ) : '';
1393
+    if ($reminder_days = wpinv_get_option('email_due_reminder_days')) {
1394
+        $reminder_days  = is_array($reminder_days) ? array_values($reminder_days) : '';
1395 1395
 
1396
-        if ( empty( $reminder_days ) ) {
1396
+        if (empty($reminder_days)) {
1397 1397
             return;
1398 1398
         }
1399
-        $reminder_days  = array_unique( array_map( 'absint', $reminder_days ) );
1399
+        $reminder_days = array_unique(array_map('absint', $reminder_days));
1400 1400
 
1401 1401
         $args = array(
1402 1402
             'post_type'     => 'wpi_invoice',
@@ -1406,7 +1406,7 @@  discard block
 block discarded – undo
1406 1406
             'meta_query'    => array(
1407 1407
                 array(
1408 1408
                     'key'       =>  '_wpinv_due_date',
1409
-                    'value'     =>  array( '', 'none' ),
1409
+                    'value'     =>  array('', 'none'),
1410 1410
                     'compare'   =>  'NOT IN',
1411 1411
                 )
1412 1412
             ),
@@ -1415,143 +1415,143 @@  discard block
 block discarded – undo
1415 1415
             'order'         => 'ASC',
1416 1416
         );
1417 1417
 
1418
-        $invoices = get_posts( $args );
1418
+        $invoices = get_posts($args);
1419 1419
 
1420
-        if ( empty( $invoices ) ) {
1420
+        if (empty($invoices)) {
1421 1421
             return;
1422 1422
         }
1423 1423
 
1424
-        $date_to_send   = array();
1424
+        $date_to_send = array();
1425 1425
 
1426
-        foreach ( $invoices as $id ) {
1427
-            $due_date = get_post_meta( $id, '_wpinv_due_date', true );
1426
+        foreach ($invoices as $id) {
1427
+            $due_date = get_post_meta($id, '_wpinv_due_date', true);
1428 1428
 
1429
-            foreach ( $reminder_days as $key => $days ) {
1430
-                if ( $days !== '' ) {
1431
-                    $date_to_send[$id][] = date_i18n( 'Y-m-d', strtotime( $due_date ) + ( $days * DAY_IN_SECONDS ) );
1429
+            foreach ($reminder_days as $key => $days) {
1430
+                if ($days !== '') {
1431
+                    $date_to_send[$id][] = date_i18n('Y-m-d', strtotime($due_date) + ($days * DAY_IN_SECONDS));
1432 1432
                 }
1433 1433
             }
1434 1434
         }
1435 1435
 
1436
-        $today              = date_i18n( 'Y-m-d' );
1436
+        $today              = date_i18n('Y-m-d');
1437 1437
         $wpi_auto_reminder  = true;
1438 1438
 
1439
-        foreach ( $date_to_send as $id => $values ) {
1440
-            if ( in_array( $today, $values ) ) {
1441
-                $sent = get_post_meta( $id, '_wpinv_reminder_sent', true );
1439
+        foreach ($date_to_send as $id => $values) {
1440
+            if (in_array($today, $values)) {
1441
+                $sent = get_post_meta($id, '_wpinv_reminder_sent', true);
1442 1442
 
1443
-                if ( isset( $sent ) && !empty( $sent ) ) {
1444
-                    if ( !in_array( $today, $sent ) ) {
1445
-                        do_action( 'wpinv_send_payment_reminder_notification', $id );
1443
+                if (isset($sent) && !empty($sent)) {
1444
+                    if (!in_array($today, $sent)) {
1445
+                        do_action('wpinv_send_payment_reminder_notification', $id);
1446 1446
                     }
1447 1447
                 } else {
1448
-                    do_action( 'wpinv_send_payment_reminder_notification', $id );
1448
+                    do_action('wpinv_send_payment_reminder_notification', $id);
1449 1449
                 }
1450 1450
             }
1451 1451
         }
1452 1452
 
1453
-        $wpi_auto_reminder  = false;
1453
+        $wpi_auto_reminder = false;
1454 1454
     }
1455 1455
 }
1456 1456
 
1457
-function wpinv_send_payment_reminder_notification( $invoice_id ) {
1457
+function wpinv_send_payment_reminder_notification($invoice_id) {
1458 1458
     $email_type = 'overdue';
1459
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
1459
+    if (!wpinv_email_is_enabled($email_type)) {
1460 1460
         return false;
1461 1461
     }
1462 1462
 
1463
-    $invoice    = wpinv_get_invoice( $invoice_id );
1464
-    if ( empty( $invoice ) ) {
1463
+    $invoice = wpinv_get_invoice($invoice_id);
1464
+    if (empty($invoice)) {
1465 1465
         return false;
1466 1466
     }
1467 1467
 
1468
-    if ( !$invoice->needs_payment() ) {
1468
+    if (!$invoice->needs_payment()) {
1469 1469
         return false;
1470 1470
     }
1471 1471
 
1472
-    $recipient  = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
1473
-    if ( !is_email( $recipient ) ) {
1472
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
1473
+    if (!is_email($recipient)) {
1474 1474
         return false;
1475 1475
     }
1476 1476
 
1477
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
1477
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
1478 1478
 
1479
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
1480
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
1481
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
1482
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
1483
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
1479
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
1480
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
1481
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
1482
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
1483
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
1484 1484
 
1485
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
1485
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
1486 1486
             'invoice'       => $invoice,
1487 1487
             'email_type'    => $email_type,
1488 1488
             'email_heading' => $email_heading,
1489 1489
             'sent_to_admin' => false,
1490 1490
             'plain_text'    => false,
1491 1491
             'message_body'  => $message_body
1492
-        ) );
1492
+        ));
1493 1493
 
1494
-    $content        = wpinv_email_format_text( $content, $invoice );
1494
+    $content = wpinv_email_format_text($content, $invoice);
1495 1495
 
1496
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1497
-    if ( $sent ) {
1498
-        do_action( 'wpinv_payment_reminder_sent', $invoice_id, $invoice );
1496
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
1497
+    if ($sent) {
1498
+        do_action('wpinv_payment_reminder_sent', $invoice_id, $invoice);
1499 1499
     }
1500 1500
 
1501
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
1501
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
1502 1502
 
1503 1503
     return $sent;
1504 1504
 }
1505
-add_action( 'wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1 );
1505
+add_action('wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1);
1506 1506
 
1507
-function wpinv_payment_reminder_sent( $invoice_id, $invoice ) {
1507
+function wpinv_payment_reminder_sent($invoice_id, $invoice) {
1508 1508
     global $wpi_auto_reminder;
1509 1509
 
1510
-    $sent = get_post_meta( $invoice_id, '_wpinv_reminder_sent', true );
1510
+    $sent = get_post_meta($invoice_id, '_wpinv_reminder_sent', true);
1511 1511
 
1512
-    if ( empty( $sent ) ) {
1512
+    if (empty($sent)) {
1513 1513
         $sent = array();
1514 1514
     }
1515
-    $sent[] = date_i18n( 'Y-m-d' );
1515
+    $sent[] = date_i18n('Y-m-d');
1516 1516
 
1517
-    update_post_meta( $invoice_id, '_wpinv_reminder_sent', $sent );
1517
+    update_post_meta($invoice_id, '_wpinv_reminder_sent', $sent);
1518 1518
 
1519
-    if ( $wpi_auto_reminder ) { // Auto reminder note.
1520
-        $note = __( 'Automated reminder sent to the user.', 'invoicing' );
1521
-        $invoice->add_note( $note, false, false, true );
1519
+    if ($wpi_auto_reminder) { // Auto reminder note.
1520
+        $note = __('Automated reminder sent to the user.', 'invoicing');
1521
+        $invoice->add_note($note, false, false, true);
1522 1522
     } else { // Menual reminder note.
1523
-        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1524
-        $invoice->add_note( $note );
1523
+        $note = __('Manual reminder sent to the user.', 'invoicing');
1524
+        $invoice->add_note($note);
1525 1525
     }
1526 1526
 }
1527
-add_action( 'wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2 );
1527
+add_action('wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2);
1528 1528
 
1529
-function wpinv_invoice_notification_set_locale( $invoice, $email_type, $site = false ) {
1530
-    if ( empty( $invoice ) ) {
1529
+function wpinv_invoice_notification_set_locale($invoice, $email_type, $site = false) {
1530
+    if (empty($invoice)) {
1531 1531
         return;
1532 1532
     }
1533 1533
 
1534
-    if ( is_int( $invoice ) ) {
1535
-        $invoice = wpinv_get_invoice( $invoice );
1534
+    if (is_int($invoice)) {
1535
+        $invoice = wpinv_get_invoice($invoice);
1536 1536
     }
1537 1537
 
1538
-    if ( ! empty( $invoice ) && is_object( $invoice ) ) {
1539
-        if ( ! $site && function_exists( 'get_user_locale' ) ) {
1540
-            $locale = get_user_locale( $invoice->get_user_id() );
1538
+    if (!empty($invoice) && is_object($invoice)) {
1539
+        if (!$site && function_exists('get_user_locale')) {
1540
+            $locale = get_user_locale($invoice->get_user_id());
1541 1541
         } else {
1542 1542
             $locale = get_locale();
1543 1543
         }
1544 1544
 
1545
-        wpinv_switch_to_locale( $locale );
1545
+        wpinv_switch_to_locale($locale);
1546 1546
     }
1547 1547
 }
1548
-add_action( 'wpinv_pre_send_invoice_notification', 'wpinv_invoice_notification_set_locale', 10, 3 );
1548
+add_action('wpinv_pre_send_invoice_notification', 'wpinv_invoice_notification_set_locale', 10, 3);
1549 1549
 
1550
-function wpinv_invoice_notification_restore_locale( $invoice, $email_type, $site = false ) {
1551
-    if ( empty( $invoice ) ) {
1550
+function wpinv_invoice_notification_restore_locale($invoice, $email_type, $site = false) {
1551
+    if (empty($invoice)) {
1552 1552
         return;
1553 1553
     }
1554 1554
 
1555 1555
     wpinv_restore_locale();
1556 1556
 }
1557
-add_action( 'wpinv_post_send_invoice_notification', 'wpinv_invoice_notification_restore_locale', 10, 3 );
1557
+add_action('wpinv_post_send_invoice_notification', 'wpinv_invoice_notification_restore_locale', 10, 3);
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-invoice-items.php 1 patch
Spacing   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -1,47 +1,47 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Items {
8
-    public static function output( $post ) {
8
+    public static function output($post) {
9 9
         global $wpinv_euvat, $ajax_cart_details;
10 10
 
11
-        $post_id            = !empty( $post->ID ) ? $post->ID : 0;
12
-        $invoice            = new WPInv_Invoice( $post_id );
11
+        $post_id            = !empty($post->ID) ? $post->ID : 0;
12
+        $invoice            = new WPInv_Invoice($post_id);
13 13
         $ajax_cart_details  = $invoice->get_cart_details();
14
-        $subtotal           = $invoice->get_subtotal( true );
14
+        $subtotal           = $invoice->get_subtotal(true);
15 15
         $discount_raw       = $invoice->get_discount();
16
-        $discount           = wpinv_price( $discount_raw, $invoice->get_currency() );
16
+        $discount           = wpinv_price($discount_raw, $invoice->get_currency());
17 17
         $discounts          = $discount_raw > 0 ? $invoice->get_discounts() : '';
18
-        $tax                = $invoice->get_tax( true );
19
-        $total              = $invoice->get_total( true );
18
+        $tax                = $invoice->get_tax(true);
19
+        $total              = $invoice->get_total(true);
20 20
         $item_quantities    = wpinv_item_quantities_enabled();
21 21
         $use_taxes          = wpinv_use_taxes();
22
-        if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) {
22
+        if (!$use_taxes && (float) $invoice->get_tax() > 0) {
23 23
             $use_taxes = true;
24 24
         }
25
-        $item_types         = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post );
25
+        $item_types         = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post);
26 26
         $is_recurring       = $invoice->is_recurring();
27 27
         $post_type_object   = get_post_type_object($invoice->post_type);
28 28
         $type_title         = $post_type_object->labels->singular_name;
29 29
 
30 30
         $cols = 5;
31
-        if ( $item_quantities ) {
31
+        if ($item_quantities) {
32 32
             $cols++;
33 33
         }
34
-        if ( $use_taxes ) {
34
+        if ($use_taxes) {
35 35
             $cols++;
36 36
         }
37 37
         $class = '';
38
-        if ( $invoice->is_paid() ) {
38
+        if ($invoice->is_paid()) {
39 39
             $class .= ' wpinv-paid';
40 40
         }
41
-        if ( $invoice->is_refunded() ) {
41
+        if ($invoice->is_refunded()) {
42 42
             $class .= ' wpinv-refunded';
43 43
         }
44
-        if ( $is_recurring ) {
44
+        if ($is_recurring) {
45 45
             $class .= ' wpi-recurring';
46 46
         }
47 47
         ?>
@@ -49,21 +49,21 @@  discard block
 block discarded – undo
49 49
             <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0">
50 50
                 <thead>
51 51
                     <tr>
52
-                        <th class="id"><?php _e( 'ID', 'invoicing' );?></th>
53
-                        <th class="title"><?php _e( 'Item', 'invoicing' );?></th>
54
-                        <th class="price"><?php _e( 'Price', 'invoicing' );?></th>
55
-                        <?php if ( $item_quantities ) { ?>
56
-                        <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th>
52
+                        <th class="id"><?php _e('ID', 'invoicing'); ?></th>
53
+                        <th class="title"><?php _e('Item', 'invoicing'); ?></th>
54
+                        <th class="price"><?php _e('Price', 'invoicing'); ?></th>
55
+                        <?php if ($item_quantities) { ?>
56
+                        <th class="qty"><?php _e('Qty', 'invoicing'); ?></th>
57 57
                         <?php } ?>
58
-                        <th class="total"><?php _e( 'Total', 'invoicing' );?></th>
59
-                        <?php if ( $use_taxes ) { ?>
60
-                        <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th>
58
+                        <th class="total"><?php _e('Total', 'invoicing'); ?></th>
59
+                        <?php if ($use_taxes) { ?>
60
+                        <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th>
61 61
                         <?php } ?>
62 62
                         <th class="action"></th>
63 63
                     </tr>
64 64
                 </thead>
65 65
                 <tbody class="wpinv-line-items">
66
-                    <?php echo wpinv_admin_get_line_items( $invoice ); ?>
66
+                    <?php echo wpinv_admin_get_line_items($invoice); ?>
67 67
                 </tbody>
68 68
                 <tfoot class="wpinv-totals">
69 69
                     <tr>
@@ -74,45 +74,45 @@  discard block
 block discarded – undo
74 74
                                         <td class="id">
75 75
                                         </td>
76 76
                                         <td class="title">
77
-                                            <input type="text" class="regular-text" placeholder="<?php _e( 'Item Name', 'invoicing' ); ?>" value="" name="_wpinv_quick[name]">
78
-                                            <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?>
77
+                                            <input type="text" class="regular-text" placeholder="<?php _e('Item Name', 'invoicing'); ?>" value="" name="_wpinv_quick[name]">
78
+                                            <?php if ($wpinv_euvat->allow_vat_rules()) { ?>
79 79
                                             <div class="wp-clearfix">
80 80
                                                 <label class="wpi-vat-rule">
81
-                                                    <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span>
81
+                                                    <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span>
82 82
                                                     <span class="input-text-wrap">
83
-                                                        <?php echo wpinv_html_select( array(
83
+                                                        <?php echo wpinv_html_select(array(
84 84
                                                             'options'          => $wpinv_euvat->get_rules(),
85 85
                                                             'name'             => '_wpinv_quick[vat_rule]',
86 86
                                                             'id'               => '_wpinv_quick_vat_rule',
87 87
                                                             'show_option_all'  => false,
88 88
                                                             'show_option_none' => false,
89 89
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule wpi_select2',
90
-                                                        ) ); ?>
90
+                                                        )); ?>
91 91
                                                     </span>
92 92
                                                 </label>
93 93
                                             </div>
94
-                                            <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?>
94
+                                            <?php } if ($wpinv_euvat->allow_vat_classes()) { ?>
95 95
                                             <div class="wp-clearfix">
96 96
                                                 <label class="wpi-vat-class">
97
-                                                    <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span>
97
+                                                    <span class="title"><?php _e('VAT class', 'invoicing'); ?></span>
98 98
                                                     <span class="input-text-wrap">
99
-                                                        <?php echo wpinv_html_select( array(
99
+                                                        <?php echo wpinv_html_select(array(
100 100
                                                             'options'          => $wpinv_euvat->get_all_classes(),
101 101
                                                             'name'             => '_wpinv_quick[vat_class]',
102 102
                                                             'id'               => '_wpinv_quick_vat_class',
103 103
                                                             'show_option_all'  => false,
104 104
                                                             'show_option_none' => false,
105 105
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class wpi_select2',
106
-                                                        ) ); ?>
106
+                                                        )); ?>
107 107
                                                     </span>
108 108
                                                 </label>
109 109
                                             </div>
110 110
                                             <?php } ?>
111 111
                                             <div class="wp-clearfix">
112 112
                                                 <label class="wpi-item-type">
113
-                                                    <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>
113
+                                                    <span class="title"><?php _e('Item type', 'invoicing'); ?></span>
114 114
                                                     <span class="input-text-wrap">
115
-                                                        <?php echo wpinv_html_select( array(
115
+                                                        <?php echo wpinv_html_select(array(
116 116
                                                             'options'          => $item_types,
117 117
                                                             'name'             => '_wpinv_quick[type]',
118 118
                                                             'id'               => '_wpinv_quick_type',
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
                                                             'show_option_all'  => false,
121 121
                                                             'show_option_none' => false,
122 122
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-type wpi_select2',
123
-                                                        ) ); ?>
123
+                                                        )); ?>
124 124
                                                     </span>
125 125
                                                 </label>
126 126
                                             </div>
@@ -133,11 +133,11 @@  discard block
 block discarded – undo
133 133
                                             </div>
134 134
                                         </td>
135 135
                                         <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td>
136
-                                        <?php if ( $item_quantities ) { ?>
136
+                                        <?php if ($item_quantities) { ?>
137 137
                                         <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td>
138 138
                                         <?php } ?>
139 139
                                         <td class="total"></td>
140
-                                        <?php if ( $use_taxes ) { ?>
140
+                                        <?php if ($use_taxes) { ?>
141 141
                                         <td class="tax"></td>
142 142
                                         <?php } ?>
143 143
                                         <td class="action"></td>
@@ -150,29 +150,29 @@  discard block
 block discarded – undo
150 150
                         <td colspan="<?php echo $cols; ?>"></td>
151 151
                     </tr>
152 152
                     <tr class="totals">
153
-                        <td colspan="<?php echo ( $cols - 4 ); ?>"></td>
153
+                        <td colspan="<?php echo ($cols - 4); ?>"></td>
154 154
                         <td colspan="4">
155 155
                             <table cellspacing="0" cellpadding="0">
156 156
                                 <tr class="subtotal">
157
-                                    <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td>
158
-                                    <td class="total"><?php echo $subtotal;?></td>
157
+                                    <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td>
158
+                                    <td class="total"><?php echo $subtotal; ?></td>
159 159
                                     <td class="action"></td>
160 160
                                 </tr>
161 161
                                 <tr class="discount">
162
-                                    <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td>
163
-                                    <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td>
162
+                                    <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td>
163
+                                    <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td>
164 164
                                     <td class="action"></td>
165 165
                                 </tr>
166
-                                <?php if ( $use_taxes ) { ?>
166
+                                <?php if ($use_taxes) { ?>
167 167
                                 <tr class="tax">
168
-                                    <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td>
169
-                                    <td class="total"><?php echo $tax;?></td>
168
+                                    <td class="name"><?php _e('Tax:', 'invoicing'); ?></td>
169
+                                    <td class="total"><?php echo $tax; ?></td>
170 170
                                     <td class="action"></td>
171 171
                                 </tr>
172 172
                                 <?php } ?>
173 173
                                 <tr class="total">
174
-                                    <td class="name"><?php echo apply_filters( 'wpinv_invoice_items_total_label', __( 'Invoice Total:', 'invoicing' ), $invoice );?></td>
175
-                                    <td class="total"><?php echo $total;?></td>
174
+                                    <td class="name"><?php echo apply_filters('wpinv_invoice_items_total_label', __('Invoice Total:', 'invoicing'), $invoice); ?></td>
175
+                                    <td class="total"><?php echo $total; ?></td>
176 176
                                     <td class="action"></td>
177 177
                                 </tr>
178 178
                             </table>
@@ -183,90 +183,90 @@  discard block
 block discarded – undo
183 183
             <div class="wpinv-actions">
184 184
                 <?php ob_start(); ?>
185 185
                 <?php
186
-                    if ( !$invoice->is_paid() && !$invoice->is_refunded() ) {
187
-                        if ( !$invoice->is_recurring() ) {
188
-                            echo wpinv_item_dropdown( array(
186
+                    if (!$invoice->is_paid() && !$invoice->is_refunded()) {
187
+                        if (!$invoice->is_recurring()) {
188
+                            echo wpinv_item_dropdown(array(
189 189
                                 'name'             => 'wpinv_invoice_item',
190 190
                                 'id'               => 'wpinv_invoice_item',
191 191
                                 'show_recurring'   => true,
192 192
                                 'class'            => 'wpi_select2',
193
-                            ) );
193
+                            ));
194 194
                     ?>
195
-                <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
195
+                <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
196 196
                     <?php } ?>
197
-                <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?>
198
-                <?php $item_actions = ob_get_clean(); echo apply_filters( 'wpinv_invoice_items_actions_content', $item_actions, $invoice, $post ); ?>
197
+                <?php do_action('wpinv_invoice_items_actions', $invoice); ?>
198
+                <?php $item_actions = ob_get_clean(); echo apply_filters('wpinv_invoice_items_actions_content', $item_actions, $invoice, $post); ?>
199 199
             </div>
200 200
         </div>
201 201
         <?php
202 202
     }
203 203
 
204
-    public static function prices( $post ) {        
204
+    public static function prices($post) {        
205 205
         $symbol         = wpinv_currency_symbol();
206 206
         $position       = wpinv_currency_position();
207
-        $item           = new WPInv_Item( $post->ID );
207
+        $item           = new WPInv_Item($post->ID);
208 208
 
209 209
         $price                = $item->get_price();
210 210
         $is_dynamic_pricing   = $item->get_is_dynamic_pricing();
211 211
         $minimum_price        = $item->get_minimum_price();
212 212
         $is_recurring         = $item->is_recurring();
213 213
         $period               = $item->get_recurring_period();
214
-        $interval             = absint( $item->get_recurring_interval() );
215
-        $times                = absint( $item->get_recurring_limit() );
214
+        $interval             = absint($item->get_recurring_interval());
215
+        $times                = absint($item->get_recurring_limit());
216 216
         $free_trial           = $item->has_free_trial();
217 217
         $trial_interval       = $item->get_trial_interval();
218 218
         $trial_period         = $item->get_trial_period();
219 219
 
220 220
         $intervals            = array();
221
-        for ( $i = 1; $i <= 90; $i++ ) {
221
+        for ($i = 1; $i <= 90; $i++) {
222 222
             $intervals[$i] = $i;
223 223
         }
224 224
 
225
-        $interval       = $interval > 0 ? $interval : 1;
225
+        $interval = $interval > 0 ? $interval : 1;
226 226
 
227 227
         $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n';
228 228
 
229 229
         $minimum_price_style = 'margin-left: 24px;';
230
-        if(! $is_dynamic_pricing ) {
230
+        if (!$is_dynamic_pricing) {
231 231
             $minimum_price_style .= 'display: none;';
232 232
         }
233 233
 
234 234
         ?>
235
-        <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_editable(), false ); ?> /><?php echo ( $position == 'right' ? '&nbsp;' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" />
236
-        <?php do_action( 'wpinv_prices_metabox_price', $item ); ?>
235
+        <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_editable(), false); ?> /><?php echo ($position == 'right' ? '&nbsp;' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" />
236
+        <?php do_action('wpinv_prices_metabox_price', $item); ?>
237 237
         </p>
238 238
 
239
-    <?php if( $item->supports_dynamic_pricing() ) { ?>
239
+    <?php if ($item->supports_dynamic_pricing()) { ?>
240 240
 
241 241
         <p class="wpinv-row-name-your-price">
242 242
             <label>
243
-                <input type="checkbox" name="wpinv_name_your_price" id="wpinv_name_your_price" value="1" <?php checked( 1, $is_dynamic_pricing ); ?> />
244
-                <?php echo apply_filters( 'wpinv_name_your_price_toggle_text', __( 'User can set a custom price', 'invoicing' ) ); ?>
243
+                <input type="checkbox" name="wpinv_name_your_price" id="wpinv_name_your_price" value="1" <?php checked(1, $is_dynamic_pricing); ?> />
244
+                <?php echo apply_filters('wpinv_name_your_price_toggle_text', __('User can set a custom price', 'invoicing')); ?>
245 245
             </label>
246
-            <?php do_action( 'wpinv_prices_metabox_name_your_price_field', $item ); ?>
246
+            <?php do_action('wpinv_prices_metabox_name_your_price_field', $item); ?>
247 247
         </p>
248 248
 
249 249
         <p class="wpinv-row-minimum-price" style="<?php echo $minimum_price_style; ?>">
250 250
             <label>
251
-                <?php _e( 'Minimum Price', 'invoicing' ); ?>
252
-                <?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $minimum_price;?>" id="wpinv_minimum_price" name="wpinv_minimum_price" class="medium-text wpi-field-price" <?php disabled( $item->is_editable(), false ); ?> /><?php echo ( $position == 'right' ? '&nbsp;' . $symbol : '' );?>
251
+                <?php _e('Minimum Price', 'invoicing'); ?>
252
+                <?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $minimum_price; ?>" id="wpinv_minimum_price" name="wpinv_minimum_price" class="medium-text wpi-field-price" <?php disabled($item->is_editable(), false); ?> /><?php echo ($position == 'right' ? '&nbsp;' . $symbol : ''); ?>
253 253
             </label>
254 254
 
255
-            <?php do_action( 'wpinv_prices_metabox_minimum_price_field', $item ); ?>
255
+            <?php do_action('wpinv_prices_metabox_minimum_price_field', $item); ?>
256 256
         </p>
257 257
 
258 258
     <?php } ?>
259 259
 
260 260
         <p class="wpinv-row-is-recurring">
261 261
             <label for="wpinv_is_recurring">
262
-                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> />
263
-                <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?>
262
+                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> />
263
+                <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?>
264 264
             </label>
265
-            <?php do_action( 'wpinv_prices_metabox_is_recurring_field', $item ); ?>
265
+            <?php do_action('wpinv_prices_metabox_is_recurring_field', $item); ?>
266 266
         </p>
267
-        <p class="wpinv-row-recurring-fields <?php echo $class;?>">
268
-            <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select wpi_select2" id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label>
269
-            <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array(
267
+        <p class="wpinv-row-recurring-fields <?php echo $class; ?>">
268
+            <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select wpi_select2" id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e('day(s)', 'invoicing'); ?>" <?php selected('D', $period); ?>><?php _e('Daily', 'invoicing'); ?></option><option value="W" data-text="<?php esc_attr_e('week(s)', 'invoicing'); ?>" <?php selected('W', $period); ?>><?php _e('Weekly', 'invoicing'); ?></option><option value="M" data-text="<?php esc_attr_e('month(s)', 'invoicing'); ?>" <?php selected('M', $period); ?>><?php _e('Monthly', 'invoicing'); ?></option><option value="Y" data-text="<?php esc_attr_e('year(s)', 'invoicing'); ?>" <?php selected('Y', $period); ?>><?php _e('Yearly', 'invoicing'); ?></option></select></label>
269
+            <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array(
270 270
                 'options'          => $intervals,
271 271
                 'name'             => 'wpinv_recurring_interval',
272 272
                 'id'               => 'wpinv_recurring_interval',
@@ -274,30 +274,30 @@  discard block
 block discarded – undo
274 274
                 'show_option_all'  => false,
275 275
                 'show_option_none' => false,
276 276
                 'class'            => 'wpi_select2',
277
-            ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label>
278
-            <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label>
277
+            )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label>
278
+            <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e('for', 'invoicing'); ?> <input class="small-text" type="number" value="<?php echo $times; ?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e('time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing'); ?></label>
279 279
             <span class="clear wpi-trial-clr"></span>
280 280
             <label class="wpinv-free-trial" for="wpinv_free_trial">
281
-                <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> 
282
-                <?php echo __( 'Offer free trial for', 'invoicing' ); ?>
281
+                <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool) $free_trial); ?> /> 
282
+                <?php echo __('Offer free trial for', 'invoicing'); ?>
283 283
             </label>
284 284
             <label class="wpinv-trial-interval" for="wpinv_trial_interval">
285
-                <input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select wpi_select2" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select>
285
+                <input class="small-text" type="number" value="<?php echo $trial_interval; ?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select wpi_select2" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected('D', $trial_period); ?>><?php _e('day(s)', 'invoicing'); ?></option><option value="W" <?php selected('W', $trial_period); ?>><?php _e('week(s)', 'invoicing'); ?></option><option value="M" <?php selected('M', $trial_period); ?>><?php _e('month(s)', 'invoicing'); ?></option><option value="Y" <?php selected('Y', $trial_period); ?>><?php _e('year(s)', 'invoicing'); ?></option></select>
286 286
             </label>
287
-            <?php do_action( 'wpinv_prices_metabox_recurring_fields', $item ); ?>
287
+            <?php do_action('wpinv_prices_metabox_recurring_fields', $item); ?>
288 288
         </p>
289
-        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" />
290
-        <?php do_action( 'wpinv_item_price_field', $post->ID ); ?>
289
+        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" />
290
+        <?php do_action('wpinv_item_price_field', $post->ID); ?>
291 291
         <?php
292 292
     }
293 293
 
294
-    public static function vat_rules( $post ) {
294
+    public static function vat_rules($post) {
295 295
         global $wpinv_euvat;
296 296
 
297
-        $rule_type = $wpinv_euvat->get_item_rule( $post->ID );
297
+        $rule_type = $wpinv_euvat->get_item_rule($post->ID);
298 298
         ?>
299
-        <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
300
-        <?php echo wpinv_html_select( array(
299
+        <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
300
+        <?php echo wpinv_html_select(array(
301 301
                     'options'          => $wpinv_euvat->get_rules(),
302 302
                     'name'             => 'wpinv_vat_rules',
303 303
                     'id'               => 'wpinv_vat_rules',
@@ -305,19 +305,19 @@  discard block
 block discarded – undo
305 305
                     'show_option_all'  => false,
306 306
                     'show_option_none' => false,
307 307
                     'class'            => 'gdmbx2-text-medium wpinv-vat-rules wpi_select2',
308
-                ) ); ?>
308
+                )); ?>
309 309
         </p>
310
-        <p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p>
311
-        <p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p>
310
+        <p class="wpi-m0"><?php _e('When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing'); ?></p>
311
+        <p class="wpi-m0"><?php _e('If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing'); ?></p>
312 312
         <?php
313 313
     }
314 314
 
315
-    public static function vat_classes( $post ) {
315
+    public static function vat_classes($post) {
316 316
         global $wpinv_euvat;
317 317
         
318
-        $vat_class = $wpinv_euvat->get_item_class( $post->ID );
318
+        $vat_class = $wpinv_euvat->get_item_class($post->ID);
319 319
         ?>
320
-        <p><?php echo wpinv_html_select( array(
320
+        <p><?php echo wpinv_html_select(array(
321 321
                     'options'          => $wpinv_euvat->get_all_classes(),
322 322
                     'name'             => 'wpinv_vat_class',
323 323
                     'id'               => 'wpinv_vat_class',
@@ -325,18 +325,18 @@  discard block
 block discarded – undo
325 325
                     'show_option_all'  => false,
326 326
                     'show_option_none' => false,
327 327
                     'class'            => 'gdmbx2-text-medium wpinv-vat-class wpi_select2',
328
-                ) ); ?>
328
+                )); ?>
329 329
         </p>
330
-        <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p>
330
+        <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p>
331 331
         <?php
332 332
     }
333 333
 
334
-    public static function item_info( $post ) {
335
-        $item_type = wpinv_get_item_type( $post->ID );
336
-        do_action( 'wpinv_item_info_metabox_before', $post );
334
+    public static function item_info($post) {
335
+        $item_type = wpinv_get_item_type($post->ID);
336
+        do_action('wpinv_item_info_metabox_before', $post);
337 337
         ?>
338
-        <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
339
-        <?php echo wpinv_html_select( array(
338
+        <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
339
+        <?php echo wpinv_html_select(array(
340 340
                     'options'          => wpinv_get_item_types(),
341 341
                     'name'             => 'wpinv_item_type',
342 342
                     'id'               => 'wpinv_item_type',
@@ -344,114 +344,114 @@  discard block
 block discarded – undo
344 344
                     'show_option_all'  => false,
345 345
                     'show_option_none' => false,
346 346
                     'class'            => 'gdmbx2-text-medium wpinv-item-type',
347
-                ) ); ?>
347
+                )); ?>
348 348
         </p>
349
-        <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( '<b>Standard:</b> Standard item type', 'invoicing' );?><br><?php _e( '<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing' );?></p>
349
+        <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('<b>Standard:</b> Standard item type', 'invoicing'); ?><br><?php _e('<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing'); ?></p>
350 350
         <?php
351
-        do_action( 'wpinv_item_info_metabox_after', $post );
351
+        do_action('wpinv_item_info_metabox_after', $post);
352 352
     }
353 353
 
354
-    public static function meta_values( $post ) {
355
-        $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array(
354
+    public static function meta_values($post) {
355
+        $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array(
356 356
             'type',
357 357
             'custom_id'
358
-        ) );
358
+        ));
359 359
 
360
-        if ( empty( $meta_keys ) ) {
360
+        if (empty($meta_keys)) {
361 361
             return;
362 362
         }
363 363
 
364
-        do_action( 'wpinv_meta_values_metabox_before', $post );
364
+        do_action('wpinv_meta_values_metabox_before', $post);
365 365
 
366
-        foreach ( $meta_keys as $meta_key ) {
366
+        foreach ($meta_keys as $meta_key) {
367 367
             ?>
368
-            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p>
368
+            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p>
369 369
             <?php 
370 370
         }
371 371
 
372
-        do_action( 'wpinv_meta_values_metabox_after', $post );
372
+        do_action('wpinv_meta_values_metabox_after', $post);
373 373
     }
374 374
 
375
-    public static function save( $post_id, $data, $post ) {
376
-        $invoice        = new WPInv_Invoice( $post_id );
375
+    public static function save($post_id, $data, $post) {
376
+        $invoice        = new WPInv_Invoice($post_id);
377 377
 
378 378
         // Billing
379
-        $first_name     = sanitize_text_field( $data['wpinv_first_name'] );
380
-        $last_name      = sanitize_text_field( $data['wpinv_last_name'] );
381
-        $company        = sanitize_text_field( $data['wpinv_company'] );
382
-        $vat_number     = sanitize_text_field( $data['wpinv_vat_number'] );
383
-        $phone          = sanitize_text_field( $data['wpinv_phone'] );
384
-        $address        = sanitize_text_field( $data['wpinv_address'] );
385
-        $city           = sanitize_text_field( $data['wpinv_city'] );
386
-        $zip            = sanitize_text_field( $data['wpinv_zip'] );
387
-        $country        = sanitize_text_field( $data['wpinv_country'] );
388
-        $state          = sanitize_text_field( $data['wpinv_state'] );
379
+        $first_name     = sanitize_text_field($data['wpinv_first_name']);
380
+        $last_name      = sanitize_text_field($data['wpinv_last_name']);
381
+        $company        = sanitize_text_field($data['wpinv_company']);
382
+        $vat_number     = sanitize_text_field($data['wpinv_vat_number']);
383
+        $phone          = sanitize_text_field($data['wpinv_phone']);
384
+        $address        = sanitize_text_field($data['wpinv_address']);
385
+        $city           = sanitize_text_field($data['wpinv_city']);
386
+        $zip            = sanitize_text_field($data['wpinv_zip']);
387
+        $country        = sanitize_text_field($data['wpinv_country']);
388
+        $state          = sanitize_text_field($data['wpinv_state']);
389 389
 
390 390
         // Details
391
-        $status         = sanitize_text_field( $data['wpinv_status'] );
392
-        $old_status     = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status;
393
-        $number         = sanitize_text_field( $data['wpinv_number'] );
394
-        $due_date       = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : '';
391
+        $status         = sanitize_text_field($data['wpinv_status']);
392
+        $old_status     = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status;
393
+        $number         = sanitize_text_field($data['wpinv_number']);
394
+        $due_date       = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : '';
395 395
         //$discounts      = sanitize_text_field( $data['wpinv_discounts'] );
396 396
         //$discount       = sanitize_text_field( $data['wpinv_discount'] );
397 397
 
398
-        $ip             = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
399
-
400
-        $invoice->set( 'due_date', $due_date );
401
-        $invoice->set( 'first_name', $first_name );
402
-        $invoice->set( 'last_name', $last_name );
403
-        $invoice->set( 'company', $company );
404
-        $invoice->set( 'vat_number', $vat_number );
405
-        $invoice->set( 'phone', $phone );
406
-        $invoice->set( 'address', $address );
407
-        $invoice->set( 'city', $city );
408
-        $invoice->set( 'zip', $zip );
409
-        $invoice->set( 'country', $country );
410
-        $invoice->set( 'state', $state );
411
-        $invoice->set( 'status', $status );
398
+        $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
399
+
400
+        $invoice->set('due_date', $due_date);
401
+        $invoice->set('first_name', $first_name);
402
+        $invoice->set('last_name', $last_name);
403
+        $invoice->set('company', $company);
404
+        $invoice->set('vat_number', $vat_number);
405
+        $invoice->set('phone', $phone);
406
+        $invoice->set('address', $address);
407
+        $invoice->set('city', $city);
408
+        $invoice->set('zip', $zip);
409
+        $invoice->set('country', $country);
410
+        $invoice->set('state', $state);
411
+        $invoice->set('status', $status);
412 412
         //$invoice->set( 'number', $number );
413 413
         //$invoice->set( 'discounts', $discounts );
414 414
         //$invoice->set( 'discount', $discount );
415
-        $invoice->set( 'ip', $ip );
415
+        $invoice->set('ip', $ip);
416 416
         $invoice->old_status = $_POST['original_post_status'];
417 417
         $invoice->currency = wpinv_get_currency();
418
-        if ( !empty( $data['wpinv_gateway'] ) ) {
419
-            $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) );
418
+        if (!empty($data['wpinv_gateway'])) {
419
+            $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway']));
420 420
         }
421 421
         $saved = $invoice->save();
422 422
 
423 423
         // Check for payment notes
424
-        if ( !empty( $data['invoice_note'] ) ) {
425
-            $note               = wp_kses( $data['invoice_note'], array() );
426
-            $note_type          = sanitize_text_field( $data['invoice_note_type'] );
424
+        if (!empty($data['invoice_note'])) {
425
+            $note               = wp_kses($data['invoice_note'], array());
426
+            $note_type          = sanitize_text_field($data['invoice_note_type']);
427 427
             $is_customer_note   = $note_type == 'customer' ? 1 : 0;
428 428
 
429
-            wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note );
429
+            wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note);
430 430
         }
431 431
 
432 432
         // Update user address if empty.
433
-        if ( $saved && !empty( $invoice ) ) {
434
-            if ( $user_id = $invoice->get_user_id() ) {
435
-                $user_address = wpinv_get_user_address( $user_id, false );
433
+        if ($saved && !empty($invoice)) {
434
+            if ($user_id = $invoice->get_user_id()) {
435
+                $user_address = wpinv_get_user_address($user_id, false);
436 436
 
437 437
                 if (empty($user_address['first_name'])) {
438
-                    update_user_meta( $user_id, '_wpinv_first_name', $first_name );
439
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
438
+                    update_user_meta($user_id, '_wpinv_first_name', $first_name);
439
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
440 440
                 } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) {
441
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
441
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
442 442
                 }
443 443
 
444 444
                 if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) {
445
-                    update_user_meta( $user_id, '_wpinv_address', $address );
446
-                    update_user_meta( $user_id, '_wpinv_city', $city );
447
-                    update_user_meta( $user_id, '_wpinv_state', $state );
448
-                    update_user_meta( $user_id, '_wpinv_country', $country );
449
-                    update_user_meta( $user_id, '_wpinv_zip', $zip );
450
-                    update_user_meta( $user_id, '_wpinv_phone', $phone );
445
+                    update_user_meta($user_id, '_wpinv_address', $address);
446
+                    update_user_meta($user_id, '_wpinv_city', $city);
447
+                    update_user_meta($user_id, '_wpinv_state', $state);
448
+                    update_user_meta($user_id, '_wpinv_country', $country);
449
+                    update_user_meta($user_id, '_wpinv_zip', $zip);
450
+                    update_user_meta($user_id, '_wpinv_phone', $phone);
451 451
                 }
452 452
             }
453 453
 
454
-            do_action( 'wpinv_invoice_metabox_saved', $invoice );
454
+            do_action('wpinv_invoice_metabox_saved', $invoice);
455 455
         }
456 456
 
457 457
         return $saved;
Please login to merge, or discard this patch.
includes/admin/wpinv-upgrade-functions.php 1 patch
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -11,49 +11,49 @@  discard block
 block discarded – undo
11 11
  * @since 1.0.0
12 12
 */
13 13
 function wpinv_automatic_upgrade() {
14
-    $wpi_version = get_option( 'wpinv_version' );
14
+    $wpi_version = get_option('wpinv_version');
15 15
 
16
-    if ( $wpi_version == WPINV_VERSION ) {
16
+    if ($wpi_version == WPINV_VERSION) {
17 17
         return;
18 18
     }
19 19
     
20
-    if ( version_compare( $wpi_version, '0.0.5', '<' ) ) {
20
+    if (version_compare($wpi_version, '0.0.5', '<')) {
21 21
         wpinv_v005_upgrades();
22 22
     }
23 23
     
24
-    if ( version_compare( $wpi_version, '1.0.3', '<' ) ) {
24
+    if (version_compare($wpi_version, '1.0.3', '<')) {
25 25
         wpinv_v110_upgrades();
26 26
     }
27 27
     
28
-    update_option( 'wpinv_version', WPINV_VERSION );
28
+    update_option('wpinv_version', WPINV_VERSION);
29 29
 }
30
-add_action( 'admin_init', 'wpinv_automatic_upgrade' );
30
+add_action('admin_init', 'wpinv_automatic_upgrade');
31 31
 
32 32
 function wpinv_v005_upgrades() {
33 33
     global $wpdb;
34 34
     
35 35
     // Invoices status
36
-    $results = $wpdb->get_results( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
37
-    if ( !empty( $results ) ) {
38
-        $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
36
+    $results = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
37
+    if (!empty($results)) {
38
+        $wpdb->query("UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
39 39
         
40 40
         // Clean post cache
41
-        foreach ( $results as $row ) {
42
-            clean_post_cache( $row->ID );
41
+        foreach ($results as $row) {
42
+            clean_post_cache($row->ID);
43 43
         }
44 44
     }
45 45
     
46 46
     // Item meta key changes
47 47
     $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
48
-    $results = $wpdb->get_results( $query );
48
+    $results = $wpdb->get_results($query);
49 49
     
50
-    if ( !empty( $results ) ) {
51
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
52
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
53
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
50
+    if (!empty($results)) {
51
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )");
52
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'");
53
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'");
54 54
         
55
-        foreach ( $results as $row ) {
56
-            clean_post_cache( $row->post_id );
55
+        foreach ($results as $row) {
56
+            clean_post_cache($row->post_id);
57 57
         }
58 58
     }
59 59
 
@@ -74,79 +74,79 @@  discard block
 block discarded – undo
74 74
 function wpinv_convert_old_subscriptions() {
75 75
     global $wpdb;
76 76
 
77
-    $query = "SELECT ". $wpdb->posts .".ID FROM ". $wpdb->posts ." INNER JOIN ". $wpdb->postmeta ." ON ( ". $wpdb->posts .".ID = ". $wpdb->postmeta .".post_id ) WHERE 1=1  AND ". $wpdb->postmeta .".meta_key = '_wpinv_subscr_status' AND (". $wpdb->postmeta .".meta_value = 'pending' OR ". $wpdb->postmeta .".meta_value = 'active' OR ". $wpdb->postmeta .".meta_value = 'cancelled' OR ". $wpdb->postmeta .".meta_value = 'completed' OR ". $wpdb->postmeta .".meta_value = 'expired' OR ". $wpdb->postmeta .".meta_value = 'trialling' OR ". $wpdb->postmeta .".meta_value = 'failing') AND ". $wpdb->posts .".post_type = 'wpi_invoice' GROUP BY ". $wpdb->posts .".ID ORDER BY ". $wpdb->posts .".ID ASC";
77
+    $query = "SELECT " . $wpdb->posts . ".ID FROM " . $wpdb->posts . " INNER JOIN " . $wpdb->postmeta . " ON ( " . $wpdb->posts . ".ID = " . $wpdb->postmeta . ".post_id ) WHERE 1=1  AND " . $wpdb->postmeta . ".meta_key = '_wpinv_subscr_status' AND (" . $wpdb->postmeta . ".meta_value = 'pending' OR " . $wpdb->postmeta . ".meta_value = 'active' OR " . $wpdb->postmeta . ".meta_value = 'cancelled' OR " . $wpdb->postmeta . ".meta_value = 'completed' OR " . $wpdb->postmeta . ".meta_value = 'expired' OR " . $wpdb->postmeta . ".meta_value = 'trialling' OR " . $wpdb->postmeta . ".meta_value = 'failing') AND " . $wpdb->posts . ".post_type = 'wpi_invoice' GROUP BY " . $wpdb->posts . ".ID ORDER BY " . $wpdb->posts . ".ID ASC";
78 78
 
79
-    $results = $wpdb->get_results( $query );
79
+    $results = $wpdb->get_results($query);
80 80
 
81
-    if ( empty( $results ) ) {
81
+    if (empty($results)) {
82 82
         return;
83 83
     }
84 84
 
85
-    foreach ( $results as $row ) {
86
-        $invoice = new WPInv_Invoice( $row->ID );
85
+    foreach ($results as $row) {
86
+        $invoice = new WPInv_Invoice($row->ID);
87 87
 
88
-        if ( empty( $invoice->ID ) ) {
88
+        if (empty($invoice->ID)) {
89 89
             continue;
90 90
         }
91 91
 
92
-        if ( $invoice->has_status( 'wpi-renewal' ) ) {
92
+        if ($invoice->has_status('wpi-renewal')) {
93 93
             continue;
94 94
         }
95 95
         
96
-        $item = $invoice->get_recurring( true );
96
+        $item = $invoice->get_recurring(true);
97 97
 
98
-        if ( empty( $item ) ) {
98
+        if (empty($item)) {
99 99
             continue;
100 100
         }
101 101
 
102 102
         $is_free_trial          = $invoice->is_free_trial();
103
-        $profile_id             = get_post_meta( $invoice->ID, '_wpinv_subscr_profile_id', true );
104
-        $subscription_status    = get_post_meta( $invoice->ID, '_wpinv_subscr_status', true );
103
+        $profile_id             = get_post_meta($invoice->ID, '_wpinv_subscr_profile_id', true);
104
+        $subscription_status    = get_post_meta($invoice->ID, '_wpinv_subscr_status', true);
105 105
         $transaction_id         = $invoice->get_transaction_id();
106 106
 
107 107
         // Last invoice
108
-        $query          = "SELECT ID, post_date FROM ". $wpdb->posts ." WHERE post_type = 'wpi_invoice' AND post_parent = '" . $invoice->ID . "' ORDER BY ID DESC LIMIT 1";
109
-        $last_payment   = $wpdb->get_row( $query );
108
+        $query          = "SELECT ID, post_date FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_parent = '" . $invoice->ID . "' ORDER BY ID DESC LIMIT 1";
109
+        $last_payment   = $wpdb->get_row($query);
110 110
 
111
-        if ( !empty( $last_payment ) ) {
112
-            $invoice_date       = $last_payment->post_date;
111
+        if (!empty($last_payment)) {
112
+            $invoice_date = $last_payment->post_date;
113 113
             
114
-            $meta_profile_id     = get_post_meta( $last_payment->ID, '_wpinv_subscr_profile_id', true );
115
-            $meta_transaction_id = get_post_meta( $last_payment->ID, '_wpinv_transaction_id', true );
114
+            $meta_profile_id     = get_post_meta($last_payment->ID, '_wpinv_subscr_profile_id', true);
115
+            $meta_transaction_id = get_post_meta($last_payment->ID, '_wpinv_transaction_id', true);
116 116
 
117
-            if ( !empty( $meta_profile_id ) ) {
118
-                $profile_id  = $meta_profile_id;
117
+            if (!empty($meta_profile_id)) {
118
+                $profile_id = $meta_profile_id;
119 119
             }
120 120
 
121
-            if ( !empty( $meta_transaction_id ) ) {
122
-                $transaction_id  = $meta_transaction_id;
121
+            if (!empty($meta_transaction_id)) {
122
+                $transaction_id = $meta_transaction_id;
123 123
             }
124 124
         } else {
125
-            $invoice_date       = $invoice->get_invoice_date( false );
125
+            $invoice_date       = $invoice->get_invoice_date(false);
126 126
         }
127 127
         
128
-        $profile_id             = empty( $profile_id ) ? $invoice->ID : $profile_id;
129
-        $status                 = empty( $subscription_status ) ? 'pending' : $subscription_status;
128
+        $profile_id             = empty($profile_id) ? $invoice->ID : $profile_id;
129
+        $status                 = empty($subscription_status) ? 'pending' : $subscription_status;
130 130
         
131
-        $period                 = $item->get_recurring_period( true );
131
+        $period                 = $item->get_recurring_period(true);
132 132
         $interval               = $item->get_recurring_interval();
133
-        $bill_times             = (int)$item->get_recurring_limit();
133
+        $bill_times             = (int) $item->get_recurring_limit();
134 134
         $add_period             = $interval . ' ' . $period;
135 135
         $trial_period           = '';
136 136
 
137
-        if ( $invoice->is_free_trial() ) {
138
-            $trial_period       = $item->get_trial_period( true );
137
+        if ($invoice->is_free_trial()) {
138
+            $trial_period       = $item->get_trial_period(true);
139 139
             $free_interval      = $item->get_trial_interval();
140 140
             $trial_period       = $free_interval . ' ' . $trial_period;
141 141
 
142
-            if ( empty( $last_payment ) ) {
142
+            if (empty($last_payment)) {
143 143
                 $add_period     = $trial_period;
144 144
             }
145 145
         }
146 146
 
147
-        $expiration             = date_i18n( 'Y-m-d H:i:s', strtotime( '+' . $add_period  . ' 23:59:59', strtotime( $invoice_date ) ) );
148
-        if ( strtotime( $expiration ) <  strtotime( date_i18n( 'Y-m-d' ) ) ) {
149
-            if ( $status == 'active' || $status == 'trialling' || $status == 'pending' ) {
147
+        $expiration = date_i18n('Y-m-d H:i:s', strtotime('+' . $add_period . ' 23:59:59', strtotime($invoice_date)));
148
+        if (strtotime($expiration) < strtotime(date_i18n('Y-m-d'))) {
149
+            if ($status == 'active' || $status == 'trialling' || $status == 'pending') {
150 150
                 $status = 'expired';
151 151
             }
152 152
         }
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
             'frequency'         => $interval,
160 160
             'period'            => $period,
161 161
             'initial_amount'    => $invoice->get_total(),
162
-            'recurring_amount'  => $invoice->get_recurring_details( 'total' ),
162
+            'recurring_amount'  => $invoice->get_recurring_details('total'),
163 163
             'bill_times'        => $bill_times,
164 164
             'created'           => $invoice_date,
165 165
             'expiration'        => $expiration,
@@ -169,14 +169,14 @@  discard block
 block discarded – undo
169 169
         );
170 170
 
171 171
         $subs_db      = new WPInv_Subscriptions_DB;
172
-        $subs         = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice->ID, 'number' => 1 ) );
173
-        $subscription = reset( $subs );
172
+        $subs         = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->ID, 'number' => 1));
173
+        $subscription = reset($subs);
174 174
 
175
-        if ( empty( $subscription ) || $subscription->id <= 0 ) {
175
+        if (empty($subscription) || $subscription->id <= 0) {
176 176
             $subscription = new WPInv_Subscription();
177
-            $new_sub = $subscription->create( $args );
177
+            $new_sub = $subscription->create($args);
178 178
 
179
-            if ( !empty( $bill_times ) && $new_sub->get_times_billed() >= $bill_times && ( 'active' == $new_sub->status || 'trialling' == $new_sub->status ) ) {
179
+            if (!empty($bill_times) && $new_sub->get_times_billed() >= $bill_times && ('active' == $new_sub->status || 'trialling' == $new_sub->status)) {
180 180
                 $new_sub->complete(); // Mark completed if all times billed
181 181
             }
182 182
         }
@@ -186,20 +186,20 @@  discard block
 block discarded – undo
186 186
 function wpinv_update_new_email_settings() {
187 187
     global $wpinv_options;
188 188
 
189
-    $current_options = get_option( 'wpinv_settings', array() );
189
+    $current_options = get_option('wpinv_settings', array());
190 190
     $options = array(
191
-        'email_new_invoice_body' => __( '<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing' ),
192
-        'email_cancelled_invoice_body' => __( '<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing' ),
193
-        'email_failed_invoice_body' => __( '<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing' ),
194
-        'email_onhold_invoice_body' => __( '<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing' ),
195
-        'email_processing_invoice_body' => __( '<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing' ),
196
-        'email_refunded_invoice_body' => __( '<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing' ),
197
-        'email_user_invoice_body' => __( '<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' ),
198
-        'email_user_note_body' => __( '<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing' ),
199
-        'email_overdue_body' => __( '<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' ),
191
+        'email_new_invoice_body' => __('<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing'),
192
+        'email_cancelled_invoice_body' => __('<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing'),
193
+        'email_failed_invoice_body' => __('<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing'),
194
+        'email_onhold_invoice_body' => __('<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing'),
195
+        'email_processing_invoice_body' => __('<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing'),
196
+        'email_refunded_invoice_body' => __('<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing'),
197
+        'email_user_invoice_body' => __('<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'),
198
+        'email_user_note_body' => __('<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing'),
199
+        'email_overdue_body' => __('<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'),
200 200
     );
201 201
 
202
-    foreach ($options as $option => $value){
202
+    foreach ($options as $option => $value) {
203 203
         if (!isset($current_options[$option])) {
204 204
             $current_options[$option] = $value;
205 205
         }
@@ -207,5 +207,5 @@  discard block
 block discarded – undo
207 207
 
208 208
     $wpinv_options = $current_options;
209 209
 
210
-    update_option( 'wpinv_settings', $current_options );
210
+    update_option('wpinv_settings', $current_options);
211 211
 }
212 212
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-notes.php 1 patch
Spacing   +42 added lines, -42 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; // Exit if accessed directly
4 4
 }
5 5
 
@@ -14,74 +14,74 @@  discard block
 block discarded – undo
14 14
     }
15 15
     
16 16
     public function init() {
17
-        do_action( 'wpinv_class_notes_init', $this );
17
+        do_action('wpinv_class_notes_init', $this);
18 18
     }
19 19
     
20 20
     public function includes() {
21
-        do_action( 'wpinv_class_notes_includes', $this );
21
+        do_action('wpinv_class_notes_includes', $this);
22 22
     }
23 23
     
24 24
     public function actions() {
25 25
         // Secure inovice notes
26
-        add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
27
-        add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 );
26
+        add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1);
27
+        add_action('comment_feed_where', array($this, 'wpinv_comment_feed_where'), 10, 1);
28 28
         
29 29
         // Count comments
30
-        add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 11, 2 );
30
+        add_filter('wp_count_comments', array($this, 'wp_count_comments'), 11, 2);
31 31
         
32 32
         // Delete comments count cache whenever there is a new comment or a comment status changes
33
-        add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) );
34
-        add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) );
33
+        add_action('wp_insert_comment', array($this, 'delete_comments_count_cache'));
34
+        add_action('wp_set_comment_status', array($this, 'delete_comments_count_cache'));
35 35
         
36
-        do_action( 'wpinv_class_notes_actions', $this );
36
+        do_action('wpinv_class_notes_actions', $this);
37 37
     }
38 38
         
39
-    public function set_invoice_note_type( $query ) {
40
-        $post_ID        = !empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
39
+    public function set_invoice_note_type($query) {
40
+        $post_ID = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
41 41
         
42
-        if ( $post_ID && in_array(get_post_type( $post_ID ), array($this->invoice_post_type, 'wpi_quote' )) ) {
42
+        if ($post_ID && in_array(get_post_type($post_ID), array($this->invoice_post_type, 'wpi_quote'))) {
43 43
             $query->query_vars['type__in']      = $this->comment_type;
44 44
             $query->query_vars['type__not_in']  = '';
45 45
         } else {        
46
-            if ( isset( $query->query_vars['type__in'] ) && $type_in = $query->query_vars['type__in'] ) {
47
-                if ( is_array( $type_in ) && in_array( $this->comment_type, $type_in ) ) {
48
-                    $key = array_search( $this->comment_type, $type_in );
49
-                    unset( $query->query_vars['type__in'][$key] );
50
-                } else if ( !is_array( $type_in ) && $type_in == $this->comment_type ) {
46
+            if (isset($query->query_vars['type__in']) && $type_in = $query->query_vars['type__in']) {
47
+                if (is_array($type_in) && in_array($this->comment_type, $type_in)) {
48
+                    $key = array_search($this->comment_type, $type_in);
49
+                    unset($query->query_vars['type__in'][$key]);
50
+                } else if (!is_array($type_in) && $type_in == $this->comment_type) {
51 51
                     $query->query_vars['type__in'] = '';
52 52
                 }
53 53
             }
54 54
             
55
-            if ( isset( $query->query_vars['type__not_in'] ) && $type_not_in = $query->query_vars['type__not_in'] ) {
56
-                if ( is_array( $type_not_in ) && !in_array( $this->comment_type, $type_not_in ) ) {
55
+            if (isset($query->query_vars['type__not_in']) && $type_not_in = $query->query_vars['type__not_in']) {
56
+                if (is_array($type_not_in) && !in_array($this->comment_type, $type_not_in)) {
57 57
                     $query->query_vars['type__not_in'][] = $this->comment_type;
58
-                } else if ( !is_array( $type_not_in ) && $type_not_in != $this->comment_type ) {
59
-                    $query->query_vars['type__not_in'] = (array)$query->query_vars['type__not_in'];
58
+                } else if (!is_array($type_not_in) && $type_not_in != $this->comment_type) {
59
+                    $query->query_vars['type__not_in'] = (array) $query->query_vars['type__not_in'];
60 60
                     $query->query_vars['type__not_in'][] = $this->comment_type;
61 61
                 }
62 62
             } else {
63
-                $query->query_vars['type__not_in']  = $this->comment_type;
63
+                $query->query_vars['type__not_in'] = $this->comment_type;
64 64
             }
65 65
         }
66 66
         
67 67
         return $query;
68 68
     }
69 69
     
70
-    public function get_invoice_notes( $invoice_id = 0, $type = '' ) {
70
+    public function get_invoice_notes($invoice_id = 0, $type = '') {
71 71
         $args = array( 
72 72
             'post_id'   => $invoice_id,
73 73
             'orderby'   => 'comment_ID',
74 74
             'order'     => 'ASC',
75 75
         );
76 76
         
77
-        if ( $type == 'customer' ) {
77
+        if ($type == 'customer') {
78 78
             $args['meta_key']   = '_wpi_customer_note';
79 79
             $args['meta_value'] = 1;
80 80
         }
81 81
         
82
-        $args   = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
82
+        $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type);
83 83
         
84
-        return get_comments( $args );
84
+        return get_comments($args);
85 85
     }
86 86
     
87 87
     /**
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
      * @return void
93 93
      */
94 94
     public function delete_comments_count_cache() {
95
-        delete_transient( 'wpinv_count_comments' );
95
+        delete_transient('wpinv_count_comments');
96 96
     }
97 97
     
98 98
     /**
@@ -103,16 +103,16 @@  discard block
 block discarded – undo
103 103
      * @param  int    $post_id Post ID.
104 104
      * @return object
105 105
      */
106
-    public function wp_count_comments( $stats, $post_id ) {
106
+    public function wp_count_comments($stats, $post_id) {
107 107
         global $wpdb;
108 108
 
109
-        if ( 0 === $post_id ) {
110
-            $stats = get_transient( 'wpinv_count_comments' );
109
+        if (0 === $post_id) {
110
+            $stats = get_transient('wpinv_count_comments');
111 111
 
112
-            if ( ! $stats ) {
112
+            if (!$stats) {
113 113
                 $stats = array();
114 114
 
115
-                $count = $wpdb->get_results( "SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A );
115
+                $count = $wpdb->get_results("SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A);
116 116
 
117 117
                 $total = 0;
118 118
                 $approved = array(
@@ -123,33 +123,33 @@  discard block
 block discarded – undo
123 123
                     'post-trashed' => 'post-trashed',
124 124
                 );
125 125
 
126
-                foreach ( (array) $count as $row ) {
126
+                foreach ((array) $count as $row) {
127 127
                     // Do not count post-trashed toward totals.
128
-                    if ( 'post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved'] ) {
128
+                    if ('post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved']) {
129 129
                         $total += $row['num_comments'];
130 130
                     }
131
-                    if ( isset( $approved[ $row['comment_approved'] ] ) ) {
132
-                        $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
131
+                    if (isset($approved[$row['comment_approved']])) {
132
+                        $stats[$approved[$row['comment_approved']]] = $row['num_comments'];
133 133
                     }
134 134
                 }
135 135
 
136 136
                 $stats['total_comments'] = $total;
137 137
                 $stats['all'] = $total;
138
-                foreach ( $approved as $key ) {
139
-                    if ( empty( $stats[ $key ] ) ) {
140
-                        $stats[ $key ] = 0;
138
+                foreach ($approved as $key) {
139
+                    if (empty($stats[$key])) {
140
+                        $stats[$key] = 0;
141 141
                     }
142 142
                 }
143 143
 
144 144
                 $stats = (object) $stats;
145
-                set_transient( 'wpinv_count_comments', $stats );
145
+                set_transient('wpinv_count_comments', $stats);
146 146
             }
147 147
         }
148 148
 
149 149
         return $stats;
150 150
     }
151 151
 
152
-    function wpinv_comment_feed_where($where){
153
-        return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
152
+    function wpinv_comment_feed_where($where) {
153
+        return $where . ($where ? ' AND ' : '') . " comment_type != 'wpinv_note' ";
154 154
     }
155 155
 }
Please login to merge, or discard this patch.
includes/wpinv-payment-functions.php 1 patch
Spacing   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -1,155 +1,155 @@  discard block
 block discarded – undo
1 1
 <?php
2
-function wpinv_is_subscription_payment( $invoice = '' ) {
3
-    if ( empty( $invoice ) ) {
2
+function wpinv_is_subscription_payment($invoice = '') {
3
+    if (empty($invoice)) {
4 4
         return false;
5 5
     }
6 6
     
7
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
8
-        $invoice = wpinv_get_invoice( $invoice );
7
+    if (!is_object($invoice) && is_scalar($invoice)) {
8
+        $invoice = wpinv_get_invoice($invoice);
9 9
     }
10 10
     
11
-    if ( empty( $invoice ) ) {
11
+    if (empty($invoice)) {
12 12
         return false;
13 13
     }
14 14
         
15
-    if ( $invoice->is_renewal() ) {
15
+    if ($invoice->is_renewal()) {
16 16
         return true;
17 17
     }
18 18
 
19 19
     return false;
20 20
 }
21 21
 
22
-function wpinv_payment_link_transaction_id( $invoice = '' ) {
23
-    if ( empty( $invoice ) ) {
22
+function wpinv_payment_link_transaction_id($invoice = '') {
23
+    if (empty($invoice)) {
24 24
         return false;
25 25
     }
26 26
     
27
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
28
-        $invoice = wpinv_get_invoice( $invoice );
27
+    if (!is_object($invoice) && is_scalar($invoice)) {
28
+        $invoice = wpinv_get_invoice($invoice);
29 29
     }
30 30
     
31
-    if ( empty( $invoice ) ) {
31
+    if (empty($invoice)) {
32 32
         return false;
33 33
     }
34 34
 
35
-    return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice );
35
+    return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice);
36 36
 }
37 37
 
38
-function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) {
39
-    $interval   = (int)$interval > 0 ? (int)$interval : 1;
38
+function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) {
39
+    $interval   = (int) $interval > 0 ? (int) $interval : 1;
40 40
     
41
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
42
-        $amount = __( 'Free', 'invoicing' );
41
+    if ($trial_interval > 0 && !empty($trial_period)) {
42
+        $amount = __('Free', 'invoicing');
43 43
         $interval = $trial_interval;
44 44
         $period = $trial_period;
45 45
     }
46 46
     
47 47
     $description = '';
48
-    switch ( $period ) {
48
+    switch ($period) {
49 49
         case 'D' :
50 50
         case 'day' :
51
-            $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval );
51
+            $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval);
52 52
             break;
53 53
         case 'W' :
54 54
         case 'week' :
55
-            $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval );
55
+            $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval);
56 56
             break;
57 57
         case 'M' :
58 58
         case 'month' :
59
-            $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval );
59
+            $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval);
60 60
             break;
61 61
         case 'Y' :
62 62
         case 'year' :
63
-            $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval );
63
+            $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval);
64 64
             break;
65 65
     }
66 66
 
67
-    return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval  );
67
+    return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval);
68 68
 }
69 69
 
70
-function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) {
71
-    $interval   = (int)$interval > 0 ? (int)$interval : 1;
72
-    $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0;
70
+function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) {
71
+    $interval   = (int) $interval > 0 ? (int) $interval : 1;
72
+    $bill_times = (int) $bill_times > 0 ? (int) $bill_times : 0;
73 73
     
74 74
     $description = '';
75
-    switch ( $period ) {
75
+    switch ($period) {
76 76
         case 'D' :
77 77
         case 'day' :            
78
-            if ( (int)$bill_times > 0 ) {
79
-                if ( $interval > 1 ) {
80
-                    if ( $bill_times > 1 ) {
81
-                        $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
78
+            if ((int) $bill_times > 0) {
79
+                if ($interval > 1) {
80
+                    if ($bill_times > 1) {
81
+                        $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
82 82
                     } else {
83
-                        $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval );
83
+                        $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval);
84 84
                     }
85 85
                 } else {
86
-                    $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
86
+                    $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
87 87
                 }
88 88
             } else {
89
-                $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval );
89
+                $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval);
90 90
             }
91 91
             break;
92 92
         case 'W' :
93 93
         case 'week' :            
94
-            if ( (int)$bill_times > 0 ) {
95
-                if ( $interval > 1 ) {
96
-                    if ( $bill_times > 1 ) {
97
-                        $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
94
+            if ((int) $bill_times > 0) {
95
+                if ($interval > 1) {
96
+                    if ($bill_times > 1) {
97
+                        $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
98 98
                     } else {
99
-                        $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval );
99
+                        $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval);
100 100
                     }
101 101
                 } else {
102
-                    $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
102
+                    $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
103 103
                 }
104 104
             } else {
105
-                $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval );
105
+                $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval);
106 106
             }
107 107
             break;
108 108
         case 'M' :
109 109
         case 'month' :            
110
-            if ( (int)$bill_times > 0 ) {
111
-                if ( $interval > 1 ) {
112
-                    if ( $bill_times > 1 ) {
113
-                        $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
110
+            if ((int) $bill_times > 0) {
111
+                if ($interval > 1) {
112
+                    if ($bill_times > 1) {
113
+                        $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
114 114
                     } else {
115
-                        $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval );
115
+                        $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval);
116 116
                     }
117 117
                 } else {
118
-                    $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
118
+                    $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
119 119
                 }
120 120
             } else {
121
-                $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval );
121
+                $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval);
122 122
             }
123 123
             break;
124 124
         case 'Y' :
125 125
         case 'year' :            
126
-            if ( (int)$bill_times > 0 ) {
127
-                if ( $interval > 1 ) {
128
-                    if ( $bill_times > 1 ) {
129
-                        $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
126
+            if ((int) $bill_times > 0) {
127
+                if ($interval > 1) {
128
+                    if ($bill_times > 1) {
129
+                        $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
130 130
                     } else {
131
-                        $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval );
131
+                        $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval);
132 132
                     }
133 133
                 } else {
134
-                    $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
134
+                    $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
135 135
                 }
136 136
             } else {
137
-                $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval );
137
+                $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval);
138 138
             }
139 139
             break;
140 140
     }
141 141
 
142
-    return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
142
+    return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
143 143
 }
144 144
 
145
-function wpinv_subscription_payment_desc( $invoice ) {
146
-    if ( empty( $invoice ) ) {
145
+function wpinv_subscription_payment_desc($invoice) {
146
+    if (empty($invoice)) {
147 147
         return NULL;
148 148
     }
149 149
     
150 150
     $description = '';
151
-    if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) {
152
-        if ( $item->has_free_trial() ) {
151
+    if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) {
152
+        if ($item->has_free_trial()) {
153 153
             $trial_period = $item->get_trial_period();
154 154
             $trial_interval = $item->get_trial_interval();
155 155
         } else {
@@ -157,45 +157,45 @@  discard block
 block discarded – undo
157 157
             $trial_interval = 0;
158 158
         }
159 159
         
160
-        $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() );
160
+        $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency());
161 161
     }
162 162
     
163
-    return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice );
163
+    return apply_filters('wpinv_subscription_payment_desc', $description, $invoice);
164 164
 }
165 165
 
166
-function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) {
167
-    $initial_total      = wpinv_round_amount( $initial );
168
-    $recurring_total    = wpinv_round_amount( $recurring );
166
+function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') {
167
+    $initial_total      = wpinv_round_amount($initial);
168
+    $recurring_total    = wpinv_round_amount($recurring);
169 169
     
170
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
170
+    if ($trial_interval > 0 && !empty($trial_period)) {
171 171
         // Free trial
172 172
     } else {
173
-        if ( $bill_times == 1 ) {
173
+        if ($bill_times == 1) {
174 174
             $recurring_total = $initial_total;
175
-        } else if ( $bill_times > 1 && $initial_total != $recurring_total ) {
175
+        } else if ($bill_times > 1 && $initial_total != $recurring_total) {
176 176
             $bill_times--;
177 177
         }
178 178
     }
179 179
     
180
-    $initial_amount     = wpinv_price( wpinv_format_amount( $initial_total ), $currency );
181
-    $recurring_amount   = wpinv_price( wpinv_format_amount( $recurring_total ), $currency );
180
+    $initial_amount     = wpinv_price(wpinv_format_amount($initial_total), $currency);
181
+    $recurring_amount   = wpinv_price(wpinv_format_amount($recurring_total), $currency);
182 182
     
183
-    $recurring          = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
183
+    $recurring          = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
184 184
         
185
-    if ( $initial_total != $recurring_total ) {
186
-        $initial        = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval );
185
+    if ($initial_total != $recurring_total) {
186
+        $initial        = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval);
187 187
         
188
-        $description    = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring );
188
+        $description    = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring);
189 189
     } else {
190 190
         $description    = $recurring;
191 191
     }
192 192
     
193
-    return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency );
193
+    return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency);
194 194
 }
195 195
 
196
-function wpinv_recurring_send_payment_failed( $invoice ) {
197
-    if ( !empty( $invoice->ID ) ) {
198
-        wpinv_failed_invoice_notification( $invoice->ID );
196
+function wpinv_recurring_send_payment_failed($invoice) {
197
+    if (!empty($invoice->ID)) {
198
+        wpinv_failed_invoice_notification($invoice->ID);
199 199
     }
200 200
 }
201
-add_action( 'wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1 );
202 201
\ No newline at end of file
202
+add_action('wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1);
203 203
\ No newline at end of file
Please login to merge, or discard this patch.
templates/wpinv-invoice-receipt.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -4,17 +4,17 @@  discard block
 block discarded – undo
4 4
  */
5 5
 global $wpinv_receipt_args;
6 6
 
7
-$invoice   = get_post( $wpinv_receipt_args['id'] );
7
+$invoice = get_post($wpinv_receipt_args['id']);
8 8
 
9
-if( empty( $invoice ) ) {
9
+if (empty($invoice)) {
10 10
     ?>
11 11
     <div class="wpinv_errors alert wpi-alert-error">
12
-        <?php _e( 'The specified receipt ID appears to be invalid', 'invoicing' ); ?>
12
+        <?php _e('The specified receipt ID appears to be invalid', 'invoicing'); ?>
13 13
     </div>
14 14
     <?php
15 15
     return;
16 16
 }
17
-$invoice = wpinv_get_invoice( $invoice->ID );
17
+$invoice = wpinv_get_invoice($invoice->ID);
18 18
 
19 19
 global $ajax_cart_details;
20 20
 $ajax_cart_details = $invoice->get_cart_details();
@@ -23,19 +23,19 @@  discard block
 block discarded – undo
23 23
 $invoice_id         = $invoice->ID;
24 24
 $quantities_enabled = wpinv_item_quantities_enabled();
25 25
 $use_taxes          = wpinv_use_taxes();
26
-$zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
27
-$tax_label          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? __( '(Tax Incl.)', 'invoicing' ) : __( '(Tax Excl.)', 'invoicing' ) ) : '';
26
+$zero_tax           = !(float) $invoice->get_tax() > 0 ? true : false;
27
+$tax_label          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? __('(Tax Incl.)', 'invoicing') : __('(Tax Excl.)', 'invoicing')) : '';
28 28
 ?>
29
-<?php do_action( 'wpinv_before_receipt', $invoice ); ?>
29
+<?php do_action('wpinv_before_receipt', $invoice); ?>
30 30
 <div class="wpinv-receipt">
31
-    <?php do_action( 'wpinv_receipt_start', $invoice ); ?>
32
-    <div class="wpinv-receipt-message"><?php _e( 'Thank you for your payment!', 'invoicing' ); ?></div>
33
-    <?php do_action( 'wpinv_before_receipt_details', $invoice ); ?>
31
+    <?php do_action('wpinv_receipt_start', $invoice); ?>
32
+    <div class="wpinv-receipt-message"><?php _e('Thank you for your payment!', 'invoicing'); ?></div>
33
+    <?php do_action('wpinv_before_receipt_details', $invoice); ?>
34 34
     <div class="wpinv-receipt-details">
35
-        <h3 class="wpinv-details-t"><?php echo apply_filters( 'wpinv_receipt_details_title', __( 'Invoice Details', 'invoicing' ) ); ?></h3>
36
-        <?php wpinv_display_invoice_details( $invoice ); ?>
35
+        <h3 class="wpinv-details-t"><?php echo apply_filters('wpinv_receipt_details_title', __('Invoice Details', 'invoicing')); ?></h3>
36
+        <?php wpinv_display_invoice_details($invoice); ?>
37 37
     </div>
38
-    <?php do_action( 'wpinv_after_receipt_details', $invoice ); ?>
39
-    <?php do_action( 'wpinv_receipt_end', $invoice ); ?>
38
+    <?php do_action('wpinv_after_receipt_details', $invoice); ?>
39
+    <?php do_action('wpinv_receipt_end', $invoice); ?>
40 40
 </div>
41
-<?php do_action( 'wpinv_after_receipt', $invoice ); ?>
42 41
\ No newline at end of file
42
+<?php do_action('wpinv_after_receipt', $invoice); ?>
43 43
\ No newline at end of file
Please login to merge, or discard this patch.
includes/api/class-wpinv-rest-items-controller.php 2 patches
Indentation   +987 added lines, -987 removed lines patch added patch discarded remove patch
@@ -20,91 +20,91 @@  discard block
 block discarded – undo
20 20
 class WPInv_REST_Items_Controller extends WP_REST_Posts_Controller {
21 21
 
22 22
     /**
23
-	 * Post type.
24
-	 *
25
-	 * @var string
26
-	 */
27
-	protected $post_type = 'wpi_item';
23
+     * Post type.
24
+     *
25
+     * @var string
26
+     */
27
+    protected $post_type = 'wpi_item';
28 28
 	
29
-	/**
30
-	 * Cached results of get_item_schema.
31
-	 *
32
-	 * @since 1.0.13
33
-	 * @var array
34
-	 */
35
-	protected $schema;
29
+    /**
30
+     * Cached results of get_item_schema.
31
+     *
32
+     * @since 1.0.13
33
+     * @var array
34
+     */
35
+    protected $schema;
36 36
 
37 37
     /**
38
-	 * Constructor.
39
-	 *
40
-	 * @since 1.0.13
41
-	 *
42
-	 * @param string $namespace Api Namespace
43
-	 */
44
-	public function __construct( $namespace ) {
38
+     * Constructor.
39
+     *
40
+     * @since 1.0.13
41
+     *
42
+     * @param string $namespace Api Namespace
43
+     */
44
+    public function __construct( $namespace ) {
45 45
         
46 46
         // Set api namespace...
47
-		$this->namespace = $namespace;
47
+        $this->namespace = $namespace;
48 48
 
49 49
         // ... and the rest base
50 50
         $this->rest_base = 'items';
51 51
 		
52 52
     }
53 53
 	
54
-	/**
55
-	 * Registers the routes for the objects of the controller.
56
-	 *
57
-	 * @since 1.0.13
58
-	 *
59
-	 * @see register_rest_route()
60
-	 */
61
-	public function register_routes() {
62
-
63
-		parent::register_routes();
64
-
65
-		register_rest_route(
66
-			$this->namespace,
67
-			'/' . $this->rest_base . '/item-types',
68
-			array(
69
-				array(
70
-					'methods'             => WP_REST_Server::READABLE,
71
-					'callback'            => array( $this, 'get_item_types' ),
72
-				),
73
-			)
74
-		);
75
-
76
-	}
54
+    /**
55
+     * Registers the routes for the objects of the controller.
56
+     *
57
+     * @since 1.0.13
58
+     *
59
+     * @see register_rest_route()
60
+     */
61
+    public function register_routes() {
62
+
63
+        parent::register_routes();
64
+
65
+        register_rest_route(
66
+            $this->namespace,
67
+            '/' . $this->rest_base . '/item-types',
68
+            array(
69
+                array(
70
+                    'methods'             => WP_REST_Server::READABLE,
71
+                    'callback'            => array( $this, 'get_item_types' ),
72
+                ),
73
+            )
74
+        );
75
+
76
+    }
77 77
 
78 78
     /**
79
-	 * Checks if a given request has access to read items.
79
+     * Checks if a given request has access to read items.
80 80
      * 
81
-	 *
82
-	 * @since 1.0.13
83
-	 *
84
-	 * @param WP_REST_Request $request Full details about the request.
85
-	 * @return true|WP_Error True if the request has read access, WP_Error object otherwise.
86
-	 */
87
-	public function get_items_permissions_check( $request ) {
81
+     *
82
+     * @since 1.0.13
83
+     *
84
+     * @param WP_REST_Request $request Full details about the request.
85
+     * @return true|WP_Error True if the request has read access, WP_Error object otherwise.
86
+     */
87
+    public function get_items_permissions_check( $request ) {
88 88
 	
89
-		if ( current_user_can( 'manage_options' ) ||  current_user_can( 'manage_invoicing' ) ) {
90
-			return true;
91
-		}
89
+        if ( current_user_can( 'manage_options' ) ||  current_user_can( 'manage_invoicing' ) ) {
90
+            return true;
91
+        }
92 92
 
93
-		return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to view invoice items.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
93
+        return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to view invoice items.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
94 94
 
95 95
     }
96 96
     
97 97
     /**
98
-	 * Retrieves a collection of invoice items.
99
-	 *
100
-	 * @since 1.0.13
101
-	 *
102
-	 * @param WP_REST_Request $request Full details about the request.
103
-	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
104
-	 */
105
-	public function get_items( $request ) {
98
+     * Retrieves a collection of invoice items.
99
+     *
100
+     * @since 1.0.13
101
+     *
102
+     * @param WP_REST_Request $request Full details about the request.
103
+     * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
104
+     */
105
+    public function get_items( $request ) {
106 106
 		
107
-		// Retrieve the list of registered item query parameters.
107
+        // Retrieve the list of registered item query parameters.
108 108
         $registered = $this->get_collection_params();
109 109
         
110 110
         $args       = array();
@@ -117,54 +117,54 @@  discard block
 block discarded – undo
117 117
 
118 118
         }
119 119
 
120
-		/**
121
-		 * Filters the wpinv_get_items arguments for items rest requests.
122
-		 *
123
-		 *
124
-		 * @since 1.0.13
125
-		 *
126
-		 *
127
-		 * @param array           $args    Key value array of query var to query value.
128
-		 * @param WP_REST_Request $request The request used.
129
-		 */
120
+        /**
121
+         * Filters the wpinv_get_items arguments for items rest requests.
122
+         *
123
+         *
124
+         * @since 1.0.13
125
+         *
126
+         *
127
+         * @param array           $args    Key value array of query var to query value.
128
+         * @param WP_REST_Request $request The request used.
129
+         */
130 130
         $args       = apply_filters( "wpinv_rest_get_items_arguments", $args, $request, $this );
131 131
 		
132
-		// Special args
133
-		$args[ 'return' ]   = 'objects';
134
-		$args[ 'paginate' ] = true;
132
+        // Special args
133
+        $args[ 'return' ]   = 'objects';
134
+        $args[ 'paginate' ] = true;
135 135
 
136 136
         // Run the query.
137
-		$query = wpinv_get_all_items( $args );
137
+        $query = wpinv_get_all_items( $args );
138 138
 		
139
-		// Prepare the retrieved items
140
-		$items = array();
141
-		foreach( $query->items as $item ) {
142
-
143
-			if ( ! $this->check_read_permission( $item ) ) {
144
-				continue;
145
-			}
146
-
147
-			$data       = $this->prepare_item_for_response( $item, $request );
148
-			$items[]    = $this->prepare_response_for_collection( $data );
149
-
150
-		}
151
-
152
-		// Prepare the response.
153
-		$response = rest_ensure_response( $items );
154
-		$response->header( 'X-WP-Total', (int) $query->total );
155
-		$response->header( 'X-WP-TotalPages', (int) $query->max_num_pages );
156
-
157
-		/**
158
-		 * Filters the responses for item requests.
159
-		 *
160
-		 *
161
-		 * @since 1.0.13
162
-		 *
163
-		 *
164
-		 * @param arrWP_REST_Response $response    Response object.
165
-		 * @param WP_REST_Request     $request The request used.
139
+        // Prepare the retrieved items
140
+        $items = array();
141
+        foreach( $query->items as $item ) {
142
+
143
+            if ( ! $this->check_read_permission( $item ) ) {
144
+                continue;
145
+            }
146
+
147
+            $data       = $this->prepare_item_for_response( $item, $request );
148
+            $items[]    = $this->prepare_response_for_collection( $data );
149
+
150
+        }
151
+
152
+        // Prepare the response.
153
+        $response = rest_ensure_response( $items );
154
+        $response->header( 'X-WP-Total', (int) $query->total );
155
+        $response->header( 'X-WP-TotalPages', (int) $query->max_num_pages );
156
+
157
+        /**
158
+         * Filters the responses for item requests.
159
+         *
160
+         *
161
+         * @since 1.0.13
162
+         *
163
+         *
164
+         * @param arrWP_REST_Response $response    Response object.
165
+         * @param WP_REST_Request     $request The request used.
166 166
          * @param array               $args Array of args used to retrieve the items
167
-		 */
167
+         */
168 168
         $response       = apply_filters( "wpinv_rest_items_response", $response, $request, $args );
169 169
 
170 170
         return rest_ensure_response( $response );
@@ -172,25 +172,25 @@  discard block
 block discarded – undo
172 172
     }
173 173
 
174 174
     /**
175
-	 * Get the post, if the ID is valid.
176
-	 *
177
-	 * @since 1.0.13
178
-	 *
179
-	 * @param int $item_id Supplied ID.
180
-	 * @return WPInv_Item|WP_Error Item object if ID is valid, WP_Error otherwise.
181
-	 */
182
-	protected function get_post( $item_id ) {
175
+     * Get the post, if the ID is valid.
176
+     *
177
+     * @since 1.0.13
178
+     *
179
+     * @param int $item_id Supplied ID.
180
+     * @return WPInv_Item|WP_Error Item object if ID is valid, WP_Error otherwise.
181
+     */
182
+    protected function get_post( $item_id ) {
183 183
 		
184
-		$error     = new WP_Error( 'rest_item_invalid_id', __( 'Invalid item ID.', 'invoicing' ), array( 'status' => 404 ) );
184
+        $error     = new WP_Error( 'rest_item_invalid_id', __( 'Invalid item ID.', 'invoicing' ), array( 'status' => 404 ) );
185 185
 
186 186
         // Ids start from 1
187 187
         if ( (int) $item_id <= 0 ) {
188
-			return $error;
189
-		}
188
+            return $error;
189
+        }
190 190
 
191
-		$item = wpinv_get_item_by( 'id', (int) $item_id );
192
-		if ( empty( $item ) ) {
193
-			return $error;
191
+        $item = wpinv_get_item_by( 'id', (int) $item_id );
192
+        if ( empty( $item ) ) {
193
+            return $error;
194 194
         }
195 195
 
196 196
         return $item;
@@ -198,27 +198,27 @@  discard block
 block discarded – undo
198 198
     }
199 199
 
200 200
     /**
201
-	 * Checks if a given request has access to read an invoice item.
202
-	 *
203
-	 * @since 1.0.13
204
-	 *
205
-	 * @param WP_REST_Request $request Full details about the request.
206
-	 * @return bool|WP_Error True if the request has read access for the invoice item, WP_Error object otherwise.
207
-	 */
208
-	public function get_item_permissions_check( $request ) {
201
+     * Checks if a given request has access to read an invoice item.
202
+     *
203
+     * @since 1.0.13
204
+     *
205
+     * @param WP_REST_Request $request Full details about the request.
206
+     * @return bool|WP_Error True if the request has read access for the invoice item, WP_Error object otherwise.
207
+     */
208
+    public function get_item_permissions_check( $request ) {
209 209
 
210 210
         // Retrieve the item object.
211 211
         $item = $this->get_post( $request['id'] );
212 212
         
213 213
         // Ensure it is valid.
214
-		if ( is_wp_error( $item ) ) {
215
-			return $item;
216
-		}
214
+        if ( is_wp_error( $item ) ) {
215
+            return $item;
216
+        }
217 217
 
218
-		$post_type = get_post_type_object( $this->post_type );
218
+        $post_type = get_post_type_object( $this->post_type );
219 219
 
220
-		if ( ! current_user_can(  $post_type->cap->read_post, $item->ID  ) ) {
221
-			return new WP_Error( 
220
+        if ( ! current_user_can(  $post_type->cap->read_post, $item->ID  ) ) {
221
+            return new WP_Error( 
222 222
                 'rest_cannot_edit', 
223 223
                 __( 'Sorry, you are not allowed to view this item.', 'invoicing' ), 
224 224
                 array( 
@@ -227,61 +227,61 @@  discard block
 block discarded – undo
227 227
             );
228 228
         }
229 229
 
230
-		return $this->check_read_permission( $item );
230
+        return $this->check_read_permission( $item );
231 231
     }
232 232
     
233 233
     /**
234
-	 * Checks if an item can be read.
235
-	 * 
236
-	 * An item can be read by site admins.
237
-	 *
238
-	 *
239
-	 * @since 1.0.13
240
-	 *
241
-	 * @param WPInv_Item $item WPInv_Item object.
242
-	 * @return bool Whether the post can be read.
243
-	 */
244
-	public function check_read_permission( $item ) {
245
-
246
-		// An item can be read by an admin...
247
-		if ( current_user_can( 'manage_options' ) ||  current_user_can( 'manage_invoicing' ) ) {
248
-			return true;
249
-		}
250
-
251
-		return false;
234
+     * Checks if an item can be read.
235
+     * 
236
+     * An item can be read by site admins.
237
+     *
238
+     *
239
+     * @since 1.0.13
240
+     *
241
+     * @param WPInv_Item $item WPInv_Item object.
242
+     * @return bool Whether the post can be read.
243
+     */
244
+    public function check_read_permission( $item ) {
245
+
246
+        // An item can be read by an admin...
247
+        if ( current_user_can( 'manage_options' ) ||  current_user_can( 'manage_invoicing' ) ) {
248
+            return true;
249
+        }
250
+
251
+        return false;
252 252
     }
253 253
     
254 254
     /**
255
-	 * Retrieves a single invoice item.
256
-	 *
257
-	 * @since 1.0.13
258
-	 *
259
-	 * @param WP_REST_Request $request Full details about the request.
260
-	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
261
-	 */
262
-	public function get_item( $request ) {
255
+     * Retrieves a single invoice item.
256
+     *
257
+     * @since 1.0.13
258
+     *
259
+     * @param WP_REST_Request $request Full details about the request.
260
+     * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
261
+     */
262
+    public function get_item( $request ) {
263 263
 
264 264
         // Fetch the item.
265 265
         $item = $this->get_post( $request['id'] );
266 266
         
267 267
         // Abort early if it does not exist
268
-		if ( is_wp_error( $item ) ) {
269
-			return $item;
270
-		}
271
-
272
-		// Prepare the response
273
-		$response = $this->prepare_item_for_response( $item, $request );
274
-
275
-		/**
276
-		 * Filters the responses for single invoice item requests.
277
-		 *
278
-		 *
279
-		 * @since 1.0.13
280
-		 * @var WP_HTTP_Response
281
-		 *
282
-		 * @param WP_HTTP_Response $response Response.
283
-		 * @param WP_REST_Request  $request The request used.
284
-		 */
268
+        if ( is_wp_error( $item ) ) {
269
+            return $item;
270
+        }
271
+
272
+        // Prepare the response
273
+        $response = $this->prepare_item_for_response( $item, $request );
274
+
275
+        /**
276
+         * Filters the responses for single invoice item requests.
277
+         *
278
+         *
279
+         * @since 1.0.13
280
+         * @var WP_HTTP_Response
281
+         *
282
+         * @param WP_HTTP_Response $response Response.
283
+         * @param WP_REST_Request  $request The request used.
284
+         */
285 285
         $response       = apply_filters( "wpinv_rest_get_item_response", $response, $request );
286 286
 
287 287
         return rest_ensure_response( $response );
@@ -289,26 +289,26 @@  discard block
 block discarded – undo
289 289
     }
290 290
     
291 291
     /**
292
-	 * Checks if a given request has access to create an invoice item.
293
-	 *
294
-	 * @since 1.0.13
295
-	 *
296
-	 * @param WP_REST_Request $request Full details about the request.
297
-	 * @return true|WP_Error True if the request has access to create items, WP_Error object otherwise.
298
-	 */
299
-	public function create_item_permissions_check( $request ) {
292
+     * Checks if a given request has access to create an invoice item.
293
+     *
294
+     * @since 1.0.13
295
+     *
296
+     * @param WP_REST_Request $request Full details about the request.
297
+     * @return true|WP_Error True if the request has access to create items, WP_Error object otherwise.
298
+     */
299
+    public function create_item_permissions_check( $request ) {
300 300
 	
301
-		if ( ! empty( $request['id'] ) ) {
302
-			return new WP_Error( 'rest_item_exists', __( 'Cannot create existing item.', 'invoicing' ), array( 'status' => 400 ) );
303
-		}
301
+        if ( ! empty( $request['id'] ) ) {
302
+            return new WP_Error( 'rest_item_exists', __( 'Cannot create existing item.', 'invoicing' ), array( 'status' => 400 ) );
303
+        }
304 304
 
305
-		if ( current_user_can( 'manage_options' ) ||  current_user_can( 'manage_invoicing' ) ) {
306
-			return true;
307
-		}
305
+        if ( current_user_can( 'manage_options' ) ||  current_user_can( 'manage_invoicing' ) ) {
306
+            return true;
307
+        }
308 308
 
309
-		$post_type = get_post_type_object( $this->post_type );
310
-		if ( ! current_user_can( $post_type->cap->create_posts ) ) {
311
-			return new WP_Error( 
309
+        $post_type = get_post_type_object( $this->post_type );
310
+        if ( ! current_user_can( $post_type->cap->create_posts ) ) {
311
+            return new WP_Error( 
312 312
                 'rest_cannot_create', 
313 313
                 __( 'Sorry, you are not allowed to create invoice items as this user.', 'invoicing' ), 
314 314
                 array( 
@@ -317,253 +317,253 @@  discard block
 block discarded – undo
317 317
             );
318 318
         }
319 319
 
320
-		return true;
320
+        return true;
321 321
     }
322 322
     
323 323
     /**
324
-	 * Creates a single invoice item.
325
-	 *
326
-	 * @since 1.0.13
327
-	 *
328
-	 * @param WP_REST_Request $request Full details about the request.
329
-	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
330
-	 */
331
-	public function create_item( $request ) {
332
-
333
-		if ( ! empty( $request['id'] ) ) {
334
-			return new WP_Error( 'rest_item_exists', __( 'Cannot create existing invoice item.', 'invoicing' ), array( 'status' => 400 ) );
335
-		}
324
+     * Creates a single invoice item.
325
+     *
326
+     * @since 1.0.13
327
+     *
328
+     * @param WP_REST_Request $request Full details about the request.
329
+     * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
330
+     */
331
+    public function create_item( $request ) {
332
+
333
+        if ( ! empty( $request['id'] ) ) {
334
+            return new WP_Error( 'rest_item_exists', __( 'Cannot create existing invoice item.', 'invoicing' ), array( 'status' => 400 ) );
335
+        }
336 336
 
337
-		$request->set_param( 'context', 'edit' );
337
+        $request->set_param( 'context', 'edit' );
338 338
 
339
-		// Prepare the updated data.
340
-		$item_data = $this->prepare_item_for_database( $request );
339
+        // Prepare the updated data.
340
+        $item_data = $this->prepare_item_for_database( $request );
341 341
 
342
-		if ( is_wp_error( $item_data ) ) {
343
-			return $item_data;
344
-		}
342
+        if ( is_wp_error( $item_data ) ) {
343
+            return $item_data;
344
+        }
345 345
 
346
-		// Try creating the item.
346
+        // Try creating the item.
347 347
         $item = wpinv_create_item( $item_data, true );
348 348
 
349
-		if ( is_wp_error( $item ) ) {
349
+        if ( is_wp_error( $item ) ) {
350 350
             return $item;
351
-		}
352
-
353
-		// Prepare the response
354
-		$response = $this->prepare_item_for_response( $item, $request );
355
-
356
-		/**
357
-		 * Fires after a single invoice item is created or updated via the REST API.
358
-		 *
359
-		 * @since 1.0.13
360
-		 *
361
-		 * @param WPinv_Item   $item  Inserted or updated item object.
362
-		 * @param WP_REST_Request $request  Request object.
363
-		 * @param bool            $creating True when creating a post, false when updating.
364
-		 */
365
-		do_action( "wpinv_rest_insert_item", $item, $request, true );
366
-
367
-		/**
368
-		 * Filters the responses for creating single item requests.
369
-		 *
370
-		 *
371
-		 * @since 1.0.13
372
-		 *
373
-		 *
374
-		 * @param array           $item_data Invoice properties.
375
-		 * @param WP_REST_Request $request The request used.
376
-		 */
351
+        }
352
+
353
+        // Prepare the response
354
+        $response = $this->prepare_item_for_response( $item, $request );
355
+
356
+        /**
357
+         * Fires after a single invoice item is created or updated via the REST API.
358
+         *
359
+         * @since 1.0.13
360
+         *
361
+         * @param WPinv_Item   $item  Inserted or updated item object.
362
+         * @param WP_REST_Request $request  Request object.
363
+         * @param bool            $creating True when creating a post, false when updating.
364
+         */
365
+        do_action( "wpinv_rest_insert_item", $item, $request, true );
366
+
367
+        /**
368
+         * Filters the responses for creating single item requests.
369
+         *
370
+         *
371
+         * @since 1.0.13
372
+         *
373
+         *
374
+         * @param array           $item_data Invoice properties.
375
+         * @param WP_REST_Request $request The request used.
376
+         */
377 377
         $response       = apply_filters( "wpinv_rest_create_item_response", $response, $request );
378 378
 
379 379
         return rest_ensure_response( $response );
380
-	}
381
-
382
-	/**
383
-	 * Checks if a given request has access to update an item.
384
-	 *
385
-	 * @since 1.0.13
386
-	 *
387
-	 * @param WP_REST_Request $request Full details about the request.
388
-	 * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise.
389
-	 */
390
-	public function update_item_permissions_check( $request ) {
391
-
392
-		// Retrieve the item.
393
-		$item = $this->get_post( $request['id'] );
394
-		if ( is_wp_error( $item ) ) {
395
-			return $item;
396
-		}
397
-
398
-		if ( wpinv_current_user_can_manage_invoicing() ) {
399
-			return true;
400
-		}
401
-
402
-		return new WP_Error( 
403
-			'rest_cannot_edit', 
404
-			__( 'Sorry, you are not allowed to update this item.', 'invoicing' ), 
405
-			array( 
406
-				'status' => rest_authorization_required_code(),
407
-			)
408
-		);
409
-
410
-	}
411
-
412
-	/**
413
-	 * Updates a single item.
414
-	 *
415
-	 * @since 1.0.13
416
-	 *
417
-	 * @param WP_REST_Request $request Full details about the request.
418
-	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
419
-	 */
420
-	public function update_item( $request ) {
380
+    }
381
+
382
+    /**
383
+     * Checks if a given request has access to update an item.
384
+     *
385
+     * @since 1.0.13
386
+     *
387
+     * @param WP_REST_Request $request Full details about the request.
388
+     * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise.
389
+     */
390
+    public function update_item_permissions_check( $request ) {
391
+
392
+        // Retrieve the item.
393
+        $item = $this->get_post( $request['id'] );
394
+        if ( is_wp_error( $item ) ) {
395
+            return $item;
396
+        }
397
+
398
+        if ( wpinv_current_user_can_manage_invoicing() ) {
399
+            return true;
400
+        }
401
+
402
+        return new WP_Error( 
403
+            'rest_cannot_edit', 
404
+            __( 'Sorry, you are not allowed to update this item.', 'invoicing' ), 
405
+            array( 
406
+                'status' => rest_authorization_required_code(),
407
+            )
408
+        );
409
+
410
+    }
411
+
412
+    /**
413
+     * Updates a single item.
414
+     *
415
+     * @since 1.0.13
416
+     *
417
+     * @param WP_REST_Request $request Full details about the request.
418
+     * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
419
+     */
420
+    public function update_item( $request ) {
421 421
 		
422
-		// Ensure the item exists.
422
+        // Ensure the item exists.
423 423
         $valid_check = $this->get_post( $request['id'] );
424 424
         
425 425
         // Abort early if it does not exist
426
-		if ( is_wp_error( $valid_check ) ) {
427
-			return $valid_check;
428
-		}
426
+        if ( is_wp_error( $valid_check ) ) {
427
+            return $valid_check;
428
+        }
429 429
 
430
-		$request->set_param( 'context', 'edit' );
430
+        $request->set_param( 'context', 'edit' );
431 431
 
432
-		// Prepare the updated data.
433
-		$data_to_update = $this->prepare_item_for_database( $request );
432
+        // Prepare the updated data.
433
+        $data_to_update = $this->prepare_item_for_database( $request );
434 434
 
435
-		if ( is_wp_error( $data_to_update ) ) {
436
-			return $data_to_update;
437
-		}
435
+        if ( is_wp_error( $data_to_update ) ) {
436
+            return $data_to_update;
437
+        }
438 438
 
439
-		// Abort if no item data is provided
439
+        // Abort if no item data is provided
440 440
         if( empty( $data_to_update ) ) {
441 441
             return new WP_Error( 'missing_data', __( 'An update request cannot be empty.', 'invoicing' ) );
442 442
         }
443 443
 
444
-		// Include the item ID
445
-		$data_to_update['ID'] = $request['id'];
446
-
447
-		// Update the item
448
-		$updated_item = wpinv_update_item( $data_to_update, true );
449
-
450
-		// Incase the update operation failed...
451
-		if ( is_wp_error( $updated_item ) ) {
452
-			return $updated_item;
453
-		}
454
-
455
-		// Prepare the response
456
-		$response = $this->prepare_item_for_response( $updated_item, $request );
457
-
458
-		/** This action is documented in includes/class-wpinv-rest-item-controller.php */
459
-		do_action( "wpinv_rest_insert_item", $updated_item, $request, false );
460
-
461
-		/**
462
-		 * Filters the responses for updating single item requests.
463
-		 *
464
-		 *
465
-		 * @since 1.0.13
466
-		 *
467
-		 *
468
-		 * @param array           $data_to_update Item properties.
469
-		 * @param WP_REST_Request $request The request used.
470
-		 */
444
+        // Include the item ID
445
+        $data_to_update['ID'] = $request['id'];
446
+
447
+        // Update the item
448
+        $updated_item = wpinv_update_item( $data_to_update, true );
449
+
450
+        // Incase the update operation failed...
451
+        if ( is_wp_error( $updated_item ) ) {
452
+            return $updated_item;
453
+        }
454
+
455
+        // Prepare the response
456
+        $response = $this->prepare_item_for_response( $updated_item, $request );
457
+
458
+        /** This action is documented in includes/class-wpinv-rest-item-controller.php */
459
+        do_action( "wpinv_rest_insert_item", $updated_item, $request, false );
460
+
461
+        /**
462
+         * Filters the responses for updating single item requests.
463
+         *
464
+         *
465
+         * @since 1.0.13
466
+         *
467
+         *
468
+         * @param array           $data_to_update Item properties.
469
+         * @param WP_REST_Request $request The request used.
470
+         */
471 471
         $response       = apply_filters( "wpinv_rest_update_item_response", $response,  $data_to_update, $request );
472 472
 
473 473
         return rest_ensure_response( $response );
474
-	}
475
-
476
-	/**
477
-	 * Checks if a given request has access to delete an item.
478
-	 *
479
-	 * @since 1.0.13
480
-	 *
481
-	 * @param WP_REST_Request $request Full details about the request.
482
-	 * @return true|WP_Error True if the request has access to delete the item, WP_Error object otherwise.
483
-	 */
484
-	public function delete_item_permissions_check( $request ) {
485
-
486
-		// Retrieve the item.
487
-		$item = $this->get_post( $request['id'] );
488
-		if ( is_wp_error( $item ) ) {
489
-			return $item;
490
-		}
491
-
492
-		// 
493
-
494
-		// Ensure the current user can delete the item
495
-		if (! wpinv_can_delete_item( $request['id'] ) ) {
496
-			return new WP_Error( 
474
+    }
475
+
476
+    /**
477
+     * Checks if a given request has access to delete an item.
478
+     *
479
+     * @since 1.0.13
480
+     *
481
+     * @param WP_REST_Request $request Full details about the request.
482
+     * @return true|WP_Error True if the request has access to delete the item, WP_Error object otherwise.
483
+     */
484
+    public function delete_item_permissions_check( $request ) {
485
+
486
+        // Retrieve the item.
487
+        $item = $this->get_post( $request['id'] );
488
+        if ( is_wp_error( $item ) ) {
489
+            return $item;
490
+        }
491
+
492
+        // 
493
+
494
+        // Ensure the current user can delete the item
495
+        if (! wpinv_can_delete_item( $request['id'] ) ) {
496
+            return new WP_Error( 
497 497
                 'rest_cannot_delete', 
498 498
                 __( 'Sorry, you are not allowed to delete this item.', 'invoicing' ), 
499 499
                 array( 
500 500
                     'status' => rest_authorization_required_code(),
501 501
                 )
502 502
             );
503
-		}
504
-
505
-		return true;
506
-	}
507
-
508
-	/**
509
-	 * Deletes a single item.
510
-	 *
511
-	 * @since 1.0.13
512
-	 *
513
-	 * @param WP_REST_Request $request Full details about the request.
514
-	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
515
-	 */
516
-	public function delete_item( $request ) {
503
+        }
504
+
505
+        return true;
506
+    }
507
+
508
+    /**
509
+     * Deletes a single item.
510
+     *
511
+     * @since 1.0.13
512
+     *
513
+     * @param WP_REST_Request $request Full details about the request.
514
+     * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
515
+     */
516
+    public function delete_item( $request ) {
517 517
 		
518
-		// Retrieve the item.
519
-		$item = $this->get_post( $request['id'] );
520
-		if ( is_wp_error( $item ) ) {
521
-			return $item;
522
-		}
518
+        // Retrieve the item.
519
+        $item = $this->get_post( $request['id'] );
520
+        if ( is_wp_error( $item ) ) {
521
+            return $item;
522
+        }
523 523
 
524
-		$request->set_param( 'context', 'edit' );
524
+        $request->set_param( 'context', 'edit' );
525 525
 
526
-		// Prepare the item id
527
-		$id    = $item->ID;
526
+        // Prepare the item id
527
+        $id    = $item->ID;
528 528
 
529
-		// Prepare the response
530
-		$response = $this->prepare_item_for_response( $item, $request );
529
+        // Prepare the response
530
+        $response = $this->prepare_item_for_response( $item, $request );
531 531
 
532
-		// Check if the user wants to bypass the trash...
533
-		$force_delete = (bool) $request['force'];
532
+        // Check if the user wants to bypass the trash...
533
+        $force_delete = (bool) $request['force'];
534 534
 
535
-		// Try deleting the item.
536
-		$deleted = wp_delete_post( $id, $force_delete );
535
+        // Try deleting the item.
536
+        $deleted = wp_delete_post( $id, $force_delete );
537 537
 
538
-		// Abort early if we can't delete the item.
539
-		if ( ! $deleted ) {
540
-			return new WP_Error( 'rest_cannot_delete', __( 'The item cannot be deleted.', 'invoicing' ), array( 'status' => 500 ) );
541
-		}
538
+        // Abort early if we can't delete the item.
539
+        if ( ! $deleted ) {
540
+            return new WP_Error( 'rest_cannot_delete', __( 'The item cannot be deleted.', 'invoicing' ), array( 'status' => 500 ) );
541
+        }
542 542
 
543
-		/**
544
-		 * Fires immediately after a single item is deleted or trashed via the REST API.
545
-		 *
546
-		 *
547
-		 * @since 1.0.13
548
-		 *
549
-		 * @param WPInv_Item    $item  The deleted or trashed item.
550
-		 * @param WP_REST_Request  $request  The request sent to the API.
551
-		 */
552
-		do_action( "wpinv_rest_delete_item", $item, $request );
543
+        /**
544
+         * Fires immediately after a single item is deleted or trashed via the REST API.
545
+         *
546
+         *
547
+         * @since 1.0.13
548
+         *
549
+         * @param WPInv_Item    $item  The deleted or trashed item.
550
+         * @param WP_REST_Request  $request  The request sent to the API.
551
+         */
552
+        do_action( "wpinv_rest_delete_item", $item, $request );
553 553
 
554
-		return $response;
554
+        return $response;
555 555
 
556
-	}
556
+    }
557 557
     
558 558
     
559 559
     /**
560
-	 * Retrieves the query params for the items collection.
561
-	 *
562
-	 * @since 1.0.13
563
-	 *
564
-	 * @return array Collection parameters.
565
-	 */
566
-	public function get_collection_params() {
560
+     * Retrieves the query params for the items collection.
561
+     *
562
+     * @since 1.0.13
563
+     *
564
+     * @return array Collection parameters.
565
+     */
566
+    public function get_collection_params() {
567 567
         
568 568
         $query_params               = array(
569 569
 
@@ -577,27 +577,27 @@  discard block
 block discarded – undo
577 577
             
578 578
             // Item types
579 579
             'type'                  => array(
580
-				'description'       => __( 'Type of items to fetch.', 'invoicing' ),
581
-				'type'              => 'array',
582
-				'default'           => wpinv_item_types(),
583
-				'items'             => array(
580
+                'description'       => __( 'Type of items to fetch.', 'invoicing' ),
581
+                'type'              => 'array',
582
+                'default'           => wpinv_item_types(),
583
+                'items'             => array(
584 584
                     'enum'          => wpinv_item_types(),
585 585
                     'type'          => 'string',
586 586
                 ),
587
-			),
587
+            ),
588 588
 			
589
-			// Number of results per page
589
+            // Number of results per page
590 590
             'limit'                 => array(
591
-				'description'       => __( 'Number of items to fetch.', 'invoicing' ),
592
-				'type'              => 'integer',
593
-				'default'           => (int) get_option( 'posts_per_page' ),
591
+                'description'       => __( 'Number of items to fetch.', 'invoicing' ),
592
+                'type'              => 'integer',
593
+                'default'           => (int) get_option( 'posts_per_page' ),
594 594
             ),
595 595
 
596 596
             // Pagination
597 597
             'page'     => array(
598
-				'description'       => __( 'Current page to fetch.', 'invoicing' ),
599
-				'type'              => 'integer',
600
-				'default'           => 1,
598
+                'description'       => __( 'Current page to fetch.', 'invoicing' ),
599
+                'type'              => 'integer',
600
+                'default'           => 1,
601 601
             ),
602 602
 
603 603
             // Exclude certain items
@@ -620,9 +620,9 @@  discard block
 block discarded – undo
620 620
                     'date',
621 621
                     'ID',
622 622
                     'modified',
623
-					'title',
624
-					'relevance',
625
-					'rand'
623
+                    'title',
624
+                    'relevance',
625
+                    'rand'
626 626
                 ),
627 627
             ),
628 628
 
@@ -632,617 +632,617 @@  discard block
 block discarded – undo
632 632
                 'type'        => 'string',
633 633
                 'default'     => 'DESC',
634 634
                 'enum'        => array( 'ASC', 'DESC' ),
635
-			),
635
+            ),
636 636
 			
637
-			// Search term
637
+            // Search term
638 638
             'search'                => array(
639
-				'description'       => __( 'Return items that match the search term.', 'invoicing' ),
640
-				'type'              => 'string',
639
+                'description'       => __( 'Return items that match the search term.', 'invoicing' ),
640
+                'type'              => 'string',
641 641
             ),
642 642
         );
643 643
 
644
-		/**
645
-		 * Filter collection parameters for the items controller.
646
-		 *
647
-		 *
648
-		 * @since 1.0.13
649
-		 *
650
-		 * @param array        $query_params JSON Schema-formatted collection parameters.
651
-		 */
652
-		return apply_filters( "wpinv_rest_items_collection_params", $query_params );
644
+        /**
645
+         * Filter collection parameters for the items controller.
646
+         *
647
+         *
648
+         * @since 1.0.13
649
+         *
650
+         * @param array        $query_params JSON Schema-formatted collection parameters.
651
+         */
652
+        return apply_filters( "wpinv_rest_items_collection_params", $query_params );
653 653
     }
654 654
     
655 655
     /**
656
-	 * Checks if a given post type can be viewed or managed.
657
-	 *
658
-	 * @since 1.0.13
659
-	 *
660
-	 * @param object|string $post_type Post type name or object.
661
-	 * @return bool Whether the post type is allowed in REST.
662
-	 */
663
-	protected function check_is_post_type_allowed( $post_type ) {
664
-		return true;
665
-	}
666
-
667
-	/**
668
-	 * Prepares a single item for create or update.
669
-	 *
670
-	 * @since 1.0.13
671
-	 *
672
-	 * @param WP_REST_Request $request Request object.
673
-	 * @return array|WP_Error Invoice Properties or WP_Error.
674
-	 */
675
-	protected function prepare_item_for_database( $request ) {
676
-		$prepared_item = new stdClass();
677
-
678
-		// Post ID.
679
-		if ( isset( $request['id'] ) ) {
680
-			$existing_item = $this->get_post( $request['id'] );
681
-			if ( is_wp_error( $existing_item ) ) {
682
-				return $existing_item;
683
-			}
684
-
685
-			$prepared_item->ID 		  = $existing_item->ID;
686
-		}
687
-
688
-		$schema = $this->get_item_schema();
689
-
690
-		// item title.
691
-		if ( ! empty( $schema['properties']['name'] ) && isset( $request['name'] ) ) {
692
-			$prepared_item->title = sanitize_text_field( $request['name'] );
693
-		}
694
-
695
-		// item summary.
696
-		if ( ! empty( $schema['properties']['summary'] ) && isset( $request['summary'] ) ) {
697
-			$prepared_item->excerpt = wp_kses_post( $request['summary'] );
698
-		}
699
-
700
-		// item price.
701
-		if ( ! empty( $schema['properties']['price'] ) && isset( $request['price'] ) ) {
702
-			$prepared_item->price = floatval( $request['price'] );
703
-		}
704
-
705
-		// minimum price (for dynamc items).
706
-		if ( ! empty( $schema['properties']['minimum_price'] ) && isset( $request['minimum_price'] ) ) {
707
-			$prepared_item->minimum_price = floatval( $request['minimum_price'] );
708
-		}
709
-
710
-		// item status.
711
-		if ( ! empty( $schema['properties']['status'] ) && isset( $request['status'] ) ) {
712
-			$prepared_item->status = 'publish' === $request['status'] ? 'publish' : 'pending';
713
-		}
714
-
715
-		// item type.
716
-		if ( ! empty( $schema['properties']['type'] ) && isset( $request['type'] ) ) {
717
-			$prepared_item->type = in_array( $request['type'], wpinv_item_types() ) ? trim( strtolower( $request['type'] ) ) : 'custom';
718
-		}
719
-
720
-		// VAT rule.
721
-		if ( ! empty( $schema['properties']['vat_rule'] ) && isset( $request['vat_rule'] ) ) {
722
-			$prepared_item->vat_rule = 'digital' === $request['vat_rule'] ? 'digital' : 'physical';
723
-		}
724
-
725
-		// Simple strings.
726
-		foreach( array( 'custom_id', 'custom_name', 'custom_singular_name' ) as $property ) {
727
-
728
-			if ( ! empty( $schema['properties'][$property] ) && isset( $request[$property] ) ) {
729
-				$prepared_item->$property = sanitize_text_field( $request[$property] );
730
-			}
731
-
732
-		}
733
-
734
-		// Simple integers.
735
-		foreach( array( 'is_recurring', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_interval', 'dynamic_pricing', 'editable' ) as $property ) {
736
-
737
-			if ( ! empty( $schema['properties'][$property] ) && isset( $request[$property] ) ) {
738
-				$prepared_item->$property = intval( $request[$property] );
739
-			}
740
-
741
-		}
742
-
743
-		// Time periods.
744
-		foreach( array( 'recurring_period',  'trial_period' ) as $property ) {
745
-
746
-			if ( ! empty( $schema['properties'][$property] ) && isset( $request[$property] ) ) {
747
-				$prepared_item->$property = in_array( $request[$property], array( 'D', 'W', 'M', 'Y' ) ) ? trim( strtoupper( $request[$property] ) ) : 'D';
748
-			}
749
-
750
-		}
751
-
752
-		$item_data = (array) wp_unslash( $prepared_item );
753
-
754
-		/**
755
-		 * Filters an item before it is inserted via the REST API.
756
-		 *
757
-		 * @since 1.0.13
758
-		 *
759
-		 * @param array        $item_data An array of item data
760
-		 * @param WP_REST_Request $request       Request object.
761
-		 */
762
-		return apply_filters( "wpinv_rest_pre_insert_item", $item_data, $request );
763
-
764
-	}
765
-
766
-	/**
767
-	 * Prepares a single item output for response.
768
-	 *
769
-	 * @since 1.0.13
770
-	 *
771
-	 * @param WPInv_Item   $item    item object.
772
-	 * @param WP_REST_Request $request Request object.
773
-	 * @return WP_REST_Response Response object.
774
-	 */
775
-	public function prepare_item_for_response( $item, $request ) {
656
+     * Checks if a given post type can be viewed or managed.
657
+     *
658
+     * @since 1.0.13
659
+     *
660
+     * @param object|string $post_type Post type name or object.
661
+     * @return bool Whether the post type is allowed in REST.
662
+     */
663
+    protected function check_is_post_type_allowed( $post_type ) {
664
+        return true;
665
+    }
776 666
 
777
-		$GLOBALS['post'] = get_post( $item->get_ID() );
667
+    /**
668
+     * Prepares a single item for create or update.
669
+     *
670
+     * @since 1.0.13
671
+     *
672
+     * @param WP_REST_Request $request Request object.
673
+     * @return array|WP_Error Invoice Properties or WP_Error.
674
+     */
675
+    protected function prepare_item_for_database( $request ) {
676
+        $prepared_item = new stdClass();
677
+
678
+        // Post ID.
679
+        if ( isset( $request['id'] ) ) {
680
+            $existing_item = $this->get_post( $request['id'] );
681
+            if ( is_wp_error( $existing_item ) ) {
682
+                return $existing_item;
683
+            }
778 684
 
779
-		setup_postdata( $item->get_ID() );
685
+            $prepared_item->ID 		  = $existing_item->ID;
686
+        }
780 687
 
781
-		// Fetch the fields to include in this response.
782
-		$fields = $this->get_fields_for_response( $request );
688
+        $schema = $this->get_item_schema();
783 689
 
784
-		// Base fields for every item.
785
-		$data = array();
690
+        // item title.
691
+        if ( ! empty( $schema['properties']['name'] ) && isset( $request['name'] ) ) {
692
+            $prepared_item->title = sanitize_text_field( $request['name'] );
693
+        }
786 694
 
787
-		// Set up ID
788
-		if ( rest_is_field_included( 'id', $fields ) ) {
789
-			$data['id'] = $item->get_ID();
790
-		}
695
+        // item summary.
696
+        if ( ! empty( $schema['properties']['summary'] ) && isset( $request['summary'] ) ) {
697
+            $prepared_item->excerpt = wp_kses_post( $request['summary'] );
698
+        }
791 699
 
700
+        // item price.
701
+        if ( ! empty( $schema['properties']['price'] ) && isset( $request['price'] ) ) {
702
+            $prepared_item->price = floatval( $request['price'] );
703
+        }
792 704
 
793
-		// Item properties
794
-		$item_properties = array(
795
-			'name', 'summary', 'price', 'status', 'type',
796
-			'vat_rule', 'vat_class',
797
-			'custom_id', 'custom_name', 'custom_singular_name', 
798
-			'editable'
799
-		);
705
+        // minimum price (for dynamc items).
706
+        if ( ! empty( $schema['properties']['minimum_price'] ) && isset( $request['minimum_price'] ) ) {
707
+            $prepared_item->minimum_price = floatval( $request['minimum_price'] );
708
+        }
709
+
710
+        // item status.
711
+        if ( ! empty( $schema['properties']['status'] ) && isset( $request['status'] ) ) {
712
+            $prepared_item->status = 'publish' === $request['status'] ? 'publish' : 'pending';
713
+        }
800 714
 
801
-		foreach( $item_properties as $property ) {
715
+        // item type.
716
+        if ( ! empty( $schema['properties']['type'] ) && isset( $request['type'] ) ) {
717
+            $prepared_item->type = in_array( $request['type'], wpinv_item_types() ) ? trim( strtolower( $request['type'] ) ) : 'custom';
718
+        }
802 719
 
803
-			if ( rest_is_field_included( $property, $fields ) && method_exists( $item, 'get_' . $property ) ) {
804
-				$data[$property] = call_user_func( array( $item, 'get_' . $property ) );
805
-			}
720
+        // VAT rule.
721
+        if ( ! empty( $schema['properties']['vat_rule'] ) && isset( $request['vat_rule'] ) ) {
722
+            $prepared_item->vat_rule = 'digital' === $request['vat_rule'] ? 'digital' : 'physical';
723
+        }
806 724
 
807
-		}
725
+        // Simple strings.
726
+        foreach( array( 'custom_id', 'custom_name', 'custom_singular_name' ) as $property ) {
808 727
 
809
-		// Dynamic pricing.
810
-		if( $item->supports_dynamic_pricing() ) {
728
+            if ( ! empty( $schema['properties'][$property] ) && isset( $request[$property] ) ) {
729
+                $prepared_item->$property = sanitize_text_field( $request[$property] );
730
+            }
811 731
 
812
-			if( rest_is_field_included( 'dynamic_pricing', $fields ) ) {
813
-				$data['dynamic_pricing'] = $item->get_is_dynamic_pricing();
814
-			}
732
+        }
815 733
 
816
-			if( rest_is_field_included( 'minimum_price', $fields ) ) {
817
-				$data['minimum_price'] = $item->get_minimum_price();
818
-			}
819
-		}
734
+        // Simple integers.
735
+        foreach( array( 'is_recurring', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_interval', 'dynamic_pricing', 'editable' ) as $property ) {
820 736
 
821
-		// Subscriptions.
822
-		if( rest_is_field_included( 'is_recurring', $fields ) ) {
823
-			$data['is_recurring'] = $item->get_is_recurring();
824
-		}
737
+            if ( ! empty( $schema['properties'][$property] ) && isset( $request[$property] ) ) {
738
+                $prepared_item->$property = intval( $request[$property] );
739
+            }
825 740
 
826
-		if( $item->is_recurring() ) {
741
+        }
827 742
 
828
-			$recurring_fields = array( 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial' );
829
-			foreach( $recurring_fields as $field ) {
743
+        // Time periods.
744
+        foreach( array( 'recurring_period',  'trial_period' ) as $property ) {
830 745
 
831
-				if ( rest_is_field_included( $field, $fields ) && method_exists( $item, 'get_' . $field ) ) {
832
-					$data[$field] = call_user_func( array( $item, 'get_' . $field ) );
833
-				}
746
+            if ( ! empty( $schema['properties'][$property] ) && isset( $request[$property] ) ) {
747
+                $prepared_item->$property = in_array( $request[$property], array( 'D', 'W', 'M', 'Y' ) ) ? trim( strtoupper( $request[$property] ) ) : 'D';
748
+            }
749
+
750
+        }
751
+
752
+        $item_data = (array) wp_unslash( $prepared_item );
753
+
754
+        /**
755
+         * Filters an item before it is inserted via the REST API.
756
+         *
757
+         * @since 1.0.13
758
+         *
759
+         * @param array        $item_data An array of item data
760
+         * @param WP_REST_Request $request       Request object.
761
+         */
762
+        return apply_filters( "wpinv_rest_pre_insert_item", $item_data, $request );
763
+
764
+    }
765
+
766
+    /**
767
+     * Prepares a single item output for response.
768
+     *
769
+     * @since 1.0.13
770
+     *
771
+     * @param WPInv_Item   $item    item object.
772
+     * @param WP_REST_Request $request Request object.
773
+     * @return WP_REST_Response Response object.
774
+     */
775
+    public function prepare_item_for_response( $item, $request ) {
776
+
777
+        $GLOBALS['post'] = get_post( $item->get_ID() );
778
+
779
+        setup_postdata( $item->get_ID() );
780
+
781
+        // Fetch the fields to include in this response.
782
+        $fields = $this->get_fields_for_response( $request );
783
+
784
+        // Base fields for every item.
785
+        $data = array();
786
+
787
+        // Set up ID
788
+        if ( rest_is_field_included( 'id', $fields ) ) {
789
+            $data['id'] = $item->get_ID();
790
+        }
791
+
792
+
793
+        // Item properties
794
+        $item_properties = array(
795
+            'name', 'summary', 'price', 'status', 'type',
796
+            'vat_rule', 'vat_class',
797
+            'custom_id', 'custom_name', 'custom_singular_name', 
798
+            'editable'
799
+        );
800
+
801
+        foreach( $item_properties as $property ) {
802
+
803
+            if ( rest_is_field_included( $property, $fields ) && method_exists( $item, 'get_' . $property ) ) {
804
+                $data[$property] = call_user_func( array( $item, 'get_' . $property ) );
805
+            }
806
+
807
+        }
808
+
809
+        // Dynamic pricing.
810
+        if( $item->supports_dynamic_pricing() ) {
811
+
812
+            if( rest_is_field_included( 'dynamic_pricing', $fields ) ) {
813
+                $data['dynamic_pricing'] = $item->get_is_dynamic_pricing();
814
+            }
815
+
816
+            if( rest_is_field_included( 'minimum_price', $fields ) ) {
817
+                $data['minimum_price'] = $item->get_minimum_price();
818
+            }
819
+        }
820
+
821
+        // Subscriptions.
822
+        if( rest_is_field_included( 'is_recurring', $fields ) ) {
823
+            $data['is_recurring'] = $item->get_is_recurring();
824
+        }
825
+
826
+        if( $item->is_recurring() ) {
827
+
828
+            $recurring_fields = array( 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial' );
829
+            foreach( $recurring_fields as $field ) {
830
+
831
+                if ( rest_is_field_included( $field, $fields ) && method_exists( $item, 'get_' . $field ) ) {
832
+                    $data[$field] = call_user_func( array( $item, 'get_' . $field ) );
833
+                }
834 834
 	
835
-			}
835
+            }
836 836
 
837
-			if( $item->has_free_trial() ) {
837
+            if( $item->has_free_trial() ) {
838 838
 
839
-				$trial_fields = array( 'trial_period', 'trial_interval' );
840
-				foreach( $trial_fields as $field ) {
839
+                $trial_fields = array( 'trial_period', 'trial_interval' );
840
+                foreach( $trial_fields as $field ) {
841 841
 
842
-					if ( rest_is_field_included( $field, $fields ) && method_exists( $item, 'get_' . $field ) ) {
843
-						$data[$field] = call_user_func( array( $item, 'get_' . $field ) );
844
-					}
842
+                    if ( rest_is_field_included( $field, $fields ) && method_exists( $item, 'get_' . $field ) ) {
843
+                        $data[$field] = call_user_func( array( $item, 'get_' . $field ) );
844
+                    }
845 845
 	
846
-				}
847
-
848
-			}
849
-
850
-		}
851
-
852
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
853
-		$data    = $this->add_additional_fields_to_object( $data, $request );
854
-		$data    = $this->filter_response_by_context( $data, $context );
855
-
856
-		// Wrap the data in a response object.
857
-		$response = rest_ensure_response( $data );
858
-
859
-		$links = $this->prepare_links( $item );
860
-		$response->add_links( $links );
861
-
862
-		if ( ! empty( $links['self']['href'] ) ) {
863
-			$actions = $this->get_available_actions( $item, $request );
864
-
865
-			$self = $links['self']['href'];
866
-
867
-			foreach ( $actions as $rel ) {
868
-				$response->add_link( $rel, $self );
869
-			}
870
-		}
871
-
872
-		/**
873
-		 * Filters the item data for a response.
874
-		 *
875
-		 * @since 1.0.13
876
-		 *
877
-		 * @param WP_REST_Response $response The response object.
878
-		 * @param WPInv_Item    $item  The item object.
879
-		 * @param WP_REST_Request  $request  Request object.
880
-		 */
881
-		return apply_filters( "wpinv_rest_prepare_item", $response, $item, $request );
882
-	}
883
-
884
-	/**
885
-	 * Gets an array of fields to be included on the response.
886
-	 *
887
-	 * Included fields are based on item schema and `_fields=` request argument.
888
-	 *
889
-	 * @since 1.0.13
890
-	 *
891
-	 * @param WP_REST_Request $request Full details about the request.
892
-	 * @return array Fields to be included in the response.
893
-	 */
894
-	public function get_fields_for_response( $request ) {
895
-		$schema     = $this->get_item_schema();
896
-		$properties = isset( $schema['properties'] ) ? $schema['properties'] : array();
897
-
898
-		$additional_fields = $this->get_additional_fields();
899
-		foreach ( $additional_fields as $field_name => $field_options ) {
900
-			// For back-compat, include any field with an empty schema
901
-			// because it won't be present in $this->get_item_schema().
902
-			if ( is_null( $field_options['schema'] ) ) {
903
-				$properties[ $field_name ] = $field_options;
904
-			}
905
-		}
906
-
907
-		// Exclude fields that specify a different context than the request context.
908
-		$context = $request['context'];
909
-		if ( $context ) {
910
-			foreach ( $properties as $name => $options ) {
911
-				if ( ! empty( $options['context'] ) && ! in_array( $context, $options['context'], true ) ) {
912
-					unset( $properties[ $name ] );
913
-				}
914
-			}
915
-		}
916
-
917
-		$fields = array_keys( $properties );
918
-
919
-		if ( ! isset( $request['_fields'] ) ) {
920
-			return $fields;
921
-		}
922
-		$requested_fields = wpinv_parse_list( $request['_fields'] );
923
-		if ( 0 === count( $requested_fields ) ) {
924
-			return $fields;
925
-		}
926
-		// Trim off outside whitespace from the comma delimited list.
927
-		$requested_fields = array_map( 'trim', $requested_fields );
928
-		// Always persist 'id', because it can be needed for add_additional_fields_to_object().
929
-		if ( in_array( 'id', $fields, true ) ) {
930
-			$requested_fields[] = 'id';
931
-		}
932
-		// Return the list of all requested fields which appear in the schema.
933
-		return array_reduce(
934
-			$requested_fields,
935
-			function( $response_fields, $field ) use ( $fields ) {
936
-				if ( in_array( $field, $fields, true ) ) {
937
-					$response_fields[] = $field;
938
-					return $response_fields;
939
-				}
940
-				// Check for nested fields if $field is not a direct match.
941
-				$nested_fields = explode( '.', $field );
942
-				// A nested field is included so long as its top-level property is
943
-				// present in the schema.
944
-				if ( in_array( $nested_fields[0], $fields, true ) ) {
945
-					$response_fields[] = $field;
946
-				}
947
-				return $response_fields;
948
-			},
949
-			array()
950
-		);
951
-	}
952
-
953
-	/**
954
-	 * Retrieves the item's schema, conforming to JSON Schema.
955
-	 *
956
-	 * @since 1.0.13
957
-	 *
958
-	 * @return array Item schema data.
959
-	 */
960
-	public function get_item_schema() {
961
-
962
-		// Maybe retrieve the schema from cache.
963
-		if ( $this->schema ) {
964
-			return $this->add_additional_fields_schema( $this->schema );
965
-		}
966
-
967
-		$schema = array(
968
-			'$schema'    => 'http://json-schema.org/draft-04/schema#',
969
-			'title'      => $this->post_type,
970
-			'type'       => 'object',
971
-
972
-			// Base properties for every Item.
973
-			'properties' 		  => array(
974
-
975
-				'id'           => array(
976
-					'description' => __( 'Unique identifier for the item.', 'invoicing' ),
977
-					'type'        => 'integer',
978
-					'context'     => array( 'view', 'edit', 'embed' ),
979
-					'readonly'    => true,
980
-				),
981
-
982
-				'name'			  => array(
983
-					'description' => __( 'The name for the item.', 'invoicing' ),
984
-					'type'        => 'string',
985
-					'context'     => array( 'view', 'edit', 'embed' ),
986
-				),
987
-
988
-				'summary'        => array(
989
-					'description' => __( 'A summary for the item.', 'invoicing' ),
990
-					'type'        => 'string',
991
-					'context'     => array( 'view', 'edit', 'embed' ),
992
-				),
993
-
994
-				'price'        => array(
995
-					'description' => __( 'The price for the item.', 'invoicing' ),
996
-					'type'        => 'number',
997
-					'context'     => array( 'view', 'edit', 'embed' ),
998
-				),
999
-
1000
-				'status'       => array(
1001
-					'description' => __( 'A named status for the item.', 'invoicing' ),
1002
-					'type'        => 'string',
1003
-					'enum'        => array_keys( get_post_stati( array( 'internal' => false ) ) ),
1004
-					'context'     => array( 'view', 'edit' ),
1005
-				),
1006
-
1007
-				'type'       => array(
1008
-					'description' => __( 'The item type.', 'invoicing' ),
1009
-					'type'        => 'string',
1010
-					'enum'        => wpinv_item_types(),
1011
-					'context'     => array( 'view', 'edit', 'embed' ),
1012
-				),
1013
-
1014
-				'vat_rule'       => array(
1015
-					'description' => __( 'VAT rule applied to the item.', 'invoicing' ),
1016
-					'type'        => 'string',
1017
-					'enum'        => array( 'digital', 'physical' ),
1018
-					'context'     => array( 'view', 'edit' ),
1019
-				),
1020
-
1021
-				'vat_class'       => array(
1022
-					'description' => __( 'VAT class for the item.', 'invoicing' ),
1023
-					'type'        => 'string',
1024
-					'context'     => array( 'view', 'edit' ),
1025
-					'readonly'    => true,
1026
-				),
1027
-
1028
-				'custom_id'       => array(
1029
-					'description' => __( 'Custom id for the item.', 'invoicing' ),
1030
-					'type'        => 'string',
1031
-					'context'     => array( 'view', 'edit', 'embed' ),
1032
-				),
846
+                }
847
+
848
+            }
849
+
850
+        }
851
+
852
+        $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
853
+        $data    = $this->add_additional_fields_to_object( $data, $request );
854
+        $data    = $this->filter_response_by_context( $data, $context );
855
+
856
+        // Wrap the data in a response object.
857
+        $response = rest_ensure_response( $data );
858
+
859
+        $links = $this->prepare_links( $item );
860
+        $response->add_links( $links );
861
+
862
+        if ( ! empty( $links['self']['href'] ) ) {
863
+            $actions = $this->get_available_actions( $item, $request );
864
+
865
+            $self = $links['self']['href'];
866
+
867
+            foreach ( $actions as $rel ) {
868
+                $response->add_link( $rel, $self );
869
+            }
870
+        }
871
+
872
+        /**
873
+         * Filters the item data for a response.
874
+         *
875
+         * @since 1.0.13
876
+         *
877
+         * @param WP_REST_Response $response The response object.
878
+         * @param WPInv_Item    $item  The item object.
879
+         * @param WP_REST_Request  $request  Request object.
880
+         */
881
+        return apply_filters( "wpinv_rest_prepare_item", $response, $item, $request );
882
+    }
883
+
884
+    /**
885
+     * Gets an array of fields to be included on the response.
886
+     *
887
+     * Included fields are based on item schema and `_fields=` request argument.
888
+     *
889
+     * @since 1.0.13
890
+     *
891
+     * @param WP_REST_Request $request Full details about the request.
892
+     * @return array Fields to be included in the response.
893
+     */
894
+    public function get_fields_for_response( $request ) {
895
+        $schema     = $this->get_item_schema();
896
+        $properties = isset( $schema['properties'] ) ? $schema['properties'] : array();
897
+
898
+        $additional_fields = $this->get_additional_fields();
899
+        foreach ( $additional_fields as $field_name => $field_options ) {
900
+            // For back-compat, include any field with an empty schema
901
+            // because it won't be present in $this->get_item_schema().
902
+            if ( is_null( $field_options['schema'] ) ) {
903
+                $properties[ $field_name ] = $field_options;
904
+            }
905
+        }
906
+
907
+        // Exclude fields that specify a different context than the request context.
908
+        $context = $request['context'];
909
+        if ( $context ) {
910
+            foreach ( $properties as $name => $options ) {
911
+                if ( ! empty( $options['context'] ) && ! in_array( $context, $options['context'], true ) ) {
912
+                    unset( $properties[ $name ] );
913
+                }
914
+            }
915
+        }
916
+
917
+        $fields = array_keys( $properties );
918
+
919
+        if ( ! isset( $request['_fields'] ) ) {
920
+            return $fields;
921
+        }
922
+        $requested_fields = wpinv_parse_list( $request['_fields'] );
923
+        if ( 0 === count( $requested_fields ) ) {
924
+            return $fields;
925
+        }
926
+        // Trim off outside whitespace from the comma delimited list.
927
+        $requested_fields = array_map( 'trim', $requested_fields );
928
+        // Always persist 'id', because it can be needed for add_additional_fields_to_object().
929
+        if ( in_array( 'id', $fields, true ) ) {
930
+            $requested_fields[] = 'id';
931
+        }
932
+        // Return the list of all requested fields which appear in the schema.
933
+        return array_reduce(
934
+            $requested_fields,
935
+            function( $response_fields, $field ) use ( $fields ) {
936
+                if ( in_array( $field, $fields, true ) ) {
937
+                    $response_fields[] = $field;
938
+                    return $response_fields;
939
+                }
940
+                // Check for nested fields if $field is not a direct match.
941
+                $nested_fields = explode( '.', $field );
942
+                // A nested field is included so long as its top-level property is
943
+                // present in the schema.
944
+                if ( in_array( $nested_fields[0], $fields, true ) ) {
945
+                    $response_fields[] = $field;
946
+                }
947
+                return $response_fields;
948
+            },
949
+            array()
950
+        );
951
+    }
952
+
953
+    /**
954
+     * Retrieves the item's schema, conforming to JSON Schema.
955
+     *
956
+     * @since 1.0.13
957
+     *
958
+     * @return array Item schema data.
959
+     */
960
+    public function get_item_schema() {
961
+
962
+        // Maybe retrieve the schema from cache.
963
+        if ( $this->schema ) {
964
+            return $this->add_additional_fields_schema( $this->schema );
965
+        }
966
+
967
+        $schema = array(
968
+            '$schema'    => 'http://json-schema.org/draft-04/schema#',
969
+            'title'      => $this->post_type,
970
+            'type'       => 'object',
971
+
972
+            // Base properties for every Item.
973
+            'properties' 		  => array(
974
+
975
+                'id'           => array(
976
+                    'description' => __( 'Unique identifier for the item.', 'invoicing' ),
977
+                    'type'        => 'integer',
978
+                    'context'     => array( 'view', 'edit', 'embed' ),
979
+                    'readonly'    => true,
980
+                ),
981
+
982
+                'name'			  => array(
983
+                    'description' => __( 'The name for the item.', 'invoicing' ),
984
+                    'type'        => 'string',
985
+                    'context'     => array( 'view', 'edit', 'embed' ),
986
+                ),
987
+
988
+                'summary'        => array(
989
+                    'description' => __( 'A summary for the item.', 'invoicing' ),
990
+                    'type'        => 'string',
991
+                    'context'     => array( 'view', 'edit', 'embed' ),
992
+                ),
993
+
994
+                'price'        => array(
995
+                    'description' => __( 'The price for the item.', 'invoicing' ),
996
+                    'type'        => 'number',
997
+                    'context'     => array( 'view', 'edit', 'embed' ),
998
+                ),
999
+
1000
+                'status'       => array(
1001
+                    'description' => __( 'A named status for the item.', 'invoicing' ),
1002
+                    'type'        => 'string',
1003
+                    'enum'        => array_keys( get_post_stati( array( 'internal' => false ) ) ),
1004
+                    'context'     => array( 'view', 'edit' ),
1005
+                ),
1006
+
1007
+                'type'       => array(
1008
+                    'description' => __( 'The item type.', 'invoicing' ),
1009
+                    'type'        => 'string',
1010
+                    'enum'        => wpinv_item_types(),
1011
+                    'context'     => array( 'view', 'edit', 'embed' ),
1012
+                ),
1013
+
1014
+                'vat_rule'       => array(
1015
+                    'description' => __( 'VAT rule applied to the item.', 'invoicing' ),
1016
+                    'type'        => 'string',
1017
+                    'enum'        => array( 'digital', 'physical' ),
1018
+                    'context'     => array( 'view', 'edit' ),
1019
+                ),
1020
+
1021
+                'vat_class'       => array(
1022
+                    'description' => __( 'VAT class for the item.', 'invoicing' ),
1023
+                    'type'        => 'string',
1024
+                    'context'     => array( 'view', 'edit' ),
1025
+                    'readonly'    => true,
1026
+                ),
1027
+
1028
+                'custom_id'       => array(
1029
+                    'description' => __( 'Custom id for the item.', 'invoicing' ),
1030
+                    'type'        => 'string',
1031
+                    'context'     => array( 'view', 'edit', 'embed' ),
1032
+                ),
1033 1033
 				
1034
-				'custom_name'       => array(
1035
-					'description' => __( 'Custom name for the item.', 'invoicing' ),
1036
-					'type'        => 'string',
1037
-					'context'     => array( 'view', 'edit', 'embed' ),
1038
-				),
1039
-
1040
-				'custom_singular_name'       => array(
1041
-					'description' => __( 'Custom singular name for the item.', 'invoicing' ),
1042
-					'type'        => 'string',
1043
-					'context'     => array( 'view', 'edit', 'embed' ),
1044
-				),
1045
-
1046
-				'dynamic_pricing'        => array(
1047
-					'description' => __( 'Whether the item allows a user to set their own price.', 'invoicing' ),
1048
-					'type'        => 'integer',
1049
-					'context'     => array( 'view', 'edit', 'embed' ),
1050
-				),
1051
-
1052
-				'minimum_price'        => array(
1053
-					'description' => __( 'For dynamic prices, this is the minimum price that a user can set.', 'invoicing' ),
1054
-					'type'        => 'number',
1055
-					'context'     => array( 'view', 'edit', 'embed' ),
1056
-				),
1057
-
1058
-				'is_recurring'        => array(
1059
-					'description' => __( 'Whether the item is a subscription item.', 'invoicing' ),
1060
-					'type'        => 'integer',
1061
-					'context'     => array( 'view', 'edit', 'embed' ),
1062
-				),
1063
-
1064
-				'recurring_period'        => array(
1065
-					'description' => __( 'The recurring period for a recurring item.', 'invoicing' ),
1066
-					'type'        => 'string',
1067
-					'context'     => array( 'view', 'edit', 'embed' ),
1068
-					'enum'        => array( 'D', 'W', 'M', 'Y' ),
1069
-				),
1070
-
1071
-				'recurring_interval'        => array(
1072
-					'description' => __( 'The recurring interval for a subscription item.', 'invoicing' ),
1073
-					'type'        => 'integer',
1074
-					'context'     => array( 'view', 'edit', 'embed' ),
1075
-				),
1076
-
1077
-				'recurring_limit'        => array(
1078
-					'description' => __( 'The maximum number of renewals for a subscription item.', 'invoicing' ),
1079
-					'type'        => 'integer',
1080
-					'context'     => array( 'view', 'edit', 'embed' ),
1081
-				),
1082
-
1083
-				'free_trial'        => array(
1084
-					'description' => __( 'Whether the item has a free trial period.', 'invoicing' ),
1085
-					'type'        => 'integer',
1086
-					'context'     => array( 'view', 'edit', 'embed' ),
1087
-				),
1088
-
1089
-				'trial_period'        => array(
1090
-					'description' => __( 'The trial period of a recurring item.', 'invoicing' ),
1091
-					'type'        => 'string',
1092
-					'context'     => array( 'view', 'edit', 'embed' ),
1093
-					'enum'        => array( 'D', 'W', 'M', 'Y' ),
1094
-				),
1095
-
1096
-				'trial_interval'        => array(
1097
-					'description' => __( 'The trial interval for a subscription item.', 'invoicing' ),
1098
-					'type'        => 'integer',
1099
-					'context'     => array( 'view', 'edit', 'embed' ),
1100
-				),
1101
-
1102
-				'editable'        => array(
1103
-					'description' => __( 'Whether or not the item is editable.', 'invoicing' ),
1104
-					'type'        => 'integer',
1105
-					'context'     => array( 'view', 'edit' ),
1106
-				),
1107
-
1108
-			),
1109
-		);
1110
-
1111
-		// Add helpful links to the item schem.
1112
-		$schema['links'] = $this->get_schema_links();
1113
-
1114
-		/**
1115
-		 * Filters the item schema for the REST API.
1116
-		 *
1117
-		 * Enables adding extra properties to items.
1118
-		 *
1119
-		 * @since 1.0.13
1120
-		 *
1121
-		 * @param array   $schema    The item schema.
1122
-		 */
1034
+                'custom_name'       => array(
1035
+                    'description' => __( 'Custom name for the item.', 'invoicing' ),
1036
+                    'type'        => 'string',
1037
+                    'context'     => array( 'view', 'edit', 'embed' ),
1038
+                ),
1039
+
1040
+                'custom_singular_name'       => array(
1041
+                    'description' => __( 'Custom singular name for the item.', 'invoicing' ),
1042
+                    'type'        => 'string',
1043
+                    'context'     => array( 'view', 'edit', 'embed' ),
1044
+                ),
1045
+
1046
+                'dynamic_pricing'        => array(
1047
+                    'description' => __( 'Whether the item allows a user to set their own price.', 'invoicing' ),
1048
+                    'type'        => 'integer',
1049
+                    'context'     => array( 'view', 'edit', 'embed' ),
1050
+                ),
1051
+
1052
+                'minimum_price'        => array(
1053
+                    'description' => __( 'For dynamic prices, this is the minimum price that a user can set.', 'invoicing' ),
1054
+                    'type'        => 'number',
1055
+                    'context'     => array( 'view', 'edit', 'embed' ),
1056
+                ),
1057
+
1058
+                'is_recurring'        => array(
1059
+                    'description' => __( 'Whether the item is a subscription item.', 'invoicing' ),
1060
+                    'type'        => 'integer',
1061
+                    'context'     => array( 'view', 'edit', 'embed' ),
1062
+                ),
1063
+
1064
+                'recurring_period'        => array(
1065
+                    'description' => __( 'The recurring period for a recurring item.', 'invoicing' ),
1066
+                    'type'        => 'string',
1067
+                    'context'     => array( 'view', 'edit', 'embed' ),
1068
+                    'enum'        => array( 'D', 'W', 'M', 'Y' ),
1069
+                ),
1070
+
1071
+                'recurring_interval'        => array(
1072
+                    'description' => __( 'The recurring interval for a subscription item.', 'invoicing' ),
1073
+                    'type'        => 'integer',
1074
+                    'context'     => array( 'view', 'edit', 'embed' ),
1075
+                ),
1076
+
1077
+                'recurring_limit'        => array(
1078
+                    'description' => __( 'The maximum number of renewals for a subscription item.', 'invoicing' ),
1079
+                    'type'        => 'integer',
1080
+                    'context'     => array( 'view', 'edit', 'embed' ),
1081
+                ),
1082
+
1083
+                'free_trial'        => array(
1084
+                    'description' => __( 'Whether the item has a free trial period.', 'invoicing' ),
1085
+                    'type'        => 'integer',
1086
+                    'context'     => array( 'view', 'edit', 'embed' ),
1087
+                ),
1088
+
1089
+                'trial_period'        => array(
1090
+                    'description' => __( 'The trial period of a recurring item.', 'invoicing' ),
1091
+                    'type'        => 'string',
1092
+                    'context'     => array( 'view', 'edit', 'embed' ),
1093
+                    'enum'        => array( 'D', 'W', 'M', 'Y' ),
1094
+                ),
1095
+
1096
+                'trial_interval'        => array(
1097
+                    'description' => __( 'The trial interval for a subscription item.', 'invoicing' ),
1098
+                    'type'        => 'integer',
1099
+                    'context'     => array( 'view', 'edit', 'embed' ),
1100
+                ),
1101
+
1102
+                'editable'        => array(
1103
+                    'description' => __( 'Whether or not the item is editable.', 'invoicing' ),
1104
+                    'type'        => 'integer',
1105
+                    'context'     => array( 'view', 'edit' ),
1106
+                ),
1107
+
1108
+            ),
1109
+        );
1110
+
1111
+        // Add helpful links to the item schem.
1112
+        $schema['links'] = $this->get_schema_links();
1113
+
1114
+        /**
1115
+         * Filters the item schema for the REST API.
1116
+         *
1117
+         * Enables adding extra properties to items.
1118
+         *
1119
+         * @since 1.0.13
1120
+         *
1121
+         * @param array   $schema    The item schema.
1122
+         */
1123 1123
         $schema = apply_filters( "wpinv_rest_item_schema", $schema );
1124 1124
 
1125
-		//  Cache the item schema.
1126
-		$this->schema = $schema;
1125
+        //  Cache the item schema.
1126
+        $this->schema = $schema;
1127 1127
 		
1128
-		return $this->add_additional_fields_schema( $this->schema );
1129
-	}
1130
-
1131
-	/**
1132
-	 * Retrieve Link Description Objects that should be added to the Schema for the invoices collection.
1133
-	 *
1134
-	 * @since 1.0.13
1135
-	 *
1136
-	 * @return array
1137
-	 */
1138
-	protected function get_schema_links() {
1139
-
1140
-		$href = rest_url( "{$this->namespace}/{$this->rest_base}/{id}" );
1141
-
1142
-		$links = array();
1143
-
1144
-		$links[] = array(
1145
-			'rel'          => 'https://api.w.org/action-publish',
1146
-			'title'        => __( 'The current user can publish this item.' ),
1147
-			'href'         => $href,
1148
-			'targetSchema' => array(
1149
-				'type'       => 'object',
1150
-				'properties' => array(
1151
-					'status' => array(
1152
-						'type' => 'string',
1153
-						'enum' => array( 'publish', 'future' ),
1154
-					),
1155
-				),
1156
-			),
1157
-		);
1158
-
1159
-		return $links;
1160
-	}
1161
-
1162
-	/**
1163
-	 * Prepares links for the request.
1164
-	 *
1165
-	 * @since 1.0.13
1166
-	 *
1167
-	 * @param WPInv_Item $item Item Object.
1168
-	 * @return array Links for the given item.
1169
-	 */
1170
-	protected function prepare_links( $item ) {
1171
-
1172
-		// Prepare the base REST API endpoint for items.
1173
-		$base = sprintf( '%s/%s', $this->namespace, $this->rest_base );
1174
-
1175
-		// Entity meta.
1176
-		$links = array(
1177
-			'self'       => array(
1178
-				'href' => rest_url( trailingslashit( $base ) . $item->ID ),
1179
-			),
1180
-			'collection' => array(
1181
-				'href' => rest_url( $base ),
1182
-			),
1183
-		);
1184
-
1185
-		/**
1186
-		 * Filters the returned item links for the REST API.
1187
-		 *
1188
-		 * Enables adding extra links to item API responses.
1189
-		 *
1190
-		 * @since 1.0.13
1191
-		 *
1192
-		 * @param array   $links    Rest links.
1193
-		 */
1194
-		return apply_filters( "wpinv_rest_item_links", $links );
1195
-
1196
-	}
1197
-
1198
-	/**
1199
-	 * Get the link relations available for the post and current user.
1200
-	 *
1201
-	 * @since 1.0.13
1202
-	 *
1203
-	 * @param WPInv_Item   $item    Item object.
1204
-	 * @param WP_REST_Request $request Request object.
1205
-	 * @return array List of link relations.
1206
-	 */
1207
-	protected function get_available_actions( $item, $request ) {
1208
-
1209
-		if ( 'edit' !== $request['context'] ) {
1210
-			return array();
1211
-		}
1212
-
1213
-		$rels = array();
1214
-
1215
-		// Retrieve the post type object.
1216
-		$post_type = get_post_type_object( $item->post_type );
1217
-
1218
-		// Mark item as published.
1219
-		if ( current_user_can( $post_type->cap->publish_posts ) ) {
1220
-			$rels[] = 'https://api.w.org/action-publish';
1221
-		}
1222
-
1223
-		/**
1224
-		 * Filters the available item link relations for the REST API.
1225
-		 *
1226
-		 * Enables adding extra link relation for the current user and request to item responses.
1227
-		 *
1228
-		 * @since 1.0.13
1229
-		 *
1230
-		 * @param array   $rels    Available link relations.
1231
-		 */
1232
-		return apply_filters( "wpinv_rest_item_link_relations", $rels );
1233
-	}
1234
-
1235
-	/**
1236
-	 * Handles rest requests for item types.
1237
-	 *
1238
-	 * @since 1.0.13
1239
-	 * 
1240
-	 * 
1241
-	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
1242
-	 */
1243
-	public function get_item_types() {
1244
-		return rest_ensure_response( wpinv_get_item_types() );
1245
-	}
1128
+        return $this->add_additional_fields_schema( $this->schema );
1129
+    }
1130
+
1131
+    /**
1132
+     * Retrieve Link Description Objects that should be added to the Schema for the invoices collection.
1133
+     *
1134
+     * @since 1.0.13
1135
+     *
1136
+     * @return array
1137
+     */
1138
+    protected function get_schema_links() {
1139
+
1140
+        $href = rest_url( "{$this->namespace}/{$this->rest_base}/{id}" );
1141
+
1142
+        $links = array();
1143
+
1144
+        $links[] = array(
1145
+            'rel'          => 'https://api.w.org/action-publish',
1146
+            'title'        => __( 'The current user can publish this item.' ),
1147
+            'href'         => $href,
1148
+            'targetSchema' => array(
1149
+                'type'       => 'object',
1150
+                'properties' => array(
1151
+                    'status' => array(
1152
+                        'type' => 'string',
1153
+                        'enum' => array( 'publish', 'future' ),
1154
+                    ),
1155
+                ),
1156
+            ),
1157
+        );
1158
+
1159
+        return $links;
1160
+    }
1161
+
1162
+    /**
1163
+     * Prepares links for the request.
1164
+     *
1165
+     * @since 1.0.13
1166
+     *
1167
+     * @param WPInv_Item $item Item Object.
1168
+     * @return array Links for the given item.
1169
+     */
1170
+    protected function prepare_links( $item ) {
1171
+
1172
+        // Prepare the base REST API endpoint for items.
1173
+        $base = sprintf( '%s/%s', $this->namespace, $this->rest_base );
1174
+
1175
+        // Entity meta.
1176
+        $links = array(
1177
+            'self'       => array(
1178
+                'href' => rest_url( trailingslashit( $base ) . $item->ID ),
1179
+            ),
1180
+            'collection' => array(
1181
+                'href' => rest_url( $base ),
1182
+            ),
1183
+        );
1184
+
1185
+        /**
1186
+         * Filters the returned item links for the REST API.
1187
+         *
1188
+         * Enables adding extra links to item API responses.
1189
+         *
1190
+         * @since 1.0.13
1191
+         *
1192
+         * @param array   $links    Rest links.
1193
+         */
1194
+        return apply_filters( "wpinv_rest_item_links", $links );
1195
+
1196
+    }
1197
+
1198
+    /**
1199
+     * Get the link relations available for the post and current user.
1200
+     *
1201
+     * @since 1.0.13
1202
+     *
1203
+     * @param WPInv_Item   $item    Item object.
1204
+     * @param WP_REST_Request $request Request object.
1205
+     * @return array List of link relations.
1206
+     */
1207
+    protected function get_available_actions( $item, $request ) {
1208
+
1209
+        if ( 'edit' !== $request['context'] ) {
1210
+            return array();
1211
+        }
1212
+
1213
+        $rels = array();
1214
+
1215
+        // Retrieve the post type object.
1216
+        $post_type = get_post_type_object( $item->post_type );
1217
+
1218
+        // Mark item as published.
1219
+        if ( current_user_can( $post_type->cap->publish_posts ) ) {
1220
+            $rels[] = 'https://api.w.org/action-publish';
1221
+        }
1222
+
1223
+        /**
1224
+         * Filters the available item link relations for the REST API.
1225
+         *
1226
+         * Enables adding extra link relation for the current user and request to item responses.
1227
+         *
1228
+         * @since 1.0.13
1229
+         *
1230
+         * @param array   $rels    Available link relations.
1231
+         */
1232
+        return apply_filters( "wpinv_rest_item_link_relations", $rels );
1233
+    }
1234
+
1235
+    /**
1236
+     * Handles rest requests for item types.
1237
+     *
1238
+     * @since 1.0.13
1239
+     * 
1240
+     * 
1241
+     * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
1242
+     */
1243
+    public function get_item_types() {
1244
+        return rest_ensure_response( wpinv_get_item_types() );
1245
+    }
1246 1246
 
1247 1247
     
1248 1248
 }
1249 1249
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +254 added lines, -254 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since    1.0.13
9 9
  */
10 10
 
11
-if ( !defined( 'WPINC' ) ) {
11
+if (!defined('WPINC')) {
12 12
     exit;
13 13
 }
14 14
 
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 *
42 42
 	 * @param string $namespace Api Namespace
43 43
 	 */
44
-	public function __construct( $namespace ) {
44
+	public function __construct($namespace) {
45 45
         
46 46
         // Set api namespace...
47 47
 		$this->namespace = $namespace;
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 			array(
69 69
 				array(
70 70
 					'methods'             => WP_REST_Server::READABLE,
71
-					'callback'            => array( $this, 'get_item_types' ),
71
+					'callback'            => array($this, 'get_item_types'),
72 72
 				),
73 73
 			)
74 74
 		);
@@ -84,13 +84,13 @@  discard block
 block discarded – undo
84 84
 	 * @param WP_REST_Request $request Full details about the request.
85 85
 	 * @return true|WP_Error True if the request has read access, WP_Error object otherwise.
86 86
 	 */
87
-	public function get_items_permissions_check( $request ) {
87
+	public function get_items_permissions_check($request) {
88 88
 	
89
-		if ( current_user_can( 'manage_options' ) ||  current_user_can( 'manage_invoicing' ) ) {
89
+		if (current_user_can('manage_options') || current_user_can('manage_invoicing')) {
90 90
 			return true;
91 91
 		}
92 92
 
93
-		return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to view invoice items.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
93
+		return new WP_Error('rest_forbidden_context', __('Sorry, you are not allowed to view invoice items.', 'invoicing'), array('status' => rest_authorization_required_code()));
94 94
 
95 95
     }
96 96
     
@@ -102,17 +102,17 @@  discard block
 block discarded – undo
102 102
 	 * @param WP_REST_Request $request Full details about the request.
103 103
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
104 104
 	 */
105
-	public function get_items( $request ) {
105
+	public function get_items($request) {
106 106
 		
107 107
 		// Retrieve the list of registered item query parameters.
108 108
         $registered = $this->get_collection_params();
109 109
         
110 110
         $args       = array();
111 111
 
112
-        foreach( array_keys( $registered ) as $key ) {
112
+        foreach (array_keys($registered) as $key) {
113 113
 
114
-            if( isset( $request[ $key] ) ) {
115
-                $args[ $key ] = $request[ $key];
114
+            if (isset($request[$key])) {
115
+                $args[$key] = $request[$key];
116 116
             }
117 117
 
118 118
         }
@@ -127,32 +127,32 @@  discard block
 block discarded – undo
127 127
 		 * @param array           $args    Key value array of query var to query value.
128 128
 		 * @param WP_REST_Request $request The request used.
129 129
 		 */
130
-        $args       = apply_filters( "wpinv_rest_get_items_arguments", $args, $request, $this );
130
+        $args = apply_filters("wpinv_rest_get_items_arguments", $args, $request, $this);
131 131
 		
132 132
 		// Special args
133
-		$args[ 'return' ]   = 'objects';
134
-		$args[ 'paginate' ] = true;
133
+		$args['return']   = 'objects';
134
+		$args['paginate'] = true;
135 135
 
136 136
         // Run the query.
137
-		$query = wpinv_get_all_items( $args );
137
+		$query = wpinv_get_all_items($args);
138 138
 		
139 139
 		// Prepare the retrieved items
140 140
 		$items = array();
141
-		foreach( $query->items as $item ) {
141
+		foreach ($query->items as $item) {
142 142
 
143
-			if ( ! $this->check_read_permission( $item ) ) {
143
+			if (!$this->check_read_permission($item)) {
144 144
 				continue;
145 145
 			}
146 146
 
147
-			$data       = $this->prepare_item_for_response( $item, $request );
148
-			$items[]    = $this->prepare_response_for_collection( $data );
147
+			$data       = $this->prepare_item_for_response($item, $request);
148
+			$items[]    = $this->prepare_response_for_collection($data);
149 149
 
150 150
 		}
151 151
 
152 152
 		// Prepare the response.
153
-		$response = rest_ensure_response( $items );
154
-		$response->header( 'X-WP-Total', (int) $query->total );
155
-		$response->header( 'X-WP-TotalPages', (int) $query->max_num_pages );
153
+		$response = rest_ensure_response($items);
154
+		$response->header('X-WP-Total', (int) $query->total);
155
+		$response->header('X-WP-TotalPages', (int) $query->max_num_pages);
156 156
 
157 157
 		/**
158 158
 		 * Filters the responses for item requests.
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
 		 * @param WP_REST_Request     $request The request used.
166 166
          * @param array               $args Array of args used to retrieve the items
167 167
 		 */
168
-        $response       = apply_filters( "wpinv_rest_items_response", $response, $request, $args );
168
+        $response = apply_filters("wpinv_rest_items_response", $response, $request, $args);
169 169
 
170
-        return rest_ensure_response( $response );
170
+        return rest_ensure_response($response);
171 171
         
172 172
     }
173 173
 
@@ -179,17 +179,17 @@  discard block
 block discarded – undo
179 179
 	 * @param int $item_id Supplied ID.
180 180
 	 * @return WPInv_Item|WP_Error Item object if ID is valid, WP_Error otherwise.
181 181
 	 */
182
-	protected function get_post( $item_id ) {
182
+	protected function get_post($item_id) {
183 183
 		
184
-		$error     = new WP_Error( 'rest_item_invalid_id', __( 'Invalid item ID.', 'invoicing' ), array( 'status' => 404 ) );
184
+		$error = new WP_Error('rest_item_invalid_id', __('Invalid item ID.', 'invoicing'), array('status' => 404));
185 185
 
186 186
         // Ids start from 1
187
-        if ( (int) $item_id <= 0 ) {
187
+        if ((int) $item_id <= 0) {
188 188
 			return $error;
189 189
 		}
190 190
 
191
-		$item = wpinv_get_item_by( 'id', (int) $item_id );
192
-		if ( empty( $item ) ) {
191
+		$item = wpinv_get_item_by('id', (int) $item_id);
192
+		if (empty($item)) {
193 193
 			return $error;
194 194
         }
195 195
 
@@ -205,29 +205,29 @@  discard block
 block discarded – undo
205 205
 	 * @param WP_REST_Request $request Full details about the request.
206 206
 	 * @return bool|WP_Error True if the request has read access for the invoice item, WP_Error object otherwise.
207 207
 	 */
208
-	public function get_item_permissions_check( $request ) {
208
+	public function get_item_permissions_check($request) {
209 209
 
210 210
         // Retrieve the item object.
211
-        $item = $this->get_post( $request['id'] );
211
+        $item = $this->get_post($request['id']);
212 212
         
213 213
         // Ensure it is valid.
214
-		if ( is_wp_error( $item ) ) {
214
+		if (is_wp_error($item)) {
215 215
 			return $item;
216 216
 		}
217 217
 
218
-		$post_type = get_post_type_object( $this->post_type );
218
+		$post_type = get_post_type_object($this->post_type);
219 219
 
220
-		if ( ! current_user_can(  $post_type->cap->read_post, $item->ID  ) ) {
220
+		if (!current_user_can($post_type->cap->read_post, $item->ID)) {
221 221
 			return new WP_Error( 
222 222
                 'rest_cannot_edit', 
223
-                __( 'Sorry, you are not allowed to view this item.', 'invoicing' ), 
223
+                __('Sorry, you are not allowed to view this item.', 'invoicing'), 
224 224
                 array( 
225 225
                     'status' => rest_authorization_required_code(),
226 226
                 )
227 227
             );
228 228
         }
229 229
 
230
-		return $this->check_read_permission( $item );
230
+		return $this->check_read_permission($item);
231 231
     }
232 232
     
233 233
     /**
@@ -241,10 +241,10 @@  discard block
 block discarded – undo
241 241
 	 * @param WPInv_Item $item WPInv_Item object.
242 242
 	 * @return bool Whether the post can be read.
243 243
 	 */
244
-	public function check_read_permission( $item ) {
244
+	public function check_read_permission($item) {
245 245
 
246 246
 		// An item can be read by an admin...
247
-		if ( current_user_can( 'manage_options' ) ||  current_user_can( 'manage_invoicing' ) ) {
247
+		if (current_user_can('manage_options') || current_user_can('manage_invoicing')) {
248 248
 			return true;
249 249
 		}
250 250
 
@@ -259,18 +259,18 @@  discard block
 block discarded – undo
259 259
 	 * @param WP_REST_Request $request Full details about the request.
260 260
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
261 261
 	 */
262
-	public function get_item( $request ) {
262
+	public function get_item($request) {
263 263
 
264 264
         // Fetch the item.
265
-        $item = $this->get_post( $request['id'] );
265
+        $item = $this->get_post($request['id']);
266 266
         
267 267
         // Abort early if it does not exist
268
-		if ( is_wp_error( $item ) ) {
268
+		if (is_wp_error($item)) {
269 269
 			return $item;
270 270
 		}
271 271
 
272 272
 		// Prepare the response
273
-		$response = $this->prepare_item_for_response( $item, $request );
273
+		$response = $this->prepare_item_for_response($item, $request);
274 274
 
275 275
 		/**
276 276
 		 * Filters the responses for single invoice item requests.
@@ -282,9 +282,9 @@  discard block
 block discarded – undo
282 282
 		 * @param WP_HTTP_Response $response Response.
283 283
 		 * @param WP_REST_Request  $request The request used.
284 284
 		 */
285
-        $response       = apply_filters( "wpinv_rest_get_item_response", $response, $request );
285
+        $response = apply_filters("wpinv_rest_get_item_response", $response, $request);
286 286
 
287
-        return rest_ensure_response( $response );
287
+        return rest_ensure_response($response);
288 288
 
289 289
     }
290 290
     
@@ -296,21 +296,21 @@  discard block
 block discarded – undo
296 296
 	 * @param WP_REST_Request $request Full details about the request.
297 297
 	 * @return true|WP_Error True if the request has access to create items, WP_Error object otherwise.
298 298
 	 */
299
-	public function create_item_permissions_check( $request ) {
299
+	public function create_item_permissions_check($request) {
300 300
 	
301
-		if ( ! empty( $request['id'] ) ) {
302
-			return new WP_Error( 'rest_item_exists', __( 'Cannot create existing item.', 'invoicing' ), array( 'status' => 400 ) );
301
+		if (!empty($request['id'])) {
302
+			return new WP_Error('rest_item_exists', __('Cannot create existing item.', 'invoicing'), array('status' => 400));
303 303
 		}
304 304
 
305
-		if ( current_user_can( 'manage_options' ) ||  current_user_can( 'manage_invoicing' ) ) {
305
+		if (current_user_can('manage_options') || current_user_can('manage_invoicing')) {
306 306
 			return true;
307 307
 		}
308 308
 
309
-		$post_type = get_post_type_object( $this->post_type );
310
-		if ( ! current_user_can( $post_type->cap->create_posts ) ) {
309
+		$post_type = get_post_type_object($this->post_type);
310
+		if (!current_user_can($post_type->cap->create_posts)) {
311 311
 			return new WP_Error( 
312 312
                 'rest_cannot_create', 
313
-                __( 'Sorry, you are not allowed to create invoice items as this user.', 'invoicing' ), 
313
+                __('Sorry, you are not allowed to create invoice items as this user.', 'invoicing'), 
314 314
                 array( 
315 315
                     'status' => rest_authorization_required_code(),
316 316
                 )
@@ -328,30 +328,30 @@  discard block
 block discarded – undo
328 328
 	 * @param WP_REST_Request $request Full details about the request.
329 329
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
330 330
 	 */
331
-	public function create_item( $request ) {
331
+	public function create_item($request) {
332 332
 
333
-		if ( ! empty( $request['id'] ) ) {
334
-			return new WP_Error( 'rest_item_exists', __( 'Cannot create existing invoice item.', 'invoicing' ), array( 'status' => 400 ) );
333
+		if (!empty($request['id'])) {
334
+			return new WP_Error('rest_item_exists', __('Cannot create existing invoice item.', 'invoicing'), array('status' => 400));
335 335
 		}
336 336
 
337
-		$request->set_param( 'context', 'edit' );
337
+		$request->set_param('context', 'edit');
338 338
 
339 339
 		// Prepare the updated data.
340
-		$item_data = $this->prepare_item_for_database( $request );
340
+		$item_data = $this->prepare_item_for_database($request);
341 341
 
342
-		if ( is_wp_error( $item_data ) ) {
342
+		if (is_wp_error($item_data)) {
343 343
 			return $item_data;
344 344
 		}
345 345
 
346 346
 		// Try creating the item.
347
-        $item = wpinv_create_item( $item_data, true );
347
+        $item = wpinv_create_item($item_data, true);
348 348
 
349
-		if ( is_wp_error( $item ) ) {
349
+		if (is_wp_error($item)) {
350 350
             return $item;
351 351
 		}
352 352
 
353 353
 		// Prepare the response
354
-		$response = $this->prepare_item_for_response( $item, $request );
354
+		$response = $this->prepare_item_for_response($item, $request);
355 355
 
356 356
 		/**
357 357
 		 * Fires after a single invoice item is created or updated via the REST API.
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 		 * @param WP_REST_Request $request  Request object.
363 363
 		 * @param bool            $creating True when creating a post, false when updating.
364 364
 		 */
365
-		do_action( "wpinv_rest_insert_item", $item, $request, true );
365
+		do_action("wpinv_rest_insert_item", $item, $request, true);
366 366
 
367 367
 		/**
368 368
 		 * Filters the responses for creating single item requests.
@@ -374,9 +374,9 @@  discard block
 block discarded – undo
374 374
 		 * @param array           $item_data Invoice properties.
375 375
 		 * @param WP_REST_Request $request The request used.
376 376
 		 */
377
-        $response       = apply_filters( "wpinv_rest_create_item_response", $response, $request );
377
+        $response = apply_filters("wpinv_rest_create_item_response", $response, $request);
378 378
 
379
-        return rest_ensure_response( $response );
379
+        return rest_ensure_response($response);
380 380
 	}
381 381
 
382 382
 	/**
@@ -387,21 +387,21 @@  discard block
 block discarded – undo
387 387
 	 * @param WP_REST_Request $request Full details about the request.
388 388
 	 * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise.
389 389
 	 */
390
-	public function update_item_permissions_check( $request ) {
390
+	public function update_item_permissions_check($request) {
391 391
 
392 392
 		// Retrieve the item.
393
-		$item = $this->get_post( $request['id'] );
394
-		if ( is_wp_error( $item ) ) {
393
+		$item = $this->get_post($request['id']);
394
+		if (is_wp_error($item)) {
395 395
 			return $item;
396 396
 		}
397 397
 
398
-		if ( wpinv_current_user_can_manage_invoicing() ) {
398
+		if (wpinv_current_user_can_manage_invoicing()) {
399 399
 			return true;
400 400
 		}
401 401
 
402 402
 		return new WP_Error( 
403 403
 			'rest_cannot_edit', 
404
-			__( 'Sorry, you are not allowed to update this item.', 'invoicing' ), 
404
+			__('Sorry, you are not allowed to update this item.', 'invoicing'), 
405 405
 			array( 
406 406
 				'status' => rest_authorization_required_code(),
407 407
 			)
@@ -417,46 +417,46 @@  discard block
 block discarded – undo
417 417
 	 * @param WP_REST_Request $request Full details about the request.
418 418
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
419 419
 	 */
420
-	public function update_item( $request ) {
420
+	public function update_item($request) {
421 421
 		
422 422
 		// Ensure the item exists.
423
-        $valid_check = $this->get_post( $request['id'] );
423
+        $valid_check = $this->get_post($request['id']);
424 424
         
425 425
         // Abort early if it does not exist
426
-		if ( is_wp_error( $valid_check ) ) {
426
+		if (is_wp_error($valid_check)) {
427 427
 			return $valid_check;
428 428
 		}
429 429
 
430
-		$request->set_param( 'context', 'edit' );
430
+		$request->set_param('context', 'edit');
431 431
 
432 432
 		// Prepare the updated data.
433
-		$data_to_update = $this->prepare_item_for_database( $request );
433
+		$data_to_update = $this->prepare_item_for_database($request);
434 434
 
435
-		if ( is_wp_error( $data_to_update ) ) {
435
+		if (is_wp_error($data_to_update)) {
436 436
 			return $data_to_update;
437 437
 		}
438 438
 
439 439
 		// Abort if no item data is provided
440
-        if( empty( $data_to_update ) ) {
441
-            return new WP_Error( 'missing_data', __( 'An update request cannot be empty.', 'invoicing' ) );
440
+        if (empty($data_to_update)) {
441
+            return new WP_Error('missing_data', __('An update request cannot be empty.', 'invoicing'));
442 442
         }
443 443
 
444 444
 		// Include the item ID
445 445
 		$data_to_update['ID'] = $request['id'];
446 446
 
447 447
 		// Update the item
448
-		$updated_item = wpinv_update_item( $data_to_update, true );
448
+		$updated_item = wpinv_update_item($data_to_update, true);
449 449
 
450 450
 		// Incase the update operation failed...
451
-		if ( is_wp_error( $updated_item ) ) {
451
+		if (is_wp_error($updated_item)) {
452 452
 			return $updated_item;
453 453
 		}
454 454
 
455 455
 		// Prepare the response
456
-		$response = $this->prepare_item_for_response( $updated_item, $request );
456
+		$response = $this->prepare_item_for_response($updated_item, $request);
457 457
 
458 458
 		/** This action is documented in includes/class-wpinv-rest-item-controller.php */
459
-		do_action( "wpinv_rest_insert_item", $updated_item, $request, false );
459
+		do_action("wpinv_rest_insert_item", $updated_item, $request, false);
460 460
 
461 461
 		/**
462 462
 		 * Filters the responses for updating single item requests.
@@ -468,9 +468,9 @@  discard block
 block discarded – undo
468 468
 		 * @param array           $data_to_update Item properties.
469 469
 		 * @param WP_REST_Request $request The request used.
470 470
 		 */
471
-        $response       = apply_filters( "wpinv_rest_update_item_response", $response,  $data_to_update, $request );
471
+        $response = apply_filters("wpinv_rest_update_item_response", $response, $data_to_update, $request);
472 472
 
473
-        return rest_ensure_response( $response );
473
+        return rest_ensure_response($response);
474 474
 	}
475 475
 
476 476
 	/**
@@ -481,21 +481,21 @@  discard block
 block discarded – undo
481 481
 	 * @param WP_REST_Request $request Full details about the request.
482 482
 	 * @return true|WP_Error True if the request has access to delete the item, WP_Error object otherwise.
483 483
 	 */
484
-	public function delete_item_permissions_check( $request ) {
484
+	public function delete_item_permissions_check($request) {
485 485
 
486 486
 		// Retrieve the item.
487
-		$item = $this->get_post( $request['id'] );
488
-		if ( is_wp_error( $item ) ) {
487
+		$item = $this->get_post($request['id']);
488
+		if (is_wp_error($item)) {
489 489
 			return $item;
490 490
 		}
491 491
 
492 492
 		// 
493 493
 
494 494
 		// Ensure the current user can delete the item
495
-		if (! wpinv_can_delete_item( $request['id'] ) ) {
495
+		if (!wpinv_can_delete_item($request['id'])) {
496 496
 			return new WP_Error( 
497 497
                 'rest_cannot_delete', 
498
-                __( 'Sorry, you are not allowed to delete this item.', 'invoicing' ), 
498
+                __('Sorry, you are not allowed to delete this item.', 'invoicing'), 
499 499
                 array( 
500 500
                     'status' => rest_authorization_required_code(),
501 501
                 )
@@ -513,31 +513,31 @@  discard block
 block discarded – undo
513 513
 	 * @param WP_REST_Request $request Full details about the request.
514 514
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
515 515
 	 */
516
-	public function delete_item( $request ) {
516
+	public function delete_item($request) {
517 517
 		
518 518
 		// Retrieve the item.
519
-		$item = $this->get_post( $request['id'] );
520
-		if ( is_wp_error( $item ) ) {
519
+		$item = $this->get_post($request['id']);
520
+		if (is_wp_error($item)) {
521 521
 			return $item;
522 522
 		}
523 523
 
524
-		$request->set_param( 'context', 'edit' );
524
+		$request->set_param('context', 'edit');
525 525
 
526 526
 		// Prepare the item id
527
-		$id    = $item->ID;
527
+		$id = $item->ID;
528 528
 
529 529
 		// Prepare the response
530
-		$response = $this->prepare_item_for_response( $item, $request );
530
+		$response = $this->prepare_item_for_response($item, $request);
531 531
 
532 532
 		// Check if the user wants to bypass the trash...
533 533
 		$force_delete = (bool) $request['force'];
534 534
 
535 535
 		// Try deleting the item.
536
-		$deleted = wp_delete_post( $id, $force_delete );
536
+		$deleted = wp_delete_post($id, $force_delete);
537 537
 
538 538
 		// Abort early if we can't delete the item.
539
-		if ( ! $deleted ) {
540
-			return new WP_Error( 'rest_cannot_delete', __( 'The item cannot be deleted.', 'invoicing' ), array( 'status' => 500 ) );
539
+		if (!$deleted) {
540
+			return new WP_Error('rest_cannot_delete', __('The item cannot be deleted.', 'invoicing'), array('status' => 500));
541 541
 		}
542 542
 
543 543
 		/**
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
 		 * @param WPInv_Item    $item  The deleted or trashed item.
550 550
 		 * @param WP_REST_Request  $request  The request sent to the API.
551 551
 		 */
552
-		do_action( "wpinv_rest_delete_item", $item, $request );
552
+		do_action("wpinv_rest_delete_item", $item, $request);
553 553
 
554 554
 		return $response;
555 555
 
@@ -565,19 +565,19 @@  discard block
 block discarded – undo
565 565
 	 */
566 566
 	public function get_collection_params() {
567 567
         
568
-        $query_params               = array(
568
+        $query_params = array(
569 569
 
570 570
             // Item status.
571 571
             'status'                => array(
572 572
                 'default'           => 'publish',
573
-                'description'       => __( 'Limit result set to items assigned one or more statuses.', 'invoicing' ),
573
+                'description'       => __('Limit result set to items assigned one or more statuses.', 'invoicing'),
574 574
                 'type'              => 'array',
575
-                'sanitize_callback' => array( $this, 'sanitize_post_statuses' ),
575
+                'sanitize_callback' => array($this, 'sanitize_post_statuses'),
576 576
             ),
577 577
             
578 578
             // Item types
579 579
             'type'                  => array(
580
-				'description'       => __( 'Type of items to fetch.', 'invoicing' ),
580
+				'description'       => __('Type of items to fetch.', 'invoicing'),
581 581
 				'type'              => 'array',
582 582
 				'default'           => wpinv_item_types(),
583 583
 				'items'             => array(
@@ -588,21 +588,21 @@  discard block
 block discarded – undo
588 588
 			
589 589
 			// Number of results per page
590 590
             'limit'                 => array(
591
-				'description'       => __( 'Number of items to fetch.', 'invoicing' ),
591
+				'description'       => __('Number of items to fetch.', 'invoicing'),
592 592
 				'type'              => 'integer',
593
-				'default'           => (int) get_option( 'posts_per_page' ),
593
+				'default'           => (int) get_option('posts_per_page'),
594 594
             ),
595 595
 
596 596
             // Pagination
597 597
             'page'     => array(
598
-				'description'       => __( 'Current page to fetch.', 'invoicing' ),
598
+				'description'       => __('Current page to fetch.', 'invoicing'),
599 599
 				'type'              => 'integer',
600 600
 				'default'           => 1,
601 601
             ),
602 602
 
603 603
             // Exclude certain items
604 604
             'exclude'  => array(
605
-                'description' => __( 'Ensure result set excludes specific IDs.', 'invoicing' ),
605
+                'description' => __('Ensure result set excludes specific IDs.', 'invoicing'),
606 606
                 'type'        => 'array',
607 607
                 'items'       => array(
608 608
                     'type' => 'integer',
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
 
613 613
             // Order items by
614 614
             'orderby'  => array(
615
-                'description' => __( 'Sort items by object attribute.', 'invoicing' ),
615
+                'description' => __('Sort items by object attribute.', 'invoicing'),
616 616
                 'type'        => 'string',
617 617
                 'default'     => 'date',
618 618
                 'enum'        => array(
@@ -628,15 +628,15 @@  discard block
 block discarded – undo
628 628
 
629 629
             // How to order
630 630
             'order'    => array(
631
-                'description' => __( 'Order sort attribute ascending or descending.', 'invoicing' ),
631
+                'description' => __('Order sort attribute ascending or descending.', 'invoicing'),
632 632
                 'type'        => 'string',
633 633
                 'default'     => 'DESC',
634
-                'enum'        => array( 'ASC', 'DESC' ),
634
+                'enum'        => array('ASC', 'DESC'),
635 635
 			),
636 636
 			
637 637
 			// Search term
638 638
             'search'                => array(
639
-				'description'       => __( 'Return items that match the search term.', 'invoicing' ),
639
+				'description'       => __('Return items that match the search term.', 'invoicing'),
640 640
 				'type'              => 'string',
641 641
             ),
642 642
         );
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
 		 *
650 650
 		 * @param array        $query_params JSON Schema-formatted collection parameters.
651 651
 		 */
652
-		return apply_filters( "wpinv_rest_items_collection_params", $query_params );
652
+		return apply_filters("wpinv_rest_items_collection_params", $query_params);
653 653
     }
654 654
     
655 655
     /**
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
 	 * @param object|string $post_type Post type name or object.
661 661
 	 * @return bool Whether the post type is allowed in REST.
662 662
 	 */
663
-	protected function check_is_post_type_allowed( $post_type ) {
663
+	protected function check_is_post_type_allowed($post_type) {
664 664
 		return true;
665 665
 	}
666 666
 
@@ -672,84 +672,84 @@  discard block
 block discarded – undo
672 672
 	 * @param WP_REST_Request $request Request object.
673 673
 	 * @return array|WP_Error Invoice Properties or WP_Error.
674 674
 	 */
675
-	protected function prepare_item_for_database( $request ) {
675
+	protected function prepare_item_for_database($request) {
676 676
 		$prepared_item = new stdClass();
677 677
 
678 678
 		// Post ID.
679
-		if ( isset( $request['id'] ) ) {
680
-			$existing_item = $this->get_post( $request['id'] );
681
-			if ( is_wp_error( $existing_item ) ) {
679
+		if (isset($request['id'])) {
680
+			$existing_item = $this->get_post($request['id']);
681
+			if (is_wp_error($existing_item)) {
682 682
 				return $existing_item;
683 683
 			}
684 684
 
685
-			$prepared_item->ID 		  = $existing_item->ID;
685
+			$prepared_item->ID = $existing_item->ID;
686 686
 		}
687 687
 
688 688
 		$schema = $this->get_item_schema();
689 689
 
690 690
 		// item title.
691
-		if ( ! empty( $schema['properties']['name'] ) && isset( $request['name'] ) ) {
692
-			$prepared_item->title = sanitize_text_field( $request['name'] );
691
+		if (!empty($schema['properties']['name']) && isset($request['name'])) {
692
+			$prepared_item->title = sanitize_text_field($request['name']);
693 693
 		}
694 694
 
695 695
 		// item summary.
696
-		if ( ! empty( $schema['properties']['summary'] ) && isset( $request['summary'] ) ) {
697
-			$prepared_item->excerpt = wp_kses_post( $request['summary'] );
696
+		if (!empty($schema['properties']['summary']) && isset($request['summary'])) {
697
+			$prepared_item->excerpt = wp_kses_post($request['summary']);
698 698
 		}
699 699
 
700 700
 		// item price.
701
-		if ( ! empty( $schema['properties']['price'] ) && isset( $request['price'] ) ) {
702
-			$prepared_item->price = floatval( $request['price'] );
701
+		if (!empty($schema['properties']['price']) && isset($request['price'])) {
702
+			$prepared_item->price = floatval($request['price']);
703 703
 		}
704 704
 
705 705
 		// minimum price (for dynamc items).
706
-		if ( ! empty( $schema['properties']['minimum_price'] ) && isset( $request['minimum_price'] ) ) {
707
-			$prepared_item->minimum_price = floatval( $request['minimum_price'] );
706
+		if (!empty($schema['properties']['minimum_price']) && isset($request['minimum_price'])) {
707
+			$prepared_item->minimum_price = floatval($request['minimum_price']);
708 708
 		}
709 709
 
710 710
 		// item status.
711
-		if ( ! empty( $schema['properties']['status'] ) && isset( $request['status'] ) ) {
711
+		if (!empty($schema['properties']['status']) && isset($request['status'])) {
712 712
 			$prepared_item->status = 'publish' === $request['status'] ? 'publish' : 'pending';
713 713
 		}
714 714
 
715 715
 		// item type.
716
-		if ( ! empty( $schema['properties']['type'] ) && isset( $request['type'] ) ) {
717
-			$prepared_item->type = in_array( $request['type'], wpinv_item_types() ) ? trim( strtolower( $request['type'] ) ) : 'custom';
716
+		if (!empty($schema['properties']['type']) && isset($request['type'])) {
717
+			$prepared_item->type = in_array($request['type'], wpinv_item_types()) ? trim(strtolower($request['type'])) : 'custom';
718 718
 		}
719 719
 
720 720
 		// VAT rule.
721
-		if ( ! empty( $schema['properties']['vat_rule'] ) && isset( $request['vat_rule'] ) ) {
721
+		if (!empty($schema['properties']['vat_rule']) && isset($request['vat_rule'])) {
722 722
 			$prepared_item->vat_rule = 'digital' === $request['vat_rule'] ? 'digital' : 'physical';
723 723
 		}
724 724
 
725 725
 		// Simple strings.
726
-		foreach( array( 'custom_id', 'custom_name', 'custom_singular_name' ) as $property ) {
726
+		foreach (array('custom_id', 'custom_name', 'custom_singular_name') as $property) {
727 727
 
728
-			if ( ! empty( $schema['properties'][$property] ) && isset( $request[$property] ) ) {
729
-				$prepared_item->$property = sanitize_text_field( $request[$property] );
728
+			if (!empty($schema['properties'][$property]) && isset($request[$property])) {
729
+				$prepared_item->$property = sanitize_text_field($request[$property]);
730 730
 			}
731 731
 
732 732
 		}
733 733
 
734 734
 		// Simple integers.
735
-		foreach( array( 'is_recurring', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_interval', 'dynamic_pricing', 'editable' ) as $property ) {
735
+		foreach (array('is_recurring', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_interval', 'dynamic_pricing', 'editable') as $property) {
736 736
 
737
-			if ( ! empty( $schema['properties'][$property] ) && isset( $request[$property] ) ) {
738
-				$prepared_item->$property = intval( $request[$property] );
737
+			if (!empty($schema['properties'][$property]) && isset($request[$property])) {
738
+				$prepared_item->$property = intval($request[$property]);
739 739
 			}
740 740
 
741 741
 		}
742 742
 
743 743
 		// Time periods.
744
-		foreach( array( 'recurring_period',  'trial_period' ) as $property ) {
744
+		foreach (array('recurring_period', 'trial_period') as $property) {
745 745
 
746
-			if ( ! empty( $schema['properties'][$property] ) && isset( $request[$property] ) ) {
747
-				$prepared_item->$property = in_array( $request[$property], array( 'D', 'W', 'M', 'Y' ) ) ? trim( strtoupper( $request[$property] ) ) : 'D';
746
+			if (!empty($schema['properties'][$property]) && isset($request[$property])) {
747
+				$prepared_item->$property = in_array($request[$property], array('D', 'W', 'M', 'Y')) ? trim(strtoupper($request[$property])) : 'D';
748 748
 			}
749 749
 
750 750
 		}
751 751
 
752
-		$item_data = (array) wp_unslash( $prepared_item );
752
+		$item_data = (array) wp_unslash($prepared_item);
753 753
 
754 754
 		/**
755 755
 		 * Filters an item before it is inserted via the REST API.
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
 		 * @param array        $item_data An array of item data
760 760
 		 * @param WP_REST_Request $request       Request object.
761 761
 		 */
762
-		return apply_filters( "wpinv_rest_pre_insert_item", $item_data, $request );
762
+		return apply_filters("wpinv_rest_pre_insert_item", $item_data, $request);
763 763
 
764 764
 	}
765 765
 
@@ -772,20 +772,20 @@  discard block
 block discarded – undo
772 772
 	 * @param WP_REST_Request $request Request object.
773 773
 	 * @return WP_REST_Response Response object.
774 774
 	 */
775
-	public function prepare_item_for_response( $item, $request ) {
775
+	public function prepare_item_for_response($item, $request) {
776 776
 
777
-		$GLOBALS['post'] = get_post( $item->get_ID() );
777
+		$GLOBALS['post'] = get_post($item->get_ID());
778 778
 
779
-		setup_postdata( $item->get_ID() );
779
+		setup_postdata($item->get_ID());
780 780
 
781 781
 		// Fetch the fields to include in this response.
782
-		$fields = $this->get_fields_for_response( $request );
782
+		$fields = $this->get_fields_for_response($request);
783 783
 
784 784
 		// Base fields for every item.
785 785
 		$data = array();
786 786
 
787 787
 		// Set up ID
788
-		if ( rest_is_field_included( 'id', $fields ) ) {
788
+		if (rest_is_field_included('id', $fields)) {
789 789
 			$data['id'] = $item->get_ID();
790 790
 		}
791 791
 
@@ -798,49 +798,49 @@  discard block
 block discarded – undo
798 798
 			'editable'
799 799
 		);
800 800
 
801
-		foreach( $item_properties as $property ) {
801
+		foreach ($item_properties as $property) {
802 802
 
803
-			if ( rest_is_field_included( $property, $fields ) && method_exists( $item, 'get_' . $property ) ) {
804
-				$data[$property] = call_user_func( array( $item, 'get_' . $property ) );
803
+			if (rest_is_field_included($property, $fields) && method_exists($item, 'get_' . $property)) {
804
+				$data[$property] = call_user_func(array($item, 'get_' . $property));
805 805
 			}
806 806
 
807 807
 		}
808 808
 
809 809
 		// Dynamic pricing.
810
-		if( $item->supports_dynamic_pricing() ) {
810
+		if ($item->supports_dynamic_pricing()) {
811 811
 
812
-			if( rest_is_field_included( 'dynamic_pricing', $fields ) ) {
812
+			if (rest_is_field_included('dynamic_pricing', $fields)) {
813 813
 				$data['dynamic_pricing'] = $item->get_is_dynamic_pricing();
814 814
 			}
815 815
 
816
-			if( rest_is_field_included( 'minimum_price', $fields ) ) {
816
+			if (rest_is_field_included('minimum_price', $fields)) {
817 817
 				$data['minimum_price'] = $item->get_minimum_price();
818 818
 			}
819 819
 		}
820 820
 
821 821
 		// Subscriptions.
822
-		if( rest_is_field_included( 'is_recurring', $fields ) ) {
822
+		if (rest_is_field_included('is_recurring', $fields)) {
823 823
 			$data['is_recurring'] = $item->get_is_recurring();
824 824
 		}
825 825
 
826
-		if( $item->is_recurring() ) {
826
+		if ($item->is_recurring()) {
827 827
 
828
-			$recurring_fields = array( 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial' );
829
-			foreach( $recurring_fields as $field ) {
828
+			$recurring_fields = array('is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial');
829
+			foreach ($recurring_fields as $field) {
830 830
 
831
-				if ( rest_is_field_included( $field, $fields ) && method_exists( $item, 'get_' . $field ) ) {
832
-					$data[$field] = call_user_func( array( $item, 'get_' . $field ) );
831
+				if (rest_is_field_included($field, $fields) && method_exists($item, 'get_' . $field)) {
832
+					$data[$field] = call_user_func(array($item, 'get_' . $field));
833 833
 				}
834 834
 	
835 835
 			}
836 836
 
837
-			if( $item->has_free_trial() ) {
837
+			if ($item->has_free_trial()) {
838 838
 
839
-				$trial_fields = array( 'trial_period', 'trial_interval' );
840
-				foreach( $trial_fields as $field ) {
839
+				$trial_fields = array('trial_period', 'trial_interval');
840
+				foreach ($trial_fields as $field) {
841 841
 
842
-					if ( rest_is_field_included( $field, $fields ) && method_exists( $item, 'get_' . $field ) ) {
843
-						$data[$field] = call_user_func( array( $item, 'get_' . $field ) );
842
+					if (rest_is_field_included($field, $fields) && method_exists($item, 'get_' . $field)) {
843
+						$data[$field] = call_user_func(array($item, 'get_' . $field));
844 844
 					}
845 845
 	
846 846
 				}
@@ -849,23 +849,23 @@  discard block
 block discarded – undo
849 849
 
850 850
 		}
851 851
 
852
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
853
-		$data    = $this->add_additional_fields_to_object( $data, $request );
854
-		$data    = $this->filter_response_by_context( $data, $context );
852
+		$context = !empty($request['context']) ? $request['context'] : 'view';
853
+		$data    = $this->add_additional_fields_to_object($data, $request);
854
+		$data    = $this->filter_response_by_context($data, $context);
855 855
 
856 856
 		// Wrap the data in a response object.
857
-		$response = rest_ensure_response( $data );
857
+		$response = rest_ensure_response($data);
858 858
 
859
-		$links = $this->prepare_links( $item );
860
-		$response->add_links( $links );
859
+		$links = $this->prepare_links($item);
860
+		$response->add_links($links);
861 861
 
862
-		if ( ! empty( $links['self']['href'] ) ) {
863
-			$actions = $this->get_available_actions( $item, $request );
862
+		if (!empty($links['self']['href'])) {
863
+			$actions = $this->get_available_actions($item, $request);
864 864
 
865 865
 			$self = $links['self']['href'];
866 866
 
867
-			foreach ( $actions as $rel ) {
868
-				$response->add_link( $rel, $self );
867
+			foreach ($actions as $rel) {
868
+				$response->add_link($rel, $self);
869 869
 			}
870 870
 		}
871 871
 
@@ -878,7 +878,7 @@  discard block
 block discarded – undo
878 878
 		 * @param WPInv_Item    $item  The item object.
879 879
 		 * @param WP_REST_Request  $request  Request object.
880 880
 		 */
881
-		return apply_filters( "wpinv_rest_prepare_item", $response, $item, $request );
881
+		return apply_filters("wpinv_rest_prepare_item", $response, $item, $request);
882 882
 	}
883 883
 
884 884
 	/**
@@ -891,57 +891,57 @@  discard block
 block discarded – undo
891 891
 	 * @param WP_REST_Request $request Full details about the request.
892 892
 	 * @return array Fields to be included in the response.
893 893
 	 */
894
-	public function get_fields_for_response( $request ) {
894
+	public function get_fields_for_response($request) {
895 895
 		$schema     = $this->get_item_schema();
896
-		$properties = isset( $schema['properties'] ) ? $schema['properties'] : array();
896
+		$properties = isset($schema['properties']) ? $schema['properties'] : array();
897 897
 
898 898
 		$additional_fields = $this->get_additional_fields();
899
-		foreach ( $additional_fields as $field_name => $field_options ) {
899
+		foreach ($additional_fields as $field_name => $field_options) {
900 900
 			// For back-compat, include any field with an empty schema
901 901
 			// because it won't be present in $this->get_item_schema().
902
-			if ( is_null( $field_options['schema'] ) ) {
903
-				$properties[ $field_name ] = $field_options;
902
+			if (is_null($field_options['schema'])) {
903
+				$properties[$field_name] = $field_options;
904 904
 			}
905 905
 		}
906 906
 
907 907
 		// Exclude fields that specify a different context than the request context.
908 908
 		$context = $request['context'];
909
-		if ( $context ) {
910
-			foreach ( $properties as $name => $options ) {
911
-				if ( ! empty( $options['context'] ) && ! in_array( $context, $options['context'], true ) ) {
912
-					unset( $properties[ $name ] );
909
+		if ($context) {
910
+			foreach ($properties as $name => $options) {
911
+				if (!empty($options['context']) && !in_array($context, $options['context'], true)) {
912
+					unset($properties[$name]);
913 913
 				}
914 914
 			}
915 915
 		}
916 916
 
917
-		$fields = array_keys( $properties );
917
+		$fields = array_keys($properties);
918 918
 
919
-		if ( ! isset( $request['_fields'] ) ) {
919
+		if (!isset($request['_fields'])) {
920 920
 			return $fields;
921 921
 		}
922
-		$requested_fields = wpinv_parse_list( $request['_fields'] );
923
-		if ( 0 === count( $requested_fields ) ) {
922
+		$requested_fields = wpinv_parse_list($request['_fields']);
923
+		if (0 === count($requested_fields)) {
924 924
 			return $fields;
925 925
 		}
926 926
 		// Trim off outside whitespace from the comma delimited list.
927
-		$requested_fields = array_map( 'trim', $requested_fields );
927
+		$requested_fields = array_map('trim', $requested_fields);
928 928
 		// Always persist 'id', because it can be needed for add_additional_fields_to_object().
929
-		if ( in_array( 'id', $fields, true ) ) {
929
+		if (in_array('id', $fields, true)) {
930 930
 			$requested_fields[] = 'id';
931 931
 		}
932 932
 		// Return the list of all requested fields which appear in the schema.
933 933
 		return array_reduce(
934 934
 			$requested_fields,
935
-			function( $response_fields, $field ) use ( $fields ) {
936
-				if ( in_array( $field, $fields, true ) ) {
935
+			function($response_fields, $field) use ($fields) {
936
+				if (in_array($field, $fields, true)) {
937 937
 					$response_fields[] = $field;
938 938
 					return $response_fields;
939 939
 				}
940 940
 				// Check for nested fields if $field is not a direct match.
941
-				$nested_fields = explode( '.', $field );
941
+				$nested_fields = explode('.', $field);
942 942
 				// A nested field is included so long as its top-level property is
943 943
 				// present in the schema.
944
-				if ( in_array( $nested_fields[0], $fields, true ) ) {
944
+				if (in_array($nested_fields[0], $fields, true)) {
945 945
 					$response_fields[] = $field;
946 946
 				}
947 947
 				return $response_fields;
@@ -960,8 +960,8 @@  discard block
 block discarded – undo
960 960
 	public function get_item_schema() {
961 961
 
962 962
 		// Maybe retrieve the schema from cache.
963
-		if ( $this->schema ) {
964
-			return $this->add_additional_fields_schema( $this->schema );
963
+		if ($this->schema) {
964
+			return $this->add_additional_fields_schema($this->schema);
965 965
 		}
966 966
 
967 967
 		$schema = array(
@@ -973,136 +973,136 @@  discard block
 block discarded – undo
973 973
 			'properties' 		  => array(
974 974
 
975 975
 				'id'           => array(
976
-					'description' => __( 'Unique identifier for the item.', 'invoicing' ),
976
+					'description' => __('Unique identifier for the item.', 'invoicing'),
977 977
 					'type'        => 'integer',
978
-					'context'     => array( 'view', 'edit', 'embed' ),
978
+					'context'     => array('view', 'edit', 'embed'),
979 979
 					'readonly'    => true,
980 980
 				),
981 981
 
982 982
 				'name'			  => array(
983
-					'description' => __( 'The name for the item.', 'invoicing' ),
983
+					'description' => __('The name for the item.', 'invoicing'),
984 984
 					'type'        => 'string',
985
-					'context'     => array( 'view', 'edit', 'embed' ),
985
+					'context'     => array('view', 'edit', 'embed'),
986 986
 				),
987 987
 
988 988
 				'summary'        => array(
989
-					'description' => __( 'A summary for the item.', 'invoicing' ),
989
+					'description' => __('A summary for the item.', 'invoicing'),
990 990
 					'type'        => 'string',
991
-					'context'     => array( 'view', 'edit', 'embed' ),
991
+					'context'     => array('view', 'edit', 'embed'),
992 992
 				),
993 993
 
994 994
 				'price'        => array(
995
-					'description' => __( 'The price for the item.', 'invoicing' ),
995
+					'description' => __('The price for the item.', 'invoicing'),
996 996
 					'type'        => 'number',
997
-					'context'     => array( 'view', 'edit', 'embed' ),
997
+					'context'     => array('view', 'edit', 'embed'),
998 998
 				),
999 999
 
1000 1000
 				'status'       => array(
1001
-					'description' => __( 'A named status for the item.', 'invoicing' ),
1001
+					'description' => __('A named status for the item.', 'invoicing'),
1002 1002
 					'type'        => 'string',
1003
-					'enum'        => array_keys( get_post_stati( array( 'internal' => false ) ) ),
1004
-					'context'     => array( 'view', 'edit' ),
1003
+					'enum'        => array_keys(get_post_stati(array('internal' => false))),
1004
+					'context'     => array('view', 'edit'),
1005 1005
 				),
1006 1006
 
1007 1007
 				'type'       => array(
1008
-					'description' => __( 'The item type.', 'invoicing' ),
1008
+					'description' => __('The item type.', 'invoicing'),
1009 1009
 					'type'        => 'string',
1010 1010
 					'enum'        => wpinv_item_types(),
1011
-					'context'     => array( 'view', 'edit', 'embed' ),
1011
+					'context'     => array('view', 'edit', 'embed'),
1012 1012
 				),
1013 1013
 
1014 1014
 				'vat_rule'       => array(
1015
-					'description' => __( 'VAT rule applied to the item.', 'invoicing' ),
1015
+					'description' => __('VAT rule applied to the item.', 'invoicing'),
1016 1016
 					'type'        => 'string',
1017
-					'enum'        => array( 'digital', 'physical' ),
1018
-					'context'     => array( 'view', 'edit' ),
1017
+					'enum'        => array('digital', 'physical'),
1018
+					'context'     => array('view', 'edit'),
1019 1019
 				),
1020 1020
 
1021 1021
 				'vat_class'       => array(
1022
-					'description' => __( 'VAT class for the item.', 'invoicing' ),
1022
+					'description' => __('VAT class for the item.', 'invoicing'),
1023 1023
 					'type'        => 'string',
1024
-					'context'     => array( 'view', 'edit' ),
1024
+					'context'     => array('view', 'edit'),
1025 1025
 					'readonly'    => true,
1026 1026
 				),
1027 1027
 
1028 1028
 				'custom_id'       => array(
1029
-					'description' => __( 'Custom id for the item.', 'invoicing' ),
1029
+					'description' => __('Custom id for the item.', 'invoicing'),
1030 1030
 					'type'        => 'string',
1031
-					'context'     => array( 'view', 'edit', 'embed' ),
1031
+					'context'     => array('view', 'edit', 'embed'),
1032 1032
 				),
1033 1033
 				
1034 1034
 				'custom_name'       => array(
1035
-					'description' => __( 'Custom name for the item.', 'invoicing' ),
1035
+					'description' => __('Custom name for the item.', 'invoicing'),
1036 1036
 					'type'        => 'string',
1037
-					'context'     => array( 'view', 'edit', 'embed' ),
1037
+					'context'     => array('view', 'edit', 'embed'),
1038 1038
 				),
1039 1039
 
1040 1040
 				'custom_singular_name'       => array(
1041
-					'description' => __( 'Custom singular name for the item.', 'invoicing' ),
1041
+					'description' => __('Custom singular name for the item.', 'invoicing'),
1042 1042
 					'type'        => 'string',
1043
-					'context'     => array( 'view', 'edit', 'embed' ),
1043
+					'context'     => array('view', 'edit', 'embed'),
1044 1044
 				),
1045 1045
 
1046 1046
 				'dynamic_pricing'        => array(
1047
-					'description' => __( 'Whether the item allows a user to set their own price.', 'invoicing' ),
1047
+					'description' => __('Whether the item allows a user to set their own price.', 'invoicing'),
1048 1048
 					'type'        => 'integer',
1049
-					'context'     => array( 'view', 'edit', 'embed' ),
1049
+					'context'     => array('view', 'edit', 'embed'),
1050 1050
 				),
1051 1051
 
1052 1052
 				'minimum_price'        => array(
1053
-					'description' => __( 'For dynamic prices, this is the minimum price that a user can set.', 'invoicing' ),
1053
+					'description' => __('For dynamic prices, this is the minimum price that a user can set.', 'invoicing'),
1054 1054
 					'type'        => 'number',
1055
-					'context'     => array( 'view', 'edit', 'embed' ),
1055
+					'context'     => array('view', 'edit', 'embed'),
1056 1056
 				),
1057 1057
 
1058 1058
 				'is_recurring'        => array(
1059
-					'description' => __( 'Whether the item is a subscription item.', 'invoicing' ),
1059
+					'description' => __('Whether the item is a subscription item.', 'invoicing'),
1060 1060
 					'type'        => 'integer',
1061
-					'context'     => array( 'view', 'edit', 'embed' ),
1061
+					'context'     => array('view', 'edit', 'embed'),
1062 1062
 				),
1063 1063
 
1064 1064
 				'recurring_period'        => array(
1065
-					'description' => __( 'The recurring period for a recurring item.', 'invoicing' ),
1065
+					'description' => __('The recurring period for a recurring item.', 'invoicing'),
1066 1066
 					'type'        => 'string',
1067
-					'context'     => array( 'view', 'edit', 'embed' ),
1068
-					'enum'        => array( 'D', 'W', 'M', 'Y' ),
1067
+					'context'     => array('view', 'edit', 'embed'),
1068
+					'enum'        => array('D', 'W', 'M', 'Y'),
1069 1069
 				),
1070 1070
 
1071 1071
 				'recurring_interval'        => array(
1072
-					'description' => __( 'The recurring interval for a subscription item.', 'invoicing' ),
1072
+					'description' => __('The recurring interval for a subscription item.', 'invoicing'),
1073 1073
 					'type'        => 'integer',
1074
-					'context'     => array( 'view', 'edit', 'embed' ),
1074
+					'context'     => array('view', 'edit', 'embed'),
1075 1075
 				),
1076 1076
 
1077 1077
 				'recurring_limit'        => array(
1078
-					'description' => __( 'The maximum number of renewals for a subscription item.', 'invoicing' ),
1078
+					'description' => __('The maximum number of renewals for a subscription item.', 'invoicing'),
1079 1079
 					'type'        => 'integer',
1080
-					'context'     => array( 'view', 'edit', 'embed' ),
1080
+					'context'     => array('view', 'edit', 'embed'),
1081 1081
 				),
1082 1082
 
1083 1083
 				'free_trial'        => array(
1084
-					'description' => __( 'Whether the item has a free trial period.', 'invoicing' ),
1084
+					'description' => __('Whether the item has a free trial period.', 'invoicing'),
1085 1085
 					'type'        => 'integer',
1086
-					'context'     => array( 'view', 'edit', 'embed' ),
1086
+					'context'     => array('view', 'edit', 'embed'),
1087 1087
 				),
1088 1088
 
1089 1089
 				'trial_period'        => array(
1090
-					'description' => __( 'The trial period of a recurring item.', 'invoicing' ),
1090
+					'description' => __('The trial period of a recurring item.', 'invoicing'),
1091 1091
 					'type'        => 'string',
1092
-					'context'     => array( 'view', 'edit', 'embed' ),
1093
-					'enum'        => array( 'D', 'W', 'M', 'Y' ),
1092
+					'context'     => array('view', 'edit', 'embed'),
1093
+					'enum'        => array('D', 'W', 'M', 'Y'),
1094 1094
 				),
1095 1095
 
1096 1096
 				'trial_interval'        => array(
1097
-					'description' => __( 'The trial interval for a subscription item.', 'invoicing' ),
1097
+					'description' => __('The trial interval for a subscription item.', 'invoicing'),
1098 1098
 					'type'        => 'integer',
1099
-					'context'     => array( 'view', 'edit', 'embed' ),
1099
+					'context'     => array('view', 'edit', 'embed'),
1100 1100
 				),
1101 1101
 
1102 1102
 				'editable'        => array(
1103
-					'description' => __( 'Whether or not the item is editable.', 'invoicing' ),
1103
+					'description' => __('Whether or not the item is editable.', 'invoicing'),
1104 1104
 					'type'        => 'integer',
1105
-					'context'     => array( 'view', 'edit' ),
1105
+					'context'     => array('view', 'edit'),
1106 1106
 				),
1107 1107
 
1108 1108
 			),
@@ -1120,12 +1120,12 @@  discard block
 block discarded – undo
1120 1120
 		 *
1121 1121
 		 * @param array   $schema    The item schema.
1122 1122
 		 */
1123
-        $schema = apply_filters( "wpinv_rest_item_schema", $schema );
1123
+        $schema = apply_filters("wpinv_rest_item_schema", $schema);
1124 1124
 
1125 1125
 		//  Cache the item schema.
1126 1126
 		$this->schema = $schema;
1127 1127
 		
1128
-		return $this->add_additional_fields_schema( $this->schema );
1128
+		return $this->add_additional_fields_schema($this->schema);
1129 1129
 	}
1130 1130
 
1131 1131
 	/**
@@ -1137,20 +1137,20 @@  discard block
 block discarded – undo
1137 1137
 	 */
1138 1138
 	protected function get_schema_links() {
1139 1139
 
1140
-		$href = rest_url( "{$this->namespace}/{$this->rest_base}/{id}" );
1140
+		$href = rest_url("{$this->namespace}/{$this->rest_base}/{id}");
1141 1141
 
1142 1142
 		$links = array();
1143 1143
 
1144 1144
 		$links[] = array(
1145 1145
 			'rel'          => 'https://api.w.org/action-publish',
1146
-			'title'        => __( 'The current user can publish this item.' ),
1146
+			'title'        => __('The current user can publish this item.'),
1147 1147
 			'href'         => $href,
1148 1148
 			'targetSchema' => array(
1149 1149
 				'type'       => 'object',
1150 1150
 				'properties' => array(
1151 1151
 					'status' => array(
1152 1152
 						'type' => 'string',
1153
-						'enum' => array( 'publish', 'future' ),
1153
+						'enum' => array('publish', 'future'),
1154 1154
 					),
1155 1155
 				),
1156 1156
 			),
@@ -1167,18 +1167,18 @@  discard block
 block discarded – undo
1167 1167
 	 * @param WPInv_Item $item Item Object.
1168 1168
 	 * @return array Links for the given item.
1169 1169
 	 */
1170
-	protected function prepare_links( $item ) {
1170
+	protected function prepare_links($item) {
1171 1171
 
1172 1172
 		// Prepare the base REST API endpoint for items.
1173
-		$base = sprintf( '%s/%s', $this->namespace, $this->rest_base );
1173
+		$base = sprintf('%s/%s', $this->namespace, $this->rest_base);
1174 1174
 
1175 1175
 		// Entity meta.
1176 1176
 		$links = array(
1177 1177
 			'self'       => array(
1178
-				'href' => rest_url( trailingslashit( $base ) . $item->ID ),
1178
+				'href' => rest_url(trailingslashit($base) . $item->ID),
1179 1179
 			),
1180 1180
 			'collection' => array(
1181
-				'href' => rest_url( $base ),
1181
+				'href' => rest_url($base),
1182 1182
 			),
1183 1183
 		);
1184 1184
 
@@ -1191,7 +1191,7 @@  discard block
 block discarded – undo
1191 1191
 		 *
1192 1192
 		 * @param array   $links    Rest links.
1193 1193
 		 */
1194
-		return apply_filters( "wpinv_rest_item_links", $links );
1194
+		return apply_filters("wpinv_rest_item_links", $links);
1195 1195
 
1196 1196
 	}
1197 1197
 
@@ -1204,19 +1204,19 @@  discard block
 block discarded – undo
1204 1204
 	 * @param WP_REST_Request $request Request object.
1205 1205
 	 * @return array List of link relations.
1206 1206
 	 */
1207
-	protected function get_available_actions( $item, $request ) {
1207
+	protected function get_available_actions($item, $request) {
1208 1208
 
1209
-		if ( 'edit' !== $request['context'] ) {
1209
+		if ('edit' !== $request['context']) {
1210 1210
 			return array();
1211 1211
 		}
1212 1212
 
1213 1213
 		$rels = array();
1214 1214
 
1215 1215
 		// Retrieve the post type object.
1216
-		$post_type = get_post_type_object( $item->post_type );
1216
+		$post_type = get_post_type_object($item->post_type);
1217 1217
 
1218 1218
 		// Mark item as published.
1219
-		if ( current_user_can( $post_type->cap->publish_posts ) ) {
1219
+		if (current_user_can($post_type->cap->publish_posts)) {
1220 1220
 			$rels[] = 'https://api.w.org/action-publish';
1221 1221
 		}
1222 1222
 
@@ -1229,7 +1229,7 @@  discard block
 block discarded – undo
1229 1229
 		 *
1230 1230
 		 * @param array   $rels    Available link relations.
1231 1231
 		 */
1232
-		return apply_filters( "wpinv_rest_item_link_relations", $rels );
1232
+		return apply_filters("wpinv_rest_item_link_relations", $rels);
1233 1233
 	}
1234 1234
 
1235 1235
 	/**
@@ -1241,7 +1241,7 @@  discard block
 block discarded – undo
1241 1241
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
1242 1242
 	 */
1243 1243
 	public function get_item_types() {
1244
-		return rest_ensure_response( wpinv_get_item_types() );
1244
+		return rest_ensure_response(wpinv_get_item_types());
1245 1245
 	}
1246 1246
 
1247 1247
     
Please login to merge, or discard this patch.