Passed
Push — master ( 555ee7...c90a51 )
by Brian
09:54 queued 04:19
created
widgets/getpaid.php 2 patches
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -36,36 +36,36 @@  discard block
 block discarded – undo
36 36
                     'desc_tip'    => true,
37 37
                     'default'     => '',
38 38
                     'advanced'    => false
39
-				),
39
+                ),
40 40
 
41 41
                 'form'  => array(
42
-	                'title'       => __( 'Form', 'invoicing' ),
43
-	                'desc'        => __( 'Enter a form id in case you want to display a specific payment form', 'invoicing' ),
44
-	                'type'        => 'text',
45
-	                'desc_tip'    => true,
46
-	                'default'     => '',
47
-	                'placeholder' => __('1','invoicing'),
48
-	                'advanced'    => false
49
-				),
50
-
51
-				'item'  => array(
52
-	                'title'       => __( 'Items', 'invoicing' ),
53
-	                'desc'        => __( 'Enter comma separated list of invoicing item id and quantity (item_id|quantity). Ex. 101|2. This will be ignored in case you specify a form above. Enter 0 as the quantity to let users select their own quantities', 'invoicing' ),
54
-	                'type'        => 'text',
55
-	                'desc_tip'    => true,
56
-	                'default'     => '',
57
-	                'placeholder' => __('1','invoicing'),
58
-	                'advanced'    => false
59
-				),
42
+                    'title'       => __( 'Form', 'invoicing' ),
43
+                    'desc'        => __( 'Enter a form id in case you want to display a specific payment form', 'invoicing' ),
44
+                    'type'        => 'text',
45
+                    'desc_tip'    => true,
46
+                    'default'     => '',
47
+                    'placeholder' => __('1','invoicing'),
48
+                    'advanced'    => false
49
+                ),
50
+
51
+                'item'  => array(
52
+                    'title'       => __( 'Items', 'invoicing' ),
53
+                    'desc'        => __( 'Enter comma separated list of invoicing item id and quantity (item_id|quantity). Ex. 101|2. This will be ignored in case you specify a form above. Enter 0 as the quantity to let users select their own quantities', 'invoicing' ),
54
+                    'type'        => 'text',
55
+                    'desc_tip'    => true,
56
+                    'default'     => '',
57
+                    'placeholder' => __('1','invoicing'),
58
+                    'advanced'    => false
59
+                ),
60 60
 
61 61
                 'button'  => array(
62
-	                'title'       => __( 'Button', 'invoicing' ),
63
-	                'desc'        => __( 'Enter button label in case you would like to display the forms in a popup.', 'invoicing' ),
64
-	                'type'        => 'text',
65
-	                'desc_tip'    => true,
66
-	                'default'     => '',
67
-	                'advanced'    => false
68
-				)
62
+                    'title'       => __( 'Button', 'invoicing' ),
63
+                    'desc'        => __( 'Enter button label in case you would like to display the forms in a popup.', 'invoicing' ),
64
+                    'type'        => 'text',
65
+                    'desc_tip'    => true,
66
+                    'default'     => '',
67
+                    'advanced'    => false
68
+                )
69 69
 
70 70
             )
71 71
 
@@ -75,91 +75,91 @@  discard block
 block discarded – undo
75 75
         parent::__construct( $options );
76 76
     }
77 77
 
78
-	/**
79
-	 * The Super block output function.
80
-	 *
81
-	 * @param array $args
82
-	 * @param array $widget_args
83
-	 * @param string $content
84
-	 *
85
-	 * @return string
86
-	 */
78
+    /**
79
+     * The Super block output function.
80
+     *
81
+     * @param array $args
82
+     * @param array $widget_args
83
+     * @param string $content
84
+     *
85
+     * @return string
86
+     */
87 87
     public function output( $args = array(), $widget_args = array(), $content = '' ) {
88 88
 
89
-	    // Is the shortcode set up correctly?
90
-		if ( empty( $args['form'] ) && empty( $args['item'] ) ) {
91
-			return aui()->alert(
92
-				array(
93
-					'type'    => 'warning',
94
-					'content' => __( 'No payment form or item selected', 'invoicing' ),
95
-				)
96
-			);
97
-		}
98
-
99
-		// Payment form or button?
100
-		if ( ! empty( $args['form'] ) ) {
101
-			return $this->handle_payment_form(  $args );
102
-		} else {
103
-			return $this->handle_buy_item(  $args );
104
-		}
105
-
106
-	}
107
-
108
-	/**
109
-	 * Displaying a payment form
110
-	 *
111
-	 * @return string
112
-	 */
89
+        // Is the shortcode set up correctly?
90
+        if ( empty( $args['form'] ) && empty( $args['item'] ) ) {
91
+            return aui()->alert(
92
+                array(
93
+                    'type'    => 'warning',
94
+                    'content' => __( 'No payment form or item selected', 'invoicing' ),
95
+                )
96
+            );
97
+        }
98
+
99
+        // Payment form or button?
100
+        if ( ! empty( $args['form'] ) ) {
101
+            return $this->handle_payment_form(  $args );
102
+        } else {
103
+            return $this->handle_buy_item(  $args );
104
+        }
105
+
106
+    }
107
+
108
+    /**
109
+     * Displaying a payment form
110
+     *
111
+     * @return string
112
+     */
113 113
     protected function handle_payment_form( $args = array() ) {
114 114
 
115
-		if ( empty( $args['button'] ) ) {
116
-			return getpaid_display_payment_form( $args['form'] );
117
-		}
115
+        if ( empty( $args['button'] ) ) {
116
+            return getpaid_display_payment_form( $args['form'] );
117
+        }
118 118
 
119
-		return $this->payment_form_button( $args['form'], $args['button'] );
120
-	}
119
+        return $this->payment_form_button( $args['form'], $args['button'] );
120
+    }
121 121
 
122
-	/**
123
-	 * Displays a payment form button.
124
-	 *
125
-	 * @return string
126
-	 */
122
+    /**
123
+     * Displays a payment form button.
124
+     *
125
+     * @return string
126
+     */
127 127
     protected function payment_form_button( $form, $button ) {
128
-		return getpaid_get_payment_button( $button, $form );
129
-	}
130
-
131
-	/**
132
-	 * Selling an item
133
-	 *
134
-	 * @return string
135
-	 */
128
+        return getpaid_get_payment_button( $button, $form );
129
+    }
130
+
131
+    /**
132
+     * Selling an item
133
+     *
134
+     * @return string
135
+     */
136 136
     protected function handle_buy_item( $args = array() ) {
137 137
 
138
-		if ( empty( $args['button'] ) ) {
139
-			return $this->buy_item_form( $args['item'] );
140
-		}
138
+        if ( empty( $args['button'] ) ) {
139
+            return $this->buy_item_form( $args['item'] );
140
+        }
141 141
 
142
-		return $this->buy_item_button( $args['item'], $args['button'] );
142
+        return $this->buy_item_button( $args['item'], $args['button'] );
143 143
 
144
-	}
144
+    }
145 145
 
146
-	/**
147
-	 * Displays a buy item form.
148
-	 *
149
-	 * @return string
150
-	 */
146
+    /**
147
+     * Displays a buy item form.
148
+     *
149
+     * @return string
150
+     */
151 151
     protected function buy_item_form( $item ) {
152
-		$items = getpaid_convert_items_to_array( $item );
153
-		return getpaid_display_item_payment_form( $items );
154
-	}
155
-
156
-	/**
157
-	 * Displays a buy item button.
158
-	 *
159
-	 * @return string
160
-	 */
152
+        $items = getpaid_convert_items_to_array( $item );
153
+        return getpaid_display_item_payment_form( $items );
154
+    }
155
+
156
+    /**
157
+     * Displays a buy item button.
158
+     *
159
+     * @return string
160
+     */
161 161
     protected function buy_item_button( $item, $button ) {
162
-		return getpaid_get_payment_button( $button, null, $item );
162
+        return getpaid_get_payment_button( $button, null, $item );
163 163
     }
164 164
 
165 165
 }
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit;
4 4
 }
5 5
 
@@ -22,16 +22,16 @@  discard block
 block discarded – undo
22 22
             'block-keywords'=> "['invoicing','buy', 'buy item', 'form']",
23 23
             'class_name'     => __CLASS__,
24 24
             'base_id'       => 'getpaid',
25
-            'name'          => __('GetPaid','invoicing'),
25
+            'name'          => __('GetPaid', 'invoicing'),
26 26
             'widget_ops'    => array(
27 27
                 'classname'   => 'getpaid bsui',
28
-                'description' => esc_html__('Show payment forms or buttons.','invoicing'),
28
+                'description' => esc_html__('Show payment forms or buttons.', 'invoicing'),
29 29
             ),
30 30
             'arguments'     => array(
31 31
 
32 32
                 'title'  => array(
33
-                    'title'       => __( 'Widget title', 'invoicing' ),
34
-                    'desc'        => __( 'Enter widget title.', 'invoicing' ),
33
+                    'title'       => __('Widget title', 'invoicing'),
34
+                    'desc'        => __('Enter widget title.', 'invoicing'),
35 35
                     'type'        => 'text',
36 36
                     'desc_tip'    => true,
37 37
                     'default'     => '',
@@ -39,28 +39,28 @@  discard block
 block discarded – undo
39 39
 				),
40 40
 
41 41
                 'form'  => array(
42
-	                'title'       => __( 'Form', 'invoicing' ),
43
-	                'desc'        => __( 'Enter a form id in case you want to display a specific payment form', 'invoicing' ),
42
+	                'title'       => __('Form', 'invoicing'),
43
+	                'desc'        => __('Enter a form id in case you want to display a specific payment form', 'invoicing'),
44 44
 	                'type'        => 'text',
45 45
 	                'desc_tip'    => true,
46 46
 	                'default'     => '',
47
-	                'placeholder' => __('1','invoicing'),
47
+	                'placeholder' => __('1', 'invoicing'),
48 48
 	                'advanced'    => false
49 49
 				),
50 50
 
51 51
 				'item'  => array(
52
-	                'title'       => __( 'Items', 'invoicing' ),
53
-	                'desc'        => __( 'Enter comma separated list of invoicing item id and quantity (item_id|quantity). Ex. 101|2. This will be ignored in case you specify a form above. Enter 0 as the quantity to let users select their own quantities', 'invoicing' ),
52
+	                'title'       => __('Items', 'invoicing'),
53
+	                'desc'        => __('Enter comma separated list of invoicing item id and quantity (item_id|quantity). Ex. 101|2. This will be ignored in case you specify a form above. Enter 0 as the quantity to let users select their own quantities', 'invoicing'),
54 54
 	                'type'        => 'text',
55 55
 	                'desc_tip'    => true,
56 56
 	                'default'     => '',
57
-	                'placeholder' => __('1','invoicing'),
57
+	                'placeholder' => __('1', 'invoicing'),
58 58
 	                'advanced'    => false
59 59
 				),
60 60
 
61 61
                 'button'  => array(
62
-	                'title'       => __( 'Button', 'invoicing' ),
63
-	                'desc'        => __( 'Enter button label in case you would like to display the forms in a popup.', 'invoicing' ),
62
+	                'title'       => __('Button', 'invoicing'),
63
+	                'desc'        => __('Enter button label in case you would like to display the forms in a popup.', 'invoicing'),
64 64
 	                'type'        => 'text',
65 65
 	                'desc_tip'    => true,
66 66
 	                'default'     => '',
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
         );
73 73
 
74 74
 
75
-        parent::__construct( $options );
75
+        parent::__construct($options);
76 76
     }
77 77
 
78 78
 	/**
@@ -84,23 +84,23 @@  discard block
 block discarded – undo
84 84
 	 *
85 85
 	 * @return string
86 86
 	 */
