Passed
Push — master ( 0a2cdb...97ebee )
by Brian
04:41
created
includes/class-wpinv-privacy-exporters.php 1 patch
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Personal data exporters.
4 4
  */
5 5
 
6
-defined( 'ABSPATH' ) || exit;
6
+defined('ABSPATH') || exit;
7 7
 
8 8
 /**
9 9
  * WPInv_Privacy_Exporters Class.
@@ -17,39 +17,39 @@  discard block
 block discarded – undo
17 17
      * @param int    $page  Page.
18 18
      * @return array An array of invoice data in name value pairs
19 19
      */
20
-    public static function customer_invoice_data_exporter( $email_address, $page ) {
20
+    public static function customer_invoice_data_exporter($email_address, $page) {
21 21
         $done           = false;
22 22
         $page           = (int) $page;
23 23
         $data_to_export = array();
24 24
 
25
-        $user           = get_user_by( 'email', $email_address );
26
-        if ( ! $user instanceof WP_User ) {
25
+        $user           = get_user_by('email', $email_address);
26
+        if (!$user instanceof WP_User) {
27 27
             return array(
28 28
                 'data' => $data_to_export,
29 29
                 'done' => true,
30 30
             );
31 31
         }
32 32
 
33
-        $args    = array(
34
-            'limit'    => get_option( 'posts_per_page' ),
33
+        $args = array(
34
+            'limit'    => get_option('posts_per_page'),
35 35
             'page'     => $page,
36 36
             'user'     => $user->ID,
37 37
             'paginate' => false,
38 38
         );
39 39
 
40
-        $invoices = wpinv_get_invoices( $args );
40
+        $invoices = wpinv_get_invoices($args);
41 41
 
42
-        if ( 0 < count( $invoices ) ) {
43
-            foreach ( $invoices as $invoice ) {
42
+        if (0 < count($invoices)) {
43
+            foreach ($invoices as $invoice) {
44 44
                 $data_to_export[] = array(
45 45
                     'group_id'          => 'customer_invoices',
46
-                    'group_label'       => __( 'GetPaid: Invoices', 'invoicing' ),
47
-                    'group_description' => __( 'Customer invoices.', 'invoicing' ),
46
+                    'group_label'       => __('GetPaid: Invoices', 'invoicing'),
47
+                    'group_description' => __('Customer invoices.', 'invoicing'),
48 48
                     'item_id'           => "wpinv-{$invoice->get_id()}",
49
-                    'data'              => self::get_customer_invoice_data( $invoice ),
49
+                    'data'              => self::get_customer_invoice_data($invoice),
50 50
                 );
51 51
             }
52
-            $done = get_option( 'posts_per_page' ) > count( $invoices );
52
+            $done = get_option('posts_per_page') > count($invoices);
53 53
         } else {
54 54
             $done = true;
55 55
         }
@@ -67,116 +67,116 @@  discard block
 block discarded – undo
67 67
      * @param WPInv_Invoice $invoice invoice object.
68 68
      * @return array
69 69
      */
70
-    public static function get_customer_invoice_data( $invoice ) {
70
+    public static function get_customer_invoice_data($invoice) {
71 71
 
72 72
         // Prepare basic properties.
73 73
         $props_to_export = array(
74 74
             'number'       => array(
75
-                'name'  => __( 'Invoice Number', 'invoicing' ),
75
+                'name'  => __('Invoice Number', 'invoicing'),
76 76
                 'value' => $invoice->get_number(),
77 77
             ),
78 78
             'created_date' => array(
79
-                'name'  => __( 'Created Date', 'invoicing' ),
79
+                'name'  => __('Created Date', 'invoicing'),
80 80
                 'value' => $invoice->get_date_created(),
81 81
             ),
82 82
             'due_date'     => array(
83
-                'name'  => __( 'Due Date', 'invoicing' ),
83
+                'name'  => __('Due Date', 'invoicing'),
84 84
                 'value' => $invoice->get_due_date(),
85 85
             ),
86 86
             'items'        => array(
87
-                'name'  => __( 'Invoice Items', 'invoicing' ),
88
-                'value' => self::process_invoice_items( $invoice ),
87
+                'name'  => __('Invoice Items', 'invoicing'),
88
+                'value' => self::process_invoice_items($invoice),
89 89
             ),
90 90
             'discount'     => array(
91
-                'name'  => __( 'Invoice Discount', 'invoicing' ),
92
-                'value' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ),
91
+                'name'  => __('Invoice Discount', 'invoicing'),
92
+                'value' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()),
93 93
             ),
94 94
             'total'        => array(
95
-                'name'  => __( 'Invoice Total', 'invoicing' ),
96
-                'value' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ),
95
+                'name'  => __('Invoice Total', 'invoicing'),
96
+                'value' => wpinv_price($invoice->get_total(), $invoice->get_currency()),
97 97
             ),
98 98
             'status'       => array(
99
-                'name'  => __( 'Invoice Status', 'invoicing' ),
99
+                'name'  => __('Invoice Status', 'invoicing'),
100 100
                 'value' => $invoice->get_status_nicename(),
101 101
             ),
102 102
             'first_name'   => array(
103
-                'name'  => __( 'First Name', 'invoicing' ),
103
+                'name'  => __('First Name', 'invoicing'),
104 104
                 'value' => $invoice->get_first_name(),
105 105
             ),
106 106
             'last_name'    => array(
107
-                'name'  => __( 'Last Name', 'invoicing' ),
107
+                'name'  => __('Last Name', 'invoicing'),
108 108
                 'value' => $invoice->get_last_name(),
109 109
             ),
110 110
             'email'        => array(
111
-                'name'  => __( 'Email Address', 'invoicing' ),
111
+                'name'  => __('Email Address', 'invoicing'),
112 112
                 'value' => $invoice->get_email(),
113 113
             ),
114 114
             'company'      => array(
115
-                'name'  => __( 'Company', 'invoicing' ),
115
+                'name'  => __('Company', 'invoicing'),
116 116
                 'value' => $invoice->get_company(),
117 117
             ),
118 118
             'phone'        => array(
119
-                'name'  => __( 'Phone Number', 'invoicing' ),
119
+                'name'  => __('Phone Number', 'invoicing'),
120 120
                 'value' => $invoice->get_phone(),
121 121
             ),
122 122
             'address'      => array(
123
-                'name'  => __( 'Address', 'invoicing' ),
123
+                'name'  => __('Address', 'invoicing'),
124 124
                 'value' => $invoice->get_address(),
125 125
             ),
126 126
             'city'         => array(
127
-                'name'  => __( 'City', 'invoicing' ),
127
+                'name'  => __('City', 'invoicing'),
128 128
                 'value' => $invoice->get_city(),
129 129
             ),
130 130
             'state'        => array(
131
-                'name'  => __( 'State', 'invoicing' ),
131
+                'name'  => __('State', 'invoicing'),
132 132
                 'value' => $invoice->get_state(),
133 133
             ),
134 134
             'zip'          => array(
135
-                'name'  => __( 'Zip', 'invoicing' ),
135
+                'name'  => __('Zip', 'invoicing'),
136 136
                 'value' => $invoice->get_zip(),
137 137
             ),
138 138
             'vat_number'   => array(
139
-                'name'  => __( 'VAT Number', 'invoicing' ),
139
+                'name'  => __('VAT Number', 'invoicing'),
140 140
                 'value' => $invoice->get_vat_number(),
141 141
             ),
142 142
             'description'  => array(
143
-                'name'  => __( 'Description', 'invoicing' ),
143
+                'name'  => __('Description', 'invoicing'),
144 144
                 'value' => $invoice->get_description(),
145 145
             ),
146 146
         );
147 147
 
148 148
         // In case the invoice is paid, add the payment date and gateway.
149
-        if ( $invoice->is_paid() ) {
149
+        if ($invoice->is_paid()) {
150 150
 
151 151
             $props_to_export['completed_date'] = array(
152
-                'name'  => __( 'Completed Date', 'invoicing' ),
152
+                'name'  => __('Completed Date', 'invoicing'),
153 153
                 'value' => $invoice->get_completed_date(),
154 154
             );
155 155
 
156 156
             $props_to_export['gateway'] = array(
157
-                'name'  => __( 'Paid Via', 'invoicing' ),
157
+                'name'  => __('Paid Via', 'invoicing'),
158 158
                 'value' => $invoice->get_gateway(),
159 159
             );
160 160
 
161 161
         }
162 162
 
163 163
         // Maybe add subscription details.
164
-        $props_to_export = self::process_subscription( $invoice, $props_to_export );
164
+        $props_to_export = self::process_subscription($invoice, $props_to_export);
165 165
 
166 166
         // Add the ip address.
167 167
         $props_to_export['ip'] = array(
168
-            'name'  => __( 'IP Address', 'invoicing' ),
168
+            'name'  => __('IP Address', 'invoicing'),
169 169
             'value' => $invoice->get_ip(),
170 170
         );
171 171
 
172 172
         // Add the invoice url.
173 173
         $props_to_export['view_url'] = array(
174
-            'name'  => __( 'Invoice URL', 'invoicing' ),
174
+            'name'  => __('Invoice URL', 'invoicing'),
175 175
             'value' => $invoice->get_view_url(),
176 176
         );
177 177
 
178 178
         // Return the values.
179
-        return apply_filters( 'getpaid_privacy_export_invoice_personal_data', array_values( $props_to_export ), $invoice );
179
+        return apply_filters('getpaid_privacy_export_invoice_personal_data', array_values($props_to_export), $invoice);
180 180
 
181 181
     }
182 182
 
@@ -188,40 +188,40 @@  discard block
 block discarded – undo
188 188
      * @param array $props invoice props.
189 189
      * @return array
190 190
      */
191
-    public static function process_subscription( $invoice, $props ) {
191
+    public static function process_subscription($invoice, $props) {
192 192
 
193
-        $subscription = wpinv_get_subscription( $invoice );
194
-        if ( ! empty( $subscription ) ) {
193
+        $subscription = wpinv_get_subscription($invoice);
194
+        if (!empty($subscription)) {
195 195
 
196
-            $frequency    = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency() );
197
-            $period       = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ) . ' / ' . $frequency;
198
-            $initial_amt  = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
199
-            $bill_times   = $subscription->get_times_billed() . ' / ' . ( ( $subscription->get_bill_times() == 0 ) ? __( 'Until Cancelled', 'invoicing' ) : $subscription->get_bill_times() );
200
-            $renewal_date = getpaid_format_date_value( $subscription->get_expiration() );
196
+            $frequency    = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency());
197
+            $period       = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency()) . ' / ' . $frequency;
198
+            $initial_amt  = wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency());
199
+            $bill_times   = $subscription->get_times_billed() . ' / ' . (($subscription->get_bill_times() == 0) ? __('Until Cancelled', 'invoicing') : $subscription->get_bill_times());
200
+            $renewal_date = getpaid_format_date_value($subscription->get_expiration());
201 201
 
202 202
             // Billing cycle.
203 203
             $props['period'] = array(
204
-                'name'  => __( 'Billing Cycle', 'invoicing' ),
204
+                'name'  => __('Billing Cycle', 'invoicing'),
205 205
                 'value' => $period,
206 206
             );
207 207
 
208 208
             // Initial amount.
209 209
             $props['initial_amount'] = array(
210
-                'name'  => __( 'Initial Amount', 'invoicing' ),
210
+                'name'  => __('Initial Amount', 'invoicing'),
211 211
                 'value' => $initial_amt,
212 212
             );
213 213
 
214 214
             // Bill times.
215 215
             $props['bill_times'] = array(
216
-                'name'  => __( 'Times Billed', 'invoicing' ),
216
+                'name'  => __('Times Billed', 'invoicing'),
217 217
                 'value' => $bill_times,
218 218
             );
219 219
 
220 220
             // Add expiry date.
221
-            if ( $subscription->is_active() ) {
221
+            if ($subscription->is_active()) {
222 222
 
223 223
                 $props['renewal_date'] = array(
224
-                    'name'  => __( 'Expires', 'invoicing' ),
224
+                    'name'  => __('Expires', 'invoicing'),
225 225
                     'value' => $renewal_date,
226 226
                 );
227 227
 
@@ -239,19 +239,19 @@  discard block
 block discarded – undo
239 239
      * @param WPInv_Invoice $invoice invoice object.
240 240
      * @return array
241 241
      */
242
-    public static function process_invoice_items( $invoice ) {
242
+    public static function process_invoice_items($invoice) {
243 243
 
244 244
         $item_names = array();
245
-        foreach ( $invoice->get_items() as $cart_item ) {
245
+        foreach ($invoice->get_items() as $cart_item) {
246 246
             $item_names[] = sprintf(
247 247
                 '%s x %s - %s',
248 248
                 $cart_item->get_name(),
249 249
                 $cart_item->get_quantity(),
250
-                wpinv_price( $invoice->is_renewal() ? $cart_item->get_recurring_sub_total() : $cart_item->get_sub_total(), $invoice->get_currency() )
250
+                wpinv_price($invoice->is_renewal() ? $cart_item->get_recurring_sub_total() : $cart_item->get_sub_total(), $invoice->get_currency())
251 251
             );
252 252
         }
253 253
 
254
-        return implode( ', ', $item_names );
254
+        return implode(', ', $item_names);
255 255
 
256 256
     }
257 257
 
Please login to merge, or discard this patch.
includes/wpinv-discount-functions.php 2 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -160,50 +160,50 @@
 block discarded – undo
160 160
  */
161 161
 function getpaid_calculate_invoice_discount( $invoice, $discount ) {
162 162
 
163
-	$initial_discount   = 0;
164
-	$recurring_discount = 0;
163
+    $initial_discount   = 0;
164
+    $recurring_discount = 0;
165 165
 
166
-	foreach ( $invoice->get_items() as $item ) {
166
+    foreach ( $invoice->get_items() as $item ) {
167 167
 
168
-		// Abort if it is not valid for this item.
169
-		if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) {
170
-			continue;
171
-		}
168
+        // Abort if it is not valid for this item.
169
+        if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) {
170
+            continue;
171
+        }
172 172
 
173
-		// Calculate the initial amount...
174
-		$item_discount           = $discount->get_discounted_amount( $item->get_sub_total() );
175
-		$recurring_item_discount = 0;
173
+        // Calculate the initial amount...
174
+        $item_discount           = $discount->get_discounted_amount( $item->get_sub_total() );
175
+        $recurring_item_discount = 0;
176 176
 
177
-		// ... and maybe the recurring amount.
178
-		if ( $item->is_recurring() && $discount->is_recurring() ) {
179
-			$recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() );
180
-		}
177
+        // ... and maybe the recurring amount.
178
+        if ( $item->is_recurring() && $discount->is_recurring() ) {
179
+            $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() );
180
+        }
181 181
 
182
-		// Discount should not exceed discounted amount.
183
-		if ( ! $discount->is_type( 'percent' ) ) {
182
+        // Discount should not exceed discounted amount.
183
+        if ( ! $discount->is_type( 'percent' ) ) {
184 184
 
185
-			if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) {
186
-				$item_discount = $discount->get_amount() - $initial_discount;
187
-			}
185
+            if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) {
186
+                $item_discount = $discount->get_amount() - $initial_discount;
187
+            }
188 188
 
189
-			if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) {
190
-				$recurring_item_discount = $discount->get_amount() - $recurring_discount;
191
-			}
189
+            if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) {
190
+                $recurring_item_discount = $discount->get_amount() - $recurring_discount;
191
+            }
192 192
 }
193 193
 
194
-		$initial_discount             += $item_discount;
195
-		$recurring_discount           += $recurring_item_discount;
196
-		$item->item_discount           = $item_discount;
197
-		$item->recurring_item_discount = $recurring_item_discount;
194
+        $initial_discount             += $item_discount;
195
+        $recurring_discount           += $recurring_item_discount;
196
+        $item->item_discount           = $item_discount;
197
+        $item->recurring_item_discount = $recurring_item_discount;
198 198
 
199
-	}
199
+    }
200 200
 
201
-	return array(
202
-		'name'               => 'discount_code',
203
-		'discount_code'      => $discount->get_code(),
204
-		'initial_discount'   => $initial_discount,
205
-		'recurring_discount' => $recurring_discount,
206
-	);
201
+    return array(
202
+        'name'               => 'discount_code',
203
+        'discount_code'      => $discount->get_code(),
204
+        'initial_discount'   => $initial_discount,
205
+        'recurring_discount' => $recurring_discount,
206
+    );
207 207
 
208 208
 }
209 209
 
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Returns an array of discount type.
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
     return apply_filters(
18 18
         'wpinv_discount_types',
19 19
         array(
20
-            'percent' => __( 'Percentage', 'invoicing' ),
21
-            'flat'    => __( 'Flat Amount', 'invoicing' ),
20
+            'percent' => __('Percentage', 'invoicing'),
21
+            'flat'    => __('Flat Amount', 'invoicing'),
22 22
         )
23 23
     );
24 24
 }
@@ -28,46 +28,46 @@  discard block
 block discarded – undo
28 28
  *
29 29
  * @return string
30 30
  */
31
-function wpinv_get_discount_type_name( $type = '' ) {
31
+function wpinv_get_discount_type_name($type = '') {
32 32
     $types = wpinv_get_discount_types();
33
-    return isset( $types[ $type ] ) ? $types[ $type ] : $type;
33
+    return isset($types[$type]) ? $types[$type] : $type;
34 34
 }
35 35
 
36 36
 /**
37 37
  * Deletes a discount via the admin page.
38 38
  *
39 39
  */
40
-function wpinv_delete_discount( $data ) {
40
+function wpinv_delete_discount($data) {
41 41
 
42
-    $discount = new WPInv_Discount( absint( $data['discount'] ) );
43
-    $discount->delete( true );
42
+    $discount = new WPInv_Discount(absint($data['discount']));
43
+    $discount->delete(true);
44 44
 
45 45
 }
46
-add_action( 'getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount' );
46
+add_action('getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount');
47 47
 
48 48
 /**
49 49
  * Deactivates a discount via the admin page.
50 50
  */
51
-function wpinv_activate_discount( $data ) {
51
+function wpinv_activate_discount($data) {
52 52
 
53
-    $discount = new WPInv_Discount( absint( $data['discount'] ) );
54
-    $discount->set_status( 'publish' );
53
+    $discount = new WPInv_Discount(absint($data['discount']));
54
+    $discount->set_status('publish');
55 55
     $discount->save();
56 56
 
57 57
 }
58
-add_action( 'getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount' );
58
+add_action('getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount');
59 59
 
60 60
 /**
61 61
  * Activates a discount via the admin page.
62 62
  */
63
-function wpinv_deactivate_discount( $data ) {
63
+function wpinv_deactivate_discount($data) {
64 64
 
65
-    $discount = new WPInv_Discount( absint( $data['discount'] ) );
66
-    $discount->set_status( 'pending' );
65
+    $discount = new WPInv_Discount(absint($data['discount']));
66
+    $discount->set_status('pending');
67 67
     $discount->save();
68 68
 
69 69
 }
70
-add_action( 'getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount' );
70
+add_action('getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount');
71 71
 
72 72
 /**
73 73
  * Fetches a discount object.
@@ -76,8 +76,8 @@  discard block
 block discarded – undo
76 76
  * @since 1.0.15
77 77
  * @return WPInv_Discount
78 78
  */
79
-function wpinv_get_discount( $discount ) {
80
-    return new WPInv_Discount( $discount );
79
+function wpinv_get_discount($discount) {
80
+    return new WPInv_Discount($discount);
81 81
 }
82 82
 
83 83
 /**
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
  * @since 1.0.15
88 88
  * @return WPInv_Discount
89 89
  */
90
-function wpinv_get_discount_obj( $discount = 0 ) {
91
-    return new WPInv_Discount( $discount );
90
+function wpinv_get_discount_obj($discount = 0) {
91
+    return new WPInv_Discount($discount);
92 92
 }
93 93
 
94 94
 /**
@@ -98,10 +98,10 @@  discard block
 block discarded – undo
98 98
  * @param string|int $value The field value
99 99
  * @return bool|WPInv_Discount
100 100
  */
101
-function wpinv_get_discount_by( $deprecated = null, $value = '' ) {
102
-    $discount = new WPInv_Discount( $value );
101
+function wpinv_get_discount_by($deprecated = null, $value = '') {
102
+    $discount = new WPInv_Discount($value);
103 103
 
104
-    if ( $discount->get_id() != 0 ) {
104
+    if ($discount->get_id() != 0) {
105 105
         return $discount;
106 106
     }
107 107
 
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
 function wpinv_get_discount_statuses() {
117 117
 
118 118
     return array(
119
-        'expired'  => __( 'Expired', 'invoicing' ),
120
-        'publish'  => __( 'Active', 'invoicing' ),
121
-        'inactive' => __( 'Inactive', 'invoicing' ),
119
+        'expired'  => __('Expired', 'invoicing'),
120
+        'publish'  => __('Active', 'invoicing'),
121
+        'inactive' => __('Inactive', 'invoicing'),
122 122
     );
123 123
 
124 124
 }
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
 /**
127 127
  * Retrieves an invoice status label.
128 128
  */
129
-function wpinv_discount_status( $status ) {
129
+function wpinv_discount_status($status) {
130 130
     $statuses = wpinv_get_discount_statuses();
131
-    return isset( $statuses[ $status ] ) ? $statuses[ $status ] : __( 'Inactive', 'invoicing' );
131
+    return isset($statuses[$status]) ? $statuses[$status] : __('Inactive', 'invoicing');
132 132
 }
133 133
 
134 134
 /**
@@ -138,12 +138,12 @@  discard block
 block discarded – undo
138 138
  * @param int|array|string|WPInv_Discount $code discount data, object, ID or code.
139 139
  * @return bool
140 140
  */
141
-function wpinv_discount_is_recurring( $discount = 0, $code = 0 ) {
141
+function wpinv_discount_is_recurring($discount = 0, $code = 0) {
142 142
 
143
-    if ( ! empty( $discount ) ) {
144
-        $discount    = wpinv_get_discount_obj( $discount );
143
+    if (!empty($discount)) {
144
+        $discount    = wpinv_get_discount_obj($discount);
145 145
     } else {
146
-        $discount    = wpinv_get_discount_obj( $code );
146
+        $discount    = wpinv_get_discount_obj($code);
147 147
     }
148 148
 
149 149
     return $discount->get_is_recurring();
@@ -158,35 +158,35 @@  discard block
 block discarded – undo
158 158
  * @param WPInv_Discount $discount
159 159
  * @return array
160 160
  */
161
-function getpaid_calculate_invoice_discount( $invoice, $discount ) {
161
+function getpaid_calculate_invoice_discount($invoice, $discount) {
162 162
 
163 163
 	$initial_discount   = 0;
164 164
 	$recurring_discount = 0;
165 165
 
166
-	foreach ( $invoice->get_items() as $item ) {
166
+	foreach ($invoice->get_items() as $item) {
167 167
 
168 168
 		// Abort if it is not valid for this item.
169
-		if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) {
169
+		if (!$discount->is_valid_for_items(array($item->get_id()))) {
170 170
 			continue;
171 171
 		}
172 172
 
173 173
 		// Calculate the initial amount...
174
-		$item_discount           = $discount->get_discounted_amount( $item->get_sub_total() );
174
+		$item_discount           = $discount->get_discounted_amount($item->get_sub_total());
175 175
 		$recurring_item_discount = 0;
176 176
 
177 177
 		// ... and maybe the recurring amount.
178
-		if ( $item->is_recurring() && $discount->is_recurring() ) {
179
-			$recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() );
178
+		if ($item->is_recurring() && $discount->is_recurring()) {
179
+			$recurring_item_discount = $discount->get_discounted_amount($item->get_recurring_sub_total());
180 180
 		}
181 181
 
182 182
 		// Discount should not exceed discounted amount.
183
-		if ( ! $discount->is_type( 'percent' ) ) {
183
+		if (!$discount->is_type('percent')) {
184 184
 
185
-			if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) {
185
+			if (($initial_discount + $item_discount) > $discount->get_amount()) {
186 186
 				$item_discount = $discount->get_amount() - $initial_discount;
187 187
 			}
188 188
 
189
-			if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) {
189
+			if (($recurring_discount + $recurring_item_discount) > $discount->get_amount()) {
190 190
 				$recurring_item_discount = $discount->get_amount() - $recurring_discount;
191 191
 			}
192 192
 }
@@ -218,10 +218,10 @@  discard block
 block discarded – undo
218 218
         array(
219 219
             'post_type'   => 'wpi_discount',
220 220
             'numberposts' => 1,
221
-            'fields'      => array( 'ids' ),
221
+            'fields'      => array('ids'),
222 222
         )
223 223
     );
224 224
 
225
-    return ! empty( $discounts );
225
+    return !empty($discounts);
226 226
 
227 227
 }
Please login to merge, or discard this patch.
includes/wpinv-subscription.php 2 patches
Indentation   +1023 added lines, -1023 removed lines patch added patch discarded remove patch
@@ -15,125 +15,125 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class WPInv_Subscription extends GetPaid_Data {
17 17
 
18
-	/**
19
-	 * Which data store to load.
20
-	 *
21
-	 * @var string
22
-	 */
23
-	protected $data_store_name = 'subscription';
24
-
25
-	/**
26
-	 * This is the name of this object type.
27
-	 *
28
-	 * @var string
29
-	 */
30
-	protected $object_type = 'subscription';
31
-
32
-	/**
33
-	 * Item Data array. This is the core item data exposed in APIs.
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array(
39
-		'customer_id'       => 0,
40
-		'frequency'         => 1,
41
-		'period'            => 'D',
42
-		'initial_amount'    => null,
43
-		'recurring_amount'  => null,
44
-		'bill_times'        => 0,
45
-		'transaction_id'    => '',
46
-		'parent_payment_id' => null,
47
-		'product_id'        => 0,
48
-		'created'           => '0000-00-00 00:00:00',
49
-		'expiration'        => '0000-00-00 00:00:00',
50
-		'trial_period'      => '',
51
-		'status'            => 'pending',
52
-		'profile_id'        => '',
53
-		'gateway'           => '',
54
-		'customer'          => '',
55
-	);
56
-
57
-	/**
58
-	 * Stores the status transition information.
59
-	 *
60
-	 * @since 1.0.19
61
-	 * @var bool
62
-	 */
63
-	protected $status_transition = false;
64
-
65
-	/**
66
-	 * Get the subscription if ID is passed, otherwise the subscription is new and empty.
67
-	 *
68
-	 * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69
-	 * @param  bool $deprecated
70
-	 */
71
-	function __construct( $subscription = 0, $deprecated = false ) {
72
-
73
-		parent::__construct( $subscription );
74
-
75
-		if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
-			$this->set_id( $subscription );
77
-		} elseif ( $subscription instanceof self ) {
78
-			$this->set_id( $subscription->get_id() );
79
-		} elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
80
-			$this->set_id( $subscription_id );
81
-		} elseif ( ! empty( $subscription->id ) ) {
82
-			$this->set_id( $subscription->id );
83
-		} else {
84
-			$this->set_object_read( true );
85
-		}
86
-
87
-		// Load the datastore.
88
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
89
-
90
-		if ( $this->get_id() > 0 ) {
91
-			$this->data_store->read( $this );
92
-		}
93
-
94
-	}
95
-
96
-	/**
97
-	 * Given an invoice id, profile id, transaction id, it returns the subscription's id.
98
-	 *
99
-	 *
100
-	 * @static
101
-	 * @param string $value
102
-	 * @param string $field Either invoice_id, transaction_id or profile_id.
103
-	 * @since 1.0.19
104
-	 * @return int
105
-	 */
106
-	public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
18
+    /**
19
+     * Which data store to load.
20
+     *
21
+     * @var string
22
+     */
23
+    protected $data_store_name = 'subscription';
24
+
25
+    /**
26
+     * This is the name of this object type.
27
+     *
28
+     * @var string
29
+     */
30
+    protected $object_type = 'subscription';
31
+
32
+    /**
33
+     * Item Data array. This is the core item data exposed in APIs.
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array(
39
+        'customer_id'       => 0,
40
+        'frequency'         => 1,
41
+        'period'            => 'D',
42
+        'initial_amount'    => null,
43
+        'recurring_amount'  => null,
44
+        'bill_times'        => 0,
45
+        'transaction_id'    => '',
46
+        'parent_payment_id' => null,
47
+        'product_id'        => 0,
48
+        'created'           => '0000-00-00 00:00:00',
49
+        'expiration'        => '0000-00-00 00:00:00',
50
+        'trial_period'      => '',
51
+        'status'            => 'pending',
52
+        'profile_id'        => '',
53
+        'gateway'           => '',
54
+        'customer'          => '',
55
+    );
56
+
57
+    /**
58
+     * Stores the status transition information.
59
+     *
60
+     * @since 1.0.19
61
+     * @var bool
62
+     */
63
+    protected $status_transition = false;
64
+
65
+    /**
66
+     * Get the subscription if ID is passed, otherwise the subscription is new and empty.
67
+     *
68
+     * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69
+     * @param  bool $deprecated
70
+     */
71
+    function __construct( $subscription = 0, $deprecated = false ) {
72
+
73
+        parent::__construct( $subscription );
74
+
75
+        if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
+            $this->set_id( $subscription );
77
+        } elseif ( $subscription instanceof self ) {
78
+            $this->set_id( $subscription->get_id() );
79
+        } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
80
+            $this->set_id( $subscription_id );
81
+        } elseif ( ! empty( $subscription->id ) ) {
82
+            $this->set_id( $subscription->id );
83
+        } else {
84
+            $this->set_object_read( true );
85
+        }
86
+
87
+        // Load the datastore.
88
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
89
+
90
+        if ( $this->get_id() > 0 ) {
91
+            $this->data_store->read( $this );
92
+        }
93
+
94
+    }
95
+
96
+    /**
97
+     * Given an invoice id, profile id, transaction id, it returns the subscription's id.
98
+     *
99
+     *
100
+     * @static
101
+     * @param string $value
102
+     * @param string $field Either invoice_id, transaction_id or profile_id.
103
+     * @since 1.0.19
104
+     * @return int
105
+     */
106
+    public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
107 107
         global $wpdb;
108 108
 
109
-		// Trim the value.
110
-		$value = trim( $value );
109
+        // Trim the value.
110
+        $value = trim( $value );
111 111
 
112
-		if ( empty( $value ) ) {
113
-			return 0;
114
-		}
112
+        if ( empty( $value ) ) {
113
+            return 0;
114
+        }
115 115
 
116
-		if ( 'invoice_id' == $field ) {
117
-			$field = 'parent_payment_id';
118
-		}
116
+        if ( 'invoice_id' == $field ) {
117
+            $field = 'parent_payment_id';
118
+        }
119 119
 
120 120
         // Valid fields.
121 121
         $fields = array(
122
-			'parent_payment_id',
123
-			'transaction_id',
124
-			'profile_id',
125
-		);
126
-
127
-		// Ensure a field has been passed.
128
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
129
-			return 0;
130
-		}
131
-
132
-		// Maybe retrieve from the cache.
133
-		$subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
-		if ( ! empty( $subscription_id ) ) {
135
-			return $subscription_id;
136
-		}
122
+            'parent_payment_id',
123
+            'transaction_id',
124
+            'profile_id',
125
+        );
126
+
127
+        // Ensure a field has been passed.
128
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
129
+            return 0;
130
+        }
131
+
132
+        // Maybe retrieve from the cache.
133
+        $subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
+        if ( ! empty( $subscription_id ) ) {
135
+            return $subscription_id;
136
+        }
137 137
 
138 138
         // Fetch from the db.
139 139
         $table            = $wpdb->prefix . 'wpinv_subscriptions';
@@ -141,34 +141,34 @@  discard block
 block discarded – undo
141 141
             $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
142 142
         );
143 143
 
144
-		if ( empty( $subscription_id ) ) {
145
-			return 0;
146
-		}
144
+        if ( empty( $subscription_id ) ) {
145
+            return 0;
146
+        }
147 147
 
148
-		// Update the cache with our data.
149
-		wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
148
+        // Update the cache with our data.
149
+        wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
150 150
 
151
-		return $subscription_id;
152
-	}
151
+        return $subscription_id;
152
+    }
153 153
 
154
-	/**
154
+    /**
155 155
      * Clears the subscription's cache.
156 156
      */
157 157
     public function clear_cache() {
158
-		wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
159
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
160
-		wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
161
-		wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
162
-	}
158
+        wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
159
+        wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
160
+        wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
161
+        wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
162
+    }
163 163
 
164
-	/**
164
+    /**
165 165
      * Checks if a subscription key is set.
166 166
      */
167 167
     public function _isset( $key ) {
168 168
         return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" );
169
-	}
169
+    }
170 170
 
171
-	/*
171
+    /*
172 172
 	|--------------------------------------------------------------------------
173 173
 	| CRUD methods
174 174
 	|--------------------------------------------------------------------------
@@ -177,57 +177,57 @@  discard block
 block discarded – undo
177 177
 	|
178 178
     */
179 179
 
180
-	/*
180
+    /*
181 181
 	|--------------------------------------------------------------------------
182 182
 	| Getters
183 183
 	|--------------------------------------------------------------------------
184 184
 	*/
185 185
 
186
-	/**
187
-	 * Get customer id.
188
-	 *
189
-	 * @since 1.0.19
190
-	 * @param  string $context View or edit context.
191
-	 * @return int
192
-	 */
193
-	public function get_customer_id( $context = 'view' ) {
194
-		return (int) $this->get_prop( 'customer_id', $context );
195
-	}
196
-
197
-	/**
198
-	 * Get customer information.
199
-	 *
200
-	 * @since 1.0.19
201
-	 * @param  string $context View or edit context.
202
-	 * @return WP_User|false WP_User object on success, false on failure.
203
-	 */
204
-	public function get_customer( $context = 'view' ) {
205
-		return get_userdata( $this->get_customer_id( $context ) );
206
-	}
207
-
208
-	/**
209
-	 * Get parent invoice id.
210
-	 *
211
-	 * @since 1.0.19
212
-	 * @param  string $context View or edit context.
213
-	 * @return int
214
-	 */
215
-	public function get_parent_invoice_id( $context = 'view' ) {
216
-		return (int) $this->get_prop( 'parent_payment_id', $context );
217
-	}
218
-
219
-	/**
220
-	 * Alias for self::get_parent_invoice_id().
221
-	 *
222
-	 * @since 1.0.19
223
-	 * @param  string $context View or edit context.
224
-	 * @return int
225
-	 */
186
+    /**
187
+     * Get customer id.
188
+     *
189
+     * @since 1.0.19
190
+     * @param  string $context View or edit context.
191
+     * @return int
192
+     */
193
+    public function get_customer_id( $context = 'view' ) {
194
+        return (int) $this->get_prop( 'customer_id', $context );
195
+    }
196
+
197
+    /**
198
+     * Get customer information.
199
+     *
200
+     * @since 1.0.19
201
+     * @param  string $context View or edit context.
202
+     * @return WP_User|false WP_User object on success, false on failure.
203
+     */
204
+    public function get_customer( $context = 'view' ) {
205
+        return get_userdata( $this->get_customer_id( $context ) );
206
+    }
207
+
208
+    /**
209
+     * Get parent invoice id.
210
+     *
211
+     * @since 1.0.19
212
+     * @param  string $context View or edit context.
213
+     * @return int
214
+     */
215
+    public function get_parent_invoice_id( $context = 'view' ) {
216
+        return (int) $this->get_prop( 'parent_payment_id', $context );
217
+    }
218
+
219
+    /**
220
+     * Alias for self::get_parent_invoice_id().
221
+     *
222
+     * @since 1.0.19
223
+     * @param  string $context View or edit context.
224
+     * @return int
225
+     */
226 226
     public function get_parent_payment_id( $context = 'view' ) {
227 227
         return $this->get_parent_invoice_id( $context );
228
-	}
228
+    }
229 229
 
230
-	/**
230
+    /**
231 231
      * Alias for self::get_parent_invoice_id().
232 232
      *
233 233
      * @since  1.0.0
@@ -237,484 +237,484 @@  discard block
 block discarded – undo
237 237
         return $this->get_parent_invoice_id( $context );
238 238
     }
239 239
 
240
-	/**
241
-	 * Get parent invoice.
242
-	 *
243
-	 * @since 1.0.19
244
-	 * @param  string $context View or edit context.
245
-	 * @return WPInv_Invoice
246
-	 */
247
-	public function get_parent_invoice( $context = 'view' ) {
248
-		return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
249
-	}
250
-
251
-	/**
252
-	 * Alias for self::get_parent_invoice().
253
-	 *
254
-	 * @since 1.0.19
255
-	 * @param  string $context View or edit context.
256
-	 * @return WPInv_Invoice
257
-	 */
258
-    public function get_parent_payment( $context = 'view' ) {
259
-        return $this->get_parent_invoice( $context );
260
-	}
261
-
262
-	/**
263
-	 * Get subscription's product id.
264
-	 *
265
-	 * @since 1.0.19
266
-	 * @param  string $context View or edit context.
267
-	 * @return int
268
-	 */
269
-	public function get_product_id( $context = 'view' ) {
270
-		return (int) $this->get_prop( 'product_id', $context );
271
-	}
272
-
273
-	/**
274
-	 * Get the subscription product.
275
-	 *
276
-	 * @since 1.0.19
277
-	 * @param  string $context View or edit context.
278
-	 * @return WPInv_Item
279
-	 */
280
-	public function get_product( $context = 'view' ) {
281
-		return new WPInv_Item( $this->get_product_id( $context ) );
282
-	}
283
-
284
-	/**
285
-	 * Get parent invoice's gateway.
286
-	 *
287
-	 * Here for backwards compatibility.
288
-	 *
289
-	 * @since 1.0.19
290
-	 * @param  string $context View or edit context.
291
-	 * @return string
292
-	 */
293
-	public function get_gateway( $context = 'view' ) {
294
-		return $this->get_parent_invoice( $context )->get_gateway();
295
-	}
296
-
297
-	/**
298
-	 * Get the period of a renewal.
299
-	 *
300
-	 * @since 1.0.19
301
-	 * @param  string $context View or edit context.
302
-	 * @return string
303
-	 */
304
-	public function get_period( $context = 'view' ) {
305
-		return $this->get_prop( 'period', $context );
306
-	}
307
-
308
-	/**
309
-	 * Get number of periods each renewal is valid for.
310
-	 *
311
-	 * @since 1.0.19
312
-	 * @param  string $context View or edit context.
313
-	 * @return int
314
-	 */
315
-	public function get_frequency( $context = 'view' ) {
316
-		return (int) $this->get_prop( 'frequency', $context );
317
-	}
318
-
319
-	/**
320
-	 * Get the initial amount for the subscription.
321
-	 *
322
-	 * @since 1.0.19
323
-	 * @param  string $context View or edit context.
324
-	 * @return float
325
-	 */
326
-	public function get_initial_amount( $context = 'view' ) {
327
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
328
-	}
329
-
330
-	/**
331
-	 * Get the recurring amount for the subscription.
332
-	 *
333
-	 * @since 1.0.19
334
-	 * @param  string $context View or edit context.
335
-	 * @return float
336
-	 */
337
-	public function get_recurring_amount( $context = 'view' ) {
338
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
339
-	}
340
-
341
-	/**
342
-	 * Get number of times that this subscription can be renewed.
343
-	 *
344
-	 * @since 1.0.19
345
-	 * @param  string $context View or edit context.
346
-	 * @return int
347
-	 */
348
-	public function get_bill_times( $context = 'view' ) {
349
-		return (int) $this->get_prop( 'bill_times', $context );
350
-	}
351
-
352
-	/**
353
-	 * Get transaction id of this subscription's parent invoice.
354
-	 *
355
-	 * @since 1.0.19
356
-	 * @param  string $context View or edit context.
357
-	 * @return string
358
-	 */
359
-	public function get_transaction_id( $context = 'view' ) {
360
-		return $this->get_prop( 'transaction_id', $context );
361
-	}
362
-
363
-	/**
364
-	 * Get the date that the subscription was created.
365
-	 *
366
-	 * @since 1.0.19
367
-	 * @param  string $context View or edit context.
368
-	 * @return string
369
-	 */
370
-	public function get_created( $context = 'view' ) {
371
-		return $this->get_prop( 'created', $context );
372
-	}
373
-
374
-	/**
375
-	 * Alias for self::get_created().
376
-	 *
377
-	 * @since 1.0.19
378
-	 * @param  string $context View or edit context.
379
-	 * @return string
380
-	 */
381
-	public function get_date_created( $context = 'view' ) {
382
-		return $this->get_created( $context );
383
-	}
384
-
385
-	/**
386
-	 * Retrieves the creation date in a timestamp
387
-	 *
388
-	 * @since  1.0.0
389
-	 * @return int
390
-	 */
391
-	public function get_time_created() {
392
-		$created = $this->get_date_created();
393
-		return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
394
-	}
395
-
396
-	/**
397
-	 * Get GMT date when the subscription was created.
398
-	 *
399
-	 * @since 1.0.19
400
-	 * @param  string $context View or edit context.
401
-	 * @return string
402
-	 */
403
-	public function get_date_created_gmt( $context = 'view' ) {
404
-        $date = $this->get_date_created( $context );
240
+    /**
241
+     * Get parent invoice.
242
+     *
243
+     * @since 1.0.19
244
+     * @param  string $context View or edit context.
245
+     * @return WPInv_Invoice
246
+     */
247
+    public function get_parent_invoice( $context = 'view' ) {
248
+        return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
249
+    }
250
+
251
+    /**
252
+     * Alias for self::get_parent_invoice().
253
+     *
254
+     * @since 1.0.19
255
+     * @param  string $context View or edit context.
256
+     * @return WPInv_Invoice
257
+     */
258
+    public function get_parent_payment( $context = 'view' ) {
259
+        return $this->get_parent_invoice( $context );
260
+    }
261
+
262
+    /**
263
+     * Get subscription's product id.
264
+     *
265
+     * @since 1.0.19
266
+     * @param  string $context View or edit context.
267
+     * @return int
268
+     */
269
+    public function get_product_id( $context = 'view' ) {
270
+        return (int) $this->get_prop( 'product_id', $context );
271
+    }
272
+
273
+    /**
274
+     * Get the subscription product.
275
+     *
276
+     * @since 1.0.19
277
+     * @param  string $context View or edit context.
278
+     * @return WPInv_Item
279
+     */
280
+    public function get_product( $context = 'view' ) {
281
+        return new WPInv_Item( $this->get_product_id( $context ) );
282
+    }
283
+
284
+    /**
285
+     * Get parent invoice's gateway.
286
+     *
287
+     * Here for backwards compatibility.
288
+     *
289
+     * @since 1.0.19
290
+     * @param  string $context View or edit context.
291
+     * @return string
292
+     */
293
+    public function get_gateway( $context = 'view' ) {
294
+        return $this->get_parent_invoice( $context )->get_gateway();
295
+    }
296
+
297
+    /**
298
+     * Get the period of a renewal.
299
+     *
300
+     * @since 1.0.19
301
+     * @param  string $context View or edit context.
302
+     * @return string
303
+     */
304
+    public function get_period( $context = 'view' ) {
305
+        return $this->get_prop( 'period', $context );
306
+    }
307
+
308
+    /**
309
+     * Get number of periods each renewal is valid for.
310
+     *
311
+     * @since 1.0.19
312
+     * @param  string $context View or edit context.
313
+     * @return int
314
+     */
315
+    public function get_frequency( $context = 'view' ) {
316
+        return (int) $this->get_prop( 'frequency', $context );
317
+    }
318
+
319
+    /**
320
+     * Get the initial amount for the subscription.
321
+     *
322
+     * @since 1.0.19
323
+     * @param  string $context View or edit context.
324
+     * @return float
325
+     */
326
+    public function get_initial_amount( $context = 'view' ) {
327
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
328
+    }
329
+
330
+    /**
331
+     * Get the recurring amount for the subscription.
332
+     *
333
+     * @since 1.0.19
334
+     * @param  string $context View or edit context.
335
+     * @return float
336
+     */
337
+    public function get_recurring_amount( $context = 'view' ) {
338
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
339
+    }
340
+
341
+    /**
342
+     * Get number of times that this subscription can be renewed.
343
+     *
344
+     * @since 1.0.19
345
+     * @param  string $context View or edit context.
346
+     * @return int
347
+     */
348
+    public function get_bill_times( $context = 'view' ) {
349
+        return (int) $this->get_prop( 'bill_times', $context );
350
+    }
351
+
352
+    /**
353
+     * Get transaction id of this subscription's parent invoice.
354
+     *
355
+     * @since 1.0.19
356
+     * @param  string $context View or edit context.
357
+     * @return string
358
+     */
359
+    public function get_transaction_id( $context = 'view' ) {
360
+        return $this->get_prop( 'transaction_id', $context );
361
+    }
362
+
363
+    /**
364
+     * Get the date that the subscription was created.
365
+     *
366
+     * @since 1.0.19
367
+     * @param  string $context View or edit context.
368
+     * @return string
369
+     */
370
+    public function get_created( $context = 'view' ) {
371
+        return $this->get_prop( 'created', $context );
372
+    }
373
+
374
+    /**
375
+     * Alias for self::get_created().
376
+     *
377
+     * @since 1.0.19
378
+     * @param  string $context View or edit context.
379
+     * @return string
380
+     */
381
+    public function get_date_created( $context = 'view' ) {
382
+        return $this->get_created( $context );
383
+    }
384
+
385
+    /**
386
+     * Retrieves the creation date in a timestamp
387
+     *
388
+     * @since  1.0.0
389
+     * @return int
390
+     */
391
+    public function get_time_created() {
392
+        $created = $this->get_date_created();
393
+        return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
394
+    }
395
+
396
+    /**
397
+     * Get GMT date when the subscription was created.
398
+     *
399
+     * @since 1.0.19
400
+     * @param  string $context View or edit context.
401
+     * @return string
402
+     */
403
+    public function get_date_created_gmt( $context = 'view' ) {
404
+        $date = $this->get_date_created( $context );
405
+
406
+        if ( $date ) {
407
+            $date = get_gmt_from_date( $date );
408
+        }
409
+        return $date;
410
+    }
411
+
412
+    /**
413
+     * Get the date that the subscription will renew.
414
+     *
415
+     * @since 1.0.19
416
+     * @param  string $context View or edit context.
417
+     * @return string
418
+     */
419
+    public function get_next_renewal_date( $context = 'view' ) {
420
+        return $this->get_prop( 'expiration', $context );
421
+    }
422
+
423
+    /**
424
+     * Alias for self::get_next_renewal_date().
425
+     *
426
+     * @since 1.0.19
427
+     * @param  string $context View or edit context.
428
+     * @return string
429
+     */
430
+    public function get_expiration( $context = 'view' ) {
431
+        return $this->get_next_renewal_date( $context );
432
+    }
433
+
434
+    /**
435
+     * Retrieves the expiration date in a timestamp
436
+     *
437
+     * @since  1.0.0
438
+     * @return int
439
+     */
440
+    public function get_expiration_time() {
441
+        $expiration = $this->get_expiration();
442
+
443
+        if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
444
+            return current_time( 'timestamp' );
445
+        }
446
+
447
+        $expiration = strtotime( $expiration, current_time( 'timestamp' ) );
448
+        return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
449
+    }
450
+
451
+    /**
452
+     * Get GMT date when the subscription will renew.
453
+     *
454
+     * @since 1.0.19
455
+     * @param  string $context View or edit context.
456
+     * @return string
457
+     */
458
+    public function get_next_renewal_date_gmt( $context = 'view' ) {
459
+        $date = $this->get_next_renewal_date( $context );
460
+
461
+        if ( $date ) {
462
+            $date = get_gmt_from_date( $date );
463
+        }
464
+        return $date;
465
+    }
466
+
467
+    /**
468
+     * Get the subscription's trial period.
469
+     *
470
+     * @since 1.0.19
471
+     * @param  string $context View or edit context.
472
+     * @return string
473
+     */
474
+    public function get_trial_period( $context = 'view' ) {
475
+        return $this->get_prop( 'trial_period', $context );
476
+    }
477
+
478
+    /**
479
+     * Get the subscription's status.
480
+     *
481
+     * @since 1.0.19
482
+     * @param  string $context View or edit context.
483
+     * @return string
484
+     */
485
+    public function get_status( $context = 'view' ) {
486
+        return $this->get_prop( 'status', $context );
487
+    }
488
+
489
+    /**
490
+     * Get the subscription's profile id.
491
+     *
492
+     * @since 1.0.19
493
+     * @param  string $context View or edit context.
494
+     * @return string
495
+     */
496
+    public function get_profile_id( $context = 'view' ) {
497
+        return $this->get_prop( 'profile_id', $context );
498
+    }
499
+
500
+    /*
501
+	|--------------------------------------------------------------------------
502
+	| Setters
503
+	|--------------------------------------------------------------------------
504
+	*/
505
+
506
+    /**
507
+     * Set customer id.
508
+     *
509
+     * @since 1.0.19
510
+     * @param  int $value The customer's id.
511
+     */
512
+    public function set_customer_id( $value ) {
513
+        $this->set_prop( 'customer_id', (int) $value );
514
+    }
515
+
516
+    /**
517
+     * Set parent invoice id.
518
+     *
519
+     * @since 1.0.19
520
+     * @param  int $value The parent invoice id.
521
+     */
522
+    public function set_parent_invoice_id( $value ) {
523
+        $this->set_prop( 'parent_payment_id', (int) $value );
524
+    }
525
+
526
+    /**
527
+     * Alias for self::set_parent_invoice_id().
528
+     *
529
+     * @since 1.0.19
530
+     * @param  int $value The parent invoice id.
531
+     */
532
+    public function set_parent_payment_id( $value ) {
533
+        $this->set_parent_invoice_id( $value );
534
+    }
535
+
536
+    /**
537
+     * Alias for self::set_parent_invoice_id().
538
+     *
539
+     * @since 1.0.19
540
+     * @param  int $value The parent invoice id.
541
+     */
542
+    public function set_original_payment_id( $value ) {
543
+        $this->set_parent_invoice_id( $value );
544
+    }
545
+
546
+    /**
547
+     * Set subscription's product id.
548
+     *
549
+     * @since 1.0.19
550
+     * @param  int $value The subscription product id.
551
+     */
552
+    public function set_product_id( $value ) {
553
+        $this->set_prop( 'product_id', (int) $value );
554
+    }
555
+
556
+    /**
557
+     * Set the period of a renewal.
558
+     *
559
+     * @since 1.0.19
560
+     * @param  string $value The renewal period.
561
+     */
562
+    public function set_period( $value ) {
563
+        $this->set_prop( 'period', $value );
564
+    }
565
+
566
+    /**
567
+     * Set number of periods each renewal is valid for.
568
+     *
569
+     * @since 1.0.19
570
+     * @param  int $value The subscription frequency.
571
+     */
572
+    public function set_frequency( $value ) {
573
+        $value = empty( $value ) ? 1 : (int) $value;
574
+        $this->set_prop( 'frequency', absint( $value ) );
575
+    }
576
+
577
+    /**
578
+     * Set the initial amount for the subscription.
579
+     *
580
+     * @since 1.0.19
581
+     * @param  float $value The initial subcription amount.
582
+     */
583
+    public function set_initial_amount( $value ) {
584
+        $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
585
+    }
586
+
587
+    /**
588
+     * Set the recurring amount for the subscription.
589
+     *
590
+     * @since 1.0.19
591
+     * @param  float $value The recurring subcription amount.
592
+     */
593
+    public function set_recurring_amount( $value ) {
594
+        $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
595
+    }
596
+
597
+    /**
598
+     * Set number of times that this subscription can be renewed.
599
+     *
600
+     * @since 1.0.19
601
+     * @param  int $value Bill times.
602
+     */
603
+    public function set_bill_times( $value ) {
604
+        $this->set_prop( 'bill_times', (int) $value );
605
+    }
606
+
607
+    /**
608
+     * Get transaction id of this subscription's parent invoice.
609
+     *
610
+     * @since 1.0.19
611
+     * @param string $value Bill times.
612
+     */
613
+    public function set_transaction_id( $value ) {
614
+        $this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
615
+    }
616
+
617
+    /**
618
+     * Set date when this subscription started.
619
+     *
620
+     * @since 1.0.19
621
+     * @param string $value strtotime compliant date.
622
+     */
623
+    public function set_created( $value ) {
624
+        $date = strtotime( $value );
405 625
 
406
-        if ( $date ) {
407
-            $date = get_gmt_from_date( $date );
626
+        if ( $date && $value !== '0000-00-00 00:00:00' ) {
627
+            $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) );
628
+            return;
408 629
         }
409
-		return $date;
410
-	}
411
-
412
-	/**
413
-	 * Get the date that the subscription will renew.
414
-	 *
415
-	 * @since 1.0.19
416
-	 * @param  string $context View or edit context.
417
-	 * @return string
418
-	 */
419
-	public function get_next_renewal_date( $context = 'view' ) {
420
-		return $this->get_prop( 'expiration', $context );
421
-	}
422
-
423
-	/**
424
-	 * Alias for self::get_next_renewal_date().
425
-	 *
426
-	 * @since 1.0.19
427
-	 * @param  string $context View or edit context.
428
-	 * @return string
429
-	 */
430
-	public function get_expiration( $context = 'view' ) {
431
-		return $this->get_next_renewal_date( $context );
432
-	}
433
-
434
-	/**
435
-	 * Retrieves the expiration date in a timestamp
436
-	 *
437
-	 * @since  1.0.0
438
-	 * @return int
439
-	 */
440
-	public function get_expiration_time() {
441
-		$expiration = $this->get_expiration();
442
-
443
-		if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
444
-			return current_time( 'timestamp' );
445
-		}
446
-
447
-		$expiration = strtotime( $expiration, current_time( 'timestamp' ) );
448
-		return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
449
-	}
450
-
451
-	/**
452
-	 * Get GMT date when the subscription will renew.
453
-	 *
454
-	 * @since 1.0.19
455
-	 * @param  string $context View or edit context.
456
-	 * @return string
457
-	 */
458
-	public function get_next_renewal_date_gmt( $context = 'view' ) {
459
-        $date = $this->get_next_renewal_date( $context );
460 630
 
461
-        if ( $date ) {
462
-            $date = get_gmt_from_date( $date );
463
-        }
464
-		return $date;
465
-	}
466
-
467
-	/**
468
-	 * Get the subscription's trial period.
469
-	 *
470
-	 * @since 1.0.19
471
-	 * @param  string $context View or edit context.
472
-	 * @return string
473
-	 */
474
-	public function get_trial_period( $context = 'view' ) {
475
-		return $this->get_prop( 'trial_period', $context );
476
-	}
477
-
478
-	/**
479
-	 * Get the subscription's status.
480
-	 *
481
-	 * @since 1.0.19
482
-	 * @param  string $context View or edit context.
483
-	 * @return string
484
-	 */
485
-	public function get_status( $context = 'view' ) {
486
-		return $this->get_prop( 'status', $context );
487
-	}
488
-
489
-	/**
490
-	 * Get the subscription's profile id.
491
-	 *
492
-	 * @since 1.0.19
493
-	 * @param  string $context View or edit context.
494
-	 * @return string
495
-	 */
496
-	public function get_profile_id( $context = 'view' ) {
497
-		return $this->get_prop( 'profile_id', $context );
498
-	}
499
-
500
-	/*
501
-	|--------------------------------------------------------------------------
502
-	| Setters
503
-	|--------------------------------------------------------------------------
504
-	*/
631
+        $this->set_prop( 'created', '' );
505 632
 
506
-	/**
507
-	 * Set customer id.
508
-	 *
509
-	 * @since 1.0.19
510
-	 * @param  int $value The customer's id.
511
-	 */
512
-	public function set_customer_id( $value ) {
513
-		$this->set_prop( 'customer_id', (int) $value );
514
-	}
515
-
516
-	/**
517
-	 * Set parent invoice id.
518
-	 *
519
-	 * @since 1.0.19
520
-	 * @param  int $value The parent invoice id.
521
-	 */
522
-	public function set_parent_invoice_id( $value ) {
523
-		$this->set_prop( 'parent_payment_id', (int) $value );
524
-	}
525
-
526
-	/**
527
-	 * Alias for self::set_parent_invoice_id().
528
-	 *
529
-	 * @since 1.0.19
530
-	 * @param  int $value The parent invoice id.
531
-	 */
532
-    public function set_parent_payment_id( $value ) {
533
-        $this->set_parent_invoice_id( $value );
534
-	}
633
+    }
535 634
 
536
-	/**
537
-     * Alias for self::set_parent_invoice_id().
635
+    /**
636
+     * Alias for self::set_created().
538 637
      *
539 638
      * @since 1.0.19
540
-	 * @param  int $value The parent invoice id.
639
+     * @param string $value strtotime compliant date.
541 640
      */
542
-    public function set_original_payment_id( $value ) {
543
-        $this->set_parent_invoice_id( $value );
544
-	}
545
-
546
-	/**
547
-	 * Set subscription's product id.
548
-	 *
549
-	 * @since 1.0.19
550
-	 * @param  int $value The subscription product id.
551
-	 */
552
-	public function set_product_id( $value ) {
553
-		$this->set_prop( 'product_id', (int) $value );
554
-	}
555
-
556
-	/**
557
-	 * Set the period of a renewal.
558
-	 *
559
-	 * @since 1.0.19
560
-	 * @param  string $value The renewal period.
561
-	 */
562
-	public function set_period( $value ) {
563
-		$this->set_prop( 'period', $value );
564
-	}
565
-
566
-	/**
567
-	 * Set number of periods each renewal is valid for.
568
-	 *
569
-	 * @since 1.0.19
570
-	 * @param  int $value The subscription frequency.
571
-	 */
572
-	public function set_frequency( $value ) {
573
-		$value = empty( $value ) ? 1 : (int) $value;
574
-		$this->set_prop( 'frequency', absint( $value ) );
575
-	}
576
-
577
-	/**
578
-	 * Set the initial amount for the subscription.
579
-	 *
580
-	 * @since 1.0.19
581
-	 * @param  float $value The initial subcription amount.
582
-	 */
583
-	public function set_initial_amount( $value ) {
584
-		$this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
585
-	}
586
-
587
-	/**
588
-	 * Set the recurring amount for the subscription.
589
-	 *
590
-	 * @since 1.0.19
591
-	 * @param  float $value The recurring subcription amount.
592
-	 */
593
-	public function set_recurring_amount( $value ) {
594
-		$this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
595
-	}
596
-
597
-	/**
598
-	 * Set number of times that this subscription can be renewed.
599
-	 *
600
-	 * @since 1.0.19
601
-	 * @param  int $value Bill times.
602
-	 */
603
-	public function set_bill_times( $value ) {
604
-		$this->set_prop( 'bill_times', (int) $value );
605
-	}
606
-
607
-	/**
608
-	 * Get transaction id of this subscription's parent invoice.
609
-	 *
610
-	 * @since 1.0.19
611
-	 * @param string $value Bill times.
612
-	 */
613
-	public function set_transaction_id( $value ) {
614
-		$this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
615
-	}
616
-
617
-	/**
618
-	 * Set date when this subscription started.
619
-	 *
620
-	 * @since 1.0.19
621
-	 * @param string $value strtotime compliant date.
622
-	 */
623
-	public function set_created( $value ) {
641
+    public function set_date_created( $value ) {
642
+        $this->set_created( $value );
643
+    }
644
+
645
+    /**
646
+     * Set the date that the subscription will renew.
647
+     *
648
+     * @since 1.0.19
649
+     * @param string $value strtotime compliant date.
650
+     */
651
+    public function set_next_renewal_date( $value ) {
624 652
         $date = strtotime( $value );
625 653
 
626 654
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
627
-            $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) );
655
+            $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
628 656
             return;
629 657
         }
630 658
 
631
-		$this->set_prop( 'created', '' );
659
+        $this->set_prop( 'expiration', '' );
632 660
 
633
-	}
661
+    }
634 662
 
635
-	/**
636
-	 * Alias for self::set_created().
637
-	 *
638
-	 * @since 1.0.19
639
-	 * @param string $value strtotime compliant date.
640
-	 */
641
-	public function set_date_created( $value ) {
642
-		$this->set_created( $value );
663
+    /**
664
+     * Alias for self::set_next_renewal_date().
665
+     *
666
+     * @since 1.0.19
667
+     * @param string $value strtotime compliant date.
668
+     */
669
+    public function set_expiration( $value ) {
670
+        $this->set_next_renewal_date( $value );
643 671
     }
644 672
 
645
-	/**
646
-	 * Set the date that the subscription will renew.
647
-	 *
648
-	 * @since 1.0.19
649
-	 * @param string $value strtotime compliant date.
650
-	 */
651
-	public function set_next_renewal_date( $value ) {
652
-		$date = strtotime( $value );
673
+    /**
674
+     * Set the subscription's trial period.
675
+     *
676
+     * @since 1.0.19
677
+     * @param string $value trial period e.g 1 year.
678
+     */
679
+    public function set_trial_period( $value ) {
680
+        $this->set_prop( 'trial_period', $value );
681
+    }
653 682
 
654
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
655
-            $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
683
+    /**
684
+     * Set the subscription's status.
685
+     *
686
+     * @since 1.0.19
687
+     * @param string $new_status    New subscription status.
688
+     */
689
+    public function set_status( $new_status ) {
690
+
691
+        // Abort if this is not a valid status;
692
+        if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
656 693
             return;
657
-		}
658
-
659
-		$this->set_prop( 'expiration', '' );
660
-
661
-	}
662
-
663
-	/**
664
-	 * Alias for self::set_next_renewal_date().
665
-	 *
666
-	 * @since 1.0.19
667
-	 * @param string $value strtotime compliant date.
668
-	 */
669
-	public function set_expiration( $value ) {
670
-		$this->set_next_renewal_date( $value );
671
-    }
672
-
673
-	/**
674
-	 * Set the subscription's trial period.
675
-	 *
676
-	 * @since 1.0.19
677
-	 * @param string $value trial period e.g 1 year.
678
-	 */
679
-	public function set_trial_period( $value ) {
680
-		$this->set_prop( 'trial_period', $value );
681
-	}
682
-
683
-	/**
684
-	 * Set the subscription's status.
685
-	 *
686
-	 * @since 1.0.19
687
-	 * @param string $new_status    New subscription status.
688
-	 */
689
-	public function set_status( $new_status ) {
690
-
691
-		// Abort if this is not a valid status;
692
-		if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
693
-			return;
694
-		}
695
-
696
-		$old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status();
697
-		if ( true === $this->object_read && $old_status !== $new_status ) {
698
-			$this->status_transition = array(
699
-				'from' => $old_status,
700
-				'to'   => $new_status,
701
-			);
702
-		}
703
-
704
-		$this->set_prop( 'status', $new_status );
705
-	}
706
-
707
-	/**
708
-	 * Set the subscription's (remote) profile id.
709
-	 *
710
-	 * @since 1.0.19
711
-	 * @param  string $value the remote profile id.
712
-	 */
713
-	public function set_profile_id( $value ) {
714
-		$this->set_prop( 'profile_id', sanitize_text_field( $value ) );
715
-	}
716
-
717
-	/*
694
+        }
695
+
696
+        $old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status();
697
+        if ( true === $this->object_read && $old_status !== $new_status ) {
698
+            $this->status_transition = array(
699
+                'from' => $old_status,
700
+                'to'   => $new_status,
701
+            );
702
+        }
703
+
704
+        $this->set_prop( 'status', $new_status );
705
+    }
706
+
707
+    /**
708
+     * Set the subscription's (remote) profile id.
709
+     *
710
+     * @since 1.0.19
711
+     * @param  string $value the remote profile id.
712
+     */
713
+    public function set_profile_id( $value ) {
714
+        $this->set_prop( 'profile_id', sanitize_text_field( $value ) );
715
+    }
716
+
717
+    /*
718 718
 	|--------------------------------------------------------------------------
719 719
 	| Boolean methods
720 720
 	|--------------------------------------------------------------------------
@@ -723,55 +723,55 @@  discard block
 block discarded – undo
723 723
 	|
724 724
 	*/
725 725
 
726
-	/**
726
+    /**
727 727
      * Checks if the subscription has a given status.
728
-	 *
729
-	 * @param string|array String or array of strings to check for.
730
-	 * @return bool
728
+     *
729
+     * @param string|array String or array of strings to check for.
730
+     * @return bool
731 731
      */
732 732
     public function has_status( $status ) {
733 733
         return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) );
734
-	}
734
+    }
735 735
 
736
-	/**
736
+    /**
737 737
      * Checks if the subscription has a trial period.
738
-	 *
739
-	 * @return bool
738
+     *
739
+     * @return bool
740 740
      */
741 741
     public function has_trial_period() {
742
-		$period = $this->get_trial_period();
742
+        $period = $this->get_trial_period();
743 743
         return ! empty( $period );
744
-	}
745
-
746
-	/**
747
-	 * Is the subscription active?
748
-	 *
749
-	 * @return bool
750
-	 */
751
-	public function is_active() {
752
-		return $this->has_status( 'active trialling' ) && ! $this->is_expired();
753
-	}
754
-
755
-	/**
756
-	 * Is the subscription expired?
757
-	 *
758
-	 * @return bool
759
-	 */
760
-	public function is_expired() {
761
-		return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) );
762
-	}
763
-
764
-	/**
765
-	 * Is this the last renewals?
766
-	 *
767
-	 * @return bool
768
-	 */
769
-	public function is_last_renewal() {
770
-		$max_bills = $this->get_bill_times();
771
-		return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
772
-	}
773
-
774
-	/*
744
+    }
745
+
746
+    /**
747
+     * Is the subscription active?
748
+     *
749
+     * @return bool
750
+     */
751
+    public function is_active() {
752
+        return $this->has_status( 'active trialling' ) && ! $this->is_expired();
753
+    }
754
+
755
+    /**
756
+     * Is the subscription expired?
757
+     *
758
+     * @return bool
759
+     */
760
+    public function is_expired() {
761
+        return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) );
762
+    }
763
+
764
+    /**
765
+     * Is this the last renewals?
766
+     *
767
+     * @return bool
768
+     */
769
+    public function is_last_renewal() {
770
+        $max_bills = $this->get_bill_times();
771
+        return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
772
+    }
773
+
774
+    /*
775 775
 	|--------------------------------------------------------------------------
776 776
 	| Additional methods
777 777
 	|--------------------------------------------------------------------------
@@ -780,27 +780,27 @@  discard block
 block discarded – undo
780 780
 	|
781 781
 	*/
782 782
 
783
-	/**
784
-	 * Backwards compatibilty.
785
-	 */
786
-	public function create( $data = array() ) {
783
+    /**
784
+     * Backwards compatibilty.
785
+     */
786
+    public function create( $data = array() ) {
787 787
 
788
-		// Set the properties.
789
-		if ( is_array( $data ) ) {
790
-			$this->set_props( $data );
791
-		}
788
+        // Set the properties.
789
+        if ( is_array( $data ) ) {
790
+            $this->set_props( $data );
791
+        }
792 792
 
793
-		// Save the item.
794
-		return $this->save();
793
+        // Save the item.
794
+        return $this->save();
795 795
 
796
-	}
796
+    }
797 797
 
798
-	/**
799
-	 * Backwards compatibilty.
800
-	 */
801
-	public function update( $args = array() ) {
802
-		return $this->create( $args );
803
-	}
798
+    /**
799
+     * Backwards compatibilty.
800
+     */
801
+    public function update( $args = array() ) {
802
+        return $this->create( $args );
803
+    }
804 804
 
805 805
     /**
806 806
      * Retrieve renewal payments for a subscription
@@ -810,22 +810,22 @@  discard block
 block discarded – undo
810 810
      */
811 811
     public function get_child_payments( $hide_pending = true ) {
812 812
 
813
-		$statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
813
+        $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
814 814
 
815
-		if ( ! $hide_pending ) {
816
-			$statuses = array_keys( wpinv_get_invoice_statuses() );
817
-		}
815
+        if ( ! $hide_pending ) {
816
+            $statuses = array_keys( wpinv_get_invoice_statuses() );
817
+        }
818 818
 
819 819
         return get_posts(
820
-			array(
821
-            	'post_parent' => $this->get_parent_payment_id(),
822
-            	'numberposts' => -1,
823
-            	'post_status' => $statuses,
824
-            	'orderby'     => 'ID',
825
-            	'order'       => 'ASC',
826
-            	'post_type'   => 'wpi_invoice',
827
-			)
828
-		);
820
+            array(
821
+                'post_parent' => $this->get_parent_payment_id(),
822
+                'numberposts' => -1,
823
+                'post_status' => $statuses,
824
+                'orderby'     => 'ID',
825
+                'order'       => 'ASC',
826
+                'post_type'   => 'wpi_invoice',
827
+            )
828
+        );
829 829
     }
830 830
 
831 831
     /**
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
      * @return int
836 836
      */
837 837
     public function get_total_payments() {
838
-		return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() );
838
+        return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() );
839 839
     }
840 840
 
841 841
     /**
@@ -859,56 +859,56 @@  discard block
 block discarded – undo
859 859
      *
860 860
      * @since  2.4
861 861
      * @param  array $args Array of values for the payment, including amount and transaction ID
862
-	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
862
+     * @param  WPInv_Invoice $invoice If adding an existing invoice.
863 863
      * @return bool
864 864
      */
865 865
     public function add_payment( $args = array(), $invoice = false ) {
866 866
 
867
-		// Process each payment once.
867
+        // Process each payment once.
868 868
         if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
869 869
             return false;
870 870
         }
871 871
 
872
-		// Are we creating a new invoice?
873
-		if ( empty( $invoice ) ) {
874
-			$invoice = $this->create_payment();
872
+        // Are we creating a new invoice?
873
+        if ( empty( $invoice ) ) {
874
+            $invoice = $this->create_payment();
875 875
 
876
-			if ( empty( $invoice ) ) {
877
-				return false;
878
-			}
876
+            if ( empty( $invoice ) ) {
877
+                return false;
878
+            }
879 879
 }
880 880
 
881
-		$invoice->set_status( 'wpi-renewal' );
881
+        $invoice->set_status( 'wpi-renewal' );
882 882
 
883
-		// Maybe set a transaction id.
884
-		if ( ! empty( $args['transaction_id'] ) ) {
885
-			$invoice->set_transaction_id( $args['transaction_id'] );
886
-		}
883
+        // Maybe set a transaction id.
884
+        if ( ! empty( $args['transaction_id'] ) ) {
885
+            $invoice->set_transaction_id( $args['transaction_id'] );
886
+        }
887 887
 
888
-		// Set the completed date.
889
-		$invoice->set_completed_date( current_time( 'mysql' ) );
888
+        // Set the completed date.
889
+        $invoice->set_completed_date( current_time( 'mysql' ) );
890 890
 
891
-		// And the gateway.
892
-		if ( ! empty( $args['gateway'] ) ) {
893
-			$invoice->set_gateway( $args['gateway'] );
894
-		}
891
+        // And the gateway.
892
+        if ( ! empty( $args['gateway'] ) ) {
893
+            $invoice->set_gateway( $args['gateway'] );
894
+        }
895 895
 
896
-		$invoice->save();
896
+        $invoice->save();
897 897
 
898
-		if ( ! $invoice->exists() ) {
899
-			return false;
900
-		}
898
+        if ( ! $invoice->exists() ) {
899
+            return false;
900
+        }
901 901
 
902
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
903
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
902
+        do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
903
+        do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
904 904
         do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
905 905
 
906 906
         update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
907 907
 
908 908
         return $invoice->get_id();
909
-	}
909
+    }
910 910
 
911
-	/**
911
+    /**
912 912
      * Creates a new invoice and returns it.
913 913
      *
914 914
      * @since  1.0.19
@@ -916,124 +916,124 @@  discard block
 block discarded – undo
916 916
      */
917 917
     public function create_payment() {
918 918
 
919
-		$parent_invoice = $this->get_parent_payment();
920
-
921
-		if ( ! $parent_invoice->exists() ) {
922
-			return false;
923
-		}
924
-
925
-		// Duplicate the parent invoice.
926
-		$invoice = getpaid_duplicate_invoice( $parent_invoice );
927
-		$invoice->set_parent_id( $parent_invoice->get_id() );
928
-		$invoice->set_subscription_id( $this->get_id() );
929
-		$invoice->set_remote_subscription_id( $this->get_profile_id() );
930
-
931
-		// Set invoice items.
932
-		$subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() );
933
-		$allowed_items      = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] );
934
-		$invoice_items      = array();
935
-
936
-		foreach ( $invoice->get_items() as $item ) {
937
-			if ( in_array( $item->get_id(), $allowed_items ) ) {
938
-				$invoice_items[] = $item;
939
-			}
940
-		}
941
-
942
-		$invoice->set_items( $invoice_items );
943
-
944
-		if ( ! empty( $subscription_group['fees'] ) ) {
945
-			$invoice->set_fees( $subscription_group['fees'] );
946
-		}
947
-
948
-		// Maybe recalculate discount (Pre-GetPaid Fix).
949
-		$discount = new WPInv_Discount( $invoice->get_discount_code() );
950
-		if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
951
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
952
-		}
953
-
954
-		$invoice->recalculate_total();
955
-		$invoice->set_status( 'wpi-pending' );
956
-		$invoice->save();
957
-
958
-		return $invoice->exists() ? $invoice : false;
959
-    }
960
-
961
-	/**
962
-	 * Renews or completes a subscription
963
-	 *
964
-	 * @since  1.0.0
965
-	 * @return int The subscription's id
966
-	 */
967
-	public function renew() {
968
-
969
-		// Complete subscription if applicable
970
-		if ( $this->is_last_renewal() ) {
971
-			return $this->complete();
972
-		}
973
-
974
-		// Calculate new expiration
975
-		$frequency      = $this->get_frequency();
976
-		$period         = $this->get_period();
977
-		$new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
978
-
979
-		$this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) );
980
-		$this->set_status( 'active' );
981
-		$this->save();
982
-
983
-		do_action( 'getpaid_subscription_renewed', $this );
984
-
985
-		return $this->get_id();
986
-	}
987
-
988
-	/**
989
-	 * Marks a subscription as completed
990
-	 *
991
-	 * Subscription is completed when the number of payments matches the billing_times field
992
-	 *
993
-	 * @since  1.0.0
994
-	 * @return int|bool Subscription id or false if the subscription is cancelled.
995
-	 */
996
-	public function complete() {
997
-
998
-		// Only mark a subscription as complete if it's not already cancelled.
999
-		if ( $this->has_status( 'cancelled' ) ) {
1000
-			return false;
1001
-		}
1002
-
1003
-		$this->set_status( 'completed' );
1004
-		return $this->save();
1005
-
1006
-	}
1007
-
1008
-	/**
1009
-	 * Marks a subscription as expired
1010
-	 *
1011
-	 * @since  1.0.0
1012
-	 * @param  bool $check_expiration
1013
-	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1014
-	 */
1015
-	public function expire( $check_expiration = false ) {
1016
-
1017
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1018
-			// Do not mark as expired since real expiration date is in the future
1019
-			return false;
1020
-		}
1021
-
1022
-		$this->set_status( 'expired' );
1023
-		return $this->save();
1024
-
1025
-	}
1026
-
1027
-	/**
1028
-	 * Marks a subscription as failing
1029
-	 *
1030
-	 * @since  2.4.2
1031
-	 * @return int Subscription id.
1032
-	 */
1033
-	public function failing() {
1034
-		$this->set_status( 'failing' );
1035
-		return $this->save();
1036
-	}
919
+        $parent_invoice = $this->get_parent_payment();
920
+
921
+        if ( ! $parent_invoice->exists() ) {
922
+            return false;
923
+        }
924
+
925
+        // Duplicate the parent invoice.
926
+        $invoice = getpaid_duplicate_invoice( $parent_invoice );
927
+        $invoice->set_parent_id( $parent_invoice->get_id() );
928
+        $invoice->set_subscription_id( $this->get_id() );
929
+        $invoice->set_remote_subscription_id( $this->get_profile_id() );
930
+
931
+        // Set invoice items.
932
+        $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() );
933
+        $allowed_items      = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] );
934
+        $invoice_items      = array();
935
+
936
+        foreach ( $invoice->get_items() as $item ) {
937
+            if ( in_array( $item->get_id(), $allowed_items ) ) {
938
+                $invoice_items[] = $item;
939
+            }
940
+        }
941
+
942
+        $invoice->set_items( $invoice_items );
943
+
944
+        if ( ! empty( $subscription_group['fees'] ) ) {
945
+            $invoice->set_fees( $subscription_group['fees'] );
946
+        }
947
+
948
+        // Maybe recalculate discount (Pre-GetPaid Fix).
949
+        $discount = new WPInv_Discount( $invoice->get_discount_code() );
950
+        if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
951
+            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
952
+        }
953
+
954
+        $invoice->recalculate_total();
955
+        $invoice->set_status( 'wpi-pending' );
956
+        $invoice->save();
957
+
958
+        return $invoice->exists() ? $invoice : false;
959
+    }
960
+
961
+    /**
962
+     * Renews or completes a subscription
963
+     *
964
+     * @since  1.0.0
965
+     * @return int The subscription's id
966
+     */
967
+    public function renew() {
968
+
969
+        // Complete subscription if applicable
970
+        if ( $this->is_last_renewal() ) {
971
+            return $this->complete();
972
+        }
973
+
974
+        // Calculate new expiration
975
+        $frequency      = $this->get_frequency();
976
+        $period         = $this->get_period();
977
+        $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
978
+
979
+        $this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) );
980
+        $this->set_status( 'active' );
981
+        $this->save();
982
+
983
+        do_action( 'getpaid_subscription_renewed', $this );
984
+
985
+        return $this->get_id();
986
+    }
987
+
988
+    /**
989
+     * Marks a subscription as completed
990
+     *
991
+     * Subscription is completed when the number of payments matches the billing_times field
992
+     *
993
+     * @since  1.0.0
994
+     * @return int|bool Subscription id or false if the subscription is cancelled.
995
+     */
996
+    public function complete() {
997
+
998
+        // Only mark a subscription as complete if it's not already cancelled.
999
+        if ( $this->has_status( 'cancelled' ) ) {
1000
+            return false;
1001
+        }
1002
+
1003
+        $this->set_status( 'completed' );
1004
+        return $this->save();
1005
+
1006
+    }
1007
+
1008
+    /**
1009
+     * Marks a subscription as expired
1010
+     *
1011
+     * @since  1.0.0
1012
+     * @param  bool $check_expiration
1013
+     * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1014
+     */
1015
+    public function expire( $check_expiration = false ) {
1016
+
1017
+        if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1018
+            // Do not mark as expired since real expiration date is in the future
1019
+            return false;
1020
+        }
1021
+
1022
+        $this->set_status( 'expired' );
1023
+        return $this->save();
1024
+
1025
+    }
1026
+
1027
+    /**
1028
+     * Marks a subscription as failing
1029
+     *
1030
+     * @since  2.4.2
1031
+     * @return int Subscription id.
1032
+     */
1033
+    public function failing() {
1034
+        $this->set_status( 'failing' );
1035
+        return $this->save();
1036
+    }
1037 1037
 
1038 1038
     /**
1039 1039
      * Marks a subscription as cancelled
@@ -1042,19 +1042,19 @@  discard block
 block discarded – undo
1042 1042
      * @return int Subscription id.
1043 1043
      */
1044 1044
     public function cancel() {
1045
-		$this->set_status( 'cancelled' );
1046
-		return $this->save();
1045
+        $this->set_status( 'cancelled' );
1046
+        return $this->save();
1047 1047
     }
1048 1048
 
1049
-	/**
1050
-	 * Determines if a subscription can be cancelled both locally and with a payment processor.
1051
-	 *
1052
-	 * @since  1.0.0
1053
-	 * @return bool
1054
-	 */
1055
-	public function can_cancel() {
1056
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1057
-	}
1049
+    /**
1050
+     * Determines if a subscription can be cancelled both locally and with a payment processor.
1051
+     *
1052
+     * @since  1.0.0
1053
+     * @return bool
1054
+     */
1055
+    public function can_cancel() {
1056
+        return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1057
+    }
1058 1058
 
1059 1059
     /**
1060 1060
      * Returns an array of subscription statuses that can be cancelled
@@ -1067,109 +1067,109 @@  discard block
 block discarded – undo
1067 1067
         return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1068 1068
     }
1069 1069
 
1070
-	/**
1071
-	 * Retrieves the URL to cancel subscription
1072
-	 *
1073
-	 * @since  1.0.0
1074
-	 * @return string
1075
-	 */
1076
-	public function get_cancel_url() {
1077
-		$url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1078
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1079
-	}
1080
-
1081
-	/**
1082
-	 * Retrieves the URL to view a subscription
1083
-	 *
1084
-	 * @since  1.0.19
1085
-	 * @return string
1086
-	 */
1087
-	public function get_view_url() {
1088
-
1089
-		$url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1090
-		$url = add_query_arg( 'subscription', $this->get_id(), $url );
1091
-
1092
-		return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1093
-	}
1094
-
1095
-	/**
1096
-	 * Determines if subscription can be manually renewed
1097
-	 *
1098
-	 * This method is filtered by payment gateways in order to return true on subscriptions
1099
-	 * that can be renewed manually
1100
-	 *
1101
-	 * @since  2.5
1102
-	 * @return bool
1103
-	 */
1104
-	public function can_renew() {
1105
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1106
-	}
1107
-
1108
-	/**
1109
-	 * Retrieves the URL to renew a subscription
1110
-	 *
1111
-	 * @since  2.5
1112
-	 * @return string
1113
-	 */
1114
-	public function get_renew_url() {
1115
-		$url = wp_nonce_url(
1070
+    /**
1071
+     * Retrieves the URL to cancel subscription
1072
+     *
1073
+     * @since  1.0.0
1074
+     * @return string
1075
+     */
1076
+    public function get_cancel_url() {
1077
+        $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1078
+        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1079
+    }
1080
+
1081
+    /**
1082
+     * Retrieves the URL to view a subscription
1083
+     *
1084
+     * @since  1.0.19
1085
+     * @return string
1086
+     */
1087
+    public function get_view_url() {
1088
+
1089
+        $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1090
+        $url = add_query_arg( 'subscription', $this->get_id(), $url );
1091
+
1092
+        return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1093
+    }
1094
+
1095
+    /**
1096
+     * Determines if subscription can be manually renewed
1097
+     *
1098
+     * This method is filtered by payment gateways in order to return true on subscriptions
1099
+     * that can be renewed manually
1100
+     *
1101
+     * @since  2.5
1102
+     * @return bool
1103
+     */
1104
+    public function can_renew() {
1105
+        return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1106
+    }
1107
+
1108
+    /**
1109
+     * Retrieves the URL to renew a subscription
1110
+     *
1111
+     * @since  2.5
1112
+     * @return string
1113
+     */
1114
+    public function get_renew_url() {
1115
+        $url = wp_nonce_url(
1116 1116
             add_query_arg(
1117 1117
                 array(
1118
-					'getpaid-action' => 'renew_subscription',
1119
-					'sub_id'         => $this->get_id,
1118
+                    'getpaid-action' => 'renew_subscription',
1119
+                    'sub_id'         => $this->get_id,
1120 1120
                 )
1121 1121
             ),
1122 1122
             'getpaid-nonce'
1123 1123
         );
1124
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1125
-	}
1126
-
1127
-	/**
1128
-	 * Determines if subscription can have their payment method updated
1129
-	 *
1130
-	 * @since  1.0.0
1131
-	 * @return bool
1132
-	 */
1133
-	public function can_update() {
1134
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1135
-	}
1136
-
1137
-	/**
1138
-	 * Retrieves the URL to update subscription
1139
-	 *
1140
-	 * @since  1.0.0
1141
-	 * @return string
1142
-	 */
1143
-	public function get_update_url() {
1144
-		$url = add_query_arg(
1124
+        return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1125
+    }
1126
+
1127
+    /**
1128
+     * Determines if subscription can have their payment method updated
1129
+     *
1130
+     * @since  1.0.0
1131
+     * @return bool
1132
+     */
1133
+    public function can_update() {
1134
+        return apply_filters( 'wpinv_subscription_can_update', false, $this );
1135
+    }
1136
+
1137
+    /**
1138
+     * Retrieves the URL to update subscription
1139
+     *
1140
+     * @since  1.0.0
1141
+     * @return string
1142
+     */
1143
+    public function get_update_url() {
1144
+        $url = add_query_arg(
1145 1145
             array(
1146
-				'action'          => 'update',
1147
-				'subscription_id' => $this->get_id(),
1146
+                'action'          => 'update',
1147
+                'subscription_id' => $this->get_id(),
1148 1148
             )
1149 1149
         );
1150
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1151
-	}
1152
-
1153
-	/**
1154
-	 * Retrieves the subscription status label
1155
-	 *
1156
-	 * @since  1.0.0
1157
-	 * @return string
1158
-	 */
1159
-	public function get_status_label() {
1160
-		return getpaid_get_subscription_status_label( $this->get_status() );
1161
-	}
1162
-
1163
-	/**
1164
-	 * Retrieves the subscription status class
1165
-	 *
1166
-	 * @since  1.0.19
1167
-	 * @return string
1168
-	 */
1169
-	public function get_status_class() {
1170
-		$statuses = getpaid_get_subscription_status_classes();
1171
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark';
1172
-	}
1150
+        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1151
+    }
1152
+
1153
+    /**
1154
+     * Retrieves the subscription status label
1155
+     *
1156
+     * @since  1.0.0
1157
+     * @return string
1158
+     */
1159
+    public function get_status_label() {
1160
+        return getpaid_get_subscription_status_label( $this->get_status() );
1161
+    }
1162
+
1163
+    /**
1164
+     * Retrieves the subscription status class
1165
+     *
1166
+     * @since  1.0.19
1167
+     * @return string
1168
+     */
1169
+    public function get_status_class() {
1170
+        $statuses = getpaid_get_subscription_status_classes();
1171
+        return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark';
1172
+    }
1173 1173
 
1174 1174
     /**
1175 1175
      * Retrieves the subscription status label
@@ -1179,11 +1179,11 @@  discard block
 block discarded – undo
1179 1179
      */
1180 1180
     public function get_status_label_html() {
1181 1181
 
1182
-		$status_label = sanitize_text_field( $this->get_status_label() );
1183
-		$class        = esc_attr( $this->get_status_class() );
1184
-		$status       = sanitize_html_class( $this->get_status() );
1182
+        $status_label = sanitize_text_field( $this->get_status_label() );
1183
+        $class        = esc_attr( $this->get_status_class() );
1184
+        $status       = sanitize_html_class( $this->get_status() );
1185 1185
 
1186
-		return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1186
+        return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1187 1187
     }
1188 1188
 
1189 1189
     /**
@@ -1194,75 +1194,75 @@  discard block
 block discarded – undo
1194 1194
      * @return bool
1195 1195
      */
1196 1196
     public function payment_exists( $txn_id = '' ) {
1197
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1197
+        $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1198 1198
         return ! empty( $invoice_id );
1199
-	}
1200
-
1201
-	/**
1202
-	 * Handle the status transition.
1203
-	 */
1204
-	protected function status_transition() {
1205
-		$status_transition = $this->status_transition;
1206
-
1207
-		// Reset status transition variable.
1208
-		$this->status_transition = false;
1209
-
1210
-		if ( $status_transition ) {
1211
-			try {
1212
-
1213
-				// Fire a hook for the status change.
1214
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1215
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1216
-
1217
-				if ( ! empty( $status_transition['from'] ) ) {
1218
-
1219
-					/* translators: 1: old subscription status 2: new subscription status */
1220
-					$transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1221
-
1222
-					// Note the transition occurred.
1223
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1224
-
1225
-					// Fire another hook.
1226
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1227
-					do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1228
-
1229
-				} else {
1230
-					/* translators: %s: new invoice status */
1231
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1232
-
1233
-					// Note the transition occurred.
1234
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1235
-
1236
-				}
1237
-			} catch ( Exception $e ) {
1238
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1239
-			}
1240
-		}
1241
-
1242
-	}
1243
-
1244
-	/**
1245
-	 * Save data to the database.
1246
-	 *
1247
-	 * @since 1.0.19
1248
-	 * @return int subscription ID
1249
-	 */
1250
-	public function save() {
1251
-		parent::save();
1252
-		$this->status_transition();
1253
-		return $this->get_id();
1254
-	}
1255
-
1256
-	/**
1257
-	 * Activates a subscription.
1258
-	 *
1259
-	 * @since 1.0.19
1260
-	 * @return int subscription ID
1261
-	 */
1262
-	public function activate() {
1263
-		$status = 'trialling' == $this->get_status() ? 'trialling' : 'active';
1264
-		$this->set_status( $status );
1265
-		return $this->save();
1266
-	}
1199
+    }
1200
+
1201
+    /**
1202
+     * Handle the status transition.
1203
+     */
1204
+    protected function status_transition() {
1205
+        $status_transition = $this->status_transition;
1206
+
1207
+        // Reset status transition variable.
1208
+        $this->status_transition = false;
1209
+
1210
+        if ( $status_transition ) {
1211
+            try {
1212
+
1213
+                // Fire a hook for the status change.
1214
+                do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1215
+                do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1216
+
1217
+                if ( ! empty( $status_transition['from'] ) ) {
1218
+
1219
+                    /* translators: 1: old subscription status 2: new subscription status */
1220
+                    $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1221
+
1222
+                    // Note the transition occurred.
1223
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1224
+
1225
+                    // Fire another hook.
1226
+                    do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1227
+                    do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1228
+
1229
+                } else {
1230
+                    /* translators: %s: new invoice status */
1231
+                    $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1232
+
1233
+                    // Note the transition occurred.
1234
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1235
+
1236
+                }
1237
+            } catch ( Exception $e ) {
1238
+                $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1239
+            }
1240
+        }
1241
+
1242
+    }
1243
+
1244
+    /**
1245
+     * Save data to the database.
1246
+     *
1247
+     * @since 1.0.19
1248
+     * @return int subscription ID
1249
+     */
1250
+    public function save() {
1251
+        parent::save();
1252
+        $this->status_transition();
1253
+        return $this->get_id();
1254
+    }
1255
+
1256
+    /**
1257
+     * Activates a subscription.
1258
+     *
1259
+     * @since 1.0.19
1260
+     * @return int subscription ID
1261
+     */
1262
+    public function activate() {
1263
+        $status = 'trialling' == $this->get_status() ? 'trialling' : 'active';
1264
+        $this->set_status( $status );
1265
+        return $this->save();
1266
+    }
1267 1267
 
1268 1268
 }
Please login to merge, or discard this patch.
Spacing   +228 added lines, -228 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * The Subscription Class
@@ -68,27 +68,27 @@  discard block
 block discarded – undo
68 68
 	 * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69 69
 	 * @param  bool $deprecated
70 70
 	 */
71
-	function __construct( $subscription = 0, $deprecated = false ) {
71
+	function __construct($subscription = 0, $deprecated = false) {
72 72
 
73
-		parent::__construct( $subscription );
73
+		parent::__construct($subscription);
74 74
 
75
-		if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
-			$this->set_id( $subscription );
77
-		} elseif ( $subscription instanceof self ) {
78
-			$this->set_id( $subscription->get_id() );
79
-		} elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
80
-			$this->set_id( $subscription_id );
81
-		} elseif ( ! empty( $subscription->id ) ) {
82
-			$this->set_id( $subscription->id );
75
+		if (!$deprecated && !empty($subscription) && is_numeric($subscription)) {
76
+			$this->set_id($subscription);
77
+		} elseif ($subscription instanceof self) {
78
+			$this->set_id($subscription->get_id());
79
+		} elseif ($deprecated && $subscription_id = self::get_subscription_id_by_field($subscription, 'profile_id')) {
80
+			$this->set_id($subscription_id);
81
+		} elseif (!empty($subscription->id)) {
82
+			$this->set_id($subscription->id);
83 83
 		} else {
84
-			$this->set_object_read( true );
84
+			$this->set_object_read(true);
85 85
 		}
86 86
 
87 87
 		// Load the datastore.
88
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
88
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
89 89
 
90
-		if ( $this->get_id() > 0 ) {
91
-			$this->data_store->read( $this );
90
+		if ($this->get_id() > 0) {
91
+			$this->data_store->read($this);
92 92
 		}
93 93
 
94 94
 	}
@@ -103,17 +103,17 @@  discard block
 block discarded – undo
103 103
 	 * @since 1.0.19
104 104
 	 * @return int
105 105
 	 */
106
-	public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
106
+	public static function get_subscription_id_by_field($value, $field = 'profile_id') {
107 107
         global $wpdb;
108 108
 
109 109
 		// Trim the value.
110
-		$value = trim( $value );
110
+		$value = trim($value);
111 111
 
112
-		if ( empty( $value ) ) {
112
+		if (empty($value)) {
113 113
 			return 0;
114 114
 		}
115 115
 
116
-		if ( 'invoice_id' == $field ) {
116
+		if ('invoice_id' == $field) {
117 117
 			$field = 'parent_payment_id';
118 118
 		}
119 119
 
@@ -125,28 +125,28 @@  discard block
 block discarded – undo
125 125
 		);
126 126
 
127 127
 		// Ensure a field has been passed.
128
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
128
+		if (empty($field) || !in_array($field, $fields)) {
129 129
 			return 0;
130 130
 		}
131 131
 
132 132
 		// Maybe retrieve from the cache.
133
-		$subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
-		if ( ! empty( $subscription_id ) ) {
133
+		$subscription_id = wp_cache_get($value, "getpaid_subscription_{$field}s_to_subscription_ids");
134
+		if (!empty($subscription_id)) {
135 135
 			return $subscription_id;
136 136
 		}
137 137
 
138 138
         // Fetch from the db.
139 139
         $table            = $wpdb->prefix . 'wpinv_subscriptions';
140 140
         $subscription_id  = (int) $wpdb->get_var(
141
-            $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
141
+            $wpdb->prepare("SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value)
142 142
         );
143 143
 
144
-		if ( empty( $subscription_id ) ) {
144
+		if (empty($subscription_id)) {
145 145
 			return 0;
146 146
 		}
147 147
 
148 148
 		// Update the cache with our data.
149
-		wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
149
+		wp_cache_set($value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids");
150 150
 
151 151
 		return $subscription_id;
152 152
 	}
@@ -155,17 +155,17 @@  discard block
 block discarded – undo
155 155
      * Clears the subscription's cache.
156 156
      */
157 157
     public function clear_cache() {
158
-		wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
159
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
160
-		wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
161
-		wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
158
+		wp_cache_delete($this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids');
159
+		wp_cache_delete($this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids');
160
+		wp_cache_delete($this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids');
161
+		wp_cache_delete($this->get_id(), 'getpaid_subscriptions');
162 162
 	}
163 163
 
164 164
 	/**
165 165
      * Checks if a subscription key is set.
166 166
      */
167
-    public function _isset( $key ) {
168
-        return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" );
167
+    public function _isset($key) {
168
+        return isset($this->data[$key]) || method_exists($this, "get_$key");
169 169
 	}
170 170
 
171 171
 	/*
@@ -190,8 +190,8 @@  discard block
 block discarded – undo
190 190
 	 * @param  string $context View or edit context.
191 191
 	 * @return int
192 192
 	 */
193
-	public function get_customer_id( $context = 'view' ) {
194
-		return (int) $this->get_prop( 'customer_id', $context );
193
+	public function get_customer_id($context = 'view') {
194
+		return (int) $this->get_prop('customer_id', $context);
195 195
 	}
196 196
 
197 197
 	/**
@@ -201,8 +201,8 @@  discard block
 block discarded – undo
201 201
 	 * @param  string $context View or edit context.
202 202
 	 * @return WP_User|false WP_User object on success, false on failure.
203 203
 	 */
204
-	public function get_customer( $context = 'view' ) {
205
-		return get_userdata( $this->get_customer_id( $context ) );
204
+	public function get_customer($context = 'view') {
205
+		return get_userdata($this->get_customer_id($context));
206 206
 	}
207 207
 
208 208
 	/**
@@ -212,8 +212,8 @@  discard block
 block discarded – undo
212 212
 	 * @param  string $context View or edit context.
213 213
 	 * @return int
214 214
 	 */
215
-	public function get_parent_invoice_id( $context = 'view' ) {
216
-		return (int) $this->get_prop( 'parent_payment_id', $context );
215
+	public function get_parent_invoice_id($context = 'view') {
216
+		return (int) $this->get_prop('parent_payment_id', $context);
217 217
 	}
218 218
 
219 219
 	/**
@@ -223,8 +223,8 @@  discard block
 block discarded – undo
223 223
 	 * @param  string $context View or edit context.
224 224
 	 * @return int
225 225
 	 */
226
-    public function get_parent_payment_id( $context = 'view' ) {
227
-        return $this->get_parent_invoice_id( $context );
226
+    public function get_parent_payment_id($context = 'view') {
227
+        return $this->get_parent_invoice_id($context);
228 228
 	}
229 229
 
230 230
 	/**
@@ -233,8 +233,8 @@  discard block
 block discarded – undo
233 233
      * @since  1.0.0
234 234
      * @return int
235 235
      */
236
-    public function get_original_payment_id( $context = 'view' ) {
237
-        return $this->get_parent_invoice_id( $context );
236
+    public function get_original_payment_id($context = 'view') {
237
+        return $this->get_parent_invoice_id($context);
238 238
     }
239 239
 
240 240
 	/**
@@ -244,8 +244,8 @@  discard block
 block discarded – undo
244 244
 	 * @param  string $context View or edit context.
245 245
 	 * @return WPInv_Invoice
246 246
 	 */
247
-	public function get_parent_invoice( $context = 'view' ) {
248
-		return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
247
+	public function get_parent_invoice($context = 'view') {
248
+		return new WPInv_Invoice($this->get_parent_invoice_id($context));
249 249
 	}
250 250
 
251 251
 	/**
@@ -255,8 +255,8 @@  discard block
 block discarded – undo
255 255
 	 * @param  string $context View or edit context.
256 256
 	 * @return WPInv_Invoice
257 257
 	 */
258
-    public function get_parent_payment( $context = 'view' ) {
259
-        return $this->get_parent_invoice( $context );
258
+    public function get_parent_payment($context = 'view') {
259
+        return $this->get_parent_invoice($context);
260 260
 	}
261 261
 
262 262
 	/**
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
 	 * @param  string $context View or edit context.
267 267
 	 * @return int
268 268
 	 */
269
-	public function get_product_id( $context = 'view' ) {
270
-		return (int) $this->get_prop( 'product_id', $context );
269
+	public function get_product_id($context = 'view') {
270
+		return (int) $this->get_prop('product_id', $context);
271 271
 	}
272 272
 
273 273
 	/**
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
 	 * @param  string $context View or edit context.
278 278
 	 * @return WPInv_Item
279 279
 	 */
280
-	public function get_product( $context = 'view' ) {
281
-		return new WPInv_Item( $this->get_product_id( $context ) );
280
+	public function get_product($context = 'view') {
281
+		return new WPInv_Item($this->get_product_id($context));
282 282
 	}
283 283
 
284 284
 	/**
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
 	 * @param  string $context View or edit context.
291 291
 	 * @return string
292 292
 	 */
293
-	public function get_gateway( $context = 'view' ) {
294
-		return $this->get_parent_invoice( $context )->get_gateway();
293
+	public function get_gateway($context = 'view') {
294
+		return $this->get_parent_invoice($context)->get_gateway();
295 295
 	}
296 296
 
297 297
 	/**
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
 	 * @param  string $context View or edit context.
302 302
 	 * @return string
303 303
 	 */
304
-	public function get_period( $context = 'view' ) {
305
-		return $this->get_prop( 'period', $context );
304
+	public function get_period($context = 'view') {
305
+		return $this->get_prop('period', $context);
306 306
 	}
307 307
 
308 308
 	/**
@@ -312,8 +312,8 @@  discard block
 block discarded – undo
312 312
 	 * @param  string $context View or edit context.
313 313
 	 * @return int
314 314
 	 */
315
-	public function get_frequency( $context = 'view' ) {
316
-		return (int) $this->get_prop( 'frequency', $context );
315
+	public function get_frequency($context = 'view') {
316
+		return (int) $this->get_prop('frequency', $context);
317 317
 	}
318 318
 
319 319
 	/**
@@ -323,8 +323,8 @@  discard block
 block discarded – undo
323 323
 	 * @param  string $context View or edit context.
324 324
 	 * @return float
325 325
 	 */
326
-	public function get_initial_amount( $context = 'view' ) {
327
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
326
+	public function get_initial_amount($context = 'view') {
327
+		return (float) wpinv_sanitize_amount($this->get_prop('initial_amount', $context));
328 328
 	}
329 329
 
330 330
 	/**
@@ -334,8 +334,8 @@  discard block
 block discarded – undo
334 334
 	 * @param  string $context View or edit context.
335 335
 	 * @return float
336 336
 	 */
337
-	public function get_recurring_amount( $context = 'view' ) {
338
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
337
+	public function get_recurring_amount($context = 'view') {
338
+		return (float) wpinv_sanitize_amount($this->get_prop('recurring_amount', $context));
339 339
 	}
340 340
 
341 341
 	/**
@@ -345,8 +345,8 @@  discard block
 block discarded – undo
345 345
 	 * @param  string $context View or edit context.
346 346
 	 * @return int
347 347
 	 */
348
-	public function get_bill_times( $context = 'view' ) {
349
-		return (int) $this->get_prop( 'bill_times', $context );
348
+	public function get_bill_times($context = 'view') {
349
+		return (int) $this->get_prop('bill_times', $context);
350 350
 	}
351 351
 
352 352
 	/**
@@ -356,8 +356,8 @@  discard block
 block discarded – undo
356 356
 	 * @param  string $context View or edit context.
357 357
 	 * @return string
358 358
 	 */
359
-	public function get_transaction_id( $context = 'view' ) {
360
-		return $this->get_prop( 'transaction_id', $context );
359
+	public function get_transaction_id($context = 'view') {
360
+		return $this->get_prop('transaction_id', $context);
361 361
 	}
362 362
 
363 363
 	/**
@@ -367,8 +367,8 @@  discard block
 block discarded – undo
367 367
 	 * @param  string $context View or edit context.
368 368
 	 * @return string
369 369
 	 */
370
-	public function get_created( $context = 'view' ) {
371
-		return $this->get_prop( 'created', $context );
370
+	public function get_created($context = 'view') {
371
+		return $this->get_prop('created', $context);
372 372
 	}
373 373
 
374 374
 	/**
@@ -378,8 +378,8 @@  discard block
 block discarded – undo
378 378
 	 * @param  string $context View or edit context.
379 379
 	 * @return string
380 380
 	 */
381
-	public function get_date_created( $context = 'view' ) {
382
-		return $this->get_created( $context );
381
+	public function get_date_created($context = 'view') {
382
+		return $this->get_created($context);
383 383
 	}
384 384
 
385 385
 	/**
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
 	 */
391 391
 	public function get_time_created() {
392 392
 		$created = $this->get_date_created();
393
-		return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
393
+		return empty($created) ? current_time('timestamp') : strtotime($created, current_time('timestamp'));
394 394
 	}
395 395
 
396 396
 	/**
@@ -400,11 +400,11 @@  discard block
 block discarded – undo
400 400
 	 * @param  string $context View or edit context.
401 401
 	 * @return string
402 402
 	 */
403
-	public function get_date_created_gmt( $context = 'view' ) {
404
-        $date = $this->get_date_created( $context );
403
+	public function get_date_created_gmt($context = 'view') {
404
+        $date = $this->get_date_created($context);
405 405
 
406
-        if ( $date ) {
407
-            $date = get_gmt_from_date( $date );
406
+        if ($date) {
407
+            $date = get_gmt_from_date($date);
408 408
         }
409 409
 		return $date;
410 410
 	}
@@ -416,8 +416,8 @@  discard block
 block discarded – undo
416 416
 	 * @param  string $context View or edit context.
417 417
 	 * @return string
418 418
 	 */
419
-	public function get_next_renewal_date( $context = 'view' ) {
420
-		return $this->get_prop( 'expiration', $context );
419
+	public function get_next_renewal_date($context = 'view') {
420
+		return $this->get_prop('expiration', $context);
421 421
 	}
422 422
 
423 423
 	/**
@@ -427,8 +427,8 @@  discard block
 block discarded – undo
427 427
 	 * @param  string $context View or edit context.
428 428
 	 * @return string
429 429
 	 */
430
-	public function get_expiration( $context = 'view' ) {
431
-		return $this->get_next_renewal_date( $context );
430
+	public function get_expiration($context = 'view') {
431
+		return $this->get_next_renewal_date($context);
432 432
 	}
433 433
 
434 434
 	/**
@@ -440,12 +440,12 @@  discard block
 block discarded – undo
440 440
 	public function get_expiration_time() {
441 441
 		$expiration = $this->get_expiration();
442 442
 
443
-		if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
444
-			return current_time( 'timestamp' );
443
+		if (empty($expiration) || '0000-00-00 00:00:00' == $expiration) {
444
+			return current_time('timestamp');
445 445
 		}
446 446
 
447
-		$expiration = strtotime( $expiration, current_time( 'timestamp' ) );
448
-		return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
447
+		$expiration = strtotime($expiration, current_time('timestamp'));
448
+		return $expiration < current_time('timestamp') ? current_time('timestamp') : $expiration;
449 449
 	}
450 450
 
451 451
 	/**
@@ -455,11 +455,11 @@  discard block
 block discarded – undo
455 455
 	 * @param  string $context View or edit context.
456 456
 	 * @return string
457 457
 	 */
458
-	public function get_next_renewal_date_gmt( $context = 'view' ) {
459
-        $date = $this->get_next_renewal_date( $context );
458
+	public function get_next_renewal_date_gmt($context = 'view') {
459
+        $date = $this->get_next_renewal_date($context);
460 460
 
461
-        if ( $date ) {
462
-            $date = get_gmt_from_date( $date );
461
+        if ($date) {
462
+            $date = get_gmt_from_date($date);
463 463
         }
464 464
 		return $date;
465 465
 	}
@@ -471,8 +471,8 @@  discard block
 block discarded – undo
471 471
 	 * @param  string $context View or edit context.
472 472
 	 * @return string
473 473
 	 */
474
-	public function get_trial_period( $context = 'view' ) {
475
-		return $this->get_prop( 'trial_period', $context );
474
+	public function get_trial_period($context = 'view') {
475
+		return $this->get_prop('trial_period', $context);
476 476
 	}
477 477
 
478 478
 	/**
@@ -482,8 +482,8 @@  discard block
 block discarded – undo
482 482
 	 * @param  string $context View or edit context.
483 483
 	 * @return string
484 484
 	 */
485
-	public function get_status( $context = 'view' ) {
486
-		return $this->get_prop( 'status', $context );
485
+	public function get_status($context = 'view') {
486
+		return $this->get_prop('status', $context);
487 487
 	}
488 488
 
489 489
 	/**
@@ -493,8 +493,8 @@  discard block
 block discarded – undo
493 493
 	 * @param  string $context View or edit context.
494 494
 	 * @return string
495 495
 	 */
496
-	public function get_profile_id( $context = 'view' ) {
497
-		return $this->get_prop( 'profile_id', $context );
496
+	public function get_profile_id($context = 'view') {
497
+		return $this->get_prop('profile_id', $context);
498 498
 	}
499 499
 
500 500
 	/*
@@ -509,8 +509,8 @@  discard block
 block discarded – undo
509 509
 	 * @since 1.0.19
510 510
 	 * @param  int $value The customer's id.
511 511
 	 */
512
-	public function set_customer_id( $value ) {
513
-		$this->set_prop( 'customer_id', (int) $value );
512
+	public function set_customer_id($value) {
513
+		$this->set_prop('customer_id', (int) $value);
514 514
 	}
515 515
 
516 516
 	/**
@@ -519,8 +519,8 @@  discard block
 block discarded – undo
519 519
 	 * @since 1.0.19
520 520
 	 * @param  int $value The parent invoice id.
521 521
 	 */
522
-	public function set_parent_invoice_id( $value ) {
523
-		$this->set_prop( 'parent_payment_id', (int) $value );
522
+	public function set_parent_invoice_id($value) {
523
+		$this->set_prop('parent_payment_id', (int) $value);
524 524
 	}
525 525
 
526 526
 	/**
@@ -529,8 +529,8 @@  discard block
 block discarded – undo
529 529
 	 * @since 1.0.19
530 530
 	 * @param  int $value The parent invoice id.
531 531
 	 */
532
-    public function set_parent_payment_id( $value ) {
533
-        $this->set_parent_invoice_id( $value );
532
+    public function set_parent_payment_id($value) {
533
+        $this->set_parent_invoice_id($value);
534 534
 	}
535 535
 
536 536
 	/**
@@ -539,8 +539,8 @@  discard block
 block discarded – undo
539 539
      * @since 1.0.19
540 540
 	 * @param  int $value The parent invoice id.
541 541
      */
542
-    public function set_original_payment_id( $value ) {
543
-        $this->set_parent_invoice_id( $value );
542
+    public function set_original_payment_id($value) {
543
+        $this->set_parent_invoice_id($value);
544 544
 	}
545 545
 
546 546
 	/**
@@ -549,8 +549,8 @@  discard block
 block discarded – undo
549 549
 	 * @since 1.0.19
550 550
 	 * @param  int $value The subscription product id.
551 551
 	 */
552
-	public function set_product_id( $value ) {
553
-		$this->set_prop( 'product_id', (int) $value );
552
+	public function set_product_id($value) {
553
+		$this->set_prop('product_id', (int) $value);
554 554
 	}
555 555
 
556 556
 	/**
@@ -559,8 +559,8 @@  discard block
 block discarded – undo
559 559
 	 * @since 1.0.19
560 560
 	 * @param  string $value The renewal period.
561 561
 	 */
562
-	public function set_period( $value ) {
563
-		$this->set_prop( 'period', $value );
562
+	public function set_period($value) {
563
+		$this->set_prop('period', $value);
564 564
 	}
565 565
 
566 566
 	/**
@@ -569,9 +569,9 @@  discard block
 block discarded – undo
569 569
 	 * @since 1.0.19
570 570
 	 * @param  int $value The subscription frequency.
571 571
 	 */
572
-	public function set_frequency( $value ) {
573
-		$value = empty( $value ) ? 1 : (int) $value;
574
-		$this->set_prop( 'frequency', absint( $value ) );
572
+	public function set_frequency($value) {
573
+		$value = empty($value) ? 1 : (int) $value;
574
+		$this->set_prop('frequency', absint($value));
575 575
 	}
576 576
 
577 577
 	/**
@@ -580,8 +580,8 @@  discard block
 block discarded – undo
580 580
 	 * @since 1.0.19
581 581
 	 * @param  float $value The initial subcription amount.
582 582
 	 */
583
-	public function set_initial_amount( $value ) {
584
-		$this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
583
+	public function set_initial_amount($value) {
584
+		$this->set_prop('initial_amount', wpinv_sanitize_amount($value));
585 585
 	}
586 586
 
587 587
 	/**
@@ -590,8 +590,8 @@  discard block
 block discarded – undo
590 590
 	 * @since 1.0.19
591 591
 	 * @param  float $value The recurring subcription amount.
592 592
 	 */
593
-	public function set_recurring_amount( $value ) {
594
-		$this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
593
+	public function set_recurring_amount($value) {
594
+		$this->set_prop('recurring_amount', wpinv_sanitize_amount($value));
595 595
 	}
596 596
 
597 597
 	/**
@@ -600,8 +600,8 @@  discard block
 block discarded – undo
600 600
 	 * @since 1.0.19
601 601
 	 * @param  int $value Bill times.
602 602
 	 */
603
-	public function set_bill_times( $value ) {
604
-		$this->set_prop( 'bill_times', (int) $value );
603
+	public function set_bill_times($value) {
604
+		$this->set_prop('bill_times', (int) $value);
605 605
 	}
606 606
 
607 607
 	/**
@@ -610,8 +610,8 @@  discard block
 block discarded – undo
610 610
 	 * @since 1.0.19
611 611
 	 * @param string $value Bill times.
612 612
 	 */
613
-	public function set_transaction_id( $value ) {
614
-		$this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
613
+	public function set_transaction_id($value) {
614
+		$this->set_prop('transaction_id', sanitize_text_field($value));
615 615
 	}
616 616
 
617 617
 	/**
@@ -620,15 +620,15 @@  discard block
 block discarded – undo
620 620
 	 * @since 1.0.19
621 621
 	 * @param string $value strtotime compliant date.
622 622
 	 */
623
-	public function set_created( $value ) {
624
-        $date = strtotime( $value );
623
+	public function set_created($value) {
624
+        $date = strtotime($value);
625 625
 
626
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
627
-            $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) );
626
+        if ($date && $value !== '0000-00-00 00:00:00') {
627
+            $this->set_prop('created', date('Y-m-d H:i:s', $date));
628 628
             return;
629 629
         }
630 630
 
631
-		$this->set_prop( 'created', '' );
631
+		$this->set_prop('created', '');
632 632
 
633 633
 	}
634 634
 
@@ -638,8 +638,8 @@  discard block
 block discarded – undo
638 638
 	 * @since 1.0.19
639 639
 	 * @param string $value strtotime compliant date.
640 640
 	 */
641
-	public function set_date_created( $value ) {
642
-		$this->set_created( $value );
641
+	public function set_date_created($value) {
642
+		$this->set_created($value);
643 643
     }
644 644
 
645 645
 	/**
@@ -648,15 +648,15 @@  discard block
 block discarded – undo
648 648
 	 * @since 1.0.19
649 649
 	 * @param string $value strtotime compliant date.
650 650
 	 */
651
-	public function set_next_renewal_date( $value ) {
652
-		$date = strtotime( $value );
651
+	public function set_next_renewal_date($value) {
652
+		$date = strtotime($value);
653 653
 
654
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
655
-            $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
654
+        if ($date && $value !== '0000-00-00 00:00:00') {
655
+            $this->set_prop('expiration', date('Y-m-d H:i:s', $date));
656 656
             return;
657 657
 		}
658 658
 
659
-		$this->set_prop( 'expiration', '' );
659
+		$this->set_prop('expiration', '');
660 660
 
661 661
 	}
662 662
 
@@ -666,8 +666,8 @@  discard block
 block discarded – undo
666 666
 	 * @since 1.0.19
667 667
 	 * @param string $value strtotime compliant date.
668 668
 	 */
669
-	public function set_expiration( $value ) {
670
-		$this->set_next_renewal_date( $value );
669
+	public function set_expiration($value) {
670
+		$this->set_next_renewal_date($value);
671 671
     }
672 672
 
673 673
 	/**
@@ -676,8 +676,8 @@  discard block
 block discarded – undo
676 676
 	 * @since 1.0.19
677 677
 	 * @param string $value trial period e.g 1 year.
678 678
 	 */
679
-	public function set_trial_period( $value ) {
680
-		$this->set_prop( 'trial_period', $value );
679
+	public function set_trial_period($value) {
680
+		$this->set_prop('trial_period', $value);
681 681
 	}
682 682
 
683 683
 	/**
@@ -686,22 +686,22 @@  discard block
 block discarded – undo
686 686
 	 * @since 1.0.19
687 687
 	 * @param string $new_status    New subscription status.
688 688
 	 */
689
-	public function set_status( $new_status ) {
689
+	public function set_status($new_status) {
690 690
 
691 691
 		// Abort if this is not a valid status;
692
-		if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
692
+		if (!array_key_exists($new_status, getpaid_get_subscription_statuses())) {
693 693
 			return;
694 694
 		}
695 695
 
696
-		$old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status();
697
-		if ( true === $this->object_read && $old_status !== $new_status ) {
696
+		$old_status = !empty($this->status_transition['from']) ? $this->status_transition['from'] : $this->get_status();
697
+		if (true === $this->object_read && $old_status !== $new_status) {
698 698
 			$this->status_transition = array(
699 699
 				'from' => $old_status,
700 700
 				'to'   => $new_status,
701 701
 			);
702 702
 		}
703 703
 
704
-		$this->set_prop( 'status', $new_status );
704
+		$this->set_prop('status', $new_status);
705 705
 	}
706 706
 
707 707
 	/**
@@ -710,8 +710,8 @@  discard block
 block discarded – undo
710 710
 	 * @since 1.0.19
711 711
 	 * @param  string $value the remote profile id.
712 712
 	 */
713
-	public function set_profile_id( $value ) {
714
-		$this->set_prop( 'profile_id', sanitize_text_field( $value ) );
713
+	public function set_profile_id($value) {
714
+		$this->set_prop('profile_id', sanitize_text_field($value));
715 715
 	}
716 716
 
717 717
 	/*
@@ -729,8 +729,8 @@  discard block
 block discarded – undo
729 729
 	 * @param string|array String or array of strings to check for.
730 730
 	 * @return bool
731 731
      */
732
-    public function has_status( $status ) {
733
-        return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) );
732
+    public function has_status($status) {
733
+        return in_array($this->get_status(), wpinv_clean(wpinv_parse_list($status)));
734 734
 	}
735 735
 
736 736
 	/**
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
      */
741 741
     public function has_trial_period() {
742 742
 		$period = $this->get_trial_period();
743
-        return ! empty( $period );
743
+        return !empty($period);
744 744
 	}
745 745
 
746 746
 	/**
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
 	 * @return bool
750 750
 	 */
751 751
 	public function is_active() {
752
-		return $this->has_status( 'active trialling' ) && ! $this->is_expired();
752
+		return $this->has_status('active trialling') && !$this->is_expired();
753 753
 	}
754 754
 
755 755
 	/**
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
 	 * @return bool
759 759
 	 */
760 760
 	public function is_expired() {
761
-		return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) );
761
+		return $this->has_status('expired') || ($this->has_status('active cancelled trialling') && $this->get_expiration_time() < current_time('timestamp'));
762 762
 	}
763 763
 
764 764
 	/**
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
 	 */
769 769
 	public function is_last_renewal() {
770 770
 		$max_bills = $this->get_bill_times();
771
-		return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
771
+		return !empty($max_bills) && $max_bills <= $this->get_times_billed();
772 772
 	}
773 773
 
774 774
 	/*
@@ -783,11 +783,11 @@  discard block
 block discarded – undo
783 783
 	/**
784 784
 	 * Backwards compatibilty.
785 785
 	 */
786
-	public function create( $data = array() ) {
786
+	public function create($data = array()) {
787 787
 
788 788
 		// Set the properties.
789
-		if ( is_array( $data ) ) {
790
-			$this->set_props( $data );
789
+		if (is_array($data)) {
790
+			$this->set_props($data);
791 791
 		}
792 792
 
793 793
 		// Save the item.
@@ -798,8 +798,8 @@  discard block
 block discarded – undo
798 798
 	/**
799 799
 	 * Backwards compatibilty.
800 800
 	 */
801
-	public function update( $args = array() ) {
802
-		return $this->create( $args );
801
+	public function update($args = array()) {
802
+		return $this->create($args);
803 803
 	}
804 804
 
805 805
     /**
@@ -808,12 +808,12 @@  discard block
 block discarded – undo
808 808
      * @since  1.0.0
809 809
      * @return WP_Post[]
810 810
      */
811
-    public function get_child_payments( $hide_pending = true ) {
811
+    public function get_child_payments($hide_pending = true) {
812 812
 
813
-		$statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
813
+		$statuses = array('publish', 'wpi-processing', 'wpi-renewal');
814 814
 
815
-		if ( ! $hide_pending ) {
816
-			$statuses = array_keys( wpinv_get_invoice_statuses() );
815
+		if (!$hide_pending) {
816
+			$statuses = array_keys(wpinv_get_invoice_statuses());
817 817
 		}
818 818
 
819 819
         return get_posts(
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
      * @return int
836 836
      */
837 837
     public function get_total_payments() {
838
-		return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() );
838
+		return getpaid_count_subscription_invoices($this->get_parent_invoice_id(), $this->get_id());
839 839
     }
840 840
 
841 841
     /**
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
     public function get_times_billed() {
848 848
         $times_billed = $this->get_total_payments();
849 849
 
850
-        if ( (float) $this->get_initial_amount() == 0 && $times_billed > 0 ) {
850
+        if ((float) $this->get_initial_amount() == 0 && $times_billed > 0) {
851 851
             $times_billed--;
852 852
         }
853 853
 
@@ -862,48 +862,48 @@  discard block
 block discarded – undo
862 862
 	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
863 863
      * @return bool
864 864
      */
865
-    public function add_payment( $args = array(), $invoice = false ) {
865
+    public function add_payment($args = array(), $invoice = false) {
866 866
 
867 867
 		// Process each payment once.
868
-        if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
868
+        if (!empty($args['transaction_id']) && $this->payment_exists($args['transaction_id'])) {
869 869
             return false;
870 870
         }
871 871
 
872 872
 		// Are we creating a new invoice?
873
-		if ( empty( $invoice ) ) {
873
+		if (empty($invoice)) {
874 874
 			$invoice = $this->create_payment();
875 875
 
876
-			if ( empty( $invoice ) ) {
876
+			if (empty($invoice)) {
877 877
 				return false;
878 878
 			}
879 879
 }
880 880
 
881
-		$invoice->set_status( 'wpi-renewal' );
881
+		$invoice->set_status('wpi-renewal');
882 882
 
883 883
 		// Maybe set a transaction id.
884
-		if ( ! empty( $args['transaction_id'] ) ) {
885
-			$invoice->set_transaction_id( $args['transaction_id'] );
884
+		if (!empty($args['transaction_id'])) {
885
+			$invoice->set_transaction_id($args['transaction_id']);
886 886
 		}
887 887
 
888 888
 		// Set the completed date.
889
-		$invoice->set_completed_date( current_time( 'mysql' ) );
889
+		$invoice->set_completed_date(current_time('mysql'));
890 890
 
891 891
 		// And the gateway.
892
-		if ( ! empty( $args['gateway'] ) ) {
893
-			$invoice->set_gateway( $args['gateway'] );
892
+		if (!empty($args['gateway'])) {
893
+			$invoice->set_gateway($args['gateway']);
894 894
 		}
895 895
 
896 896
 		$invoice->save();
897 897
 
898
-		if ( ! $invoice->exists() ) {
898
+		if (!$invoice->exists()) {
899 899
 			return false;
900 900
 		}
901 901
 
902
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
903
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
904
-        do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
902
+		do_action('getpaid_after_create_subscription_renewal_invoice', $invoice, $this);
903
+		do_action('wpinv_recurring_add_subscription_payment', $invoice, $this);
904
+        do_action('wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id());
905 905
 
906
-        update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
906
+        update_post_meta($invoice->get_id(), '_wpinv_subscription_id', $this->id);
907 907
 
908 908
         return $invoice->get_id();
909 909
 	}
@@ -918,41 +918,41 @@  discard block
 block discarded – undo
918 918
 
919 919
 		$parent_invoice = $this->get_parent_payment();
920 920
 
921
-		if ( ! $parent_invoice->exists() ) {
921
+		if (!$parent_invoice->exists()) {
922 922
 			return false;
923 923
 		}
924 924
 
925 925
 		// Duplicate the parent invoice.
926
-		$invoice = getpaid_duplicate_invoice( $parent_invoice );
927
-		$invoice->set_parent_id( $parent_invoice->get_id() );
928
-		$invoice->set_subscription_id( $this->get_id() );
929
-		$invoice->set_remote_subscription_id( $this->get_profile_id() );
926
+		$invoice = getpaid_duplicate_invoice($parent_invoice);
927
+		$invoice->set_parent_id($parent_invoice->get_id());
928
+		$invoice->set_subscription_id($this->get_id());
929
+		$invoice->set_remote_subscription_id($this->get_profile_id());
930 930
 
931 931
 		// Set invoice items.
932
-		$subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() );
933
-		$allowed_items      = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] );
932
+		$subscription_group = getpaid_get_invoice_subscription_group($parent_invoice->get_id(), $this->get_id());
933
+		$allowed_items      = empty($subscription_group) ? array($this->get_product_id()) : array_keys($subscription_group['items']);
934 934
 		$invoice_items      = array();
935 935
 
936
-		foreach ( $invoice->get_items() as $item ) {
937
-			if ( in_array( $item->get_id(), $allowed_items ) ) {
936
+		foreach ($invoice->get_items() as $item) {
937
+			if (in_array($item->get_id(), $allowed_items)) {
938 938
 				$invoice_items[] = $item;
939 939
 			}
940 940
 		}
941 941
 
942
-		$invoice->set_items( $invoice_items );
942
+		$invoice->set_items($invoice_items);
943 943
 
944
-		if ( ! empty( $subscription_group['fees'] ) ) {
945
-			$invoice->set_fees( $subscription_group['fees'] );
944
+		if (!empty($subscription_group['fees'])) {
945
+			$invoice->set_fees($subscription_group['fees']);
946 946
 		}
947 947
 
948 948
 		// Maybe recalculate discount (Pre-GetPaid Fix).
949
-		$discount = new WPInv_Discount( $invoice->get_discount_code() );
950
-		if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
951
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
949
+		$discount = new WPInv_Discount($invoice->get_discount_code());
950
+		if ($discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount()) {
951
+			$invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
952 952
 		}
953 953
 
954 954
 		$invoice->recalculate_total();
955
-		$invoice->set_status( 'wpi-pending' );
955
+		$invoice->set_status('wpi-pending');
956 956
 		$invoice->save();
957 957
 
958 958
 		return $invoice->exists() ? $invoice : false;
@@ -967,20 +967,20 @@  discard block
 block discarded – undo
967 967
 	public function renew() {
968 968
 
969 969
 		// Complete subscription if applicable
970
-		if ( $this->is_last_renewal() ) {
970
+		if ($this->is_last_renewal()) {
971 971
 			return $this->complete();
972 972
 		}
973 973
 
974 974
 		// Calculate new expiration
975 975
 		$frequency      = $this->get_frequency();
976 976
 		$period         = $this->get_period();
977
-		$new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
977
+		$new_expiration = strtotime("+ $frequency $period", $this->get_expiration_time());
978 978
 
979
-		$this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) );
980
-		$this->set_status( 'active' );
979
+		$this->set_expiration(date('Y-m-d H:i:s', $new_expiration));
980
+		$this->set_status('active');
981 981
 		$this->save();
982 982
 
983
-		do_action( 'getpaid_subscription_renewed', $this );
983
+		do_action('getpaid_subscription_renewed', $this);
984 984
 
985 985
 		return $this->get_id();
986 986
 	}
@@ -996,11 +996,11 @@  discard block
 block discarded – undo
996 996
 	public function complete() {
997 997
 
998 998
 		// Only mark a subscription as complete if it's not already cancelled.
999
-		if ( $this->has_status( 'cancelled' ) ) {
999
+		if ($this->has_status('cancelled')) {
1000 1000
 			return false;
1001 1001
 		}
1002 1002
 
1003
-		$this->set_status( 'completed' );
1003
+		$this->set_status('completed');
1004 1004
 		return $this->save();
1005 1005
 
1006 1006
 	}
@@ -1012,14 +1012,14 @@  discard block
 block discarded – undo
1012 1012
 	 * @param  bool $check_expiration
1013 1013
 	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1014 1014
 	 */
1015
-	public function expire( $check_expiration = false ) {
1015
+	public function expire($check_expiration = false) {
1016 1016
 
1017
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1017
+		if ($check_expiration && $this->get_expiration_time() > current_time('timestamp')) {
1018 1018
 			// Do not mark as expired since real expiration date is in the future
1019 1019
 			return false;
1020 1020
 		}
1021 1021
 
1022
-		$this->set_status( 'expired' );
1022
+		$this->set_status('expired');
1023 1023
 		return $this->save();
1024 1024
 
1025 1025
 	}
@@ -1031,7 +1031,7 @@  discard block
 block discarded – undo
1031 1031
 	 * @return int Subscription id.
1032 1032
 	 */
1033 1033
 	public function failing() {
1034
-		$this->set_status( 'failing' );
1034
+		$this->set_status('failing');
1035 1035
 		return $this->save();
1036 1036
 	}
1037 1037
 
@@ -1042,7 +1042,7 @@  discard block
 block discarded – undo
1042 1042
      * @return int Subscription id.
1043 1043
      */
1044 1044
     public function cancel() {
1045
-		$this->set_status( 'cancelled' );
1045
+		$this->set_status('cancelled');
1046 1046
 		return $this->save();
1047 1047
     }
1048 1048
 
@@ -1053,7 +1053,7 @@  discard block
 block discarded – undo
1053 1053
 	 * @return bool
1054 1054
 	 */
1055 1055
 	public function can_cancel() {
1056
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1056
+		return apply_filters('wpinv_subscription_can_cancel', $this->has_status($this->get_cancellable_statuses()), $this);
1057 1057
 	}
1058 1058
 
1059 1059
     /**
@@ -1064,7 +1064,7 @@  discard block
 block discarded – undo
1064 1064
      * @return      array
1065 1065
      */
1066 1066
     public function get_cancellable_statuses() {
1067
-        return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1067
+        return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing'));
1068 1068
     }
1069 1069
 
1070 1070
 	/**
@@ -1074,8 +1074,8 @@  discard block
 block discarded – undo
1074 1074
 	 * @return string
1075 1075
 	 */
1076 1076
 	public function get_cancel_url() {
1077
-		$url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1078
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1077
+		$url = getpaid_get_authenticated_action_url('subscription_cancel', $this->get_view_url());
1078
+		return apply_filters('wpinv_subscription_cancel_url', $url, $this);
1079 1079
 	}
1080 1080
 
1081 1081
 	/**
@@ -1086,10 +1086,10 @@  discard block
 block discarded – undo
1086 1086
 	 */
1087 1087
 	public function get_view_url() {
1088 1088
 
1089
-		$url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1090
-		$url = add_query_arg( 'subscription', $this->get_id(), $url );
1089
+		$url = getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page')));
1090
+		$url = add_query_arg('subscription', $this->get_id(), $url);
1091 1091
 
1092
-		return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1092
+		return apply_filters('getpaid_get_subscription_view_url', $url, $this);
1093 1093
 	}
1094 1094
 
1095 1095
 	/**
@@ -1102,7 +1102,7 @@  discard block
 block discarded – undo
1102 1102
 	 * @return bool
1103 1103
 	 */
1104 1104
 	public function can_renew() {
1105
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1105
+		return apply_filters('wpinv_subscription_can_renew', true, $this);
1106 1106
 	}
1107 1107
 
1108 1108
 	/**
@@ -1121,7 +1121,7 @@  discard block
 block discarded – undo
1121 1121
             ),
1122 1122
             'getpaid-nonce'
1123 1123
         );
1124
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1124
+		return apply_filters('wpinv_subscription_renew_url', $url, $this);
1125 1125
 	}
1126 1126
 
1127 1127
 	/**
@@ -1131,7 +1131,7 @@  discard block
 block discarded – undo
1131 1131
 	 * @return bool
1132 1132
 	 */
1133 1133
 	public function can_update() {
1134
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1134
+		return apply_filters('wpinv_subscription_can_update', false, $this);
1135 1135
 	}
1136 1136
 
1137 1137
 	/**
@@ -1147,7 +1147,7 @@  discard block
 block discarded – undo
1147 1147
 				'subscription_id' => $this->get_id(),
1148 1148
             )
1149 1149
         );
1150
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1150
+		return apply_filters('wpinv_subscription_update_url', $url, $this);
1151 1151
 	}
1152 1152
 
1153 1153
 	/**
@@ -1157,7 +1157,7 @@  discard block
 block discarded – undo
1157 1157
 	 * @return string
1158 1158
 	 */
1159 1159
 	public function get_status_label() {
1160
-		return getpaid_get_subscription_status_label( $this->get_status() );
1160
+		return getpaid_get_subscription_status_label($this->get_status());
1161 1161
 	}
1162 1162
 
1163 1163
 	/**
@@ -1168,7 +1168,7 @@  discard block
 block discarded – undo
1168 1168
 	 */
1169 1169
 	public function get_status_class() {
1170 1170
 		$statuses = getpaid_get_subscription_status_classes();
1171
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark';
1171
+		return isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : 'badge-dark';
1172 1172
 	}
1173 1173
 
1174 1174
     /**
@@ -1179,9 +1179,9 @@  discard block
 block discarded – undo
1179 1179
      */
1180 1180
     public function get_status_label_html() {
1181 1181
 
1182
-		$status_label = sanitize_text_field( $this->get_status_label() );
1183
-		$class        = esc_attr( $this->get_status_class() );
1184
-		$status       = sanitize_html_class( $this->get_status() );
1182
+		$status_label = sanitize_text_field($this->get_status_label());
1183
+		$class        = esc_attr($this->get_status_class());
1184
+		$status       = sanitize_html_class($this->get_status());
1185 1185
 
1186 1186
 		return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1187 1187
     }
@@ -1193,9 +1193,9 @@  discard block
 block discarded – undo
1193 1193
      * @param  string $txn_id The transaction ID from the merchant processor
1194 1194
      * @return bool
1195 1195
      */
1196
-    public function payment_exists( $txn_id = '' ) {
1197
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1198
-        return ! empty( $invoice_id );
1196
+    public function payment_exists($txn_id = '') {
1197
+		$invoice_id = WPInv_Invoice::get_invoice_id_by_field($txn_id, 'transaction_id');
1198
+        return !empty($invoice_id);
1199 1199
 	}
1200 1200
 
1201 1201
 	/**
@@ -1207,35 +1207,35 @@  discard block
 block discarded – undo
1207 1207
 		// Reset status transition variable.
1208 1208
 		$this->status_transition = false;
1209 1209
 
1210
-		if ( $status_transition ) {
1210
+		if ($status_transition) {
1211 1211
 			try {
1212 1212
 
1213 1213
 				// Fire a hook for the status change.
1214
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1215
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1214
+				do_action('wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition);
1215
+				do_action('getpaid_subscription_' . $status_transition['to'], $this, $status_transition);
1216 1216
 
1217
-				if ( ! empty( $status_transition['from'] ) ) {
1217
+				if (!empty($status_transition['from'])) {
1218 1218
 
1219 1219
 					/* translators: 1: old subscription status 2: new subscription status */
1220
-					$transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1220
+					$transition_note = sprintf(__('Subscription status changed from %1$s to %2$s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['from']), getpaid_get_subscription_status_label($status_transition['to']));
1221 1221
 
1222 1222
 					// Note the transition occurred.
1223
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1223
+					$this->get_parent_payment()->add_note($transition_note, false, false, true);
1224 1224
 
1225 1225
 					// Fire another hook.
1226
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1227
-					do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1226
+					do_action('getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this);
1227
+					do_action('getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to']);
1228 1228
 
1229 1229
 				} else {
1230 1230
 					/* translators: %s: new invoice status */
1231
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1231
+					$transition_note = sprintf(__('Subscription status set to %s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['to']));
1232 1232
 
1233 1233
 					// Note the transition occurred.
1234
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1234
+					$this->get_parent_payment()->add_note($transition_note, false, false, true);
1235 1235
 
1236 1236
 				}
1237
-			} catch ( Exception $e ) {
1238
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1237
+			} catch (Exception $e) {
1238
+				$this->get_parent_payment()->add_note(__('Error during subscription status transition.', 'invoicing') . ' ' . $e->getMessage());
1239 1239
 			}
1240 1240
 		}
1241 1241
 
@@ -1261,7 +1261,7 @@  discard block
 block discarded – undo
1261 1261
 	 */
1262 1262
 	public function activate() {
1263 1263
 		$status = 'trialling' == $this->get_status() ? 'trialling' : 'active';
1264
-		$this->set_status( $status );
1264
+		$this->set_status($status);
1265 1265
 		return $this->save();
1266 1266
 	}
1267 1267
 
Please login to merge, or discard this patch.
includes/class-wpinv-cache-helper.php 1 patch
Spacing   +36 added lines, -36 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,18 +14,18 @@  discard block
 block discarded – undo
14 14
      * Hook in methods.
15 15
      */
16 16
     public static function init() {
17
-        add_action( 'init', array( __CLASS__, 'init_hooks' ), 0 );
18
-        add_action( 'admin_notices', array( __CLASS__, 'notices' ) );
17
+        add_action('init', array(__CLASS__, 'init_hooks'), 0);
18
+        add_action('admin_notices', array(__CLASS__, 'notices'));
19 19
     }
20 20
 
21 21
     public static function init_hooks() {
22
-        if ( false === ( $page_uris = get_transient( 'wpinv_cache_excluded_uris' ) ) ) {
23
-            $checkout_page = wpinv_get_option( 'checkout_page', '' );
24
-            $success_page  = wpinv_get_option( 'success_page', '' );
25
-            $failure_page  = wpinv_get_option( 'failure_page', '' );
26
-            $history_page  = wpinv_get_option( 'invoice_history_page', '' );
27
-            $subscr_page   = wpinv_get_option( 'invoice_subscription_page', '' );
28
-            if ( empty( $checkout_page ) || empty( $success_page ) || empty( $failure_page ) || empty( $history_page ) || empty( $subscr_page ) ) {
22
+        if (false === ($page_uris = get_transient('wpinv_cache_excluded_uris'))) {
23
+            $checkout_page = wpinv_get_option('checkout_page', '');
24
+            $success_page  = wpinv_get_option('success_page', '');
25
+            $failure_page  = wpinv_get_option('failure_page', '');
26
+            $history_page  = wpinv_get_option('invoice_history_page', '');
27
+            $subscr_page   = wpinv_get_option('invoice_subscription_page', '');
28
+            if (empty($checkout_page) || empty($success_page) || empty($failure_page) || empty($history_page) || empty($subscr_page)) {
29 29
                 return;
30 30
             }
31 31
 
@@ -39,34 +39,34 @@  discard block
 block discarded – undo
39 39
             $page_uris[] = 'p=' . $subscr_page;
40 40
 
41 41
             // Exclude permalinks
42
-            $checkout_page  = get_post( $checkout_page );
43
-            $success_page   = get_post( $success_page );
44
-            $failure_page   = get_post( $failure_page );
45
-            $history_page   = get_post( $history_page );
46
-            $subscr_page    = get_post( $subscr_page );
42
+            $checkout_page  = get_post($checkout_page);
43
+            $success_page   = get_post($success_page);
44
+            $failure_page   = get_post($failure_page);
45
+            $history_page   = get_post($history_page);
46
+            $subscr_page    = get_post($subscr_page);
47 47
 
48
-            if ( ! is_null( $checkout_page ) ) {
48
+            if (!is_null($checkout_page)) {
49 49
                 $page_uris[] = '/' . $checkout_page->post_name;
50 50
             }
51
-            if ( ! is_null( $success_page ) ) {
51
+            if (!is_null($success_page)) {
52 52
                 $page_uris[] = '/' . $success_page->post_name;
53 53
             }
54
-            if ( ! is_null( $failure_page ) ) {
54
+            if (!is_null($failure_page)) {
55 55
                 $page_uris[] = '/' . $failure_page->post_name;
56 56
             }
57
-            if ( ! is_null( $history_page ) ) {
57
+            if (!is_null($history_page)) {
58 58
                 $page_uris[] = '/' . $history_page->post_name;
59 59
             }
60
-            if ( ! is_null( $subscr_page ) ) {
60
+            if (!is_null($subscr_page)) {
61 61
                 $page_uris[] = '/' . $subscr_page->post_name;
62 62
             }
63 63
 
64
-            set_transient( 'wpinv_cache_excluded_uris', $page_uris );
64
+            set_transient('wpinv_cache_excluded_uris', $page_uris);
65 65
         }
66 66
 
67
-        if ( is_array( $page_uris ) ) {
68
-            foreach ( $page_uris as $uri ) {
69
-                if ( strstr( $_SERVER['REQUEST_URI'], $uri ) ) {
67
+        if (is_array($page_uris)) {
68
+            foreach ($page_uris as $uri) {
69
+                if (strstr($_SERVER['REQUEST_URI'], $uri)) {
70 70
                     self::nocache();
71 71
                     break;
72 72
                 }
@@ -79,14 +79,14 @@  discard block
 block discarded – undo
79 79
      * @access private
80 80
      */
81 81
     private static function nocache() {
82
-        if ( ! defined( 'DONOTCACHEPAGE' ) ) {
83
-            define( 'DONOTCACHEPAGE', true );
82
+        if (!defined('DONOTCACHEPAGE')) {
83
+            define('DONOTCACHEPAGE', true);
84 84
         }
85
-        if ( ! defined( 'DONOTCACHEOBJECT' ) ) {
86
-            define( 'DONOTCACHEOBJECT', true );
85
+        if (!defined('DONOTCACHEOBJECT')) {
86
+            define('DONOTCACHEOBJECT', true);
87 87
         }
88
-        if ( ! defined( 'DONOTCACHEDB' ) ) {
89
-            define( 'DONOTCACHEDB', true );
88
+        if (!defined('DONOTCACHEDB')) {
89
+            define('DONOTCACHEDB', true);
90 90
         }
91 91
         nocache_headers();
92 92
     }
@@ -95,18 +95,18 @@  discard block
 block discarded – undo
95 95
      * notices function.
96 96
      */
97 97
     public static function notices() {
98
-        if ( ! function_exists( 'w3tc_pgcache_flush' ) || ! function_exists( 'w3_instance' ) ) {
98
+        if (!function_exists('w3tc_pgcache_flush') || !function_exists('w3_instance')) {
99 99
             return;
100 100
         }
101 101
 
102
-        $config   = w3_instance( 'W3_Config' );
103
-        $enabled  = $config->get_integer( 'dbcache.enabled' );
104
-        $settings = array_map( 'trim', $config->get_array( 'dbcache.reject.sql' ) );
102
+        $config   = w3_instance('W3_Config');
103
+        $enabled  = $config->get_integer('dbcache.enabled');
104
+        $settings = array_map('trim', $config->get_array('dbcache.reject.sql'));
105 105
 
106
-        if ( $enabled && ! in_array( '_wp_session_', $settings ) ) {
106
+        if ($enabled && !in_array('_wp_session_', $settings)) {
107 107
             ?>
108 108
             <div class="error">
109
-                <p><?php printf( __( 'In order for <strong>database caching</strong> to work with Invoicing you must add %1$s to the "Ignored Query Strings" option in <a href="%2$s">W3 Total Cache settings</a>.', 'invoicing' ), '<code>_wp_session_</code>', admin_url( 'admin.php?page=w3tc_dbcache' ) ); ?></p>
109
+                <p><?php printf(__('In order for <strong>database caching</strong> to work with Invoicing you must add %1$s to the "Ignored Query Strings" option in <a href="%2$s">W3 Total Cache settings</a>.', 'invoicing'), '<code>_wp_session_</code>', admin_url('admin.php?page=w3tc_dbcache')); ?></p>
110 110
             </div>
111 111
             <?php
112 112
         }
Please login to merge, or discard this patch.
includes/wpinv-email-functions.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
     $css = getpaid_get_email_css();
110 110
 
111 111
     // include css inliner
112
-	if ( ! class_exists( 'Emogrifier' ) ) {
113
-		include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php';
112
+    if ( ! class_exists( 'Emogrifier' ) ) {
113
+        include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php';
114 114
     }
115 115
 
116 116
     // Inline the css.
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
     $message = wpinv_email_style_body( $message );
190 190
     $to      = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) );
191 191
 
192
-	return $mailer->send(
192
+    return $mailer->send(
193 193
         $to,
194 194
         $subject,
195 195
         $message,
Please login to merge, or discard this patch.
Spacing   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * Please use GetPaid_Notification_Email_Sender
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /*
12 12
 |--------------------------------------------------------------------------
@@ -17,19 +17,19 @@  discard block
 block discarded – undo
17 17
 /**
18 18
  * Generates the email header.
19 19
  */
20
-function wpinv_email_header( $email_heading ) {
21
-    wpinv_get_template( 'emails/wpinv-email-header.php', compact( 'email_heading' ) );
20
+function wpinv_email_header($email_heading) {
21
+    wpinv_get_template('emails/wpinv-email-header.php', compact('email_heading'));
22 22
 }
23
-add_action( 'wpinv_email_header', 'wpinv_email_header' );
23
+add_action('wpinv_email_header', 'wpinv_email_header');
24 24
 
25 25
 
26 26
 /**
27 27
  * Generates the email footer.
28 28
  */
29 29
 function wpinv_email_footer() {
30
-    wpinv_get_template( 'emails/wpinv-email-footer.php' );
30
+    wpinv_get_template('emails/wpinv-email-footer.php');
31 31
 }
32
-add_action( 'wpinv_email_footer', 'wpinv_email_footer' );
32
+add_action('wpinv_email_footer', 'wpinv_email_footer');
33 33
 
34 34
 
35 35
 /**
@@ -39,13 +39,13 @@  discard block
 block discarded – undo
39 39
  * @param string $email_type
40 40
  * @param bool $sent_to_admin
41 41
  */
42
-function wpinv_email_invoice_details( $invoice, $email_type, $sent_to_admin ) {
42
+function wpinv_email_invoice_details($invoice, $email_type, $sent_to_admin) {
43 43
 
44
-    $args = compact( 'invoice', 'email_type', 'sent_to_admin' );
45
-    wpinv_get_template( 'emails/invoice-details.php', $args );
44
+    $args = compact('invoice', 'email_type', 'sent_to_admin');
45
+    wpinv_get_template('emails/invoice-details.php', $args);
46 46
 
47 47
 }
48
-add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 );
48
+add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3);
49 49
 
50 50
 /**
51 51
  * Display line items in emails.
@@ -54,17 +54,17 @@  discard block
 block discarded – undo
54 54
  * @param string $email_type
55 55
  * @param bool $sent_to_admin
56 56
  */
57
-function wpinv_email_invoice_items( $invoice, $email_type, $sent_to_admin ) {
57
+function wpinv_email_invoice_items($invoice, $email_type, $sent_to_admin) {
58 58
 
59 59
     // Prepare line items.
60
-    $columns = getpaid_invoice_item_columns( $invoice );
61
-    $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice );
60
+    $columns = getpaid_invoice_item_columns($invoice);
61
+    $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice);
62 62
 
63 63
     // Load the template.
64
-    wpinv_get_template( 'emails/invoice-items.php', compact( 'invoice', 'columns', 'email_type', 'sent_to_admin' ) );
64
+    wpinv_get_template('emails/invoice-items.php', compact('invoice', 'columns', 'email_type', 'sent_to_admin'));
65 65
 
66 66
 }
67
-add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 );
67
+add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3);
68 68
 
69 69
 
70 70
 /**
@@ -74,13 +74,13 @@  discard block
 block discarded – undo
74 74
  * @param string $email_type
75 75
  * @param bool $sent_to_admin
76 76
  */
77
-function wpinv_email_billing_details( $invoice, $email_type, $sent_to_admin ) {
77
+function wpinv_email_billing_details($invoice, $email_type, $sent_to_admin) {
78 78
 
79
-    $args = compact( 'invoice', 'email_type', 'sent_to_admin' );
80
-    wpinv_get_template( 'emails/wpinv-email-billing-details.php', $args );
79
+    $args = compact('invoice', 'email_type', 'sent_to_admin');
80
+    wpinv_get_template('emails/wpinv-email-billing-details.php', $args);
81 81
 
82 82
 }
83
-add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 );
83
+add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3);
84 84
 
85 85
 /**
86 86
  * Returns email css.
@@ -88,8 +88,8 @@  discard block
 block discarded – undo
88 88
  */
89 89
 function getpaid_get_email_css() {
90 90
 
91
-    $css = wpinv_get_template_html( 'emails/wpinv-email-styles.php' );
92
-    return apply_filters( 'wpinv_email_styles', $css );
91
+    $css = wpinv_get_template_html('emails/wpinv-email-styles.php');
92
+    return apply_filters('wpinv_email_styles', $css);
93 93
 
94 94
 }
95 95
 
@@ -100,26 +100,26 @@  discard block
 block discarded – undo
100 100
  * @return string
101 101
  *
102 102
  */
103
-function wpinv_email_style_body( $content ) {
103
+function wpinv_email_style_body($content) {
104 104
 
105
-    if ( ! class_exists( 'DOMDocument' ) ) {
105
+    if (!class_exists('DOMDocument')) {
106 106
         return $content;
107 107
     }
108 108
 
109 109
     $css = getpaid_get_email_css();
110 110
 
111 111
     // include css inliner
112
-	if ( ! class_exists( 'Emogrifier' ) ) {
112
+	if (!class_exists('Emogrifier')) {
113 113
 		include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php';
114 114
     }
115 115
 
116 116
     // Inline the css.
117 117
     try {
118
-        $emogrifier = new Emogrifier( $content, $css );
118
+        $emogrifier = new Emogrifier($content, $css);
119 119
         $_content   = $emogrifier->emogrify();
120 120
         $content    = $_content;
121
-    } catch ( Exception $e ) {
122
-        wpinv_error_log( $e->getMessage(), 'emogrifier' );
121
+    } catch (Exception $e) {
122
+        wpinv_error_log($e->getMessage(), 'emogrifier');
123 123
     }
124 124
 
125 125
     return $content;
@@ -128,37 +128,37 @@  discard block
 block discarded – undo
128 128
 
129 129
 // Backwards compatibility.
130 130
 function wpinv_init_transactional_emails() {
131
-    foreach ( apply_filters( 'wpinv_email_actions', array() ) as $action ) {
132
-        add_action( $action, 'wpinv_send_transactional_email', 10, 10 );
131
+    foreach (apply_filters('wpinv_email_actions', array()) as $action) {
132
+        add_action($action, 'wpinv_send_transactional_email', 10, 10);
133 133
     }
134 134
 }
135
-add_action( 'init', 'wpinv_init_transactional_emails' );
135
+add_action('init', 'wpinv_init_transactional_emails');
136 136
 
137 137
 function wpinv_send_transactional_email() {
138 138
     $args       = func_get_args();
139 139
     $function   = current_filter() . '_notification';
140
-    do_action_ref_array( $function, $args );
140
+    do_action_ref_array($function, $args);
141 141
 }
142 142
 
143 143
 function wpinv_mail_get_from_address() {
144
-    $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from', get_option( 'admin_email' ) ) );
145
-    return sanitize_email( $from_address );
144
+    $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from', get_option('admin_email')));
145
+    return sanitize_email($from_address);
146 146
 }
147 147
 
148 148
 function wpinv_mail_get_from_name() {
149
-    $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name', get_bloginfo( 'name', 'display' ) ) );
150
-    return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES );
149
+    $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name', get_bloginfo('name', 'display')));
150
+    return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES);
151 151
 }
152 152
 
153
-function wpinv_mail_admin_bcc_active( $mail_type = '' ) {
154
-    $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) );
155
-    return ( $active ? true : false );
153
+function wpinv_mail_admin_bcc_active($mail_type = '') {
154
+    $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc'));
155
+    return ($active ? true : false);
156 156
 }
157 157
 
158
-function wpinv_mail_get_content_type( $content_type = 'text/html', $email_type = 'html' ) {
159
-    $email_type = apply_filters( 'wpinv_mail_content_type', $email_type );
158
+function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') {
159
+    $email_type = apply_filters('wpinv_mail_content_type', $email_type);
160 160
 
161
-    switch ( $email_type ) {
161
+    switch ($email_type) {
162 162
         case 'html':
163 163
             $content_type = 'text/html';
164 164
             break;
@@ -183,11 +183,11 @@  discard block
 block discarded – undo
183 183
  * @param array        $attachments Any files to attach to the email.
184 184
  * @param string|array $cc An email or array of extra emails to send a copy of the email to.
185 185
  */
186
-function wpinv_mail_send( $to, $subject, $message, $deprecated, $attachments = array(), $cc = array() ) {
186
+function wpinv_mail_send($to, $subject, $message, $deprecated, $attachments = array(), $cc = array()) {
187 187
 
188 188
     $mailer  = new GetPaid_Notification_Email_Sender();
189
-    $message = wpinv_email_style_body( $message );
190
-    $to      = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) );
189
+    $message = wpinv_email_style_body($message);
190
+    $to      = array_merge(wpinv_parse_list($to), wpinv_parse_list($cc));
191 191
 
192 192
 	return $mailer->send(
193 193
         $to,
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
  * @return array
205 205
  */
206 206
 function wpinv_get_emails() {
207
-    return apply_filters( 'wpinv_get_emails', wpinv_get_data( 'email-settings' ) );
207
+    return apply_filters('wpinv_get_emails', wpinv_get_data('email-settings'));
208 208
 }
209 209
 
210 210
 /**
@@ -213,172 +213,172 @@  discard block
 block discarded – undo
213 213
  * @param array $settings
214 214
  * @return array
215 215
  */
216
-function wpinv_settings_emails( $settings = array() ) {
217
-    $settings = array_merge( $settings, wpinv_get_emails() );
218
-    return apply_filters( 'wpinv_settings_get_emails', $settings );
216
+function wpinv_settings_emails($settings = array()) {
217
+    $settings = array_merge($settings, wpinv_get_emails());
218
+    return apply_filters('wpinv_settings_get_emails', $settings);
219 219
 }
220
-add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 );
220
+add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1);
221 221
 
222 222
 /**
223 223
  * Filter email section names.
224 224
  *
225 225
  */
226
-function wpinv_settings_sections_emails( $settings ) {
227
-    foreach ( wpinv_get_emails() as $key => $email ) {
228
-        $settings[ $key ] = ! empty( $email[ 'email_' . $key . '_header' ]['name'] ) ? strip_tags( $email[ 'email_' . $key . '_header' ]['name'] ) : strip_tags( $key );
226
+function wpinv_settings_sections_emails($settings) {
227
+    foreach (wpinv_get_emails() as $key => $email) {
228
+        $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : strip_tags($key);
229 229
     }
230 230
 
231 231
     return $settings;
232 232
 }
233
-add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 );
233
+add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1);
234 234
 
235
-function wpinv_email_is_enabled( $email_type ) {
235
+function wpinv_email_is_enabled($email_type) {
236 236
     $emails = wpinv_get_emails();
237
-    $enabled = isset( $emails[ $email_type ] ) && wpinv_get_option( 'email_' . $email_type . '_active', 0 ) ? true : false;
237
+    $enabled = isset($emails[$email_type]) && wpinv_get_option('email_' . $email_type . '_active', 0) ? true : false;
238 238
 
239
-    return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type );
239
+    return apply_filters('wpinv_email_is_enabled', $enabled, $email_type);
240 240
 }
241 241
 
242
-function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) {
243
-    switch ( $email_type ) {
242
+function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) {
243
+    switch ($email_type) {
244 244
         case 'new_invoice':
245 245
         case 'cancelled_invoice':
246 246
         case 'failed_invoice':
247 247
             $recipient  = wpinv_get_admin_email();
248 248
             break;
249 249
         default:
250
-            $invoice    = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null );
251
-            $recipient  = ! empty( $invoice ) ? $invoice->get_email() : '';
250
+            $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null);
251
+            $recipient  = !empty($invoice) ? $invoice->get_email() : '';
252 252
             break;
253 253
     }
254 254
 
255
-    return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice );
255
+    return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice);
256 256
 }
257 257
 
258 258
 /**
259 259
  * Returns invoice CC recipients
260 260
  */
261
-function wpinv_email_get_cc_recipients( $email_type = '', $invoice_id = 0, $invoice = array() ) {
262
-    switch ( $email_type ) {
261
+function wpinv_email_get_cc_recipients($email_type = '', $invoice_id = 0, $invoice = array()) {
262
+    switch ($email_type) {
263 263
         case 'new_invoice':
264 264
         case 'cancelled_invoice':
265 265
         case 'failed_invoice':
266 266
             return array();
267 267
         break;
268 268
         default:
269
-            $invoice    = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null );
270
-            $recipient  = empty( $invoice ) ? '' : get_post_meta( $invoice->ID, 'wpinv_email_cc', true );
271
-            if ( empty( $recipient ) ) {
269
+            $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null);
270
+            $recipient  = empty($invoice) ? '' : get_post_meta($invoice->ID, 'wpinv_email_cc', true);
271
+            if (empty($recipient)) {
272 272
                 return array();
273 273
             }
274
-            return array_filter( array_map( 'trim', explode( ',', $recipient ) ) );
274
+            return array_filter(array_map('trim', explode(',', $recipient)));
275 275
         break;
276 276
     }
277 277
 
278 278
 }
279 279
 
280
-function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) {
281
-    $subject    = wpinv_get_option( 'email_' . $email_type . '_subject' );
282
-    $subject    = __( $subject, 'invoicing' );
280
+function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) {
281
+    $subject    = wpinv_get_option('email_' . $email_type . '_subject');
282
+    $subject    = __($subject, 'invoicing');
283 283
 
284
-    $subject    = wpinv_email_format_text( $subject, $invoice );
284
+    $subject    = wpinv_email_format_text($subject, $invoice);
285 285
 
286
-    return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice );
286
+    return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice);
287 287
 }
288 288
 
289
-function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) {
290
-    $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' );
291
-    $email_heading = __( $email_heading, 'invoicing' );
289
+function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) {
290
+    $email_heading = wpinv_get_option('email_' . $email_type . '_heading');
291
+    $email_heading = __($email_heading, 'invoicing');
292 292
 
293
-    $email_heading = wpinv_email_format_text( $email_heading, $invoice );
293
+    $email_heading = wpinv_email_format_text($email_heading, $invoice);
294 294
 
295
-    return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice );
295
+    return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice);
296 296
 }
297 297
 
298
-function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) {
299
-    $content    = wpinv_get_option( 'email_' . $email_type . '_body' );
300
-    $content    = __( $content, 'invoicing' );
298
+function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) {
299
+    $content    = wpinv_get_option('email_' . $email_type . '_body');
300
+    $content    = __($content, 'invoicing');
301 301
 
302
-    $content    = wpinv_email_format_text( $content, $invoice );
302
+    $content    = wpinv_email_format_text($content, $invoice);
303 303
 
304
-    return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice );
304
+    return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice);
305 305
 }
306 306
 
307
-function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) {
307
+function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) {
308 308
     $from_name = wpinv_mail_get_from_address();
309 309
     $from_email = wpinv_mail_get_from_address();
310 310
 
311
-    $invoice    = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null );
311
+    $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null);
312 312
 
313
-    $headers    = 'From: ' . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
313
+    $headers    = 'From: ' . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n";
314 314
     $headers    .= 'Reply-To: ' . $from_email . "\r\n";
315 315
     $headers    .= 'Content-Type: ' . wpinv_mail_get_content_type() . "\r\n";
316 316
 
317
-    return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice );
317
+    return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice);
318 318
 }
319 319
 
320
-function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) {
320
+function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) {
321 321
     $attachments = array();
322 322
 
323
-    return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice );
323
+    return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice);
324 324
 }
325 325
 
326 326
 /**
327 327
  * Searches for and replaces certain placeholders in an email.
328 328
  */
329
-function wpinv_email_format_text( $content, $invoice ) {
329
+function wpinv_email_format_text($content, $invoice) {
330 330
 
331 331
     $replace_array = array(
332 332
         '{site_title}' => wpinv_get_blogname(),
333
-        '{date}'       => getpaid_format_date( current_time( 'mysql' ) ),
333
+        '{date}'       => getpaid_format_date(current_time('mysql')),
334 334
     );
335 335
 
336
-    $invoice = new WPInv_Invoice( $invoice );
336
+    $invoice = new WPInv_Invoice($invoice);
337 337
 
338
-    if ( $invoice->get_id() ) {
338
+    if ($invoice->get_id()) {
339 339
 
340 340
         $replace_array = array_merge(
341 341
             $replace_array,
342 342
             array(
343
-                '{name}'             => sanitize_text_field( $invoice->get_user_full_name() ),
344
-                '{full_name}'        => sanitize_text_field( $invoice->get_user_full_name() ),
345
-                '{first_name}'       => sanitize_text_field( $invoice->get_first_name() ),
346
-                '{last_name}'        => sanitize_text_field( $invoice->get_last_name() ),
347
-                '{email}'            => sanitize_email( $invoice->get_email() ),
348
-                '{invoice_number}'   => sanitize_text_field( $invoice->get_number() ),
349
-                '{invoice_total}'    => sanitize_text_field( wpinv_price( $invoice->get_total( true ), $invoice->get_currency() ) ),
350
-                '{invoice_link}'     => esc_url( $invoice->get_view_url() ),
351
-                '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ),
352
-                '{invoice_date}'     => date( get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ),
353
-                '{invoice_due_date}' => date( get_option( 'date_format' ), strtotime( $invoice->get_due_date(), current_time( 'timestamp' ) ) ),
354
-                '{invoice_quote}'    => sanitize_text_field( $invoice->get_invoice_quote_type() ),
355
-                '{invoice_label}'    => sanitize_text_field( ucfirst( $invoice->get_invoice_quote_type() ) ),
356
-                '{is_was}'           => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
343
+                '{name}'             => sanitize_text_field($invoice->get_user_full_name()),
344
+                '{full_name}'        => sanitize_text_field($invoice->get_user_full_name()),
345
+                '{first_name}'       => sanitize_text_field($invoice->get_first_name()),
346
+                '{last_name}'        => sanitize_text_field($invoice->get_last_name()),
347
+                '{email}'            => sanitize_email($invoice->get_email()),
348
+                '{invoice_number}'   => sanitize_text_field($invoice->get_number()),
349
+                '{invoice_total}'    => sanitize_text_field(wpinv_price($invoice->get_total(true), $invoice->get_currency())),
350
+                '{invoice_link}'     => esc_url($invoice->get_view_url()),
351
+                '{invoice_pay_link}' => esc_url($invoice->get_checkout_payment_url()),
352
+                '{invoice_date}'     => date(get_option('date_format'), strtotime($invoice->get_date_created(), current_time('timestamp'))),
353
+                '{invoice_due_date}' => date(get_option('date_format'), strtotime($invoice->get_due_date(), current_time('timestamp'))),
354
+                '{invoice_quote}'    => sanitize_text_field($invoice->get_invoice_quote_type()),
355
+                '{invoice_label}'    => sanitize_text_field(ucfirst($invoice->get_invoice_quote_type())),
356
+                '{is_was}'           => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'),
357 357
             )
358 358
         );
359 359
 
360 360
     }
361 361
 
362 362
     // Let third party plugins filter the arra.
363
-    $replace_array = apply_filters( 'wpinv_email_format_text', $replace_array, $content, $invoice );
363
+    $replace_array = apply_filters('wpinv_email_format_text', $replace_array, $content, $invoice);
364 364
 
365
-    foreach ( $replace_array as $key => $value ) {
366
-        $content = str_replace( $key, $value, $content );
365
+    foreach ($replace_array as $key => $value) {
366
+        $content = str_replace($key, $value, $content);
367 367
     }
368 368
 
369
-    return apply_filters( 'wpinv_email_content_replace', $content );
369
+    return apply_filters('wpinv_email_content_replace', $content);
370 370
 }
371 371
 
372 372
 
373
-function wpinv_email_wrap_message( $message ) {
373
+function wpinv_email_wrap_message($message) {
374 374
     // Buffer
375 375
     ob_start();
376 376
 
377
-    do_action( 'wpinv_email_header' );
377
+    do_action('wpinv_email_header');
378 378
 
379
-    echo wp_kses_post( wpautop( wptexturize( $message ) ) );
379
+    echo wp_kses_post(wpautop(wptexturize($message)));
380 380
 
381
-    do_action( 'wpinv_email_footer' );
381
+    do_action('wpinv_email_footer');
382 382
 
383 383
     // Get contents
384 384
     $message = ob_get_clean();
@@ -386,21 +386,21 @@  discard block
 block discarded – undo
386 386
     return $message;
387 387
 }
388 388
 
389
-function wpinv_add_notes_to_invoice_email( $invoice, $email_type ) {
390
-    if ( ! empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->get_id(), true ) ) {
391
-        $date_format = get_option( 'date_format' );
392
-        $time_format = get_option( 'time_format' );
389
+function wpinv_add_notes_to_invoice_email($invoice, $email_type) {
390
+    if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->get_id(), true)) {
391
+        $date_format = get_option('date_format');
392
+        $time_format = get_option('time_format');
393 393
         ?>
394 394
         <div id="wpinv-email-notes">
395
-            <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3>
395
+            <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3>
396 396
             <ol class="wpinv-notes-lists">
397 397
         <?php
398
-        foreach ( $invoice_notes as $note ) {
399
-            $note_time = strtotime( $note->comment_date );
398
+        foreach ($invoice_notes as $note) {
399
+            $note_time = strtotime($note->comment_date);
400 400
             ?>
401 401
             <li class="comment wpinv-note">
402
-            <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>
403
-            <div class="wpinv-note-desc description"><?php echo wp_kses_post( wpautop( wptexturize( $note->comment_content ) ) ); ?></div>
402
+            <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>
403
+            <div class="wpinv-note-desc description"><?php echo wp_kses_post(wpautop(wptexturize($note->comment_content))); ?></div>
404 404
             </li>
405 405
             <?php
406 406
         }
@@ -410,4 +410,4 @@  discard block
 block discarded – undo
410 410
         <?php
411 411
     }
412 412
 }
413
-add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 );
413
+add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3);
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 2 patches
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -14,70 +14,70 @@  discard block
 block discarded – undo
14 14
 class WPInv_Ajax {
15 15
 
16 16
     /**
17
-	 * Hook in ajax handlers.
18
-	 */
19
-	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
22
-		self::add_ajax_events();
17
+     * Hook in ajax handlers.
18
+     */
19
+    public static function init() {
20
+        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
+        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
22
+        self::add_ajax_events();
23 23
     }
24 24
 
25 25
     /**
26
-	 * Set GetPaid AJAX constant and headers.
27
-	 */
28
-	public static function define_ajax() {
29
-
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
35
-			}
36
-			$GLOBALS['wpdb']->hide_errors();
37
-		}
26
+     * Set GetPaid AJAX constant and headers.
27
+     */
28
+    public static function define_ajax() {
29
+
30
+        if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
+            getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
+            getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
+            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
+                /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
35
+            }
36
+            $GLOBALS['wpdb']->hide_errors();
37
+        }
38 38
 
39 39
     }
40 40
 
41 41
     /**
42
-	 * Send headers for GetPaid Ajax Requests.
43
-	 *
44
-	 * @since 1.0.18
45
-	 */
46
-	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
48
-			send_origin_headers();
49
-			send_nosniff_header();
50
-			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
54
-		}
42
+     * Send headers for GetPaid Ajax Requests.
43
+     *
44
+     * @since 1.0.18
45
+     */
46
+    private static function wpinv_ajax_headers() {
47
+        if ( ! headers_sent() ) {
48
+            send_origin_headers();
49
+            send_nosniff_header();
50
+            nocache_headers();
51
+            header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
+            header( 'X-Robots-Tag: noindex' );
53
+            status_header( 200 );
54
+        }
55 55
     }
56 56
 
57 57
     /**
58
-	 * Check for GetPaid Ajax request and fire action.
59
-	 */
60
-	public static function do_wpinv_ajax() {
61
-		global $wp_query;
58
+     * Check for GetPaid Ajax request and fire action.
59
+     */
60
+    public static function do_wpinv_ajax() {
61
+        global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
65
-		}
63
+        if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
+            $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
65
+        }
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+        $action = $wp_query->get( 'wpinv-ajax' );
68 68
 
69
-		if ( $action ) {
70
-			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
73
-			wp_die();
74
-		}
69
+        if ( $action ) {
70
+            self::wpinv_ajax_headers();
71
+            $action = sanitize_text_field( $action );
72
+            do_action( 'wpinv_ajax_' . $action );
73
+            wp_die();
74
+        }
75 75
 
76 76
     }
77 77
 
78 78
     /**
79
-	 * Hook in ajax methods.
80
-	 */
79
+     * Hook in ajax methods.
80
+     */
81 81
     public static function add_ajax_events() {
82 82
 
83 83
         // array( 'event' => is_frontend )
@@ -261,18 +261,18 @@  discard block
 block discarded – undo
261 261
         check_ajax_referer( 'getpaid_form_nonce' );
262 262
 
263 263
         // Is the request set up correctly?
264
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) {
265
-			echo aui()->alert(
266
-				array(
267
-					'type'    => 'warning',
268
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
269
-				)
264
+        if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) {
265
+            echo aui()->alert(
266
+                array(
267
+                    'type'    => 'warning',
268
+                    'content' => __( 'No payment form or item provided', 'invoicing' ),
269
+                )
270 270
             );
271 271
             exit;
272 272
         }
273 273
 
274 274
         // Payment form or button?
275
-		if ( ! empty( $_GET['form'] ) ) {
275
+        if ( ! empty( $_GET['form'] ) ) {
276 276
             $form = sanitize_text_field( urldecode( $_GET['form'] ) );
277 277
 
278 278
             if ( false !== strpos( $form, '|' ) ) {
@@ -325,10 +325,10 @@  discard block
 block discarded – undo
325 325
                 getpaid_display_payment_form( $form );
326 326
             }
327 327
 } elseif ( ! empty( $_GET['invoice'] ) ) {
328
-		    getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) );
328
+            getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) );
329 329
         } else {
330
-			$items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) );
331
-		    getpaid_display_item_payment_form( $items );
330
+            $items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) );
331
+            getpaid_display_item_payment_form( $items );
332 332
         }
333 333
 
334 334
         exit;
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
         if ( is_wp_error( $error ) ) {
649 649
             $alert = $error->get_error_message();
650 650
             wp_send_json_success( compact( 'alert' ) );
651
-         }
651
+            }
652 652
 
653 653
         // Update totals.
654 654
         $invoice->recalculate_total();
@@ -1083,12 +1083,12 @@  discard block
 block discarded – undo
1083 1083
     }
1084 1084
 
1085 1085
     /**
1086
-	 * Handles file uploads.
1087
-	 *
1088
-	 * @since       1.0.0
1089
-	 * @return      void
1090
-	 */
1091
-	public static function file_upload() {
1086
+     * Handles file uploads.
1087
+     *
1088
+     * @since       1.0.0
1089
+     * @return      void
1090
+     */
1091
+    public static function file_upload() {
1092 1092
 
1093 1093
         // Check nonce.
1094 1094
         check_ajax_referer( 'getpaid_form_nonce' );
@@ -1149,7 +1149,7 @@  discard block
 block discarded – undo
1149 1149
 
1150 1150
         wp_send_json_success( $response );
1151 1151
 
1152
-	}
1152
+    }
1153 1153
 
1154 1154
 }
1155 1155
 
Please login to merge, or discard this patch.
Spacing   +325 added lines, -325 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * WPInv_Ajax class.
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 	 * Hook in ajax handlers.
18 18
 	 */
19 19
 	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
20
+		add_action('init', array(__CLASS__, 'define_ajax'), 0);
21
+		add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
22 22
 		self::add_ajax_events();
23 23
     }
24 24
 
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 	 */
28 28
 	public static function define_ajax() {
29 29
 
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+		if (!empty($_GET['wpinv-ajax'])) {
31
+			getpaid_maybe_define_constant('DOING_AJAX', true);
32
+			getpaid_maybe_define_constant('WPInv_DOING_AJAX', true);
33
+			if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
34
+				/** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
35 35
 			}
36 36
 			$GLOBALS['wpdb']->hide_errors();
37 37
 		}
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 	 * @since 1.0.18
45 45
 	 */
46 46
 	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
47
+		if (!headers_sent()) {
48 48
 			send_origin_headers();
49 49
 			send_nosniff_header();
50 50
 			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
51
+			header('Content-Type: text/html; charset=' . get_option('blog_charset'));
52
+			header('X-Robots-Tag: noindex');
53
+			status_header(200);
54 54
 		}
55 55
     }
56 56
 
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
 	public static function do_wpinv_ajax() {
61 61
 		global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
63
+		if (!empty($_GET['wpinv-ajax'])) {
64
+			$wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax'])));
65 65
 		}
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+		$action = $wp_query->get('wpinv-ajax');
68 68
 
69
-		if ( $action ) {
69
+		if ($action) {
70 70
 			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
71
+			$action = sanitize_text_field($action);
72
+			do_action('wpinv_ajax_' . $action);
73 73
 			wp_die();
74 74
 		}
75 75
 
@@ -106,36 +106,36 @@  discard block
 block discarded – undo
106 106
             'file_upload'                   => true,
107 107
         );
108 108
 
109
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
110
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
111
-            add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
109
+        foreach ($ajax_events as $ajax_event => $nopriv) {
110
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
111
+            add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
112 112
 
113
-            if ( $nopriv ) {
114
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
115
-                add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
116
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
113
+            if ($nopriv) {
114
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
115
+                add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
116
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
117 117
             }
118 118
         }
119 119
     }
120 120
 
121 121
     public static function add_note() {
122
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
122
+        check_ajax_referer('add-invoice-note', '_nonce');
123 123
 
124
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
124
+        if (!wpinv_current_user_can_manage_invoicing()) {
125 125
             die( -1 );
126 126
         }
127 127
 
128
-        $post_id   = absint( $_POST['post_id'] );
129
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
130
-        $note_type = sanitize_text_field( $_POST['note_type'] );
128
+        $post_id   = absint($_POST['post_id']);
129
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
130
+        $note_type = sanitize_text_field($_POST['note_type']);
131 131
 
132 132
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
133 133
 
134
-        if ( $post_id > 0 ) {
135
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
134
+        if ($post_id > 0) {
135
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
136 136
 
137
-            if ( $note_id > 0 && ! is_wp_error( $note_id ) ) {
138
-                wpinv_get_invoice_note_line_item( $note_id );
137
+            if ($note_id > 0 && !is_wp_error($note_id)) {
138
+                wpinv_get_invoice_note_line_item($note_id);
139 139
             }
140 140
         }
141 141
 
@@ -143,16 +143,16 @@  discard block
 block discarded – undo
143 143
     }
144 144
 
145 145
     public static function delete_note() {
146
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
146
+        check_ajax_referer('delete-invoice-note', '_nonce');
147 147
 
148
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
148
+        if (!wpinv_current_user_can_manage_invoicing()) {
149 149
             die( -1 );
150 150
         }
151 151
 
152
-        $note_id = (int)$_POST['note_id'];
152
+        $note_id = (int) $_POST['note_id'];
153 153
 
154
-        if ( $note_id > 0 ) {
155
-            wp_delete_comment( $note_id, true );
154
+        if ($note_id > 0) {
155
+            wp_delete_comment($note_id, true);
156 156
         }
157 157
 
158 158
         die();
@@ -170,34 +170,34 @@  discard block
 block discarded – undo
170 170
     public static function get_billing_details() {
171 171
 
172 172
         // Verify nonce.
173
-        check_ajax_referer( 'wpinv-nonce' );
173
+        check_ajax_referer('wpinv-nonce');
174 174
 
175 175
         // Can the user manage the plugin?
176
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
176
+        if (!wpinv_current_user_can_manage_invoicing()) {
177 177
             die( -1 );
178 178
         }
179 179
 
180 180
         // Do we have a user id?
181 181
         $user_id = (int) $_GET['user_id'];
182 182
 
183
-        if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
183
+        if (empty($user_id) || !is_numeric($user_id)) {
184 184
             die( -1 );
185 185
         }
186 186
 
187 187
         // Fetch the billing details.
188
-        $billing_details    = wpinv_get_user_address( $user_id );
189
-        $billing_details    = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id );
188
+        $billing_details    = wpinv_get_user_address($user_id);
189
+        $billing_details    = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id);
190 190
 
191 191
         // unset the user id and email.
192
-        $to_ignore = array( 'user_id', 'email' );
192
+        $to_ignore = array('user_id', 'email');
193 193
 
194
-        foreach ( $to_ignore as $key ) {
195
-            if ( isset( $billing_details[ $key ] ) ) {
196
-                unset( $billing_details[ $key ] );
194
+        foreach ($to_ignore as $key) {
195
+            if (isset($billing_details[$key])) {
196
+                unset($billing_details[$key]);
197 197
             }
198 198
         }
199 199
 
200
-        wp_send_json_success( $billing_details );
200
+        wp_send_json_success($billing_details);
201 201
 
202 202
     }
203 203
 
@@ -207,47 +207,47 @@  discard block
 block discarded – undo
207 207
     public static function check_new_user_email() {
208 208
 
209 209
         // Verify nonce.
210
-        check_ajax_referer( 'wpinv-nonce' );
210
+        check_ajax_referer('wpinv-nonce');
211 211
 
212 212
         // Can the user manage the plugin?
213
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
213
+        if (!wpinv_current_user_can_manage_invoicing()) {
214 214
             die( -1 );
215 215
         }
216 216
 
217 217
         // We need an email address.
218
-        if ( empty( $_GET['email'] ) ) {
219
-            _e( "Provide the new user's email address", 'invoicing' );
218
+        if (empty($_GET['email'])) {
219
+            _e("Provide the new user's email address", 'invoicing');
220 220
             exit;
221 221
         }
222 222
 
223 223
         // Ensure the email is valid.
224
-        $email = sanitize_email( $_GET['email'] );
225
-        if ( ! is_email( $email ) ) {
226
-            _e( 'Invalid email address', 'invoicing' );
224
+        $email = sanitize_email($_GET['email']);
225
+        if (!is_email($email)) {
226
+            _e('Invalid email address', 'invoicing');
227 227
             exit;
228 228
         }
229 229
 
230 230
         // And it does not exist.
231
-        $id = email_exists( $email );
232
-        if ( $id ) {
233
-            wp_send_json_success( compact( 'id' ) );
231
+        $id = email_exists($email);
232
+        if ($id) {
233
+            wp_send_json_success(compact('id'));
234 234
         }
235 235
 
236
-        wp_send_json_success( true );
236
+        wp_send_json_success(true);
237 237
     }
238 238
 
239 239
     public static function run_tool() {
240
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
241
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
240
+        check_ajax_referer('wpinv-nonce', '_nonce');
241
+        if (!wpinv_current_user_can_manage_invoicing()) {
242 242
             die( -1 );
243 243
         }
244 244
 
245
-        $tool = sanitize_text_field( $_POST['tool'] );
245
+        $tool = sanitize_text_field($_POST['tool']);
246 246
 
247
-        do_action( 'wpinv_run_tool' );
247
+        do_action('wpinv_run_tool');
248 248
 
249
-        if ( ! empty( $tool ) ) {
250
-            do_action( 'wpinv_tool_' . $tool );
249
+        if (!empty($tool)) {
250
+            do_action('wpinv_tool_' . $tool);
251 251
         }
252 252
     }
253 253
 
@@ -258,43 +258,43 @@  discard block
 block discarded – undo
258 258
         global $getpaid_force_checkbox;
259 259
 
260 260
         // Check nonce.
261
-        check_ajax_referer( 'getpaid_form_nonce' );
261
+        check_ajax_referer('getpaid_form_nonce');
262 262
 
263 263
         // Is the request set up correctly?
264
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) {
264
+		if (empty($_GET['form']) && empty($_GET['item']) && empty($_GET['invoice'])) {
265 265
 			echo aui()->alert(
266 266
 				array(
267 267
 					'type'    => 'warning',
268
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
268
+					'content' => __('No payment form or item provided', 'invoicing'),
269 269
 				)
270 270
             );
271 271
             exit;
272 272
         }
273 273
 
274 274
         // Payment form or button?
275
-		if ( ! empty( $_GET['form'] ) ) {
276
-            $form = sanitize_text_field( urldecode( $_GET['form'] ) );
275
+		if (!empty($_GET['form'])) {
276
+            $form = sanitize_text_field(urldecode($_GET['form']));
277 277
 
278
-            if ( false !== strpos( $form, '|' ) ) {
279
-                $form_pos = strpos( $form, '|' );
280
-                $_items   = getpaid_convert_items_to_array( substr( $form, $form_pos + 1 ) );
281
-                $form     = substr( $form, 0, $form_pos );
278
+            if (false !== strpos($form, '|')) {
279
+                $form_pos = strpos($form, '|');
280
+                $_items   = getpaid_convert_items_to_array(substr($form, $form_pos + 1));
281
+                $form     = substr($form, 0, $form_pos);
282 282
 
283 283
                 // Retrieve appropriate payment form.
284
-                $payment_form = new GetPaid_Payment_Form( $form );
285
-                $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
284
+                $payment_form = new GetPaid_Payment_Form($form);
285
+                $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form());
286 286
 
287 287
                 $items    = array();
288 288
                 $item_ids = array();
289 289
 
290
-                foreach ( $_items as $item_id => $qty ) {
291
-                    if ( ! in_array( $item_id, $item_ids ) ) {
292
-                        $item = new GetPaid_Form_Item( $item_id );
293
-                        $item->set_quantity( $qty );
290
+                foreach ($_items as $item_id => $qty) {
291
+                    if (!in_array($item_id, $item_ids)) {
292
+                        $item = new GetPaid_Form_Item($item_id);
293
+                        $item->set_quantity($qty);
294 294
 
295
-                        if ( 0 == $qty ) {
296
-                            $item->set_allow_quantities( true );
297
-                            $item->set_is_required( false );
295
+                        if (0 == $qty) {
296
+                            $item->set_allow_quantities(true);
297
+                            $item->set_is_required(false);
298 298
                             $getpaid_force_checkbox = true;
299 299
                         }
300 300
 
@@ -303,32 +303,32 @@  discard block
 block discarded – undo
303 303
                     }
304 304
                 }
305 305
 
306
-                if ( ! $payment_form->is_default() ) {
306
+                if (!$payment_form->is_default()) {
307 307
 
308
-                    foreach ( $payment_form->get_items() as $item ) {
309
-                        if ( ! in_array( $item->get_id(), $item_ids ) ) {
308
+                    foreach ($payment_form->get_items() as $item) {
309
+                        if (!in_array($item->get_id(), $item_ids)) {
310 310
                             $item_ids[] = $item->get_id();
311 311
                             $items[]    = $item;
312 312
                         }
313 313
                     }
314 314
 }
315 315
 
316
-                $payment_form->set_items( $items );
317
-                $extra_items     = esc_attr( getpaid_convert_items_to_string( $_items ) );
318
-                $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items );
316
+                $payment_form->set_items($items);
317
+                $extra_items     = esc_attr(getpaid_convert_items_to_string($_items));
318
+                $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items);
319 319
                 $extra_items     = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />";
320 320
                 $extra_items    .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />";
321
-                $payment_form->display( $extra_items );
321
+                $payment_form->display($extra_items);
322 322
                 $getpaid_force_checkbox = false;
323 323
 
324 324
             } else {
325
-                getpaid_display_payment_form( $form );
325
+                getpaid_display_payment_form($form);
326 326
             }
327
-} elseif ( ! empty( $_GET['invoice'] ) ) {
328
-		    getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) );
327
+} elseif (!empty($_GET['invoice'])) {
328
+		    getpaid_display_invoice_payment_form((int) urldecode($_GET['invoice']));
329 329
         } else {
330
-			$items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) );
331
-		    getpaid_display_item_payment_form( $items );
330
+			$items = getpaid_convert_items_to_array(sanitize_text_field(urldecode($_GET['item'])));
331
+		    getpaid_display_item_payment_form($items);
332 332
         }
333 333
 
334 334
         exit;
@@ -343,17 +343,17 @@  discard block
 block discarded – undo
343 343
     public static function payment_form() {
344 344
 
345 345
         // Check nonce.
346
-        check_ajax_referer( 'getpaid_form_nonce' );
346
+        check_ajax_referer('getpaid_form_nonce');
347 347
 
348 348
         // ... form fields...
349
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
350
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
349
+        if (empty($_POST['getpaid_payment_form_submission'])) {
350
+            _e('Error: Reload the page and try again.', 'invoicing');
351 351
             exit;
352 352
         }
353 353
 
354 354
         // Process the payment form.
355
-        $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' );
356
-        $checkout       = new $checkout_class( new GetPaid_Payment_Form_Submission() );
355
+        $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout');
356
+        $checkout       = new $checkout_class(new GetPaid_Payment_Form_Submission());
357 357
         $checkout->process_checkout();
358 358
 
359 359
         exit;
@@ -366,55 +366,55 @@  discard block
 block discarded – undo
366 366
      */
367 367
     public static function get_payment_form_states_field() {
368 368
 
369
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
369
+        if (empty($_GET['country']) || empty($_GET['form'])) {
370 370
             exit;
371 371
         }
372 372
 
373
-        $elements = getpaid_get_payment_form_elements( (int) $_GET['form'] );
373
+        $elements = getpaid_get_payment_form_elements((int) $_GET['form']);
374 374
 
375
-        if ( empty( $elements ) ) {
375
+        if (empty($elements)) {
376 376
             exit;
377 377
         }
378 378
 
379 379
         $address_fields = array();
380
-        foreach ( $elements as $element ) {
381
-            if ( 'address' === $element['type'] ) {
380
+        foreach ($elements as $element) {
381
+            if ('address' === $element['type']) {
382 382
                 $address_fields = $element;
383 383
                 break;
384 384
             }
385 385
         }
386 386
 
387
-        if ( empty( $address_fields ) ) {
387
+        if (empty($address_fields)) {
388 388
             exit;
389 389
         }
390 390
 
391
-        foreach ( $address_fields['fields'] as $address_field ) {
391
+        foreach ($address_fields['fields'] as $address_field) {
392 392
 
393
-            if ( 'wpinv_state' == $address_field['name'] ) {
393
+            if ('wpinv_state' == $address_field['name']) {
394 394
 
395
-                $wrap_class  = getpaid_get_form_element_grid_class( $address_field );
396
-                $wrap_class  = esc_attr( "$wrap_class getpaid-address-field-wrapper" );
397
-                $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] );
398
-                $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] );
399
-                $value       = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : '';
400
-                $label       = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] );
395
+                $wrap_class  = getpaid_get_form_element_grid_class($address_field);
396
+                $wrap_class  = esc_attr("$wrap_class getpaid-address-field-wrapper");
397
+                $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']);
398
+                $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']);
399
+                $value       = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : '';
400
+                $label       = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']);
401 401
 
402
-                if ( ! empty( $address_field['required'] ) ) {
402
+                if (!empty($address_field['required'])) {
403 403
                     $label .= "<span class='text-danger'> *</span>";
404 404
                 }
405 405
 
406 406
                 $html = getpaid_get_states_select_markup(
407
-                    sanitize_text_field( $_GET['country'] ),
407
+                    sanitize_text_field($_GET['country']),
408 408
                     $value,
409 409
                     $placeholder,
410 410
                     $label,
411 411
                     $description,
412
-                    ! empty( $address_field['required'] ),
412
+                    !empty($address_field['required']),
413 413
                     $wrap_class,
414
-                    sanitize_text_field( $_GET['name'] )
414
+                    sanitize_text_field($_GET['name'])
415 415
                 );
416 416
 
417
-                wp_send_json_success( $html );
417
+                wp_send_json_success($html);
418 418
                 exit;
419 419
 
420 420
             }
@@ -429,66 +429,66 @@  discard block
 block discarded – undo
429 429
     public static function recalculate_invoice_totals() {
430 430
 
431 431
         // Verify nonce.
432
-        check_ajax_referer( 'wpinv-nonce' );
432
+        check_ajax_referer('wpinv-nonce');
433 433
 
434
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
434
+        if (!wpinv_current_user_can_manage_invoicing()) {
435 435
             exit;
436 436
         }
437 437
 
438 438
         // We need an invoice.
439
-        if ( empty( $_POST['post_id'] ) ) {
439
+        if (empty($_POST['post_id'])) {
440 440
             exit;
441 441
         }
442 442
 
443 443
         // Fetch the invoice.
444
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
444
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
445 445
 
446 446
         // Ensure it exists.
447
-        if ( ! $invoice->get_id() ) {
447
+        if (!$invoice->get_id()) {
448 448
             exit;
449 449
         }
450 450
 
451 451
         // Maybe set the country, state, currency.
452
-        foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) {
453
-            if ( isset( $_POST[ $key ] ) ) {
452
+        foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) {
453
+            if (isset($_POST[$key])) {
454 454
                 $method = "set_$key";
455
-                $invoice->$method( sanitize_text_field( $_POST[ $key ] ) );
455
+                $invoice->$method(sanitize_text_field($_POST[$key]));
456 456
             }
457 457
         }
458 458
 
459 459
         // Maybe disable taxes.
460
-        $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) );
460
+        $invoice->set_disable_taxes(!empty($_POST['taxes']));
461 461
 
462 462
         // Discount code.
463
-        if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
464
-            $discount = new WPInv_Discount( $invoice->get_discount_code() );
465
-            if ( $discount->exists() ) {
466
-                $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
463
+        if (!$invoice->is_paid() && !$invoice->is_refunded()) {
464
+            $discount = new WPInv_Discount($invoice->get_discount_code());
465
+            if ($discount->exists()) {
466
+                $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
467 467
             } else {
468
-                $invoice->remove_discount( 'discount_code' );
468
+                $invoice->remove_discount('discount_code');
469 469
             }
470 470
         }
471 471
 
472 472
         // Recalculate totals.
473 473
         $invoice->recalculate_total();
474 474
 
475
-        $total        = wpinv_price( $invoice->get_total(), $invoice->get_currency() );
476
-        $suscriptions = getpaid_get_invoice_subscriptions( $invoice );
477
-        if ( is_a( $suscriptions, 'WPInv_Subscription' ) && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) {
478
-            $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() );
479
-            $total          .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>';
475
+        $total        = wpinv_price($invoice->get_total(), $invoice->get_currency());
476
+        $suscriptions = getpaid_get_invoice_subscriptions($invoice);
477
+        if (is_a($suscriptions, 'WPInv_Subscription') && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) {
478
+            $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency());
479
+            $total          .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>';
480 480
         }
481 481
 
482 482
         $totals = array(
483
-            'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ),
484
-            'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ),
485
-            'tax'      => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ),
483
+            'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()),
484
+            'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()),
485
+            'tax'      => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()),
486 486
             'total'    => $total,
487 487
         );
488 488
 
489
-        $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice );
489
+        $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice);
490 490
 
491
-        wp_send_json_success( compact( 'totals' ) );
491
+        wp_send_json_success(compact('totals'));
492 492
     }
493 493
 
494 494
     /**
@@ -497,33 +497,33 @@  discard block
 block discarded – undo
497 497
     public static function get_invoice_items() {
498 498
 
499 499
         // Verify nonce.
500
-        check_ajax_referer( 'wpinv-nonce' );
500
+        check_ajax_referer('wpinv-nonce');
501 501
 
502
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
502
+        if (!wpinv_current_user_can_manage_invoicing()) {
503 503
             exit;
504 504
         }
505 505
 
506 506
         // We need an invoice and items.
507
-        if ( empty( $_POST['post_id'] ) ) {
507
+        if (empty($_POST['post_id'])) {
508 508
             exit;
509 509
         }
510 510
 
511 511
         // Fetch the invoice.
512
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
512
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
513 513
 
514 514
         // Ensure it exists.
515
-        if ( ! $invoice->get_id() ) {
515
+        if (!$invoice->get_id()) {
516 516
             exit;
517 517
         }
518 518
 
519 519
         // Return an array of invoice items.
520 520
         $items = array();
521 521
 
522
-        foreach ( $invoice->get_items() as $item ) {
523
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency(), $invoice->is_renewal() );
522
+        foreach ($invoice->get_items() as $item) {
523
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal());
524 524
         }
525 525
 
526
-        wp_send_json_success( compact( 'items' ) );
526
+        wp_send_json_success(compact('items'));
527 527
     }
528 528
 
529 529
     /**
@@ -532,50 +532,50 @@  discard block
 block discarded – undo
532 532
     public static function edit_invoice_item() {
533 533
 
534 534
         // Verify nonce.
535
-        check_ajax_referer( 'wpinv-nonce' );
535
+        check_ajax_referer('wpinv-nonce');
536 536
 
537
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
537
+        if (!wpinv_current_user_can_manage_invoicing()) {
538 538
             exit;
539 539
         }
540 540
 
541 541
         // We need an invoice and item details.
542
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) {
542
+        if (empty($_POST['post_id']) || empty($_POST['data'])) {
543 543
             exit;
544 544
         }
545 545
 
546 546
         // Fetch the invoice.
547
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
547
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
548 548
 
549 549
         // Ensure it exists and its not been paid for.
550
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
550
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
551 551
             exit;
552 552
         }
553 553
 
554 554
         // Format the data.
555
-        $data = wp_kses_post_deep( wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ) );
555
+        $data = wp_kses_post_deep(wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field')));
556 556
 
557 557
         // Ensure that we have an item id.
558
-        if ( empty( $data['id'] ) ) {
558
+        if (empty($data['id'])) {
559 559
             exit;
560 560
         }
561 561
 
562 562
         // Abort if the invoice does not have the specified item.
563
-        $item = $invoice->get_item( (int) $data['id'] );
563
+        $item = $invoice->get_item((int) $data['id']);
564 564
 
565
-        if ( empty( $item ) ) {
565
+        if (empty($item)) {
566 566
             exit;
567 567
         }
568 568
 
569 569
         // Update the item.
570
-        $item->set_price( getpaid_standardize_amount( $data['price'] ) );
571
-        $item->set_name( sanitize_text_field( $data['name'] ) );
572
-        $item->set_description( wp_kses_post( $data['description'] ) );
573
-        $item->set_quantity( floatval( $data['quantity'] ) );
570
+        $item->set_price(getpaid_standardize_amount($data['price']));
571
+        $item->set_name(sanitize_text_field($data['name']));
572
+        $item->set_description(wp_kses_post($data['description']));
573
+        $item->set_quantity(floatval($data['quantity']));
574 574
 
575 575
         // Add it to the invoice.
576
-        $error = $invoice->add_item( $item );
576
+        $error = $invoice->add_item($item);
577 577
         $alert = false;
578
-        if ( is_wp_error( $error ) ) {
578
+        if (is_wp_error($error)) {
579 579
             $alert = $error->get_error_message();
580 580
         }
581 581
 
@@ -588,11 +588,11 @@  discard block
 block discarded – undo
588 588
         // Return an array of invoice items.
589 589
         $items = array();
590 590
 
591
-        foreach ( $invoice->get_items() as $item ) {
592
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
591
+        foreach ($invoice->get_items() as $item) {
592
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
593 593
         }
594 594
 
595
-        wp_send_json_success( compact( 'items', 'alert' ) );
595
+        wp_send_json_success(compact('items', 'alert'));
596 596
     }
597 597
 
598 598
     /**
@@ -601,53 +601,53 @@  discard block
 block discarded – undo
601 601
     public static function create_invoice_item() {
602 602
 
603 603
         // Verify nonce.
604
-        check_ajax_referer( 'wpinv-nonce' );
604
+        check_ajax_referer('wpinv-nonce');
605 605
 
606
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
606
+        if (!wpinv_current_user_can_manage_invoicing()) {
607 607
             exit;
608 608
         }
609 609
 
610 610
         // We need an invoice and item details.
611
-        if ( empty( $_POST['invoice_id'] ) || empty( $_POST['_wpinv_quick'] ) ) {
611
+        if (empty($_POST['invoice_id']) || empty($_POST['_wpinv_quick'])) {
612 612
             exit;
613 613
         }
614 614
 
615 615
         // Fetch the invoice.
616
-        $invoice = new WPInv_Invoice( intval( $_POST['invoice_id'] ) );
616
+        $invoice = new WPInv_Invoice(intval($_POST['invoice_id']));
617 617
 
618 618
         // Ensure it exists and its not been paid for.
619
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
619
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
620 620
             exit;
621 621
         }
622 622
 
623 623
         // Format the data.
624
-        $data = wp_kses_post_deep( wp_unslash( $_POST['_wpinv_quick'] ) );
624
+        $data = wp_kses_post_deep(wp_unslash($_POST['_wpinv_quick']));
625 625
 
626 626
         $item = new WPInv_Item();
627
-        $item->set_price( getpaid_standardize_amount( $data['price'] ) );
628
-        $item->set_name( sanitize_text_field( $data['name'] ) );
629
-        $item->set_description( wp_kses_post( $data['description'] ) );
630
-        $item->set_type( sanitize_text_field( $data['type'] ) );
631
-        $item->set_vat_rule( sanitize_text_field( $data['vat_rule'] ) );
632
-        $item->set_vat_class( sanitize_text_field( $data['vat_class'] ) );
633
-        $item->set_status( 'publish' );
627
+        $item->set_price(getpaid_standardize_amount($data['price']));
628
+        $item->set_name(sanitize_text_field($data['name']));
629
+        $item->set_description(wp_kses_post($data['description']));
630
+        $item->set_type(sanitize_text_field($data['type']));
631
+        $item->set_vat_rule(sanitize_text_field($data['vat_rule']));
632
+        $item->set_vat_class(sanitize_text_field($data['vat_class']));
633
+        $item->set_status('publish');
634 634
         $item->save();
635 635
 
636
-        if ( ! $item->exists() ) {
637
-            $alert = __( 'Could not create invoice item. Please try again.', 'invoicing' );
638
-            wp_send_json_success( compact( 'alert' ) );
636
+        if (!$item->exists()) {
637
+            $alert = __('Could not create invoice item. Please try again.', 'invoicing');
638
+            wp_send_json_success(compact('alert'));
639 639
         }
640 640
 
641
-        $item = new GetPaid_Form_Item( $item->get_id() );
642
-        $item->set_quantity( floatval( $data['qty'] ) );
641
+        $item = new GetPaid_Form_Item($item->get_id());
642
+        $item->set_quantity(floatval($data['qty']));
643 643
 
644 644
         // Add it to the invoice.
645
-        $error = $invoice->add_item( $item );
645
+        $error = $invoice->add_item($item);
646 646
         $alert = false;
647 647
 
648
-        if ( is_wp_error( $error ) ) {
648
+        if (is_wp_error($error)) {
649 649
             $alert = $error->get_error_message();
650
-            wp_send_json_success( compact( 'alert' ) );
650
+            wp_send_json_success(compact('alert'));
651 651
          }
652 652
 
653 653
         // Update totals.
@@ -660,9 +660,9 @@  discard block
 block discarded – undo
660 660
         $invoice->recalculate_total();
661 661
         $invoice->save();
662 662
         ob_start();
663
-        GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice );
663
+        GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice);
664 664
         $row = ob_get_clean();
665
-        wp_send_json_success( compact( 'row' ) );
665
+        wp_send_json_success(compact('row'));
666 666
     }
667 667
 
668 668
     /**
@@ -671,33 +671,33 @@  discard block
 block discarded – undo
671 671
     public static function remove_invoice_item() {
672 672
 
673 673
         // Verify nonce.
674
-        check_ajax_referer( 'wpinv-nonce' );
674
+        check_ajax_referer('wpinv-nonce');
675 675
 
676
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
676
+        if (!wpinv_current_user_can_manage_invoicing()) {
677 677
             exit;
678 678
         }
679 679
 
680 680
         // We need an invoice and an item.
681
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
681
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
682 682
             exit;
683 683
         }
684 684
 
685 685
         // Fetch the invoice.
686
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
686
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
687 687
 
688 688
         // Ensure it exists and its not been paid for.
689
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
689
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
690 690
             exit;
691 691
         }
692 692
 
693 693
         // Abort if the invoice does not have the specified item.
694
-        $item = $invoice->get_item( (int) $_POST['item_id'] );
694
+        $item = $invoice->get_item((int) $_POST['item_id']);
695 695
 
696
-        if ( empty( $item ) ) {
696
+        if (empty($item)) {
697 697
             exit;
698 698
         }
699 699
 
700
-        $invoice->remove_item( (int) $_POST['item_id'] );
700
+        $invoice->remove_item((int) $_POST['item_id']);
701 701
 
702 702
         // Update totals.
703 703
         $invoice->recalculate_total();
@@ -708,11 +708,11 @@  discard block
 block discarded – undo
708 708
         // Return an array of invoice items.
709 709
         $items = array();
710 710
 
711
-        foreach ( $invoice->get_items() as $item ) {
712
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
711
+        foreach ($invoice->get_items() as $item) {
712
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
713 713
         }
714 714
 
715
-        wp_send_json_success( compact( 'items' ) );
715
+        wp_send_json_success(compact('items'));
716 716
     }
717 717
 
718 718
     /**
@@ -721,68 +721,68 @@  discard block
 block discarded – undo
721 721
     public static function recalculate_full_prices() {
722 722
 
723 723
         // Verify nonce.
724
-        check_ajax_referer( 'wpinv-nonce' );
724
+        check_ajax_referer('wpinv-nonce');
725 725
 
726
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
726
+        if (!wpinv_current_user_can_manage_invoicing()) {
727 727
             exit;
728 728
         }
729 729
 
730 730
         // We need an invoice and item.
731
-        if ( empty( $_POST['post_id'] ) ) {
731
+        if (empty($_POST['post_id'])) {
732 732
             exit;
733 733
         }
734 734
 
735 735
         // Fetch the invoice.
736
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
736
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
737 737
         $alert   = false;
738 738
 
739 739
         // Ensure it exists and its not been paid for.
740
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
740
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
741 741
             exit;
742 742
         }
743 743
 
744
-        $invoice->set_items( array() );
744
+        $invoice->set_items(array());
745 745
 
746
-        if ( ! empty( $_POST['getpaid_items'] ) ) {
746
+        if (!empty($_POST['getpaid_items'])) {
747 747
 
748
-            foreach ( wp_kses_post_deep( $_POST['getpaid_items'] ) as $item_id => $args ) {
749
-                $item = new GetPaid_Form_Item( $item_id );
748
+            foreach (wp_kses_post_deep($_POST['getpaid_items']) as $item_id => $args) {
749
+                $item = new GetPaid_Form_Item($item_id);
750 750
 
751
-                if ( $item->exists() ) {
752
-                    $item->set_price( getpaid_standardize_amount( $args['price'] ) );
753
-                    $item->set_quantity( floatval( $args['quantity'] ) );
754
-                    $item->set_name( sanitize_text_field( $args['name'] ) );
755
-                    $item->set_description( wp_kses_post( $args['description'] ) );
756
-                    $invoice->add_item( $item );
751
+                if ($item->exists()) {
752
+                    $item->set_price(getpaid_standardize_amount($args['price']));
753
+                    $item->set_quantity(floatval($args['quantity']));
754
+                    $item->set_name(sanitize_text_field($args['name']));
755
+                    $item->set_description(wp_kses_post($args['description']));
756
+                    $invoice->add_item($item);
757 757
                 }
758 758
             }
759 759
 }
760 760
 
761
-        $invoice->set_disable_taxes( ! empty( $_POST['disable_taxes'] ) );
761
+        $invoice->set_disable_taxes(!empty($_POST['disable_taxes']));
762 762
 
763 763
         // Maybe set the country, state, currency.
764
-        foreach ( array( 'wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code' ) as $key ) {
765
-            if ( isset( $_POST[ $key ] ) ) {
766
-                $_key   = str_replace( 'wpinv_', '', $key );
764
+        foreach (array('wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code') as $key) {
765
+            if (isset($_POST[$key])) {
766
+                $_key   = str_replace('wpinv_', '', $key);
767 767
                 $method = "set_$_key";
768
-                $invoice->$method( sanitize_text_field( $_POST[ $key ] ) );
768
+                $invoice->$method(sanitize_text_field($_POST[$key]));
769 769
             }
770 770
         }
771 771
 
772
-        $discount = new WPInv_Discount( $invoice->get_discount_code() );
773
-        if ( $discount->exists() ) {
774
-            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
772
+        $discount = new WPInv_Discount($invoice->get_discount_code());
773
+        if ($discount->exists()) {
774
+            $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
775 775
         } else {
776
-            $invoice->remove_discount( 'discount_code' );
776
+            $invoice->remove_discount('discount_code');
777 777
         }
778 778
 
779 779
         // Save the invoice.
780 780
         $invoice->recalculate_total();
781 781
         $invoice->save();
782 782
         ob_start();
783
-        GetPaid_Meta_Box_Invoice_Items::output( get_post( $invoice->get_id() ), $invoice );
783
+        GetPaid_Meta_Box_Invoice_Items::output(get_post($invoice->get_id()), $invoice);
784 784
         $table = ob_get_clean();
785
-        wp_send_json_success( compact( 'table' ) );
785
+        wp_send_json_success(compact('table'));
786 786
     }
787 787
 
788 788
     /**
@@ -791,42 +791,42 @@  discard block
 block discarded – undo
791 791
     public static function admin_add_invoice_item() {
792 792
 
793 793
         // Verify nonce.
794
-        check_ajax_referer( 'wpinv-nonce' );
794
+        check_ajax_referer('wpinv-nonce');
795 795
 
796
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
796
+        if (!wpinv_current_user_can_manage_invoicing()) {
797 797
             exit;
798 798
         }
799 799
 
800 800
         // We need an invoice and item.
801
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
801
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
802 802
             exit;
803 803
         }
804 804
 
805 805
         // Fetch the invoice.
806
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
806
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
807 807
         $alert   = false;
808 808
 
809 809
         // Ensure it exists and its not been paid for.
810
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
810
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
811 811
             exit;
812 812
         }
813 813
 
814 814
         // Add the item.
815
-        $item  = new GetPaid_Form_Item( (int) $_POST['item_id'] );
816
-        $error = $invoice->add_item( $item );
815
+        $item  = new GetPaid_Form_Item((int) $_POST['item_id']);
816
+        $error = $invoice->add_item($item);
817 817
 
818
-        if ( is_wp_error( $error ) ) {
818
+        if (is_wp_error($error)) {
819 819
             $alert = $error->get_error_message();
820
-            wp_send_json_success( compact( 'alert' ) );
820
+            wp_send_json_success(compact('alert'));
821 821
         }
822 822
 
823 823
         // Save the invoice.
824 824
         $invoice->recalculate_total();
825 825
         $invoice->save();
826 826
         ob_start();
827
-        GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice );
827
+        GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice);
828 828
         $row = ob_get_clean();
829
-        wp_send_json_success( compact( 'row' ) );
829
+        wp_send_json_success(compact('row'));
830 830
     }
831 831
 
832 832
     /**
@@ -835,39 +835,39 @@  discard block
 block discarded – undo
835 835
     public static function add_invoice_items() {
836 836
 
837 837
         // Verify nonce.
838
-        check_ajax_referer( 'wpinv-nonce' );
838
+        check_ajax_referer('wpinv-nonce');
839 839
 
840
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
840
+        if (!wpinv_current_user_can_manage_invoicing()) {
841 841
             exit;
842 842
         }
843 843
 
844 844
         // We need an invoice and items.
845
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) {
845
+        if (empty($_POST['post_id']) || empty($_POST['items'])) {
846 846
             exit;
847 847
         }
848 848
 
849 849
         // Fetch the invoice.
850
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
850
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
851 851
         $alert   = false;
852 852
 
853 853
         // Ensure it exists and its not been paid for.
854
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
854
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
855 855
             exit;
856 856
         }
857 857
 
858 858
         // Add the items.
859
-        foreach ( wp_kses_post_deep( wp_unslash( $_POST['items'] ) ) as $data ) {
859
+        foreach (wp_kses_post_deep(wp_unslash($_POST['items'])) as $data) {
860 860
 
861
-            $item = new GetPaid_Form_Item( (int) $data['id'] );
861
+            $item = new GetPaid_Form_Item((int) $data['id']);
862 862
 
863
-            if ( is_numeric( $data['qty'] ) && (float) $data['qty'] > 0 ) {
864
-                $item->set_quantity( floatval( $data['qty'] ) );
863
+            if (is_numeric($data['qty']) && (float) $data['qty'] > 0) {
864
+                $item->set_quantity(floatval($data['qty']));
865 865
             }
866 866
 
867
-            if ( $item->get_id() > 0 ) {
868
-                $error = $invoice->add_item( $item );
867
+            if ($item->get_id() > 0) {
868
+                $error = $invoice->add_item($item);
869 869
 
870
-                if ( is_wp_error( $error ) ) {
870
+                if (is_wp_error($error)) {
871 871
                     $alert = $error->get_error_message();
872 872
                 }
873 873
 }
@@ -880,11 +880,11 @@  discard block
 block discarded – undo
880 880
         // Return an array of invoice items.
881 881
         $items = array();
882 882
 
883
-        foreach ( $invoice->get_items() as $item ) {
884
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
883
+        foreach ($invoice->get_items() as $item) {
884
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
885 885
         }
886 886
 
887
-        wp_send_json_success( compact( 'items', 'alert' ) );
887
+        wp_send_json_success(compact('items', 'alert'));
888 888
     }
889 889
 
890 890
     /**
@@ -893,15 +893,15 @@  discard block
 block discarded – undo
893 893
     public static function get_invoicing_items() {
894 894
 
895 895
         // Verify nonce.
896
-        check_ajax_referer( 'wpinv-nonce' );
896
+        check_ajax_referer('wpinv-nonce');
897 897
 
898
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
898
+        if (!wpinv_current_user_can_manage_invoicing()) {
899 899
             exit;
900 900
         }
901 901
 
902 902
         // We need a search term.
903
-        if ( empty( $_GET['search'] ) ) {
904
-            wp_send_json_success( array() );
903
+        if (empty($_GET['search'])) {
904
+            wp_send_json_success(array());
905 905
         }
906 906
 
907 907
         // Retrieve items.
@@ -910,8 +910,8 @@  discard block
 block discarded – undo
910 910
             'orderby'        => 'title',
911 911
             'order'          => 'ASC',
912 912
             'posts_per_page' => -1,
913
-            'post_status'    => array( 'publish' ),
914
-            's'              => sanitize_text_field( urldecode( $_GET['search'] ) ),
913
+            'post_status'    => array('publish'),
914
+            's'              => sanitize_text_field(urldecode($_GET['search'])),
915 915
             'meta_query'     => array(
916 916
                 array(
917 917
                     'key'     => '_wpinv_type',
@@ -921,25 +921,25 @@  discard block
 block discarded – undo
921 921
             ),
922 922
         );
923 923
 
924
-        if ( ! empty( $_GET['ignore'] ) ) {
925
-            $item_args['exclude'] = wp_parse_id_list( sanitize_text_field( $_GET['ignore'] ) );
924
+        if (!empty($_GET['ignore'])) {
925
+            $item_args['exclude'] = wp_parse_id_list(sanitize_text_field($_GET['ignore']));
926 926
         }
927 927
 
928
-        $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) );
928
+        $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args));
929 929
         $data  = array();
930 930
 
931
-        $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( (int) $_GET['post_id'] ) );
931
+        $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type((int) $_GET['post_id']));
932 932
 
933
-        foreach ( $items as $item ) {
934
-            $item      = new GetPaid_Form_Item( $item );
933
+        foreach ($items as $item) {
934
+            $item = new GetPaid_Form_Item($item);
935 935
             $data[] = array(
936 936
                 'id'        => (int) $item->get_id(),
937
-                'text'      => strip_tags( $item->get_name() ),
938
-                'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '',
937
+                'text'      => strip_tags($item->get_name()),
938
+                'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '',
939 939
             );
940 940
         }
941 941
 
942
-        wp_send_json_success( $data );
942
+        wp_send_json_success($data);
943 943
 
944 944
     }
945 945
 
@@ -949,37 +949,37 @@  discard block
 block discarded – undo
949 949
     public static function get_customers() {
950 950
 
951 951
         // Verify nonce.
952
-        check_ajax_referer( 'wpinv-nonce' );
952
+        check_ajax_referer('wpinv-nonce');
953 953
 
954
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
954
+        if (!wpinv_current_user_can_manage_invoicing()) {
955 955
             exit;
956 956
         }
957 957
 
958 958
         // We need a search term.
959
-        if ( empty( $_GET['search'] ) ) {
960
-            wp_send_json_success( array() );
959
+        if (empty($_GET['search'])) {
960
+            wp_send_json_success(array());
961 961
         }
962 962
 
963 963
         // Retrieve customers.
964 964
 
965 965
         $customer_args = array(
966
-            'fields'         => array( 'ID', 'user_email', 'display_name' ),
966
+            'fields'         => array('ID', 'user_email', 'display_name'),
967 967
             'orderby'        => 'display_name',
968
-            'search'         => '*' . sanitize_text_field( $_GET['search'] ) . '*',
969
-            'search_columns' => array( 'user_login', 'user_email', 'display_name' ),
968
+            'search'         => '*' . sanitize_text_field($_GET['search']) . '*',
969
+            'search_columns' => array('user_login', 'user_email', 'display_name'),
970 970
         );
971 971
 
972
-        $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) );
972
+        $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args));
973 973
         $data      = array();
974 974
 
975
-        foreach ( $customers as $customer ) {
975
+        foreach ($customers as $customer) {
976 976
             $data[] = array(
977 977
                 'id'   => (int) $customer->ID,
978
-                'text' => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ),
978
+                'text' => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)),
979 979
             );
980 980
         }
981 981
 
982
-        wp_send_json_success( $data );
982
+        wp_send_json_success($data);
983 983
 
984 984
     }
985 985
 
@@ -989,28 +989,28 @@  discard block
 block discarded – undo
989 989
     public static function get_aui_states_field() {
990 990
 
991 991
         // Verify nonce.
992
-        check_ajax_referer( 'wpinv-nonce' );
992
+        check_ajax_referer('wpinv-nonce');
993 993
 
994 994
         // We need a country.
995
-        if ( empty( $_GET['country'] ) ) {
995
+        if (empty($_GET['country'])) {
996 996
             exit;
997 997
         }
998 998
 
999
-        $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) );
1000
-        $state  = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state();
1001
-        $name   = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state';
1002
-        $class  = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm';
999
+        $states = wpinv_get_country_states(sanitize_text_field($_GET['country']));
1000
+        $state  = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state();
1001
+        $name   = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state';
1002
+        $class  = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm';
1003 1003
 
1004
-        if ( empty( $states ) ) {
1004
+        if (empty($states)) {
1005 1005
 
1006 1006
             $html = aui()->input(
1007 1007
                 array(
1008 1008
                     'type'        => 'text',
1009 1009
                     'id'          => 'wpinv_state',
1010 1010
                     'name'        => $name,
1011
-                    'label'       => __( 'State', 'invoicing' ),
1011
+                    'label'       => __('State', 'invoicing'),
1012 1012
                     'label_type'  => 'vertical',
1013
-                    'placeholder' => __( 'State', 'invoicing' ),
1013
+                    'placeholder' => __('State', 'invoicing'),
1014 1014
                     'class'       => $class,
1015 1015
                     'value'       => $state,
1016 1016
                 )
@@ -1022,9 +1022,9 @@  discard block
 block discarded – undo
1022 1022
                 array(
1023 1023
                     'id'               => 'wpinv_state',
1024 1024
                     'name'             => $name,
1025
-                    'label'            => __( 'State', 'invoicing' ),
1025
+                    'label'            => __('State', 'invoicing'),
1026 1026
                     'label_type'       => 'vertical',
1027
-                    'placeholder'      => __( 'Select a state', 'invoicing' ),
1027
+                    'placeholder'      => __('Select a state', 'invoicing'),
1028 1028
                     'class'            => $class,
1029 1029
                     'value'            => $state,
1030 1030
                     'options'          => $states,
@@ -1038,7 +1038,7 @@  discard block
 block discarded – undo
1038 1038
         wp_send_json_success(
1039 1039
             array(
1040 1040
                 'html'   => $html,
1041
-                'select' => ! empty( $states ),
1041
+                'select' => !empty($states),
1042 1042
             )
1043 1043
         );
1044 1044
 
@@ -1052,11 +1052,11 @@  discard block
 block discarded – undo
1052 1052
     public static function payment_form_refresh_prices() {
1053 1053
 
1054 1054
         // Check nonce.
1055
-        check_ajax_referer( 'getpaid_form_nonce' );
1055
+        check_ajax_referer('getpaid_form_nonce');
1056 1056
 
1057 1057
         // ... form fields...
1058
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
1059
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
1058
+        if (empty($_POST['getpaid_payment_form_submission'])) {
1059
+            _e('Error: Reload the page and try again.', 'invoicing');
1060 1060
             exit;
1061 1061
         }
1062 1062
 
@@ -1064,7 +1064,7 @@  discard block
 block discarded – undo
1064 1064
         $submission = new GetPaid_Payment_Form_Submission();
1065 1065
 
1066 1066
         // Do we have an error?
1067
-        if ( ! empty( $submission->last_error ) ) {
1067
+        if (!empty($submission->last_error)) {
1068 1068
             wp_send_json_error(
1069 1069
                 array(
1070 1070
                     'code'  => $submission->last_error_code,
@@ -1074,12 +1074,12 @@  discard block
 block discarded – undo
1074 1074
         }
1075 1075
 
1076 1076
         // Prepare the response.
1077
-        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission );
1077
+        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission);
1078 1078
 
1079 1079
         // Filter the response.
1080
-        $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission );
1080
+        $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission);
1081 1081
 
1082
-        wp_send_json_success( $response );
1082
+        wp_send_json_success($response);
1083 1083
     }
1084 1084
 
1085 1085
     /**
@@ -1091,63 +1091,63 @@  discard block
 block discarded – undo
1091 1091
 	public static function file_upload() {
1092 1092
 
1093 1093
         // Check nonce.
1094
-        check_ajax_referer( 'getpaid_form_nonce' );
1094
+        check_ajax_referer('getpaid_form_nonce');
1095 1095
 
1096
-        if ( empty( $_POST['form_id'] ) || empty( $_POST['field_name'] ) || empty( $_FILES['file'] ) ) {
1097
-            wp_die( __( 'Bad Request', 'invoicing' ), 400 );
1096
+        if (empty($_POST['form_id']) || empty($_POST['field_name']) || empty($_FILES['file'])) {
1097
+            wp_die(__('Bad Request', 'invoicing'), 400);
1098 1098
         }
1099 1099
 
1100 1100
         // Fetch form.
1101
-        $form = new GetPaid_Payment_Form( intval( $_POST['form_id'] ) );
1101
+        $form = new GetPaid_Payment_Form(intval($_POST['form_id']));
1102 1102
 
1103
-        if ( ! $form->is_active() ) {
1104
-            wp_send_json_error( __( 'Payment form not active', 'invoicing' ) );
1103
+        if (!$form->is_active()) {
1104
+            wp_send_json_error(__('Payment form not active', 'invoicing'));
1105 1105
         }
1106 1106
 
1107 1107
         // Fetch appropriate field.
1108
-        $upload_field = current( wp_list_filter( $form->get_elements(), array( 'id' => sanitize_text_field( $_POST['field_name'] ) ) ) );
1109
-        if ( empty( $upload_field ) ) {
1110
-            wp_send_json_error( __( 'Invalid upload field.', 'invoicing' ) );
1108
+        $upload_field = current(wp_list_filter($form->get_elements(), array('id' => sanitize_text_field($_POST['field_name']))));
1109
+        if (empty($upload_field)) {
1110
+            wp_send_json_error(__('Invalid upload field.', 'invoicing'));
1111 1111
         }
1112 1112
 
1113 1113
         // Prepare allowed file types.
1114
-        $file_types = isset( $upload_field['file_types'] ) ? $upload_field['file_types'] : array( 'jpg|jpeg|jpe', 'gif', 'png' );
1114
+        $file_types = isset($upload_field['file_types']) ? $upload_field['file_types'] : array('jpg|jpeg|jpe', 'gif', 'png');
1115 1115
         $all_types  = getpaid_get_allowed_mime_types();
1116 1116
         $mime_types = array();
1117 1117
 
1118
-        foreach ( $file_types as $file_type ) {
1119
-            if ( isset( $all_types[ $file_type ] ) ) {
1120
-                $mime_types[] = $all_types[ $file_type ];
1118
+        foreach ($file_types as $file_type) {
1119
+            if (isset($all_types[$file_type])) {
1120
+                $mime_types[] = $all_types[$file_type];
1121 1121
             }
1122 1122
         }
1123 1123
 
1124
-        if ( ! in_array( $_FILES['file']['type'], $mime_types ) ) {
1125
-            wp_send_json_error( __( 'Unsupported file type.', 'invoicing' ) );
1124
+        if (!in_array($_FILES['file']['type'], $mime_types)) {
1125
+            wp_send_json_error(__('Unsupported file type.', 'invoicing'));
1126 1126
         }
1127 1127
 
1128 1128
         // Upload file.
1129
-        $file_name = explode( '.', strtolower( $_FILES['file']['name'] ) );
1130
-        $file_name = uniqid( 'getpaid-' ) . '.' . array_pop( $file_name );
1129
+        $file_name = explode('.', strtolower($_FILES['file']['name']));
1130
+        $file_name = uniqid('getpaid-') . '.' . array_pop($file_name);
1131 1131
 
1132 1132
         $uploaded = wp_upload_bits(
1133 1133
             $file_name,
1134 1134
             null,
1135
-            file_get_contents( $_FILES['file']['tmp_name'] )
1135
+            file_get_contents($_FILES['file']['tmp_name'])
1136 1136
         );
1137 1137
 
1138
-        if ( ! empty( $uploaded['error'] ) ) {
1139
-            wp_send_json_error( $uploaded['error'] );
1138
+        if (!empty($uploaded['error'])) {
1139
+            wp_send_json_error($uploaded['error']);
1140 1140
         }
1141 1141
 
1142 1142
         // Retrieve response.
1143 1143
         $response = sprintf(
1144 1144
             '<input type="hidden" name="%s[%s]" value="%s" />',
1145
-            esc_attr( sanitize_text_field( $_POST['field_name'] ) ),
1146
-            esc_url( $uploaded['url'] ),
1147
-            esc_attr( sanitize_text_field( strtolower( $_FILES['file']['name'] ) ) )
1145
+            esc_attr(sanitize_text_field($_POST['field_name'])),
1146
+            esc_url($uploaded['url']),
1147
+            esc_attr(sanitize_text_field(strtolower($_FILES['file']['name'])))
1148 1148
         );
1149 1149
 
1150
-        wp_send_json_success( $response );
1150
+        wp_send_json_success($response);
1151 1151
 
1152 1152
 	}
1153 1153
 
Please login to merge, or discard this patch.
includes/class-wpinv-notes.php 2 patches
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -12,207 +12,207 @@
 block discarded – undo
12 12
  */
13 13
 class WPInv_Notes {
14 14
 
15
-	/**
16
-	 * Class constructor.
17
-	 */
18
-	public function __construct() {
19
-
20
-		// Filter inovice notes.
21
-		add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
22
-		add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 );
23
-
24
-		// Delete comments count cache whenever there is a new comment or a comment status changes.
25
-		add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) );
26
-		add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) );
27
-
28
-		// Count comments.
29
-		add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 );
30
-
31
-		// Fires after notes are loaded.
32
-		do_action( 'wpinv_notes_init', $this );
33
-	}
34
-
35
-	/**
36
-	 * Filters invoice notes query to only include our notes.
37
-	 *
38
-	 * @param WP_Comment_Query $query
39
-	 */
40
-	public function set_invoice_note_type( $query ) {
41
-		$post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
42
-
43
-		if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) {
44
-			$query->query_vars['type'] = 'wpinv_note';
45
-		} else {
46
-
47
-			if ( empty( $query->query_vars['type__not_in'] ) ) {
48
-				$query->query_vars['type__not_in'] = array();
49
-			}
50
-
51
-			$query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] );
52
-			$query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] );
53
-		}
54
-
55
-		return $query;
56
-	}
57
-
58
-	/**
59
-	 * Exclude notes from the comments feed.
60
-	 */
61
-	function wpinv_comment_feed_where( $where ) {
62
-		return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
63
-	}
64
-
65
-	/**
66
-	 * Delete comments count cache whenever there is
67
-	 * new comment or the status of a comment changes. Cache
68
-	 * will be regenerated next time WPInv_Notes::wp_count_comments()
69
-	 * is called.
70
-	 */
71
-	public function delete_comments_count_cache() {
72
-		delete_transient( 'getpaid_count_comments' );
73
-	}
74
-
75
-	/**
76
-	 * Remove invoice notes from wp_count_comments().
77
-	 *
78
-	 * @since  2.2
79
-	 * @param  object $stats   Comment stats.
80
-	 * @param  int    $post_id Post ID.
81
-	 * @return object
82
-	 */
83
-	public function wp_count_comments( $stats, $post_id ) {
84
-		global $wpdb;
85
-
86
-		if ( empty( $post_id ) ) {
87
-			$stats = get_transient( 'getpaid_count_comments' );
88
-
89
-			if ( ! $stats ) {
90
-				$stats = array(
91
-					'total_comments' => 0,
92
-					'all'            => 0,
93
-				);
94
-
95
-				$count = $wpdb->get_results(
96
-					"
15
+    /**
16
+     * Class constructor.
17
+     */
18
+    public function __construct() {
19
+
20
+        // Filter inovice notes.
21
+        add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
22
+        add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 );
23
+
24
+        // Delete comments count cache whenever there is a new comment or a comment status changes.
25
+        add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) );
26
+        add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) );
27
+
28
+        // Count comments.
29
+        add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 );
30
+
31
+        // Fires after notes are loaded.
32
+        do_action( 'wpinv_notes_init', $this );
33
+    }
34
+
35
+    /**
36
+     * Filters invoice notes query to only include our notes.
37
+     *
38
+     * @param WP_Comment_Query $query
39
+     */
40
+    public function set_invoice_note_type( $query ) {
41
+        $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
42
+
43
+        if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) {
44
+            $query->query_vars['type'] = 'wpinv_note';
45
+        } else {
46
+
47
+            if ( empty( $query->query_vars['type__not_in'] ) ) {
48
+                $query->query_vars['type__not_in'] = array();
49
+            }
50
+
51
+            $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] );
52
+            $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] );
53
+        }
54
+
55
+        return $query;
56
+    }
57
+
58
+    /**
59
+     * Exclude notes from the comments feed.
60
+     */
61
+    function wpinv_comment_feed_where( $where ) {
62
+        return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
63
+    }
64
+
65
+    /**
66
+     * Delete comments count cache whenever there is
67
+     * new comment or the status of a comment changes. Cache
68
+     * will be regenerated next time WPInv_Notes::wp_count_comments()
69
+     * is called.
70
+     */
71
+    public function delete_comments_count_cache() {
72
+        delete_transient( 'getpaid_count_comments' );
73
+    }
74
+
75
+    /**
76
+     * Remove invoice notes from wp_count_comments().
77
+     *
78
+     * @since  2.2
79
+     * @param  object $stats   Comment stats.
80
+     * @param  int    $post_id Post ID.
81
+     * @return object
82
+     */
83
+    public function wp_count_comments( $stats, $post_id ) {
84
+        global $wpdb;
85
+
86
+        if ( empty( $post_id ) ) {
87
+            $stats = get_transient( 'getpaid_count_comments' );
88
+
89
+            if ( ! $stats ) {
90
+                $stats = array(
91
+                    'total_comments' => 0,
92
+                    'all'            => 0,
93
+                );
94
+
95
+                $count = $wpdb->get_results(
96
+                    "
97 97
 					SELECT comment_approved, COUNT(*) AS num_comments
98 98
 					FROM {$wpdb->comments}
99 99
 					WHERE comment_type NOT IN ('action_log', 'order_note', 'webhook_delivery', 'wpinv_note')
100 100
 					GROUP BY comment_approved
101 101
 					",
102
-					ARRAY_A
103
-				);
104
-
105
-				$approved = array(
106
-					'0'            => 'moderated',
107
-					'1'            => 'approved',
108
-					'spam'         => 'spam',
109
-					'trash'        => 'trash',
110
-					'post-trashed' => 'post-trashed',
111
-				);
112
-
113
-				foreach ( (array) $count as $row ) {
114
-					// Don't count post-trashed toward totals.
115
-					if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) {
116
-						$stats['all']            += $row['num_comments'];
117
-						$stats['total_comments'] += $row['num_comments'];
118
-					} elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) {
119
-						$stats['total_comments'] += $row['num_comments'];
120
-					}
121
-					if ( isset( $approved[ $row['comment_approved'] ] ) ) {
122
-						$stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
123
-					}
124
-				}
125
-
126
-				foreach ( $approved as $key ) {
127
-					if ( empty( $stats[ $key ] ) ) {
128
-						$stats[ $key ] = 0;
129
-					}
130
-				}
131
-
132
-				$stats = (object) $stats;
133
-				set_transient( 'getpaid_count_comments', $stats );
134
-			}
102
+                    ARRAY_A
103
+                );
104
+
105
+                $approved = array(
106
+                    '0'            => 'moderated',
107
+                    '1'            => 'approved',
108
+                    'spam'         => 'spam',
109
+                    'trash'        => 'trash',
110
+                    'post-trashed' => 'post-trashed',
111
+                );
112
+
113
+                foreach ( (array) $count as $row ) {
114
+                    // Don't count post-trashed toward totals.
115
+                    if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) {
116
+                        $stats['all']            += $row['num_comments'];
117
+                        $stats['total_comments'] += $row['num_comments'];
118
+                    } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) {
119
+                        $stats['total_comments'] += $row['num_comments'];
120
+                    }
121
+                    if ( isset( $approved[ $row['comment_approved'] ] ) ) {
122
+                        $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
123
+                    }
124
+                }
125
+
126
+                foreach ( $approved as $key ) {
127
+                    if ( empty( $stats[ $key ] ) ) {
128
+                        $stats[ $key ] = 0;
129
+                    }
130
+                }
131
+
132
+                $stats = (object) $stats;
133
+                set_transient( 'getpaid_count_comments', $stats );
134
+            }
135 135
 }
136 136
 
137
-		return $stats;
138
-	}
139
-
140
-	/**
141
-	 * Returns an array of invoice notes.
142
-	 *
143
-	 * @param int $invoice_id The invoice ID whose notes to retrieve.
144
-	 * @param string $type Optional. Pass in customer to only return customer notes.
145
-	 * @return WP_Comment[]
146
-	 */
147
-	public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) {
148
-
149
-		// Default comment args.
150
-		$args = array(
151
-			'post_id' => $invoice_id,
152
-			'orderby' => 'comment_ID',
153
-			'order'   => 'ASC',
154
-		);
155
-
156
-		// Maybe only show customer comments.
157
-		if ( $type == 'customer' ) {
158
-			$args['meta_key']   = '_wpi_customer_note';
159
-			$args['meta_value'] = 1;
160
-		}
161
-
162
-		$args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
163
-
164
-		return get_comments( $args );
165
-	}
166
-
167
-	/**
168
-	 * Saves an invoice comment.
169
-	 *
170
-	 * @param WPInv_Invoice $invoice The invoice to add the comment to.
171
-	 * @param string $note The note content.
172
-	 * @param string $note_author The name of the author of the note.
173
-	 * @param bool $for_customer Whether or not this comment is meant to be sent to the customer.
174
-	 * @return int|false The new note's ID on success, false on failure.
175
-	 */
176
-	function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) {
177
-
178
-		do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer );
179
-
180
-		/**
181
-		 * Insert the comment.
182
-		 */
183
-		$note_id = wp_insert_comment(
184
-			wp_filter_comment(
185
-				array(
186
-					'comment_post_ID'      => $invoice->get_id(),
187
-					'comment_content'      => $note,
188
-					'comment_agent'        => 'Invoicing',
189
-					'user_id'              => get_current_user_id(),
190
-					'comment_author'       => $note_author,
191
-					'comment_author_IP'    => wpinv_get_ip(),
192
-					'comment_author_email' => $author_email,
193
-					'comment_author_url'   => $invoice->get_view_url(),
194
-					'comment_type'         => 'wpinv_note',
195
-				)
196
-			)
197
-		);
198
-
199
-		do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer );
200
-
201
-		// Are we notifying the customer?
202
-		if ( empty( $note_id ) || empty( $for_customer ) ) {
203
-			return $note_id;
204
-		}
205
-
206
-		add_comment_meta( $note_id, '_wpi_customer_note', 1 );
207
-		do_action(
137
+        return $stats;
138
+    }
139
+
140
+    /**
141
+     * Returns an array of invoice notes.
142
+     *
143
+     * @param int $invoice_id The invoice ID whose notes to retrieve.
144
+     * @param string $type Optional. Pass in customer to only return customer notes.
145
+     * @return WP_Comment[]
146
+     */
147
+    public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) {
148
+
149
+        // Default comment args.
150
+        $args = array(
151
+            'post_id' => $invoice_id,
152
+            'orderby' => 'comment_ID',
153
+            'order'   => 'ASC',
154
+        );
155
+
156
+        // Maybe only show customer comments.
157
+        if ( $type == 'customer' ) {
158
+            $args['meta_key']   = '_wpi_customer_note';
159
+            $args['meta_value'] = 1;
160
+        }
161
+
162
+        $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
163
+
164
+        return get_comments( $args );
165
+    }
166
+
167
+    /**
168
+     * Saves an invoice comment.
169
+     *
170
+     * @param WPInv_Invoice $invoice The invoice to add the comment to.
171
+     * @param string $note The note content.
172
+     * @param string $note_author The name of the author of the note.
173
+     * @param bool $for_customer Whether or not this comment is meant to be sent to the customer.
174
+     * @return int|false The new note's ID on success, false on failure.
175
+     */
176
+    function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) {
177
+
178
+        do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer );
179
+
180
+        /**
181
+         * Insert the comment.
182
+         */
183
+        $note_id = wp_insert_comment(
184
+            wp_filter_comment(
185
+                array(
186
+                    'comment_post_ID'      => $invoice->get_id(),
187
+                    'comment_content'      => $note,
188
+                    'comment_agent'        => 'Invoicing',
189
+                    'user_id'              => get_current_user_id(),
190
+                    'comment_author'       => $note_author,
191
+                    'comment_author_IP'    => wpinv_get_ip(),
192
+                    'comment_author_email' => $author_email,
193
+                    'comment_author_url'   => $invoice->get_view_url(),
194
+                    'comment_type'         => 'wpinv_note',
195
+                )
196
+            )
197
+        );
198
+
199
+        do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer );
200
+
201
+        // Are we notifying the customer?
202
+        if ( empty( $note_id ) || empty( $for_customer ) ) {
203
+            return $note_id;
204
+        }
205
+
206
+        add_comment_meta( $note_id, '_wpi_customer_note', 1 );
207
+        do_action(
208 208
             'wpinv_new_customer_note',
209 209
             array(
210
-				'invoice_id' => $invoice->get_id(),
211
-				'user_note'  => $note,
210
+                'invoice_id' => $invoice->get_id(),
211
+                'user_note'  => $note,
212 212
             )
213 213
         );
214
-		do_action( 'getpaid_new_customer_note', $invoice, $note );
215
-		return $note_id;
216
-	}
214
+        do_action( 'getpaid_new_customer_note', $invoice, $note );
215
+        return $note_id;
216
+    }
217 217
 
218 218
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Handles invoice notes.
@@ -18,18 +18,18 @@  discard block
 block discarded – undo
18 18
 	public function __construct() {
19 19
 
20 20
 		// Filter inovice notes.
21
-		add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
22
-		add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 );
21
+		add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1);
22
+		add_action('comment_feed_where', array($this, 'wpinv_comment_feed_where'), 10, 1);
23 23
 
24 24
 		// Delete comments count cache whenever there is a new comment or a comment status changes.
25
-		add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) );
26
-		add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) );
25
+		add_action('wp_insert_comment', array($this, 'delete_comments_count_cache'));
26
+		add_action('wp_set_comment_status', array($this, 'delete_comments_count_cache'));
27 27
 
28 28
 		// Count comments.
29
-		add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 );
29
+		add_filter('wp_count_comments', array($this, 'wp_count_comments'), 100, 2);
30 30
 
31 31
 		// Fires after notes are loaded.
32
-		do_action( 'wpinv_notes_init', $this );
32
+		do_action('wpinv_notes_init', $this);
33 33
 	}
34 34
 
35 35
 	/**
@@ -37,19 +37,19 @@  discard block
 block discarded – undo
37 37
 	 *
38 38
 	 * @param WP_Comment_Query $query
39 39
 	 */
40
-	public function set_invoice_note_type( $query ) {
41
-		$post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
40
+	public function set_invoice_note_type($query) {
41
+		$post_id = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
42 42
 
43
-		if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) {
43
+		if ($post_id && getpaid_is_invoice_post_type(get_post_type($post_id))) {
44 44
 			$query->query_vars['type'] = 'wpinv_note';
45 45
 		} else {
46 46
 
47
-			if ( empty( $query->query_vars['type__not_in'] ) ) {
47
+			if (empty($query->query_vars['type__not_in'])) {
48 48
 				$query->query_vars['type__not_in'] = array();
49 49
 			}
50 50
 
51
-			$query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] );
52
-			$query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] );
51
+			$query->query_vars['type__not_in'] = wpinv_parse_list($query->query_vars['type__not_in']);
52
+			$query->query_vars['type__not_in'] = array_merge(array('wpinv_note'), $query->query_vars['type__not_in']);
53 53
 		}
54 54
 
55 55
 		return $query;
@@ -58,8 +58,8 @@  discard block
 block discarded – undo
58 58
 	/**
59 59
 	 * Exclude notes from the comments feed.
60 60
 	 */
61
-	function wpinv_comment_feed_where( $where ) {
62
-		return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
61
+	function wpinv_comment_feed_where($where) {
62
+		return $where . ($where ? ' AND ' : '') . " comment_type != 'wpinv_note' ";
63 63
 	}
64 64
 
65 65
 	/**
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 * is called.
70 70
 	 */
71 71
 	public function delete_comments_count_cache() {
72
-		delete_transient( 'getpaid_count_comments' );
72
+		delete_transient('getpaid_count_comments');
73 73
 	}
74 74
 
75 75
 	/**
@@ -80,13 +80,13 @@  discard block
 block discarded – undo
80 80
 	 * @param  int    $post_id Post ID.
81 81
 	 * @return object
82 82
 	 */
83
-	public function wp_count_comments( $stats, $post_id ) {
83
+	public function wp_count_comments($stats, $post_id) {
84 84
 		global $wpdb;
85 85
 
86
-		if ( empty( $post_id ) ) {
87
-			$stats = get_transient( 'getpaid_count_comments' );
86
+		if (empty($post_id)) {
87
+			$stats = get_transient('getpaid_count_comments');
88 88
 
89
-			if ( ! $stats ) {
89
+			if (!$stats) {
90 90
 				$stats = array(
91 91
 					'total_comments' => 0,
92 92
 					'all'            => 0,
@@ -110,27 +110,27 @@  discard block
 block discarded – undo
110 110
 					'post-trashed' => 'post-trashed',
111 111
 				);
112 112
 
113
-				foreach ( (array) $count as $row ) {
113
+				foreach ((array) $count as $row) {
114 114
 					// Don't count post-trashed toward totals.
115
-					if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) {
115
+					if (!in_array($row['comment_approved'], array('post-trashed', 'trash', 'spam'), true)) {
116 116
 						$stats['all']            += $row['num_comments'];
117 117
 						$stats['total_comments'] += $row['num_comments'];
118
-					} elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) {
118
+					} elseif (!in_array($row['comment_approved'], array('post-trashed', 'trash'), true)) {
119 119
 						$stats['total_comments'] += $row['num_comments'];
120 120
 					}
121
-					if ( isset( $approved[ $row['comment_approved'] ] ) ) {
122
-						$stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
121
+					if (isset($approved[$row['comment_approved']])) {
122
+						$stats[$approved[$row['comment_approved']]] = $row['num_comments'];
123 123
 					}
124 124
 				}
125 125
 
126
-				foreach ( $approved as $key ) {
127
-					if ( empty( $stats[ $key ] ) ) {
128
-						$stats[ $key ] = 0;
126
+				foreach ($approved as $key) {
127
+					if (empty($stats[$key])) {
128
+						$stats[$key] = 0;
129 129
 					}
130 130
 				}
131 131
 
132 132
 				$stats = (object) $stats;
133
-				set_transient( 'getpaid_count_comments', $stats );
133
+				set_transient('getpaid_count_comments', $stats);
134 134
 			}
135 135
 }
136 136
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 	 * @param string $type Optional. Pass in customer to only return customer notes.
145 145
 	 * @return WP_Comment[]
146 146
 	 */
147
-	public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) {
147
+	public function get_invoice_notes($invoice_id = 0, $type = 'all') {
148 148
 
149 149
 		// Default comment args.
150 150
 		$args = array(
@@ -154,14 +154,14 @@  discard block
 block discarded – undo
154 154
 		);
155 155
 
156 156
 		// Maybe only show customer comments.
157
-		if ( $type == 'customer' ) {
157
+		if ($type == 'customer') {
158 158
 			$args['meta_key']   = '_wpi_customer_note';
159 159
 			$args['meta_value'] = 1;
160 160
 		}
161 161
 
162
-		$args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
162
+		$args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type);
163 163
 
164
-		return get_comments( $args );
164
+		return get_comments($args);
165 165
 	}
166 166
 
167 167
 	/**
@@ -173,9 +173,9 @@  discard block
 block discarded – undo
173 173
 	 * @param bool $for_customer Whether or not this comment is meant to be sent to the customer.
174 174
 	 * @return int|false The new note's ID on success, false on failure.
175 175
 	 */
176
-	function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) {
176
+	function add_invoice_note($invoice, $note, $note_author, $author_email, $for_customer = false) {
177 177
 
178
-		do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer );
178
+		do_action('wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer);
179 179
 
180 180
 		/**
181 181
 		 * Insert the comment.
@@ -196,14 +196,14 @@  discard block
 block discarded – undo
196 196
 			)
197 197
 		);
198 198
 
199
-		do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer );
199
+		do_action('wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer);
200 200
 
201 201
 		// Are we notifying the customer?
202
-		if ( empty( $note_id ) || empty( $for_customer ) ) {
202
+		if (empty($note_id) || empty($for_customer)) {
203 203
 			return $note_id;
204 204
 		}
205 205
 
206
-		add_comment_meta( $note_id, '_wpi_customer_note', 1 );
206
+		add_comment_meta($note_id, '_wpi_customer_note', 1);
207 207
 		do_action(
208 208
             'wpinv_new_customer_note',
209 209
             array(
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 				'user_note'  => $note,
212 212
             )
213 213
         );
214
-		do_action( 'getpaid_new_customer_note', $invoice, $note );
214
+		do_action('getpaid_new_customer_note', $invoice, $note);
215 215
 		return $note_id;
216 216
 	}
217 217
 
Please login to merge, or discard this patch.
includes/class-bp-getpaid-component.php 2 patches
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -17,45 +17,45 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class BP_GetPaid_Component extends BP_Component {
19 19
 
20
-	/**
21
-	 * Start the component setup process.
22
-	 *
23
-	 * @since 2.1.5
24
-	 */
25
-	public function __construct() {
26
-		parent::start(
27
-			'getpaid',
28
-			'GetPaid',
29
-			buddypress()->plugin_dir,
30
-			array(
31
-				'adminbar_myaccount_order' => 30,
32
-			)
33
-		);
34
-	}
20
+    /**
21
+     * Start the component setup process.
22
+     *
23
+     * @since 2.1.5
24
+     */
25
+    public function __construct() {
26
+        parent::start(
27
+            'getpaid',
28
+            'GetPaid',
29
+            buddypress()->plugin_dir,
30
+            array(
31
+                'adminbar_myaccount_order' => 30,
32
+            )
33
+        );
34
+    }
35 35
 
36 36
     /**
37
-	 * Set up component global variables.
38
-	 *
39
-	 * @since 2.1.5
40
-	 *
41
-	 *
42
-	 * @param array $args {
43
-	 *     All values are optional.
44
-	 *     @type string   $slug                  The component slug. Used to construct certain URLs, such as 'friends' in
45
-	 *                                           http://example.com/members/joe/friends/. Default: the value of $this->id.
46
-	 *     @type string   $root_slug             The component root slug. Note that this value is generally unused if the
47
-	 *                                           component has a root directory (the slug will be overridden by the
48
-	 *                                           post_name of the directory page). Default: the slug of the directory page
49
-	 *                                           if one is found, otherwise an empty string.
50
-	 *     @type bool     $has_directory         Set to true if the component requires an associated WordPress page.
51
-	 *     @type callable $notification_callback Optional. The callable function that formats the component's notifications.
52
-	 *     @type string   $search_term           Optional. The placeholder text in the component directory search box. Eg,
53
-	 *                                           'Search Groups...'.
54
-	 *     @type array    $global_tables         Optional. An array of database table names.
55
-	 *     @type array    $meta_tables           Optional. An array of metadata table names.
56
-	 * }
57
-	 */
58
-	public function setup_globals( $args = array() ) {
37
+     * Set up component global variables.
38
+     *
39
+     * @since 2.1.5
40
+     *
41
+     *
42
+     * @param array $args {
43
+     *     All values are optional.
44
+     *     @type string   $slug                  The component slug. Used to construct certain URLs, such as 'friends' in
45
+     *                                           http://example.com/members/joe/friends/. Default: the value of $this->id.
46
+     *     @type string   $root_slug             The component root slug. Note that this value is generally unused if the
47
+     *                                           component has a root directory (the slug will be overridden by the
48
+     *                                           post_name of the directory page). Default: the slug of the directory page
49
+     *                                           if one is found, otherwise an empty string.
50
+     *     @type bool     $has_directory         Set to true if the component requires an associated WordPress page.
51
+     *     @type callable $notification_callback Optional. The callable function that formats the component's notifications.
52
+     *     @type string   $search_term           Optional. The placeholder text in the component directory search box. Eg,
53
+     *                                           'Search Groups...'.
54
+     *     @type array    $global_tables         Optional. An array of database table names.
55
+     *     @type array    $meta_tables           Optional. An array of metadata table names.
56
+     * }
57
+     */
58
+    public function setup_globals( $args = array() ) {
59 59
         parent::setup_globals(
60 60
             array(
61 61
                 'id'            => 'getpaid',
@@ -64,21 +64,21 @@  discard block
 block discarded – undo
64 64
                 'has_directory' => false,
65 65
             )
66 66
         );
67
-	}
68
-
69
-	/**
70
-	 * Set up component navigation.
71
-	 *
72
-	 * @since 2.1.5
73
-	 *
74
-	 * @see BP_Component::setup_nav() for a description of arguments.
75
-	 *
76
-	 * @param array $main_nav Optional. See BP_Component::setup_nav() for description.
77
-	 * @param array $sub_nav  Optional. See BP_Component::setup_nav() for description.
78
-	 */
79
-	public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
80
-
81
-		// Abort if the integration is inactive.
67
+    }
68
+
69
+    /**
70
+     * Set up component navigation.
71
+     *
72
+     * @since 2.1.5
73
+     *
74
+     * @see BP_Component::setup_nav() for a description of arguments.
75
+     *
76
+     * @param array $main_nav Optional. See BP_Component::setup_nav() for description.
77
+     * @param array $sub_nav  Optional. See BP_Component::setup_nav() for description.
78
+     */
79
+    public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
80
+
81
+        // Abort if the integration is inactive.
82 82
         if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) {
83 83
             return;
84 84
         }
@@ -88,25 +88,25 @@  discard block
 block discarded – undo
88 88
             return;
89 89
         }
90 90
 
91
-		// Determine user to use.
92
-		$user_domain   = bp_loggedin_user_domain();
93
-		$slug          = 'getpaid';
94
-		$payments_link = trailingslashit( $user_domain . $slug );
95
-
96
-		// Add 'Payments' to the main navigation.
97
-		$main_nav = array(
98
-			'name'                    => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ),
99
-			'slug'                    => $slug,
100
-			'position'                => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ),
101
-			'screen_function'         => array( $this, 'display_current_tab' ),
102
-			'default_subnav_slug'     => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ),
91
+        // Determine user to use.
92
+        $user_domain   = bp_loggedin_user_domain();
93
+        $slug          = 'getpaid';
94
+        $payments_link = trailingslashit( $user_domain . $slug );
95
+
96
+        // Add 'Payments' to the main navigation.
97
+        $main_nav = array(
98
+            'name'                    => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ),
99
+            'slug'                    => $slug,
100
+            'position'                => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ),
101
+            'screen_function'         => array( $this, 'display_current_tab' ),
102
+            'default_subnav_slug'     => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ),
103 103
             'show_for_displayed_user' => false,
104
-			'item_css_id'             => $this->id,
105
-			'parent_url'              => $user_domain,
106
-			'parent_slug'             => buddypress()->slug,
107
-		);
104
+            'item_css_id'             => $this->id,
105
+            'parent_url'              => $user_domain,
106
+            'parent_slug'             => buddypress()->slug,
107
+        );
108 108
 
109
-		// Add the subnav items to the payments nav item if we are using a theme that supports this.
109
+        // Add the subnav items to the payments nav item if we are using a theme that supports this.
110 110
         foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) {
111 111
 
112 112
             $sub_nav[] = array(
@@ -116,8 +116,8 @@  discard block
 block discarded – undo
116 116
                 'parent_slug'             => $slug,
117 117
                 'position'                => 10,
118 118
                 'screen_function'         => function() use ( $tab ) {
119
-					$GLOBALS['getpaid_bp_current_tab'] = $tab;
120
-					$this->display_current_tab();
119
+                    $GLOBALS['getpaid_bp_current_tab'] = $tab;
120
+                    $this->display_current_tab();
121 121
                 },
122 122
                 'show_for_displayed_user' => false,
123 123
                 'item_css_id'             => "getpaid-bp-$_slug",
@@ -125,27 +125,27 @@  discard block
 block discarded – undo
125 125
 
126 126
         }
127 127
 
128
-		parent::setup_nav( $main_nav, $sub_nav );
129
-	}
130
-
131
-	/**
132
-	 * Set up the component entries in the WordPress Admin Bar.
133
-	 *
134
-	 * @since 2.1.5
135
-	 *
136
-	 * @see BP_Component::setup_nav() for a description of the $wp_admin_nav
137
-	 *      parameter array.
138
-	 *
139
-	 * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a
140
-	 *                            description.
141
-	 */
142
-	public function setup_admin_bar( $wp_admin_nav = array() ) {
128
+        parent::setup_nav( $main_nav, $sub_nav );
129
+    }
143 130
 
144
-		// Menus for logged in user.
145
-		if ( is_user_logged_in() ) {
146
-
147
-			// Setup the logged in user variables.
148
-			$payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' );
131
+    /**
132
+     * Set up the component entries in the WordPress Admin Bar.
133
+     *
134
+     * @since 2.1.5
135
+     *
136
+     * @see BP_Component::setup_nav() for a description of the $wp_admin_nav
137
+     *      parameter array.
138
+     *
139
+     * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a
140
+     *                            description.
141
+     */
142
+    public function setup_admin_bar( $wp_admin_nav = array() ) {
143
+
144
+        // Menus for logged in user.
145
+        if ( is_user_logged_in() ) {
146
+
147
+            // Setup the logged in user variables.
148
+            $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' );
149 149
 
150 150
             // Add the "Payments" sub menu.
151 151
             $wp_admin_nav[] = array(
@@ -168,48 +168,48 @@  discard block
 block discarded – undo
168 168
             }
169 169
 }
170 170
 
171
-		parent::setup_admin_bar( $wp_admin_nav );
172
-	}
173
-
174
-	/**
175
-	 * Retrieves the current tab.
176
-	 *
177
-	 * @since 2.1.5
178
-	 */
179
-	public function get_current_tab() {
180
-		global $getpaid_bp_current_tab;
181
-
182
-		if ( empty( $getpaid_bp_current_tab ) ) {
183
-			return array(
184
-				'label'   => __( 'Invoices', 'invoicing' ),
185
-				'content' => '[wpinv_history]',
186
-				'icon'    => 'fas fa-file-invoice',
187
-			);
188
-		}
189
-
190
-		return $getpaid_bp_current_tab;
191
-	}
192
-
193
-	/**
194
-	 * Displays the current tab.
195
-	 *
196
-	 * @since 2.1.5
197
-	 */
198
-	public function display_current_tab() {
199
-
200
-		add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) );
201
-		$template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' );
171
+        parent::setup_admin_bar( $wp_admin_nav );
172
+    }
173
+
174
+    /**
175
+     * Retrieves the current tab.
176
+     *
177
+     * @since 2.1.5
178
+     */
179
+    public function get_current_tab() {
180
+        global $getpaid_bp_current_tab;
181
+
182
+        if ( empty( $getpaid_bp_current_tab ) ) {
183
+            return array(
184
+                'label'   => __( 'Invoices', 'invoicing' ),
185
+                'content' => '[wpinv_history]',
186
+                'icon'    => 'fas fa-file-invoice',
187
+            );
188
+        }
189
+
190
+        return $getpaid_bp_current_tab;
191
+    }
192
+
193
+    /**
194
+     * Displays the current tab.
195
+     *
196
+     * @since 2.1.5
197
+     */
198
+    public function display_current_tab() {
199
+
200
+        add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) );
201
+        $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' );
202 202
 
203 203
         bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) );
204
-	}
205
-
206
-	/**
207
-	 * Handles the actual display of the current tab.
208
-	 *
209
-	 * @since 2.1.5
210
-	 */
211
-	public function handle_display_current_tab() {
212
-		 getpaid_prepare_user_content_tab( $this->get_current_tab() );
213
-	}
204
+    }
205
+
206
+    /**
207
+     * Handles the actual display of the current tab.
208
+     *
209
+     * @since 2.1.5
210
+     */
211
+    public function handle_display_current_tab() {
212
+            getpaid_prepare_user_content_tab( $this->get_current_tab() );
213
+    }
214 214
 
215 215
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 // Exit if accessed directly.
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * Main GetPaid Class.
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	 *     @type array    $meta_tables           Optional. An array of metadata table names.
56 56
 	 * }
57 57
 	 */
58
-	public function setup_globals( $args = array() ) {
58
+	public function setup_globals($args = array()) {
59 59
         parent::setup_globals(
60 60
             array(
61 61
                 'id'            => 'getpaid',
@@ -76,30 +76,30 @@  discard block
 block discarded – undo
76 76
 	 * @param array $main_nav Optional. See BP_Component::setup_nav() for description.
77 77
 	 * @param array $sub_nav  Optional. See BP_Component::setup_nav() for description.
78 78
 	 */
79
-	public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
79
+	public function setup_nav($main_nav = array(), $sub_nav = array()) {
80 80
 
81 81
 		// Abort if the integration is inactive.
82
-        if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) {
82
+        if (!getpaid_is_buddypress_integration_active() || !is_user_logged_in()) {
83 83
             return;
84 84
         }
85 85
 
86 86
         // Or a user is not viewing their profile.
87
-        if ( bp_displayed_user_id() != bp_loggedin_user_id() ) {
87
+        if (bp_displayed_user_id() != bp_loggedin_user_id()) {
88 88
             return;
89 89
         }
90 90
 
91 91
 		// Determine user to use.
92 92
 		$user_domain   = bp_loggedin_user_domain();
93 93
 		$slug          = 'getpaid';
94
-		$payments_link = trailingslashit( $user_domain . $slug );
94
+		$payments_link = trailingslashit($user_domain . $slug);
95 95
 
96 96
 		// Add 'Payments' to the main navigation.
97 97
 		$main_nav = array(
98
-			'name'                    => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ),
98
+			'name'                    => _x('Billing', 'BuddyPress profile payments screen nav', 'invoicing'),
99 99
 			'slug'                    => $slug,
100
-			'position'                => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ),
101
-			'screen_function'         => array( $this, 'display_current_tab' ),
102
-			'default_subnav_slug'     => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ),
100
+			'position'                => apply_filters('wpinv_bp_nav_position', wpinv_get_option('wpinv_menu_position', 91), $slug),
101
+			'screen_function'         => array($this, 'display_current_tab'),
102
+			'default_subnav_slug'     => apply_filters('getpaid_default_tab', 'gp-edit-address'),
103 103
             'show_for_displayed_user' => false,
104 104
 			'item_css_id'             => $this->id,
105 105
 			'parent_url'              => $user_domain,
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 		);
108 108
 
109 109
 		// Add the subnav items to the payments nav item if we are using a theme that supports this.
110
-        foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) {
110
+        foreach (getpaid_get_user_content_tabs() as $_slug => $tab) {
111 111
 
112 112
             $sub_nav[] = array(
113 113
                 'name'                    => $tab['label'],
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
                 'parent_url'              => $payments_link,
116 116
                 'parent_slug'             => $slug,
117 117
                 'position'                => 10,
118
-                'screen_function'         => function() use ( $tab ) {
118
+                'screen_function'         => function() use ($tab) {
119 119
 					$GLOBALS['getpaid_bp_current_tab'] = $tab;
120 120
 					$this->display_current_tab();
121 121
                 },
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 
126 126
         }
127 127
 
128
-		parent::setup_nav( $main_nav, $sub_nav );
128
+		parent::setup_nav($main_nav, $sub_nav);
129 129
 	}
130 130
 
131 131
 	/**
@@ -139,36 +139,36 @@  discard block
 block discarded – undo
139 139
 	 * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a
140 140
 	 *                            description.
141 141
 	 */
142
-	public function setup_admin_bar( $wp_admin_nav = array() ) {
142
+	public function setup_admin_bar($wp_admin_nav = array()) {
143 143
 
144 144
 		// Menus for logged in user.
145
-		if ( is_user_logged_in() ) {
145
+		if (is_user_logged_in()) {
146 146
 
147 147
 			// Setup the logged in user variables.
148
-			$payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' );
148
+			$payments_link = trailingslashit(bp_loggedin_user_domain() . 'getpaid/');
149 149
 
150 150
             // Add the "Payments" sub menu.
151 151
             $wp_admin_nav[] = array(
152 152
                 'parent' => buddypress()->my_account_menu_id,
153 153
                 'id'     => 'my-account-getpaid',
154
-                'title'  => _x( 'Billing', 'BuddyPress my account payments sub nav', 'invoicing' ),
155
-                'href'   => $payments_link . apply_filters( 'getpaid_default_tab', 'gp-edit-address' ),
154
+                'title'  => _x('Billing', 'BuddyPress my account payments sub nav', 'invoicing'),
155
+                'href'   => $payments_link . apply_filters('getpaid_default_tab', 'gp-edit-address'),
156 156
             );
157 157
 
158
-            foreach ( getpaid_get_user_content_tabs() as $slug => $tab ) {
158
+            foreach (getpaid_get_user_content_tabs() as $slug => $tab) {
159 159
 
160 160
                 $wp_admin_nav[] = array(
161 161
                     'parent'   => 'my-account-getpaid',
162 162
                     'id'       => 'my-account-getpaid' . $slug,
163 163
                     'title'    => $tab['label'],
164
-                    'href'     => trailingslashit( $payments_link . $slug ),
164
+                    'href'     => trailingslashit($payments_link . $slug),
165 165
                     'position' => 20,
166 166
                 );
167 167
 
168 168
             }
169 169
 }
170 170
 
171
-		parent::setup_admin_bar( $wp_admin_nav );
171
+		parent::setup_admin_bar($wp_admin_nav);
172 172
 	}
173 173
 
174 174
 	/**
@@ -179,9 +179,9 @@  discard block
 block discarded – undo
179 179
 	public function get_current_tab() {
180 180
 		global $getpaid_bp_current_tab;
181 181
 
182
-		if ( empty( $getpaid_bp_current_tab ) ) {
182
+		if (empty($getpaid_bp_current_tab)) {
183 183
 			return array(
184
-				'label'   => __( 'Invoices', 'invoicing' ),
184
+				'label'   => __('Invoices', 'invoicing'),
185 185
 				'content' => '[wpinv_history]',
186 186
 				'icon'    => 'fas fa-file-invoice',
187 187
 			);
@@ -197,10 +197,10 @@  discard block
 block discarded – undo
197 197
 	 */
198 198
 	public function display_current_tab() {
199 199
 
200
-		add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) );
201
-		$template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' );
200
+		add_action('bp_template_content', array($this, 'handle_display_current_tab'));
201
+		$template = apply_filters('bp_core_template_plugin', 'members/single/plugins');
202 202
 
203
-        bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) );
203
+        bp_core_load_template(apply_filters('wpinv_bp_core_template_plugin', $template));
204 204
 	}
205 205
 
206 206
 	/**
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 	 * @since 2.1.5
210 210
 	 */
211 211
 	public function handle_display_current_tab() {
212
-		 getpaid_prepare_user_content_tab( $this->get_current_tab() );
212
+		 getpaid_prepare_user_content_tab($this->get_current_tab());
213 213
 	}
214 214
 
215 215
 }
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 2 patches
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
141 141
  */
142 142
 function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
143
-	return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path );
143
+    return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path );
144 144
 }
145 145
 
146 146
 /**
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
  * @return string
159 159
  */
160 160
 function wpinv_get_theme_template_dir_name() {
161
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
161
+    return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
162 162
 }
163 163
 
164 164
 /**
@@ -175,125 +175,125 @@  discard block
 block discarded – undo
175 175
 }
176 176
 
177 177
 function wpinv_get_template_part( $slug, $name = null, $load = true ) {
178
-	do_action( 'get_template_part_' . $slug, $slug, $name );
178
+    do_action( 'get_template_part_' . $slug, $slug, $name );
179 179
 
180
-	// Setup possible parts
181
-	$templates = array();
182
-	if ( isset( $name ) ) {
183
-		$templates[] = $slug . '-' . $name . '.php';
180
+    // Setup possible parts
181
+    $templates = array();
182
+    if ( isset( $name ) ) {
183
+        $templates[] = $slug . '-' . $name . '.php';
184 184
     }
185
-	$templates[] = $slug . '.php';
185
+    $templates[] = $slug . '.php';
186 186
 
187
-	// Allow template parts to be filtered
188
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
187
+    // Allow template parts to be filtered
188
+    $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
189 189
 
190
-	// Return the part that is found
191
-	return wpinv_locate_tmpl( $templates, $load, false );
190
+    // Return the part that is found
191
+    return wpinv_locate_tmpl( $templates, $load, false );
192 192
 }
193 193
 
194 194
 function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
195
-	// No file found yet
196
-	$located = false;
195
+    // No file found yet
196
+    $located = false;
197 197
 
198
-	// Try to find a template file
199
-	foreach ( (array)$template_names as $template_name ) {
198
+    // Try to find a template file
199
+    foreach ( (array)$template_names as $template_name ) {
200 200
 
201
-		// Continue if template is empty
202
-		if ( empty( $template_name ) ) {
203
-			continue;
201
+        // Continue if template is empty
202
+        if ( empty( $template_name ) ) {
203
+            continue;
204 204
         }
205 205
 
206
-		// Trim off any slashes from the template name
207
-		$template_name = ltrim( $template_name, '/' );
206
+        // Trim off any slashes from the template name
207
+        $template_name = ltrim( $template_name, '/' );
208 208
 
209
-		// try locating this template file by looping through the template paths
210
-		foreach ( wpinv_get_theme_template_paths() as $template_path ) {
209
+        // try locating this template file by looping through the template paths
210
+        foreach ( wpinv_get_theme_template_paths() as $template_path ) {
211 211
 
212
-			if ( file_exists( $template_path . $template_name ) ) {
213
-				$located = $template_path . $template_name;
214
-				break;
215
-			}
216
-		}
212
+            if ( file_exists( $template_path . $template_name ) ) {
213
+                $located = $template_path . $template_name;
214
+                break;
215
+            }
216
+        }
217 217
 
218
-		if ( ! empty( $located ) ) {
219
-			break;
220
-		}
221
-	}
218
+        if ( ! empty( $located ) ) {
219
+            break;
220
+        }
221
+    }
222 222
 
223
-	if ( ( true == $load ) && ! empty( $located ) ) {
224
-		load_template( $located, $require_once );
223
+    if ( ( true == $load ) && ! empty( $located ) ) {
224
+        load_template( $located, $require_once );
225 225
     }
226 226
 
227
-	return $located;
227
+    return $located;
228 228
 }
229 229
 
230 230
 function wpinv_get_theme_template_paths() {
231
-	$template_dir = wpinv_get_theme_template_dir_name();
231
+    $template_dir = wpinv_get_theme_template_dir_name();
232 232
 
233
-	$file_paths = array(
234
-		1   => trailingslashit( get_stylesheet_directory() ) . $template_dir,
235
-		10  => trailingslashit( get_template_directory() ) . $template_dir,
236
-		100 => wpinv_get_templates_dir(),
237
-	);
233
+    $file_paths = array(
234
+        1   => trailingslashit( get_stylesheet_directory() ) . $template_dir,
235
+        10  => trailingslashit( get_template_directory() ) . $template_dir,
236
+        100 => wpinv_get_templates_dir(),
237
+    );
238 238
 
239
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
239
+    $file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
240 240
 
241
-	// sort the file paths based on priority
242
-	ksort( $file_paths, SORT_NUMERIC );
241
+    // sort the file paths based on priority
242
+    ksort( $file_paths, SORT_NUMERIC );
243 243
 
244
-	return array_map( 'trailingslashit', $file_paths );
244
+    return array_map( 'trailingslashit', $file_paths );
245 245
 }
246 246
 
247 247
 function wpinv_checkout_meta_tags() {
248 248
 
249
-	$pages   = array();
250
-	$pages[] = wpinv_get_option( 'success_page' );
251
-	$pages[] = wpinv_get_option( 'failure_page' );
252
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
253
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
249
+    $pages   = array();
250
+    $pages[] = wpinv_get_option( 'success_page' );
251
+    $pages[] = wpinv_get_option( 'failure_page' );
252
+    $pages[] = wpinv_get_option( 'invoice_history_page' );
253
+    $pages[] = wpinv_get_option( 'invoice_subscription_page' );
254 254
 
255
-	if ( ! wpinv_is_checkout() && ! is_page( $pages ) ) {
256
-		return;
257
-	}
255
+    if ( ! wpinv_is_checkout() && ! is_page( $pages ) ) {
256
+        return;
257
+    }
258 258
 
259
-	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
259
+    echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
260 260
 }
261 261
 add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
262 262
 
263 263
 function wpinv_add_body_classes( $class ) {
264
-	$classes = (array)$class;
264
+    $classes = (array)$class;
265 265
 
266
-	if ( wpinv_is_checkout() ) {
267
-		$classes[] = 'wpinv-checkout';
268
-		$classes[] = 'wpinv-page';
269
-	}
266
+    if ( wpinv_is_checkout() ) {
267
+        $classes[] = 'wpinv-checkout';
268
+        $classes[] = 'wpinv-page';
269
+    }
270 270
 
271
-	if ( wpinv_is_success_page() ) {
272
-		$classes[] = 'wpinv-success';
273
-		$classes[] = 'wpinv-page';
274
-	}
271
+    if ( wpinv_is_success_page() ) {
272
+        $classes[] = 'wpinv-success';
273
+        $classes[] = 'wpinv-page';
274
+    }
275 275
 
276
-	if ( wpinv_is_failed_transaction_page() ) {
277
-		$classes[] = 'wpinv-failed-transaction';
278
-		$classes[] = 'wpinv-page';
279
-	}
276
+    if ( wpinv_is_failed_transaction_page() ) {
277
+        $classes[] = 'wpinv-failed-transaction';
278
+        $classes[] = 'wpinv-page';
279
+    }
280 280
 
281
-	if ( wpinv_is_invoice_history_page() ) {
282
-		$classes[] = 'wpinv-history';
283
-		$classes[] = 'wpinv-page';
284
-	}
281
+    if ( wpinv_is_invoice_history_page() ) {
282
+        $classes[] = 'wpinv-history';
283
+        $classes[] = 'wpinv-page';
284
+    }
285 285
 
286
-	if ( wpinv_is_subscriptions_history_page() ) {
287
-		$classes[] = 'wpinv-subscription';
288
-		$classes[] = 'wpinv-page';
289
-	}
286
+    if ( wpinv_is_subscriptions_history_page() ) {
287
+        $classes[] = 'wpinv-subscription';
288
+        $classes[] = 'wpinv-page';
289
+    }
290 290
 
291
-	if ( wpinv_is_test_mode() ) {
292
-		$classes[] = 'wpinv-test-mode';
293
-		$classes[] = 'wpinv-page';
294
-	}
291
+    if ( wpinv_is_test_mode() ) {
292
+        $classes[] = 'wpinv-test-mode';
293
+        $classes[] = 'wpinv-page';
294
+    }
295 295
 
296
-	return array_unique( $classes );
296
+    return array_unique( $classes );
297 297
 }
298 298
 add_filter( 'body_class', 'wpinv_add_body_classes' );
299 299
 
@@ -311,11 +311,11 @@  discard block
 block discarded – undo
311 311
 
312 312
     $output = wpinv_html_select(
313 313
         array(
314
-			'name'             => $name,
315
-			'selected'         => $selected,
316
-			'options'          => $options,
317
-			'show_option_all'  => false,
318
-			'show_option_none' => false,
314
+            'name'             => $name,
315
+            'selected'         => $selected,
316
+            'options'          => $options,
317
+            'show_option_all'  => false,
318
+            'show_option_none' => false,
319 319
         )
320 320
     );
321 321
 
@@ -344,11 +344,11 @@  discard block
 block discarded – undo
344 344
 
345 345
     $output = wpinv_html_select(
346 346
         array(
347
-			'name'             => $name,
348
-			'selected'         => $selected,
349
-			'options'          => $options,
350
-			'show_option_all'  => false,
351
-			'show_option_none' => false,
347
+            'name'             => $name,
348
+            'selected'         => $selected,
349
+            'options'          => $options,
350
+            'show_option_all'  => false,
351
+            'show_option_none' => false,
352 352
         )
353 353
     );
354 354
 
@@ -512,16 +512,16 @@  discard block
 block discarded – undo
512 512
 
513 513
     $output = wpinv_html_select(
514 514
         array(
515
-			'name'             => $args['name'],
516
-			'selected'         => $args['selected'],
517
-			'id'               => $args['id'],
518
-			'class'            => $args['class'],
519
-			'options'          => $options,
520
-			'multiple'         => $args['multiple'],
521
-			'placeholder'      => $args['placeholder'],
522
-			'show_option_all'  => $args['show_option_all'],
523
-			'show_option_none' => $args['show_option_none'],
524
-			'data'             => $args['data'],
515
+            'name'             => $args['name'],
516
+            'selected'         => $args['selected'],
517
+            'id'               => $args['id'],
518
+            'class'            => $args['class'],
519
+            'options'          => $options,
520
+            'multiple'         => $args['multiple'],
521
+            'placeholder'      => $args['placeholder'],
522
+            'show_option_all'  => $args['show_option_all'],
523
+            'show_option_none' => $args['show_option_none'],
524
+            'data'             => $args['data'],
525 525
         )
526 526
     );
527 527
 
@@ -822,21 +822,21 @@  discard block
 block discarded – undo
822 822
 
823 823
     $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format );
824 824
 
825
-	// Remove unavailable tags.
825
+    // Remove unavailable tags.
826 826
     $formatted_address = preg_replace( '/\{\{\w+\}\}/', '', $formatted_address );
827 827
 
828 828
     // Clean up white space.
829
-	$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
829
+    $formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
830 830
     $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
831 831
 
832 832
     // Break newlines apart and remove empty lines/trim commas and white space.
833
-	$formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
833
+    $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
834 834
 
835 835
     // Add html breaks.
836
-	$formatted_address = implode( $separator, $formatted_address );
836
+    $formatted_address = implode( $separator, $formatted_address );
837 837
 
838
-	// We're done!
839
-	return $formatted_address;
838
+    // We're done!
839
+    return $formatted_address;
840 840
 
841 841
 }
842 842
 
@@ -882,7 +882,7 @@  discard block
 block discarded – undo
882 882
 function getpaid_display_invoice_subscriptions( $invoice ) {
883 883
 
884 884
     // Subscriptions.
885
-	$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
885
+    $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
886 886
 
887 887
     if ( empty( $subscriptions ) || ! $invoice->is_recurring() ) {
888 888
         return;
@@ -1094,7 +1094,7 @@  discard block
 block discarded – undo
1094 1094
 }
1095 1095
 
1096 1096
 function wpinv_empty_cart_message() {
1097
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1097
+    return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1098 1098
 }
1099 1099
 
1100 1100
 /**
@@ -1291,10 +1291,10 @@  discard block
 block discarded – undo
1291 1291
 
1292 1292
     if ( 0 == count( $form->get_items() ) ) {
1293 1293
         echo aui()->alert(
1294
-			array(
1295
-				'type'    => 'warning',
1296
-				'content' => __( 'No published items found', 'invoicing' ),
1297
-			)
1294
+            array(
1295
+                'type'    => 'warning',
1296
+                'content' => __( 'No published items found', 'invoicing' ),
1297
+            )
1298 1298
         );
1299 1299
         return;
1300 1300
     }
@@ -1315,21 +1315,21 @@  discard block
 block discarded – undo
1315 1315
     $invoice = wpinv_get_invoice( $invoice_id );
1316 1316
 
1317 1317
     if ( empty( $invoice ) ) {
1318
-		echo aui()->alert(
1319
-			array(
1320
-				'type'    => 'warning',
1321
-				'content' => __( 'Invoice not found', 'invoicing' ),
1322
-			)
1318
+        echo aui()->alert(
1319
+            array(
1320
+                'type'    => 'warning',
1321
+                'content' => __( 'Invoice not found', 'invoicing' ),
1322
+            )
1323 1323
         );
1324 1324
         return;
1325 1325
     }
1326 1326
 
1327 1327
     if ( $invoice->is_paid() ) {
1328
-		echo aui()->alert(
1329
-			array(
1330
-				'type'    => 'warning',
1331
-				'content' => __( 'Invoice has already been paid', 'invoicing' ),
1332
-			)
1328
+        echo aui()->alert(
1329
+            array(
1330
+                'type'    => 'warning',
1331
+                'content' => __( 'Invoice has already been paid', 'invoicing' ),
1332
+            )
1333 1333
         );
1334 1334
         return;
1335 1335
     }
@@ -1391,7 +1391,7 @@  discard block
 block discarded – undo
1391 1391
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>";
1392 1392
     }
1393 1393
 
1394
-	if ( ! empty( $items ) ) {
1394
+    if ( ! empty( $items ) ) {
1395 1395
         $items  = esc_attr( $items );
1396 1396
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>";
1397 1397
     }
@@ -1577,21 +1577,21 @@  discard block
 block discarded – undo
1577 1577
 
1578 1578
         return aui()->select(
1579 1579
             array(
1580
-				'options'          => $states,
1581
-				'name'             => esc_attr( $field_name ),
1582
-				'id'               => sanitize_html_class( $field_name ) . $uniqid,
1583
-				'value'            => sanitize_text_field( $state ),
1584
-				'placeholder'      => $placeholder,
1585
-				'required'         => $required,
1586
-				'label'            => wp_kses_post( $label ),
1587
-				'label_type'       => 'vertical',
1588
-				'help_text'        => $help_text,
1589
-				'class'            => 'getpaid-address-field wpinv_state',
1590
-				'wrap_class'       => "$wrapper_class getpaid-address-field-wrapper__state",
1591
-				'label_class'      => 'getpaid-address-field-label getpaid-address-field-label__state',
1592
-				'extra_attributes' => array(
1593
-					'autocomplete' => 'address-level1',
1594
-				),
1580
+                'options'          => $states,
1581
+                'name'             => esc_attr( $field_name ),
1582
+                'id'               => sanitize_html_class( $field_name ) . $uniqid,
1583
+                'value'            => sanitize_text_field( $state ),
1584
+                'placeholder'      => $placeholder,
1585
+                'required'         => $required,
1586
+                'label'            => wp_kses_post( $label ),
1587
+                'label_type'       => 'vertical',
1588
+                'help_text'        => $help_text,
1589
+                'class'            => 'getpaid-address-field wpinv_state',
1590
+                'wrap_class'       => "$wrapper_class getpaid-address-field-wrapper__state",
1591
+                'label_class'      => 'getpaid-address-field-label getpaid-address-field-label__state',
1592
+                'extra_attributes' => array(
1593
+                    'autocomplete' => 'address-level1',
1594
+                ),
1595 1595
             )
1596 1596
         );
1597 1597
 
Please login to merge, or discard this patch.
Spacing   +456 added lines, -456 removed lines patch added patch discarded remove patch
@@ -4,99 +4,99 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Displays an invoice.
11 11
  *
12 12
  * @param WPInv_Invoice $invoice.
13 13
  */
14
-function getpaid_invoice( $invoice ) {
15
-    if ( ! empty( $invoice ) ) {
16
-        wpinv_get_template( 'invoice/invoice.php', compact( 'invoice' ) );
14
+function getpaid_invoice($invoice) {
15
+    if (!empty($invoice)) {
16
+        wpinv_get_template('invoice/invoice.php', compact('invoice'));
17 17
     }
18 18
 }
19
-add_action( 'getpaid_invoice', 'getpaid_invoice', 10 );
19
+add_action('getpaid_invoice', 'getpaid_invoice', 10);
20 20
 
21 21
 /**
22 22
  * Displays the invoice footer.
23 23
  */
24
-function getpaid_invoice_footer( $invoice ) {
25
-    if ( ! empty( $invoice ) ) {
26
-        wpinv_get_template( 'invoice/footer.php', compact( 'invoice' ) );
24
+function getpaid_invoice_footer($invoice) {
25
+    if (!empty($invoice)) {
26
+        wpinv_get_template('invoice/footer.php', compact('invoice'));
27 27
     }
28 28
 }
29
-add_action( 'getpaid_invoice_footer', 'getpaid_invoice_footer', 10 );
29
+add_action('getpaid_invoice_footer', 'getpaid_invoice_footer', 10);
30 30
 
31 31
 /**
32 32
  * Displays the invoice top bar.
33 33
  */
34
-function getpaid_invoice_header( $invoice ) {
35
-    if ( ! empty( $invoice ) ) {
36
-        wpinv_get_template( 'invoice/header.php', compact( 'invoice' ) );
34
+function getpaid_invoice_header($invoice) {
35
+    if (!empty($invoice)) {
36
+        wpinv_get_template('invoice/header.php', compact('invoice'));
37 37
     }
38 38
 }
39
-add_action( 'getpaid_invoice_header', 'getpaid_invoice_header', 10 );
39
+add_action('getpaid_invoice_header', 'getpaid_invoice_header', 10);
40 40
 
41 41
 /**
42 42
  * Displays actions on the left side of the header.
43 43
  */
44
-function getpaid_invoice_header_left_actions( $invoice ) {
45
-    if ( ! empty( $invoice ) ) {
46
-        wpinv_get_template( 'invoice/header-left-actions.php', compact( 'invoice' ) );
44
+function getpaid_invoice_header_left_actions($invoice) {
45
+    if (!empty($invoice)) {
46
+        wpinv_get_template('invoice/header-left-actions.php', compact('invoice'));
47 47
     }
48 48
 }
49
-add_action( 'getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10 );
49
+add_action('getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10);
50 50
 
51 51
 /**
52 52
  * Displays actions on the right side of the invoice top bar.
53 53
  */
54
-function getpaid_invoice_header_right_actions( $invoice ) {
55
-    if ( ! empty( $invoice ) ) {
56
-        wpinv_get_template( 'invoice/header-right-actions.php', compact( 'invoice' ) );
54
+function getpaid_invoice_header_right_actions($invoice) {
55
+    if (!empty($invoice)) {
56
+        wpinv_get_template('invoice/header-right-actions.php', compact('invoice'));
57 57
     }
58 58
 }
59
-add_action( 'getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10 );
59
+add_action('getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10);
60 60
 
61 61
 /**
62 62
  * Displays the invoice title, logo etc.
63 63
  */
64
-function getpaid_invoice_details_top( $invoice ) {
65
-    if ( ! empty( $invoice ) ) {
66
-        wpinv_get_template( 'invoice/details-top.php', compact( 'invoice' ) );
64
+function getpaid_invoice_details_top($invoice) {
65
+    if (!empty($invoice)) {
66
+        wpinv_get_template('invoice/details-top.php', compact('invoice'));
67 67
     }
68 68
 }
69
-add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_top', 10 );
69
+add_action('getpaid_invoice_details', 'getpaid_invoice_details_top', 10);
70 70
 
71 71
 /**
72 72
  * Displays the company logo.
73 73
  */
74
-function getpaid_invoice_logo( $invoice ) {
75
-    if ( ! empty( $invoice ) ) {
76
-        wpinv_get_template( 'invoice/invoice-logo.php', compact( 'invoice' ) );
74
+function getpaid_invoice_logo($invoice) {
75
+    if (!empty($invoice)) {
76
+        wpinv_get_template('invoice/invoice-logo.php', compact('invoice'));
77 77
     }
78 78
 }
79
-add_action( 'getpaid_invoice_details_top_left', 'getpaid_invoice_logo' );
79
+add_action('getpaid_invoice_details_top_left', 'getpaid_invoice_logo');
80 80
 
81 81
 /**
82 82
  * Displays the type of invoice.
83 83
  */
84
-function getpaid_invoice_type( $invoice ) {
85
-    if ( ! empty( $invoice ) ) {
86
-        wpinv_get_template( 'invoice/invoice-type.php', compact( 'invoice' ) );
84
+function getpaid_invoice_type($invoice) {
85
+    if (!empty($invoice)) {
86
+        wpinv_get_template('invoice/invoice-type.php', compact('invoice'));
87 87
     }
88 88
 }
89
-add_action( 'getpaid_invoice_details_top_right', 'getpaid_invoice_type' );
89
+add_action('getpaid_invoice_details_top_right', 'getpaid_invoice_type');
90 90
 
91 91
 /**
92 92
  * Displays the invoice details.
93 93
  */
94
-function getpaid_invoice_details_main( $invoice ) {
95
-    if ( ! empty( $invoice ) ) {
96
-        wpinv_get_template( 'invoice/details.php', compact( 'invoice' ) );
94
+function getpaid_invoice_details_main($invoice) {
95
+    if (!empty($invoice)) {
96
+        wpinv_get_template('invoice/details.php', compact('invoice'));
97 97
     }
98 98
 }
99
-add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_main', 50 );
99
+add_action('getpaid_invoice_details', 'getpaid_invoice_details_main', 50);
100 100
 
101 101
 /**
102 102
  * Returns a path to the templates directory.
@@ -125,8 +125,8 @@  discard block
 block discarded – undo
125 125
  * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'.
126 126
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
127 127
  */
128
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
129
-    getpaid_template()->display_template( $template_name, $args, $template_path, $default_path );
128
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
129
+    getpaid_template()->display_template($template_name, $args, $template_path, $default_path);
130 130
 }
131 131
 
132 132
 /**
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
  * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'.
140 140
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
141 141
  */
142
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
143
-	return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path );
142
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
143
+	return getpaid_template()->get_template($template_name, $args, $template_path, $default_path);
144 144
 }
145 145
 
146 146
 /**
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
  * @return string
150 150
  */
151 151
 function wpinv_template_path() {
152
-    return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() );
152
+    return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name());
153 153
 }
154 154
 
155 155
 /**
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
  * @return string
159 159
  */
160 160
 function wpinv_get_theme_template_dir_name() {
161
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
161
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing'));
162 162
 }
163 163
 
164 164
 /**
@@ -170,58 +170,58 @@  discard block
 block discarded – undo
170 170
  * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'.
171 171
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
172 172
  */
173
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
174
-    return getpaid_template()->locate_template( $template_name, $template_path, $default_path );
173
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
174
+    return getpaid_template()->locate_template($template_name, $template_path, $default_path);
175 175
 }
176 176
 
177
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
178
-	do_action( 'get_template_part_' . $slug, $slug, $name );
177
+function wpinv_get_template_part($slug, $name = null, $load = true) {
178
+	do_action('get_template_part_' . $slug, $slug, $name);
179 179
 
180 180
 	// Setup possible parts
181 181
 	$templates = array();
182
-	if ( isset( $name ) ) {
182
+	if (isset($name)) {
183 183
 		$templates[] = $slug . '-' . $name . '.php';
184 184
     }
185 185
 	$templates[] = $slug . '.php';
186 186
 
187 187
 	// Allow template parts to be filtered
188
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
188
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
189 189
 
190 190
 	// Return the part that is found
191
-	return wpinv_locate_tmpl( $templates, $load, false );
191
+	return wpinv_locate_tmpl($templates, $load, false);
192 192
 }
193 193
 
194
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
194
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
195 195
 	// No file found yet
196 196
 	$located = false;
197 197
 
198 198
 	// Try to find a template file
199
-	foreach ( (array)$template_names as $template_name ) {
199
+	foreach ((array) $template_names as $template_name) {
200 200
 
201 201
 		// Continue if template is empty
202
-		if ( empty( $template_name ) ) {
202
+		if (empty($template_name)) {
203 203
 			continue;
204 204
         }
205 205
 
206 206
 		// Trim off any slashes from the template name
207
-		$template_name = ltrim( $template_name, '/' );
207
+		$template_name = ltrim($template_name, '/');
208 208
 
209 209
 		// try locating this template file by looping through the template paths
210
-		foreach ( wpinv_get_theme_template_paths() as $template_path ) {
210
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
211 211
 
212
-			if ( file_exists( $template_path . $template_name ) ) {
212
+			if (file_exists($template_path . $template_name)) {
213 213
 				$located = $template_path . $template_name;
214 214
 				break;
215 215
 			}
216 216
 		}
217 217
 
218
-		if ( ! empty( $located ) ) {
218
+		if (!empty($located)) {
219 219
 			break;
220 220
 		}
221 221
 	}
222 222
 
223
-	if ( ( true == $load ) && ! empty( $located ) ) {
224
-		load_template( $located, $require_once );
223
+	if ((true == $load) && !empty($located)) {
224
+		load_template($located, $require_once);
225 225
     }
226 226
 
227 227
 	return $located;
@@ -231,81 +231,81 @@  discard block
 block discarded – undo
231 231
 	$template_dir = wpinv_get_theme_template_dir_name();
232 232
 
233 233
 	$file_paths = array(
234
-		1   => trailingslashit( get_stylesheet_directory() ) . $template_dir,
235
-		10  => trailingslashit( get_template_directory() ) . $template_dir,
234
+		1   => trailingslashit(get_stylesheet_directory()) . $template_dir,
235
+		10  => trailingslashit(get_template_directory()) . $template_dir,
236 236
 		100 => wpinv_get_templates_dir(),
237 237
 	);
238 238
 
239
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
239
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
240 240
 
241 241
 	// sort the file paths based on priority
242
-	ksort( $file_paths, SORT_NUMERIC );
242
+	ksort($file_paths, SORT_NUMERIC);
243 243
 
244
-	return array_map( 'trailingslashit', $file_paths );
244
+	return array_map('trailingslashit', $file_paths);
245 245
 }
246 246
 
247 247
 function wpinv_checkout_meta_tags() {
248 248
 
249 249
 	$pages   = array();
250
-	$pages[] = wpinv_get_option( 'success_page' );
251
-	$pages[] = wpinv_get_option( 'failure_page' );
252
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
253
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
250
+	$pages[] = wpinv_get_option('success_page');
251
+	$pages[] = wpinv_get_option('failure_page');
252
+	$pages[] = wpinv_get_option('invoice_history_page');
253
+	$pages[] = wpinv_get_option('invoice_subscription_page');
254 254
 
255
-	if ( ! wpinv_is_checkout() && ! is_page( $pages ) ) {
255
+	if (!wpinv_is_checkout() && !is_page($pages)) {
256 256
 		return;
257 257
 	}
258 258
 
259 259
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
260 260
 }
261
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
261
+add_action('wp_head', 'wpinv_checkout_meta_tags');
262 262
 
263
-function wpinv_add_body_classes( $class ) {
264
-	$classes = (array)$class;
263
+function wpinv_add_body_classes($class) {
264
+	$classes = (array) $class;
265 265
 
266
-	if ( wpinv_is_checkout() ) {
266
+	if (wpinv_is_checkout()) {
267 267
 		$classes[] = 'wpinv-checkout';
268 268
 		$classes[] = 'wpinv-page';
269 269
 	}
270 270
 
271
-	if ( wpinv_is_success_page() ) {
271
+	if (wpinv_is_success_page()) {
272 272
 		$classes[] = 'wpinv-success';
273 273
 		$classes[] = 'wpinv-page';
274 274
 	}
275 275
 
276
-	if ( wpinv_is_failed_transaction_page() ) {
276
+	if (wpinv_is_failed_transaction_page()) {
277 277
 		$classes[] = 'wpinv-failed-transaction';
278 278
 		$classes[] = 'wpinv-page';
279 279
 	}
280 280
 
281
-	if ( wpinv_is_invoice_history_page() ) {
281
+	if (wpinv_is_invoice_history_page()) {
282 282
 		$classes[] = 'wpinv-history';
283 283
 		$classes[] = 'wpinv-page';
284 284
 	}
285 285
 
286
-	if ( wpinv_is_subscriptions_history_page() ) {
286
+	if (wpinv_is_subscriptions_history_page()) {
287 287
 		$classes[] = 'wpinv-subscription';
288 288
 		$classes[] = 'wpinv-page';
289 289
 	}
290 290
 
291
-	if ( wpinv_is_test_mode() ) {
291
+	if (wpinv_is_test_mode()) {
292 292
 		$classes[] = 'wpinv-test-mode';
293 293
 		$classes[] = 'wpinv-page';
294 294
 	}
295 295
 
296
-	return array_unique( $classes );
296
+	return array_unique($classes);
297 297
 }
298
-add_filter( 'body_class', 'wpinv_add_body_classes' );
298
+add_filter('body_class', 'wpinv_add_body_classes');
299 299
 
300
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
301
-    $current     = date( 'Y' );
302
-    $start_year  = $current - absint( $years_before );
303
-    $end_year    = $current + absint( $years_after );
304
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
300
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
301
+    $current     = date('Y');
302
+    $start_year  = $current - absint($years_before);
303
+    $end_year    = $current + absint($years_after);
304
+    $selected    = empty($selected) ? date('Y') : $selected;
305 305
     $options     = array();
306 306
 
307
-    while ( $start_year <= $end_year ) {
308
-        $options[ absint( $start_year ) ] = $start_year;
307
+    while ($start_year <= $end_year) {
308
+        $options[absint($start_year)] = $start_year;
309 309
         $start_year++;
310 310
     }
311 311
 
@@ -322,25 +322,25 @@  discard block
 block discarded – undo
322 322
     return $output;
323 323
 }
324 324
 
325
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
325
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
326 326
 
327 327
     $options = array(
328
-        '1'  => __( 'January', 'invoicing' ),
329
-        '2'  => __( 'February', 'invoicing' ),
330
-        '3'  => __( 'March', 'invoicing' ),
331
-        '4'  => __( 'April', 'invoicing' ),
332
-        '5'  => __( 'May', 'invoicing' ),
333
-        '6'  => __( 'June', 'invoicing' ),
334
-        '7'  => __( 'July', 'invoicing' ),
335
-        '8'  => __( 'August', 'invoicing' ),
336
-        '9'  => __( 'September', 'invoicing' ),
337
-        '10' => __( 'October', 'invoicing' ),
338
-        '11' => __( 'November', 'invoicing' ),
339
-        '12' => __( 'December', 'invoicing' ),
328
+        '1'  => __('January', 'invoicing'),
329
+        '2'  => __('February', 'invoicing'),
330
+        '3'  => __('March', 'invoicing'),
331
+        '4'  => __('April', 'invoicing'),
332
+        '5'  => __('May', 'invoicing'),
333
+        '6'  => __('June', 'invoicing'),
334
+        '7'  => __('July', 'invoicing'),
335
+        '8'  => __('August', 'invoicing'),
336
+        '9'  => __('September', 'invoicing'),
337
+        '10' => __('October', 'invoicing'),
338
+        '11' => __('November', 'invoicing'),
339
+        '12' => __('December', 'invoicing'),
340 340
     );
341 341
 
342 342
     // If no month is selected, default to the current month
343
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
343
+    $selected = empty($selected) ? date('n') : $selected;
344 344
 
345 345
     $output = wpinv_html_select(
346 346
         array(
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
     return $output;
356 356
 }
357 357
 
358
-function wpinv_html_select( $args = array() ) {
358
+function wpinv_html_select($args = array()) {
359 359
     $defaults = array(
360 360
         'options'          => array(),
361 361
         'name'             => null,
@@ -364,8 +364,8 @@  discard block
 block discarded – undo
364 364
         'selected'         => 0,
365 365
         'placeholder'      => null,
366 366
         'multiple'         => false,
367
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
368
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
367
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
368
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
369 369
         'data'             => array(),
370 370
         'onchange'         => null,
371 371
         'required'         => false,
@@ -373,74 +373,74 @@  discard block
 block discarded – undo
373 373
         'readonly'         => false,
374 374
     );
375 375
 
376
-    $args = wp_parse_args( $args, $defaults );
376
+    $args = wp_parse_args($args, $defaults);
377 377
 
378 378
     $data_elements = '';
379
-    foreach ( $args['data'] as $key => $value ) {
380
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
379
+    foreach ($args['data'] as $key => $value) {
380
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
381 381
     }
382 382
 
383
-    if ( $args['multiple'] ) {
383
+    if ($args['multiple']) {
384 384
         $multiple = ' MULTIPLE';
385 385
     } else {
386 386
         $multiple = '';
387 387
     }
388 388
 
389
-    if ( $args['placeholder'] ) {
389
+    if ($args['placeholder']) {
390 390
         $placeholder = $args['placeholder'];
391 391
     } else {
392 392
         $placeholder = '';
393 393
     }
394 394
 
395 395
     $options = '';
396
-    if ( ! empty( $args['onchange'] ) ) {
397
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
396
+    if (!empty($args['onchange'])) {
397
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
398 398
     }
399 399
 
400
-    if ( ! empty( $args['required'] ) ) {
400
+    if (!empty($args['required'])) {
401 401
         $options .= ' required="required"';
402 402
     }
403 403
 
404
-    if ( ! empty( $args['disabled'] ) ) {
404
+    if (!empty($args['disabled'])) {
405 405
         $options .= ' disabled';
406 406
     }
407 407
 
408
-    if ( ! empty( $args['readonly'] ) ) {
408
+    if (!empty($args['readonly'])) {
409 409
         $options .= ' readonly';
410 410
     }
411 411
 
412
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
413
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
412
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
413
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
414 414
 
415
-    if ( $args['show_option_all'] ) {
416
-        if ( $args['multiple'] ) {
417
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
415
+    if ($args['show_option_all']) {
416
+        if ($args['multiple']) {
417
+            $selected = selected(true, in_array(0, $args['selected']), false);
418 418
         } else {
419
-            $selected = selected( $args['selected'], 0, false );
419
+            $selected = selected($args['selected'], 0, false);
420 420
         }
421
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
421
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
422 422
     }
423 423
 
424
-    if ( ! empty( $args['options'] ) ) {
424
+    if (!empty($args['options'])) {
425 425
 
426
-        if ( $args['show_option_none'] ) {
427
-            if ( $args['multiple'] ) {
428
-                $selected = selected( true, in_array( '', $args['selected'] ), false );
426
+        if ($args['show_option_none']) {
427
+            if ($args['multiple']) {
428
+                $selected = selected(true, in_array('', $args['selected']), false);
429 429
             } else {
430
-                $selected = selected( $args['selected'] === '', true, false );
430
+                $selected = selected($args['selected'] === '', true, false);
431 431
             }
432
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
432
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
433 433
         }
434 434
 
435
-        foreach ( $args['options'] as $key => $option ) {
435
+        foreach ($args['options'] as $key => $option) {
436 436
 
437
-            if ( $args['multiple'] && is_array( $args['selected'] ) ) {
438
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
437
+            if ($args['multiple'] && is_array($args['selected'])) {
438
+                $selected = selected(true, (bool) in_array($key, $args['selected']), false);
439 439
             } else {
440
-                $selected = selected( $args['selected'], $key, false );
440
+                $selected = selected($args['selected'], $key, false);
441 441
             }
442 442
 
443
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
443
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
444 444
         }
445 445
     }
446 446
 
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
     return $output;
450 450
 }
451 451
 
452
-function wpinv_item_dropdown( $args = array() ) {
452
+function wpinv_item_dropdown($args = array()) {
453 453
     $defaults = array(
454 454
         'name'             => 'wpi_item',
455 455
         'id'               => 'wpi_item',
@@ -457,14 +457,14 @@  discard block
 block discarded – undo
457 457
         'multiple'         => false,
458 458
         'selected'         => 0,
459 459
         'number'           => -1,
460
-        'placeholder'      => __( 'Choose a item', 'invoicing' ),
461
-        'data'             => array( 'search-type' => 'item' ),
460
+        'placeholder'      => __('Choose a item', 'invoicing'),
461
+        'data'             => array('search-type' => 'item'),
462 462
         'show_option_all'  => false,
463 463
         'show_option_none' => false,
464 464
         'show_recurring'   => false,
465 465
     );
466 466
 
467
-    $args = wp_parse_args( $args, $defaults );
467
+    $args = wp_parse_args($args, $defaults);
468 468
 
469 469
     $item_args = array(
470 470
         'post_type'      => 'wpi_item',
@@ -473,40 +473,40 @@  discard block
 block discarded – undo
473 473
         'posts_per_page' => $args['number'],
474 474
     );
475 475
 
476
-    $item_args  = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults );
476
+    $item_args  = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults);
477 477
 
478
-    $items      = get_posts( $item_args );
478
+    $items      = get_posts($item_args);
479 479
     $options    = array();
480
-    if ( $items ) {
481
-        foreach ( $items as $item ) {
482
-            $title = esc_html( $item->post_title );
480
+    if ($items) {
481
+        foreach ($items as $item) {
482
+            $title = esc_html($item->post_title);
483 483
 
484
-            if ( ! empty( $args['show_recurring'] ) ) {
485
-                $title .= wpinv_get_item_suffix( $item->ID, false );
484
+            if (!empty($args['show_recurring'])) {
485
+                $title .= wpinv_get_item_suffix($item->ID, false);
486 486
             }
487 487
 
488
-            $options[ absint( $item->ID ) ] = $title;
488
+            $options[absint($item->ID)] = $title;
489 489
         }
490 490
     }
491 491
 
492 492
     // This ensures that any selected items are included in the drop down
493
-    if ( is_array( $args['selected'] ) ) {
494
-        foreach ( $args['selected'] as $item ) {
495
-            if ( ! in_array( $item, $options ) ) {
496
-                $title = get_the_title( $item );
497
-                if ( ! empty( $args['show_recurring'] ) ) {
498
-                    $title .= wpinv_get_item_suffix( $item, false );
493
+    if (is_array($args['selected'])) {
494
+        foreach ($args['selected'] as $item) {
495
+            if (!in_array($item, $options)) {
496
+                $title = get_the_title($item);
497
+                if (!empty($args['show_recurring'])) {
498
+                    $title .= wpinv_get_item_suffix($item, false);
499 499
                 }
500
-                $options[ $item ] = $title;
500
+                $options[$item] = $title;
501 501
             }
502 502
         }
503
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
504
-        if ( ! in_array( $args['selected'], $options ) ) {
505
-            $title = get_the_title( $args['selected'] );
506
-            if ( ! empty( $args['show_recurring'] ) ) {
507
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
503
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
504
+        if (!in_array($args['selected'], $options)) {
505
+            $title = get_the_title($args['selected']);
506
+            if (!empty($args['show_recurring'])) {
507
+                $title .= wpinv_get_item_suffix($args['selected'], false);
508 508
             }
509
-            $options[ $args['selected'] ] = get_the_title( $args['selected'] );
509
+            $options[$args['selected']] = get_the_title($args['selected']);
510 510
         }
511 511
     }
512 512
 
@@ -543,16 +543,16 @@  discard block
 block discarded – undo
543 543
     );
544 544
 
545 545
     $options = array();
546
-    if ( $items ) {
547
-        foreach ( $items as $item ) {
548
-            $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false );
546
+    if ($items) {
547
+        foreach ($items as $item) {
548
+            $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false);
549 549
         }
550 550
     }
551 551
 
552 552
     return $options;
553 553
 }
554 554
 
555
-function wpinv_html_checkbox( $args = array() ) {
555
+function wpinv_html_checkbox($args = array()) {
556 556
     $defaults = array(
557 557
         'name'    => null,
558 558
         'current' => null,
@@ -563,17 +563,17 @@  discard block
 block discarded – undo
563 563
         ),
564 564
     );
565 565
 
566
-    $args = wp_parse_args( $args, $defaults );
566
+    $args = wp_parse_args($args, $defaults);
567 567
 
568
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
568
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
569 569
     $attr  = '';
570
-    if ( ! empty( $args['options']['disabled'] ) ) {
570
+    if (!empty($args['options']['disabled'])) {
571 571
         $attr .= ' disabled="disabled"';
572
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
572
+    } elseif (!empty($args['options']['readonly'])) {
573 573
         $attr .= ' readonly';
574 574
     }
575 575
 
576
-    $output = '<input type="checkbox"' . $attr . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . esc_attr( $class ) . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
576
+    $output = '<input type="checkbox"' . $attr . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . esc_attr($class) . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />';
577 577
 
578 578
     return $output;
579 579
 }
@@ -581,34 +581,34 @@  discard block
 block discarded – undo
581 581
 /**
582 582
  * Displays a hidden field.
583 583
  */
584
-function getpaid_hidden_field( $name, $value ) {
585
-    echo "<input type='hidden' name='" . esc_attr( $name ) . "' value=' " . esc_attr( $value ) . "' />";
584
+function getpaid_hidden_field($name, $value) {
585
+    echo "<input type='hidden' name='" . esc_attr($name) . "' value=' " . esc_attr($value) . "' />";
586 586
 }
587 587
 
588 588
 /**
589 589
  * Displays a submit field.
590 590
  */
591
-function getpaid_submit_field( $value, $name = 'submit', $class = 'btn-primary' ) {
592
-    echo "<input type='submit' name='" . esc_attr( $name ) . "' value='" . esc_attr( $value ) . "' class='btn " . esc_attr( $class ) . "' />";
591
+function getpaid_submit_field($value, $name = 'submit', $class = 'btn-primary') {
592
+    echo "<input type='submit' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' class='btn " . esc_attr($class) . "' />";
593 593
 }
594 594
 
595
-function wpinv_html_text( $args = array() ) {
595
+function wpinv_html_text($args = array()) {
596 596
     // Backwards compatibility
597
-    if ( func_num_args() > 1 ) {
597
+    if (func_num_args() > 1) {
598 598
         $args = func_get_args();
599 599
 
600 600
         $name  = $args[0];
601
-        $value = isset( $args[1] ) ? $args[1] : '';
602
-        $label = isset( $args[2] ) ? $args[2] : '';
603
-        $desc  = isset( $args[3] ) ? $args[3] : '';
601
+        $value = isset($args[1]) ? $args[1] : '';
602
+        $label = isset($args[2]) ? $args[2] : '';
603
+        $desc  = isset($args[3]) ? $args[3] : '';
604 604
     }
605 605
 
606 606
     $defaults = array(
607 607
         'id'           => '',
608
-        'name'         => isset( $name ) ? $name : 'text',
609
-        'value'        => isset( $value ) ? $value : null,
610
-        'label'        => isset( $label ) ? $label : null,
611
-        'desc'         => isset( $desc ) ? $desc : null,
608
+        'name'         => isset($name) ? $name : 'text',
609
+        'value'        => isset($value) ? $value : null,
610
+        'label'        => isset($label) ? $label : null,
611
+        'desc'         => isset($desc) ? $desc : null,
612 612
         'placeholder'  => '',
613 613
         'class'        => 'regular-text',
614 614
         'disabled'     => false,
@@ -618,41 +618,41 @@  discard block
 block discarded – undo
618 618
         'data'         => false,
619 619
     );
620 620
 
621
-    $args = wp_parse_args( $args, $defaults );
621
+    $args = wp_parse_args($args, $defaults);
622 622
 
623
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
623
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
624 624
     $options = '';
625
-    if ( $args['required'] ) {
625
+    if ($args['required']) {
626 626
         $options .= ' required="required"';
627 627
     }
628
-    if ( $args['readonly'] ) {
628
+    if ($args['readonly']) {
629 629
         $options .= ' readonly';
630 630
     }
631
-    if ( $args['readonly'] ) {
631
+    if ($args['readonly']) {
632 632
         $options .= ' readonly';
633 633
     }
634 634
 
635 635
     $data = '';
636
-    if ( ! empty( $args['data'] ) ) {
637
-        foreach ( $args['data'] as $key => $value ) {
638
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
636
+    if (!empty($args['data'])) {
637
+        foreach ($args['data'] as $key => $value) {
638
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
639 639
         }
640 640
     }
641 641
 
642
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
643
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
644
-    if ( ! empty( $args['desc'] ) ) {
645
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
642
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
643
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
644
+    if (!empty($args['desc'])) {
645
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
646 646
     }
647 647
 
648
-    $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>';
648
+    $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>';
649 649
 
650 650
     $output .= '</span>';
651 651
 
652 652
     return $output;
653 653
 }
654 654
 
655
-function wpinv_html_textarea( $args = array() ) {
655
+function wpinv_html_textarea($args = array()) {
656 656
     $defaults = array(
657 657
         'name'        => 'textarea',
658 658
         'value'       => null,
@@ -663,31 +663,31 @@  discard block
 block discarded – undo
663 663
         'placeholder' => '',
664 664
     );
665 665
 
666
-    $args = wp_parse_args( $args, $defaults );
666
+    $args = wp_parse_args($args, $defaults);
667 667
 
668
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
668
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
669 669
     $disabled = '';
670
-    if ( $args['disabled'] ) {
670
+    if ($args['disabled']) {
671 671
         $disabled = ' disabled="disabled"';
672 672
     }
673 673
 
674
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
675
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
676
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
674
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
675
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
676
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
677 677
 
678
-    if ( ! empty( $args['desc'] ) ) {
679
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
678
+    if (!empty($args['desc'])) {
679
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
680 680
     }
681 681
     $output .= '</span>';
682 682
 
683 683
     return $output;
684 684
 }
685 685
 
686
-function wpinv_html_ajax_user_search( $args = array() ) {
686
+function wpinv_html_ajax_user_search($args = array()) {
687 687
     $defaults = array(
688 688
         'name'         => 'user_id',
689 689
         'value'        => null,
690
-        'placeholder'  => __( 'Enter username', 'invoicing' ),
690
+        'placeholder'  => __('Enter username', 'invoicing'),
691 691
         'label'        => null,
692 692
         'desc'         => null,
693 693
         'class'        => '',
@@ -696,13 +696,13 @@  discard block
 block discarded – undo
696 696
         'data'         => false,
697 697
     );
698 698
 
699
-    $args = wp_parse_args( $args, $defaults );
699
+    $args = wp_parse_args($args, $defaults);
700 700
 
701 701
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
702 702
 
703 703
     $output  = '<span class="wpinv_user_search_wrap">';
704
-        $output .= wpinv_html_text( $args );
705
-        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>';
704
+        $output .= wpinv_html_text($args);
705
+        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>';
706 706
     $output .= '</span>';
707 707
 
708 708
     return $output;
@@ -713,44 +713,44 @@  discard block
 block discarded – undo
713 713
  *
714 714
  * @param string $template the template that is currently being used.
715 715
  */
716
-function wpinv_template( $template ) {
716
+function wpinv_template($template) {
717 717
     global $post;
718 718
 
719
-    if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) {
719
+    if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) {
720 720
 
721 721
         // If the user can view this invoice, display it.
722
-        if ( wpinv_user_can_view_invoice( $post->ID ) ) {
722
+        if (wpinv_user_can_view_invoice($post->ID)) {
723 723
 
724
-            return wpinv_get_template_part( 'wpinv-invoice-print', false, false );
724
+            return wpinv_get_template_part('wpinv-invoice-print', false, false);
725 725
 
726 726
         // Else display an error message.
727 727
         } else {
728 728
 
729
-            return wpinv_get_template_part( 'wpinv-invalid-access', false, false );
729
+            return wpinv_get_template_part('wpinv-invalid-access', false, false);
730 730
 
731 731
         }
732 732
 }
733 733
 
734 734
     return $template;
735 735
 }
736
-add_filter( 'template_include', 'wpinv_template', 10, 1 );
736
+add_filter('template_include', 'wpinv_template', 10, 1);
737 737
 
738 738
 function wpinv_get_business_address() {
739 739
     $business_address   = wpinv_store_address();
740
-    $business_address   = ! empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
740
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
741 741
 
742 742
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
743 743
 
744
-    return apply_filters( 'wpinv_get_business_address', $business_address );
744
+    return apply_filters('wpinv_get_business_address', $business_address);
745 745
 }
746 746
 
747 747
 /**
748 748
  * Displays the company address.
749 749
  */
750 750
 function wpinv_display_from_address() {
751
-    wpinv_get_template( 'invoice/company-address.php' );
751
+    wpinv_get_template('invoice/company-address.php');
752 752
 }
753
-add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 );
753
+add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10);
754 754
 
755 755
 /**
756 756
  * Generates a watermark text for an invoice.
@@ -758,9 +758,9 @@  discard block
 block discarded – undo
758 758
  * @param WPInv_Invoice $invoice
759 759
  * @return string
760 760
  */
761
-function wpinv_watermark( $invoice ) {
762
-    $watermark = wpinv_get_watermark( $invoice );
763
-    return apply_filters( 'wpinv_get_watermark', $watermark, $invoice );
761
+function wpinv_watermark($invoice) {
762
+    $watermark = wpinv_get_watermark($invoice);
763
+    return apply_filters('wpinv_get_watermark', $watermark, $invoice);
764 764
 }
765 765
 
766 766
 /**
@@ -769,37 +769,37 @@  discard block
 block discarded – undo
769 769
  * @param WPInv_Invoice $invoice
770 770
  * @return string
771 771
  */
772
-function wpinv_get_watermark( $invoice ) {
772
+function wpinv_get_watermark($invoice) {
773 773
     return $invoice->get_status_nicename();
774 774
 }
775 775
 
776 776
 /**
777 777
  * @deprecated
778 778
  */
779
-function wpinv_display_invoice_details( $invoice ) {
780
-    return getpaid_invoice_meta( $invoice );
779
+function wpinv_display_invoice_details($invoice) {
780
+    return getpaid_invoice_meta($invoice);
781 781
 }
782 782
 
783 783
 /**
784 784
  * Displays invoice meta.
785 785
  */
786
-function getpaid_invoice_meta( $invoice ) {
786
+function getpaid_invoice_meta($invoice) {
787 787
 
788
-    $invoice = new WPInv_Invoice( $invoice );
788
+    $invoice = new WPInv_Invoice($invoice);
789 789
 
790 790
     // Ensure that we have an invoice.
791
-    if ( 0 == $invoice->get_id() ) {
791
+    if (0 == $invoice->get_id()) {
792 792
         return;
793 793
     }
794 794
 
795 795
     // Get the invoice meta.
796
-    $meta = getpaid_get_invoice_meta( $invoice );
796
+    $meta = getpaid_get_invoice_meta($invoice);
797 797
 
798 798
     // Display the meta.
799
-    wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) );
799
+    wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta'));
800 800
 
801 801
 }
802
-add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 );
802
+add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10);
803 803
 
804 804
 /**
805 805
  * Retrieves the address markup to use on Invoices.
@@ -811,29 +811,29 @@  discard block
 block discarded – undo
811 811
  * @param  string $separator How to separate address lines.
812 812
  * @return string
813 813
  */
814
-function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) {
814
+function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') {
815 815
 
816 816
     // Retrieve the address markup...
817
-    $country = empty( $billing_details['country'] ) ? '' : $billing_details['country'];
818
-    $format = wpinv_get_full_address_format( $country );
817
+    $country = empty($billing_details['country']) ? '' : $billing_details['country'];
818
+    $format = wpinv_get_full_address_format($country);
819 819
 
820 820
     // ... and the replacements.
821
-    $replacements = wpinv_get_invoice_address_replacements( $billing_details );
821
+    $replacements = wpinv_get_invoice_address_replacements($billing_details);
822 822
 
823
-    $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format );
823
+    $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format);
824 824
 
825 825
 	// Remove unavailable tags.
826
-    $formatted_address = preg_replace( '/\{\{\w+\}\}/', '', $formatted_address );
826
+    $formatted_address = preg_replace('/\{\{\w+\}\}/', '', $formatted_address);
827 827
 
828 828
     // Clean up white space.
829
-	$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
830
-    $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
829
+	$formatted_address = preg_replace('/  +/', ' ', trim($formatted_address));
830
+    $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address);
831 831
 
832 832
     // Break newlines apart and remove empty lines/trim commas and white space.
833
-	$formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
833
+	$formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address)));
834 834
 
835 835
     // Add html breaks.
836
-	$formatted_address = implode( $separator, $formatted_address );
836
+	$formatted_address = implode($separator, $formatted_address);
837 837
 
838 838
 	// We're done!
839 839
 	return $formatted_address;
@@ -845,119 +845,119 @@  discard block
 block discarded – undo
845 845
  *
846 846
  * @param WPInv_Invoice $invoice
847 847
  */
848
-function wpinv_display_to_address( $invoice = 0 ) {
849
-    if ( ! empty( $invoice ) ) {
850
-        wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) );
848
+function wpinv_display_to_address($invoice = 0) {
849
+    if (!empty($invoice)) {
850
+        wpinv_get_template('invoice/billing-address.php', compact('invoice'));
851 851
     }
852 852
 }
853
-add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 );
853
+add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40);
854 854
 
855 855
 
856 856
 /**
857 857
  * Displays invoice line items.
858 858
  */
859
-function wpinv_display_line_items( $invoice_id = 0 ) {
859
+function wpinv_display_line_items($invoice_id = 0) {
860 860
 
861 861
     // Prepare the invoice.
862
-    $invoice = new WPInv_Invoice( $invoice_id );
862
+    $invoice = new WPInv_Invoice($invoice_id);
863 863
 
864 864
     // Abort if there is no invoice.
865
-    if ( 0 == $invoice->get_id() ) {
865
+    if (0 == $invoice->get_id()) {
866 866
         return;
867 867
     }
868 868
 
869 869
     // Line item columns.
870
-    $columns = getpaid_invoice_item_columns( $invoice );
871
-    $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice );
870
+    $columns = getpaid_invoice_item_columns($invoice);
871
+    $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice);
872 872
 
873
-    wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) );
873
+    wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns'));
874 874
 }
875
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 );
875
+add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10);
876 876
 
877 877
 /**
878 878
  * Displays invoice subscriptions.
879 879
  *
880 880
  * @param WPInv_Invoice $invoice
881 881
  */
882
-function getpaid_display_invoice_subscriptions( $invoice ) {
882
+function getpaid_display_invoice_subscriptions($invoice) {
883 883
 
884 884
     // Subscriptions.
885
-	$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
885
+	$subscriptions = getpaid_get_invoice_subscriptions($invoice);
886 886
 
887
-    if ( empty( $subscriptions ) || ! $invoice->is_recurring() ) {
887
+    if (empty($subscriptions) || !$invoice->is_recurring()) {
888 888
         return;
889 889
     }
890 890
 
891
-    $main_subscription = getpaid_get_invoice_subscription( $invoice );
891
+    $main_subscription = getpaid_get_invoice_subscription($invoice);
892 892
 
893 893
     // Display related subscriptions.
894
-    if ( is_array( $subscriptions ) ) {
895
-        printf( '<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__( 'Related Subscriptions', 'invoicing' ) );
896
-        getpaid_admin_subscription_related_subscriptions_metabox( $main_subscription, false );
894
+    if (is_array($subscriptions)) {
895
+        printf('<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__('Related Subscriptions', 'invoicing'));
896
+        getpaid_admin_subscription_related_subscriptions_metabox($main_subscription, false);
897 897
     }
898 898
 
899
-    if ( $main_subscription->get_total_payments() > 1 ) {
900
-        printf( '<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__( 'Related Invoices', 'invoicing' ) );
901
-        getpaid_admin_subscription_invoice_details_metabox( $main_subscription, false );
899
+    if ($main_subscription->get_total_payments() > 1) {
900
+        printf('<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__('Related Invoices', 'invoicing'));
901
+        getpaid_admin_subscription_invoice_details_metabox($main_subscription, false);
902 902
     }
903 903
 
904 904
 }
905
-add_action( 'getpaid_invoice_line_items', 'getpaid_display_invoice_subscriptions', 55 );
906
-add_action( 'wpinv_receipt_end', 'getpaid_display_invoice_subscriptions', 11 );
905
+add_action('getpaid_invoice_line_items', 'getpaid_display_invoice_subscriptions', 55);
906
+add_action('wpinv_receipt_end', 'getpaid_display_invoice_subscriptions', 11);
907 907
 
908 908
 /**
909 909
  * Displays invoice notices on invoices.
910 910
  */
911 911
 function wpinv_display_invoice_notice() {
912 912
 
913
-    $label  = wpinv_get_option( 'vat_invoice_notice_label' );
914
-    $notice = wpinv_get_option( 'vat_invoice_notice' );
913
+    $label  = wpinv_get_option('vat_invoice_notice_label');
914
+    $notice = wpinv_get_option('vat_invoice_notice');
915 915
 
916
-    if ( empty( $label ) && empty( $notice ) ) {
916
+    if (empty($label) && empty($notice)) {
917 917
         return;
918 918
     }
919 919
 
920 920
     echo '<div class="mt-4 mb-4 wpinv-vat-notice">';
921 921
 
922
-    if ( ! empty( $label ) ) {
923
-        $label = esc_html( $label );
922
+    if (!empty($label)) {
923
+        $label = esc_html($label);
924 924
         echo "<h5>$label</h5>";
925 925
     }
926 926
 
927
-    if ( ! empty( $notice ) ) {
928
-        echo '<small class="form-text text-muted">' . wp_kses_post( wpautop( wptexturize( $notice ) ) ) . '</small>';
927
+    if (!empty($notice)) {
928
+        echo '<small class="form-text text-muted">' . wp_kses_post(wpautop(wptexturize($notice))) . '</small>';
929 929
     }
930 930
 
931 931
     echo '</div>';
932 932
 }
933
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 );
933
+add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100);
934 934
 
935 935
 /**
936 936
  * @param WPInv_Invoice $invoice
937 937
  */
938
-function wpinv_display_invoice_notes( $invoice ) {
938
+function wpinv_display_invoice_notes($invoice) {
939 939
 
940 940
     // Retrieve the notes.
941
-    $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' );
941
+    $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer');
942 942
 
943 943
     // Abort if we have non.
944
-    if ( empty( $notes ) ) {
944
+    if (empty($notes)) {
945 945
         return;
946 946
     }
947 947
 
948 948
     // Echo the note.
949 949
     echo '<div class="getpaid-invoice-notes-wrapper position-relative my-4">';
950
-    echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . __( 'Notes', 'invoicing' ) . '</h2>';
950
+    echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . __('Notes', 'invoicing') . '</h2>';
951 951
     echo '<ul class="getpaid-invoice-notes text-break overflow-auto list-unstyled p-0 m-0">';
952 952
 
953
-    foreach ( $notes as $note ) {
954
-        wpinv_get_invoice_note_line_item( $note );
953
+    foreach ($notes as $note) {
954
+        wpinv_get_invoice_note_line_item($note);
955 955
     }
956 956
 
957 957
     echo '</ul>';
958 958
     echo '</div>';
959 959
 }
960
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 );
960
+add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60);
961 961
 
962 962
 /**
963 963
  * Loads scripts on our invoice templates.
@@ -965,32 +965,32 @@  discard block
 block discarded – undo
965 965
 function wpinv_display_style() {
966 966
 
967 967
     // Make sure that all scripts have been loaded.
968
-    if ( ! did_action( 'wp_enqueue_scripts' ) ) {
969
-        do_action( 'wp_enqueue_scripts' );
968
+    if (!did_action('wp_enqueue_scripts')) {
969
+        do_action('wp_enqueue_scripts');
970 970
     }
971 971
 
972 972
     // Register the invoices style.
973
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) );
973
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css'));
974 974
 
975 975
     // Load required styles
976
-    wp_print_styles( 'wpinv-single-style' );
977
-    wp_print_styles( 'ayecode-ui' );
976
+    wp_print_styles('wpinv-single-style');
977
+    wp_print_styles('ayecode-ui');
978 978
 
979 979
     // Maybe load custom css.
980
-    $custom_css = wpinv_get_option( 'template_custom_css' );
980
+    $custom_css = wpinv_get_option('template_custom_css');
981 981
 
982
-    if ( isset( $custom_css ) && ! empty( $custom_css ) ) {
983
-        $custom_css     = wp_kses( $custom_css, array( '\'', '\"' ) );
984
-        $custom_css     = str_replace( '&gt;', '>', $custom_css );
982
+    if (isset($custom_css) && !empty($custom_css)) {
983
+        $custom_css     = wp_kses($custom_css, array('\'', '\"'));
984
+        $custom_css     = str_replace('&gt;', '>', $custom_css);
985 985
         echo '<style type="text/css">';
986
-        echo wp_kses_post( $custom_css );
986
+        echo wp_kses_post($custom_css);
987 987
         echo '</style>';
988 988
     }
989 989
 
990 990
     wp_site_icon();
991 991
 }
992
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
993
-add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' );
992
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
993
+add_action('wpinv_invalid_invoice_head', 'wpinv_display_style');
994 994
 
995 995
 
996 996
 /**
@@ -1002,41 +1002,41 @@  discard block
 block discarded – undo
1002 1002
     // Retrieve the current invoice.
1003 1003
     $invoice_id = getpaid_get_current_invoice_id();
1004 1004
 
1005
-    if ( empty( $invoice_id ) ) {
1005
+    if (empty($invoice_id)) {
1006 1006
 
1007 1007
         return aui()->alert(
1008 1008
             array(
1009 1009
                 'type'    => 'warning',
1010
-                'content' => __( 'Invalid invoice', 'invoicing' ),
1010
+                'content' => __('Invalid invoice', 'invoicing'),
1011 1011
             )
1012 1012
         );
1013 1013
 
1014 1014
     }
1015 1015
 
1016 1016
     // Can the user view this invoice?
1017
-    if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) {
1017
+    if (!wpinv_user_can_view_invoice($invoice_id)) {
1018 1018
 
1019 1019
         return aui()->alert(
1020 1020
             array(
1021 1021
                 'type'    => 'warning',
1022
-                'content' => __( 'You are not allowed to view this invoice', 'invoicing' ),
1022
+                'content' => __('You are not allowed to view this invoice', 'invoicing'),
1023 1023
             )
1024 1024
         );
1025 1025
 
1026 1026
     }
1027 1027
 
1028 1028
     // Ensure that it is not yet paid for.
1029
-    $invoice = new WPInv_Invoice( $invoice_id );
1029
+    $invoice = new WPInv_Invoice($invoice_id);
1030 1030
 
1031 1031
     // Maybe mark it as viewed.
1032
-    getpaid_maybe_mark_invoice_as_viewed( $invoice );
1032
+    getpaid_maybe_mark_invoice_as_viewed($invoice);
1033 1033
 
1034
-    if ( $invoice->is_paid() ) {
1034
+    if ($invoice->is_paid()) {
1035 1035
 
1036 1036
         return aui()->alert(
1037 1037
             array(
1038 1038
                 'type'    => 'success',
1039
-                'content' => __( 'This invoice has already been paid.', 'invoicing' ),
1039
+                'content' => __('This invoice has already been paid.', 'invoicing'),
1040 1040
             )
1041 1041
         );
1042 1042
 
@@ -1046,15 +1046,15 @@  discard block
 block discarded – undo
1046 1046
     $wpi_checkout_id = $invoice_id;
1047 1047
 
1048 1048
     // Retrieve appropriate payment form.
1049
-    $payment_form = new GetPaid_Payment_Form( $invoice->get_meta( 'force_payment_form' ) );
1050
-    $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1049
+    $payment_form = new GetPaid_Payment_Form($invoice->get_meta('force_payment_form'));
1050
+    $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1051 1051
 
1052
-    if ( ! $payment_form->exists() ) {
1052
+    if (!$payment_form->exists()) {
1053 1053
 
1054 1054
         return aui()->alert(
1055 1055
             array(
1056 1056
                 'type'    => 'warning',
1057
-                'content' => __( 'Error loading the payment form', 'invoicing' ),
1057
+                'content' => __('Error loading the payment form', 'invoicing'),
1058 1058
             )
1059 1059
         );
1060 1060
 
@@ -1063,29 +1063,29 @@  discard block
 block discarded – undo
1063 1063
     // Set the invoice.
1064 1064
     $payment_form->invoice = $invoice;
1065 1065
 
1066
-    if ( ! $payment_form->is_default() ) {
1066
+    if (!$payment_form->is_default()) {
1067 1067
 
1068 1068
         $items    = array();
1069 1069
         $item_ids = array();
1070 1070
 
1071
-        foreach ( $invoice->get_items() as $item ) {
1072
-            if ( ! in_array( $item->get_id(), $item_ids ) ) {
1071
+        foreach ($invoice->get_items() as $item) {
1072
+            if (!in_array($item->get_id(), $item_ids)) {
1073 1073
                 $item_ids[] = $item->get_id();
1074 1074
                 $items[]    = $item;
1075 1075
             }
1076 1076
         }
1077 1077
 
1078
-        foreach ( $payment_form->get_items() as $item ) {
1079
-            if ( ! in_array( $item->get_id(), $item_ids ) ) {
1078
+        foreach ($payment_form->get_items() as $item) {
1079
+            if (!in_array($item->get_id(), $item_ids)) {
1080 1080
                 $item_ids[] = $item->get_id();
1081 1081
                 $items[]    = $item;
1082 1082
             }
1083 1083
         }
1084 1084
 
1085
-        $payment_form->set_items( $items );
1085
+        $payment_form->set_items($items);
1086 1086
 
1087 1087
     } else {
1088
-        $payment_form->set_items( $invoice->get_items() );
1088
+        $payment_form->set_items($invoice->get_items());
1089 1089
     }
1090 1090
 
1091 1091
     // Generate the html.
@@ -1094,7 +1094,7 @@  discard block
 block discarded – undo
1094 1094
 }
1095 1095
 
1096 1096
 function wpinv_empty_cart_message() {
1097
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1097
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1098 1098
 }
1099 1099
 
1100 1100
 /**
@@ -1111,76 +1111,76 @@  discard block
 block discarded – undo
1111 1111
         )
1112 1112
     );
1113 1113
 }
1114
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1114
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1115 1115
 
1116 1116
 /**
1117 1117
  * Filters the receipt page.
1118 1118
  */
1119
-function wpinv_filter_success_page_content( $content ) {
1119
+function wpinv_filter_success_page_content($content) {
1120 1120
 
1121 1121
     // Maybe abort early.
1122
-    if ( is_admin() || ! is_singular() || ! in_the_loop() || ! is_main_query() || is_preview() ) {
1122
+    if (is_admin() || !is_singular() || !in_the_loop() || !is_main_query() || is_preview()) {
1123 1123
         return $content;
1124 1124
     }
1125 1125
 
1126 1126
     // Ensure this is our page.
1127
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1127
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1128 1128
 
1129
-        $gateway = sanitize_text_field( $_GET['payment-confirm'] );
1130
-        return apply_filters( "wpinv_payment_confirm_$gateway", $content );
1129
+        $gateway = sanitize_text_field($_GET['payment-confirm']);
1130
+        return apply_filters("wpinv_payment_confirm_$gateway", $content);
1131 1131
 
1132 1132
     }
1133 1133
 
1134 1134
     return $content;
1135 1135
 }
1136
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1136
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1137 1137
 
1138
-function wpinv_invoice_link( $invoice_id ) {
1139
-    $invoice = wpinv_get_invoice( $invoice_id );
1138
+function wpinv_invoice_link($invoice_id) {
1139
+    $invoice = wpinv_get_invoice($invoice_id);
1140 1140
 
1141
-    if ( empty( $invoice ) ) {
1141
+    if (empty($invoice)) {
1142 1142
         return null;
1143 1143
     }
1144 1144
 
1145
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1145
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1146 1146
 
1147
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1147
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1148 1148
 }
1149 1149
 
1150
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
1151
-    if ( empty( $note ) ) {
1150
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
1151
+    if (empty($note)) {
1152 1152
         return null;
1153 1153
     }
1154 1154
 
1155
-    if ( is_int( $note ) ) {
1156
-        $note = get_comment( $note );
1155
+    if (is_int($note)) {
1156
+        $note = get_comment($note);
1157 1157
     }
1158 1158
 
1159
-    if ( ! ( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
1159
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
1160 1160
         return null;
1161 1161
     }
1162 1162
 
1163
-    $note_classes   = array( 'note' );
1164
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
1163
+    $note_classes   = array('note');
1164
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
1165 1165
     $note_classes[] = $note->comment_author === 'System' ? 'system-note' : '';
1166
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
1167
-    $note_classes   = ! empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
1166
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
1167
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
1168 1168
 
1169 1169
     ob_start();
1170 1170
     ?>
1171
-    <li rel="<?php echo absint( $note->comment_ID ); ?>" class="<?php echo esc_attr( $note_classes ); ?> mb-2">
1171
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mb-2">
1172 1172
         <div class="note_content">
1173 1173
 
1174
-            <?php echo wptexturize( wp_kses_post( $note->comment_content ) ); ?>
1174
+            <?php echo wptexturize(wp_kses_post($note->comment_content)); ?>
1175 1175
 
1176
-            <?php if ( ! is_admin() ) : ?>
1176
+            <?php if (!is_admin()) : ?>
1177 1177
                 <em class="small form-text text-muted mt-0">
1178 1178
                     <?php
1179 1179
                         printf(
1180
-                            __( '%1$s - %2$s at %3$s', 'invoicing' ),
1180
+                            __('%1$s - %2$s at %3$s', 'invoicing'),
1181 1181
                             $note->comment_author,
1182
-                            getpaid_format_date_value( $note->comment_date ),
1183
-                            date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) )
1182
+                            getpaid_format_date_value($note->comment_date),
1183
+                            date_i18n(get_option('time_format'), strtotime($note->comment_date))
1184 1184
                         );
1185 1185
                     ?>
1186 1186
                 </em>
@@ -1188,21 +1188,21 @@  discard block
 block discarded – undo
1188 1188
 
1189 1189
         </div>
1190 1190
 
1191
-        <?php if ( is_admin() ) : ?>
1191
+        <?php if (is_admin()) : ?>
1192 1192
 
1193 1193
             <p class="meta px-4 py-2">
1194
-                <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>">
1194
+                <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>">
1195 1195
                     <?php
1196 1196
                         printf(
1197
-                            __( '%1$s - %2$s at %3$s', 'invoicing' ),
1197
+                            __('%1$s - %2$s at %3$s', 'invoicing'),
1198 1198
                             $note->comment_author,
1199
-                            getpaid_format_date_value( $note->comment_date ),
1200
-                            date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) )
1199
+                            getpaid_format_date_value($note->comment_date),
1200
+                            date_i18n(get_option('time_format'), strtotime($note->comment_date))
1201 1201
                         );
1202 1202
                     ?>
1203 1203
                 </abbr>&nbsp;&nbsp;
1204
-                <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?>
1205
-                    <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
1204
+                <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?>
1205
+                    <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
1206 1206
                 <?php } ?>
1207 1207
             </p>
1208 1208
 
@@ -1211,10 +1211,10 @@  discard block
 block discarded – undo
1211 1211
     </li>
1212 1212
     <?php
1213 1213
     $note_content = ob_get_clean();
1214
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
1214
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
1215 1215
 
1216
-    if ( $echo ) {
1217
-        echo wp_kses_post( $note_content );
1216
+    if ($echo) {
1217
+        echo wp_kses_post($note_content);
1218 1218
     } else {
1219 1219
         return $note_content;
1220 1220
     }
@@ -1227,43 +1227,43 @@  discard block
 block discarded – undo
1227 1227
  * @return string
1228 1228
  */
1229 1229
 function wpinv_get_policy_text() {
1230
-    $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 );
1230
+    $privacy_page_id = get_option('wp_page_for_privacy_policy', 0);
1231 1231
 
1232
-    $text = wpinv_get_option( 'invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' ) );
1232
+    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]'));
1233 1233
 
1234
-    if ( ! $privacy_page_id ) {
1235
-        $privacy_page_id = wpinv_get_option( 'privacy_page', 0 );
1234
+    if (!$privacy_page_id) {
1235
+        $privacy_page_id = wpinv_get_option('privacy_page', 0);
1236 1236
     }
1237 1237
 
1238
-    $privacy_link    = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' );
1238
+    $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing');
1239 1239
 
1240 1240
     $find_replace = array(
1241 1241
         '[wpinv_privacy_policy]' => $privacy_link,
1242 1242
     );
1243 1243
 
1244
-    $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text );
1244
+    $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text);
1245 1245
 
1246
-    return wp_kses_post( wpautop( $privacy_text ) );
1246
+    return wp_kses_post(wpautop($privacy_text));
1247 1247
 }
1248 1248
 
1249 1249
 function wpinv_oxygen_fix_conflict() {
1250 1250
     global $ct_ignore_post_types;
1251 1251
 
1252
-    if ( ! is_array( $ct_ignore_post_types ) ) {
1252
+    if (!is_array($ct_ignore_post_types)) {
1253 1253
         $ct_ignore_post_types = array();
1254 1254
     }
1255 1255
 
1256
-    $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form' );
1256
+    $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form');
1257 1257
 
1258
-    foreach ( $post_types as $post_type ) {
1258
+    foreach ($post_types as $post_type) {
1259 1259
         $ct_ignore_post_types[] = $post_type;
1260 1260
 
1261 1261
         // Ignore post type
1262
-        add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 );
1262
+        add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999);
1263 1263
     }
1264 1264
 
1265
-    remove_filter( 'template_include', 'wpinv_template', 10, 1 );
1266
-    add_filter( 'template_include', 'wpinv_template', 999, 1 );
1265
+    remove_filter('template_include', 'wpinv_template', 10, 1);
1266
+    add_filter('template_include', 'wpinv_template', 999, 1);
1267 1267
 }
1268 1268
 
1269 1269
 /**
@@ -1271,10 +1271,10 @@  discard block
 block discarded – undo
1271 1271
  *
1272 1272
  * @param GetPaid_Payment_Form $form
1273 1273
  */
1274
-function getpaid_display_payment_form( $form ) {
1274
+function getpaid_display_payment_form($form) {
1275 1275
 
1276
-    if ( is_numeric( $form ) ) {
1277
-        $form = new GetPaid_Payment_Form( $form );
1276
+    if (is_numeric($form)) {
1277
+        $form = new GetPaid_Payment_Form($form);
1278 1278
     }
1279 1279
 
1280 1280
     $form->display();
@@ -1284,58 +1284,58 @@  discard block
 block discarded – undo
1284 1284
 /**
1285 1285
  * Helper function to display a item payment form on the frontend.
1286 1286
  */
1287
-function getpaid_display_item_payment_form( $items ) {
1287
+function getpaid_display_item_payment_form($items) {
1288 1288
 
1289
-    $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1290
-    $form->set_items( $items );
1289
+    $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1290
+    $form->set_items($items);
1291 1291
 
1292
-    if ( 0 == count( $form->get_items() ) ) {
1292
+    if (0 == count($form->get_items())) {
1293 1293
         echo aui()->alert(
1294 1294
 			array(
1295 1295
 				'type'    => 'warning',
1296
-				'content' => __( 'No published items found', 'invoicing' ),
1296
+				'content' => __('No published items found', 'invoicing'),
1297 1297
 			)
1298 1298
         );
1299 1299
         return;
1300 1300
     }
1301 1301
 
1302
-    $extra_items     = esc_attr( getpaid_convert_items_to_string( $items ) );
1303
-    $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items );
1302
+    $extra_items     = esc_attr(getpaid_convert_items_to_string($items));
1303
+    $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items);
1304 1304
     $extra_items     = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />";
1305 1305
     $extra_items    .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />";
1306 1306
 
1307
-    $form->display( $extra_items );
1307
+    $form->display($extra_items);
1308 1308
 }
1309 1309
 
1310 1310
 /**
1311 1311
  * Helper function to display an invoice payment form on the frontend.
1312 1312
  */
1313
-function getpaid_display_invoice_payment_form( $invoice_id ) {
1313
+function getpaid_display_invoice_payment_form($invoice_id) {
1314 1314
 
1315
-    $invoice = wpinv_get_invoice( $invoice_id );
1315
+    $invoice = wpinv_get_invoice($invoice_id);
1316 1316
 
1317
-    if ( empty( $invoice ) ) {
1317
+    if (empty($invoice)) {
1318 1318
 		echo aui()->alert(
1319 1319
 			array(
1320 1320
 				'type'    => 'warning',
1321
-				'content' => __( 'Invoice not found', 'invoicing' ),
1321
+				'content' => __('Invoice not found', 'invoicing'),
1322 1322
 			)
1323 1323
         );
1324 1324
         return;
1325 1325
     }
1326 1326
 
1327
-    if ( $invoice->is_paid() ) {
1327
+    if ($invoice->is_paid()) {
1328 1328
 		echo aui()->alert(
1329 1329
 			array(
1330 1330
 				'type'    => 'warning',
1331
-				'content' => __( 'Invoice has already been paid', 'invoicing' ),
1331
+				'content' => __('Invoice has already been paid', 'invoicing'),
1332 1332
 			)
1333 1333
         );
1334 1334
         return;
1335 1335
     }
1336 1336
 
1337
-    $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1338
-    $form->set_items( $invoice->get_items() );
1337
+    $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1338
+    $form->set_items($invoice->get_items());
1339 1339
 
1340 1340
     $form->display();
1341 1341
 }
@@ -1343,23 +1343,23 @@  discard block
 block discarded – undo
1343 1343
 /**
1344 1344
  * Helper function to convert item string to array.
1345 1345
  */
1346
-function getpaid_convert_items_to_array( $items ) {
1347
-    $items    = array_filter( array_map( 'trim', explode( ',', $items ) ) );
1346
+function getpaid_convert_items_to_array($items) {
1347
+    $items    = array_filter(array_map('trim', explode(',', $items)));
1348 1348
     $prepared = array();
1349 1349
 
1350
-    foreach ( $items as $item ) {
1351
-        $data = array_map( 'trim', explode( '|', $item ) );
1350
+    foreach ($items as $item) {
1351
+        $data = array_map('trim', explode('|', $item));
1352 1352
 
1353
-        if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) {
1353
+        if (empty($data[0]) || !is_numeric($data[0])) {
1354 1354
             continue;
1355 1355
         }
1356 1356
 
1357 1357
         $quantity = 1;
1358
-        if ( isset( $data[1] ) && is_numeric( $data[1] ) ) {
1358
+        if (isset($data[1]) && is_numeric($data[1])) {
1359 1359
             $quantity = (float) $data[1];
1360 1360
         }
1361 1361
 
1362
-        $prepared[ $data[0] ] = $quantity;
1362
+        $prepared[$data[0]] = $quantity;
1363 1363
 
1364 1364
     }
1365 1365
 
@@ -1369,13 +1369,13 @@  discard block
 block discarded – undo
1369 1369
 /**
1370 1370
  * Helper function to convert item array to string.
1371 1371
  */
1372
-function getpaid_convert_items_to_string( $items ) {
1372
+function getpaid_convert_items_to_string($items) {
1373 1373
     $prepared = array();
1374 1374
 
1375
-    foreach ( $items as $item => $quantity ) {
1375
+    foreach ($items as $item => $quantity) {
1376 1376
         $prepared[] = "$item|$quantity";
1377 1377
     }
1378
-    return implode( ',', $prepared );
1378
+    return implode(',', $prepared);
1379 1379
 }
1380 1380
 
1381 1381
 /**
@@ -1383,21 +1383,21 @@  discard block
 block discarded – undo
1383 1383
  *
1384 1384
  * Provide a label and one of $form, $items or $invoice.
1385 1385
  */
1386
-function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) {
1387
-    $label = sanitize_text_field( $label );
1386
+function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) {
1387
+    $label = sanitize_text_field($label);
1388 1388
 
1389
-    if ( ! empty( $form ) ) {
1390
-        $form  = esc_attr( $form );
1389
+    if (!empty($form)) {
1390
+        $form = esc_attr($form);
1391 1391
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>";
1392 1392
     }
1393 1393
 
1394
-	if ( ! empty( $items ) ) {
1395
-        $items  = esc_attr( $items );
1394
+	if (!empty($items)) {
1395
+        $items = esc_attr($items);
1396 1396
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>";
1397 1397
     }
1398 1398
 
1399
-    if ( ! empty( $invoice ) ) {
1400
-        $invoice  = esc_attr( $invoice );
1399
+    if (!empty($invoice)) {
1400
+        $invoice = esc_attr($invoice);
1401 1401
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-invoice='$invoice'>$label</button>";
1402 1402
     }
1403 1403
 
@@ -1408,18 +1408,18 @@  discard block
 block discarded – undo
1408 1408
  *
1409 1409
  * @param WPInv_Invoice $invoice
1410 1410
  */
1411
-function getpaid_the_invoice_description( $invoice ) {
1411
+function getpaid_the_invoice_description($invoice) {
1412 1412
     $description = $invoice->get_description();
1413 1413
 
1414
-    if ( empty( $description ) ) {
1414
+    if (empty($description)) {
1415 1415
         return;
1416 1416
     }
1417 1417
 
1418
-    $description = wp_kses_post( wpautop( $description ) );
1418
+    $description = wp_kses_post(wpautop($description));
1419 1419
     echo "<small class='getpaid-invoice-description text-dark p-2 form-text' style='margin-bottom: 20px; border-left: 2px solid #2196F3;'><em>$description</em></small>";
1420 1420
 }
1421
-add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 );
1422
-add_action( 'wpinv_email_billing_details', 'getpaid_the_invoice_description', 100 );
1421
+add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100);
1422
+add_action('wpinv_email_billing_details', 'getpaid_the_invoice_description', 100);
1423 1423
 
1424 1424
 /**
1425 1425
  * Render element on a form.
@@ -1427,60 +1427,60 @@  discard block
 block discarded – undo
1427 1427
  * @param array $element
1428 1428
  * @param GetPaid_Payment_Form $form
1429 1429
  */
1430
-function getpaid_payment_form_element( $element, $form ) {
1430
+function getpaid_payment_form_element($element, $form) {
1431 1431
 
1432 1432
     // Set up the args.
1433
-    $element_type    = trim( $element['type'] );
1433
+    $element_type    = trim($element['type']);
1434 1434
     $element['form'] = $form;
1435
-    extract( $element );
1435
+    extract($element);
1436 1436
 
1437 1437
     // Try to locate the appropriate template.
1438
-    $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" );
1438
+    $located = wpinv_locate_template("payment-forms/elements/$element_type.php");
1439 1439
 
1440 1440
     // Abort if this is not our element.
1441
-    if ( empty( $located ) || ! file_exists( $located ) ) {
1441
+    if (empty($located) || !file_exists($located)) {
1442 1442
         return;
1443 1443
     }
1444 1444
 
1445 1445
     // Generate the class and id of the element.
1446
-    $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) );
1447
-    $id            = isset( $id ) ? $id : uniqid( 'gp' );
1446
+    $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type));
1447
+    $id            = isset($id) ? $id : uniqid('gp');
1448 1448
 
1449 1449
     // Echo the opening wrapper.
1450 1450
     echo "<div class='getpaid-payment-form-element $wrapper_class'>";
1451 1451
 
1452 1452
     // Fires before displaying a given element type's content.
1453
-    do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form );
1453
+    do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form);
1454 1454
 
1455 1455
     // Include the template for the element.
1456 1456
     include $located;
1457 1457
 
1458 1458
     // Fires after displaying a given element type's content.
1459
-    do_action( "getpaid_payment_form_{$element_type}_element", $element, $form );
1459
+    do_action("getpaid_payment_form_{$element_type}_element", $element, $form);
1460 1460
 
1461 1461
     // Echo the closing wrapper.
1462 1462
     echo '</div>';
1463 1463
 }
1464
-add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 );
1464
+add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2);
1465 1465
 
1466 1466
 /**
1467 1467
  * Render an element's edit page.
1468 1468
  *
1469 1469
  * @param WP_Post $post
1470 1470
  */
1471
-function getpaid_payment_form_edit_element_template( $post ) {
1471
+function getpaid_payment_form_edit_element_template($post) {
1472 1472
 
1473 1473
     // Retrieve all elements.
1474
-    $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' );
1474
+    $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type');
1475 1475
 
1476
-    foreach ( $all_elements as $element ) {
1476
+    foreach ($all_elements as $element) {
1477 1477
 
1478 1478
         // Try to locate the appropriate template.
1479
-        $element = esc_attr( sanitize_key( $element ) );
1480
-        $located = wpinv_locate_template( "payment-forms-admin/edit/$element.php" );
1479
+        $element = esc_attr(sanitize_key($element));
1480
+        $located = wpinv_locate_template("payment-forms-admin/edit/$element.php");
1481 1481
 
1482 1482
         // Continue if this is not our element.
1483
-        if ( empty( $located ) || ! file_exists( $located ) ) {
1483
+        if (empty($located) || !file_exists($located)) {
1484 1484
             continue;
1485 1485
         }
1486 1486
 
@@ -1491,7 +1491,7 @@  discard block
 block discarded – undo
1491 1491
     }
1492 1492
 
1493 1493
 }
1494
-add_action( 'getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template' );
1494
+add_action('getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template');
1495 1495
 
1496 1496
 /**
1497 1497
  * Render an element's preview.
@@ -1500,16 +1500,16 @@  discard block
 block discarded – undo
1500 1500
 function getpaid_payment_form_render_element_preview_template() {
1501 1501
 
1502 1502
     // Retrieve all elements.
1503
-    $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' );
1503
+    $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type');
1504 1504
 
1505
-    foreach ( $all_elements as $element ) {
1505
+    foreach ($all_elements as $element) {
1506 1506
 
1507 1507
         // Try to locate the appropriate template.
1508
-        $element = sanitize_key( $element );
1509
-        $located = wpinv_locate_template( "payment-forms-admin/previews/$element.php" );
1508
+        $element = sanitize_key($element);
1509
+        $located = wpinv_locate_template("payment-forms-admin/previews/$element.php");
1510 1510
 
1511 1511
         // Continue if this is not our element.
1512
-        if ( empty( $located ) || ! file_exists( $located ) ) {
1512
+        if (empty($located) || !file_exists($located)) {
1513 1513
             continue;
1514 1514
         }
1515 1515
 
@@ -1520,7 +1520,7 @@  discard block
 block discarded – undo
1520 1520
     }
1521 1521
 
1522 1522
 }
1523
-add_action( 'wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template' );
1523
+add_action('wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template');
1524 1524
 
1525 1525
 /**
1526 1526
  * Shows a list of gateways that support recurring payments.
@@ -1528,17 +1528,17 @@  discard block
 block discarded – undo
1528 1528
 function wpinv_get_recurring_gateways_text() {
1529 1529
     $gateways = array();
1530 1530
 
1531
-    foreach ( wpinv_get_payment_gateways() as $key => $gateway ) {
1532
-        if ( wpinv_gateway_support_subscription( $key ) ) {
1533
-            $gateways[] = sanitize_text_field( $gateway['admin_label'] );
1531
+    foreach (wpinv_get_payment_gateways() as $key => $gateway) {
1532
+        if (wpinv_gateway_support_subscription($key)) {
1533
+            $gateways[] = sanitize_text_field($gateway['admin_label']);
1534 1534
         }
1535 1535
     }
1536 1536
 
1537
-    if ( empty( $gateways ) ) {
1538
-        return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) . '</span>';
1537
+    if (empty($gateways)) {
1538
+        return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . '</span>';
1539 1539
     }
1540 1540
 
1541
-    return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) . '</span>';
1541
+    return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . '</span>';
1542 1542
 
1543 1543
 }
1544 1544
 
@@ -1548,7 +1548,7 @@  discard block
 block discarded – undo
1548 1548
  * @return GetPaid_Template
1549 1549
  */
1550 1550
 function getpaid_template() {
1551
-    return getpaid()->get( 'template' );
1551
+    return getpaid()->get('template');
1552 1552
 }
1553 1553
 
1554 1554
 /**
@@ -1557,8 +1557,8 @@  discard block
 block discarded – undo
1557 1557
  * @param array args
1558 1558
  * @return string
1559 1559
  */
1560
-function getpaid_paginate_links( $args ) {
1561
-    return str_replace( 'page-link dots', 'page-link text-dark', aui()->pagination( $args ) );
1560
+function getpaid_paginate_links($args) {
1561
+    return str_replace('page-link dots', 'page-link text-dark', aui()->pagination($args));
1562 1562
 }
1563 1563
 
1564 1564
 /**
@@ -1568,22 +1568,22 @@  discard block
 block discarded – undo
1568 1568
  * @param string state
1569 1569
  * @return string
1570 1570
  */
1571
-function getpaid_get_states_select_markup( $country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state' ) {
1571
+function getpaid_get_states_select_markup($country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state') {
1572 1572
 
1573
-    $states = wpinv_get_country_states( $country );
1574
-    $uniqid = uniqid( '_' );
1573
+    $states = wpinv_get_country_states($country);
1574
+    $uniqid = uniqid('_');
1575 1575
 
1576
-    if ( ! empty( $states ) ) {
1576
+    if (!empty($states)) {
1577 1577
 
1578 1578
         return aui()->select(
1579 1579
             array(
1580 1580
 				'options'          => $states,
1581
-				'name'             => esc_attr( $field_name ),
1582
-				'id'               => sanitize_html_class( $field_name ) . $uniqid,
1583
-				'value'            => sanitize_text_field( $state ),
1581
+				'name'             => esc_attr($field_name),
1582
+				'id'               => sanitize_html_class($field_name) . $uniqid,
1583
+				'value'            => sanitize_text_field($state),
1584 1584
 				'placeholder'      => $placeholder,
1585 1585
 				'required'         => $required,
1586
-				'label'            => wp_kses_post( $label ),
1586
+				'label'            => wp_kses_post($label),
1587 1587
 				'label_type'       => 'vertical',
1588 1588
 				'help_text'        => $help_text,
1589 1589
 				'class'            => 'getpaid-address-field wpinv_state',
@@ -1599,14 +1599,14 @@  discard block
 block discarded – undo
1599 1599
 
1600 1600
     return aui()->input(
1601 1601
         array(
1602
-            'name'             => esc_attr( $field_name ),
1603
-            'id'               => sanitize_html_class( $field_name ) . $uniqid,
1602
+            'name'             => esc_attr($field_name),
1603
+            'id'               => sanitize_html_class($field_name) . $uniqid,
1604 1604
             'placeholder'      => $placeholder,
1605 1605
             'required'         => $required,
1606
-            'label'            => wp_kses_post( $label ),
1606
+            'label'            => wp_kses_post($label),
1607 1607
             'label_type'       => 'vertical',
1608 1608
             'help_text'        => $help_text,
1609
-            'value'            => sanitize_text_field( $state ),
1609
+            'value'            => sanitize_text_field($state),
1610 1610
             'class'            => 'getpaid-address-field wpinv_state',
1611 1611
             'wrap_class'       => "$wrapper_class getpaid-address-field-wrapper__state",
1612 1612
             'label_class'      => 'getpaid-address-field-label getpaid-address-field-label__state',
@@ -1624,16 +1624,16 @@  discard block
 block discarded – undo
1624 1624
  * @param array $element
1625 1625
  * @return string
1626 1626
  */
1627
-function getpaid_get_form_element_grid_class( $element ) {
1627
+function getpaid_get_form_element_grid_class($element) {
1628 1628
 
1629 1629
     $class = 'col-12';
1630
-    $width = empty( $element['grid_width'] ) ? 'full' : $element['grid_width'];
1630
+    $width = empty($element['grid_width']) ? 'full' : $element['grid_width'];
1631 1631
 
1632
-    if ( $width == 'half' ) {
1632
+    if ($width == 'half') {
1633 1633
         $class .= ' col-md-6';
1634 1634
     }
1635 1635
 
1636
-    if ( $width == 'third' ) {
1636
+    if ($width == 'third') {
1637 1637
         $class .= ' col-md-4';
1638 1638
     }
1639 1639
 
@@ -1648,15 +1648,15 @@  discard block
 block discarded – undo
1648 1648
  *
1649 1649
  * @return string
1650 1650
  */
1651
-function getpaid_embed_url( $payment_form = false, $items = false ) {
1651
+function getpaid_embed_url($payment_form = false, $items = false) {
1652 1652
 
1653 1653
     return add_query_arg(
1654 1654
         array(
1655 1655
             'getpaid_embed' => 1,
1656
-            'form'          => $payment_form ? absint( $payment_form ) : false,
1657
-            'item'          => $items ? urlencode( $items ) : false,
1656
+            'form'          => $payment_form ? absint($payment_form) : false,
1657
+            'item'          => $items ? urlencode($items) : false,
1658 1658
         ),
1659
-        home_url( 'index.php' )
1659
+        home_url('index.php')
1660 1660
     );
1661 1661
 
1662 1662
 }
@@ -1666,13 +1666,13 @@  discard block
 block discarded – undo
1666 1666
  *
1667 1667
  * @return string
1668 1668
  */
1669
-function getpaid_filter_embed_template( $template ) {
1669
+function getpaid_filter_embed_template($template) {
1670 1670
 
1671
-    if ( isset( $_GET['getpaid_embed'] ) ) {
1672
-        wpinv_get_template( 'payment-forms/embed.php' );
1671
+    if (isset($_GET['getpaid_embed'])) {
1672
+        wpinv_get_template('payment-forms/embed.php');
1673 1673
         exit;
1674 1674
     }
1675 1675
 
1676 1676
     return $template;
1677 1677
 }
1678
-add_filter( 'template_include', 'getpaid_filter_embed_template' );
1678
+add_filter('template_include', 'getpaid_filter_embed_template');
Please login to merge, or discard this patch.