Passed
Push — master ( 01e429...89614d )
by Brian
08:00 queued 03:45
created
includes/class-wpinv-subscriptions.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly.
3
-if (!defined( 'ABSPATH' ) ) exit;
3
+if (!defined( 'ABSPATH' ) ) {
4
+    exit;
5
+}
4 6
 
5 7
 function wpinv_subscription_init() {
6 8
     return WPInv_Subscriptions::instance();
Please login to merge, or discard this patch.
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly.
3
-if (!defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5 5
 function wpinv_subscription_init() {
6 6
     return WPInv_Subscriptions::instance();
7 7
 }
8
-add_action( 'plugins_loaded', 'wpinv_subscription_init', 100 );
8
+add_action('plugins_loaded', 'wpinv_subscription_init', 100);
9 9
 
10 10
 /**
11 11
  * WPInv_Subscriptions Class.
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
      * Main WPInv_Subscriptions Instance
21 21
      */
22 22
     public static function instance() {
23
-        if ( ! isset( self::$instance ) ) {
23
+        if (!isset(self::$instance)) {
24 24
             self::$instance = new WPInv_Subscriptions;
25 25
 
26 26
             self::$instance->init();
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
      *
35 35
      * @since 1.0.0
36 36
      */
37
-    private function __construct(){
37
+    private function __construct() {
38 38
 
39 39
     }
40 40
 
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
     private function setup_constants() {
64 64
 
65 65
         // Make sure CAL_GREGORIAN is defined.
66
-        if ( ! defined( 'CAL_GREGORIAN' ) ) {
67
-            define( 'CAL_GREGORIAN', 1 );
66
+        if (!defined('CAL_GREGORIAN')) {
67
+            define('CAL_GREGORIAN', 1);
68 68
         }
69 69
     }
70 70
 
@@ -76,15 +76,15 @@  discard block
 block discarded – undo
76 76
      */
77 77
     private function actions() {
78 78
 
79
-        add_action( 'admin_menu', array( $this, 'wpinv_subscriptions_list' ), 40 );
80
-        add_action( 'admin_notices', array( $this, 'notices' ) );
81
-        add_action( 'init', array( $this, 'wpinv_post_actions' ) );
82
-        add_action( 'init', array( $this, 'wpinv_get_actions' ) );
83
-        add_action( 'wpinv_cancel_subscription', array( $this, 'wpinv_process_cancellation' ) );
84
-        add_action( 'getpaid_checkout_before_gateway', array( $this, 'add_subscription' ), -999 );
85
-        add_action( 'wpinv_subscriptions_front_notices', array( $this, 'notices' ) );
86
-        add_action( 'getpaid_authenticated_admin_action_update_single_subscription', array( $this, 'admin_update_single_subscription' ) );
87
-        add_action( 'getpaid_authenticated_admin_action_subscription_manual_renew', array( $this, 'admin_renew_single_subscription' ) );
79
+        add_action('admin_menu', array($this, 'wpinv_subscriptions_list'), 40);
80
+        add_action('admin_notices', array($this, 'notices'));
81
+        add_action('init', array($this, 'wpinv_post_actions'));
82
+        add_action('init', array($this, 'wpinv_get_actions'));
83
+        add_action('wpinv_cancel_subscription', array($this, 'wpinv_process_cancellation'));
84
+        add_action('getpaid_checkout_before_gateway', array($this, 'add_subscription'), -999);
85
+        add_action('wpinv_subscriptions_front_notices', array($this, 'notices'));
86
+        add_action('getpaid_authenticated_admin_action_update_single_subscription', array($this, 'admin_update_single_subscription'));
87
+        add_action('getpaid_authenticated_admin_action_subscription_manual_renew', array($this, 'admin_renew_single_subscription'));
88 88
     }
89 89
 
90 90
     /**
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
     public function wpinv_subscriptions_list() {
107 107
         add_submenu_page(
108 108
             'wpinv',
109
-            __( 'Subscriptions', 'invoicing' ),
110
-            __( 'Subscriptions', 'invoicing' ),
109
+            __('Subscriptions', 'invoicing'),
110
+            __('Subscriptions', 'invoicing'),
111 111
             wpinv_get_capability(),
112 112
             'wpinv-subscriptions',
113 113
             'wpinv_subscriptions_page'
@@ -116,37 +116,37 @@  discard block
 block discarded – undo
116 116
 
117 117
     public function notices() {
118 118
 
119
-        if( empty( $_GET['wpinv-message'] ) ) {
119
+        if (empty($_GET['wpinv-message'])) {
120 120
             return;
121 121
         }
122 122
 
123 123
         $type    = 'updated';
124 124
         $message = '';
125 125
 
126
-        switch( strtolower( $_GET['wpinv-message'] ) ) {
126
+        switch (strtolower($_GET['wpinv-message'])) {
127 127
 
128 128
             case 'updated' :
129 129
 
130
-                $message = __( 'Subscription updated successfully.', 'invoicing' );
130
+                $message = __('Subscription updated successfully.', 'invoicing');
131 131
 
132 132
                 break;
133 133
 
134 134
             case 'deleted' :
135 135
 
136
-                $message = __( 'Subscription deleted successfully.', 'invoicing' );
136
+                $message = __('Subscription deleted successfully.', 'invoicing');
137 137
 
138 138
                 break;
139 139
 
140 140
             case 'cancelled' :
141 141
 
142
-                $message = __( 'Subscription cancelled successfully.', 'invoicing' );
142
+                $message = __('Subscription cancelled successfully.', 'invoicing');
143 143
 
144 144
                 break;
145 145
 
146 146
         }
147 147
 
148
-        if ( ! empty( $message ) ) {
149
-            echo '<div class="' . esc_attr( $type ) . '"><p>' . $message . '</p></div>';
148
+        if (!empty($message)) {
149
+            echo '<div class="' . esc_attr($type) . '"><p>' . $message . '</p></div>';
150 150
         }
151 151
 
152 152
     }
@@ -159,8 +159,8 @@  discard block
 block discarded – undo
159 159
      * @return void
160 160
      */
161 161
     function wpinv_get_actions() {
162
-        if ( isset( $_GET['wpinv_action'] ) ) {
163
-            do_action( 'wpinv_' . $_GET['wpinv_action'], $_GET );
162
+        if (isset($_GET['wpinv_action'])) {
163
+            do_action('wpinv_' . $_GET['wpinv_action'], $_GET);
164 164
         }
165 165
     }
166 166
 
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
      * @return void
173 173
      */
174 174
     function wpinv_post_actions() {
175
-        if ( isset( $_POST['wpinv_action'] ) ) {
176
-            do_action( 'wpinv_' . $_POST['wpinv_action'], $_POST );
175
+        if (isset($_POST['wpinv_action'])) {
176
+            do_action('wpinv_' . $_POST['wpinv_action'], $_POST);
177 177
         }
178 178
     }
179 179
 
@@ -184,29 +184,29 @@  discard block
 block discarded – undo
184 184
      * @param int $frequency_count The frequency of the period.
185 185
      * @return mixed|string|void
186 186
      */
187
-    public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1) {
187
+    public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) {
188 188
 
189 189
         $frequency = '';
190 190
         //Format period details
191
-        switch ( strtolower( $period ) ) {
191
+        switch (strtolower($period)) {
192 192
             case 'day' :
193 193
             case 'd' :
194
-                $frequency = sprintf( _n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count);
194
+                $frequency = sprintf(_n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count);
195 195
                 break;
196 196
             case 'week' :
197 197
             case 'w' :
198
-                $frequency = sprintf( _n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count);
198
+                $frequency = sprintf(_n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count);
199 199
                 break;
200 200
             case 'month' :
201 201
             case 'm' :
202
-                $frequency = sprintf( _n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count);
202
+                $frequency = sprintf(_n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count);
203 203
                 break;
204 204
             case 'year' :
205 205
             case 'y' :
206
-                $frequency = sprintf( _n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count);
206
+                $frequency = sprintf(_n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count);
207 207
                 break;
208 208
             default :
209
-                $frequency = apply_filters( 'wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count );
209
+                $frequency = apply_filters('wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count);
210 210
                 break;
211 211
         }
212 212
 
@@ -221,50 +221,50 @@  discard block
 block discarded – undo
221 221
      * @since       1.0.0
222 222
      * @return      void
223 223
      */
224
-    public function wpinv_process_cancellation( $data ) {
224
+    public function wpinv_process_cancellation($data) {
225 225
 
226 226
 
227
-        if( empty( $data['sub_id'] ) ) {
227
+        if (empty($data['sub_id'])) {
228 228
             return;
229 229
         }
230 230
 
231
-        if( ! is_user_logged_in() ) {
231
+        if (!is_user_logged_in()) {
232 232
             return;
233 233
         }
234 234
 
235
-        if( ! wp_verify_nonce( $data['_wpnonce'], 'wpinv-recurring-cancel' ) ) {
236
-            wp_die( __( 'Error', 'invoicing' ), __( 'Nonce verification failed', 'invoicing' ), array( 'response' => 403 ) );
235
+        if (!wp_verify_nonce($data['_wpnonce'], 'wpinv-recurring-cancel')) {
236
+            wp_die(__('Error', 'invoicing'), __('Nonce verification failed', 'invoicing'), array('response' => 403));
237 237
         }
238 238
 
239
-        $data['sub_id'] = absint( $data['sub_id'] );
240
-        $subscription   = new WPInv_Subscription( $data['sub_id'] );
239
+        $data['sub_id'] = absint($data['sub_id']);
240
+        $subscription   = new WPInv_Subscription($data['sub_id']);
241 241
 
242
-        if( ! $subscription->can_cancel() ) {
243
-            wp_die( __( 'Error', 'invoicing' ), __( 'This subscription cannot be cancelled', 'invoicing' ), array( 'response' => 403 ) );
242
+        if (!$subscription->can_cancel()) {
243
+            wp_die(__('Error', 'invoicing'), __('This subscription cannot be cancelled', 'invoicing'), array('response' => 403));
244 244
         }
245 245
 
246 246
         try {
247 247
 
248
-            do_action( 'wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true );
248
+            do_action('wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true);
249 249
 
250 250
             $subscription->cancel();
251 251
 
252
-            if( is_admin() ) {
252
+            if (is_admin()) {
253 253
 
254
-                wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id ) );
254
+                wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id));
255 255
                 exit;
256 256
 
257 257
             } else {
258 258
 
259
-                $redirect = remove_query_arg( array( '_wpnonce', 'wpinv_action', 'sub_id' ), add_query_arg( array( 'wpinv-message' => 'cancelled' ) ) );
260
-                $redirect = apply_filters( 'wpinv_recurring_cancellation_redirect', $redirect, $subscription );
261
-                wp_safe_redirect( $redirect );
259
+                $redirect = remove_query_arg(array('_wpnonce', 'wpinv_action', 'sub_id'), add_query_arg(array('wpinv-message' => 'cancelled')));
260
+                $redirect = apply_filters('wpinv_recurring_cancellation_redirect', $redirect, $subscription);
261
+                wp_safe_redirect($redirect);
262 262
                 exit;
263 263
 
264 264
             }
265 265
 
266
-        } catch ( Exception $e ) {
267
-            wp_die( __( 'Error', 'invoicing' ), $e->getMessage(), array( 'response' => 403 ) );
266
+        } catch (Exception $e) {
267
+            wp_die(__('Error', 'invoicing'), $e->getMessage(), array('response' => 403));
268 268
         }
269 269
 
270 270
     }
@@ -277,33 +277,33 @@  discard block
 block discarded – undo
277 277
      * @since       1.0.0
278 278
      * @return      void
279 279
      */
280
-    public function add_subscription( $invoice ) {
280
+    public function add_subscription($invoice) {
281 281
 
282
-        $invoice = new WPInv_Invoice( $invoice );
282
+        $invoice = new WPInv_Invoice($invoice);
283 283
 
284 284
         // Abort if it is not recurring.
285
-        if ( ! $invoice->is_recurring() || $invoice->is_renewal() ) {
285
+        if (!$invoice->is_recurring() || $invoice->is_renewal()) {
286 286
             return;
287 287
         }
288 288
 
289 289
         // Should we create a subscription for the invoice?
290
-        if ( apply_filters( 'wpinv_skip_invoice_subscription_creation', false, $invoice ) ) {
290
+        if (apply_filters('wpinv_skip_invoice_subscription_creation', false, $invoice)) {
291 291
             return;
292 292
         }
293 293
 
294 294
         // Get the recurring item.
295
-        $subscription_item = $invoice->get_recurring( true );
295
+        $subscription_item = $invoice->get_recurring(true);
296 296
 
297 297
         // Prepare the subscription details.
298
-        $period       = $subscription_item->get_recurring_period( true );
298
+        $period       = $subscription_item->get_recurring_period(true);
299 299
         $interval     = $subscription_item->get_recurring_interval();
300 300
         $add_period   = $interval . ' ' . $period;
301 301
         $trial_period = '';
302 302
 
303
-        if ( $invoice->has_free_trial() ) {
303
+        if ($invoice->has_free_trial()) {
304 304
 
305
-            if ( $subscription_item->has_free_trial() ) {
306
-                $trial_period   = $subscription_item->get_trial_period( true );
305
+            if ($subscription_item->has_free_trial()) {
306
+                $trial_period   = $subscription_item->get_trial_period(true);
307 307
                 $free_interval  = $subscription_item->get_trial_interval();
308 308
             } else {
309 309
                 $trial_period   = $period;
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
         }
317 317
 
318 318
         // Calculate the next renewal date.
319
-        $expiration = date( 'Y-m-d H:i:s', strtotime( "+ $add_period", current_time( 'timestamp' ) ) );
319
+        $expiration = date('Y-m-d H:i:s', strtotime("+ $add_period", current_time('timestamp')));
320 320
 
321 321
         // Subscription arguments.
322 322
         $args = array(
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
             'initial_amount'    => $invoice->get_initial_total(),
330 330
             'recurring_amount'  => $invoice->get_recurring_total(),
331 331
             'bill_times'        => $subscription_item->get_recurring_limit(),
332
-            'created'           => current_time( 'mysql' ),
332
+            'created'           => current_time('mysql'),
333 333
             'expiration'        => $expiration,
334 334
             'trial_period'      => $trial_period,
335 335
             'profile_id'        => '',
@@ -337,19 +337,19 @@  discard block
 block discarded – undo
337 337
         );
338 338
 
339 339
         // Create or update the subscription.
340
-        $subscription = wpinv_get_subscription( $invoice );
340
+        $subscription = wpinv_get_subscription($invoice);
341 341
 
342
-        if ( empty( $subscription ) ) {
342
+        if (empty($subscription)) {
343 343
 
344 344
             $subscription = new WPInv_Subscription();
345
-            $subscription->create( $args );
345
+            $subscription->create($args);
346 346
 
347 347
         } else {
348 348
 
349 349
 
350
-            unset( $args['transaction_id'] );
351
-            unset( $args['profile_id'] );
352
-            $subscription->update( $args );
350
+            unset($args['transaction_id']);
351
+            unset($args['profile_id']);
352
+            $subscription->update($args);
353 353
 
354 354
         }
355 355
 
@@ -362,21 +362,21 @@  discard block
 block discarded – undo
362 362
      * @param       array $data
363 363
      * @since       1.0.19
364 364
      */
365
-    public function admin_update_single_subscription( $args ) {
365
+    public function admin_update_single_subscription($args) {
366 366
 
367 367
         // Ensure the subscription exists and that a status has been given.
368
-        if ( empty( $args['subscription_id'] ) || empty( $args['subscription_status'] ) ) {
368
+        if (empty($args['subscription_id']) || empty($args['subscription_status'])) {
369 369
             return;
370 370
         }
371 371
 
372 372
         // Retrieve the subscriptions.
373
-        $subscription = new WPInv_Subscription( $args['subscription_id'] );
373
+        $subscription = new WPInv_Subscription($args['subscription_id']);
374 374
 
375
-        if ( $subscription->get_id() ) {
375
+        if ($subscription->get_id()) {
376 376
 
377
-            $subscription->set_status( $args['subscription_status'] );
377
+            $subscription->set_status($args['subscription_status']);
378 378
             $subscription->save();
379
-            getpaid_admin()->show_info( __( 'Your changes have been saved', 'invoicing' ) );
379
+            getpaid_admin()->show_info(__('Your changes have been saved', 'invoicing'));
380 380
 
381 381
         }
382 382
 
@@ -388,25 +388,25 @@  discard block
 block discarded – undo
388 388
      * @param       array $data
389 389
      * @since       1.0.19
390 390
      */
391
-    public function admin_renew_single_subscription( $args ) {
391
+    public function admin_renew_single_subscription($args) {
392 392
 
393 393
         // Ensure the subscription exists and that a status has been given.
394
-        if ( empty( $args['id'] ) ) {
394
+        if (empty($args['id'])) {
395 395
             return;
396 396
         }
397 397
 
398 398
         // Retrieve the subscriptions.
399
-        $subscription = new WPInv_Subscription( $args['id'] );
399
+        $subscription = new WPInv_Subscription($args['id']);
400 400
 
401
-        if ( $subscription->get_id() ) {
401
+        if ($subscription->get_id()) {
402 402
 
403
-            $args = array( 'transaction_id', $subscription->get_parent_invoice()->generate_key( 'renewal_' ) );
403
+            $args = array('transaction_id', $subscription->get_parent_invoice()->generate_key('renewal_'));
404 404
 
405
-            if ( $subscription->add_payment( $args ) ) {
405
+            if ($subscription->add_payment($args)) {
406 406
                 $subscription->renew();
407
-                getpaid_admin()->show_info( __( 'This subscription has been renewed and extended.', 'invoicing' ) );
407
+                getpaid_admin()->show_info(__('This subscription has been renewed and extended.', 'invoicing'));
408 408
             } else {
409
-                getpaid_admin()->show_error( __( 'We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing' ) );
409
+                getpaid_admin()->show_error(__('We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing'));
410 410
             }
411 411
     
412 412
             wp_safe_redirect(
Please login to merge, or discard this patch.
templates/emails/wpinv-email-completed_invoice.php 2 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if ( !defined('ABSPATH') ) {
4 4
     die('-1');
5
+}
5 6
 
6 7
 do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
7 8
 
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
6
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
7 7
 
8
-if ( ! empty( $message_body ) ) {
9
-    echo wpautop( wptexturize( $message_body ) );
8
+if (!empty($message_body)) {
9
+    echo wpautop(wptexturize($message_body));
10 10
 }
11 11
 
12
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
12
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
13 13
 
14
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
14
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
15 15
 
16
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
16
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
17 17
 
18
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
19 18
\ No newline at end of file
19
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
20 20
\ No newline at end of file
Please login to merge, or discard this patch.
templates/emails/wpinv-email-refunded_invoice.php 2 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if ( !defined('ABSPATH') ) {
4 4
     die('-1');
5
+}
5 6
 
6 7
 do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
7 8
 
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
6
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
7 7
 
8
-if ( ! empty( $message_body ) ) {
9
-    echo wpautop( wptexturize( $message_body ) );
8
+if (!empty($message_body)) {
9
+    echo wpautop(wptexturize($message_body));
10 10
 }
11 11
 
12
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
12
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
13 13
 
14
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
14
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
15 15
 
16
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
16
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
17 17
 
18
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
19 18
\ No newline at end of file
19
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
20 20
\ No newline at end of file
Please login to merge, or discard this patch.
templates/emails/wpinv-email-onhold_invoice.php 2 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if ( !defined('ABSPATH') ) {
4 4
     die('-1');
5
+}
5 6
 
6 7
 do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
7 8
 
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
6
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
7 7
 
8
-if ( ! empty( $message_body ) ) {
9
-    echo wpautop( wptexturize( $message_body ) );
8
+if (!empty($message_body)) {
9
+    echo wpautop(wptexturize($message_body));
10 10
 }
11 11
 
12
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
12
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
13 13
 
14
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
14
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
15 15
 
16
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
16
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
17 17
 
18
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
19 18
\ No newline at end of file
19
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
20 20
\ No newline at end of file
Please login to merge, or discard this patch.
templates/emails/wpinv-email-new_invoice.php 2 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if ( !defined('ABSPATH') ) {
4 4
     die('-1');
5
+}
5 6
 
6 7
 do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
7 8
 
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
6
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
7 7
 
8
-if ( ! empty( $message_body ) ) {
9
-    echo wpautop( wptexturize( $message_body ) );
8
+if (!empty($message_body)) {
9
+    echo wpautop(wptexturize($message_body));
10 10
 }
11 11
 
12
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
12
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
13 13
 
14
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
14
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
15 15
 
16
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
16
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
17 17
 
18
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
19 18
\ No newline at end of file
19
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
20 20
\ No newline at end of file
Please login to merge, or discard this patch.
templates/emails/wpinv-email-failed_invoice.php 2 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if ( !defined('ABSPATH') ) {
4 4
     die('-1');
5
+}
5 6
 
6 7
 do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
7 8
 
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
6
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
7 7
 
8
-if ( ! empty( $message_body ) ) {
9
-    echo wpautop( wptexturize( $message_body ) );
8
+if (!empty($message_body)) {
9
+    echo wpautop(wptexturize($message_body));
10 10
 }
11 11
 
12
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
12
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
13 13
 
14
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
14
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
15 15
 
16
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
16
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
17 17
 
18
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
19 18
\ No newline at end of file
19
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
20 20
\ No newline at end of file
Please login to merge, or discard this patch.
templates/emails/wpinv-email-cancelled_invoice.php 2 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if ( !defined('ABSPATH') ) {
4 4
     die('-1');
5
+}
5 6
 
6 7
 do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
7 8
 
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
6
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
7 7
 
8
-if ( ! empty( $message_body ) ) {
9
-    echo wpautop( wptexturize( $message_body ) );
8
+if (!empty($message_body)) {
9
+    echo wpautop(wptexturize($message_body));
10 10
 }
11 11
 
12
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
12
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
13 13
 
14
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
14
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
15 15
 
16
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
16
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
17 17
 
18
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
19 18
\ No newline at end of file
19
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
20 20
\ No newline at end of file
Please login to merge, or discard this patch.
templates/emails/wpinv-email-processing_invoice.php 2 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if ( !defined('ABSPATH') ) {
4 4
     die('-1');
5
+}
5 6
 
6 7
 do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
7 8
 
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
6
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
7 7
 
8
-if ( ! empty( $message_body ) ) {
9
-    echo wpautop( wptexturize( $message_body ) );
8
+if (!empty($message_body)) {
9
+    echo wpautop(wptexturize($message_body));
10 10
 }
11 11
 
12
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
12
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
13 13
 
14
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
14
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
15 15
 
16
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
16
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
17 17
 
18
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
19 18
\ No newline at end of file
19
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
20 20
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-user-functions.php 3 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined( 'ABSPATH' ) ) {
4
+    exit;
5
+}
4 6
 
5 7
 function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'publish', $orderby = 'ID', $order = 'DESC' ) {
6 8
     if ( empty( $user ) ) {
Please login to merge, or discard this patch.
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -159,11 +159,11 @@  discard block
 block discarded – undo
159 159
  */
160 160
 function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) {
161 161
 
162
-	if ( current_user_can( 'manage_options' ) ) {
163
-		return 'manage_options';
164
-	};
162
+    if ( current_user_can( 'manage_options' ) ) {
163
+        return 'manage_options';
164
+    };
165 165
 
166
-	return $capalibilty;
166
+    return $capalibilty;
167 167
 }
168 168
 
169 169
 /**
@@ -185,10 +185,10 @@  discard block
 block discarded – undo
185 185
 function wpinv_create_user( $email ) {
186 186
 
187 187
     // Prepare user values.
188
-	$args = array(
189
-		'user_login' => wpinv_generate_user_name( $email ),
190
-		'user_pass'  => wp_generate_password(),
191
-		'user_email' => $email,
188
+    $args = array(
189
+        'user_login' => wpinv_generate_user_name( $email ),
190
+        'user_pass'  => wp_generate_password(),
191
+        'user_email' => $email,
192 192
         'role'       => 'subscriber',
193 193
     );
194 194
 
@@ -205,20 +205,20 @@  discard block
 block discarded – undo
205 205
 function wpinv_generate_user_name( $prefix = '' ) {
206 206
 
207 207
     // If prefix is an email, retrieve the part before the email.
208
-	$prefix = strtok( $prefix, '@' );
208
+    $prefix = strtok( $prefix, '@' );
209 209
 
210
-	// Trim to 4 characters max.
211
-	$prefix = sanitize_user( $prefix );
210
+    // Trim to 4 characters max.
211
+    $prefix = sanitize_user( $prefix );
212 212
 
213
-	$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
214
-	if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) {
215
-		$prefix = 'gtp';
216
-	}
213
+    $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
214
+    if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) {
215
+        $prefix = 'gtp';
216
+    }
217 217
 
218
-	$username = $prefix . '_' . zeroise( wp_rand( 0, 9999 ), 4 );
219
-	if ( username_exists( $username ) ) {
220
-		return wpinv_generate_user_name( $username );
221
-	}
218
+    $username = $prefix . '_' . zeroise( wp_rand( 0, 9999 ), 4 );
219
+    if ( username_exists( $username ) ) {
220
+        return wpinv_generate_user_name( $username );
221
+    }
222 222
 
223 223
     return $username;
224 224
 }
Please login to merge, or discard this patch.
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -1,22 +1,22 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'publish', $orderby = 'ID', $order = 'DESC' ) {
6
-    if ( empty( $user ) ) {
5
+function wpinv_get_users_invoices($user = 0, $number = 20, $pagination = false, $status = 'publish', $orderby = 'ID', $order = 'DESC') {
6
+    if (empty($user)) {
7 7
         $user = get_current_user_id();
8 8
     }
9 9
 
10
-    if ( empty( $user ) ) {
10
+    if (empty($user)) {
11 11
         return false;
12 12
     }
13 13
 
14
-    $args = apply_filters( 'wpinv_get_users_invoices_args', array( 'user' => $user, 'limit' => $number, 'status' => $status, 'paginate' => $pagination, 'orderby' => $orderby, 'order' => $order ) );
14
+    $args = apply_filters('wpinv_get_users_invoices_args', array('user' => $user, 'limit' => $number, 'status' => $status, 'paginate' => $pagination, 'orderby' => $orderby, 'order' => $order));
15 15
     
16
-    return wpinv_get_invoices( $args );
16
+    return wpinv_get_invoices($args);
17 17
 }
18 18
 
19
-function wpinv_dropdown_users( $args = '' ) {
19
+function wpinv_dropdown_users($args = '') {
20 20
     $defaults = array(
21 21
         'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '',
22 22
         'orderby' => 'display_name', 'order' => 'ASC',
@@ -27,18 +27,18 @@  discard block
 block discarded – undo
27 27
         'option_none_value' => -1
28 28
     );
29 29
 
30
-    $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
30
+    $defaults['selected'] = is_author() ? get_query_var('author') : 0;
31 31
 
32
-    $r = wp_parse_args( $args, $defaults );
32
+    $r = wp_parse_args($args, $defaults);
33 33
 
34
-    $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) );
34
+    $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who'));
35 35
 
36
-    $fields = array( 'ID', 'user_login', 'user_email' );
36
+    $fields = array('ID', 'user_login', 'user_email');
37 37
 
38
-    $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name';
39
-    if ( 'display_name_with_login' === $show ) {
38
+    $show = !empty($r['show']) ? $r['show'] : 'display_name';
39
+    if ('display_name_with_login' === $show) {
40 40
         $fields[] = 'display_name';
41
-    } else if ( 'display_name_with_email' === $show ) {
41
+    } else if ('display_name_with_email' === $show) {
42 42
         $fields[] = 'display_name';
43 43
     } else {
44 44
         $fields[] = $show;
@@ -50,99 +50,99 @@  discard block
 block discarded – undo
50 50
     $show_option_none = $r['show_option_none'];
51 51
     $option_none_value = $r['option_none_value'];
52 52
 
53
-    $query_args = apply_filters( 'wpinv_dropdown_users_args', $query_args, $r );
53
+    $query_args = apply_filters('wpinv_dropdown_users_args', $query_args, $r);
54 54
 
55
-    $users = get_users( $query_args );
55
+    $users = get_users($query_args);
56 56
 
57 57
     $output = '';
58
-    if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) {
59
-        $name = esc_attr( $r['name'] );
60
-        if ( $r['multi'] && ! $r['id'] ) {
58
+    if (!empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) {
59
+        $name = esc_attr($r['name']);
60
+        if ($r['multi'] && !$r['id']) {
61 61
             $id = '';
62 62
         } else {
63
-            $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'";
63
+            $id = $r['id'] ? " id='" . esc_attr($r['id']) . "'" : " id='$name'";
64 64
         }
65 65
         $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n";
66 66
 
67
-        if ( $show_option_all ) {
67
+        if ($show_option_all) {
68 68
             $output .= "\t<option value='0'>$show_option_all</option>\n";
69 69
         }
70 70
 
71
-        if ( $show_option_none ) {
72
-            $_selected = selected( $option_none_value, $r['selected'], false );
73
-            $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n";
71
+        if ($show_option_none) {
72
+            $_selected = selected($option_none_value, $r['selected'], false);
73
+            $output .= "\t<option value='" . esc_attr($option_none_value) . "'$_selected>$show_option_none</option>\n";
74 74
         }
75 75
 
76
-        if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) {
76
+        if ($r['include_selected'] && ($r['selected'] > 0)) {
77 77
             $found_selected = false;
78 78
             $r['selected'] = (int) $r['selected'];
79
-            foreach ( (array) $users as $user ) {
79
+            foreach ((array) $users as $user) {
80 80
                 $user->ID = (int) $user->ID;
81
-                if ( $user->ID === $r['selected'] ) {
81
+                if ($user->ID === $r['selected']) {
82 82
                     $found_selected = true;
83 83
                 }
84 84
             }
85 85
 
86
-            if ( ! $found_selected ) {
87
-                $users[] = get_userdata( $r['selected'] );
86
+            if (!$found_selected) {
87
+                $users[] = get_userdata($r['selected']);
88 88
             }
89 89
         }
90 90
 
91
-        foreach ( (array) $users as $user ) {
92
-            if ( 'display_name_with_login' === $show ) {
91
+        foreach ((array) $users as $user) {
92
+            if ('display_name_with_login' === $show) {
93 93
                 /* translators: 1: display name, 2: user_login */
94
-                $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login );
95
-            } elseif ( 'display_name_with_email' === $show ) {
94
+                $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_login);
95
+            } elseif ('display_name_with_email' === $show) {
96 96
                 /* translators: 1: display name, 2: user_email */
97
-                if ( $user->display_name == $user->user_email ) {
97
+                if ($user->display_name == $user->user_email) {
98 98
                     $display = $user->display_name;
99 99
                 } else {
100
-                    $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_email );
100
+                    $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_email);
101 101
                 }
102
-            } elseif ( ! empty( $user->$show ) ) {
102
+            } elseif (!empty($user->$show)) {
103 103
                 $display = $user->$show;
104 104
             } else {
105 105
                 $display = '(' . $user->user_login . ')';
106 106
             }
107 107
 
108
-            $_selected = selected( $user->ID, $r['selected'], false );
109
-            $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n";
108
+            $_selected = selected($user->ID, $r['selected'], false);
109
+            $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n";
110 110
         }
111 111
 
112 112
         $output .= "</select>";
113 113
     }
114 114
 
115
-    $html = apply_filters( 'wpinv_dropdown_users', $output );
115
+    $html = apply_filters('wpinv_dropdown_users', $output);
116 116
 
117
-    if ( $r['echo'] ) {
117
+    if ($r['echo']) {
118 118
         echo $html;
119 119
     }
120 120
     return $html;
121 121
 }
122 122
 
123
-function wpinv_guest_redirect( $redirect_to, $user_id = 0 ) {
124
-    if ( (int)wpinv_get_option( 'guest_checkout' ) && $user_id > 0 ) {
125
-        wpinv_login_user( $user_id );
123
+function wpinv_guest_redirect($redirect_to, $user_id = 0) {
124
+    if ((int) wpinv_get_option('guest_checkout') && $user_id > 0) {
125
+        wpinv_login_user($user_id);
126 126
     } else {
127
-        $redirect_to = wp_login_url( $redirect_to );
127
+        $redirect_to = wp_login_url($redirect_to);
128 128
     }
129 129
     
130
-    $redirect_to = apply_filters( 'wpinv_invoice_link_guest_redirect', $redirect_to, $user_id );
130
+    $redirect_to = apply_filters('wpinv_invoice_link_guest_redirect', $redirect_to, $user_id);
131 131
     
132
-    wp_redirect( $redirect_to );
132
+    wp_redirect($redirect_to);
133 133
 }
134 134
 
135
-function wpinv_login_user( $user_id ) {
136
-    if ( is_user_logged_in() ) {
135
+function wpinv_login_user($user_id) {
136
+    if (is_user_logged_in()) {
137 137
         return true;
138 138
     }
139 139
     
140
-    $user = get_user_by( 'id', $user_id );
140
+    $user = get_user_by('id', $user_id);
141 141
     
142
-    if ( !empty( $user ) && !is_wp_error( $user ) && !empty( $user->user_login ) ) {
143
-        wp_set_current_user( $user_id, $user->user_login );
144
-        wp_set_auth_cookie( $user_id );
145
-        do_action( 'wp_login', $user->user_login );
142
+    if (!empty($user) && !is_wp_error($user) && !empty($user->user_login)) {
143
+        wp_set_current_user($user_id, $user->user_login);
144
+        wp_set_auth_cookie($user_id);
145
+        do_action('wp_login', $user->user_login);
146 146
         
147 147
         return true;
148 148
     }
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
  * @return string capability to check against
158 158
  * @param string $capalibilty Optional. The alternative capability to check against.
159 159
  */
160
-function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) {
160
+function wpinv_get_capability($capalibilty = 'manage_invoicing') {
161 161
 
162
-	if ( current_user_can( 'manage_options' ) ) {
162
+	if (current_user_can('manage_options')) {
163 163
 		return 'manage_options';
164 164
 	};
165 165
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
  * @return bool
174 174
  */
175 175
 function wpinv_current_user_can_manage_invoicing() {
176
-    return current_user_can( wpinv_get_capability() );
176
+    return current_user_can(wpinv_get_capability());
177 177
 }
178 178
 
179 179
 /**
@@ -182,17 +182,17 @@  discard block
 block discarded – undo
182 182
  * @since 1.0.19
183 183
  * @return int|WP_Error
184 184
  */
185
-function wpinv_create_user( $email ) {
185
+function wpinv_create_user($email) {
186 186
 
187 187
     // Prepare user values.
188 188
 	$args = array(
189
-		'user_login' => wpinv_generate_user_name( $email ),
189
+		'user_login' => wpinv_generate_user_name($email),
190 190
 		'user_pass'  => wp_generate_password(),
191 191
 		'user_email' => $email,
192 192
         'role'       => 'subscriber',
193 193
     );
194 194
 
195
-    return wp_insert_user( $args );
195
+    return wp_insert_user($args);
196 196
 
197 197
 }
198 198
 
@@ -202,22 +202,22 @@  discard block
 block discarded – undo
202 202
  * @since 1.0.19
203 203
  * @return bool|WP_User
204 204
  */
205
-function wpinv_generate_user_name( $prefix = '' ) {
205
+function wpinv_generate_user_name($prefix = '') {
206 206
 
207 207
     // If prefix is an email, retrieve the part before the email.
208
-	$prefix = strtok( $prefix, '@' );
208
+	$prefix = strtok($prefix, '@');
209 209
 
210 210
 	// Trim to 4 characters max.
211
-	$prefix = sanitize_user( $prefix );
211
+	$prefix = sanitize_user($prefix);
212 212
 
213
-	$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
214
-	if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) {
213
+	$illegal_logins = (array) apply_filters('illegal_user_logins', array());
214
+	if (empty($prefix) || in_array(strtolower($prefix), array_map('strtolower', $illegal_logins), true)) {
215 215
 		$prefix = 'gtp';
216 216
 	}
217 217
 
218
-	$username = $prefix . '_' . zeroise( wp_rand( 0, 9999 ), 4 );
219
-	if ( username_exists( $username ) ) {
220
-		return wpinv_generate_user_name( $username );
218
+	$username = $prefix . '_' . zeroise(wp_rand(0, 9999), 4);
219
+	if (username_exists($username)) {
220
+		return wpinv_generate_user_name($username);
221 221
 	}
222 222
 
223 223
     return $username;
Please login to merge, or discard this patch.