87
-    public function output( $args = array(), $widget_args = array(), $content = '' ) {
87
+    public function output($args = array(), $widget_args = array(), $content = '') {
88 88
 
89 89
 	    // Is the shortcode set up correctly?
90
-		if ( empty( $args['form'] ) && empty( $args['item'] ) ) {
90
+		if (empty($args['form']) && empty($args['item'])) {
91 91
 			return aui()->alert(
92 92
 				array(
93 93
 					'type'    => 'warning',
94
-					'content' => __( 'No payment form or item selected', 'invoicing' ),
94
+					'content' => __('No payment form or item selected', 'invoicing'),
95 95
 				)
96 96
 			);
97 97
 		}
98 98
 
99 99
 		// Payment form or button?
100
-		if ( ! empty( $args['form'] ) ) {
101
-			return $this->handle_payment_form(  $args );
100
+		if (!empty($args['form'])) {
101
+			return $this->handle_payment_form($args);
102 102
 		} else {
103
-			return $this->handle_buy_item(  $args );
103
+			return $this->handle_buy_item($args);
104 104
 		}
105 105
 
106 106
 	}
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
 	 *
111 111
 	 * @return string
112 112
 	 */
113
-    protected function handle_payment_form( $args = array() ) {
113
+    protected function handle_payment_form($args = array()) {
114 114
 
115
-		if ( empty( $args['button'] ) ) {
116
-			return getpaid_display_payment_form( $args['form'] );
115
+		if (empty($args['button'])) {
116
+			return getpaid_display_payment_form($args['form']);
117 117
 		}
118 118
 
119
-		return $this->payment_form_button( $args['form'], $args['button'] );
119
+		return $this->payment_form_button($args['form'], $args['button']);
120 120
 	}
121 121
 
122 122
 	/**
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 	 *
125 125
 	 * @return string
126 126
 	 */
127
-    protected function payment_form_button( $form, $button ) {
128
-		return getpaid_get_payment_button( $button, $form );
127
+    protected function payment_form_button($form, $button) {
128
+		return getpaid_get_payment_button($button, $form);
129 129
 	}
130 130
 
131 131
 	/**
@@ -133,13 +133,13 @@  discard block
 block discarded – undo
133 133
 	 *
134 134
 	 * @return string
135 135
 	 */
136
-    protected function handle_buy_item( $args = array() ) {
136
+    protected function handle_buy_item($args = array()) {
137 137
 
138
-		if ( empty( $args['button'] ) ) {
139
-			return $this->buy_item_form( $args['item'] );
138
+		if (empty($args['button'])) {
139
+			return $this->buy_item_form($args['item']);
140 140
 		}
141 141
 
142
-		return $this->buy_item_button( $args['item'], $args['button'] );
142
+		return $this->buy_item_button($args['item'], $args['button']);
143 143
 
144 144
 	}
145 145
 
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
 	 *
149 149
 	 * @return string
150 150
 	 */
151
-    protected function buy_item_form( $item ) {
152
-		$items = getpaid_convert_items_to_array( $item );
153
-		return getpaid_display_item_payment_form( $items );
151
+    protected function buy_item_form($item) {
152
+		$items = getpaid_convert_items_to_array($item);
153
+		return getpaid_display_item_payment_form($items);
154 154
 	}
155 155
 
156 156
 	/**
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
 	 *
159 159
 	 * @return string
160 160
 	 */
161
-    protected function buy_item_button( $item, $button ) {
162
-		return getpaid_get_payment_button( $button, null, $item );
161
+    protected function buy_item_button($item, $button) {
162
+		return getpaid_get_payment_button($button, null, $item);
163 163
     }
164 164
 
165 165
 }
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -714,24 +714,24 @@
 block discarded – undo
714 714
         }
715 715
 
716 716
         // Is the request set up correctly?
717
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
718
-			echo aui()->alert(
719
-				array(
720
-					'type'    => 'warning',
721
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
722
-				)
717
+        if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
718
+            echo aui()->alert(
719
+                array(
720
+                    'type'    => 'warning',
721
+                    'content' => __( 'No payment form or item provided', 'invoicing' ),
722
+                )
723 723
             );
724 724
             exit;
725 725
         }
726 726
 
727 727
         // Payment form or button?
728
-		if ( ! empty( $_GET['form'] ) ) {
728
+        if ( ! empty( $_GET['form'] ) ) {
729 729
             echo getpaid_display_payment_form( $_GET['form'] );
730
-		} else if( $_GET['invoice'] ) {
731
-		    echo getpaid_display_invoice_payment_form( $_GET['invoice'] );
730
+        } else if( $_GET['invoice'] ) {
731
+            echo getpaid_display_invoice_payment_form( $_GET['invoice'] );
732 732
         } else {
733
-			$items = getpaid_convert_items_to_array( $_GET['item'] );
734
-		    echo getpaid_display_item_payment_form( $items );
733
+            $items = getpaid_convert_items_to_array( $_GET['item'] );
734
+            echo getpaid_display_item_payment_form( $items );
735 735
         }
736 736
         
737 737
         exit;
Please login to merge, or discard this patch.
Spacing   +394 added lines, -394 removed lines patch added patch discarded remove patch
@@ -7,28 +7,28 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 class WPInv_Ajax {
15 15
     public static function init() {
16
-        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
17
-        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
16
+        add_action('init', array(__CLASS__, 'define_ajax'), 0);
17
+        add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
18 18
         self::add_ajax_events();
19 19
     }
20 20
 
21 21
     public static function define_ajax() {
22
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
23
-            if ( ! defined( 'DOING_AJAX' ) ) {
24
-                define( 'DOING_AJAX', true );
22
+        if (!empty($_GET['wpinv-ajax'])) {
23
+            if (!defined('DOING_AJAX')) {
24
+                define('DOING_AJAX', true);
25 25
             }
26
-            if ( ! defined( 'WC_DOING_AJAX' ) ) {
27
-                define( 'WC_DOING_AJAX', true );
26
+            if (!defined('WC_DOING_AJAX')) {
27
+                define('WC_DOING_AJAX', true);
28 28
             }
29 29
             // Turn off display_errors during AJAX events to prevent malformed JSON
30
-            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
31
-                /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+            if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
31
+                /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
32 32
             }
33 33
             $GLOBALS['wpdb']->hide_errors();
34 34
         }
@@ -37,24 +37,24 @@  discard block
 block discarded – undo
37 37
     public static function do_wpinv_ajax() {
38 38
         global $wp_query;
39 39
 
40
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
41
-            $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) );
40
+        if (!empty($_GET['wpinv-ajax'])) {
41
+            $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax']));
42 42
         }
43 43
 
44
-        if ( $action = $wp_query->get( 'wpinv-ajax' ) ) {
44
+        if ($action = $wp_query->get('wpinv-ajax')) {
45 45
             self::wpinv_ajax_headers();
46
-            do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) );
46
+            do_action('wpinv_ajax_' . sanitize_text_field($action));
47 47
             die();
48 48
         }
49 49
     }
50 50
     
51 51
     private static function wpinv_ajax_headers() {
52 52
         send_origin_headers();
53
-        /** @scrutinizer ignore-unhandled */ @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
54
-        /** @scrutinizer ignore-unhandled */ @header( 'X-Robots-Tag: noindex' );
53
+        /** @scrutinizer ignore-unhandled */ @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
54
+        /** @scrutinizer ignore-unhandled */ @header('X-Robots-Tag: noindex');
55 55
         send_nosniff_header();
56 56
         nocache_headers();
57
-        status_header( 200 );
57
+        status_header(200);
58 58
     }
59 59
     
60 60
     public static function add_ajax_events() {
@@ -81,39 +81,39 @@  discard block
 block discarded – undo
81 81
             'buy_items' => true,
82 82
         );
83 83
 
84
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
85
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
84
+        foreach ($ajax_events as $ajax_event => $nopriv) {
85
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
86 86
             
87
-            if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) {
88
-                define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 );
87
+            if (!defined('WPI_AJAX_' . strtoupper($nopriv))) {
88
+                define('WPI_AJAX_' . strtoupper($nopriv), 1);
89 89
             }
90 90
 
91
-            if ( $nopriv ) {
92
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
91
+            if ($nopriv) {
92
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
93 93
 
94
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
94
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
95 95
             }
96 96
         }
97 97
     }
98 98
     
99 99
     public static function add_note() {
100
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
100
+        check_ajax_referer('add-invoice-note', '_nonce');
101 101
 
102
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
102
+        if (!wpinv_current_user_can_manage_invoicing()) {
103 103
             die(-1);
104 104
         }
105 105
 
106
-        $post_id   = absint( $_POST['post_id'] );
107
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
108
-        $note_type = sanitize_text_field( $_POST['note_type'] );
106
+        $post_id   = absint($_POST['post_id']);
107
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
108
+        $note_type = sanitize_text_field($_POST['note_type']);
109 109
 
110 110
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
111 111
 
112
-        if ( $post_id > 0 ) {
113
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
112
+        if ($post_id > 0) {
113
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
114 114
 
115
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
116
-                wpinv_get_invoice_note_line_item( $note_id );
115
+            if ($note_id > 0 && !is_wp_error($note_id)) {
116
+                wpinv_get_invoice_note_line_item($note_id);
117 117
             }
118 118
         }
119 119
 
@@ -121,16 +121,16 @@  discard block
 block discarded – undo
121 121
     }
122 122
 
123 123
     public static function delete_note() {
124
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
124
+        check_ajax_referer('delete-invoice-note', '_nonce');
125 125
 
126
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
126
+        if (!wpinv_current_user_can_manage_invoicing()) {
127 127
             die(-1);
128 128
         }
129 129
 
130
-        $note_id = (int)$_POST['note_id'];
130
+        $note_id = (int) $_POST['note_id'];
131 131
 
132
-        if ( $note_id > 0 ) {
133
-            wp_delete_comment( $note_id, true );
132
+        if ($note_id > 0) {
133
+            wp_delete_comment($note_id, true);
134 134
         }
135 135
 
136 136
         die();
@@ -143,8 +143,8 @@  discard block
 block discarded – undo
143 143
     }
144 144
     
145 145
     public static function checkout() {
146
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
147
-            define( 'WPINV_CHECKOUT', true );
146
+        if (!defined('WPINV_CHECKOUT')) {
147
+            define('WPINV_CHECKOUT', true);
148 148
         }
149 149
 
150 150
         wpinv_process_checkout();
@@ -153,53 +153,53 @@  discard block
 block discarded – undo
153 153
     
154 154
     public static function add_invoice_item() {
155 155
         global $wpi_userID, $wpinv_ip_address_country;
156
-        check_ajax_referer( 'invoice-item', '_nonce' );
157
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
156
+        check_ajax_referer('invoice-item', '_nonce');
157
+        if (!wpinv_current_user_can_manage_invoicing()) {
158 158
             die(-1);
159 159
         }
160 160
         
161
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
162
-        $invoice_id = absint( $_POST['invoice_id'] );
161
+        $item_id    = sanitize_text_field($_POST['item_id']);
162
+        $invoice_id = absint($_POST['invoice_id']);
163 163
         
164
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
164
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
165 165
             die();
166 166
         }
167 167
         
168
-        $invoice    = wpinv_get_invoice( $invoice_id );
169
-        if ( empty( $invoice ) ) {
168
+        $invoice = wpinv_get_invoice($invoice_id);
169
+        if (empty($invoice)) {
170 170
             die();
171 171
         }
172 172
         
173
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
173
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
174 174
             die(); // Don't allow modify items for paid invoice.
175 175
         }
176 176
         
177
-        if ( !empty( $_POST['user_id'] ) ) {
178
-            $wpi_userID = absint( $_POST['user_id'] ); 
177
+        if (!empty($_POST['user_id'])) {
178
+            $wpi_userID = absint($_POST['user_id']); 
179 179
         }
180 180
 
181
-        $item = new WPInv_Item( $item_id );
182
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
181
+        $item = new WPInv_Item($item_id);
182
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
183 183
             die();
184 184
         }
185 185
         
186 186
         // Validate item before adding to invoice because recurring item must be paid individually.
187
-        if ( !empty( $invoice->cart_details ) ) {
187
+        if (!empty($invoice->cart_details)) {
188 188
             $valid = true;
189 189
             
190
-            if ( $recurring_item = $invoice->get_recurring() ) {
191
-                if ( $recurring_item != $item_id ) {
190
+            if ($recurring_item = $invoice->get_recurring()) {
191
+                if ($recurring_item != $item_id) {
192 192
                     $valid = false;
193 193
                 }
194
-            } else if ( wpinv_is_recurring_item( $item_id ) ) {
194
+            } else if (wpinv_is_recurring_item($item_id)) {
195 195
                 $valid = false;
196 196
             }
197 197
             
198
-            if ( !$valid ) {
198
+            if (!$valid) {
199 199
                 $response               = array();
200 200
                 $response['success']    = false;
201
-                $response['msg']        = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );
202
-                wp_send_json( $response );
201
+                $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing');
202
+                wp_send_json($response);
203 203
             }
204 204
         }
205 205
         
@@ -207,11 +207,11 @@  discard block
 block discarded – undo
207 207
         
208 208
         $data                   = array();
209 209
         $data['invoice_id']     = $invoice_id;
210
-        $data['cart_discounts'] = $invoice->get_discounts( true );
210
+        $data['cart_discounts'] = $invoice->get_discounts(true);
211 211
         
212
-        wpinv_set_checkout_session( $data );
212
+        wpinv_set_checkout_session($data);
213 213
         
214
-        $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1;
214
+        $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int) $_POST['qty'] > 0 ? (int) $_POST['qty'] : 1;
215 215
 
216 216
         $args = array(
217 217
             'id'            => $item_id,
@@ -224,21 +224,21 @@  discard block
 block discarded – undo
224 224
             'fees'          => array()
225 225
         );
226 226
 
227
-        $invoice->add_item( $item_id, $args );
227
+        $invoice->add_item($item_id, $args);
228 228
         $invoice->save();
229 229
         
230
-        if ( empty( $_POST['country'] ) ) {
230
+        if (empty($_POST['country'])) {
231 231
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
232 232
         }
233
-        if ( empty( $_POST['state'] ) ) {
233
+        if (empty($_POST['state'])) {
234 234
             $_POST['state'] = $invoice->state;
235 235
         }
236 236
          
237
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
238
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
237
+        $invoice->country   = sanitize_text_field($_POST['country']);
238
+        $invoice->state     = sanitize_text_field($_POST['state']);
239 239
         
240
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
241
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
240
+        $invoice->set('country', sanitize_text_field($_POST['country']));
241
+        $invoice->set('state', sanitize_text_field($_POST['state']));
242 242
         
243 243
         $wpinv_ip_address_country = $invoice->country;
244 244
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
         
247 247
         $response                       = array();
248 248
         $response['success']            = true;
249
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
249
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
250 250
         $response['data']['subtotal']   = $invoice->get_subtotal();
251 251
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
252 252
         $response['data']['tax']        = $invoice->get_tax();
@@ -258,41 +258,41 @@  discard block
 block discarded – undo
258 258
         
259 259
         wpinv_set_checkout_session($checkout_session);
260 260
         
261
-        wp_send_json( $response );
261
+        wp_send_json($response);
262 262
     }
263 263
 
264 264
 
265 265
     public static function remove_invoice_item() {
266 266
         global $wpi_userID, $wpinv_ip_address_country;
267 267
         
268
-        check_ajax_referer( 'invoice-item', '_nonce' );
269
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
268
+        check_ajax_referer('invoice-item', '_nonce');
269
+        if (!wpinv_current_user_can_manage_invoicing()) {
270 270
             die(-1);
271 271
         }
272 272
         
273
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
274
-        $invoice_id = absint( $_POST['invoice_id'] );
275
-        $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false;
273
+        $item_id    = sanitize_text_field($_POST['item_id']);
274
+        $invoice_id = absint($_POST['invoice_id']);
275
+        $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false;
276 276
         
277
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
277
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
278 278
             die();
279 279
         }
280 280
 
281
-        $invoice    = wpinv_get_invoice( $invoice_id );
282
-        if ( empty( $invoice ) ) {
281
+        $invoice = wpinv_get_invoice($invoice_id);
282
+        if (empty($invoice)) {
283 283
             die();
284 284
         }
285 285
         
286
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
286
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
287 287
             die(); // Don't allow modify items for paid invoice.
288 288
         }
289 289
         
290
-        if ( !empty( $_POST['user_id'] ) ) {
291
-            $wpi_userID = absint( $_POST['user_id'] ); 
290
+        if (!empty($_POST['user_id'])) {
291
+            $wpi_userID = absint($_POST['user_id']); 
292 292
         }
293 293
 
294
-        $item       = new WPInv_Item( $item_id );
295
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
294
+        $item = new WPInv_Item($item_id);
295
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
296 296
             die();
297 297
         }
298 298
         
@@ -300,9 +300,9 @@  discard block
 block discarded – undo
300 300
         
301 301
         $data                   = array();
302 302
         $data['invoice_id']     = $invoice_id;
303
-        $data['cart_discounts'] = $invoice->get_discounts( true );
303
+        $data['cart_discounts'] = $invoice->get_discounts(true);
304 304
         
305
-        wpinv_set_checkout_session( $data );
305
+        wpinv_set_checkout_session($data);
306 306
 
307 307
         $args = array(
308 308
             'id'         => $item_id,
@@ -310,21 +310,21 @@  discard block
 block discarded – undo
310 310
             'cart_index' => $cart_index
311 311
         );
312 312
 
313
-        $invoice->remove_item( $item_id, $args );
313
+        $invoice->remove_item($item_id, $args);
314 314
         $invoice->save();
315 315
         
316
-        if ( empty( $_POST['country'] ) ) {
316
+        if (empty($_POST['country'])) {
317 317
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
318 318
         }
319
-        if ( empty( $_POST['state'] ) ) {
319
+        if (empty($_POST['state'])) {
320 320
             $_POST['state'] = $invoice->state;
321 321
         }
322 322
          
323
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
324
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
323
+        $invoice->country   = sanitize_text_field($_POST['country']);
324
+        $invoice->state     = sanitize_text_field($_POST['state']);
325 325
         
326
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
327
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
326
+        $invoice->set('country', sanitize_text_field($_POST['country']));
327
+        $invoice->set('state', sanitize_text_field($_POST['state']));
328 328
         
329 329
         $wpinv_ip_address_country = $invoice->country;
330 330
         
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
         
333 333
         $response                       = array();
334 334
         $response['success']            = true;
335
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
335
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
336 336
         $response['data']['subtotal']   = $invoice->get_subtotal();
337 337
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
338 338
         $response['data']['tax']        = $invoice->get_tax();
@@ -344,55 +344,55 @@  discard block
 block discarded – undo
344 344
         
345 345
         wpinv_set_checkout_session($checkout_session);
346 346
         
347
-        wp_send_json( $response );
347
+        wp_send_json($response);
348 348
     }
349 349
     
350 350
     public static function create_invoice_item() {
351
-        check_ajax_referer( 'invoice-item', '_nonce' );
352
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
351
+        check_ajax_referer('invoice-item', '_nonce');
352
+        if (!wpinv_current_user_can_manage_invoicing()) {
353 353
             die(-1);
354 354
         }
355 355
         
356
-        $invoice_id = absint( $_POST['invoice_id'] );
356
+        $invoice_id = absint($_POST['invoice_id']);
357 357
 
358 358
         // Find the item
359
-        if ( !is_numeric( $invoice_id ) ) {
359
+        if (!is_numeric($invoice_id)) {
360 360
             die();
361 361
         }        
362 362
         
363
-        $invoice     = wpinv_get_invoice( $invoice_id );
364
-        if ( empty( $invoice ) ) {
363
+        $invoice = wpinv_get_invoice($invoice_id);
364
+        if (empty($invoice)) {
365 365
             die();
366 366
         }
367 367
         
368 368
         // Validate item before adding to invoice because recurring item must be paid individually.
369
-        if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) {
369
+        if (!empty($invoice->cart_details) && $invoice->get_recurring()) {
370 370
             $response               = array();
371 371
             $response['success']    = false;
372
-            $response['msg']        = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );
373
-            wp_send_json( $response );
372
+            $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing');
373
+            wp_send_json($response);
374 374
         }        
375 375
         
376
-        $save_item = wp_unslash( $_POST['_wpinv_quick'] );
376
+        $save_item = wp_unslash($_POST['_wpinv_quick']);
377 377
         
378 378
         $meta               = array();
379 379
         $meta['type']       = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom';
380
-        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0;
380
+        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0;
381 381
         $meta['vat_rule']   = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital';
382 382
         $meta['vat_class']  = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard';
383 383
         
384 384
         $data                   = array();
385 385
         $data['post_title']     = sanitize_text_field($save_item['name']);
386 386
         $data['post_status']    = 'publish';
387
-        $data['post_excerpt']   = ! empty( $save_item['excerpt'] ) ? wp_kses_post( $save_item['excerpt'] ) : '';
387
+        $data['post_excerpt']   = !empty($save_item['excerpt']) ? wp_kses_post($save_item['excerpt']) : '';
388 388
         $data['meta']           = $meta;
389 389
         
390 390
         $item = new WPInv_Item();
391
-        $item->create( $data );
391
+        $item->create($data);
392 392
         
393
-        if ( !empty( $item ) ) {
393
+        if (!empty($item)) {
394 394
             $_POST['item_id']   = $item->ID;
395
-            $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1;
395
+            $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int) $save_item['qty'] : 1;
396 396
             
397 397
             self::add_invoice_item();
398 398
         }
@@ -400,15 +400,15 @@  discard block
 block discarded – undo
400 400
     }
401 401
     
402 402
     public static function get_billing_details() {
403
-        check_ajax_referer( 'get-billing-details', '_nonce' );
403
+        check_ajax_referer('get-billing-details', '_nonce');
404 404
         
405
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
405
+        if (!wpinv_current_user_can_manage_invoicing()) {
406 406
             die(-1);
407 407
         }
408 408
 
409
-        $user_id            = (int)$_POST['user_id'];
409
+        $user_id            = (int) $_POST['user_id'];
410 410
         $billing_details    = wpinv_get_user_address($user_id);
411
-        $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
411
+        $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
412 412
         
413 413
         if (isset($billing_details['user_id'])) {
414 414
             unset($billing_details['user_id']);
@@ -422,20 +422,20 @@  discard block
 block discarded – undo
422 422
         $response['success']                    = true;
423 423
         $response['data']['billing_details']    = $billing_details;
424 424
         
425
-        wp_send_json( $response );
425
+        wp_send_json($response);
426 426
     }
427 427
     
428 428
     public static function admin_recalculate_totals() {
429 429
         global $wpi_userID, $wpinv_ip_address_country;
430 430
         
431
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
432
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
431
+        check_ajax_referer('wpinv-nonce', '_nonce');
432
+        if (!wpinv_current_user_can_manage_invoicing()) {
433 433
             die(-1);
434 434
         }
435 435
         
436
-        $invoice_id = absint( $_POST['invoice_id'] );        
437
-        $invoice    = wpinv_get_invoice( $invoice_id );
438
-        if ( empty( $invoice ) ) {
436
+        $invoice_id = absint($_POST['invoice_id']);        
437
+        $invoice    = wpinv_get_invoice($invoice_id);
438
+        if (empty($invoice)) {
439 439
             die();
440 440
         }
441 441
 
@@ -443,29 +443,29 @@  discard block
 block discarded – undo
443 443
 
444 444
         $data                   = array();
445 445
         $data['invoice_id']     = $invoice_id;
446
-        $data['cart_discounts'] = $invoice->get_discounts( true );
446
+        $data['cart_discounts'] = $invoice->get_discounts(true);
447 447
 
448
-        wpinv_set_checkout_session( $data );
448
+        wpinv_set_checkout_session($data);
449 449
         
450
-        if ( !empty( $_POST['user_id'] ) ) {
451
-            $wpi_userID = absint( $_POST['user_id'] ); 
450
+        if (!empty($_POST['user_id'])) {
451
+            $wpi_userID = absint($_POST['user_id']); 
452 452
         }
453 453
         
454
-        if ( empty( $_POST['country'] ) ) {
454
+        if (empty($_POST['country'])) {
455 455
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
456 456
         }
457 457
 
458 458
         $disable_taxes = 0;
459
-        if ( ! empty( $_POST['disable_taxes'] ) ) {
459
+        if (!empty($_POST['disable_taxes'])) {
460 460
             $disable_taxes = 1;
461 461
         }
462
-        $invoice->set( 'disable_taxes', $disable_taxes );
462
+        $invoice->set('disable_taxes', $disable_taxes);
463 463
 
464
-        $invoice->country = sanitize_text_field( $_POST['country'] );
465
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
466
-        if ( isset( $_POST['state'] ) ) {
467
-            $invoice->state = sanitize_text_field( $_POST['state'] );
468
-            $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
464
+        $invoice->country = sanitize_text_field($_POST['country']);
465
+        $invoice->set('country', sanitize_text_field($_POST['country']));
466
+        if (isset($_POST['state'])) {
467
+            $invoice->state = sanitize_text_field($_POST['state']);
468
+            $invoice->set('state', sanitize_text_field($_POST['state']));
469 469
         }
470 470
         
471 471
         $wpinv_ip_address_country = $invoice->country;
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
         
475 475
         $response                       = array();
476 476
         $response['success']            = true;
477
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
477
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
478 478
         $response['data']['subtotal']   = $invoice->get_subtotal();
479 479
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
480 480
         $response['data']['tax']        = $invoice->get_tax();
@@ -486,25 +486,25 @@  discard block
 block discarded – undo
486 486
         
487 487
         wpinv_set_checkout_session($checkout_session);
488 488
 
489
-        wp_send_json( $response );
489
+        wp_send_json($response);
490 490
     }
491 491
     
492 492
     public static function admin_apply_discount() {
493 493
         global $wpi_userID;
494 494
         
495
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
496
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
495
+        check_ajax_referer('wpinv-nonce', '_nonce');
496
+        if (!wpinv_current_user_can_manage_invoicing()) {
497 497
             die(-1);
498 498
         }
499 499
         
500
-        $invoice_id = absint( $_POST['invoice_id'] );
501
-        $discount_code = sanitize_text_field( $_POST['code'] );
502
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
500
+        $invoice_id = absint($_POST['invoice_id']);
501
+        $discount_code = sanitize_text_field($_POST['code']);
502
+        if (empty($invoice_id) || empty($discount_code)) {
503 503
             die();
504 504
         }
505 505
         
506
-        $invoice = wpinv_get_invoice( $invoice_id );
507
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
506
+        $invoice = wpinv_get_invoice($invoice_id);
507
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
508 508
             die();
509 509
         }
510 510
         
@@ -512,49 +512,49 @@  discard block
 block discarded – undo
512 512
         
513 513
         $data                   = array();
514 514
         $data['invoice_id']     = $invoice_id;
515
-        $data['cart_discounts'] = $invoice->get_discounts( true );
515
+        $data['cart_discounts'] = $invoice->get_discounts(true);
516 516
         
517
-        wpinv_set_checkout_session( $data );
517
+        wpinv_set_checkout_session($data);
518 518
         
519 519
         $response               = array();
520 520
         $response['success']    = false;
521
-        $response['msg']        = __( 'This discount is invalid.', 'invoicing' );
521
+        $response['msg']        = __('This discount is invalid.', 'invoicing');
522 522
         $response['data']['code'] = $discount_code;
523 523
         
524
-        if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) {
525
-            $discounts = wpinv_set_cart_discount( $discount_code );
524
+        if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) {
525
+            $discounts = wpinv_set_cart_discount($discount_code);
526 526
             
527 527
             $response['success'] = true;
528
-            $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' );
529
-        }  else {
528
+            $response['msg'] = __('Discount has been applied successfully.', 'invoicing');
529
+        } else {
530 530
             $errors = wpinv_get_errors();
531
-            if ( !empty( $errors['wpinv-discount-error'] ) ) {
531
+            if (!empty($errors['wpinv-discount-error'])) {
532 532
                 $response['msg'] = $errors['wpinv-discount-error'];
533 533
             }
534
-            wpinv_unset_error( 'wpinv-discount-error' );
534
+            wpinv_unset_error('wpinv-discount-error');
535 535
         }
536 536
         
537 537
         wpinv_set_checkout_session($checkout_session);
538 538
         
539
-        wp_send_json( $response );
539
+        wp_send_json($response);
540 540
     }
541 541
     
542 542
     public static function admin_remove_discount() {
543 543
         global $wpi_userID;
544 544
         
545
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
546
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
545
+        check_ajax_referer('wpinv-nonce', '_nonce');
546
+        if (!wpinv_current_user_can_manage_invoicing()) {
547 547
             die(-1);
548 548
         }
549 549
         
550
-        $invoice_id = absint( $_POST['invoice_id'] );
551
-        $discount_code = sanitize_text_field( $_POST['code'] );
552
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
550
+        $invoice_id = absint($_POST['invoice_id']);
551
+        $discount_code = sanitize_text_field($_POST['code']);
552
+        if (empty($invoice_id) || empty($discount_code)) {
553 553
             die();
554 554
         }
555 555
         
556
-        $invoice = wpinv_get_invoice( $invoice_id );
557
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
556
+        $invoice = wpinv_get_invoice($invoice_id);
557
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
558 558
             die();
559 559
         }
560 560
         
@@ -562,38 +562,38 @@  discard block
 block discarded – undo
562 562
         
563 563
         $data                   = array();
564 564
         $data['invoice_id']     = $invoice_id;
565
-        $data['cart_discounts'] = $invoice->get_discounts( true );
565
+        $data['cart_discounts'] = $invoice->get_discounts(true);
566 566
         
567
-        wpinv_set_checkout_session( $data );
567
+        wpinv_set_checkout_session($data);
568 568
         
569 569
         $response               = array();
570 570
         $response['success']    = false;
571 571
         $response['msg']        = NULL;
572 572
         
573
-        $discounts  = wpinv_unset_cart_discount( $discount_code );
573
+        $discounts = wpinv_unset_cart_discount($discount_code);
574 574
         $response['success'] = true;
575
-        $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' );
575
+        $response['msg'] = __('Discount has been removed successfully.', 'invoicing');
576 576
         
577 577
         wpinv_set_checkout_session($checkout_session);
578 578
         
579
-        wp_send_json( $response );
579
+        wp_send_json($response);
580 580
     }
581 581
     
582 582
     public static function check_email() {
583
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
584
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
583
+        check_ajax_referer('wpinv-nonce', '_nonce');
584
+        if (!wpinv_current_user_can_manage_invoicing()) {
585 585
             die(-1);
586 586
         }
587 587
         
588
-        $email = sanitize_text_field( $_POST['email'] );
588
+        $email = sanitize_text_field($_POST['email']);
589 589
         
590 590
         $response = array();
591
-        if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) {
591
+        if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) {
592 592
             $user_id            = $user_data->ID;
593 593
             $user_login         = $user_data->user_login;
594 594
             $display_name       = $user_data->display_name ? $user_data->display_name : $user_login;
595 595
             $billing_details    = wpinv_get_user_address($user_id);
596
-            $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
596
+            $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
597 597
             
598 598
             if (isset($billing_details['user_id'])) {
599 599
                 unset($billing_details['user_id']);
@@ -609,54 +609,54 @@  discard block
 block discarded – undo
609 609
             $response['data']['billing_details']    = $billing_details;
610 610
         }
611 611
         
612
-        wp_send_json( $response );
612
+        wp_send_json($response);
613 613
     }
614 614
     
615 615
     public static function run_tool() {
616
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
617
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
616
+        check_ajax_referer('wpinv-nonce', '_nonce');
617
+        if (!wpinv_current_user_can_manage_invoicing()) {
618 618
             die(-1);
619 619
         }
620 620
         
621
-        $tool = sanitize_text_field( $_POST['tool'] );
621
+        $tool = sanitize_text_field($_POST['tool']);
622 622
         
623
-        do_action( 'wpinv_run_tool' );
623
+        do_action('wpinv_run_tool');
624 624
         
625
-        if ( !empty( $tool ) ) {
626
-            do_action( 'wpinv_tool_' . $tool );
625
+        if (!empty($tool)) {
626
+            do_action('wpinv_tool_' . $tool);
627 627
         }
628 628
     }
629 629
     
630 630
     public static function apply_discount() {
631 631
         global $wpi_userID;
632 632
         
633
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
633
+        check_ajax_referer('wpinv-nonce', '_nonce');
634 634
         
635 635
         $response = array();
636 636
         
637
-        if ( isset( $_POST['code'] ) ) {
638
-            $discount_code = sanitize_text_field( $_POST['code'] );
637
+        if (isset($_POST['code'])) {
638
+            $discount_code = sanitize_text_field($_POST['code']);
639 639
 
640 640
             $response['success']        = false;
641 641
             $response['msg']            = '';
642 642
             $response['data']['code']   = $discount_code;
643 643
             
644 644
             $invoice = wpinv_get_invoice_cart();
645
-            if ( empty( $invoice->ID ) ) {
646
-                $response['msg'] = __( 'Invalid checkout request.', 'invoicing' );
647
-                wp_send_json( $response );
645
+            if (empty($invoice->ID)) {
646
+                $response['msg'] = __('Invalid checkout request.', 'invoicing');
647
+                wp_send_json($response);
648 648
             }
649 649
 
650 650
             $wpi_userID = $invoice->get_user_id();
651 651
 
652
-            if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) {
653
-                $discount       = wpinv_get_discount_by_code( $discount_code );
654
-                $discounts      = wpinv_set_cart_discount( $discount_code );
655
-                $amount         = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
656
-                $total          = wpinv_get_cart_total( null, $discounts );
657
-                $cart_totals    = wpinv_recalculate_tax( true );
652
+            if (wpinv_is_discount_valid($discount_code, $wpi_userID)) {
653
+                $discount       = wpinv_get_discount_by_code($discount_code);
654
+                $discounts      = wpinv_set_cart_discount($discount_code);
655
+                $amount         = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
656
+                $total          = wpinv_get_cart_total(null, $discounts);
657
+                $cart_totals    = wpinv_recalculate_tax(true);
658 658
             
659
-                if ( !empty( $cart_totals ) ) {
659
+                if (!empty($cart_totals)) {
660 660
                     $response['success']        = true;
661 661
                     $response['data']           = $cart_totals;
662 662
                     $response['data']['code']   = $discount_code;
@@ -665,29 +665,29 @@  discard block
 block discarded – undo
665 665
                 }
666 666
             } else {
667 667
                 $errors = wpinv_get_errors();
668
-                $response['msg']  = $errors['wpinv-discount-error'];
669
-                wpinv_unset_error( 'wpinv-discount-error' );
668
+                $response['msg'] = $errors['wpinv-discount-error'];
669
+                wpinv_unset_error('wpinv-discount-error');
670 670
             }
671 671
 
672 672
             // Allow for custom discount code handling
673
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
673
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
674 674
         }
675 675
         
676
-        wp_send_json( $response );
676
+        wp_send_json($response);
677 677
     }
678 678
     
679 679
     public static function remove_discount() {
680
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
680
+        check_ajax_referer('wpinv-nonce', '_nonce');
681 681
         
682 682
         $response = array();
683 683
         
684
-        if ( isset( $_POST['code'] ) ) {
685
-            $discount_code  = sanitize_text_field( $_POST['code'] );
686
-            $discounts      = wpinv_unset_cart_discount( $discount_code );
687
-            $total          = wpinv_get_cart_total( null, $discounts );
688
-            $cart_totals    = wpinv_recalculate_tax( true );
684
+        if (isset($_POST['code'])) {
685
+            $discount_code  = sanitize_text_field($_POST['code']);
686
+            $discounts      = wpinv_unset_cart_discount($discount_code);
687
+            $total          = wpinv_get_cart_total(null, $discounts);
688
+            $cart_totals    = wpinv_recalculate_tax(true);
689 689
             
690
-            if ( !empty( $cart_totals ) ) {
690
+            if (!empty($cart_totals)) {
691 691
                 $response['success']        = true;
692 692
                 $response['data']           = $cart_totals;
693 693
                 $response['data']['code']   = $discount_code;
@@ -696,10 +696,10 @@  discard block
 block discarded – undo
696 696
             }
697 697
             
698 698
             // Allow for custom discount code handling
699
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
699
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
700 700
         }
701 701
         
702
-        wp_send_json( $response );
702
+        wp_send_json($response);
703 703
     }
704 704
 
705 705
     /**
@@ -708,30 +708,30 @@  discard block
 block discarded – undo
708 708
     public static function get_payment_form() {
709 709
 
710 710
         // Check nonce.
711
-        if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], 'getpaid_ajax_form' ) ) {
712
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
711
+        if (!isset($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], 'getpaid_ajax_form')) {
712
+            _e('Error: Reload the page and try again.', 'invoicing');
713 713
             exit;
714 714
         }
715 715
 
716 716
         // Is the request set up correctly?
717
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
717
+		if (empty($_GET['form']) && empty($_GET['item'])) {
718 718
 			echo aui()->alert(
719 719
 				array(
720 720
 					'type'    => 'warning',
721
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
721
+					'content' => __('No payment form or item provided', 'invoicing'),
722 722
 				)
723 723
             );
724 724
             exit;
725 725
         }
726 726
 
727 727
         // Payment form or button?
728
-		if ( ! empty( $_GET['form'] ) ) {
729
-            echo getpaid_display_payment_form( $_GET['form'] );
730
-		} else if( $_GET['invoice'] ) {
731
-		    echo getpaid_display_invoice_payment_form( $_GET['invoice'] );
728
+		if (!empty($_GET['form'])) {
729
+            echo getpaid_display_payment_form($_GET['form']);
730
+		} else if ($_GET['invoice']) {
731
+		    echo getpaid_display_invoice_payment_form($_GET['invoice']);
732 732
         } else {
733
-			$items = getpaid_convert_items_to_array( $_GET['item'] );
734
-		    echo getpaid_display_item_payment_form( $items );
733
+			$items = getpaid_convert_items_to_array($_GET['item']);
734
+		    echo getpaid_display_item_payment_form($items);
735 735
         }
736 736
         
737 737
         exit;
@@ -747,53 +747,53 @@  discard block
 block discarded – undo
747 747
         global $invoicing, $wpi_checkout_id, $cart_total;
748 748
 
749 749
         // Check nonce.
750
-        if ( ! isset( $_POST['wpinv_payment_form'] ) || ! wp_verify_nonce( $_POST['wpinv_payment_form'], 'wpinv_payment_form' ) ) {
751
-            wp_send_json_error( __( 'Security checks failed.', 'invoicing' ) );
750
+        if (!isset($_POST['wpinv_payment_form']) || !wp_verify_nonce($_POST['wpinv_payment_form'], 'wpinv_payment_form')) {
751
+            wp_send_json_error(__('Security checks failed.', 'invoicing'));
752 752
         }
753 753
 
754 754
         // Prepare submitted data...
755
-        $data = wp_unslash( $_POST );
755
+        $data = wp_unslash($_POST);
756 756
 
757 757
         // ... form fields...
758
-        if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) {
759
-            wp_send_json_error( __( 'This payment form is no longer active.', 'invoicing' ) );
758
+        if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) {
759
+            wp_send_json_error(__('This payment form is no longer active.', 'invoicing'));
760 760
         }
761 761
 
762
-        if ( empty( $data['billing_email'] ) || ! is_email( $data['billing_email'] ) ) {
763
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
762
+        if (empty($data['billing_email']) || !is_email($data['billing_email'])) {
763
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
764 764
         }
765 765
 
766 766
         $prepared = array(
767
-            'billing_email'                    => sanitize_email( $data['billing_email'] ),
768
-            __( 'Billing Email', 'invoicing' ) => sanitize_email( $data['billing_email'] ),
769
-            __( 'Form Id', 'invoicing' )       => absint( $data['form_id'] ),
767
+            'billing_email'                    => sanitize_email($data['billing_email']),
768
+            __('Billing Email', 'invoicing') => sanitize_email($data['billing_email']),
769
+            __('Form Id', 'invoicing')       => absint($data['form_id']),
770 770
         );
771 771
 
772
-        $prepared['billing_email'] = sanitize_email( $data['billing_email'] );
772
+        $prepared['billing_email'] = sanitize_email($data['billing_email']);
773 773
 
774
-        $fields = $invoicing->form_elements->get_form_elements( $data['form_id'] );
774
+        $fields = $invoicing->form_elements->get_form_elements($data['form_id']);
775 775
 
776 776
         // ... and form items.
777
-        if ( ! empty( $data['invoice_id'] ) ) {
778
-            $invoice = wpinv_get_invoice( $data['invoice_id'] );
777
+        if (!empty($data['invoice_id'])) {
778
+            $invoice = wpinv_get_invoice($data['invoice_id']);
779 779
 
780
-            if ( empty( $invoice ) ) {
781
-                wp_send_json_error( __( 'Invalid invoice.', 'invoicing' ) );
780
+            if (empty($invoice)) {
781
+                wp_send_json_error(__('Invalid invoice.', 'invoicing'));
782 782
             }
783 783
 
784
-            if ( $invoice->is_paid() ) {
785
-                wp_send_json_error( __( 'This invoice has already been paid.', 'invoicing' ) );
784
+            if ($invoice->is_paid()) {
785
+                wp_send_json_error(__('This invoice has already been paid.', 'invoicing'));
786 786
             }
787 787
 
788
-            $items   = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice );
788
+            $items = $invoicing->form_elements->convert_checkout_items($invoice->cart_details, $invoice);
789 789
 
790 790
         } else {
791 791
 
792
-            if ( isset( $data['form_items'] ) ) {
793
-                $items = getpaid_convert_items_to_array( $data['form_items'] );
794
-                $items = $invoicing->form_elements->convert_normal_items( $items );
792
+            if (isset($data['form_items'])) {
793
+                $items = getpaid_convert_items_to_array($data['form_items']);
794
+                $items = $invoicing->form_elements->convert_normal_items($items);
795 795
             } else {
796
-                $items = $invoicing->form_elements->get_form_items( $data['form_id'] );
796
+                $items = $invoicing->form_elements->get_form_items($data['form_id']);
797 797
             }
798 798
 
799 799
             $invoice = 0;
@@ -802,44 +802,44 @@  discard block
 block discarded – undo
802 802
         $prepared_items = array();
803 803
         $address_fields = array();
804 804
 
805
-        if ( ! empty( $data['wpinv-items'] ) ) {
805
+        if (!empty($data['wpinv-items'])) {
806 806
 
807
-            $selected_items = wpinv_clean( $data['wpinv-items'] );
807
+            $selected_items = wpinv_clean($data['wpinv-items']);
808 808
 
809
-            foreach ( $items as $item ) {
809
+            foreach ($items as $item) {
810 810
 
811
-                if ( ! empty( $item['required'] ) && ! isset( $selected_items[ $item['id'] ] ) ) {
812
-                    wp_send_json_error( __( 'A required item is missing.', 'invoicing' ) );
811
+                if (!empty($item['required']) && !isset($selected_items[$item['id']])) {
812
+                    wp_send_json_error(__('A required item is missing.', 'invoicing'));
813 813
                 }
814 814
 
815
-                if ( ! isset( $selected_items[ $item['id'] ] ) ) {
815
+                if (!isset($selected_items[$item['id']])) {
816 816
                     continue;
817 817
                 }
818 818
 
819
-                $quantity = empty( $item['quantity'] ) ? 1 : absint( $item['quantity'] );
819
+                $quantity = empty($item['quantity']) ? 1 : absint($item['quantity']);
820 820
 
821
-                if ( ! empty( $item['allow_quantities'] ) && ! empty( $data["wpinv-item-{$item['id']}-quantity"] ) ) {
821
+                if (!empty($item['allow_quantities']) && !empty($data["wpinv-item-{$item['id']}-quantity"])) {
822 822
 
823
-                    $_quantity = intval( $data["wpinv-item-{$item['id']}-quantity"] );
823
+                    $_quantity = intval($data["wpinv-item-{$item['id']}-quantity"]);
824 824
 
825
-                    if ( ! empty( $_quantity ) ) {
825
+                    if (!empty($_quantity)) {
826 826
                         $quantity = $_quantity;
827 827
                     }
828 828
                 }
829 829
 
830 830
                 // Custom pricing.
831
-                if ( ! empty( $item['custom_price'] ) ) {
831
+                if (!empty($item['custom_price'])) {
832 832
 
833
-                    $minimum_price = wpinv_sanitize_amount( $item['minimum_price'] );
834
-                    $set_price     = wpinv_sanitize_amount( $selected_items[ $item['id'] ] );
833
+                    $minimum_price = wpinv_sanitize_amount($item['minimum_price']);
834
+                    $set_price     = wpinv_sanitize_amount($selected_items[$item['id']]);
835 835
 
836
-                    if ( $set_price < $minimum_price ) {
837
-                        wp_send_json_error( __( 'The provided amount is less than the minimum allowed value.', 'invoicing' ) );
836
+                    if ($set_price < $minimum_price) {
837
+                        wp_send_json_error(__('The provided amount is less than the minimum allowed value.', 'invoicing'));
838 838
                     }
839 839
 
840 840
                     $prepared_items[] = array(
841 841
                         'id'           =>$item['id'],
842
-                        'item_price'   => wpinv_sanitize_amount( $item['price'] ),
842
+                        'item_price'   => wpinv_sanitize_amount($item['price']),
843 843
                         'custom_price' => $set_price,
844 844
                         'name'         => $item['title'],
845 845
                         'quantity'     => $quantity,
@@ -849,8 +849,8 @@  discard block
 block discarded – undo
849 849
 
850 850
                     $prepared_items[] = array(
851 851
                         'id'           => $item['id'],
852
-                        'item_price'   => wpinv_sanitize_amount( $item['price'] ),
853
-                        'custom_price' => wpinv_sanitize_amount( $item['price'] ),
852
+                        'item_price'   => wpinv_sanitize_amount($item['price']),
853
+                        'custom_price' => wpinv_sanitize_amount($item['price']),
854 854
                         'name'         => $item['title'],
855 855
                         'quantity'     => $quantity,
856 856
                     );
@@ -861,68 +861,68 @@  discard block
 block discarded – undo
861 861
 
862 862
         } else {
863 863
 
864
-            wp_send_json_error( __( 'You have not selected any items.', 'invoicing' ) );
864
+            wp_send_json_error(__('You have not selected any items.', 'invoicing'));
865 865
 
866 866
         }
867 867
 
868 868
         // Are all required fields provided?
869
-        foreach ( $fields as $field ) {
869
+        foreach ($fields as $field) {
870 870
 
871
-            if ( ! empty( $field['premade'] ) ) {
871
+            if (!empty($field['premade'])) {
872 872
                 continue;
873 873
             }
874 874
 
875
-            if ( ! empty( $field['required'] ) && empty( $data[ $field['id'] ] ) ) {
876
-                wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) );
875
+            if (!empty($field['required']) && empty($data[$field['id']])) {
876
+                wp_send_json_error(__('Some required fields have not been filled.', 'invoicing'));
877 877
             }
878 878
 
879
-            if ( $field['type'] == 'address' ) {
879
+            if ($field['type'] == 'address') {
880 880
 
881
-                foreach ( $field['fields'] as $address_field ) {
881
+                foreach ($field['fields'] as $address_field) {
882 882
 
883
-                    if ( empty( $address_field['visible'] ) ) {
883
+                    if (empty($address_field['visible'])) {
884 884
                         continue;
885 885
                     }
886 886
 
887
-                    if ( ! empty( $address_field['required'] ) && empty( $data[ $address_field['name'] ] ) ) {
888
-                        wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) );
887
+                    if (!empty($address_field['required']) && empty($data[$address_field['name']])) {
888
+                        wp_send_json_error(__('Some required fields have not been filled.', 'invoicing'));
889 889
                     }
890 890
 
891
-                    if ( isset( $data[ $address_field['name'] ] ) ) {
892
-                        $label = str_replace( 'wpinv_', '', $address_field['name'] );
893
-                        $address_fields[ $label ] = wpinv_clean( $data[ $address_field['name'] ] );
891
+                    if (isset($data[$address_field['name']])) {
892
+                        $label = str_replace('wpinv_', '', $address_field['name']);
893
+                        $address_fields[$label] = wpinv_clean($data[$address_field['name']]);
894 894
                     }
895 895
 
896 896
                 }
897 897
 
898
-            } else if ( isset( $data[ $field['id'] ] ) ) {
898
+            } else if (isset($data[$field['id']])) {
899 899
                 $label = $field['id'];
900 900
 
901
-                if ( isset( $field['label'] ) ) {
901
+                if (isset($field['label'])) {
902 902
                     $label = $field['label'];
903 903
                 }
904 904
 
905
-                $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] );
905
+                $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]);
906 906
             }
907 907
 
908 908
         }
909 909
 
910
-        $user = get_user_by( 'email', $prepared['billing_email'] );
910
+        $user = get_user_by('email', $prepared['billing_email']);
911 911
 
912
-        if ( empty( $user ) ) {
913
-            $user = wpinv_create_user( $prepared['billing_email'] );
912
+        if (empty($user)) {
913
+            $user = wpinv_create_user($prepared['billing_email']);
914 914
         }
915 915
 
916
-        if ( is_wp_error( $user ) ) {
917
-            wp_send_json_error( $user->get_error_message() );
916
+        if (is_wp_error($user)) {
917
+            wp_send_json_error($user->get_error_message());
918 918
         }
919 919
 
920
-        if ( is_numeric( $user ) ) {
921
-            $user = get_user_by( 'id', $user );
920
+        if (is_numeric($user)) {
921
+            $user = get_user_by('id', $user);
922 922
         }
923 923
 
924 924
         // Create the invoice.
925
-        if ( empty( $invoice ) ) {
925
+        if (empty($invoice)) {
926 926
 
927 927
             $invoice = wpinv_insert_invoice(
928 928
                 array(
@@ -950,34 +950,34 @@  discard block
 block discarded – undo
950 950
         }
951 951
         
952 952
 
953
-        if ( is_wp_error( $invoice ) ) {
954
-            wp_send_json_error( $invoice->get_error_message() );
953
+        if (is_wp_error($invoice)) {
954
+            wp_send_json_error($invoice->get_error_message());
955 955
         }
956 956
 
957
-        if ( empty( $invoice ) ) {
958
-            wp_send_json_error( __( 'Could not create your invoice.', 'invoicing' ) );
957
+        if (empty($invoice)) {
958
+            wp_send_json_error(__('Could not create your invoice.', 'invoicing'));
959 959
         }
960 960
 
961
-        unset( $prepared['billing_email'] );
962
-        update_post_meta( $invoice->ID, 'payment_form_data', $prepared );
961
+        unset($prepared['billing_email']);
962
+        update_post_meta($invoice->ID, 'payment_form_data', $prepared);
963 963
 
964 964
         $wpi_checkout_id = $invoice->ID;
965 965
         $cart_total = wpinv_price(
966 966
             wpinv_format_amount(
967
-                wpinv_get_cart_total( $invoice->get_cart_details(), NULL, $invoice ) ),
967
+                wpinv_get_cart_total($invoice->get_cart_details(), NULL, $invoice) ),
968 968
                 $invoice->get_currency()
969 969
         );
970 970
 
971 971
         $data                   = array();
972 972
         $data['invoice_id']     = $invoice->ID;
973
-        $data['cart_discounts'] = $invoice->get_discounts( true );
973
+        $data['cart_discounts'] = $invoice->get_discounts(true);
974 974
 
975
-        wpinv_set_checkout_session( $data );
976
-        add_filter( 'wp_redirect', array( $invoicing->form_elements, 'send_redirect_response' ) );
977
-        add_action( 'wpinv_pre_send_back_to_checkout', array( $invoicing->form_elements, 'checkout_error' ) );
975
+        wpinv_set_checkout_session($data);
976
+        add_filter('wp_redirect', array($invoicing->form_elements, 'send_redirect_response'));
977
+        add_action('wpinv_pre_send_back_to_checkout', array($invoicing->form_elements, 'checkout_error'));
978 978
         
979
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
980
-            define( 'WPINV_CHECKOUT', true );
979
+        if (!defined('WPINV_CHECKOUT')) {
980
+            define('WPINV_CHECKOUT', true);
981 981
         }
982 982
 
983 983
         wpinv_process_checkout();
@@ -995,51 +995,51 @@  discard block
 block discarded – undo
995 995
     public static function get_payment_form_states_field() {
996 996
         global $invoicing;
997 997
 
998
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
998
+        if (empty($_GET['country']) || empty($_GET['form'])) {
999 999
             exit;
1000 1000
         }
1001 1001
 
1002
-        $elements = $invoicing->form_elements->get_form_elements( $_GET['form'] );
1002
+        $elements = $invoicing->form_elements->get_form_elements($_GET['form']);
1003 1003
 
1004
-        if ( empty( $elements ) ) {
1004
+        if (empty($elements)) {
1005 1005
             exit;
1006 1006
         }
1007 1007
 
1008 1008
         $address_fields = array();
1009
-        foreach ( $elements as $element ) {
1010
-            if ( 'address' === $element['type'] ) {
1009
+        foreach ($elements as $element) {
1010
+            if ('address' === $element['type']) {
1011 1011
                 $address_fields = $element;
1012 1012
                 break;
1013 1013
             }
1014 1014
         }
1015 1015
 
1016
-        if ( empty( $address_fields ) ) {
1016
+        if (empty($address_fields)) {
1017 1017
             exit;
1018 1018
         }
1019 1019
 
1020
-        foreach( $address_fields['fields'] as $address_field ) {
1020
+        foreach ($address_fields['fields'] as $address_field) {
1021 1021
 
1022
-            if ( 'wpinv_state' == $address_field['name'] ) {
1022
+            if ('wpinv_state' == $address_field['name']) {
1023 1023
 
1024 1024
                 $label = $address_field['label'];
1025 1025
 
1026
-                if ( ! empty( $address_field['required'] ) ) {
1026
+                if (!empty($address_field['required'])) {
1027 1027
                     $label .= "<span class='text-danger'> *</span>";
1028 1028
                 }
1029 1029
 
1030
-                $states = wpinv_get_country_states( $_GET['country'] );
1030
+                $states = wpinv_get_country_states($_GET['country']);
1031 1031
 
1032
-                if ( ! empty( $states ) ) {
1032
+                if (!empty($states)) {
1033 1033
 
1034 1034
                     $html = aui()->select(
1035 1035
                             array(
1036 1036
                                 'options'          => $states,
1037
-                                'name'             => esc_attr( $address_field['name'] ),
1038
-                                'id'               => esc_attr( $address_field['name'] ),
1039
-                                'placeholder'      => esc_attr( $address_field['placeholder'] ),
1037
+                                'name'             => esc_attr($address_field['name']),
1038
+                                'id'               => esc_attr($address_field['name']),
1039
+                                'placeholder'      => esc_attr($address_field['placeholder']),
1040 1040
                                 'required'         => (bool) $address_field['required'],
1041 1041
                                 'no_wrap'          => true,
1042
-                                'label'            => wp_kses_post( $label ),
1042
+                                'label'            => wp_kses_post($label),
1043 1043
                                 'select2'          => false,
1044 1044
                             )
1045 1045
                         );
@@ -1048,10 +1048,10 @@  discard block
 block discarded – undo
1048 1048
 
1049 1049
                     $html = aui()->input(
1050 1050
                             array(
1051
-                                'name'       => esc_attr( $address_field['name'] ),
1052
-                                'id'         => esc_attr( $address_field['name'] ),
1051
+                                'name'       => esc_attr($address_field['name']),
1052
+                                'id'         => esc_attr($address_field['name']),
1053 1053
                                 'required'   => (bool) $address_field['required'],
1054
-                                'label'      => wp_kses_post( $label ),
1054
+                                'label'      => wp_kses_post($label),
1055 1055
                                 'no_wrap'    => true,
1056 1056
                                 'type'       => 'text',
1057 1057
                             )
@@ -1059,7 +1059,7 @@  discard block
 block discarded – undo
1059 1059
 
1060 1060
                 }
1061 1061
 
1062
-                wp_send_json_success( str_replace( 'sr-only', '', $html ) );
1062
+                wp_send_json_success(str_replace('sr-only', '', $html));
1063 1063
                 exit;
1064 1064
 
1065 1065
             }
@@ -1078,35 +1078,35 @@  discard block
 block discarded – undo
1078 1078
         global $invoicing;
1079 1079
 
1080 1080
         // Check nonce.
1081
-        check_ajax_referer( 'wpinv_payment_form', 'wpinv_payment_form' );
1081
+        check_ajax_referer('wpinv_payment_form', 'wpinv_payment_form');
1082 1082
 
1083 1083
         // Prepare submitted data...
1084
-        $data = wp_unslash( $_POST );
1084
+        $data = wp_unslash($_POST);
1085 1085
 
1086 1086
         // ... form fields...
1087
-        if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) {
1087
+        if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) {
1088 1088
             exit;
1089 1089
         }
1090 1090
 
1091 1091
         // For existing invoices.
1092
-        if ( ! empty( $data['invoice_id'] ) ) {
1093
-            $invoice = wpinv_get_invoice( $data['invoice_id'] );
1092
+        if (!empty($data['invoice_id'])) {
1093
+            $invoice = wpinv_get_invoice($data['invoice_id']);
1094 1094
 
1095
-            if ( empty( $invoice ) ) {
1095
+            if (empty($invoice)) {
1096 1096
                 exit;
1097 1097
             }
1098 1098
 
1099
-            $items   = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice );
1099
+            $items   = $invoicing->form_elements->convert_checkout_items($invoice->cart_details, $invoice);
1100 1100
             $country = $invoice->country;
1101 1101
             $state   = $invoice->state;
1102 1102
 
1103 1103
         } else {
1104 1104
 
1105
-            if ( isset( $data['form_items'] ) ) {
1106
-                $items = getpaid_convert_items_to_array( $data['form_items'] );
1107
-                $items = $invoicing->form_elements->convert_normal_items( $items );
1105
+            if (isset($data['form_items'])) {
1106
+                $items = getpaid_convert_items_to_array($data['form_items']);
1107
+                $items = $invoicing->form_elements->convert_normal_items($items);
1108 1108
             } else {
1109
-                $items = $invoicing->form_elements->get_form_items( $data['form_id'] );
1109
+                $items = $invoicing->form_elements->get_form_items($data['form_id']);
1110 1110
             }
1111 1111
 
1112 1112
             $country   = wpinv_default_billing_country();
@@ -1118,59 +1118,59 @@  discard block
 block discarded – undo
1118 1118
         $tax       = 0;
1119 1119
         $sub_total = 0;
1120 1120
 
1121
-        if ( ! empty( $data['wpinv_country'] ) ) {
1121
+        if (!empty($data['wpinv_country'])) {
1122 1122
             $country = $data['wpinv_country'];
1123 1123
         }
1124 1124
 
1125
-        if ( ! empty( $data['wpinv_state'] ) ) {
1125
+        if (!empty($data['wpinv_state'])) {
1126 1126
             $state = $data['wpinv_state'];
1127 1127
         }
1128 1128
 
1129
-        if ( ! empty( $data['wpinv-items'] ) ) {
1129
+        if (!empty($data['wpinv-items'])) {
1130 1130
 
1131
-            $selected_items = wpinv_clean( $data['wpinv-items'] );
1131
+            $selected_items = wpinv_clean($data['wpinv-items']);
1132 1132
 
1133
-            foreach ( $items as $item ) {
1133
+            foreach ($items as $item) {
1134 1134
 
1135
-                if ( ! isset( $selected_items[ $item['id'] ] ) ) {
1135
+                if (!isset($selected_items[$item['id']])) {
1136 1136
                     continue;
1137 1137
                 }
1138 1138
 
1139
-                $quantity = empty( $item['quantity'] ) ? 1 : absint( $item['quantity'] );
1139
+                $quantity = empty($item['quantity']) ? 1 : absint($item['quantity']);
1140 1140
 
1141
-                if ( ! empty( $item['allow_quantities'] ) && ! empty( $data["wpinv-item-{$item['id']}-quantity"] ) ) {
1141
+                if (!empty($item['allow_quantities']) && !empty($data["wpinv-item-{$item['id']}-quantity"])) {
1142 1142
 
1143
-                    $quantity = intval( $data["wpinv-item-{$item['id']}-quantity"] );
1143
+                    $quantity = intval($data["wpinv-item-{$item['id']}-quantity"]);
1144 1144
 
1145
-                    if ( 1 > $quantity ) {
1145
+                    if (1 > $quantity) {
1146 1146
                         $quantity = 1;
1147 1147
                     }
1148 1148
 
1149 1149
                 }
1150 1150
 
1151 1151
                 // Custom pricing.
1152
-                $price = wpinv_sanitize_amount( $item['price'] );
1153
-                if ( ! empty( $item['custom_price'] ) ) {
1152
+                $price = wpinv_sanitize_amount($item['price']);
1153
+                if (!empty($item['custom_price'])) {
1154 1154
 
1155
-                    $minimum_price = wpinv_sanitize_amount( $item['minimum_price'] );
1156
-                    $set_price     = wpinv_sanitize_amount( $selected_items[ $item['id'] ] );
1155
+                    $minimum_price = wpinv_sanitize_amount($item['minimum_price']);
1156
+                    $set_price     = wpinv_sanitize_amount($selected_items[$item['id']]);
1157 1157
 
1158
-                    if ( $set_price < $minimum_price ) {
1158
+                    if ($set_price < $minimum_price) {
1159 1159
                         $set_price = $minimum_price;
1160 1160
                     }
1161 1161
 
1162
-                    $price = wpinv_sanitize_amount( $set_price );
1162
+                    $price = wpinv_sanitize_amount($set_price);
1163 1163
 
1164 1164
                 }
1165 1165
 
1166
-                $price  = $quantity * floatval( $price );
1166
+                $price = $quantity * floatval($price);
1167 1167
 
1168
-                if ( wpinv_use_taxes() ) {
1168
+                if (wpinv_use_taxes()) {
1169 1169
 
1170
-                    $rate = wpinv_get_tax_rate( $country, $state, (int) $item['id'] );
1170
+                    $rate = wpinv_get_tax_rate($country, $state, (int) $item['id']);
1171 1171
 
1172
-                    if ( wpinv_prices_include_tax() ) {
1173
-                        $pre_tax  = ( $price - $price * $rate * 0.01 );
1172
+                    if (wpinv_prices_include_tax()) {
1173
+                        $pre_tax  = ($price - $price * $rate * 0.01);
1174 1174
                         $item_tax = $price - $pre_tax;
1175 1175
                     } else {
1176 1176
                         $pre_tax  = $price;
@@ -1182,17 +1182,17 @@  discard block
 block discarded – undo
1182 1182
                     $total     = $sub_total + $tax;
1183 1183
 
1184 1184
                 } else {
1185
-                    $total  = $total + $price;
1185
+                    $total = $total + $price;
1186 1186
                 }
1187 1187
 
1188 1188
             }
1189 1189
 
1190 1190
         }
1191 1191
 
1192
-        wp_send_json_success( array(
1193
-            'total'     => wpinv_price( wpinv_format_amount( $total ) ),
1194
-            'tax'       => wpinv_price( wpinv_format_amount( $tax ) ),
1195
-            'sub_total' => wpinv_price( wpinv_format_amount( $sub_total ) ),
1192
+        wp_send_json_success(array(
1193
+            'total'     => wpinv_price(wpinv_format_amount($total)),
1194
+            'tax'       => wpinv_price(wpinv_format_amount($tax)),
1195
+            'sub_total' => wpinv_price(wpinv_format_amount($sub_total)),
1196 1196
         ));
1197 1197
         exit;
1198 1198
     }
@@ -1205,53 +1205,53 @@  discard block
 block discarded – undo
1205 1205
     public static function buy_items() {
1206 1206
         $user_id = get_current_user_id();
1207 1207
 
1208
-        if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page
1209
-            wp_send_json( array(
1210
-                'success' => wp_login_url( wp_get_referer() )
1211
-            ) );
1208
+        if (empty($user_id)) { // If not logged in then lets redirect to the login page
1209
+            wp_send_json(array(
1210
+                'success' => wp_login_url(wp_get_referer())
1211
+            ));
1212 1212
         } else {
1213 1213
             // Only check nonce if logged in as it could be cached when logged out.
1214
-            if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) {
1215
-                wp_send_json( array(
1216
-                    'error' => __( 'Security checks failed.', 'invoicing' )
1217
-                ) );
1214
+            if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) {
1215
+                wp_send_json(array(
1216
+                    'error' => __('Security checks failed.', 'invoicing')
1217
+                ));
1218 1218
                 wp_die();
1219 1219
             }
1220 1220
 
1221 1221
             // allow to set a custom price through post_id
1222 1222
             $items = $_POST['items'];
1223
-            $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0;
1224
-            $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0;
1223
+            $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0;
1224
+            $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0;
1225 1225
 
1226 1226
             $cart_items = array();
1227
-            if ( $items ) {
1228
-                $items = explode( ',', $items );
1227
+            if ($items) {
1228
+                $items = explode(',', $items);
1229 1229
 
1230
-                foreach( $items as $item ) {
1230
+                foreach ($items as $item) {
1231 1231
                     $item_id = $item;
1232 1232
                     $quantity = 1;
1233 1233
 
1234
-                    if ( strpos( $item, '|' ) !== false ) {
1235
-                        $item_parts = explode( '|', $item );
1234
+                    if (strpos($item, '|') !== false) {
1235
+                        $item_parts = explode('|', $item);
1236 1236
                         $item_id = $item_parts[0];
1237 1237
                         $quantity = $item_parts[1];
1238 1238
                     }
1239 1239
 
1240
-                    if ( $item_id && $quantity ) {
1240
+                    if ($item_id && $quantity) {
1241 1241
                         $cart_items_arr = array(
1242
-                            'id'            => (int)$item_id,
1243
-                            'quantity'      => (int)$quantity
1242
+                            'id'            => (int) $item_id,
1243
+                            'quantity'      => (int) $quantity
1244 1244
                         );
1245 1245
 
1246 1246
                         // If there is a related post id then add it to meta
1247
-                        if ( $related_post_id ) {
1247
+                        if ($related_post_id) {
1248 1248
                             $cart_items_arr['meta'] = array(
1249 1249
                                 'post_id'   => $related_post_id
1250 1250
                             );
1251 1251
                         }
1252 1252
 
1253 1253
                         // If there is a custom price then set it.
1254
-                        if ( $custom_item_price ) {
1254
+                        if ($custom_item_price) {
1255 1255
                             $cart_items_arr['custom_price'] = $custom_item_price;
1256 1256
                         }
1257 1257
 
@@ -1267,37 +1267,37 @@  discard block
 block discarded – undo
1267 1267
              * @param int $related_post_id The related post id if any.
1268 1268
              * @since 1.0.0
1269 1269
              */
1270
-            $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id );
1270
+            $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id);
1271 1271
 
1272 1272
             // Make sure its not in the cart already, if it is then redirect to checkout.
1273 1273
             $cart_invoice = wpinv_get_invoice_cart();
1274 1274
 
1275
-            if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) {
1276
-                wp_send_json( array(
1275
+            if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) {
1276
+                wp_send_json(array(
1277 1277
                     'success' =>  $cart_invoice->get_checkout_payment_url()
1278
-                ) );
1278
+                ));
1279 1279
                 wp_die();
1280 1280
             }
1281 1281
 
1282 1282
             // Check if user has invoice with same items waiting to be paid.
1283
-            $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' );
1284
-            if ( !empty( $user_invoices ) ) {
1285
-                foreach( $user_invoices as $user_invoice ) {
1283
+            $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending');
1284
+            if (!empty($user_invoices)) {
1285
+                foreach ($user_invoices as $user_invoice) {
1286 1286
                     $user_cart_details = array();
1287
-                    $invoice  = wpinv_get_invoice( $user_invoice->ID );
1287
+                    $invoice = wpinv_get_invoice($user_invoice->ID);
1288 1288
                     $cart_details = $invoice->get_cart_details();
1289 1289
 
1290
-                    if ( !empty( $cart_details ) ) {
1291
-                        foreach ( $cart_details as $invoice_item ) {
1290
+                    if (!empty($cart_details)) {
1291
+                        foreach ($cart_details as $invoice_item) {
1292 1292
                             $ii_arr = array();
1293
-                            $ii_arr['id'] = (int)$invoice_item['id'];
1294
-                            $ii_arr['quantity'] = (int)$invoice_item['quantity'];
1293
+                            $ii_arr['id'] = (int) $invoice_item['id'];
1294
+                            $ii_arr['quantity'] = (int) $invoice_item['quantity'];
1295 1295
 
1296
-                            if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) {
1296
+                            if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) {
1297 1297
                                 $ii_arr['meta'] = $invoice_item['meta'];
1298 1298
                             }
1299 1299
 
1300
-                            if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) {
1300
+                            if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) {
1301 1301
                                 $ii_arr['custom_price'] = $invoice_item['custom_price'];
1302 1302
                             }
1303 1303
 
@@ -1305,17 +1305,17 @@  discard block
 block discarded – undo
1305 1305
                         }
1306 1306
                     }
1307 1307
 
1308
-                    if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) {
1309
-                        wp_send_json( array(
1308
+                    if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) {
1309
+                        wp_send_json(array(
1310 1310
                             'success' =>  $invoice->get_checkout_payment_url()
1311
-                        ) );
1311
+                        ));
1312 1312
                         wp_die();
1313 1313
                     }
1314 1314
                 }
1315 1315
             }
1316 1316
 
1317 1317
             // Create invoice and send user to checkout
1318
-            if ( !empty( $cart_items ) ) {
1318
+            if (!empty($cart_items)) {
1319 1319
                 $invoice_data = array(
1320 1320
                     'status'        =>  'wpi-pending',
1321 1321
                     'created_via'   =>  'wpi',
@@ -1323,21 +1323,21 @@  discard block
 block discarded – undo
1323 1323
                     'cart_details'  =>  $cart_items,
1324 1324
                 );
1325 1325
 
1326
-                $invoice = wpinv_insert_invoice( $invoice_data, true );
1326
+                $invoice = wpinv_insert_invoice($invoice_data, true);
1327 1327
 
1328
-                if ( !empty( $invoice ) && isset( $invoice->ID ) ) {
1329
-                    wp_send_json( array(
1328
+                if (!empty($invoice) && isset($invoice->ID)) {
1329
+                    wp_send_json(array(
1330 1330
                         'success' =>  $invoice->get_checkout_payment_url()
1331
-                    ) );
1331
+                    ));
1332 1332
                 } else {
1333
-                    wp_send_json( array(
1334
-                        'error' => __( 'Invoice failed to create', 'invoicing' )
1335
-                    ) );
1333
+                    wp_send_json(array(
1334
+                        'error' => __('Invoice failed to create', 'invoicing')
1335
+                    ));
1336 1336
                 }
1337 1337
             } else {
1338
-                wp_send_json( array(
1339
-                    'error' => __( 'Items not valid.', 'invoicing' )
1340
-                ) );
1338
+                wp_send_json(array(
1339
+                    'error' => __('Items not valid.', 'invoicing')
1340
+                ));
1341 1341
             }
1342 1342
         }
1343 1343
 
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 2 patches
Indentation   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -103,29 +103,29 @@  discard block
 block discarded – undo
103 103
 
104 104
 function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
105 105
     if ( ! empty( $args ) && is_array( $args ) ) {
106
-		extract( $args );
107
-	}
106
+        extract( $args );
107
+    }
108 108
 
109
-	$located = wpinv_locate_template( $template_name, $template_path, $default_path );
110
-	// Allow 3rd party plugin filter template file from their plugin.
111
-	$located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path );
109
+    $located = wpinv_locate_template( $template_name, $template_path, $default_path );
110
+    // Allow 3rd party plugin filter template file from their plugin.
111
+    $located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path );
112 112
 
113
-	if ( ! file_exists( $located ) ) {
113
+    if ( ! file_exists( $located ) ) {
114 114
         _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
115
-		return;
116
-	}
115
+        return;
116
+    }
117 117
 
118
-	do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
118
+    do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
119 119
 
120
-	include( $located );
120
+    include( $located );
121 121
 
122
-	do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
122
+    do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
123 123
 }
124 124
 
125 125
 function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
126
-	ob_start();
127
-	wpinv_get_template( $template_name, $args, $template_path, $default_path );
128
-	return ob_get_clean();
126
+    ob_start();
127
+    wpinv_get_template( $template_name, $args, $template_path, $default_path );
128
+    return ob_get_clean();
129 129
 }
130 130
 
131 131
 function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
@@ -155,126 +155,126 @@  discard block
 block discarded – undo
155 155
 }
156 156
 
157 157
 function wpinv_get_template_part( $slug, $name = null, $load = true ) {
158
-	do_action( 'get_template_part_' . $slug, $slug, $name );
158
+    do_action( 'get_template_part_' . $slug, $slug, $name );
159 159
 
160
-	// Setup possible parts
161
-	$templates = array();
162
-	if ( isset( $name ) )
163
-		$templates[] = $slug . '-' . $name . '.php';
164
-	$templates[] = $slug . '.php';
160
+    // Setup possible parts
161
+    $templates = array();
162
+    if ( isset( $name ) )
163
+        $templates[] = $slug . '-' . $name . '.php';
164
+    $templates[] = $slug . '.php';
165 165
 
166
-	// Allow template parts to be filtered
167
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
166
+    // Allow template parts to be filtered
167
+    $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
168 168
 
169
-	// Return the part that is found
170
-	return wpinv_locate_tmpl( $templates, $load, false );
169
+    // Return the part that is found
170
+    return wpinv_locate_tmpl( $templates, $load, false );
171 171
 }
172 172
 
173 173
 function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
174
-	// No file found yet
175
-	$located = false;
174
+    // No file found yet
175
+    $located = false;
176 176
 
177
-	// Try to find a template file
178
-	foreach ( (array)$template_names as $template_name ) {
177
+    // Try to find a template file
178
+    foreach ( (array)$template_names as $template_name ) {
179 179
 
180
-		// Continue if template is empty
181
-		if ( empty( $template_name ) )
182
-			continue;
180
+        // Continue if template is empty
181
+        if ( empty( $template_name ) )
182
+            continue;
183 183
 
184
-		// Trim off any slashes from the template name
185
-		$template_name = ltrim( $template_name, '/' );
184
+        // Trim off any slashes from the template name
185
+        $template_name = ltrim( $template_name, '/' );
186 186
 
187
-		// try locating this template file by looping through the template paths
188
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
187
+        // try locating this template file by looping through the template paths
188
+        foreach( wpinv_get_theme_template_paths() as $template_path ) {
189 189
 
190
-			if( file_exists( $template_path . $template_name ) ) {
191
-				$located = $template_path . $template_name;
192
-				break;
193
-			}
194
-		}
190
+            if( file_exists( $template_path . $template_name ) ) {
191
+                $located = $template_path . $template_name;
192
+                break;
193
+            }
194
+        }
195 195
 
196
-		if( !empty( $located ) ) {
197
-			break;
198
-		}
199
-	}
196
+        if( !empty( $located ) ) {
197
+            break;
198
+        }
199
+    }
200 200
 
201
-	if ( ( true == $load ) && ! empty( $located ) )
202
-		load_template( $located, $require_once );
201
+    if ( ( true == $load ) && ! empty( $located ) )
202
+        load_template( $located, $require_once );
203 203
 
204
-	return $located;
204
+    return $located;
205 205
 }
206 206
 
207 207
 function wpinv_get_theme_template_paths() {
208
-	$template_dir = wpinv_get_theme_template_dir_name();
208
+    $template_dir = wpinv_get_theme_template_dir_name();
209 209
 
210
-	$file_paths = array(
211
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
212
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
213
-		100 => wpinv_get_templates_dir()
214
-	);
210
+    $file_paths = array(
211
+        1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
212
+        10 => trailingslashit( get_template_directory() ) . $template_dir,
213
+        100 => wpinv_get_templates_dir()
214
+    );
215 215
 
216
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
216
+    $file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
217 217
 
218
-	// sort the file paths based on priority
219
-	ksort( $file_paths, SORT_NUMERIC );
218
+    // sort the file paths based on priority
219
+    ksort( $file_paths, SORT_NUMERIC );
220 220
 
221
-	return array_map( 'trailingslashit', $file_paths );
221
+    return array_map( 'trailingslashit', $file_paths );
222 222
 }
223 223
 
224 224
 function wpinv_get_theme_template_dir_name() {
225
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
225
+    return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
226 226
 }
227 227
 
228 228
 function wpinv_checkout_meta_tags() {
229 229
 
230
-	$pages   = array();
231
-	$pages[] = wpinv_get_option( 'success_page' );
232
-	$pages[] = wpinv_get_option( 'failure_page' );
233
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
234
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
230
+    $pages   = array();
231
+    $pages[] = wpinv_get_option( 'success_page' );
232
+    $pages[] = wpinv_get_option( 'failure_page' );
233
+    $pages[] = wpinv_get_option( 'invoice_history_page' );
234
+    $pages[] = wpinv_get_option( 'invoice_subscription_page' );
235 235
 
236
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
237
-		return;
238
-	}
236
+    if( !wpinv_is_checkout() && !is_page( $pages ) ) {
237
+        return;
238
+    }
239 239
 
240
-	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
240
+    echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
241 241
 }
242 242
 add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
243 243
 
244 244
 function wpinv_add_body_classes( $class ) {
245
-	$classes = (array)$class;
245
+    $classes = (array)$class;
246 246
 
247
-	if( wpinv_is_checkout() ) {
248
-		$classes[] = 'wpinv-checkout';
249
-		$classes[] = 'wpinv-page';
250
-	}
247
+    if( wpinv_is_checkout() ) {
248
+        $classes[] = 'wpinv-checkout';
249
+        $classes[] = 'wpinv-page';
250
+    }
251 251
 
252
-	if( wpinv_is_success_page() ) {
253
-		$classes[] = 'wpinv-success';
254
-		$classes[] = 'wpinv-page';
255
-	}
252
+    if( wpinv_is_success_page() ) {
253
+        $classes[] = 'wpinv-success';
254
+        $classes[] = 'wpinv-page';
255
+    }
256 256
 
257
-	if( wpinv_is_failed_transaction_page() ) {
258
-		$classes[] = 'wpinv-failed-transaction';
259
-		$classes[] = 'wpinv-page';
260
-	}
257
+    if( wpinv_is_failed_transaction_page() ) {
258
+        $classes[] = 'wpinv-failed-transaction';
259
+        $classes[] = 'wpinv-page';
260
+    }
261 261
 
262
-	if( wpinv_is_invoice_history_page() ) {
263
-		$classes[] = 'wpinv-history';
264
-		$classes[] = 'wpinv-page';
265
-	}
262
+    if( wpinv_is_invoice_history_page() ) {
263
+        $classes[] = 'wpinv-history';
264
+        $classes[] = 'wpinv-page';
265
+    }
266 266
 
267
-	if( wpinv_is_subscriptions_history_page() ) {
268
-		$classes[] = 'wpinv-subscription';
269
-		$classes[] = 'wpinv-page';
270
-	}
267
+    if( wpinv_is_subscriptions_history_page() ) {
268
+        $classes[] = 'wpinv-subscription';
269
+        $classes[] = 'wpinv-page';
270
+    }
271 271
 
272
-	if( wpinv_is_test_mode() ) {
273
-		$classes[] = 'wpinv-test-mode';
274
-		$classes[] = 'wpinv-page';
275
-	}
272
+    if( wpinv_is_test_mode() ) {
273
+        $classes[] = 'wpinv-test-mode';
274
+        $classes[] = 'wpinv-page';
275
+    }
276 276
 
277
-	return array_unique( $classes );
277
+    return array_unique( $classes );
278 278
 }
279 279
 add_filter( 'body_class', 'wpinv_add_body_classes' );
280 280
 
@@ -948,21 +948,21 @@  discard block
 block discarded – undo
948 948
 
949 949
     $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format );
950 950
     
951
-	// Remove unavailable tags.
951
+    // Remove unavailable tags.
952 952
     $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address );
953 953
 
954 954
     // Clean up white space.
955
-	$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
955
+    $formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
956 956
     $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
957 957
     
958 958
     // Break newlines apart and remove empty lines/trim commas and white space.
959
-	$formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
959
+    $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
960 960
 
961 961
     // Add html breaks.
962
-	$formatted_address = implode( $separator, $formatted_address );
962
+    $formatted_address = implode( $separator, $formatted_address );
963 963
 
964
-	// We're done!
965
-	return $formatted_address;
964
+    // We're done!
965
+    return $formatted_address;
966 966
     
967 967
 }
968 968
 
@@ -1049,7 +1049,7 @@  discard block
 block discarded – undo
1049 1049
 
1050 1050
                     $item       = $item_id ? new WPInv_Item( $item_id ) : NULL;
1051 1051
                     $summary    = '';
1052
-	                $item_name    = '';
1052
+                    $item_name    = '';
1053 1053
                     $cols       = 3;
1054 1054
                     if ( !empty($item) ) {
1055 1055
                         $item_name  = $item->get_name();
@@ -1406,13 +1406,13 @@  discard block
 block discarded – undo
1406 1406
     $payment_form    = wpinv_get_default_payment_form();
1407 1407
 
1408 1408
     ob_start();
1409
-	    do_action( 'wpinv_checkout_content_before' );
1409
+        do_action( 'wpinv_checkout_content_before' );
1410 1410
 
1411 1411
         if ( wpinv_get_cart_contents() ) {
1412 1412
 
1413 1413
             // Get the form elements and items.
1414
-	        $elements = $invoicing->form_elements->get_form_elements( $payment_form );
1415
-	        $items    = $invoicing->form_elements->convert_checkout_items( wpinv_get_cart_contents(), wpinv_get_invoice_cart() );
1414
+            $elements = $invoicing->form_elements->get_form_elements( $payment_form );
1415
+            $items    = $invoicing->form_elements->convert_checkout_items( wpinv_get_cart_contents(), wpinv_get_invoice_cart() );
1416 1416
             ?>
1417 1417
             <form class="wpinv_payment_form" action="<?php echo $form_action; ?>" method="POST">
1418 1418
                 <?php do_action( 'wpinv_main_checkout_form_top' ); ?>
@@ -1436,10 +1436,10 @@  discard block
 block discarded – undo
1436 1436
             do_action( 'wpinv_cart_empty' );
1437 1437
         }
1438 1438
         echo '</div><!--end #wpinv_checkout_wrap-->';
1439
-	    do_action( 'wpinv_checkout_content_after' );
1439
+        do_action( 'wpinv_checkout_content_after' );
1440 1440
         $content = ob_get_clean();
1441 1441
 
1442
-		return str_replace( 'sr-only', '', $content );
1442
+        return str_replace( 'sr-only', '', $content );
1443 1443
 }
1444 1444
 
1445 1445
 function wpinv_checkout_cart( $cart_details = array(), $echo = true ) {
@@ -1465,7 +1465,7 @@  discard block
 block discarded – undo
1465 1465
 add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 );
1466 1466
 
1467 1467
 function wpinv_empty_cart_message() {
1468
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1468
+    return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1469 1469
 }
1470 1470
 
1471 1471
 /**
@@ -2303,38 +2303,38 @@  discard block
 block discarded – undo
2303 2303
     global $invoicing;
2304 2304
 
2305 2305
     // Ensure that it is published.
2306
-	if ( 'publish' != get_post_status( $form ) ) {
2307
-		return aui()->alert(
2308
-			array(
2309
-				'type'    => 'warning',
2310
-				'content' => __( 'This payment form is no longer active', 'invoicing' ),
2311
-			)
2312
-		);
2313
-	}
2306
+    if ( 'publish' != get_post_status( $form ) ) {
2307
+        return aui()->alert(
2308
+            array(
2309
+                'type'    => 'warning',
2310
+                'content' => __( 'This payment form is no longer active', 'invoicing' ),
2311
+            )
2312
+        );
2313
+    }
2314 2314
 
2315 2315
     // Get the form elements and items.
2316 2316
     $form     = absint( $form );
2317
-	$elements = $invoicing->form_elements->get_form_elements( $form );
2318
-	$items    = $invoicing->form_elements->get_form_items( $form );
2317
+    $elements = $invoicing->form_elements->get_form_elements( $form );
2318
+    $items    = $invoicing->form_elements->get_form_items( $form );
2319 2319
 
2320
-	ob_start();
2321
-	echo "<form class='wpinv_payment_form'>";
2322
-	do_action( 'wpinv_payment_form_top' );
2323
-	echo "<input type='hidden' name='form_id' value='$form'/>";
2324
-	wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
2325
-	wp_nonce_field( 'vat_validation', '_wpi_nonce' );
2320
+    ob_start();
2321
+    echo "<form class='wpinv_payment_form'>";
2322
+    do_action( 'wpinv_payment_form_top' );
2323
+    echo "<input type='hidden' name='form_id' value='$form'/>";
2324
+    wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
2325
+    wp_nonce_field( 'vat_validation', '_wpi_nonce' );
2326 2326
 
2327
-	foreach ( $elements as $element ) {
2328
-		do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form );
2329
-		do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form );
2330
-	}
2327
+    foreach ( $elements as $element ) {
2328
+        do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form );
2329
+        do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form );
2330
+    }
2331 2331
 
2332
-	echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
2333
-	do_action( 'wpinv_payment_form_bottom' );
2334
-	echo '</form>';
2332
+    echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
2333
+    do_action( 'wpinv_payment_form_bottom' );
2334
+    echo '</form>';
2335 2335
 
2336
-	$content = ob_get_clean();
2337
-	return str_replace( 'sr-only', '', $content );
2336
+    $content = ob_get_clean();
2337
+    return str_replace( 'sr-only', '', $content );
2338 2338
 }
2339 2339
 
2340 2340
 /**
@@ -2344,46 +2344,46 @@  discard block
 block discarded – undo
2344 2344
     global $invoicing;
2345 2345
 
2346 2346
     foreach ( array_keys( $items ) as $id ) {
2347
-	    if ( 'publish' != get_post_status( $id ) ) {
2348
-		    unset( $items[ $id ] );
2349
-	    }
2347
+        if ( 'publish' != get_post_status( $id ) ) {
2348
+            unset( $items[ $id ] );
2349
+        }
2350 2350
     }
2351 2351
 
2352 2352
     if ( empty( $items ) ) {
2353
-		return aui()->alert(
2354
-			array(
2355
-				'type'    => 'warning',
2356
-				'content' => __( 'No published items found', 'invoicing' ),
2357
-			)
2358
-		);
2353
+        return aui()->alert(
2354
+            array(
2355
+                'type'    => 'warning',
2356
+                'content' => __( 'No published items found', 'invoicing' ),
2357
+            )
2358
+        );
2359 2359
     }
2360 2360
 
2361 2361
     $item_key = getpaid_convert_items_to_string( $items );
2362 2362
 
2363 2363
     // Get the form elements and items.
2364 2364
     $form     = wpinv_get_default_payment_form();
2365
-	$elements = $invoicing->form_elements->get_form_elements( $form );
2366
-	$items    = $invoicing->form_elements->convert_normal_items( $items );
2365
+    $elements = $invoicing->form_elements->get_form_elements( $form );
2366
+    $items    = $invoicing->form_elements->convert_normal_items( $items );
2367 2367
 
2368
-	ob_start();
2369
-	echo "<form class='wpinv_payment_form'>";
2370
-	do_action( 'wpinv_payment_form_top' );
2368
+    ob_start();
2369
+    echo "<form class='wpinv_payment_form'>";
2370
+    do_action( 'wpinv_payment_form_top' );
2371 2371
     echo "<input type='hidden' name='form_id' value='$form'/>";
2372 2372
     echo "<input type='hidden' name='form_items' value='$item_key'/>";
2373
-	wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
2374
-	wp_nonce_field( 'vat_validation', '_wpi_nonce' );
2373
+    wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
2374
+    wp_nonce_field( 'vat_validation', '_wpi_nonce' );
2375 2375
 
2376
-	foreach ( $elements as $element ) {
2377
-		do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form );
2378
-		do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form );
2379
-	}
2376
+    foreach ( $elements as $element ) {
2377
+        do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form );
2378
+        do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form );
2379
+    }
2380 2380
 
2381
-	echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
2382
-	do_action( 'wpinv_payment_form_bottom' );
2383
-	echo '</form>';
2381
+    echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
2382
+    do_action( 'wpinv_payment_form_bottom' );
2383
+    echo '</form>';
2384 2384
 
2385
-	$content = ob_get_clean();
2386
-	return str_replace( 'sr-only', '', $content );
2385
+    $content = ob_get_clean();
2386
+    return str_replace( 'sr-only', '', $content );
2387 2387
 }
2388 2388
 
2389 2389
 /**
@@ -2395,47 +2395,47 @@  discard block
 block discarded – undo
2395 2395
     $invoice = wpinv_get_invoice( $invoice_id );
2396 2396
 
2397 2397
     if ( empty( $invoice ) ) {
2398
-		return aui()->alert(
2399
-			array(
2400
-				'type'    => 'warning',
2401
-				'content' => __( 'Invoice not found', 'invoicing' ),
2402
-			)
2403
-		);
2398
+        return aui()->alert(
2399
+            array(
2400
+                'type'    => 'warning',
2401
+                'content' => __( 'Invoice not found', 'invoicing' ),
2402
+            )
2403
+        );
2404 2404
     }
2405 2405
 
2406 2406
     if ( $invoice->is_paid() ) {
2407
-		return aui()->alert(
2408
-			array(
2409
-				'type'    => 'warning',
2410
-				'content' => __( 'Invoice has already been paid', 'invoicing' ),
2411
-			)
2412
-		);
2407
+        return aui()->alert(
2408
+            array(
2409
+                'type'    => 'warning',
2410
+                'content' => __( 'Invoice has already been paid', 'invoicing' ),
2411
+            )
2412
+        );
2413 2413
     }
2414 2414
 
2415 2415
     // Get the form elements and items.
2416 2416
     $form     = wpinv_get_default_payment_form();
2417
-	$elements = $invoicing->form_elements->get_form_elements( $form );
2418
-	$items    = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice );
2417
+    $elements = $invoicing->form_elements->get_form_elements( $form );
2418
+    $items    = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice );
2419 2419
 
2420
-	ob_start();
2421
-	echo "<form class='wpinv_payment_form'>";
2422
-	do_action( 'wpinv_payment_form_top' );
2420
+    ob_start();
2421
+    echo "<form class='wpinv_payment_form'>";
2422
+    do_action( 'wpinv_payment_form_top' );
2423 2423
     echo "<input type='hidden' name='form_id' value='$form'/>";
2424 2424
     echo "<input type='hidden' name='invoice_id' value='$invoice_id'/>";
2425
-	wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
2426
-	wp_nonce_field( 'vat_validation', '_wpi_nonce' );
2425
+    wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
2426
+    wp_nonce_field( 'vat_validation', '_wpi_nonce' );
2427 2427
 
2428
-	foreach ( $elements as $element ) {
2429
-		do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form );
2430
-		do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form );
2431
-	}
2428
+    foreach ( $elements as $element ) {
2429
+        do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form );
2430
+        do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form );
2431
+    }
2432 2432
 
2433
-	echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
2434
-	do_action( 'wpinv_payment_form_bottom' );
2435
-	echo '</form>';
2433
+    echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
2434
+    do_action( 'wpinv_payment_form_bottom' );
2435
+    echo '</form>';
2436 2436
 
2437
-	$content = ob_get_clean();
2438
-	return str_replace( 'sr-only', '', $content );
2437
+    $content = ob_get_clean();
2438
+    return str_replace( 'sr-only', '', $content );
2439 2439
 }
2440 2440
 
2441 2441
 /**
@@ -2490,7 +2490,7 @@  discard block
 block discarded – undo
2490 2490
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-form='$form'>$label</button>"; 
2491 2491
     }
2492 2492
 	
2493
-	if ( ! empty( $items ) ) {
2493
+    if ( ! empty( $items ) ) {
2494 2494
         $items  = esc_attr( $items );
2495 2495
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-item='$items'>$label</button>"; 
2496 2496
     }
Please login to merge, or discard this patch.
Spacing   +802 added lines, -802 removed lines patch added patch discarded remove patch
@@ -7,91 +7,91 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14
-if ( !is_admin() ) {
15
-    add_filter( 'template_include', 'wpinv_template', 10, 1 );
16
-    add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' );
17
-    add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' );
18
-    add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' );
14
+if (!is_admin()) {
15
+    add_filter('template_include', 'wpinv_template', 10, 1);
16
+    add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar');
17
+    add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions');
18
+    add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions');
19 19
 }
20 20
 
21 21
 function wpinv_template_path() {
22
-    return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() );
22
+    return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name());
23 23
 }
24 24
 
25
-function wpinv_display_invoice_top_bar( $invoice ) {
26
-    if ( empty( $invoice ) ) {
25
+function wpinv_display_invoice_top_bar($invoice) {
26
+    if (empty($invoice)) {
27 27
         return;
28 28
     }
29 29
     ?>
30 30
     <div class="row wpinv-top-bar no-print">
31 31
         <div class="container">
32 32
             <div class="col-xs-6">
33
-                <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?>
33
+                <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?>
34 34
             </div>
35 35
             <div class="col-xs-6 text-right">
36
-                <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?>
36
+                <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?>
37 37
             </div>
38 38
         </div>
39 39
     </div>
40 40
     <?php
41 41
 }
42 42
 
43
-function wpinv_invoice_display_left_actions( $invoice ) {
44
-    if ( empty( $invoice ) ) {
43
+function wpinv_invoice_display_left_actions($invoice) {
44
+    if (empty($invoice)) {
45 45
         return; // Exit if invoice is not set.
46 46
     }
47 47
     
48
-    if ( $invoice->post_type == 'wpi_invoice' ) {
49
-        if ( $invoice->needs_payment() ) {
50
-            ?> <a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a><?php
48
+    if ($invoice->post_type == 'wpi_invoice') {
49
+        if ($invoice->needs_payment()) {
50
+            ?> <a class="btn btn-success btn-sm" title="<?php esc_attr_e('Pay This Invoice', 'invoicing'); ?>" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>"><?php _e('Pay For Invoice', 'invoicing'); ?></a><?php
51 51
         }
52 52
     }
53 53
     do_action('wpinv_invoice_display_left_actions', $invoice);
54 54
 }
55 55
 
56
-function wpinv_invoice_display_right_actions( $invoice ) {
57
-    if ( empty( $invoice ) ) {
56
+function wpinv_invoice_display_right_actions($invoice) {
57
+    if (empty($invoice)) {
58 58
         return; // Exit if invoice is not set.
59 59
     }
60 60
 
61
-    if ( $invoice->post_type == 'wpi_invoice' ) { ?>
62
-        <a class="btn btn-primary btn-sm btn-print-invoice" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a>
63
-        <?php if ( is_user_logged_in() ) { ?>
64
-        &nbsp;&nbsp;<a class="btn btn-warning btn-sm btn-invoice-history" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a>
61
+    if ($invoice->post_type == 'wpi_invoice') { ?>
62
+        <a class="btn btn-primary btn-sm btn-print-invoice" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a>
63
+        <?php if (is_user_logged_in()) { ?>
64
+        &nbsp;&nbsp;<a class="btn btn-warning btn-sm btn-invoice-history" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a>
65 65
         <?php }
66 66
     }
67 67
     do_action('wpinv_invoice_display_right_actions', $invoice);
68 68
 }
69 69
 
70
-function wpinv_before_invoice_content( $content ) {
70
+function wpinv_before_invoice_content($content) {
71 71
     global $post;
72 72
 
73
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
73
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
74 74
         ob_start();
75
-        do_action( 'wpinv_before_invoice_content', $post->ID );
75
+        do_action('wpinv_before_invoice_content', $post->ID);
76 76
         $content = ob_get_clean() . $content;
77 77
     }
78 78
 
79 79
     return $content;
80 80
 }
81
-add_filter( 'the_content', 'wpinv_before_invoice_content' );
81
+add_filter('the_content', 'wpinv_before_invoice_content');
82 82
 
83
-function wpinv_after_invoice_content( $content ) {
83
+function wpinv_after_invoice_content($content) {
84 84
     global $post;
85 85
 
86
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
86
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
87 87
         ob_start();
88
-        do_action( 'wpinv_after_invoice_content', $post->ID );
88
+        do_action('wpinv_after_invoice_content', $post->ID);
89 89
         $content .= ob_get_clean();
90 90
     }
91 91
 
92 92
     return $content;
93 93
 }
94
-add_filter( 'the_content', 'wpinv_after_invoice_content' );
94
+add_filter('the_content', 'wpinv_after_invoice_content');
95 95
 
96 96
 function wpinv_get_templates_dir() {
97 97
     return WPINV_PLUGIN_DIR . 'templates';
@@ -101,105 +101,105 @@  discard block
 block discarded – undo
101 101
     return WPINV_PLUGIN_URL . 'templates';
102 102
 }
103 103
 
104
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
105
-    if ( ! empty( $args ) && is_array( $args ) ) {
106
-		extract( $args );
104
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
105
+    if (!empty($args) && is_array($args)) {
106
+		extract($args);
107 107
 	}
108 108
 
109
-	$located = wpinv_locate_template( $template_name, $template_path, $default_path );
109
+	$located = wpinv_locate_template($template_name, $template_path, $default_path);
110 110
 	// Allow 3rd party plugin filter template file from their plugin.
111
-	$located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path );
111
+	$located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path);
112 112
 
113
-	if ( ! file_exists( $located ) ) {
114
-        _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
113
+	if (!file_exists($located)) {
114
+        _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1');
115 115
 		return;
116 116
 	}
117 117
 
118
-	do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
118
+	do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args);
119 119
 
120
-	include( $located );
120
+	include($located);
121 121
 
122
-	do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
122
+	do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args);
123 123
 }
124 124
 
125
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
125
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
126 126
 	ob_start();
127
-	wpinv_get_template( $template_name, $args, $template_path, $default_path );
127
+	wpinv_get_template($template_name, $args, $template_path, $default_path);
128 128
 	return ob_get_clean();
129 129
 }
130 130
 
131
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
132
-    if ( ! $template_path ) {
131
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
132
+    if (!$template_path) {
133 133
         $template_path = wpinv_template_path();
134 134
     }
135 135
 
136
-    if ( ! $default_path ) {
136
+    if (!$default_path) {
137 137
         $default_path = WPINV_PLUGIN_DIR . 'templates/';
138 138
     }
139 139
 
140 140
     // Look within passed path within the theme - this is priority.
141 141
     $template = locate_template(
142 142
         array(
143
-            trailingslashit( $template_path ) . $template_name,
143
+            trailingslashit($template_path) . $template_name,
144 144
             $template_name
145 145
         )
146 146
     );
147 147
 
148 148
     // Get default templates/
149
-    if ( !$template && $default_path ) {
150
-        $template = trailingslashit( $default_path ) . $template_name;
149
+    if (!$template && $default_path) {
150
+        $template = trailingslashit($default_path) . $template_name;
151 151
     }
152 152
 
153 153
     // Return what we found.
154
-    return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path );
154
+    return apply_filters('wpinv_locate_template', $template, $template_name, $template_path);
155 155
 }
156 156
 
157
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
158
-	do_action( 'get_template_part_' . $slug, $slug, $name );
157
+function wpinv_get_template_part($slug, $name = null, $load = true) {
158
+	do_action('get_template_part_' . $slug, $slug, $name);
159 159
 
160 160
 	// Setup possible parts
161 161
 	$templates = array();
162
-	if ( isset( $name ) )
162
+	if (isset($name))
163 163
 		$templates[] = $slug . '-' . $name . '.php';
164 164
 	$templates[] = $slug . '.php';
165 165
 
166 166
 	// Allow template parts to be filtered
167
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
167
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
168 168
 
169 169
 	// Return the part that is found
170
-	return wpinv_locate_tmpl( $templates, $load, false );
170
+	return wpinv_locate_tmpl($templates, $load, false);
171 171
 }
172 172
 
173
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
173
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
174 174
 	// No file found yet
175 175
 	$located = false;
176 176
 
177 177
 	// Try to find a template file
178
-	foreach ( (array)$template_names as $template_name ) {
178
+	foreach ((array) $template_names as $template_name) {
179 179
 
180 180
 		// Continue if template is empty
181
-		if ( empty( $template_name ) )
181
+		if (empty($template_name))
182 182
 			continue;
183 183
 
184 184
 		// Trim off any slashes from the template name
185
-		$template_name = ltrim( $template_name, '/' );
185
+		$template_name = ltrim($template_name, '/');
186 186
 
187 187
 		// try locating this template file by looping through the template paths
188
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
188
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
189 189
 
190
-			if( file_exists( $template_path . $template_name ) ) {
190
+			if (file_exists($template_path . $template_name)) {
191 191
 				$located = $template_path . $template_name;
192 192
 				break;
193 193
 			}
194 194
 		}
195 195
 
196
-		if( !empty( $located ) ) {
196
+		if (!empty($located)) {
197 197
 			break;
198 198
 		}
199 199
 	}
200 200
 
201
-	if ( ( true == $load ) && ! empty( $located ) )
202
-		load_template( $located, $require_once );
201
+	if ((true == $load) && !empty($located))
202
+		load_template($located, $require_once);
203 203
 
204 204
 	return $located;
205 205
 }
@@ -208,159 +208,159 @@  discard block
 block discarded – undo
208 208
 	$template_dir = wpinv_get_theme_template_dir_name();
209 209
 
210 210
 	$file_paths = array(
211
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
212
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
211
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
212
+		10 => trailingslashit(get_template_directory()) . $template_dir,
213 213
 		100 => wpinv_get_templates_dir()
214 214
 	);
215 215
 
216
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
216
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
217 217
 
218 218
 	// sort the file paths based on priority
219
-	ksort( $file_paths, SORT_NUMERIC );
219
+	ksort($file_paths, SORT_NUMERIC);
220 220
 
221
-	return array_map( 'trailingslashit', $file_paths );
221
+	return array_map('trailingslashit', $file_paths);
222 222
 }
223 223
 
224 224
 function wpinv_get_theme_template_dir_name() {
225
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
225
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing'));
226 226
 }
227 227
 
228 228
 function wpinv_checkout_meta_tags() {
229 229
 
230 230
 	$pages   = array();
231
-	$pages[] = wpinv_get_option( 'success_page' );
232
-	$pages[] = wpinv_get_option( 'failure_page' );
233
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
234
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
231
+	$pages[] = wpinv_get_option('success_page');
232
+	$pages[] = wpinv_get_option('failure_page');
233
+	$pages[] = wpinv_get_option('invoice_history_page');
234
+	$pages[] = wpinv_get_option('invoice_subscription_page');
235 235
 
236
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
236
+	if (!wpinv_is_checkout() && !is_page($pages)) {
237 237
 		return;
238 238
 	}
239 239
 
240 240
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
241 241
 }
242
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
242
+add_action('wp_head', 'wpinv_checkout_meta_tags');
243 243
 
244
-function wpinv_add_body_classes( $class ) {
245
-	$classes = (array)$class;
244
+function wpinv_add_body_classes($class) {
245
+	$classes = (array) $class;
246 246
 
247
-	if( wpinv_is_checkout() ) {
247
+	if (wpinv_is_checkout()) {
248 248
 		$classes[] = 'wpinv-checkout';
249 249
 		$classes[] = 'wpinv-page';
250 250
 	}
251 251
 
252
-	if( wpinv_is_success_page() ) {
252
+	if (wpinv_is_success_page()) {
253 253
 		$classes[] = 'wpinv-success';
254 254
 		$classes[] = 'wpinv-page';
255 255
 	}
256 256
 
257
-	if( wpinv_is_failed_transaction_page() ) {
257
+	if (wpinv_is_failed_transaction_page()) {
258 258
 		$classes[] = 'wpinv-failed-transaction';
259 259
 		$classes[] = 'wpinv-page';
260 260
 	}
261 261
 
262
-	if( wpinv_is_invoice_history_page() ) {
262
+	if (wpinv_is_invoice_history_page()) {
263 263
 		$classes[] = 'wpinv-history';
264 264
 		$classes[] = 'wpinv-page';
265 265
 	}
266 266
 
267
-	if( wpinv_is_subscriptions_history_page() ) {
267
+	if (wpinv_is_subscriptions_history_page()) {
268 268
 		$classes[] = 'wpinv-subscription';
269 269
 		$classes[] = 'wpinv-page';
270 270
 	}
271 271
 
272
-	if( wpinv_is_test_mode() ) {
272
+	if (wpinv_is_test_mode()) {
273 273
 		$classes[] = 'wpinv-test-mode';
274 274
 		$classes[] = 'wpinv-page';
275 275
 	}
276 276
 
277
-	return array_unique( $classes );
277
+	return array_unique($classes);
278 278
 }
279
-add_filter( 'body_class', 'wpinv_add_body_classes' );
279
+add_filter('body_class', 'wpinv_add_body_classes');
280 280
 
281
-function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) {
282
-    $args = array( 'nopaging' => true );
281
+function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') {
282
+    $args = array('nopaging' => true);
283 283
 
284
-    if ( ! empty( $status ) )
284
+    if (!empty($status))
285 285
         $args['post_status'] = $status;
286 286
 
287
-    $discounts = wpinv_get_discounts( $args );
287
+    $discounts = wpinv_get_discounts($args);
288 288
     $options   = array();
289 289
 
290
-    if ( $discounts ) {
291
-        foreach ( $discounts as $discount ) {
292
-            $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) );
290
+    if ($discounts) {
291
+        foreach ($discounts as $discount) {
292
+            $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID));
293 293
         }
294 294
     } else {
295
-        $options[0] = __( 'No discounts found', 'invoicing' );
295
+        $options[0] = __('No discounts found', 'invoicing');
296 296
     }
297 297
 
298
-    $output = wpinv_html_select( array(
298
+    $output = wpinv_html_select(array(
299 299
         'name'             => $name,
300 300
         'selected'         => $selected,
301 301
         'options'          => $options,
302 302
         'show_option_all'  => false,
303 303
         'show_option_none' => false,
304
-    ) );
304
+    ));
305 305
 
306 306
     return $output;
307 307
 }
308 308
 
309
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
310
-    $current     = date( 'Y' );
311
-    $start_year  = $current - absint( $years_before );
312
-    $end_year    = $current + absint( $years_after );
313
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
309
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
310
+    $current     = date('Y');
311
+    $start_year  = $current - absint($years_before);
312
+    $end_year    = $current + absint($years_after);
313
+    $selected    = empty($selected) ? date('Y') : $selected;
314 314
     $options     = array();
315 315
 
316
-    while ( $start_year <= $end_year ) {
317
-        $options[ absint( $start_year ) ] = $start_year;
316
+    while ($start_year <= $end_year) {
317
+        $options[absint($start_year)] = $start_year;
318 318
         $start_year++;
319 319
     }
320 320
 
321
-    $output = wpinv_html_select( array(
321
+    $output = wpinv_html_select(array(
322 322
         'name'             => $name,
323 323
         'selected'         => $selected,
324 324
         'options'          => $options,
325 325
         'show_option_all'  => false,
326 326
         'show_option_none' => false
327
-    ) );
327
+    ));
328 328
 
329 329
     return $output;
330 330
 }
331 331
 
332
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
332
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
333 333
 
334 334
     $options = array(
335
-        '1'  => __( 'January', 'invoicing' ),
336
-        '2'  => __( 'February', 'invoicing' ),
337
-        '3'  => __( 'March', 'invoicing' ),
338
-        '4'  => __( 'April', 'invoicing' ),
339
-        '5'  => __( 'May', 'invoicing' ),
340
-        '6'  => __( 'June', 'invoicing' ),
341
-        '7'  => __( 'July', 'invoicing' ),
342
-        '8'  => __( 'August', 'invoicing' ),
343
-        '9'  => __( 'September', 'invoicing' ),
344
-        '10' => __( 'October', 'invoicing' ),
345
-        '11' => __( 'November', 'invoicing' ),
346
-        '12' => __( 'December', 'invoicing' ),
335
+        '1'  => __('January', 'invoicing'),
336
+        '2'  => __('February', 'invoicing'),
337
+        '3'  => __('March', 'invoicing'),
338
+        '4'  => __('April', 'invoicing'),
339
+        '5'  => __('May', 'invoicing'),
340
+        '6'  => __('June', 'invoicing'),
341
+        '7'  => __('July', 'invoicing'),
342
+        '8'  => __('August', 'invoicing'),
343
+        '9'  => __('September', 'invoicing'),
344
+        '10' => __('October', 'invoicing'),
345
+        '11' => __('November', 'invoicing'),
346
+        '12' => __('December', 'invoicing'),
347 347
     );
348 348
 
349 349
     // If no month is selected, default to the current month
350
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
350
+    $selected = empty($selected) ? date('n') : $selected;
351 351
 
352
-    $output = wpinv_html_select( array(
352
+    $output = wpinv_html_select(array(
353 353
         'name'             => $name,
354 354
         'selected'         => $selected,
355 355
         'options'          => $options,
356 356
         'show_option_all'  => false,
357 357
         'show_option_none' => false
358
-    ) );
358
+    ));
359 359
 
360 360
     return $output;
361 361
 }
362 362
 
363
-function wpinv_html_select( $args = array() ) {
363
+function wpinv_html_select($args = array()) {
364 364
     $defaults = array(
365 365
         'options'          => array(),
366 366
         'name'             => null,
@@ -369,8 +369,8 @@  discard block
 block discarded – undo
369 369
         'selected'         => 0,
370 370
         'placeholder'      => null,
371 371
         'multiple'         => false,
372
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
373
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
372
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
373
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
374 374
         'data'             => array(),
375 375
         'onchange'         => null,
376 376
         'required'         => false,
@@ -378,74 +378,74 @@  discard block
 block discarded – undo
378 378
         'readonly'         => false,
379 379
     );
380 380
 
381
-    $args = wp_parse_args( $args, $defaults );
381
+    $args = wp_parse_args($args, $defaults);
382 382
 
383 383
     $data_elements = '';
384
-    foreach ( $args['data'] as $key => $value ) {
385
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
384
+    foreach ($args['data'] as $key => $value) {
385
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
386 386
     }
387 387
 
388
-    if( $args['multiple'] ) {
388
+    if ($args['multiple']) {
389 389
         $multiple = ' MULTIPLE';
390 390
     } else {
391 391
         $multiple = '';
392 392
     }
393 393
 
394
-    if( $args['placeholder'] ) {
394
+    if ($args['placeholder']) {
395 395
         $placeholder = $args['placeholder'];
396 396
     } else {
397 397
         $placeholder = '';
398 398
     }
399 399
     
400 400
     $options = '';
401
-    if( !empty( $args['onchange'] ) ) {
402
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
401
+    if (!empty($args['onchange'])) {
402
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
403 403
     }
404 404
     
405
-    if( !empty( $args['required'] ) ) {
405
+    if (!empty($args['required'])) {
406 406
         $options .= ' required="required"';
407 407
     }
408 408
     
409
-    if( !empty( $args['disabled'] ) ) {
409
+    if (!empty($args['disabled'])) {
410 410
         $options .= ' disabled';
411 411
     }
412 412
     
413
-    if( !empty( $args['readonly'] ) ) {
413
+    if (!empty($args['readonly'])) {
414 414
         $options .= ' readonly';
415 415
     }
416 416
 
417
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
418
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
417
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
418
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
419 419
 
420
-    if ( $args['show_option_all'] ) {
421
-        if( $args['multiple'] ) {
422
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
420
+    if ($args['show_option_all']) {
421
+        if ($args['multiple']) {
422
+            $selected = selected(true, in_array(0, $args['selected']), false);
423 423
         } else {
424
-            $selected = selected( $args['selected'], 0, false );
424
+            $selected = selected($args['selected'], 0, false);
425 425
         }
426
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
426
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
427 427
     }
428 428
 
429
-    if ( !empty( $args['options'] ) ) {
429
+    if (!empty($args['options'])) {
430 430
 
431
-        if ( $args['show_option_none'] ) {
432
-            if( $args['multiple'] ) {
433
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
431
+        if ($args['show_option_none']) {
432
+            if ($args['multiple']) {
433
+                $selected = selected(true, in_array("", $args['selected']), false);
434 434
             } else {
435
-                $selected = selected( $args['selected'] === "", true, false );
435
+                $selected = selected($args['selected'] === "", true, false);
436 436
             }
437
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
437
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
438 438
         }
439 439
 
440
-        foreach( $args['options'] as $key => $option ) {
440
+        foreach ($args['options'] as $key => $option) {
441 441
 
442
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
443
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
442
+            if ($args['multiple'] && is_array($args['selected'])) {
443
+                $selected = selected(true, (bool) in_array($key, $args['selected']), false);
444 444
             } else {
445
-                $selected = selected( $args['selected'], $key, false );
445
+                $selected = selected($args['selected'], $key, false);
446 446
             }
447 447
 
448
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
448
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
449 449
         }
450 450
     }
451 451
 
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
     return $output;
455 455
 }
456 456
 
457
-function wpinv_item_dropdown( $args = array() ) {
457
+function wpinv_item_dropdown($args = array()) {
458 458
     $defaults = array(
459 459
         'name'              => 'wpi_item',
460 460
         'id'                => 'wpi_item',
@@ -462,14 +462,14 @@  discard block
 block discarded – undo
462 462
         'multiple'          => false,
463 463
         'selected'          => 0,
464 464
         'number'            => 100,
465
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
466
-        'data'              => array( 'search-type' => 'item' ),
465
+        'placeholder'       => __('Choose a item', 'invoicing'),
466
+        'data'              => array('search-type' => 'item'),
467 467
         'show_option_all'   => false,
468 468
         'show_option_none'  => false,
469 469
         'show_recurring'    => false,
470 470
     );
471 471
 
472
-    $args = wp_parse_args( $args, $defaults );
472
+    $args = wp_parse_args($args, $defaults);
473 473
 
474 474
     $item_args = array(
475 475
         'post_type'      => 'wpi_item',
@@ -478,44 +478,44 @@  discard block
 block discarded – undo
478 478
         'posts_per_page' => $args['number']
479 479
     );
480 480
 
481
-    $item_args  = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults );
481
+    $item_args  = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults);
482 482
 
483
-    $items      = get_posts( $item_args );
483
+    $items      = get_posts($item_args);
484 484
     $options    = array();
485
-    if ( $items ) {
486
-        foreach ( $items as $item ) {
487
-            $title = esc_html( $item->post_title );
485
+    if ($items) {
486
+        foreach ($items as $item) {
487
+            $title = esc_html($item->post_title);
488 488
             
489
-            if ( !empty( $args['show_recurring'] ) ) {
490
-                $title .= wpinv_get_item_suffix( $item->ID, false );
489
+            if (!empty($args['show_recurring'])) {
490
+                $title .= wpinv_get_item_suffix($item->ID, false);
491 491
             }
492 492
             
493
-            $options[ absint( $item->ID ) ] = $title;
493
+            $options[absint($item->ID)] = $title;
494 494
         }
495 495
     }
496 496
 
497 497
     // This ensures that any selected items are included in the drop down
498
-    if( is_array( $args['selected'] ) ) {
499
-        foreach( $args['selected'] as $item ) {
500
-            if( ! in_array( $item, $options ) ) {
501
-                $title = get_the_title( $item );
502
-                if ( !empty( $args['show_recurring'] ) ) {
503
-                    $title .= wpinv_get_item_suffix( $item, false );
498
+    if (is_array($args['selected'])) {
499
+        foreach ($args['selected'] as $item) {
500
+            if (!in_array($item, $options)) {
501
+                $title = get_the_title($item);
502
+                if (!empty($args['show_recurring'])) {
503
+                    $title .= wpinv_get_item_suffix($item, false);
504 504
                 }
505 505
                 $options[$item] = $title;
506 506
             }
507 507
         }
508
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
509
-        if ( ! in_array( $args['selected'], $options ) ) {
510
-            $title = get_the_title( $args['selected'] );
511
-            if ( !empty( $args['show_recurring'] ) ) {
512
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
508
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
509
+        if (!in_array($args['selected'], $options)) {
510
+            $title = get_the_title($args['selected']);
511
+            if (!empty($args['show_recurring'])) {
512
+                $title .= wpinv_get_item_suffix($args['selected'], false);
513 513
             }
514
-            $options[$args['selected']] = get_the_title( $args['selected'] );
514
+            $options[$args['selected']] = get_the_title($args['selected']);
515 515
         }
516 516
     }
517 517
 
518
-    $output = wpinv_html_select( array(
518
+    $output = wpinv_html_select(array(
519 519
         'name'             => $args['name'],
520 520
         'selected'         => $args['selected'],
521 521
         'id'               => $args['id'],
@@ -526,12 +526,12 @@  discard block
 block discarded – undo
526 526
         'show_option_all'  => $args['show_option_all'],
527 527
         'show_option_none' => $args['show_option_none'],
528 528
         'data'             => $args['data'],
529
-    ) );
529
+    ));
530 530
 
531 531
     return $output;
532 532
 }
533 533
 
534
-function wpinv_html_checkbox( $args = array() ) {
534
+function wpinv_html_checkbox($args = array()) {
535 535
     $defaults = array(
536 536
         'name'     => null,
537 537
         'current'  => null,
@@ -542,38 +542,38 @@  discard block
 block discarded – undo
542 542
         )
543 543
     );
544 544
 
545
-    $args = wp_parse_args( $args, $defaults );
545
+    $args = wp_parse_args($args, $defaults);
546 546
 
547
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
547
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
548 548
     $options = '';
549
-    if ( ! empty( $args['options']['disabled'] ) ) {
549
+    if (!empty($args['options']['disabled'])) {
550 550
         $options .= ' disabled="disabled"';
551
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
551
+    } elseif (!empty($args['options']['readonly'])) {
552 552
         $options .= ' readonly';
553 553
     }
554 554
 
555
-    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
555
+    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />';
556 556
 
557 557
     return $output;
558 558
 }
559 559
 
560
-function wpinv_html_text( $args = array() ) {
560
+function wpinv_html_text($args = array()) {
561 561
     // Backwards compatibility
562
-    if ( func_num_args() > 1 ) {
562
+    if (func_num_args() > 1) {
563 563
         $args = func_get_args();
564 564
 
565 565
         $name  = $args[0];
566
-        $value = isset( $args[1] ) ? $args[1] : '';
567
-        $label = isset( $args[2] ) ? $args[2] : '';
568
-        $desc  = isset( $args[3] ) ? $args[3] : '';
566
+        $value = isset($args[1]) ? $args[1] : '';
567
+        $label = isset($args[2]) ? $args[2] : '';
568
+        $desc  = isset($args[3]) ? $args[3] : '';
569 569
     }
570 570
 
571 571
     $defaults = array(
572 572
         'id'           => '',
573
-        'name'         => isset( $name )  ? $name  : 'text',
574
-        'value'        => isset( $value ) ? $value : null,
575
-        'label'        => isset( $label ) ? $label : null,
576
-        'desc'         => isset( $desc )  ? $desc  : null,
573
+        'name'         => isset($name) ? $name : 'text',
574
+        'value'        => isset($value) ? $value : null,
575
+        'label'        => isset($label) ? $label : null,
576
+        'desc'         => isset($desc) ? $desc : null,
577 577
         'placeholder'  => '',
578 578
         'class'        => 'regular-text',
579 579
         'disabled'     => false,
@@ -583,51 +583,51 @@  discard block
 block discarded – undo
583 583
         'data'         => false
584 584
     );
585 585
 
586
-    $args = wp_parse_args( $args, $defaults );
586
+    $args = wp_parse_args($args, $defaults);
587 587
 
588
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
588
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
589 589
     $options = '';
590
-    if( $args['required'] ) {
590
+    if ($args['required']) {
591 591
         $options .= ' required="required"';
592 592
     }
593
-    if( $args['readonly'] ) {
593
+    if ($args['readonly']) {
594 594
         $options .= ' readonly';
595 595
     }
596
-    if( $args['readonly'] ) {
596
+    if ($args['readonly']) {
597 597
         $options .= ' readonly';
598 598
     }
599 599
 
600 600
     $data = '';
601
-    if ( !empty( $args['data'] ) ) {
602
-        foreach ( $args['data'] as $key => $value ) {
603
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
601
+    if (!empty($args['data'])) {
602
+        foreach ($args['data'] as $key => $value) {
603
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
604 604
         }
605 605
     }
606 606
 
607
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
608
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
609
-    if ( ! empty( $args['desc'] ) ) {
610
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
607
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
608
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
609
+    if (!empty($args['desc'])) {
610
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
611 611
     }
612 612
 
613
-    $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 ) . '/>';
613
+    $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) . '/>';
614 614
 
615 615
     $output .= '</span>';
616 616
 
617 617
     return $output;
618 618
 }
619 619
 
620
-function wpinv_html_date_field( $args = array() ) {
621
-    if( empty( $args['class'] ) ) {
620
+function wpinv_html_date_field($args = array()) {
621
+    if (empty($args['class'])) {
622 622
         $args['class'] = 'wpiDatepicker';
623
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
623
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
624 624
         $args['class'] .= ' wpiDatepicker';
625 625
     }
626 626
 
627
-    return wpinv_html_text( $args );
627
+    return wpinv_html_text($args);
628 628
 }
629 629
 
630
-function wpinv_html_textarea( $args = array() ) {
630
+function wpinv_html_textarea($args = array()) {
631 631
     $defaults = array(
632 632
         'name'        => 'textarea',
633 633
         'value'       => null,
@@ -638,31 +638,31 @@  discard block
 block discarded – undo
638 638
         'placeholder' => '',
639 639
     );
640 640
 
641
-    $args = wp_parse_args( $args, $defaults );
641
+    $args = wp_parse_args($args, $defaults);
642 642
 
643
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
643
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
644 644
     $disabled = '';
645
-    if( $args['disabled'] ) {
645
+    if ($args['disabled']) {
646 646
         $disabled = ' disabled="disabled"';
647 647
     }
648 648
 
649
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
650
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
651
-    $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>';
649
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
650
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
651
+    $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>';
652 652
 
653
-    if ( ! empty( $args['desc'] ) ) {
654
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
653
+    if (!empty($args['desc'])) {
654
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
655 655
     }
656 656
     $output .= '</span>';
657 657
 
658 658
     return $output;
659 659
 }
660 660
 
661
-function wpinv_html_ajax_user_search( $args = array() ) {
661
+function wpinv_html_ajax_user_search($args = array()) {
662 662
     $defaults = array(
663 663
         'name'        => 'user_id',
664 664
         'value'       => null,
665
-        'placeholder' => __( 'Enter username', 'invoicing' ),
665
+        'placeholder' => __('Enter username', 'invoicing'),
666 666
         'label'       => null,
667 667
         'desc'        => null,
668 668
         'class'       => '',
@@ -671,13 +671,13 @@  discard block
 block discarded – undo
671 671
         'data'        => false
672 672
     );
673 673
 
674
-    $args = wp_parse_args( $args, $defaults );
674
+    $args = wp_parse_args($args, $defaults);
675 675
 
676 676
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
677 677
 
678 678
     $output  = '<span class="wpinv_user_search_wrap">';
679
-        $output .= wpinv_html_text( $args );
680
-        $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>';
679
+        $output .= wpinv_html_text($args);
680
+        $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>';
681 681
     $output .= '</span>';
682 682
 
683 683
     return $output;
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
 function wpinv_ip_geolocation() {
687 687
     global $wpinv_euvat;
688 688
     
689
-    $ip         = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : '';    
689
+    $ip         = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : '';    
690 690
     $content    = '';
691 691
     $iso        = '';
692 692
     $country    = '';
@@ -697,69 +697,69 @@  discard block
 block discarded – undo
697 697
     $credit     = '';
698 698
     $address    = '';
699 699
     
700
-    if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) {
700
+    if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) {
701 701
         try {
702 702
             $iso        = $geoip2_city->country->isoCode;
703 703
             $country    = $geoip2_city->country->name;
704
-            $region     = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : '';
704
+            $region     = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : '';
705 705
             $city       = $geoip2_city->city->name;
706 706
             $longitude  = $geoip2_city->location->longitude;
707 707
             $latitude   = $geoip2_city->location->latitude;
708
-            $credit     = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' );
709
-        } catch( Exception $e ) { }
708
+            $credit     = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing');
709
+        } catch (Exception $e) { }
710 710
     }
711 711
     
712
-    if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) {
712
+    if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) {
713 713
         try {
714
-            $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
714
+            $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
715 715
             
716
-            if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) {
716
+            if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) {
717 717
                 $iso        = $load_xml->geoplugin_countryCode;
718 718
                 $country    = $load_xml->geoplugin_countryName;
719
-                $region     = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : '';
720
-                $city       = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : '';
719
+                $region     = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : '';
720
+                $city       = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : '';
721 721
                 $longitude  = $load_xml->geoplugin_longitude;
722 722
                 $latitude   = $load_xml->geoplugin_latitude;
723 723
                 $credit     = $load_xml->geoplugin_credit;
724
-                $credit     = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit;
724
+                $credit     = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit;
725 725
             }
726
-        } catch( Exception $e ) { }
726
+        } catch (Exception $e) { }
727 727
     }
728 728
     
729
-    if ( $iso && $longitude && $latitude ) {
730
-        if ( $city ) {
729
+    if ($iso && $longitude && $latitude) {
730
+        if ($city) {
731 731
             $address .= $city . ', ';
732 732
         }
733 733
         
734
-        if ( $region ) {
734
+        if ($region) {
735 735
             $address .= $region . ', ';
736 736
         }
737 737
         
738 738
         $address .= $country . ' (' . $iso . ')';
739
-        $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>';
740
-        $content .= '<p>'. $credit . '</p>';
739
+        $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>';
740
+        $content .= '<p>' . $credit . '</p>';
741 741
     } else {
742
-        $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>';
742
+        $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>';
743 743
     }
744 744
     ?>
745 745
 <!DOCTYPE html>
746
-<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
746
+<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
747 747
 <body>
748
-    <?php if ( $latitude && $latitude ) { ?>
748
+    <?php if ($latitude && $latitude) { ?>
749 749
     <div id="map"></div>
750 750
         <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script>
751 751
         <script type="text/javascript">
752 752
         var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
753 753
             osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
754 754
             osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}),
755
-            latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>);
755
+            latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
756 756
 
757 757
         var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]});
758 758
 
759 759
         var marker = new L.Marker(latlng);
760 760
         map.addLayer(marker);
761 761
 
762
-        marker.bindPopup("<p><?php esc_attr_e( $address );?></p>");
762
+        marker.bindPopup("<p><?php esc_attr_e($address); ?></p>");
763 763
     </script>
764 764
     <?php } ?>
765 765
     <div style="height:100px"><?php echo $content; ?></div>
@@ -767,18 +767,18 @@  discard block
 block discarded – undo
767 767
 <?php
768 768
     exit;
769 769
 }
770
-add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
771
-add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
770
+add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
771
+add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
772 772
 
773 773
 // Set up the template for the invoice.
774
-function wpinv_template( $template ) {
774
+function wpinv_template($template) {
775 775
     global $post, $wp_query;
776 776
     
777
-    if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) {
778
-        if ( wpinv_user_can_view_invoice( $post->ID ) ) {
779
-            $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false );
777
+    if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) {
778
+        if (wpinv_user_can_view_invoice($post->ID)) {
779
+            $template = wpinv_get_template_part('wpinv-invoice-print', false, false);
780 780
         } else {
781
-            $template = wpinv_get_template_part( 'wpinv-invalid-access', false, false );
781
+            $template = wpinv_get_template_part('wpinv-invalid-access', false, false);
782 782
         }
783 783
     }
784 784
 
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
 
788 788
 function wpinv_get_business_address() {
789 789
     $business_address   = wpinv_store_address();
790
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
790
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
791 791
     
792 792
     /*
793 793
     $default_country    = wpinv_get_default_country();
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
     
812 812
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
813 813
     
814
-    return apply_filters( 'wpinv_get_business_address', $business_address );
814
+    return apply_filters('wpinv_get_business_address', $business_address);
815 815
 }
816 816
 
817 817
 function wpinv_display_from_address() {
@@ -821,107 +821,107 @@  discard block
 block discarded – undo
821 821
     if (empty($from_name)) {
822 822
         $from_name = wpinv_get_business_name();
823 823
     }
824
-    ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div>
824
+    ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div>
825 825
     <div class="wrapper col-xs-10">
826
-        <div class="name"><?php echo esc_html( $from_name ); ?></div>
827
-        <?php if ( $address = wpinv_get_business_address() ) { ?>
828
-        <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div>
826
+        <div class="name"><?php echo esc_html($from_name); ?></div>
827
+        <?php if ($address = wpinv_get_business_address()) { ?>
828
+        <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div>
829 829
         <?php } ?>
830
-        <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?>
831
-        <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s', 'invoicing' ), $email_from );?></div>
830
+        <?php if ($email_from = wpinv_mail_get_from_address()) { ?>
831
+        <div class="email_from"><?php echo wp_sprintf(__('Email: %s', 'invoicing'), $email_from); ?></div>
832 832
         <?php } ?>
833 833
     </div>
834 834
     <?php
835 835
 }
836 836
 
837
-function wpinv_watermark( $id = 0 ) {
838
-    $output = wpinv_get_watermark( $id );
837
+function wpinv_watermark($id = 0) {
838
+    $output = wpinv_get_watermark($id);
839 839
     
840
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
840
+    return apply_filters('wpinv_get_watermark', $output, $id);
841 841
 }
842 842
 
843
-function wpinv_get_watermark( $id ) {
844
-    if ( !$id > 0 ) {
843
+function wpinv_get_watermark($id) {
844
+    if (!$id > 0) {
845 845
         return NULL;
846 846
     }
847
-    $invoice = wpinv_get_invoice( $id );
847
+    $invoice = wpinv_get_invoice($id);
848 848
     
849
-    if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) {
850
-        if ( $invoice->is_paid() ) {
851
-            return __( 'Paid', 'invoicing' );
849
+    if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) {
850
+        if ($invoice->is_paid()) {
851
+            return __('Paid', 'invoicing');
852 852
         }
853
-        if ( $invoice->is_refunded() ) {
854
-            return __( 'Refunded', 'invoicing' );
853
+        if ($invoice->is_refunded()) {
854
+            return __('Refunded', 'invoicing');
855 855
         }
856
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
857
-            return __( 'Cancelled', 'invoicing' );
856
+        if ($invoice->has_status(array('wpi-cancelled'))) {
857
+            return __('Cancelled', 'invoicing');
858 858
         }
859 859
     }
860 860
     
861 861
     return NULL;
862 862
 }
863 863
 
864
-function wpinv_display_invoice_details( $invoice ) {
864
+function wpinv_display_invoice_details($invoice) {
865 865
     global $wpinv_euvat;
866 866
     
867 867
     $invoice_id = $invoice->ID;
868 868
     $vat_name   = $wpinv_euvat->get_vat_name();
869 869
     $use_taxes  = wpinv_use_taxes();
870 870
     
871
-    $invoice_status = wpinv_get_invoice_status( $invoice_id );
871
+    $invoice_status = wpinv_get_invoice_status($invoice_id);
872 872
     ?>
873 873
     <table class="table table-bordered table-sm">
874
-        <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?>
874
+        <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?>
875 875
             <tr class="wpi-row-number">
876
-                <th><?php echo apply_filters( 'wpinv_invoice_number_label', __( 'Invoice Number', 'invoicing' ), $invoice ); ?></th>
877
-                <td><?php echo esc_html( $invoice_number ); ?></td>
876
+                <th><?php echo apply_filters('wpinv_invoice_number_label', __('Invoice Number', 'invoicing'), $invoice); ?></th>
877
+                <td><?php echo esc_html($invoice_number); ?></td>
878 878
             </tr>
879 879
         <?php } ?>
880 880
         <tr class="wpi-row-status">
881
-            <th><?php echo apply_filters( 'wpinv_invoice_status_label', __( 'Invoice Status', 'invoicing' ), $invoice ); ?></th>
882
-            <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td>
881
+            <th><?php echo apply_filters('wpinv_invoice_status_label', __('Invoice Status', 'invoicing'), $invoice); ?></th>
882
+            <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td>
883 883
         </tr>
884
-        <?php if ( $invoice->is_renewal() ) { ?>
884
+        <?php if ($invoice->is_renewal()) { ?>
885 885
         <tr class="wpi-row-parent">
886
-            <th><?php echo apply_filters( 'wpinv_invoice_parent_invoice_label', __( 'Parent Invoice', 'invoicing' ), $invoice ); ?></th>
887
-            <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td>
886
+            <th><?php echo apply_filters('wpinv_invoice_parent_invoice_label', __('Parent Invoice', 'invoicing'), $invoice); ?></th>
887
+            <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td>
888 888
         </tr>
889 889
         <?php } ?>
890
-        <?php if ( ( $gateway_name = wpinv_get_payment_gateway_name( $invoice_id ) ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) { ?>
890
+        <?php if (($gateway_name = wpinv_get_payment_gateway_name($invoice_id)) && ($invoice->is_paid() || $invoice->is_refunded())) { ?>
891 891
             <tr class="wpi-row-gateway">
892
-                <th><?php echo apply_filters( 'wpinv_invoice_payment_method_label', __( 'Payment Method', 'invoicing' ), $invoice ); ?></th>
892
+                <th><?php echo apply_filters('wpinv_invoice_payment_method_label', __('Payment Method', 'invoicing'), $invoice); ?></th>
893 893
                 <td><?php echo $gateway_name; ?></td>
894 894
             </tr>
895 895
         <?php } ?>
896
-        <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?>
896
+        <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?>
897 897
             <tr class="wpi-row-date">
898
-                <th><?php echo apply_filters( 'wpinv_invoice_date_label', __( 'Invoice Date', 'invoicing' ), $invoice ); ?></th>
898
+                <th><?php echo apply_filters('wpinv_invoice_date_label', __('Invoice Date', 'invoicing'), $invoice); ?></th>
899 899
                 <td><?php echo $invoice_date; ?></td>
900 900
             </tr>
901 901
         <?php } ?>
902
-        <?php do_action( 'wpinv_display_details_before_due_date', $invoice_id ); ?>
903
-        <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?>
902
+        <?php do_action('wpinv_display_details_before_due_date', $invoice_id); ?>
903
+        <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?>
904 904
             <tr class="wpi-row-date">
905
-                <th><?php echo apply_filters( 'wpinv_invoice_due_date_label', __( 'Due Date', 'invoicing' ), $invoice ); ?></th>
905
+                <th><?php echo apply_filters('wpinv_invoice_due_date_label', __('Due Date', 'invoicing'), $invoice); ?></th>
906 906
                 <td><?php echo $due_date; ?></td>
907 907
             </tr>
908 908
         <?php } ?>
909
-        <?php do_action( 'wpinv_display_details_after_due_date', $invoice_id ); ?>
910
-        <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?>
909
+        <?php do_action('wpinv_display_details_after_due_date', $invoice_id); ?>
910
+        <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?>
911 911
             <tr class="wpi-row-ovatno">
912
-                <th><?php echo apply_filters( 'wpinv_invoice_owner_vat_number_label', wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></th>
912
+                <th><?php echo apply_filters('wpinv_invoice_owner_vat_number_label', wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></th>
913 913
                 <td><?php echo $owner_vat_number; ?></td>
914 914
             </tr>
915 915
         <?php } ?>
916
-        <?php if ( $use_taxes && ( $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) ) { ?>
916
+        <?php if ($use_taxes && ($user_vat_number = wpinv_get_invoice_vat_number($invoice_id))) { ?>
917 917
             <tr class="wpi-row-uvatno">
918
-                <th><?php echo apply_filters( 'wpinv_invoice_user_vat_number_label', wp_sprintf( __( 'Invoice %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></th>
918
+                <th><?php echo apply_filters('wpinv_invoice_user_vat_number_label', wp_sprintf(__('Invoice %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></th>
919 919
                 <td><?php echo $user_vat_number; ?></td>
920 920
             </tr>
921 921
         <?php } ?>
922 922
         <tr class="table-active tr-total wpi-row-total">
923
-            <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th>
924
-            <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td>
923
+            <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th>
924
+            <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td>
925 925
         </tr>
926 926
     </table>
927 927
 <?php
@@ -937,84 +937,84 @@  discard block
 block discarded – undo
937 937
  * @param  string $separator How to separate address lines.
938 938
  * @return string
939 939
  */
940
-function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) {
940
+function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') {
941 941
 
942 942
     // Retrieve the address markup...
943
-    $country= empty( $billing_details['country'] ) ? '' : $billing_details['country'];
944
-    $format = wpinv_get_full_address_format( $country );
943
+    $country = empty($billing_details['country']) ? '' : $billing_details['country'];
944
+    $format = wpinv_get_full_address_format($country);
945 945
 
946 946
     // ... and the replacements.
947
-    $replacements = wpinv_get_invoice_address_replacements( $billing_details );
947
+    $replacements = wpinv_get_invoice_address_replacements($billing_details);
948 948
 
949
-    $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format );
949
+    $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format);
950 950
     
951 951
 	// Remove unavailable tags.
952
-    $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address );
952
+    $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address);
953 953
 
954 954
     // Clean up white space.
955
-	$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
956
-    $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
955
+	$formatted_address = preg_replace('/  +/', ' ', trim($formatted_address));
956
+    $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address);
957 957
     
958 958
     // Break newlines apart and remove empty lines/trim commas and white space.
959
-	$formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
959
+	$formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address)));
960 960
 
961 961
     // Add html breaks.
962
-	$formatted_address = implode( $separator, $formatted_address );
962
+	$formatted_address = implode($separator, $formatted_address);
963 963
 
964 964
 	// We're done!
965 965
 	return $formatted_address;
966 966
     
967 967
 }
968 968
 
969
-function wpinv_display_to_address( $invoice_id = 0 ) {
970
-    $invoice = wpinv_get_invoice( $invoice_id );
969
+function wpinv_display_to_address($invoice_id = 0) {
970
+    $invoice = wpinv_get_invoice($invoice_id);
971 971
     
972
-    if ( empty( $invoice ) ) {
972
+    if (empty($invoice)) {
973 973
         return NULL;
974 974
     }
975 975
     
976 976
     $billing_details = $invoice->get_user_info();
977
-    $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>';
977
+    $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>';
978 978
     $output .= '<div class="wrapper col-xs-10">';
979 979
     
980 980
     ob_start();
981
-    do_action( 'wpinv_display_to_address_top', $invoice );
981
+    do_action('wpinv_display_to_address_top', $invoice);
982 982
     $output .= ob_get_clean();
983 983
     
984
-    $address_row = wpinv_get_invoice_address_markup( $billing_details );
984
+    $address_row = wpinv_get_invoice_address_markup($billing_details);
985 985
 
986
-    if ( $address_row ) {
986
+    if ($address_row) {
987 987
         $output .= '<div class="address">' . $address_row . '</div>';
988 988
     }
989 989
 
990
-    if ( $phone = $invoice->get_phone() ) {
991
-        $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s', 'invoicing' ), esc_html( $phone ) ) . '</div>';
990
+    if ($phone = $invoice->get_phone()) {
991
+        $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s', 'invoicing'), esc_html($phone)) . '</div>';
992 992
     }
993
-    if ( $email = $invoice->get_email() ) {
994
-        $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' , 'invoicing'), esc_html( $email ) ) . '</div>';
993
+    if ($email = $invoice->get_email()) {
994
+        $output .= '<div class="email">' . wp_sprintf(__('Email: %s', 'invoicing'), esc_html($email)) . '</div>';
995 995
     }
996 996
 
997 997
     ob_start();
998
-    do_action( 'wpinv_display_to_address_bottom', $invoice );
998
+    do_action('wpinv_display_to_address_bottom', $invoice);
999 999
     $output .= ob_get_clean();
1000 1000
     
1001 1001
     $output .= '</div>';
1002
-    $output = apply_filters( 'wpinv_display_to_address', $output, $invoice );
1002
+    $output = apply_filters('wpinv_display_to_address', $output, $invoice);
1003 1003
 
1004 1004
     echo $output;
1005 1005
 }
1006 1006
 
1007
-function wpinv_display_line_items( $invoice_id = 0 ) {
1007
+function wpinv_display_line_items($invoice_id = 0) {
1008 1008
     global $wpinv_euvat, $ajax_cart_details;
1009
-    $invoice            = wpinv_get_invoice( $invoice_id );
1009
+    $invoice            = wpinv_get_invoice($invoice_id);
1010 1010
     $quantities_enabled = wpinv_item_quantities_enabled();
1011 1011
     $use_taxes          = wpinv_use_taxes();
1012
-    if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) {
1012
+    if (!$use_taxes && (float) $invoice->get_tax() > 0) {
1013 1013
         $use_taxes = true;
1014 1014
     }
1015
-    $zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
1016
-    $tax_label           = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
1017
-    $tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
1015
+    $zero_tax           = !(float) $invoice->get_tax() > 0 ? true : false;
1016
+    $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
1017
+    $tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
1018 1018
 
1019 1019
     $cart_details       = $invoice->get_cart_details();
1020 1020
     $ajax_cart_details  = $cart_details;
@@ -1023,67 +1023,67 @@  discard block
 block discarded – undo
1023 1023
     <table class="table table-sm table-bordered">
1024 1024
         <thead>
1025 1025
             <tr>
1026
-                <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th>
1027
-                <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th>
1026
+                <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th>
1027
+                <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th>
1028 1028
                 <?php if ($quantities_enabled) { ?>
1029
-                    <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th>
1029
+                    <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th>
1030 1030
                 <?php } ?>
1031 1031
                 <?php if ($use_taxes && !$zero_tax) { ?>
1032 1032
                     <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th>
1033 1033
                 <?php } ?>
1034
-                <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th>
1034
+                <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th>
1035 1035
             </tr>
1036 1036
         </thead>
1037 1037
         <tbody>
1038 1038
         <?php 
1039
-            if ( !empty( $cart_details ) ) {
1040
-                do_action( 'wpinv_display_line_items_start', $invoice );
1039
+            if (!empty($cart_details)) {
1040
+                do_action('wpinv_display_line_items_start', $invoice);
1041 1041
 
1042 1042
                 $count = 0;
1043 1043
                 $cols  = 3;
1044
-                foreach ( $cart_details as $key => $cart_item ) {
1045
-                    $item_id    = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : '';
1046
-                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount( $cart_item["item_price"] ) : 0;
1047
-                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount( $cart_item["subtotal"] ) : 0;
1048
-                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1;
1044
+                foreach ($cart_details as $key => $cart_item) {
1045
+                    $item_id    = !empty($cart_item['id']) ? absint($cart_item['id']) : '';
1046
+                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount($cart_item["item_price"]) : 0;
1047
+                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount($cart_item["subtotal"]) : 0;
1048
+                    $quantity   = !empty($cart_item['quantity']) && (int) $cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1;
1049 1049
 
1050
-                    $item       = $item_id ? new WPInv_Item( $item_id ) : NULL;
1050
+                    $item       = $item_id ? new WPInv_Item($item_id) : NULL;
1051 1051
                     $summary    = '';
1052
-	                $item_name    = '';
1052
+	                $item_name = '';
1053 1053
                     $cols       = 3;
1054
-                    if ( !empty($item) ) {
1054
+                    if (!empty($item)) {
1055 1055
                         $item_name  = $item->get_name();
1056 1056
                         $summary    = $item->get_summary();
1057 1057
                     }
1058
-                    $item_name  = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1058
+                    $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1059 1059
 
1060
-                    $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice );
1060
+                    $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice);
1061 1061
 
1062 1062
                     $item_tax       = '';
1063 1063
                     $tax_rate       = '';
1064
-                    if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1065
-                        $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ), $invoice->get_currency() );
1066
-                        $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1067
-                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1064
+                    if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1065
+                        $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']), $invoice->get_currency());
1066
+                        $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1067
+                        $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : '';
1068 1068
                         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : '';
1069 1069
                     }
1070 1070
 
1071 1071
                     $line_item_tax = $item_tax . $tax_rate;
1072 1072
 
1073
-                    if ( $line_item_tax === '' ) {
1073
+                    if ($line_item_tax === '') {
1074 1074
                         $line_item_tax = 0; // Zero tax
1075 1075
                     }
1076 1076
 
1077
-                    $action = apply_filters( 'wpinv_display_line_item_action', '', $cart_item, $invoice, $cols );
1077
+                    $action = apply_filters('wpinv_display_line_item_action', '', $cart_item, $invoice, $cols);
1078 1078
 
1079
-                    $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">';
1080
-                        $line_item .= '<td class="name">' . $action. esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item );
1081
-                        if ( $summary !== '' ) {
1082
-                            $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>';
1079
+                    $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">';
1080
+                        $line_item .= '<td class="name">' . $action . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item);
1081
+                        if ($summary !== '') {
1082
+                            $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>';
1083 1083
                         }
1084 1084
                         $line_item .= '</td>';
1085 1085
 
1086
-                        $line_item .= '<td class="rate">' . esc_html__( wpinv_price( wpinv_format_amount( $item_price ), $invoice->get_currency() ) ) . '</td>';
1086
+                        $line_item .= '<td class="rate">' . esc_html__(wpinv_price(wpinv_format_amount($item_price), $invoice->get_currency())) . '</td>';
1087 1087
                         if ($quantities_enabled) {
1088 1088
                             $cols++;
1089 1089
                             $line_item .= '<td class="qty">' . $quantity . '</td>';
@@ -1092,55 +1092,55 @@  discard block
 block discarded – undo
1092 1092
                             $cols++;
1093 1093
                             $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1094 1094
                         }
1095
-                        $line_item .= '<td class="total">' . esc_html__( wpinv_price( wpinv_format_amount( $line_total ), $invoice->get_currency() ) ) . '</td>';
1095
+                        $line_item .= '<td class="total">' . esc_html__(wpinv_price(wpinv_format_amount($line_total), $invoice->get_currency())) . '</td>';
1096 1096
                     $line_item .= '</tr>';
1097 1097
 
1098
-                    echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols );
1098
+                    echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols);
1099 1099
 
1100 1100
                     $count++;
1101 1101
                 }
1102 1102
 
1103
-                do_action( 'wpinv_display_before_subtotal', $invoice, $cols );
1103
+                do_action('wpinv_display_before_subtotal', $invoice, $cols);
1104 1104
                 ?>
1105 1105
                 <tr class="row-sub-total row_odd">
1106
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1107
-                    <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1106
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1107
+                    <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1108 1108
                 </tr>
1109 1109
                 <?php
1110
-                do_action( 'wpinv_display_after_subtotal', $invoice, $cols );
1110
+                do_action('wpinv_display_after_subtotal', $invoice, $cols);
1111 1111
                 
1112
-                if ( wpinv_discount( $invoice_id, false ) > 0 ) {
1113
-                    do_action( 'wpinv_display_before_discount', $invoice, $cols );
1112
+                if (wpinv_discount($invoice_id, false) > 0) {
1113
+                    do_action('wpinv_display_before_discount', $invoice, $cols);
1114 1114
                     ?>
1115 1115
                         <tr class="row-discount">
1116
-                            <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td>
1117
-                            <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1116
+                            <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td>
1117
+                            <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1118 1118
                         </tr>
1119 1119
                     <?php
1120
-                    do_action( 'wpinv_display_after_discount', $invoice, $cols );
1120
+                    do_action('wpinv_display_after_discount', $invoice, $cols);
1121 1121
                 }
1122 1122
 
1123
-                if ( $use_taxes ) {
1124
-                    do_action( 'wpinv_display_before_tax', $invoice, $cols );
1123
+                if ($use_taxes) {
1124
+                    do_action('wpinv_display_before_tax', $invoice, $cols);
1125 1125
                     ?>
1126 1126
                     <tr class="row-tax">
1127
-                        <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td>
1128
-                        <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1127
+                        <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td>
1128
+                        <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1129 1129
                     </tr>
1130 1130
                     <?php
1131
-                    do_action( 'wpinv_display_after_tax', $invoice, $cols );
1131
+                    do_action('wpinv_display_after_tax', $invoice, $cols);
1132 1132
                 }
1133 1133
 
1134
-                do_action( 'wpinv_display_before_total', $invoice, $cols );
1134
+                do_action('wpinv_display_before_total', $invoice, $cols);
1135 1135
                 ?>
1136 1136
                 <tr class="table-active row-total">
1137
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1138
-                    <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1137
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1138
+                    <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1139 1139
                 </tr>
1140 1140
                 <?php
1141
-                do_action( 'wpinv_display_after_total', $invoice, $cols );
1141
+                do_action('wpinv_display_after_total', $invoice, $cols);
1142 1142
 
1143
-                do_action( 'wpinv_display_line_end', $invoice, $cols );
1143
+                do_action('wpinv_display_line_end', $invoice, $cols);
1144 1144
             }
1145 1145
         ?>
1146 1146
         </tbody>
@@ -1152,56 +1152,56 @@  discard block
 block discarded – undo
1152 1152
 /**
1153 1153
  * @param WPInv_Invoice $invoice
1154 1154
  */
1155
-function wpinv_display_invoice_notes( $invoice ) {
1155
+function wpinv_display_invoice_notes($invoice) {
1156 1156
 
1157
-    $notes = wpinv_get_invoice_notes( $invoice->ID, 'customer' );
1157
+    $notes = wpinv_get_invoice_notes($invoice->ID, 'customer');
1158 1158
 
1159
-    if ( empty( $notes ) ) {
1159
+    if (empty($notes)) {
1160 1160
         return;
1161 1161
     }
1162 1162
 
1163 1163
     echo '<div class="wpi_invoice_notes_container">';
1164
-    echo '<h2>' . __( 'Invoice Notes', 'invoicing' ) .'</h2>';
1164
+    echo '<h2>' . __('Invoice Notes', 'invoicing') . '</h2>';
1165 1165
     echo '<ul class="wpi_invoice_notes">';
1166 1166
 
1167
-    foreach( $notes as $note ) {
1168
-        wpinv_get_invoice_note_line_item( $note );
1167
+    foreach ($notes as $note) {
1168
+        wpinv_get_invoice_note_line_item($note);
1169 1169
     }
1170 1170
 
1171 1171
     echo '</ul>';
1172 1172
     echo '</div>';
1173 1173
 }
1174
-add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_display_invoice_notes' );
1174
+add_action('wpinv_invoice_print_after_line_items', 'wpinv_display_invoice_notes');
1175 1175
 
1176
-function wpinv_display_invoice_totals( $invoice_id = 0 ) {
1176
+function wpinv_display_invoice_totals($invoice_id = 0) {
1177 1177
     $use_taxes = wpinv_use_taxes();
1178 1178
 
1179
-    do_action( 'wpinv_before_display_totals_table', $invoice_id ); 
1179
+    do_action('wpinv_before_display_totals_table', $invoice_id); 
1180 1180
     ?>
1181 1181
     <table class="table table-sm table-bordered table-responsive">
1182 1182
         <tbody>
1183
-            <?php do_action( 'wpinv_before_display_totals' ); ?>
1183
+            <?php do_action('wpinv_before_display_totals'); ?>
1184 1184
             <tr class="row-sub-total">
1185
-                <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td>
1186
-                <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1185
+                <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td>
1186
+                <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1187 1187
             </tr>
1188
-            <?php do_action( 'wpinv_after_display_totals' ); ?>
1189
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
1188
+            <?php do_action('wpinv_after_display_totals'); ?>
1189
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
1190 1190
                 <tr class="row-discount">
1191
-                    <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td>
1192
-                    <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1191
+                    <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td>
1192
+                    <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1193 1193
                 </tr>
1194
-            <?php do_action( 'wpinv_after_display_discount' ); ?>
1194
+            <?php do_action('wpinv_after_display_discount'); ?>
1195 1195
             <?php } ?>
1196
-            <?php if ( $use_taxes ) { ?>
1196
+            <?php if ($use_taxes) { ?>
1197 1197
             <tr class="row-tax">
1198
-                <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td>
1199
-                <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1198
+                <td class="rate"><?php _e('Tax', 'invoicing'); ?></td>
1199
+                <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1200 1200
             </tr>
1201
-            <?php do_action( 'wpinv_after_display_tax' ); ?>
1201
+            <?php do_action('wpinv_after_display_tax'); ?>
1202 1202
             <?php } ?>
1203
-            <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?>
1204
-                <?php foreach ( $fees as $fee ) { ?>
1203
+            <?php if ($fees = wpinv_get_fees($invoice_id)) { ?>
1204
+                <?php foreach ($fees as $fee) { ?>
1205 1205
                     <tr class="row-fee">
1206 1206
                         <td class="rate"><?php echo $fee['label']; ?></td>
1207 1207
                         <td class="total"><?php echo $fee['amount_display']; ?></td>
@@ -1209,82 +1209,82 @@  discard block
 block discarded – undo
1209 1209
                 <?php } ?>
1210 1210
             <?php } ?>
1211 1211
             <tr class="table-active row-total">
1212
-                <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td>
1213
-                <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1212
+                <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td>
1213
+                <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1214 1214
             </tr>
1215
-            <?php do_action( 'wpinv_after_totals' ); ?>
1215
+            <?php do_action('wpinv_after_totals'); ?>
1216 1216
         </tbody>
1217 1217
 
1218 1218
     </table>
1219 1219
 
1220
-    <?php do_action( 'wpinv_after_totals_table' );
1220
+    <?php do_action('wpinv_after_totals_table');
1221 1221
 }
1222 1222
 
1223
-function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) {
1224
-    $invoice = wpinv_get_invoice( $invoice_id );
1223
+function wpinv_display_payments_info($invoice_id = 0, $echo = true) {
1224
+    $invoice = wpinv_get_invoice($invoice_id);
1225 1225
 
1226 1226
     ob_start();
1227
-    do_action( 'wpinv_before_display_payments_info', $invoice_id );
1228
-    if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() || $invoice->is_refunded() ) {
1227
+    do_action('wpinv_before_display_payments_info', $invoice_id);
1228
+    if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid() || $invoice->is_refunded()) {
1229 1229
         ?>
1230 1230
         <div class="wpi-payment-info">
1231
-            <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p>
1232
-            <?php if ( $gateway_title ) { ?>
1233
-            <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p>
1231
+            <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p>
1232
+            <?php if ($gateway_title) { ?>
1233
+            <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p>
1234 1234
             <?php } ?>
1235 1235
         </div>
1236 1236
         <?php
1237 1237
     }
1238
-    do_action( 'wpinv_after_display_payments_info', $invoice_id );
1238
+    do_action('wpinv_after_display_payments_info', $invoice_id);
1239 1239
     $outout = ob_get_clean();
1240 1240
 
1241
-    if ( $echo ) {
1241
+    if ($echo) {
1242 1242
         echo $outout;
1243 1243
     } else {
1244 1244
         return $outout;
1245 1245
     }
1246 1246
 }
1247 1247
 
1248
-function wpinv_display_style( $invoice ) {
1249
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION );
1248
+function wpinv_display_style($invoice) {
1249
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION);
1250 1250
 
1251
-    wp_print_styles( 'open-sans' );
1252
-    wp_print_styles( 'wpinv-single-style' );
1251
+    wp_print_styles('open-sans');
1252
+    wp_print_styles('wpinv-single-style');
1253 1253
 
1254 1254
     $custom_css = wpinv_get_option('template_custom_css');
1255
-    if(isset($custom_css) && !empty($custom_css)){
1256
-        $custom_css     = wp_kses( $custom_css, array( '\'', '\"' ) );
1257
-        $custom_css     = str_replace( '&gt;', '>', $custom_css );
1255
+    if (isset($custom_css) && !empty($custom_css)) {
1256
+        $custom_css     = wp_kses($custom_css, array('\'', '\"'));
1257
+        $custom_css     = str_replace('&gt;', '>', $custom_css);
1258 1258
         echo '<style type="text/css">';
1259 1259
         echo $custom_css;
1260 1260
         echo '</style>';
1261 1261
     }
1262 1262
 }
1263
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
1264
-add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' );
1263
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
1264
+add_action('wpinv_invalid_invoice_head', 'wpinv_display_style');
1265 1265
 
1266 1266
 function wpinv_checkout_billing_details() {
1267
-    $invoice_id = (int)wpinv_get_invoice_cart_id();
1267
+    $invoice_id = (int) wpinv_get_invoice_cart_id();
1268 1268
     if (empty($invoice_id)) {
1269
-        wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ );
1269
+        wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__);
1270 1270
         return null;
1271 1271
     }
1272 1272
 
1273
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
1273
+    $invoice = wpinv_get_invoice_cart($invoice_id);
1274 1274
     if (empty($invoice)) {
1275
-        wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ );
1275
+        wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__);
1276 1276
         return null;
1277 1277
     }
1278 1278
     $user_id        = $invoice->get_user_id();
1279 1279
     $user_info      = $invoice->get_user_info();
1280
-    $address_info   = wpinv_get_user_address( $user_id );
1280
+    $address_info   = wpinv_get_user_address($user_id);
1281 1281
 
1282
-    if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) {
1282
+    if (empty($user_info['first_name']) && !empty($user_info['first_name'])) {
1283 1283
         $user_info['first_name'] = $user_info['first_name'];
1284 1284
         $user_info['last_name'] = $user_info['last_name'];
1285 1285
     }
1286 1286
 
1287
-    if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) {
1287
+    if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) {
1288 1288
         $user_info['country']   = $address_info['country'];
1289 1289
         $user_info['state']     = $address_info['state'];
1290 1290
         $user_info['city']      = $address_info['city'];
@@ -1300,99 +1300,99 @@  discard block
 block discarded – undo
1300 1300
         'address'
1301 1301
     );
1302 1302
 
1303
-    foreach ( $address_fields as $field ) {
1304
-        if ( empty( $user_info[$field] ) ) {
1303
+    foreach ($address_fields as $field) {
1304
+        if (empty($user_info[$field])) {
1305 1305
             $user_info[$field] = $address_info[$field];
1306 1306
         }
1307 1307
     }
1308 1308
 
1309
-    return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice );
1309
+    return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice);
1310 1310
 }
1311 1311
 
1312 1312
 function wpinv_admin_get_line_items($invoice = array()) {
1313 1313
     $item_quantities    = wpinv_item_quantities_enabled();
1314 1314
     $use_taxes          = wpinv_use_taxes();
1315 1315
 
1316
-    if ( empty( $invoice ) ) {
1316
+    if (empty($invoice)) {
1317 1317
         return NULL;
1318 1318
     }
1319 1319
 
1320 1320
     $cart_items = $invoice->get_cart_details();
1321
-    if ( empty( $cart_items ) ) {
1321
+    if (empty($cart_items)) {
1322 1322
         return NULL;
1323 1323
     }
1324 1324
 
1325 1325
     ob_start();
1326 1326
 
1327
-    do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice );
1327
+    do_action('wpinv_admin_before_line_items', $cart_items, $invoice);
1328 1328
 
1329 1329
     $count = 0;
1330
-    foreach ( $cart_items as $key => $cart_item ) {
1330
+    foreach ($cart_items as $key => $cart_item) {
1331 1331
         $item_id    = $cart_item['id'];
1332
-        $wpi_item   = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL;
1332
+        $wpi_item   = $item_id > 0 ? new WPInv_Item($item_id) : NULL;
1333 1333
 
1334 1334
         if (empty($wpi_item)) {
1335 1335
             continue;
1336 1336
         }
1337 1337
 
1338
-        $item_price     = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ), $invoice->get_currency() );
1339
-        $quantity       = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1340
-        $item_subtotal  = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ), $invoice->get_currency() );
1338
+        $item_price     = wpinv_price(wpinv_format_amount($cart_item['item_price']), $invoice->get_currency());
1339
+        $quantity       = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1340
+        $item_subtotal  = wpinv_price(wpinv_format_amount($cart_item['subtotal']), $invoice->get_currency());
1341 1341
         $can_remove     = true;
1342 1342
 
1343
-        $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', '', $cart_item, $wpi_item, $invoice );
1343
+        $summary = apply_filters('wpinv_admin_invoice_line_item_summary', '', $cart_item, $wpi_item, $invoice);
1344 1344
 
1345 1345
         $item_tax       = '';
1346 1346
         $tax_rate       = '';
1347
-        if ( $invoice->is_taxable() && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1348
-            $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ), $invoice->get_currency() );
1349
-            $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1350
-            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1347
+        if ($invoice->is_taxable() && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1348
+            $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']), $invoice->get_currency());
1349
+            $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1350
+            $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : '';
1351 1351
             $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : '';
1352 1352
         }
1353 1353
         $line_item_tax = $item_tax . $tax_rate;
1354 1354
 
1355
-        if ( $line_item_tax === '' ) {
1355
+        if ($line_item_tax === '') {
1356 1356
             $line_item_tax = 0; // Zero tax
1357 1357
         }
1358 1358
 
1359
-        $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">';
1359
+        $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">';
1360 1360
             $line_item .= '<td class="id">' . $item_id . '</td>';
1361
-            $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item );
1362
-            if ( $summary !== '' ) {
1363
-                $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>';
1361
+            $line_item .= '<td class="title"><a href="' . get_edit_post_link($item_id) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix($wpi_item);
1362
+            if ($summary !== '') {
1363
+                $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>';
1364 1364
             }
1365 1365
             $line_item .= '</td>';
1366 1366
             $line_item .= '<td class="price">' . $item_price . '</td>';
1367 1367
             
1368
-            if ( $item_quantities ) {
1369
-                if ( count( $cart_items ) == 1 && $quantity <= 1 ) {
1368
+            if ($item_quantities) {
1369
+                if (count($cart_items) == 1 && $quantity <= 1) {
1370 1370
                     $can_remove = false;
1371 1371
                 }
1372 1372
                 $line_item .= '<td class="qty" data-quantity="' . $quantity . '">&nbsp;&times;&nbsp;' . $quantity . '</td>';
1373 1373
             } else {
1374
-                if ( count( $cart_items ) == 1 ) {
1374
+                if (count($cart_items) == 1) {
1375 1375
                     $can_remove = false;
1376 1376
                 }
1377 1377
             }
1378 1378
             $line_item .= '<td class="total">' . $item_subtotal . '</td>';
1379 1379
             
1380
-            if ( $use_taxes ) {
1380
+            if ($use_taxes) {
1381 1381
                 $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1382 1382
             }
1383 1383
             $line_item .= '<td class="action">';
1384
-            if ( !$invoice->is_paid() && !$invoice->is_refunded() ) {
1384
+            if (!$invoice->is_paid() && !$invoice->is_refunded()) {
1385 1385
                 $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>';
1386 1386
             }
1387 1387
             $line_item .= '</td>';
1388 1388
         $line_item .= '</tr>';
1389 1389
 
1390
-        echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice );
1390
+        echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice);
1391 1391
 
1392 1392
         $count++;
1393 1393
     } 
1394 1394
 
1395
-    do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice );
1395
+    do_action('wpinv_admin_after_line_items', $cart_items, $invoice);
1396 1396
 
1397 1397
     return ob_get_clean();
1398 1398
 }
@@ -1402,70 +1402,70 @@  discard block
 block discarded – undo
1402 1402
 
1403 1403
     // Set current invoice id.
1404 1404
     $wpi_checkout_id = wpinv_get_invoice_cart_id();
1405
-    $form_action     = esc_url( wpinv_get_checkout_uri() );
1405
+    $form_action     = esc_url(wpinv_get_checkout_uri());
1406 1406
     $payment_form    = wpinv_get_default_payment_form();
1407 1407
 
1408 1408
     ob_start();
1409
-	    do_action( 'wpinv_checkout_content_before' );
1409
+	    do_action('wpinv_checkout_content_before');
1410 1410
 
1411
-        if ( wpinv_get_cart_contents() ) {
1411
+        if (wpinv_get_cart_contents()) {
1412 1412
 
1413 1413
             // Get the form elements and items.
1414
-	        $elements = $invoicing->form_elements->get_form_elements( $payment_form );
1415
-	        $items    = $invoicing->form_elements->convert_checkout_items( wpinv_get_cart_contents(), wpinv_get_invoice_cart() );
1414
+	        $elements = $invoicing->form_elements->get_form_elements($payment_form);
1415
+	        $items    = $invoicing->form_elements->convert_checkout_items(wpinv_get_cart_contents(), wpinv_get_invoice_cart());
1416 1416
             ?>
1417 1417
             <form class="wpinv_payment_form" action="<?php echo $form_action; ?>" method="POST">
1418
-                <?php do_action( 'wpinv_main_checkout_form_top' ); ?>
1419
-                <input type='hidden' name='form_id' value='<?php echo esc_attr( $payment_form ); ?>'/>
1420
-                <input type='hidden' name='invoice_id' value='<?php echo esc_attr( $wpi_checkout_id ); ?>'/>
1418
+                <?php do_action('wpinv_main_checkout_form_top'); ?>
1419
+                <input type='hidden' name='form_id' value='<?php echo esc_attr($payment_form); ?>'/>
1420
+                <input type='hidden' name='invoice_id' value='<?php echo esc_attr($wpi_checkout_id); ?>'/>
1421 1421
                     <?php
1422
-                        wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
1423
-                        wp_nonce_field( 'vat_validation', '_wpi_nonce' );
1422
+                        wp_nonce_field('wpinv_payment_form', 'wpinv_payment_form');
1423
+                        wp_nonce_field('vat_validation', '_wpi_nonce');
1424 1424
 
1425
-                        foreach ( $elements as $element ) {
1426
-                            do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $payment_form );
1427
-                            do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $payment_form );
1425
+                        foreach ($elements as $element) {
1426
+                            do_action('wpinv_frontend_render_payment_form_element', $element, $items, $payment_form);
1427
+                            do_action("wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $payment_form);
1428 1428
                         }
1429 1429
                     ?>
1430 1430
                 <div class='wpinv_payment_form_errors alert alert-danger d-none'></div>
1431
-                <?php do_action( 'wpinv_main_checkout_form_bottom' ); ?>
1431
+                <?php do_action('wpinv_main_checkout_form_bottom'); ?>
1432 1432
             </form>
1433 1433
         <?php
1434 1434
 
1435 1435
         } else {
1436
-            do_action( 'wpinv_cart_empty' );
1436
+            do_action('wpinv_cart_empty');
1437 1437
         }
1438 1438
         echo '</div><!--end #wpinv_checkout_wrap-->';
1439
-	    do_action( 'wpinv_checkout_content_after' );
1439
+	    do_action('wpinv_checkout_content_after');
1440 1440
         $content = ob_get_clean();
1441 1441
 
1442
-		return str_replace( 'sr-only', '', $content );
1442
+		return str_replace('sr-only', '', $content);
1443 1443
 }
1444 1444
 
1445
-function wpinv_checkout_cart( $cart_details = array(), $echo = true ) {
1445
+function wpinv_checkout_cart($cart_details = array(), $echo = true) {
1446 1446
     global $ajax_cart_details;
1447 1447
     $ajax_cart_details = $cart_details;
1448 1448
 
1449 1449
     ob_start();
1450
-    do_action( 'wpinv_before_checkout_cart' );
1450
+    do_action('wpinv_before_checkout_cart');
1451 1451
     echo '<div id="wpinv_checkout_cart_form" method="post">';
1452 1452
         echo '<div id="wpinv_checkout_cart_wrap">';
1453
-            wpinv_get_template_part( 'wpinv-checkout-cart' );
1453
+            wpinv_get_template_part('wpinv-checkout-cart');
1454 1454
         echo '</div>';
1455 1455
     echo '</div>';
1456
-    do_action( 'wpinv_after_checkout_cart' );
1456
+    do_action('wpinv_after_checkout_cart');
1457 1457
     $content = ob_get_clean();
1458 1458
 
1459
-    if ( $echo ) {
1459
+    if ($echo) {
1460 1460
         echo $content;
1461 1461
     } else {
1462 1462
         return $content;
1463 1463
     }
1464 1464
 }
1465
-add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 );
1465
+add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10);
1466 1466
 
1467 1467
 function wpinv_empty_cart_message() {
1468
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1468
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1469 1469
 }
1470 1470
 
1471 1471
 /**
@@ -1482,83 +1482,83 @@  discard block
 block discarded – undo
1482 1482
         )
1483 1483
     );
1484 1484
 }
1485
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1485
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1486 1486
 
1487 1487
 function wpinv_update_cart_button() {
1488
-    if ( !wpinv_item_quantities_enabled() )
1488
+    if (!wpinv_item_quantities_enabled())
1489 1489
         return;
1490 1490
 ?>
1491
-    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/>
1491
+    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/>
1492 1492
     <input type="hidden" name="wpi_action" value="update_cart"/>
1493 1493
 <?php
1494 1494
 }
1495 1495
 
1496 1496
 function wpinv_checkout_cart_columns() {
1497 1497
     $default = 3;
1498
-    if ( wpinv_item_quantities_enabled() ) {
1498
+    if (wpinv_item_quantities_enabled()) {
1499 1499
         $default++;
1500 1500
     }
1501 1501
     
1502
-    if ( wpinv_use_taxes() ) {
1502
+    if (wpinv_use_taxes()) {
1503 1503
         $default++;
1504 1504
     }
1505 1505
 
1506
-    return apply_filters( 'wpinv_checkout_cart_columns', $default );
1506
+    return apply_filters('wpinv_checkout_cart_columns', $default);
1507 1507
 }
1508 1508
 
1509 1509
 function wpinv_display_cart_messages() {
1510 1510
     global $wpi_session;
1511 1511
 
1512
-    $messages = $wpi_session->get( 'wpinv_cart_messages' );
1512
+    $messages = $wpi_session->get('wpinv_cart_messages');
1513 1513
 
1514
-    if ( $messages ) {
1515
-        foreach ( $messages as $message_id => $message ) {
1514
+    if ($messages) {
1515
+        foreach ($messages as $message_id => $message) {
1516 1516
             // Try and detect what type of message this is
1517
-            if ( strpos( strtolower( $message ), 'error' ) ) {
1517
+            if (strpos(strtolower($message), 'error')) {
1518 1518
                 $type = 'error';
1519
-            } elseif ( strpos( strtolower( $message ), 'success' ) ) {
1519
+            } elseif (strpos(strtolower($message), 'success')) {
1520 1520
                 $type = 'success';
1521 1521
             } else {
1522 1522
                 $type = 'info';
1523 1523
             }
1524 1524
 
1525
-            $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) );
1525
+            $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type));
1526 1526
 
1527
-            echo '<div class="' . implode( ' ', $classes ) . '">';
1527
+            echo '<div class="' . implode(' ', $classes) . '">';
1528 1528
                 // Loop message codes and display messages
1529 1529
                     echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>';
1530 1530
             echo '</div>';
1531 1531
         }
1532 1532
 
1533 1533
         // Remove all of the cart saving messages
1534
-        $wpi_session->set( 'wpinv_cart_messages', null );
1534
+        $wpi_session->set('wpinv_cart_messages', null);
1535 1535
     }
1536 1536
 }
1537
-add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' );
1537
+add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages');
1538 1538
 
1539 1539
 function wpinv_discount_field() {
1540
-    if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) {
1540
+    if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) {
1541 1541
         return; // Only show before a payment method has been selected if ajax is disabled
1542 1542
     }
1543 1543
 
1544
-    if ( !wpinv_is_checkout() ) {
1544
+    if (!wpinv_is_checkout()) {
1545 1545
         return;
1546 1546
     }
1547 1547
 
1548
-    if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) {
1548
+    if (wpinv_has_active_discounts() && wpinv_get_cart_total()) {
1549 1549
     ?>
1550 1550
     <div id="wpinv-discount-field" class="panel panel-default">
1551 1551
         <div class="panel-body">
1552 1552
             <p>
1553
-                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label>
1554
-                <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span>
1553
+                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label>
1554
+                <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span>
1555 1555
             </p>
1556 1556
             <div class="form-group row">
1557 1557
                 <div class="col-sm-4">
1558
-                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/>
1558
+                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/>
1559 1559
                 </div>
1560 1560
                 <div class="col-sm-3">
1561
-                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button>
1561
+                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button>
1562 1562
                 </div>
1563 1563
                 <div style="clear:both"></div>
1564 1564
                 <div class="col-sm-12 wpinv-discount-msg">
@@ -1571,10 +1571,10 @@  discard block
 block discarded – undo
1571 1571
 <?php
1572 1572
     }
1573 1573
 }
1574
-add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 );
1574
+add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10);
1575 1575
 
1576 1576
 function wpinv_agree_to_terms_js() {
1577
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
1577
+    if (wpinv_get_option('show_agree_to_terms', false)) {
1578 1578
 ?>
1579 1579
 <script type="text/javascript">
1580 1580
     jQuery(document).ready(function($){
@@ -1589,125 +1589,125 @@  discard block
 block discarded – undo
1589 1589
 <?php
1590 1590
     }
1591 1591
 }
1592
-add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' );
1592
+add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js');
1593 1593
 
1594 1594
 function wpinv_payment_mode_select() {
1595
-    $gateways = wpinv_get_enabled_payment_gateways( true );
1596
-    $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways );
1597
-    $invoice = wpinv_get_invoice( 0, true );
1595
+    $gateways = wpinv_get_enabled_payment_gateways(true);
1596
+    $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways);
1597
+    $invoice = wpinv_get_invoice(0, true);
1598 1598
 
1599 1599
     do_action('wpinv_payment_mode_top');
1600
-    $invoice_id = $invoice ? (int)$invoice->ID : 0;
1601
-    $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id );
1600
+    $invoice_id = $invoice ? (int) $invoice->ID : 0;
1601
+    $chosen_gateway = wpinv_get_chosen_gateway($invoice_id);
1602 1602
     ?>
1603
-    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( ( $invoice && $invoice->is_free() ) ? 'style="display:none;" data-free="1"' : '' ); ?>>
1604
-            <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?>
1603
+    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo (($invoice && $invoice->is_free()) ? 'style="display:none;" data-free="1"' : ''); ?>>
1604
+            <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?>
1605 1605
             <div id="wpinv-payment-mode-wrap" class="panel panel-default">
1606
-                <div class="panel-heading wpi-payment_methods_title"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div>
1606
+                <div class="panel-heading wpi-payment_methods_title"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div>
1607 1607
                 <div class="panel-body list-group wpi-payment_methods">
1608 1608
                     <?php
1609
-                    do_action( 'wpinv_payment_mode_before_gateways' );
1610
-
1611
-                    if ( !empty( $gateways ) ) {
1612
-                        foreach ( $gateways as $gateway_id => $gateway ) {
1613
-                            $checked       = checked( $gateway_id, $chosen_gateway, false );
1614
-                            $button_label  = wpinv_get_gateway_button_label( $gateway_id );
1615
-                            $gateway_label = wpinv_get_gateway_checkout_label( $gateway_id );
1616
-                            $description   = wpinv_get_gateway_description( $gateway_id );
1609
+                    do_action('wpinv_payment_mode_before_gateways');
1610
+
1611
+                    if (!empty($gateways)) {
1612
+                        foreach ($gateways as $gateway_id => $gateway) {
1613
+                            $checked       = checked($gateway_id, $chosen_gateway, false);
1614
+                            $button_label  = wpinv_get_gateway_button_label($gateway_id);
1615
+                            $gateway_label = wpinv_get_gateway_checkout_label($gateway_id);
1616
+                            $description   = wpinv_get_gateway_description($gateway_id);
1617 1617
                             ?>
1618 1618
                             <div class="list-group-item">
1619 1619
                                 <div class="radio">
1620
-                                    <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway_label ); ?></label>
1620
+                                    <label><input type="radio" data-button-text="<?php echo esc_attr($button_label); ?>" value="<?php echo esc_attr($gateway_id); ?>" <?php echo $checked; ?> id="wpi_gateway_<?php echo esc_attr($gateway_id); ?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html($gateway_label); ?></label>
1621 1621
                                 </div>
1622
-                                <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert">
1623
-                                    <?php if ( !empty( $description ) ) { ?>
1624
-                                        <div class="wpi-gateway-desc alert alert-info"><?php _e( $description, 'invoicing' ); ?></div>
1622
+                                <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert">
1623
+                                    <?php if (!empty($description)) { ?>
1624
+                                        <div class="wpi-gateway-desc alert alert-info"><?php _e($description, 'invoicing'); ?></div>
1625 1625
                                     <?php } ?>
1626
-                                    <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?>
1626
+                                    <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?>
1627 1627
                                 </div>
1628 1628
                             </div>
1629 1629
                             <?php
1630 1630
                         }
1631 1631
                     } else {
1632
-                        echo '<div class="alert alert-warning">'. __( 'No payment gateway active', 'invoicing' ) .'</div>';
1632
+                        echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>';
1633 1633
                     }
1634 1634
 
1635
-                    do_action( 'wpinv_payment_mode_after_gateways' );
1635
+                    do_action('wpinv_payment_mode_after_gateways');
1636 1636
                     ?>
1637 1637
                 </div>
1638 1638
             </div>
1639
-            <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?>
1639
+            <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?>
1640 1640
     </div>
1641 1641
     <?php
1642 1642
     do_action('wpinv_payment_mode_bottom');
1643 1643
 }
1644
-add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' );
1644
+add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select');
1645 1645
 
1646 1646
 function wpinv_checkout_billing_info() {
1647
-    if ( wpinv_is_checkout() ) {
1647
+    if (wpinv_is_checkout()) {
1648 1648
         $billing_details    = wpinv_checkout_billing_details();
1649
-        $selected_country   = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country();
1649
+        $selected_country   = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country();
1650 1650
         ?>
1651 1651
         <div id="wpinv-fields" class="clearfix">
1652 1652
             <div id="wpi-billing" class="wpi-billing clearfix panel panel-default">
1653
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div>
1653
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div>
1654 1654
                 <div id="wpinv-fields-box" class="panel-body">
1655
-                    <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?>
1655
+                    <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?>
1656 1656
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1657
-                        <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><?php if ( wpinv_get_option( 'fname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1657
+                        <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><?php if (wpinv_get_option('fname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1658 1658
                         <?php
1659
-                        echo wpinv_html_text( array(
1659
+                        echo wpinv_html_text(array(
1660 1660
                                 'id'            => 'wpinv_first_name',
1661 1661
                                 'name'          => 'wpinv_first_name',
1662 1662
                                 'value'         => $billing_details['first_name'],
1663 1663
                                 'class'         => 'wpi-input form-control',
1664
-                                'placeholder'   => __( 'First name', 'invoicing' ),
1665
-                                'required'      => (bool)wpinv_get_option( 'fname_mandatory' ),
1666
-                            ) );
1664
+                                'placeholder'   => __('First name', 'invoicing'),
1665
+                                'required'      => (bool) wpinv_get_option('fname_mandatory'),
1666
+                            ));
1667 1667
                         ?>
1668 1668
                     </p>
1669 1669
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1670
-                        <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?><?php if ( wpinv_get_option( 'lname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1670
+                        <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?><?php if (wpinv_get_option('lname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1671 1671
                         <?php
1672
-                        echo wpinv_html_text( array(
1672
+                        echo wpinv_html_text(array(
1673 1673
                                 'id'            => 'wpinv_last_name',
1674 1674
                                 'name'          => 'wpinv_last_name',
1675 1675
                                 'value'         => $billing_details['last_name'],
1676 1676
                                 'class'         => 'wpi-input form-control',
1677
-                                'placeholder'   => __( 'Last name', 'invoicing' ),
1678
-                                'required'      => (bool)wpinv_get_option( 'lname_mandatory' ),
1679
-                            ) );
1677
+                                'placeholder'   => __('Last name', 'invoicing'),
1678
+                                'required'      => (bool) wpinv_get_option('lname_mandatory'),
1679
+                            ));
1680 1680
                         ?>
1681 1681
                     </p>
1682 1682
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1683
-                        <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><?php if ( wpinv_get_option( 'address_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1683
+                        <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><?php if (wpinv_get_option('address_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1684 1684
                         <?php
1685
-                        echo wpinv_html_text( array(
1685
+                        echo wpinv_html_text(array(
1686 1686
                                 'id'            => 'wpinv_address',
1687 1687
                                 'name'          => 'wpinv_address',
1688 1688
                                 'value'         => $billing_details['address'],
1689 1689
                                 'class'         => 'wpi-input form-control',
1690
-                                'placeholder'   => __( 'Address', 'invoicing' ),
1691
-                                'required'      => (bool)wpinv_get_option( 'address_mandatory' ),
1692
-                            ) );
1690
+                                'placeholder'   => __('Address', 'invoicing'),
1691
+                                'required'      => (bool) wpinv_get_option('address_mandatory'),
1692
+                            ));
1693 1693
                         ?>
1694 1694
                     </p>
1695 1695
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1696
-                        <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><?php if ( wpinv_get_option( 'city_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1696
+                        <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><?php if (wpinv_get_option('city_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1697 1697
                         <?php
1698
-                        echo wpinv_html_text( array(
1698
+                        echo wpinv_html_text(array(
1699 1699
                                 'id'            => 'wpinv_city',
1700 1700
                                 'name'          => 'wpinv_city',
1701 1701
                                 'value'         => $billing_details['city'],
1702 1702
                                 'class'         => 'wpi-input form-control',
1703
-                                'placeholder'   => __( 'City', 'invoicing' ),
1704
-                                'required'      => (bool)wpinv_get_option( 'city_mandatory' ),
1705
-                            ) );
1703
+                                'placeholder'   => __('City', 'invoicing'),
1704
+                                'required'      => (bool) wpinv_get_option('city_mandatory'),
1705
+                            ));
1706 1706
                         ?>
1707 1707
                     </p>
1708 1708
                     <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf">
1709
-                        <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><?php if ( wpinv_get_option( 'country_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1710
-                        <?php echo wpinv_html_select( array(
1709
+                        <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><?php if (wpinv_get_option('country_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1710
+                        <?php echo wpinv_html_select(array(
1711 1711
                             'options'          => wpinv_get_country_list(),
1712 1712
                             'name'             => 'wpinv_country',
1713 1713
                             'id'               => 'wpinv_country',
@@ -1715,16 +1715,16 @@  discard block
 block discarded – undo
1715 1715
                             'show_option_all'  => false,
1716 1716
                             'show_option_none' => false,
1717 1717
                             'class'            => 'wpi-input form-control wpi_select2',
1718
-                            'placeholder'      => __( 'Choose a country', 'invoicing' ),
1719
-                            'required'         => (bool)wpinv_get_option( 'country_mandatory' ),
1720
-                        ) ); ?>
1718
+                            'placeholder'      => __('Choose a country', 'invoicing'),
1719
+                            'required'         => (bool) wpinv_get_option('country_mandatory'),
1720
+                        )); ?>
1721 1721
                     </p>
1722 1722
                     <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll">
1723
-                        <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><?php if ( wpinv_get_option( 'state_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1723
+                        <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><?php if (wpinv_get_option('state_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1724 1724
                         <?php
1725
-                        $states = wpinv_get_country_states( $selected_country );
1726
-                        if( !empty( $states ) ) {
1727
-                            echo wpinv_html_select( array(
1725
+                        $states = wpinv_get_country_states($selected_country);
1726
+                        if (!empty($states)) {
1727
+                            echo wpinv_html_select(array(
1728 1728
                                 'options'          => $states,
1729 1729
                                 'name'             => 'wpinv_state',
1730 1730
                                 'id'               => 'wpinv_state',
@@ -1732,61 +1732,61 @@  discard block
 block discarded – undo
1732 1732
                                 'show_option_all'  => false,
1733 1733
                                 'show_option_none' => false,
1734 1734
                                 'class'            => 'wpi-input form-control wpi_select2',
1735
-                                'placeholder'      => __( 'Choose a state', 'invoicing' ),
1736
-                                'required'         => (bool)wpinv_get_option( 'state_mandatory' ),
1737
-                            ) );
1735
+                                'placeholder'      => __('Choose a state', 'invoicing'),
1736
+                                'required'         => (bool) wpinv_get_option('state_mandatory'),
1737
+                            ));
1738 1738
                         } else {
1739
-                            echo wpinv_html_text( array(
1739
+                            echo wpinv_html_text(array(
1740 1740
                                 'name'          => 'wpinv_state',
1741 1741
                                 'value'         => $billing_details['state'],
1742 1742
                                 'id'            => 'wpinv_state',
1743 1743
                                 'class'         => 'wpi-input form-control',
1744
-                                'placeholder'   => __( 'State / Province', 'invoicing' ),
1745
-                                'required'      => (bool)wpinv_get_option( 'state_mandatory' ),
1746
-                            ) );
1744
+                                'placeholder'   => __('State / Province', 'invoicing'),
1745
+                                'required'      => (bool) wpinv_get_option('state_mandatory'),
1746
+                            ));
1747 1747
                         }
1748 1748
                         ?>
1749 1749
                     </p>
1750 1750
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1751
-                        <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?><?php if ( wpinv_get_option( 'zip_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1751
+                        <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?><?php if (wpinv_get_option('zip_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1752 1752
                         <?php
1753
-                        echo wpinv_html_text( array(
1753
+                        echo wpinv_html_text(array(
1754 1754
                                 'name'          => 'wpinv_zip',
1755 1755
                                 'value'         => $billing_details['zip'],
1756 1756
                                 'id'            => 'wpinv_zip',
1757 1757
                                 'class'         => 'wpi-input form-control',
1758
-                                'placeholder'   => __( 'ZIP / Postcode', 'invoicing' ),
1759
-                                'required'      => (bool)wpinv_get_option( 'zip_mandatory' ),
1760
-                            ) );
1758
+                                'placeholder'   => __('ZIP / Postcode', 'invoicing'),
1759
+                                'required'      => (bool) wpinv_get_option('zip_mandatory'),
1760
+                            ));
1761 1761
                         ?>
1762 1762
                     </p>
1763 1763
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1764
-                        <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1764
+                        <label for="wpinv_phone" class="wpi-label"><?php _e('Phone', 'invoicing'); ?><?php if (wpinv_get_option('phone_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1765 1765
                         <?php
1766
-                        echo wpinv_html_text( array(
1766
+                        echo wpinv_html_text(array(
1767 1767
                                 'id'            => 'wpinv_phone',
1768 1768
                                 'name'          => 'wpinv_phone',
1769 1769
                                 'value'         => $billing_details['phone'],
1770 1770
                                 'class'         => 'wpi-input form-control',
1771
-                                'placeholder'   => __( 'Phone', 'invoicing' ),
1772
-                                'required'      => (bool)wpinv_get_option( 'phone_mandatory' ),
1773
-                            ) );
1771
+                                'placeholder'   => __('Phone', 'invoicing'),
1772
+                                'required'      => (bool) wpinv_get_option('phone_mandatory'),
1773
+                            ));
1774 1774
                         ?>
1775 1775
                     </p>
1776
-                    <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?>
1776
+                    <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?>
1777 1777
                     <div class="clearfix"></div>
1778 1778
                 </div>
1779 1779
             </div>
1780
-            <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?>
1780
+            <?php do_action('wpinv_after_billing_fields', $billing_details); ?>
1781 1781
         </div>
1782 1782
         <?php
1783 1783
     }
1784 1784
 }
1785
-add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' );
1785
+add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info');
1786 1786
 
1787 1787
 function wpinv_checkout_hidden_fields() {
1788 1788
 ?>
1789
-    <?php if ( is_user_logged_in() ) { ?>
1789
+    <?php if (is_user_logged_in()) { ?>
1790 1790
     <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/>
1791 1791
     <?php } ?>
1792 1792
     <input type="hidden" name="wpi_action" value="payment" />
@@ -1796,9 +1796,9 @@  discard block
 block discarded – undo
1796 1796
 function wpinv_checkout_button_purchase() {
1797 1797
     ob_start();
1798 1798
 ?>
1799
-    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/>
1799
+    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>" name="wpinv_payment" value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>"/>
1800 1800
 <?php
1801
-    return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() );
1801
+    return apply_filters('wpinv_checkout_button_purchase', ob_get_clean());
1802 1802
 }
1803 1803
 
1804 1804
 function wpinv_checkout_total() {
@@ -1807,84 +1807,84 @@  discard block
 block discarded – undo
1807 1807
 <div id="wpinv_checkout_total" class="panel panel-info">
1808 1808
     <div class="panel-body">
1809 1809
     <?php
1810
-    do_action( 'wpinv_purchase_form_before_checkout_total' );
1810
+    do_action('wpinv_purchase_form_before_checkout_total');
1811 1811
     ?>
1812
-    <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span>
1812
+    <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span>
1813 1813
     <?php
1814
-    do_action( 'wpinv_purchase_form_after_checkout_total' );
1814
+    do_action('wpinv_purchase_form_after_checkout_total');
1815 1815
     ?>
1816 1816
     </div>
1817 1817
 </div>
1818 1818
 <?php
1819 1819
 }
1820
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 );
1820
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998);
1821 1821
 
1822 1822
 function wpinv_checkout_accept_tandc() {
1823
-    $page = wpinv_get_option( 'tandc_page' );
1823
+    $page = wpinv_get_option('tandc_page');
1824 1824
     ?>
1825 1825
     <div id="wpinv_checkout_tandc" class="panel panel-success">
1826 1826
         <div class="panel-body">
1827 1827
             <?php echo wpinv_get_policy_text(); ?>
1828 1828
             <?php
1829
-            if(isset($page) && (int)$page > 0 && apply_filters( 'wpinv_checkout_show_terms', true )){
1830
-                $terms_link = esc_url( get_permalink( $page ) );
1829
+            if (isset($page) && (int) $page > 0 && apply_filters('wpinv_checkout_show_terms', true)) {
1830
+                $terms_link = esc_url(get_permalink($page));
1831 1831
                 ?>
1832 1832
                 <label class="">
1833
-                    <input type="checkbox" class="wpi-terms-checkbox" name="wpi_terms" id="wpi-terms" <?php checked( apply_filters( 'wpinv_terms_is_checked_default', isset( $_POST['wpi_terms'] ) ), true ); ?>> <span><?php printf( __( 'I&rsquo;ve read and accept the <a href="%s" target="_blank" class="wpi-terms-and-conditions-link">terms &amp; conditions</a>', 'invoicing' ), $terms_link ); ?></span> <span class="wpi-required">*</span>
1833
+                    <input type="checkbox" class="wpi-terms-checkbox" name="wpi_terms" id="wpi-terms" <?php checked(apply_filters('wpinv_terms_is_checked_default', isset($_POST['wpi_terms'])), true); ?>> <span><?php printf(__('I&rsquo;ve read and accept the <a href="%s" target="_blank" class="wpi-terms-and-conditions-link">terms &amp; conditions</a>', 'invoicing'), $terms_link); ?></span> <span class="wpi-required">*</span>
1834 1834
                 </label>
1835 1835
             <?php } ?>
1836 1836
         </div>
1837 1837
     </div>
1838 1838
     <?php
1839 1839
 }
1840
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_accept_tandc', 9995 );
1840
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_accept_tandc', 9995);
1841 1841
 
1842 1842
 function wpinv_checkout_submit() {
1843 1843
 ?>
1844 1844
 <div id="wpinv_purchase_submit" class="panel panel-success">
1845 1845
     <div class="panel-body text-center">
1846 1846
     <?php
1847
-    do_action( 'wpinv_purchase_form_before_submit' );
1847
+    do_action('wpinv_purchase_form_before_submit');
1848 1848
     wpinv_checkout_hidden_fields();
1849 1849
     echo wpinv_checkout_button_purchase();
1850
-    do_action( 'wpinv_purchase_form_after_submit' );
1850
+    do_action('wpinv_purchase_form_after_submit');
1851 1851
     ?>
1852 1852
     </div>
1853 1853
 </div>
1854 1854
 <?php
1855 1855
 }
1856
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 );
1856
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999);
1857 1857
 
1858
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1859
-    $invoice = wpinv_get_invoice( $invoice_id );
1858
+function wpinv_receipt_billing_address($invoice_id = 0) {
1859
+    $invoice = wpinv_get_invoice($invoice_id);
1860 1860
 
1861
-    if ( empty( $invoice ) ) {
1861
+    if (empty($invoice)) {
1862 1862
         return NULL;
1863 1863
     }
1864 1864
 
1865 1865
     $billing_details = $invoice->get_user_info();
1866
-    $address_row = wpinv_get_invoice_address_markup( $billing_details );
1866
+    $address_row = wpinv_get_invoice_address_markup($billing_details);
1867 1867
 
1868 1868
     ob_start();
1869 1869
     ?>
1870 1870
     <table class="table table-bordered table-sm wpi-billing-details">
1871 1871
         <tbody>
1872 1872
             <tr class="wpi-receipt-name">
1873
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1874
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1873
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1874
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1875 1875
             </tr>
1876 1876
             <tr class="wpi-receipt-email">
1877
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1878
-                <td><?php echo $billing_details['email'] ;?></td>
1877
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1878
+                <td><?php echo $billing_details['email']; ?></td>
1879 1879
             </tr>
1880 1880
             <tr class="wpi-receipt-address">
1881
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1882
-                <td><?php echo $address_row ;?></td>
1881
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1882
+                <td><?php echo $address_row; ?></td>
1883 1883
             </tr>
1884
-            <?php if ( $billing_details['phone'] ) { ?>
1884
+            <?php if ($billing_details['phone']) { ?>
1885 1885
             <tr class="wpi-receipt-phone">
1886
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1887
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1886
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1887
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1888 1888
             </tr>
1889 1889
             <?php } ?>
1890 1890
         </tbody>
@@ -1892,74 +1892,74 @@  discard block
 block discarded – undo
1892 1892
     <?php
1893 1893
     $output = ob_get_clean();
1894 1894
     
1895
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1895
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1896 1896
 
1897 1897
     echo $output;
1898 1898
 }
1899 1899
 
1900
-function wpinv_filter_success_page_content( $content ) {
1901
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1902
-        if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) {
1903
-            $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content );
1900
+function wpinv_filter_success_page_content($content) {
1901
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1902
+        if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) {
1903
+            $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content);
1904 1904
         }
1905 1905
     }
1906 1906
 
1907 1907
     return $content;
1908 1908
 }
1909
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1909
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1910 1910
 
1911
-function wpinv_receipt_actions( $invoice ) {
1912
-    if ( !empty( $invoice ) ) {
1911
+function wpinv_receipt_actions($invoice) {
1912
+    if (!empty($invoice)) {
1913 1913
         $actions = array();
1914 1914
 
1915
-        if ( wpinv_user_can_view_invoice( $invoice->ID ) ) {
1916
-            $actions['print']   = array(
1917
-                'url'  => $invoice->get_view_url( true ),
1918
-                'name' => __( 'Print Invoice', 'invoicing' ),
1915
+        if (wpinv_user_can_view_invoice($invoice->ID)) {
1916
+            $actions['print'] = array(
1917
+                'url'  => $invoice->get_view_url(true),
1918
+                'name' => __('Print Invoice', 'invoicing'),
1919 1919
                 'class' => 'btn-primary',
1920 1920
             );
1921 1921
         }
1922 1922
 
1923
-        if ( is_user_logged_in() ) {
1923
+        if (is_user_logged_in()) {
1924 1924
             $actions['history'] = array(
1925 1925
                 'url'  => wpinv_get_history_page_uri(),
1926
-                'name' => __( 'Invoice History', 'invoicing' ),
1926
+                'name' => __('Invoice History', 'invoicing'),
1927 1927
                 'class' => 'btn-warning',
1928 1928
             );
1929 1929
         }
1930 1930
 
1931
-        $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice );
1931
+        $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice);
1932 1932
 
1933
-        if ( !empty( $actions ) ) {
1933
+        if (!empty($actions)) {
1934 1934
         ?>
1935 1935
         <div class="wpinv-receipt-actions text-right">
1936
-            <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?>
1937
-            <a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a>
1936
+            <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?>
1937
+            <a href="<?php echo esc_url($action['url']); ?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class($key); ?>" <?php echo (!empty($action['attrs']) ? $action['attrs'] : ''); ?>><?php echo esc_html($action['name']); ?></a>
1938 1938
             <?php } ?>
1939 1939
         </div>
1940 1940
         <?php
1941 1941
         }
1942 1942
     }
1943 1943
 }
1944
-add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 );
1944
+add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1);
1945 1945
 
1946
-function wpinv_invoice_link( $invoice_id ) {
1947
-    $invoice = wpinv_get_invoice( $invoice_id );
1946
+function wpinv_invoice_link($invoice_id) {
1947
+    $invoice = wpinv_get_invoice($invoice_id);
1948 1948
 
1949
-    if ( empty( $invoice ) ) {
1949
+    if (empty($invoice)) {
1950 1950
         return NULL;
1951 1951
     }
1952 1952
 
1953
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1953
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1954 1954
 
1955
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1955
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1956 1956
 }
1957 1957
 
1958
-function wpinv_invoice_subscription_details( $invoice ) {
1959
-    if ( !empty( $invoice ) && $invoice->is_recurring() && ! wpinv_is_subscription_payment( $invoice ) ) {
1960
-        $subscription = wpinv_get_subscription( $invoice, true );
1958
+function wpinv_invoice_subscription_details($invoice) {
1959
+    if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) {
1960
+        $subscription = wpinv_get_subscription($invoice, true);
1961 1961
 
1962
-        if ( empty( $subscription ) ) {
1962
+        if (empty($subscription)) {
1963 1963
             return;
1964 1964
         }
1965 1965
 
@@ -1970,15 +1970,15 @@  discard block
 block discarded – undo
1970 1970
         $payments = $subscription->get_child_payments();
1971 1971
         ?>
1972 1972
         <div class="wpinv-subscriptions-details">
1973
-            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3>
1973
+            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3>
1974 1974
             <table class="table">
1975 1975
                 <thead>
1976 1976
                     <tr>
1977
-                        <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th>
1978
-                        <th><?php _e( 'Start Date', 'invoicing' ) ;?></th>
1979
-                        <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th>
1980
-                        <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th>
1981
-                        <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th>
1977
+                        <th><?php _e('Billing Cycle', 'invoicing'); ?></th>
1978
+                        <th><?php _e('Start Date', 'invoicing'); ?></th>
1979
+                        <th><?php _e('Expiration Date', 'invoicing'); ?></th>
1980
+                        <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th>
1981
+                        <th class="text-center"><?php _e('Status', 'invoicing'); ?></th>
1982 1982
                     </tr>
1983 1983
                 </thead>
1984 1984
                 <tbody>
@@ -1992,29 +1992,29 @@  discard block
 block discarded – undo
1992 1992
                 </tbody>
1993 1993
             </table>
1994 1994
         </div>
1995
-        <?php if ( !empty( $payments ) ) { ?>
1995
+        <?php if (!empty($payments)) { ?>
1996 1996
         <div class="wpinv-renewal-payments">
1997
-            <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3>
1997
+            <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3>
1998 1998
             <table class="table">
1999 1999
                 <thead>
2000 2000
                     <tr>
2001 2001
                         <th>#</th>
2002
-                        <th><?php _e( 'Invoice', 'invoicing' ) ;?></th>
2003
-                        <th><?php _e( 'Date', 'invoicing' ) ;?></th>
2004
-                        <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th>
2002
+                        <th><?php _e('Invoice', 'invoicing'); ?></th>
2003
+                        <th><?php _e('Date', 'invoicing'); ?></th>
2004
+                        <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th>
2005 2005
                     </tr>
2006 2006
                 </thead>
2007 2007
                 <tbody>
2008 2008
                     <?php
2009 2009
                         $i = 1;
2010
-                        foreach ( $payments as $payment ) {
2010
+                        foreach ($payments as $payment) {
2011 2011
                             $invoice_id = $payment->ID;
2012 2012
                     ?>
2013 2013
                     <tr>
2014
-                        <th scope="row"><?php echo $i;?></th>
2015
-                        <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td>
2016
-                        <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td>
2017
-                        <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td>
2014
+                        <th scope="row"><?php echo $i; ?></th>
2015
+                        <td><?php echo wpinv_invoice_link($invoice_id); ?></td>
2016
+                        <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td>
2017
+                        <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td>
2018 2018
                     </tr>
2019 2019
                     <?php $i++; } ?>
2020 2020
                 </tbody>
@@ -2025,52 +2025,52 @@  discard block
 block discarded – undo
2025 2025
     }
2026 2026
 }
2027 2027
 
2028
-function wpinv_cart_total_label( $label, $invoice ) {
2029
-    if ( empty( $invoice ) ) {
2028
+function wpinv_cart_total_label($label, $invoice) {
2029
+    if (empty($invoice)) {
2030 2030
         return $label;
2031 2031
     }
2032 2032
 
2033 2033
     $prefix_label = '';
2034
-    if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) {
2035
-        $prefix_label   = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice );
2036
-    } else if ( $invoice->is_renewal() ) {
2037
-        $prefix_label   = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> ';        
2034
+    if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) {
2035
+        $prefix_label   = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice);
2036
+    } else if ($invoice->is_renewal()) {
2037
+        $prefix_label   = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> ';        
2038 2038
     }
2039 2039
 
2040
-    if ( $prefix_label != '' ) {
2041
-        $label  = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2040
+    if ($prefix_label != '') {
2041
+        $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2042 2042
     }
2043 2043
 
2044 2044
     return $label;
2045 2045
 }
2046
-add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2047
-add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2048
-add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2046
+add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2047
+add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2048
+add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2049 2049
 
2050
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 );
2050
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1);
2051 2051
 
2052
-function wpinv_invoice_print_description( $invoice ) {
2053
-    if ( empty( $invoice ) ) {
2052
+function wpinv_invoice_print_description($invoice) {
2053
+    if (empty($invoice)) {
2054 2054
         return NULL;
2055 2055
     }
2056
-    if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) {
2056
+    if ($description = wpinv_get_invoice_description($invoice->ID)) {
2057 2057
         ?>
2058 2058
         <div class="row wpinv-lower">
2059 2059
             <div class="col-sm-12 wpinv-description">
2060
-                <?php echo wpautop( $description ); ?>
2060
+                <?php echo wpautop($description); ?>
2061 2061
             </div>
2062 2062
         </div>
2063 2063
         <?php
2064 2064
     }
2065 2065
 }
2066
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 );
2066
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1);
2067 2067
 
2068
-function wpinv_invoice_print_payment_info( $invoice ) {
2069
-    if ( empty( $invoice ) ) {
2068
+function wpinv_invoice_print_payment_info($invoice) {
2069
+    if (empty($invoice)) {
2070 2070
         return NULL;
2071 2071
     }
2072 2072
 
2073
-    if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) {
2073
+    if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) {
2074 2074
         ?>
2075 2075
         <div class="row wpinv-payments">
2076 2076
             <div class="col-sm-12">
@@ -2082,43 +2082,43 @@  discard block
 block discarded – undo
2082 2082
 }
2083 2083
 // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 );
2084 2084
 
2085
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
2086
-    if ( empty( $note ) ) {
2085
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
2086
+    if (empty($note)) {
2087 2087
         return NULL;
2088 2088
     }
2089 2089
 
2090
-    if ( is_int( $note ) ) {
2091
-        $note = get_comment( $note );
2090
+    if (is_int($note)) {
2091
+        $note = get_comment($note);
2092 2092
     }
2093 2093
 
2094
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
2094
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
2095 2095
         return NULL;
2096 2096
     }
2097 2097
 
2098
-    $note_classes   = array( 'note' );
2099
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
2098
+    $note_classes   = array('note');
2099
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
2100 2100
     $note_classes[] = $note->comment_author === 'System' ? 'system-note' : '';
2101
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
2102
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
2101
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
2102
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
2103 2103
 
2104 2104
     ob_start();
2105 2105
     ?>
2106
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>">
2106
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>">
2107 2107
         <div class="note_content">
2108
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
2108
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
2109 2109
         </div>
2110 2110
         <p class="meta">
2111
-            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr>&nbsp;&nbsp;
2112
-            <?php if ( is_admin() && ( $note->comment_author !== 'System' || wpinv_current_user_can_manage_invoicing() ) ) { ?>
2113
-                <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
2111
+            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr>&nbsp;&nbsp;
2112
+            <?php if (is_admin() && ($note->comment_author !== 'System' || wpinv_current_user_can_manage_invoicing())) { ?>
2113
+                <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
2114 2114
             <?php } ?>
2115 2115
         </p>
2116 2116
     </li>
2117 2117
     <?php
2118 2118
     $note_content = ob_get_clean();
2119
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
2119
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
2120 2120
 
2121
-    if ( $echo ) {
2121
+    if ($echo) {
2122 2122
         echo $note_content;
2123 2123
     } else {
2124 2124
         return $note_content;
@@ -2128,43 +2128,43 @@  discard block
 block discarded – undo
2128 2128
 function wpinv_invalid_invoice_content() {
2129 2129
     global $post;
2130 2130
 
2131
-    $invoice = wpinv_get_invoice( $post->ID );
2131
+    $invoice = wpinv_get_invoice($post->ID);
2132 2132
 
2133
-    $error = __( 'This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing' );
2134
-    if ( !empty( $invoice->ID ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) {
2135
-        if ( is_user_logged_in() ) {
2136
-            if ( wpinv_require_login_to_checkout() ) {
2137
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2138
-                    $error = __( 'You are not allowed to view this invoice.', 'invoicing' );
2133
+    $error = __('This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing');
2134
+    if (!empty($invoice->ID) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) {
2135
+        if (is_user_logged_in()) {
2136
+            if (wpinv_require_login_to_checkout()) {
2137
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2138
+                    $error = __('You are not allowed to view this invoice.', 'invoicing');
2139 2139
                 }
2140 2140
             }
2141 2141
         } else {
2142
-            if ( wpinv_require_login_to_checkout() ) {
2143
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2144
-                    $error = __( 'You must be logged in to view this invoice.', 'invoicing' );
2142
+            if (wpinv_require_login_to_checkout()) {
2143
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2144
+                    $error = __('You must be logged in to view this invoice.', 'invoicing');
2145 2145
                 }
2146 2146
             }
2147 2147
         }
2148 2148
     } else {
2149
-        $error = __( 'This invoice is deleted or does not exist.', 'invoicing' );
2149
+        $error = __('This invoice is deleted or does not exist.', 'invoicing');
2150 2150
     }
2151 2151
     ?>
2152 2152
     <div class="row wpinv-row-invalid">
2153 2153
         <div class="col-md-6 col-md-offset-3 wpinv-message error">
2154
-            <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3>
2154
+            <h3><?php _e('Access Denied', 'invoicing'); ?></h3>
2155 2155
             <p class="wpinv-msg-text"><?php echo $error; ?></p>
2156 2156
         </div>
2157 2157
     </div>
2158 2158
     <?php
2159 2159
 }
2160
-add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' );
2160
+add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content');
2161 2161
 
2162
-add_action( 'wpinv_checkout_billing_fields_last', 'wpinv_force_company_name_field');
2163
-function wpinv_force_company_name_field(){
2162
+add_action('wpinv_checkout_billing_fields_last', 'wpinv_force_company_name_field');
2163
+function wpinv_force_company_name_field() {
2164 2164
     $invoice = wpinv_get_invoice_cart();
2165
-    $user_id = wpinv_get_user_id( $invoice->ID );
2166
-    $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
2167
-    if ( 1 == wpinv_get_option( 'force_show_company' ) && !wpinv_use_taxes() ) {
2165
+    $user_id = wpinv_get_user_id($invoice->ID);
2166
+    $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
2167
+    if (1 == wpinv_get_option('force_show_company') && !wpinv_use_taxes()) {
2168 2168
         ?>
2169 2169
         <p class="wpi-cart-field wpi-col2 wpi-colf">
2170 2170
             <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label>
@@ -2190,21 +2190,21 @@  discard block
 block discarded – undo
2190 2190
  * @return string
2191 2191
  */
2192 2192
 function wpinv_get_policy_text() {
2193
-    $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 );
2193
+    $privacy_page_id = get_option('wp_page_for_privacy_policy', 0);
2194 2194
 
2195
-    $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]' ));
2195
+    $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]'));
2196 2196
 
2197
-    if(!$privacy_page_id){
2198
-        $privacy_page_id = wpinv_get_option( 'privacy_page', 0 );
2197
+    if (!$privacy_page_id) {
2198
+        $privacy_page_id = wpinv_get_option('privacy_page', 0);
2199 2199
     }
2200 2200
 
2201
-    $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' );
2201
+    $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');
2202 2202
 
2203 2203
     $find_replace = array(
2204 2204
         '[wpinv_privacy_policy]' => $privacy_link,
2205 2205
     );
2206 2206
 
2207
-    $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text );
2207
+    $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text);
2208 2208
 
2209 2209
     return wp_kses_post(wpautop($privacy_text));
2210 2210
 }
@@ -2213,25 +2213,25 @@  discard block
 block discarded – undo
2213 2213
 /**
2214 2214
  * Allows the user to set their own price for an invoice item
2215 2215
  */
2216
-function wpinv_checkout_cart_item_name_your_price( $cart_item, $key ) {
2216
+function wpinv_checkout_cart_item_name_your_price($cart_item, $key) {
2217 2217
     
2218 2218
     //Ensure we have an item id
2219
-    if(! is_array( $cart_item ) || empty( $cart_item['id'] ) ) {
2219
+    if (!is_array($cart_item) || empty($cart_item['id'])) {
2220 2220
         return;
2221 2221
     }
2222 2222
 
2223 2223
     //Fetch the item
2224 2224
     $item_id = $cart_item['id'];
2225
-    $item    = new WPInv_Item( $item_id );
2225
+    $item    = new WPInv_Item($item_id);
2226 2226
     
2227
-    if(! $item->supports_dynamic_pricing() || !$item->get_is_dynamic_pricing() ) {
2227
+    if (!$item->supports_dynamic_pricing() || !$item->get_is_dynamic_pricing()) {
2228 2228
         return;
2229 2229
     }
2230 2230
 
2231 2231
     //Fetch the dynamic pricing "strings"
2232
-    $suggested_price_text = esc_html( wpinv_get_option( 'suggested_price_text', __( 'Suggested Price:', 'invoicing' ) ) );
2233
-    $minimum_price_text   = esc_html( wpinv_get_option( 'minimum_price_text', __( 'Minimum Price:', 'invoicing' ) ) );
2234
-    $name_your_price_text = esc_html( wpinv_get_option( 'name_your_price_text', __( 'Name Your Price', 'invoicing' ) ) );
2232
+    $suggested_price_text = esc_html(wpinv_get_option('suggested_price_text', __('Suggested Price:', 'invoicing')));
2233
+    $minimum_price_text   = esc_html(wpinv_get_option('minimum_price_text', __('Minimum Price:', 'invoicing')));
2234
+    $name_your_price_text = esc_html(wpinv_get_option('name_your_price_text', __('Name Your Price', 'invoicing')));
2235 2235
 
2236 2236
     //Display a "name_your_price" button
2237 2237
     echo " &mdash; <a href='#' class='wpinv-name-your-price-frontend small'>$name_your_price_text</a></div>";
@@ -2240,7 +2240,7 @@  discard block
 block discarded – undo
2240 2240
     echo '<div class="name-your-price-miniform">';
2241 2241
     
2242 2242
     //Maybe display the recommended price
2243
-    if( $item->get_price() > 0 && !empty( $suggested_price_text ) ) {
2243
+    if ($item->get_price() > 0 && !empty($suggested_price_text)) {
2244 2244
         $suggested_price = $item->get_the_price();
2245 2245
         echo "<div>$suggested_price_text &mdash; $suggested_price</div>";
2246 2246
     }
@@ -2248,216 +2248,216 @@  discard block
 block discarded – undo
2248 2248
     //Display the update price form
2249 2249
     $symbol         = wpinv_currency_symbol();
2250 2250
     $position       = wpinv_currency_position();
2251
-    $minimum        = esc_attr( $item->get_minimum_price() );
2252
-    $price          = esc_attr( $cart_item['item_price'] );
2253
-    $update         = esc_attr__( "Update", 'invoicing' );
2251
+    $minimum        = esc_attr($item->get_minimum_price());
2252
+    $price          = esc_attr($cart_item['item_price']);
2253
+    $update         = esc_attr__("Update", 'invoicing');
2254 2254
 
2255 2255
     //Ensure it supports dynamic prici
2256
-    if( $price < $minimum ) {
2256
+    if ($price < $minimum) {
2257 2257
         $price = $minimum;
2258 2258
     }
2259 2259
 
2260 2260
     echo '<label>';
2261 2261
     echo $position != 'right' ? $symbol . '&nbsp;' : '';
2262 2262
     echo "<input type='number' min='$minimum' placeholder='$price' value='$price' class='wpi-field-price' />";
2263
-    echo $position == 'right' ? '&nbsp;' . $symbol : '' ;
2263
+    echo $position == 'right' ? '&nbsp;' . $symbol : '';
2264 2264
     echo "</label>";
2265 2265
     echo "<input type='hidden' value='$item_id' class='wpi-field-item' />";
2266 2266
     echo "<a class='btn btn-success wpinv-submit wpinv-update-dynamic-price-frontend'>$update</a>";
2267 2267
 
2268 2268
     //Maybe display the minimum price
2269
-    if( $item->get_minimum_price() > 0 && !empty( $minimum_price_text ) ) {
2270
-        $minimum_price = wpinv_price( wpinv_format_amount( $item->get_minimum_price() ) );
2269
+    if ($item->get_minimum_price() > 0 && !empty($minimum_price_text)) {
2270
+        $minimum_price = wpinv_price(wpinv_format_amount($item->get_minimum_price()));
2271 2271
         echo "<div>$minimum_price_text &mdash; $minimum_price</div>";
2272 2272
     }
2273 2273
 
2274 2274
     echo "</div>";
2275 2275
 
2276 2276
 }
2277
-add_action( 'wpinv_checkout_cart_item_price_after', 'wpinv_checkout_cart_item_name_your_price', 10, 2 );
2277
+add_action('wpinv_checkout_cart_item_price_after', 'wpinv_checkout_cart_item_name_your_price', 10, 2);
2278 2278
 
2279 2279
 function wpinv_oxygen_fix_conflict() {
2280 2280
     global $ct_ignore_post_types;
2281 2281
 
2282
-    if ( ! is_array( $ct_ignore_post_types ) ) {
2282
+    if (!is_array($ct_ignore_post_types)) {
2283 2283
         $ct_ignore_post_types = array();
2284 2284
     }
2285 2285
 
2286
-    $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item' );
2286
+    $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item');
2287 2287
 
2288
-    foreach ( $post_types as $post_type ) {
2288
+    foreach ($post_types as $post_type) {
2289 2289
         $ct_ignore_post_types[] = $post_type;
2290 2290
 
2291 2291
         // Ignore post type
2292
-        add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 );
2292
+        add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999);
2293 2293
     }
2294 2294
 
2295
-    remove_filter( 'template_include', 'wpinv_template', 10, 1 );
2296
-    add_filter( 'template_include', 'wpinv_template', 999, 1 );
2295
+    remove_filter('template_include', 'wpinv_template', 10, 1);
2296
+    add_filter('template_include', 'wpinv_template', 999, 1);
2297 2297
 }
2298 2298
 
2299 2299
 /**
2300 2300
  * Helper function to display a payment form on the frontend.
2301 2301
  */
2302
-function getpaid_display_payment_form( $form ) {
2302
+function getpaid_display_payment_form($form) {
2303 2303
     global $invoicing;
2304 2304
 
2305 2305
     // Ensure that it is published.
2306
-	if ( 'publish' != get_post_status( $form ) ) {
2306
+	if ('publish' != get_post_status($form)) {
2307 2307
 		return aui()->alert(
2308 2308
 			array(
2309 2309
 				'type'    => 'warning',
2310
-				'content' => __( 'This payment form is no longer active', 'invoicing' ),
2310
+				'content' => __('This payment form is no longer active', 'invoicing'),
2311 2311
 			)
2312 2312
 		);
2313 2313
 	}
2314 2314
 
2315 2315
     // Get the form elements and items.
2316
-    $form     = absint( $form );
2317
-	$elements = $invoicing->form_elements->get_form_elements( $form );
2318
-	$items    = $invoicing->form_elements->get_form_items( $form );
2316
+    $form = absint($form);
2317
+	$elements = $invoicing->form_elements->get_form_elements($form);
2318
+	$items    = $invoicing->form_elements->get_form_items($form);
2319 2319
 
2320 2320
 	ob_start();
2321 2321
 	echo "<form class='wpinv_payment_form'>";
2322
-	do_action( 'wpinv_payment_form_top' );
2322
+	do_action('wpinv_payment_form_top');
2323 2323
 	echo "<input type='hidden' name='form_id' value='$form'/>";
2324
-	wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
2325
-	wp_nonce_field( 'vat_validation', '_wpi_nonce' );
2324
+	wp_nonce_field('wpinv_payment_form', 'wpinv_payment_form');
2325
+	wp_nonce_field('vat_validation', '_wpi_nonce');
2326 2326
 
2327
-	foreach ( $elements as $element ) {
2328
-		do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form );
2329
-		do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form );
2327
+	foreach ($elements as $element) {
2328
+		do_action('wpinv_frontend_render_payment_form_element', $element, $items, $form);
2329
+		do_action("wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form);
2330 2330
 	}
2331 2331
 
2332 2332
 	echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
2333
-	do_action( 'wpinv_payment_form_bottom' );
2333
+	do_action('wpinv_payment_form_bottom');
2334 2334
 	echo '</form>';
2335 2335
 
2336 2336
 	$content = ob_get_clean();
2337
-	return str_replace( 'sr-only', '', $content );
2337
+	return str_replace('sr-only', '', $content);
2338 2338
 }
2339 2339
 
2340 2340
 /**
2341 2341
  * Helper function to display a item payment form on the frontend.
2342 2342
  */
2343
-function getpaid_display_item_payment_form( $items ) {
2343
+function getpaid_display_item_payment_form($items) {
2344 2344
     global $invoicing;
2345 2345
 
2346
-    foreach ( array_keys( $items ) as $id ) {
2347
-	    if ( 'publish' != get_post_status( $id ) ) {
2348
-		    unset( $items[ $id ] );
2346
+    foreach (array_keys($items) as $id) {
2347
+	    if ('publish' != get_post_status($id)) {
2348
+		    unset($items[$id]);
2349 2349
 	    }
2350 2350
     }
2351 2351
 
2352
-    if ( empty( $items ) ) {
2352
+    if (empty($items)) {
2353 2353
 		return aui()->alert(
2354 2354
 			array(
2355 2355
 				'type'    => 'warning',
2356
-				'content' => __( 'No published items found', 'invoicing' ),
2356
+				'content' => __('No published items found', 'invoicing'),
2357 2357
 			)
2358 2358
 		);
2359 2359
     }
2360 2360
 
2361
-    $item_key = getpaid_convert_items_to_string( $items );
2361
+    $item_key = getpaid_convert_items_to_string($items);
2362 2362
 
2363 2363
     // Get the form elements and items.
2364 2364
     $form     = wpinv_get_default_payment_form();
2365
-	$elements = $invoicing->form_elements->get_form_elements( $form );
2366
-	$items    = $invoicing->form_elements->convert_normal_items( $items );
2365
+	$elements = $invoicing->form_elements->get_form_elements($form);
2366
+	$items    = $invoicing->form_elements->convert_normal_items($items);
2367 2367
 
2368 2368
 	ob_start();
2369 2369
 	echo "<form class='wpinv_payment_form'>";
2370
-	do_action( 'wpinv_payment_form_top' );
2370
+	do_action('wpinv_payment_form_top');
2371 2371
     echo "<input type='hidden' name='form_id' value='$form'/>";
2372 2372
     echo "<input type='hidden' name='form_items' value='$item_key'/>";
2373
-	wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
2374
-	wp_nonce_field( 'vat_validation', '_wpi_nonce' );
2373
+	wp_nonce_field('wpinv_payment_form', 'wpinv_payment_form');
2374
+	wp_nonce_field('vat_validation', '_wpi_nonce');
2375 2375
 
2376
-	foreach ( $elements as $element ) {
2377
-		do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form );
2378
-		do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form );
2376
+	foreach ($elements as $element) {
2377
+		do_action('wpinv_frontend_render_payment_form_element', $element, $items, $form);
2378
+		do_action("wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form);
2379 2379
 	}
2380 2380
 
2381 2381
 	echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
2382
-	do_action( 'wpinv_payment_form_bottom' );
2382
+	do_action('wpinv_payment_form_bottom');
2383 2383
 	echo '</form>';
2384 2384
 
2385 2385
 	$content = ob_get_clean();
2386
-	return str_replace( 'sr-only', '', $content );
2386
+	return str_replace('sr-only', '', $content);
2387 2387
 }
2388 2388
 
2389 2389
 /**
2390 2390
  * Helper function to display an invoice payment form on the frontend.
2391 2391
  */
2392
-function getpaid_display_invoice_payment_form( $invoice_id ) {
2392
+function getpaid_display_invoice_payment_form($invoice_id) {
2393 2393
     global $invoicing;
2394 2394
 
2395
-    $invoice = wpinv_get_invoice( $invoice_id );
2395
+    $invoice = wpinv_get_invoice($invoice_id);
2396 2396
 
2397
-    if ( empty( $invoice ) ) {
2397
+    if (empty($invoice)) {
2398 2398
 		return aui()->alert(
2399 2399
 			array(
2400 2400
 				'type'    => 'warning',
2401
-				'content' => __( 'Invoice not found', 'invoicing' ),
2401
+				'content' => __('Invoice not found', 'invoicing'),
2402 2402
 			)
2403 2403
 		);
2404 2404
     }
2405 2405
 
2406
-    if ( $invoice->is_paid() ) {
2406
+    if ($invoice->is_paid()) {
2407 2407
 		return aui()->alert(
2408 2408
 			array(
2409 2409
 				'type'    => 'warning',
2410
-				'content' => __( 'Invoice has already been paid', 'invoicing' ),
2410
+				'content' => __('Invoice has already been paid', 'invoicing'),
2411 2411
 			)
2412 2412
 		);
2413 2413
     }
2414 2414
 
2415 2415
     // Get the form elements and items.
2416
-    $form     = wpinv_get_default_payment_form();
2417
-	$elements = $invoicing->form_elements->get_form_elements( $form );
2418
-	$items    = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice );
2416
+    $form = wpinv_get_default_payment_form();
2417
+	$elements = $invoicing->form_elements->get_form_elements($form);
2418
+	$items    = $invoicing->form_elements->convert_checkout_items($invoice->cart_details, $invoice);
2419 2419
 
2420 2420
 	ob_start();
2421 2421
 	echo "<form class='wpinv_payment_form'>";
2422
-	do_action( 'wpinv_payment_form_top' );
2422
+	do_action('wpinv_payment_form_top');
2423 2423
     echo "<input type='hidden' name='form_id' value='$form'/>";
2424 2424
     echo "<input type='hidden' name='invoice_id' value='$invoice_id'/>";
2425
-	wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
2426
-	wp_nonce_field( 'vat_validation', '_wpi_nonce' );
2425
+	wp_nonce_field('wpinv_payment_form', 'wpinv_payment_form');
2426
+	wp_nonce_field('vat_validation', '_wpi_nonce');
2427 2427
 
2428
-	foreach ( $elements as $element ) {
2429
-		do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form );
2430
-		do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form );
2428
+	foreach ($elements as $element) {
2429
+		do_action('wpinv_frontend_render_payment_form_element', $element, $items, $form);
2430
+		do_action("wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form);
2431 2431
 	}
2432 2432
 
2433 2433
 	echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
2434
-	do_action( 'wpinv_payment_form_bottom' );
2434
+	do_action('wpinv_payment_form_bottom');
2435 2435
 	echo '</form>';
2436 2436
 
2437 2437
 	$content = ob_get_clean();
2438
-	return str_replace( 'sr-only', '', $content );
2438
+	return str_replace('sr-only', '', $content);
2439 2439
 }
2440 2440
 
2441 2441
 /**
2442 2442
  * Helper function to convert item string to array.
2443 2443
  */
2444
-function getpaid_convert_items_to_array( $items ) {
2445
-    $items    = array_filter( array_map( 'trim', explode( ',', $items ) ) );
2444
+function getpaid_convert_items_to_array($items) {
2445
+    $items    = array_filter(array_map('trim', explode(',', $items)));
2446 2446
     $prepared = array();
2447 2447
 
2448
-    foreach ( $items as $item ) {
2449
-        $data = array_map( 'trim', explode( '|', $item ) );
2448
+    foreach ($items as $item) {
2449
+        $data = array_map('trim', explode('|', $item));
2450 2450
 
2451
-        if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) {
2451
+        if (empty($data[0]) || !is_numeric($data[0])) {
2452 2452
             continue;
2453 2453
         }
2454 2454
 
2455 2455
         $quantity = 1;
2456
-        if ( isset( $data[1] ) && is_numeric( $data[1] ) ) {
2456
+        if (isset($data[1]) && is_numeric($data[1])) {
2457 2457
             $quantity = $data[1];
2458 2458
         }
2459 2459
 
2460
-        $prepared[ $data[0] ] = $quantity;
2460
+        $prepared[$data[0]] = $quantity;
2461 2461
 
2462 2462
     }
2463 2463
 
@@ -2467,13 +2467,13 @@  discard block
 block discarded – undo
2467 2467
 /**
2468 2468
  * Helper function to convert item array to string.
2469 2469
  */
2470
-function getpaid_convert_items_to_string( $items ) {
2470
+function getpaid_convert_items_to_string($items) {
2471 2471
     $prepared = array();
2472 2472
 
2473
-    foreach ( $items as $item => $quantity ) {
2473
+    foreach ($items as $item => $quantity) {
2474 2474
         $prepared[] = "$item|$quantity";
2475 2475
     }
2476
-    return implode( ',', $prepared );
2476
+    return implode(',', $prepared);
2477 2477
 }
2478 2478
 
2479 2479
 /**
@@ -2481,22 +2481,22 @@  discard block
 block discarded – undo
2481 2481
  * 
2482 2482
  * Provide a label and one of $form, $items or $invoice.
2483 2483
  */
2484
-function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) {
2485
-    $label = sanitize_text_field( $label );
2484
+function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) {
2485
+    $label = sanitize_text_field($label);
2486 2486
     $nonce = wp_create_nonce('getpaid_ajax_form');
2487 2487
 
2488
-    if ( ! empty( $form ) ) {
2489
-        $form  = esc_attr( $form );
2488
+    if (!empty($form)) {
2489
+        $form = esc_attr($form);
2490 2490
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-form='$form'>$label</button>"; 
2491 2491
     }
2492 2492
 	
2493
-	if ( ! empty( $items ) ) {
2494
-        $items  = esc_attr( $items );
2493
+	if (!empty($items)) {
2494
+        $items = esc_attr($items);
2495 2495
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-item='$items'>$label</button>"; 
2496 2496
     }
2497 2497
     
2498
-    if ( ! empty( $invoice ) ) {
2499
-        $invoice  = esc_attr( $invoice );
2498
+    if (!empty($invoice)) {
2499
+        $invoice = esc_attr($invoice);
2500 2500
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-invoice='$invoice'>$label</button>"; 
2501 2501
     }
2502 2502
 
Please login to merge, or discard this patch.