Passed
Push — master ( f76276...ca99e2 )
by Stiofan
03:29
created
includes/class-wpinv.php 1 patch
Spacing   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  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_Plugin {
15 15
     private static $instance;
16 16
     
17 17
     public static function run() {
18
-        if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) {
18
+        if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) {
19 19
             self::$instance = new WPInv_Plugin;
20 20
             self::$instance->includes();
21 21
             self::$instance->actions();
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
             self::$instance->reports    = new WPInv_Reports();
24 24
         }
25 25
         
26
-        do_action( 'wpinv_loaded' );
26
+        do_action('wpinv_loaded');
27 27
         
28 28
         return self::$instance;
29 29
     }
@@ -33,31 +33,31 @@  discard block
 block discarded – undo
33 33
     }
34 34
     
35 35
     public function define_constants() {
36
-        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
37
-        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
36
+        define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
37
+        define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
38 38
     }
39 39
     
40 40
     private function actions() {
41 41
         /* Internationalize the text strings used. */
42
-        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
42
+        add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
43 43
         
44 44
         /* Perform actions on admin initialization. */
45
-        add_action( 'admin_init', array( &$this, 'admin_init') );
46
-        add_action( 'init', array( &$this, 'init' ), 3 );
47
-        add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) );
48
-        add_action( 'init', array( &$this, 'wpinv_actions' ) );
45
+        add_action('admin_init', array(&$this, 'admin_init'));
46
+        add_action('init', array(&$this, 'init'), 3);
47
+        add_action('init', array('WPInv_Shortcodes', 'init'));
48
+        add_action('init', array(&$this, 'wpinv_actions'));
49 49
         
50
-        if ( class_exists( 'BuddyPress' ) ) {
51
-            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
50
+        if (class_exists('BuddyPress')) {
51
+            add_action('bp_include', array(&$this, 'bp_invoicing_init'));
52 52
         }
53 53
 
54
-        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
54
+        add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
55 55
         
56
-        if ( is_admin() ) {
57
-            add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
58
-            add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) );
56
+        if (is_admin()) {
57
+            add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
58
+            add_action('admin_body_class', array(&$this, 'admin_body_class'));
59 59
         } else {
60
-            add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
60
+            add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
61 61
         }
62 62
         
63 63
         /**
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
          *
68 68
          * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference.
69 69
          */
70
-        do_action_ref_array( 'wpinv_actions', array( &$this ) );
70
+        do_action_ref_array('wpinv_actions', array(&$this));
71 71
 
72
-        add_action( 'admin_init', array( &$this, 'activation_redirect') );
72
+        add_action('admin_init', array(&$this, 'activation_redirect'));
73 73
     }
74 74
     
75 75
     public function plugins_loaded() {
@@ -83,187 +83,187 @@  discard block
 block discarded – undo
83 83
      * @since 1.0
84 84
      */
85 85
     public function load_textdomain() {
86
-        $locale = apply_filters( 'plugin_locale', get_locale(), 'invoicing' );
86
+        $locale = apply_filters('plugin_locale', get_locale(), 'invoicing');
87 87
         
88
-        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
89
-        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
88
+        load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
89
+        load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
90 90
         
91 91
         /**
92 92
          * Define language constants.
93 93
          */
94
-        require_once( WPINV_PLUGIN_DIR . 'language.php' );
94
+        require_once(WPINV_PLUGIN_DIR . 'language.php');
95 95
     }
96 96
         
97 97
     public function includes() {
98 98
         global $wpinv_options;
99 99
         
100
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
100
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
101 101
         $wpinv_options = wpinv_get_settings();
102 102
         
103
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' );
104
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
105
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
106
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
107
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
108
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
109
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
110
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' );
111
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
112
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
113
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
114
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
115
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
116
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php' );
117
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' );
103
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php');
104
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
105
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
106
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
107
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
108
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
109
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
110
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php');
111
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
112
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
113
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
114
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
115
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php');
116
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php');
117
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php');
118 118
         //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
119 119
         //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
120
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' );
120
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php');
121 121
         //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscription.php' );
122
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' );
123
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' );
124
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' );
125
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
126
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
127
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
128
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' );
129
-        if ( !class_exists( 'Geodir_EUVat' ) ) {
130
-            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
122
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php');
123
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php');
124
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php');
125
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
126
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
127
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php');
128
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php');
129
+        if (!class_exists('Geodir_EUVat')) {
130
+            require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php');
131 131
         }
132 132
         
133
-        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
134
-        if ( !empty( $gateways ) ) {
135
-            foreach ( $gateways as $gateway ) {
136
-                if ( $gateway == 'manual' ) {
133
+        $gateways = array_keys(wpinv_get_enabled_payment_gateways());
134
+        if (!empty($gateways)) {
135
+            foreach ($gateways as $gateway) {
136
+                if ($gateway == 'manual') {
137 137
                     continue;
138 138
                 }
139 139
                 
140 140
                 $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
141 141
                 
142
-                if ( file_exists( $gateway_file ) ) {
143
-                    require_once( $gateway_file );
142
+                if (file_exists($gateway_file)) {
143
+                    require_once($gateway_file);
144 144
                 }
145 145
             }
146 146
         }
147
-        require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' );
147
+        require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php');
148 148
         
149
-        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
150
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
151
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
152
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' );
149
+        if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
150
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php');
151
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
152
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php');
153 153
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
154
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' );
155
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' );
156
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
157
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' );
158
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
154
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php');
155
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php');
156
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
157
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php');
158
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
159 159
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
160 160
         }
161 161
         
162 162
         // include css inliner
163
-        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
164
-            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
163
+        if (!class_exists('Emogrifier') && class_exists('DOMDocument')) {
164
+            include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php');
165 165
         }
166 166
         
167
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
167
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php');
168 168
     }
169 169
     
170 170
     public function init() {
171 171
     }
172 172
     
173 173
     public function admin_init() {
174
-        if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
174
+        if (!(defined('DOING_AJAX') && DOING_AJAX)) {
175 175
         }
176 176
         
177
-        add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
177
+        add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php'));
178 178
     }
179 179
 
180 180
     public function activation_redirect() {
181 181
         // Bail if no activation redirect
182
-        if ( !get_transient( '_wpinv_activation_redirect' ) ) {
182
+        if (!get_transient('_wpinv_activation_redirect')) {
183 183
             return;
184 184
         }
185 185
 
186 186
         // Delete the redirect transient
187
-        delete_transient( '_wpinv_activation_redirect' );
187
+        delete_transient('_wpinv_activation_redirect');
188 188
 
189 189
         // Bail if activating from network, or bulk
190
-        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
190
+        if (is_network_admin() || isset($_GET['activate-multi'])) {
191 191
             return;
192 192
         }
193 193
 
194
-        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
194
+        wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
195 195
         exit;
196 196
     }
197 197
     
198 198
     public function enqueue_scripts() {
199
-        $suffix       = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
199
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
200 200
         
201
-        wp_deregister_style( 'font-awesome' );
202
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
203
-        wp_enqueue_style( 'font-awesome' );
201
+        wp_deregister_style('font-awesome');
202
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
203
+        wp_enqueue_style('font-awesome');
204 204
         
205
-        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION );
206
-        wp_enqueue_style( 'wpinv_front_style' );
205
+        wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION);
206
+        wp_enqueue_style('wpinv_front_style');
207 207
                
208 208
         // Register scripts
209
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
210
-        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ),  WPINV_VERSION );
209
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
210
+        wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION);
211 211
         
212 212
         $localize                         = array();
213
-        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
214
-        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
213
+        $localize['ajax_url']             = admin_url('admin-ajax.php');
214
+        $localize['nonce']                = wp_create_nonce('wpinv-nonce');
215 215
         $localize['currency_symbol']      = wpinv_currency_symbol();
216 216
         $localize['currency_pos']         = wpinv_currency_position();
217 217
         $localize['thousand_sep']         = wpinv_thousands_separator();
218 218
         $localize['decimal_sep']          = wpinv_decimal_separator();
219 219
         $localize['decimals']             = wpinv_decimals();
220 220
         
221
-        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
221
+        $localize = apply_filters('wpinv_front_js_localize', $localize);
222 222
         
223
-        wp_enqueue_script( 'jquery-blockui' );
223
+        wp_enqueue_script('jquery-blockui');
224 224
         $autofill_api = wpinv_get_option('address_autofill_api');
225 225
         $autofill_active = wpinv_get_option('address_autofill_active');
226 226
         if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) {
227 227
             wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false);
228 228
             wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery'), '', true);
229 229
         }
230
-        wp_enqueue_script( 'wpinv-front-script' );
231
-        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
230
+        wp_enqueue_script('wpinv-front-script');
231
+        wp_localize_script('wpinv-front-script', 'WPInv', $localize);
232 232
     }
233 233
     
234 234
     public function admin_enqueue_scripts() {
235 235
         global $post, $pagenow;
236 236
         
237 237
         $post_type  = wpinv_admin_post_type();
238
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
238
+        $suffix     = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
239 239
         
240
-        wp_deregister_style( 'font-awesome' );
241
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
242
-        wp_enqueue_style( 'font-awesome' );
240
+        wp_deregister_style('font-awesome');
241
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
242
+        wp_enqueue_style('font-awesome');
243 243
         
244
-        wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
245
-        wp_enqueue_style( 'jquery-ui-css' );
244
+        wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16');
245
+        wp_enqueue_style('jquery-ui-css');
246 246
         
247
-        wp_register_style( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2' );
248
-        wp_enqueue_style( 'jquery-chosen' );
247
+        wp_register_style('jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2');
248
+        wp_enqueue_style('jquery-chosen');
249 249
 
250
-        wp_register_script( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6.2' );
251
-        wp_enqueue_script( 'jquery-chosen' );
250
+        wp_register_script('jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array('jquery'), '1.6.2');
251
+        wp_enqueue_script('jquery-chosen');
252 252
         
253
-        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
254
-        wp_enqueue_style( 'wpinv_meta_box_style' );
253
+        wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
254
+        wp_enqueue_style('wpinv_meta_box_style');
255 255
         
256
-        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION );
257
-        wp_enqueue_style( 'wpinv_admin_style' );
256
+        wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION);
257
+        wp_enqueue_style('wpinv_admin_style');
258 258
         
259
-        if ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
260
-            wp_enqueue_script( 'jquery-ui-datepicker' );
259
+        if ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
260
+            wp_enqueue_script('jquery-ui-datepicker');
261 261
         }
262 262
 
263
-        wp_enqueue_style( 'wp-color-picker' );
264
-        wp_enqueue_script( 'wp-color-picker' );
263
+        wp_enqueue_style('wp-color-picker');
264
+        wp_enqueue_script('wp-color-picker');
265 265
         
266
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
266
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
267 267
 
268 268
         if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
269 269
             $autofill_api = wpinv_get_option('address_autofill_api');
@@ -274,17 +274,17 @@  discard block
 block discarded – undo
274 274
             }
275 275
         }
276 276
 
277
-        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ),  WPINV_VERSION );
278
-        wp_enqueue_script( 'wpinv-admin-script' );
277
+        wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), WPINV_VERSION);
278
+        wp_enqueue_script('wpinv-admin-script');
279 279
         
280 280
         $localize                               = array();
281
-        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
282
-        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
283
-        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
284
-        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
285
-        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
286
-        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
287
-        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
281
+        $localize['ajax_url']                   = admin_url('admin-ajax.php');
282
+        $localize['post_ID']                    = isset($post->ID) ? $post->ID : '';
283
+        $localize['wpinv_nonce']                = wp_create_nonce('wpinv-nonce');
284
+        $localize['add_invoice_note_nonce']     = wp_create_nonce('add-invoice-note');
285
+        $localize['delete_invoice_note_nonce']  = wp_create_nonce('delete-invoice-note');
286
+        $localize['invoice_item_nonce']         = wp_create_nonce('invoice-item');
287
+        $localize['billing_details_nonce']      = wp_create_nonce('get-billing-details');
288 288
         $localize['tax']                        = wpinv_tax_amount();
289 289
         $localize['discount']                   = wpinv_discount_amount();
290 290
         $localize['currency_symbol']            = wpinv_currency_symbol();
@@ -292,65 +292,65 @@  discard block
 block discarded – undo
292 292
         $localize['thousand_sep']               = wpinv_thousands_separator();
293 293
         $localize['decimal_sep']                = wpinv_decimal_separator();
294 294
         $localize['decimals']                   = wpinv_decimals();
295
-        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
296
-        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
297
-        $localize['status_pending']             = wpinv_status_nicename( 'wpi-pending' );
298
-        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
299
-        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
300
-        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
301
-        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
302
-        $localize['confirmCalcTotals']          = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' );
303
-        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
295
+        $localize['save_invoice']               = __('Save Invoice', 'invoicing');
296
+        $localize['status_publish']             = wpinv_status_nicename('publish');
297
+        $localize['status_pending']             = wpinv_status_nicename('wpi-pending');
298
+        $localize['delete_tax_rate']            = __('Are you sure you wish to delete this tax rate?', 'invoicing');
299
+        $localize['OneItemMin']                 = __('Invoice must contain at least one item', 'invoicing');
300
+        $localize['DeleteInvoiceItem']          = __('Are you sure you wish to delete this item?', 'invoicing');
301
+        $localize['FillBillingDetails']         = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing');
302
+        $localize['confirmCalcTotals']          = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing');
303
+        $localize['AreYouSure']                 = __('Are you sure?', 'invoicing');
304 304
         $localize['hasGD']                      = wpinv_gd_active();
305 305
         $localize['hasPM']                      = wpinv_pm_active();
306
-        $localize['emptyInvoice']               = __( 'Add atleast one item to save invoice!', 'invoicing' );
307
-        $localize['deletePackage']              = __( 'GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing' );
308
-        $localize['deletePackages']             = __( 'GD package items should be deleted from GD payment manager only', 'invoicing' );
309
-        $localize['deleteInvoiceFirst']         = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
306
+        $localize['emptyInvoice']               = __('Add atleast one item to save invoice!', 'invoicing');
307
+        $localize['deletePackage']              = __('GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing');
308
+        $localize['deletePackages']             = __('GD package items should be deleted from GD payment manager only', 'invoicing');
309
+        $localize['deleteInvoiceFirst']         = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing');
310 310
 
311
-        $localize = apply_filters( 'wpinv_admin_js_localize', $localize );
311
+        $localize = apply_filters('wpinv_admin_js_localize', $localize);
312 312
 
313
-        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
313
+        wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize);
314 314
     }
315 315
     
316
-    public function admin_body_class( $classes ) {
316
+    public function admin_body_class($classes) {
317 317
         global $pagenow, $post, $current_screen;
318 318
         
319
-        if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote' ) ) {
319
+        if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote')) {
320 320
             $classes .= ' wpinv-cpt';
321 321
         }
322 322
         
323
-        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
323
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
324 324
 
325 325
         $add_class = false;
326
-        if ( $pagenow == 'admin.php' && $page ) {
327
-            $add_class = strpos( $page, 'wpinv-' );
326
+        if ($pagenow == 'admin.php' && $page) {
327
+            $add_class = strpos($page, 'wpinv-');
328 328
         }
329 329
         
330 330
         $settings_class = array();
331
-        if ( $page == 'wpinv-settings' ) {
332
-            if ( !empty( $_REQUEST['tab'] ) ) {
333
-                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
331
+        if ($page == 'wpinv-settings') {
332
+            if (!empty($_REQUEST['tab'])) {
333
+                $settings_class[] = sanitize_text_field($_REQUEST['tab']);
334 334
             }
335 335
             
336
-            if ( !empty( $_REQUEST['section'] ) ) {
337
-                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
336
+            if (!empty($_REQUEST['section'])) {
337
+                $settings_class[] = sanitize_text_field($_REQUEST['section']);
338 338
             }
339 339
             
340
-            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
340
+            $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main';
341 341
         }
342 342
         
343
-        if ( !empty( $settings_class ) ) {
344
-            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
343
+        if (!empty($settings_class)) {
344
+            $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-'));
345 345
         }
346 346
         
347 347
         $post_type = wpinv_admin_post_type();
348 348
 
349
-        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
349
+        if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) {
350 350
             return $classes .= ' wpinv';
351 351
         }
352 352
         
353
-        if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) {
353
+        if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) {
354 354
             $classes .= ' wpi-editable-n';
355 355
         }
356 356
 
@@ -362,20 +362,20 @@  discard block
 block discarded – undo
362 362
     }
363 363
     
364 364
     public function wpinv_actions() {
365
-        if ( isset( $_REQUEST['wpi_action'] ) ) {
366
-            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
365
+        if (isset($_REQUEST['wpi_action'])) {
366
+            do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
367 367
         }
368 368
     }
369 369
     
370
-    public function pre_get_posts( $wp_query ) {
371
-        if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
372
-            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
370
+    public function pre_get_posts($wp_query) {
371
+        if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
372
+            $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
373 373
         }
374 374
         
375 375
         return $wp_query;
376 376
     }
377 377
     
378 378
     public function bp_invoicing_init() {
379
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
379
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
380 380
     }
381 381
 }
382 382
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Spacing   +228 added lines, -228 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
-                @ini_set( 'display_errors', 0 );
30
+            if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
31
+                @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
-        @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
54
-        @header( 'X-Robots-Tag: noindex' );
53
+        @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
54
+        @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() {
@@ -77,39 +77,39 @@  discard block
 block discarded – undo
77 77
             'buy_items' => true,
78 78
         );
79 79
 
80
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
81
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
80
+        foreach ($ajax_events as $ajax_event => $nopriv) {
81
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
82 82
             
83
-            if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) {
84
-                define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 );
83
+            if (!defined('WPI_AJAX_' . strtoupper($nopriv))) {
84
+                define('WPI_AJAX_' . strtoupper($nopriv), 1);
85 85
             }
86 86
 
87
-            if ( $nopriv ) {
88
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
87
+            if ($nopriv) {
88
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
89 89
 
90
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
90
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
91 91
             }
92 92
         }
93 93
     }
94 94
     
95 95
     public static function add_note() {
96
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
96
+        check_ajax_referer('add-invoice-note', '_nonce');
97 97
 
98
-        if ( !current_user_can( 'manage_options' ) ) {
98
+        if (!current_user_can('manage_options')) {
99 99
             die(-1);
100 100
         }
101 101
 
102
-        $post_id   = absint( $_POST['post_id'] );
103
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
104
-        $note_type = sanitize_text_field( $_POST['note_type'] );
102
+        $post_id   = absint($_POST['post_id']);
103
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
104
+        $note_type = sanitize_text_field($_POST['note_type']);
105 105
 
106 106
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
107 107
 
108
-        if ( $post_id > 0 ) {
109
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
108
+        if ($post_id > 0) {
109
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
110 110
 
111
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
112
-                wpinv_get_invoice_note_line_item( $note_id );
111
+            if ($note_id > 0 && !is_wp_error($note_id)) {
112
+                wpinv_get_invoice_note_line_item($note_id);
113 113
             }
114 114
         }
115 115
 
@@ -117,16 +117,16 @@  discard block
 block discarded – undo
117 117
     }
118 118
 
119 119
     public static function delete_note() {
120
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
120
+        check_ajax_referer('delete-invoice-note', '_nonce');
121 121
 
122
-        if ( !current_user_can( 'manage_options' ) ) {
122
+        if (!current_user_can('manage_options')) {
123 123
             die(-1);
124 124
         }
125 125
 
126 126
         $note_id = (int)$_POST['note_id'];
127 127
 
128
-        if ( $note_id > 0 ) {
129
-            wp_delete_comment( $note_id, true );
128
+        if ($note_id > 0) {
129
+            wp_delete_comment($note_id, true);
130 130
         }
131 131
 
132 132
         die();
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
     }
140 140
     
141 141
     public static function checkout() {
142
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
143
-            define( 'WPINV_CHECKOUT', true );
142
+        if (!defined('WPINV_CHECKOUT')) {
143
+            define('WPINV_CHECKOUT', true);
144 144
         }
145 145
 
146 146
         wpinv_process_checkout();
@@ -149,53 +149,53 @@  discard block
 block discarded – undo
149 149
     
150 150
     public static function add_invoice_item() {
151 151
         global $wpi_userID, $wpinv_ip_address_country;
152
-        check_ajax_referer( 'invoice-item', '_nonce' );
153
-        if ( !current_user_can( 'manage_options' ) ) {
152
+        check_ajax_referer('invoice-item', '_nonce');
153
+        if (!current_user_can('manage_options')) {
154 154
             die(-1);
155 155
         }
156 156
         
157
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
158
-        $invoice_id = absint( $_POST['invoice_id'] );
157
+        $item_id    = sanitize_text_field($_POST['item_id']);
158
+        $invoice_id = absint($_POST['invoice_id']);
159 159
         
160
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
160
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
161 161
             die();
162 162
         }
163 163
         
164
-        $invoice    = wpinv_get_invoice( $invoice_id );
165
-        if ( empty( $invoice ) ) {
164
+        $invoice = wpinv_get_invoice($invoice_id);
165
+        if (empty($invoice)) {
166 166
             die();
167 167
         }
168 168
         
169
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
169
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
170 170
             die(); // Don't allow modify items for paid invoice.
171 171
         }
172 172
         
173
-        if ( !empty( $_POST['user_id'] ) ) {
174
-            $wpi_userID = absint( $_POST['user_id'] ); 
173
+        if (!empty($_POST['user_id'])) {
174
+            $wpi_userID = absint($_POST['user_id']); 
175 175
         }
176 176
 
177
-        $item = new WPInv_Item( $item_id );
178
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
177
+        $item = new WPInv_Item($item_id);
178
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
179 179
             die();
180 180
         }
181 181
         
182 182
         // Validate item before adding to invoice because recurring item must be paid individually.
183
-        if ( !empty( $invoice->cart_details ) ) {
183
+        if (!empty($invoice->cart_details)) {
184 184
             $valid = true;
185 185
             
186
-            if ( $recurring_item = $invoice->get_recurring() ) {
187
-                if ( $recurring_item != $item_id ) {
186
+            if ($recurring_item = $invoice->get_recurring()) {
187
+                if ($recurring_item != $item_id) {
188 188
                     $valid = false;
189 189
                 }
190
-            } else if ( wpinv_is_recurring_item( $item_id ) ) {
190
+            } else if (wpinv_is_recurring_item($item_id)) {
191 191
                 $valid = false;
192 192
             }
193 193
             
194
-            if ( !$valid ) {
194
+            if (!$valid) {
195 195
                 $response               = array();
196 196
                 $response['success']    = false;
197
-                $response['msg']        = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' );
198
-                wp_send_json( $response );
197
+                $response['msg']        = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing');
198
+                wp_send_json($response);
199 199
             }
200 200
         }
201 201
         
@@ -203,9 +203,9 @@  discard block
 block discarded – undo
203 203
         
204 204
         $data                   = array();
205 205
         $data['invoice_id']     = $invoice_id;
206
-        $data['cart_discounts'] = $invoice->get_discounts( true );
206
+        $data['cart_discounts'] = $invoice->get_discounts(true);
207 207
         
208
-        wpinv_set_checkout_session( $data );
208
+        wpinv_set_checkout_session($data);
209 209
         
210 210
         $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1;
211 211
 
@@ -220,21 +220,21 @@  discard block
 block discarded – undo
220 220
             'fees'          => array()
221 221
         );
222 222
 
223
-        $invoice->add_item( $item_id, $args );
223
+        $invoice->add_item($item_id, $args);
224 224
         $invoice->save();
225 225
         
226
-        if ( empty( $_POST['country'] ) ) {
226
+        if (empty($_POST['country'])) {
227 227
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
228 228
         }
229
-        if ( empty( $_POST['state'] ) ) {
229
+        if (empty($_POST['state'])) {
230 230
             $_POST['state'] = $invoice->state;
231 231
         }
232 232
          
233
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
234
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
233
+        $invoice->country   = sanitize_text_field($_POST['country']);
234
+        $invoice->state     = sanitize_text_field($_POST['state']);
235 235
         
236
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
237
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
236
+        $invoice->set('country', sanitize_text_field($_POST['country']));
237
+        $invoice->set('state', sanitize_text_field($_POST['state']));
238 238
         
239 239
         $wpinv_ip_address_country = $invoice->country;
240 240
 
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
         
243 243
         $response                       = array();
244 244
         $response['success']            = true;
245
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
245
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
246 246
         $response['data']['subtotal']   = $invoice->get_subtotal();
247 247
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
248 248
         $response['data']['tax']        = $invoice->get_tax();
@@ -254,40 +254,40 @@  discard block
 block discarded – undo
254 254
         
255 255
         wpinv_set_checkout_session($checkout_session);
256 256
         
257
-        wp_send_json( $response );
257
+        wp_send_json($response);
258 258
     }
259 259
     
260 260
     public static function remove_invoice_item() {
261 261
         global $wpi_userID, $wpinv_ip_address_country;
262 262
         
263
-        check_ajax_referer( 'invoice-item', '_nonce' );
264
-        if ( !current_user_can( 'manage_options' ) ) {
263
+        check_ajax_referer('invoice-item', '_nonce');
264
+        if (!current_user_can('manage_options')) {
265 265
             die(-1);
266 266
         }
267 267
         
268
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
269
-        $invoice_id = absint( $_POST['invoice_id'] );
270
-        $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false;
268
+        $item_id    = sanitize_text_field($_POST['item_id']);
269
+        $invoice_id = absint($_POST['invoice_id']);
270
+        $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false;
271 271
         
272
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
272
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
273 273
             die();
274 274
         }
275 275
 
276
-        $invoice    = wpinv_get_invoice( $invoice_id );
277
-        if ( empty( $invoice ) ) {
276
+        $invoice = wpinv_get_invoice($invoice_id);
277
+        if (empty($invoice)) {
278 278
             die();
279 279
         }
280 280
         
281
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
281
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
282 282
             die(); // Don't allow modify items for paid invoice.
283 283
         }
284 284
         
285
-        if ( !empty( $_POST['user_id'] ) ) {
286
-            $wpi_userID = absint( $_POST['user_id'] ); 
285
+        if (!empty($_POST['user_id'])) {
286
+            $wpi_userID = absint($_POST['user_id']); 
287 287
         }
288 288
 
289
-        $item       = new WPInv_Item( $item_id );
290
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
289
+        $item = new WPInv_Item($item_id);
290
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
291 291
             die();
292 292
         }
293 293
         
@@ -295,9 +295,9 @@  discard block
 block discarded – undo
295 295
         
296 296
         $data                   = array();
297 297
         $data['invoice_id']     = $invoice_id;
298
-        $data['cart_discounts'] = $invoice->get_discounts( true );
298
+        $data['cart_discounts'] = $invoice->get_discounts(true);
299 299
         
300
-        wpinv_set_checkout_session( $data );
300
+        wpinv_set_checkout_session($data);
301 301
 
302 302
         $args = array(
303 303
             'id'         => $item_id,
@@ -305,21 +305,21 @@  discard block
 block discarded – undo
305 305
             'cart_index' => $cart_index
306 306
         );
307 307
 
308
-        $invoice->remove_item( $item_id, $args );
308
+        $invoice->remove_item($item_id, $args);
309 309
         $invoice->save();
310 310
         
311
-        if ( empty( $_POST['country'] ) ) {
311
+        if (empty($_POST['country'])) {
312 312
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
313 313
         }
314
-        if ( empty( $_POST['state'] ) ) {
314
+        if (empty($_POST['state'])) {
315 315
             $_POST['state'] = $invoice->state;
316 316
         }
317 317
          
318
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
319
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
318
+        $invoice->country   = sanitize_text_field($_POST['country']);
319
+        $invoice->state     = sanitize_text_field($_POST['state']);
320 320
         
321
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
322
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
321
+        $invoice->set('country', sanitize_text_field($_POST['country']));
322
+        $invoice->set('state', sanitize_text_field($_POST['state']));
323 323
         
324 324
         $wpinv_ip_address_country = $invoice->country;
325 325
         
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
         
328 328
         $response                       = array();
329 329
         $response['success']            = true;
330
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
330
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
331 331
         $response['data']['subtotal']   = $invoice->get_subtotal();
332 332
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
333 333
         $response['data']['tax']        = $invoice->get_tax();
@@ -339,40 +339,40 @@  discard block
 block discarded – undo
339 339
         
340 340
         wpinv_set_checkout_session($checkout_session);
341 341
         
342
-        wp_send_json( $response );
342
+        wp_send_json($response);
343 343
     }
344 344
     
345 345
     public static function create_invoice_item() {
346
-        check_ajax_referer( 'invoice-item', '_nonce' );
347
-        if ( !current_user_can( 'manage_options' ) ) {
346
+        check_ajax_referer('invoice-item', '_nonce');
347
+        if (!current_user_can('manage_options')) {
348 348
             die(-1);
349 349
         }
350 350
         
351
-        $invoice_id = absint( $_POST['invoice_id'] );
351
+        $invoice_id = absint($_POST['invoice_id']);
352 352
 
353 353
         // Find the item
354
-        if ( !is_numeric( $invoice_id ) ) {
354
+        if (!is_numeric($invoice_id)) {
355 355
             die();
356 356
         }        
357 357
         
358
-        $invoice     = wpinv_get_invoice( $invoice_id );
359
-        if ( empty( $invoice ) ) {
358
+        $invoice = wpinv_get_invoice($invoice_id);
359
+        if (empty($invoice)) {
360 360
             die();
361 361
         }
362 362
         
363 363
         // Validate item before adding to invoice because recurring item must be paid individually.
364
-        if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) {
364
+        if (!empty($invoice->cart_details) && $invoice->get_recurring()) {
365 365
             $response               = array();
366 366
             $response['success']    = false;
367
-            $response['msg']        = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' );
368
-            wp_send_json( $response );
367
+            $response['msg']        = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing');
368
+            wp_send_json($response);
369 369
         }        
370 370
         
371 371
         $save_item = $_POST['_wpinv_quick'];
372 372
         
373 373
         $meta               = array();
374 374
         $meta['type']       = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom';
375
-        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0;
375
+        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0;
376 376
         $meta['vat_rule']   = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital';
377 377
         $meta['vat_class']  = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard';
378 378
         
@@ -382,9 +382,9 @@  discard block
 block discarded – undo
382 382
         $data['meta']           = $meta;
383 383
         
384 384
         $item = new WPInv_Item();
385
-        $item->create( $data );
385
+        $item->create($data);
386 386
         
387
-        if ( !empty( $item ) ) {
387
+        if (!empty($item)) {
388 388
             $_POST['item_id']   = $item->ID;
389 389
             $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1;
390 390
             
@@ -394,15 +394,15 @@  discard block
 block discarded – undo
394 394
     }
395 395
     
396 396
     public static function get_billing_details() {
397
-        check_ajax_referer( 'get-billing-details', '_nonce' );
397
+        check_ajax_referer('get-billing-details', '_nonce');
398 398
         
399
-        if ( !current_user_can( 'manage_options' ) ) {
399
+        if (!current_user_can('manage_options')) {
400 400
             die(-1);
401 401
         }
402 402
 
403 403
         $user_id            = (int)$_POST['user_id'];
404 404
         $billing_details    = wpinv_get_user_address($user_id);
405
-        $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
405
+        $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
406 406
         
407 407
         if (isset($billing_details['user_id'])) {
408 408
             unset($billing_details['user_id']);
@@ -416,20 +416,20 @@  discard block
 block discarded – undo
416 416
         $response['success']                    = true;
417 417
         $response['data']['billing_details']    = $billing_details;
418 418
         
419
-        wp_send_json( $response );
419
+        wp_send_json($response);
420 420
     }
421 421
     
422 422
     public static function admin_recalculate_totals() {
423 423
         global $wpi_userID, $wpinv_ip_address_country;
424 424
         
425
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
426
-        if ( !current_user_can( 'manage_options' ) ) {
425
+        check_ajax_referer('wpinv-nonce', '_nonce');
426
+        if (!current_user_can('manage_options')) {
427 427
             die(-1);
428 428
         }
429 429
         
430
-        $invoice_id = absint( $_POST['invoice_id'] );        
431
-        $invoice    = wpinv_get_invoice( $invoice_id );
432
-        if ( empty( $invoice ) ) {
430
+        $invoice_id = absint($_POST['invoice_id']);        
431
+        $invoice    = wpinv_get_invoice($invoice_id);
432
+        if (empty($invoice)) {
433 433
             die();
434 434
         }
435 435
         
@@ -437,23 +437,23 @@  discard block
 block discarded – undo
437 437
         
438 438
         $data                   = array();
439 439
         $data['invoice_id']     = $invoice_id;
440
-        $data['cart_discounts'] = $invoice->get_discounts( true );
440
+        $data['cart_discounts'] = $invoice->get_discounts(true);
441 441
         
442
-        wpinv_set_checkout_session( $data );
442
+        wpinv_set_checkout_session($data);
443 443
         
444
-        if ( !empty( $_POST['user_id'] ) ) {
445
-            $wpi_userID = absint( $_POST['user_id'] ); 
444
+        if (!empty($_POST['user_id'])) {
445
+            $wpi_userID = absint($_POST['user_id']); 
446 446
         }
447 447
         
448
-        if ( empty( $_POST['country'] ) ) {
448
+        if (empty($_POST['country'])) {
449 449
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
450 450
         }
451 451
             
452
-        $invoice->country = sanitize_text_field( $_POST['country'] );
453
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
454
-        if ( isset( $_POST['state'] ) ) {
455
-            $invoice->state = sanitize_text_field( $_POST['state'] );
456
-            $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
452
+        $invoice->country = sanitize_text_field($_POST['country']);
453
+        $invoice->set('country', sanitize_text_field($_POST['country']));
454
+        if (isset($_POST['state'])) {
455
+            $invoice->state = sanitize_text_field($_POST['state']);
456
+            $invoice->set('state', sanitize_text_field($_POST['state']));
457 457
         }
458 458
         
459 459
         $wpinv_ip_address_country = $invoice->country;
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
         
463 463
         $response                       = array();
464 464
         $response['success']            = true;
465
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
465
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
466 466
         $response['data']['subtotal']   = $invoice->get_subtotal();
467 467
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
468 468
         $response['data']['tax']        = $invoice->get_tax();
@@ -474,25 +474,25 @@  discard block
 block discarded – undo
474 474
         
475 475
         wpinv_set_checkout_session($checkout_session);
476 476
         
477
-        wp_send_json( $response );
477
+        wp_send_json($response);
478 478
     }
479 479
     
480 480
     public static function admin_apply_discount() {
481 481
         global $wpi_userID;
482 482
         
483
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
484
-        if ( !current_user_can( 'manage_options' ) ) {
483
+        check_ajax_referer('wpinv-nonce', '_nonce');
484
+        if (!current_user_can('manage_options')) {
485 485
             die(-1);
486 486
         }
487 487
         
488
-        $invoice_id = absint( $_POST['invoice_id'] );
489
-        $discount_code = sanitize_text_field( $_POST['code'] );
490
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
488
+        $invoice_id = absint($_POST['invoice_id']);
489
+        $discount_code = sanitize_text_field($_POST['code']);
490
+        if (empty($invoice_id) || empty($discount_code)) {
491 491
             die();
492 492
         }
493 493
         
494
-        $invoice = wpinv_get_invoice( $invoice_id );
495
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
494
+        $invoice = wpinv_get_invoice($invoice_id);
495
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
496 496
             die();
497 497
         }
498 498
         
@@ -500,49 +500,49 @@  discard block
 block discarded – undo
500 500
         
501 501
         $data                   = array();
502 502
         $data['invoice_id']     = $invoice_id;
503
-        $data['cart_discounts'] = $invoice->get_discounts( true );
503
+        $data['cart_discounts'] = $invoice->get_discounts(true);
504 504
         
505
-        wpinv_set_checkout_session( $data );
505
+        wpinv_set_checkout_session($data);
506 506
         
507 507
         $response               = array();
508 508
         $response['success']    = false;
509
-        $response['msg']        = __( 'This discount is invalid.', 'invoicing' );
509
+        $response['msg']        = __('This discount is invalid.', 'invoicing');
510 510
         $response['data']['code'] = $discount_code;
511 511
         
512
-        if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) {
513
-            $discounts = wpinv_set_cart_discount( $discount_code );
512
+        if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) {
513
+            $discounts = wpinv_set_cart_discount($discount_code);
514 514
             
515 515
             $response['success'] = true;
516
-            $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' );
517
-        }  else {
516
+            $response['msg'] = __('Discount has been applied successfully.', 'invoicing');
517
+        } else {
518 518
             $errors = wpinv_get_errors();
519
-            if ( !empty( $errors['wpinv-discount-error'] ) ) {
519
+            if (!empty($errors['wpinv-discount-error'])) {
520 520
                 $response['msg'] = $errors['wpinv-discount-error'];
521 521
             }
522
-            wpinv_unset_error( 'wpinv-discount-error' );
522
+            wpinv_unset_error('wpinv-discount-error');
523 523
         }
524 524
         
525 525
         wpinv_set_checkout_session($checkout_session);
526 526
         
527
-        wp_send_json( $response );
527
+        wp_send_json($response);
528 528
     }
529 529
     
530 530
     public static function admin_remove_discount() {
531 531
         global $wpi_userID;
532 532
         
533
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
534
-        if ( !current_user_can( 'manage_options' ) ) {
533
+        check_ajax_referer('wpinv-nonce', '_nonce');
534
+        if (!current_user_can('manage_options')) {
535 535
             die(-1);
536 536
         }
537 537
         
538
-        $invoice_id = absint( $_POST['invoice_id'] );
539
-        $discount_code = sanitize_text_field( $_POST['code'] );
540
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
538
+        $invoice_id = absint($_POST['invoice_id']);
539
+        $discount_code = sanitize_text_field($_POST['code']);
540
+        if (empty($invoice_id) || empty($discount_code)) {
541 541
             die();
542 542
         }
543 543
         
544
-        $invoice = wpinv_get_invoice( $invoice_id );
545
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
544
+        $invoice = wpinv_get_invoice($invoice_id);
545
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
546 546
             die();
547 547
         }
548 548
         
@@ -550,38 +550,38 @@  discard block
 block discarded – undo
550 550
         
551 551
         $data                   = array();
552 552
         $data['invoice_id']     = $invoice_id;
553
-        $data['cart_discounts'] = $invoice->get_discounts( true );
553
+        $data['cart_discounts'] = $invoice->get_discounts(true);
554 554
         
555
-        wpinv_set_checkout_session( $data );
555
+        wpinv_set_checkout_session($data);
556 556
         
557 557
         $response               = array();
558 558
         $response['success']    = false;
559 559
         $response['msg']        = NULL;
560 560
         
561
-        $discounts  = wpinv_unset_cart_discount( $discount_code );
561
+        $discounts = wpinv_unset_cart_discount($discount_code);
562 562
         $response['success'] = true;
563
-        $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' );
563
+        $response['msg'] = __('Discount has been removed successfully.', 'invoicing');
564 564
         
565 565
         wpinv_set_checkout_session($checkout_session);
566 566
         
567
-        wp_send_json( $response );
567
+        wp_send_json($response);
568 568
     }
569 569
     
570 570
     public static function check_email() {
571
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
572
-        if ( !current_user_can( 'manage_options' ) ) {
571
+        check_ajax_referer('wpinv-nonce', '_nonce');
572
+        if (!current_user_can('manage_options')) {
573 573
             die(-1);
574 574
         }
575 575
         
576
-        $email = sanitize_text_field( $_POST['email'] );
576
+        $email = sanitize_text_field($_POST['email']);
577 577
         
578 578
         $response = array();
579
-        if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) {
579
+        if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) {
580 580
             $user_id            = $user_data->ID;
581 581
             $user_login         = $user_data->user_login;
582 582
             $display_name       = $user_data->display_name ? $user_data->display_name : $user_login;
583 583
             $billing_details    = wpinv_get_user_address($user_id);
584
-            $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
584
+            $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
585 585
             
586 586
             if (isset($billing_details['user_id'])) {
587 587
                 unset($billing_details['user_id']);
@@ -597,54 +597,54 @@  discard block
 block discarded – undo
597 597
             $response['data']['billing_details']    = $billing_details;
598 598
         }
599 599
         
600
-        wp_send_json( $response );
600
+        wp_send_json($response);
601 601
     }
602 602
     
603 603
     public static function run_tool() {
604
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
605
-        if ( !current_user_can( 'manage_options' ) ) {
604
+        check_ajax_referer('wpinv-nonce', '_nonce');
605
+        if (!current_user_can('manage_options')) {
606 606
             die(-1);
607 607
         }
608 608
         
609
-        $tool = sanitize_text_field( $_POST['tool'] );
609
+        $tool = sanitize_text_field($_POST['tool']);
610 610
         
611
-        do_action( 'wpinv_run_tool' );
611
+        do_action('wpinv_run_tool');
612 612
         
613
-        if ( !empty( $tool ) ) {
614
-            do_action( 'wpinv_tool_' . $tool );
613
+        if (!empty($tool)) {
614
+            do_action('wpinv_tool_' . $tool);
615 615
         }
616 616
     }
617 617
     
618 618
     public static function apply_discount() {
619 619
         global $wpi_userID;
620 620
         
621
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
621
+        check_ajax_referer('wpinv-nonce', '_nonce');
622 622
         
623 623
         $response = array();
624 624
         
625
-        if ( isset( $_POST['code'] ) ) {
626
-            $discount_code = sanitize_text_field( $_POST['code'] );
625
+        if (isset($_POST['code'])) {
626
+            $discount_code = sanitize_text_field($_POST['code']);
627 627
 
628 628
             $response['success']        = false;
629 629
             $response['msg']            = '';
630 630
             $response['data']['code']   = $discount_code;
631 631
             
632 632
             $invoice = wpinv_get_invoice_cart();
633
-            if ( empty( $invoice->ID ) ) {
634
-                $response['msg'] = __( 'Invalid checkout request.', 'invoicing' );
635
-                wp_send_json( $response );
633
+            if (empty($invoice->ID)) {
634
+                $response['msg'] = __('Invalid checkout request.', 'invoicing');
635
+                wp_send_json($response);
636 636
             }
637 637
 
638 638
             $wpi_userID = $invoice->get_user_id();
639 639
 
640
-            if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) {
641
-                $discount       = wpinv_get_discount_by_code( $discount_code );
642
-                $discounts      = wpinv_set_cart_discount( $discount_code );
643
-                $amount         = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
644
-                $total          = wpinv_get_cart_total( null, $discounts );
645
-                $cart_totals    = wpinv_recalculate_tax( true );
640
+            if (wpinv_is_discount_valid($discount_code, $wpi_userID)) {
641
+                $discount       = wpinv_get_discount_by_code($discount_code);
642
+                $discounts      = wpinv_set_cart_discount($discount_code);
643
+                $amount         = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
644
+                $total          = wpinv_get_cart_total(null, $discounts);
645
+                $cart_totals    = wpinv_recalculate_tax(true);
646 646
             
647
-                if ( !empty( $cart_totals ) ) {
647
+                if (!empty($cart_totals)) {
648 648
                     $response['success']        = true;
649 649
                     $response['data']           = $cart_totals;
650 650
                     $response['data']['code']   = $discount_code;
@@ -653,29 +653,29 @@  discard block
 block discarded – undo
653 653
                 }
654 654
             } else {
655 655
                 $errors = wpinv_get_errors();
656
-                $response['msg']  = $errors['wpinv-discount-error'];
657
-                wpinv_unset_error( 'wpinv-discount-error' );
656
+                $response['msg'] = $errors['wpinv-discount-error'];
657
+                wpinv_unset_error('wpinv-discount-error');
658 658
             }
659 659
 
660 660
             // Allow for custom discount code handling
661
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
661
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
662 662
         }
663 663
         
664
-        wp_send_json( $response );
664
+        wp_send_json($response);
665 665
     }
666 666
     
667 667
     public static function remove_discount() {
668
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
668
+        check_ajax_referer('wpinv-nonce', '_nonce');
669 669
         
670 670
         $response = array();
671 671
         
672
-        if ( isset( $_POST['code'] ) ) {
673
-            $discount_code  = sanitize_text_field( $_POST['code'] );
674
-            $discounts      = wpinv_unset_cart_discount( $discount_code );
675
-            $total          = wpinv_get_cart_total( null, $discounts );
676
-            $cart_totals    = wpinv_recalculate_tax( true );
672
+        if (isset($_POST['code'])) {
673
+            $discount_code  = sanitize_text_field($_POST['code']);
674
+            $discounts      = wpinv_unset_cart_discount($discount_code);
675
+            $total          = wpinv_get_cart_total(null, $discounts);
676
+            $cart_totals    = wpinv_recalculate_tax(true);
677 677
             
678
-            if ( !empty( $cart_totals ) ) {
678
+            if (!empty($cart_totals)) {
679 679
                 $response['success']        = true;
680 680
                 $response['data']           = $cart_totals;
681 681
                 $response['data']['code']   = $discount_code;
@@ -684,10 +684,10 @@  discard block
 block discarded – undo
684 684
             }
685 685
             
686 686
             // Allow for custom discount code handling
687
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
687
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
688 688
         }
689 689
         
690
-        wp_send_json( $response );
690
+        wp_send_json($response);
691 691
     }
692 692
 
693 693
 
@@ -696,20 +696,20 @@  discard block
 block discarded – undo
696 696
      *
697 697
      * @since 1.0.0
698 698
      */
699
-    public function buy_items(){
699
+    public function buy_items() {
700 700
 
701 701
         $user_id = get_current_user_id();
702
-        if(!$user_id ){ // if not logged in then lets redirect to the login page
702
+        if (!$user_id) { // if not logged in then lets redirect to the login page
703 703
 
704 704
             wp_send_json(array(
705
-                'success' => wp_login_url( wp_get_referer() )
705
+                'success' => wp_login_url(wp_get_referer())
706 706
             ));
707
-        }else{
707
+        } else {
708 708
 
709 709
             // only check nonce if logged in as it could be cached when logged out.
710
-            if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) {
710
+            if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) {
711 711
                 wp_send_json(array(
712
-                    'error' => __('Security checks failed.','invoicing')
712
+                    'error' => __('Security checks failed.', 'invoicing')
713 713
                 ));
714 714
                 wp_die();
715 715
             }
@@ -717,36 +717,36 @@  discard block
 block discarded – undo
717 717
             // allow to set a custom price through post_id
718 718
             $items = $_POST['items'];
719 719
             $related_post_id = isset($_POST['post_id']) ? (int)$_POST['post_id'] : 0;
720
-            $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id,'_wpi_custom_price',true)) : 0;
720
+            $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0;
721 721
 
722 722
 
723 723
             $cart_items = array();
724
-            if($items){
725
-                $items = explode(',',$items);
726
-                foreach($items as $item){
724
+            if ($items) {
725
+                $items = explode(',', $items);
726
+                foreach ($items as $item) {
727 727
                     $item_id = $item;
728 728
                     $quantity = 1;
729 729
                     if (strpos($item, '|') !== false) {
730
-                        $item_parts = explode('|',$item);
730
+                        $item_parts = explode('|', $item);
731 731
                         $item_id = $item_parts[0];
732 732
                         $quantity = $item_parts[1];
733 733
                     }
734 734
 
735
-                    if($item_id && $quantity){
735
+                    if ($item_id && $quantity) {
736 736
                         $cart_items_arr = array(
737 737
                             'id'            => (int)$item_id,
738 738
                             'quantity'      => (int)$quantity
739 739
                         );
740 740
 
741 741
                         // if there is a related post id then add it to meta
742
-                        if($related_post_id){
742
+                        if ($related_post_id) {
743 743
                             $cart_items_arr['meta'] = array(
744 744
                                 'post_id'   => $related_post_id
745 745
                             );
746 746
                         }
747 747
 
748 748
                         // if there is a custom price then set it.
749
-                        if($custom_item_price){
749
+                        if ($custom_item_price) {
750 750
                             $cart_items_arr['custom_price'] = $custom_item_price;
751 751
 
752 752
                         }
@@ -765,12 +765,12 @@  discard block
 block discarded – undo
765 765
              * @param int $related_post_id The related post id if any.
766 766
              * @since 1.0.0
767 767
              */
768
-            $cart_items = apply_filters('wpinv_buy_cart_items',$cart_items,$related_post_id);
768
+            $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id);
769 769
 
770 770
 
771 771
             //make sure its not in the cart already, if it is then redirect to checkout.
772 772
             $cart_invoice = wpinv_get_invoice_cart();
773
-            if(isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items)==serialize($cart_items) ){
773
+            if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) {
774 774
                 wp_send_json(array(
775 775
                     'success' =>  $cart_invoice->get_checkout_payment_url()
776 776
                 ));
@@ -779,25 +779,25 @@  discard block
 block discarded – undo
779 779
 
780 780
 
781 781
             // check if user has invoice with same items waiting to be paid.
782
-            $user_invoices = wpinv_get_users_invoices( $user_id , 1 , false , 'pending' );
783
-            if(!empty($user_invoices)){
782
+            $user_invoices = wpinv_get_users_invoices($user_id, 1, false, 'pending');
783
+            if (!empty($user_invoices)) {
784 784
 
785
-                foreach($user_invoices as $user_invoice){
785
+                foreach ($user_invoices as $user_invoice) {
786 786
                     $user_cart_details = array();
787
-                    $invoice  = wpinv_get_invoice( $user_invoice->ID );
787
+                    $invoice = wpinv_get_invoice($user_invoice->ID);
788 788
                     $cart_details = $invoice->get_cart_details();
789
-                    if(!empty($cart_details)){
790
-                        foreach($cart_details as $invoice_item){
789
+                    if (!empty($cart_details)) {
790
+                        foreach ($cart_details as $invoice_item) {
791 791
 
792 792
                             $ii_arr = array();
793 793
                             $ii_arr['id'] = (int)$invoice_item['id'];
794 794
                             $ii_arr['quantity'] = (int)$invoice_item['quantity'];
795 795
 
796
-                            if(isset($invoice_item['meta']) && !empty($invoice_item['meta'])){
796
+                            if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) {
797 797
                                 $ii_arr['meta'] = $invoice_item['meta'];
798 798
                             }
799 799
 
800
-                            if(isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])){
800
+                            if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) {
801 801
                                 $ii_arr['custom_price'] = $invoice_item['custom_price'];
802 802
                             }
803 803
 
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
                         }
807 807
                     }
808 808
 
809
-                    if(!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)){
809
+                    if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) {
810 810
                         wp_send_json(array(
811 811
                             'success' =>  $invoice->get_checkout_payment_url()
812 812
                         ));
@@ -819,7 +819,7 @@  discard block
 block discarded – undo
819 819
 
820 820
 
821 821
             // Create invoice and send user to checkout
822
-            if(!empty($cart_items)){
822
+            if (!empty($cart_items)) {
823 823
 
824 824
                 $invoice_data = array(
825 825
                     'status'        =>  'wpi-pending',
@@ -829,26 +829,26 @@  discard block
 block discarded – undo
829 829
                 );
830 830
 
831 831
                 // default invoice args
832
-                $invoice_data['status']  = !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending';
833
-                $invoice_data['user_id'] = !empty( $invoice_data['user_id'] ) ? (int)$invoice_data['user_id'] : get_current_user_id();
832
+                $invoice_data['status']  = !empty($invoice_data['status']) ? $invoice_data['status'] : 'pending';
833
+                $invoice_data['user_id'] = !empty($invoice_data['user_id']) ? (int)$invoice_data['user_id'] : get_current_user_id();
834 834
 
835
-                $invoice = wpinv_insert_invoice( $invoice_data, true );
835
+                $invoice = wpinv_insert_invoice($invoice_data, true);
836 836
 
837
-                if(isset($invoice->ID)){
837
+                if (isset($invoice->ID)) {
838 838
 
839 839
                     wp_send_json(array(
840 840
                         'success' =>  $invoice->get_checkout_payment_url()
841 841
                     ));
842 842
 
843
-                }else{
843
+                } else {
844 844
                     wp_send_json(array(
845
-                        'error' => __('Invoice failed to create','invoicing')
845
+                        'error' => __('Invoice failed to create', 'invoicing')
846 846
                     ));
847 847
                 }
848 848
 
849
-            }else{
849
+            } else {
850 850
                 wp_send_json(array(
851
-                    'error' => __('Items not valid.','invoicing')
851
+                    'error' => __('Items not valid.', 'invoicing')
852 852
                 ));
853 853
             }
854 854
 
Please login to merge, or discard this patch.
includes/class-wpinv-shortcodes.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit; // Exit if accessed directly
4 4
 }
5 5
 
@@ -15,11 +15,11 @@  discard block
 block discarded – undo
15 15
             'wpinv_buy'  => __CLASS__ . '::buy',
16 16
         );
17 17
 
18
-        foreach ( $shortcodes as $shortcode => $function ) {
19
-            add_shortcode( apply_filters( "{$shortcode}_shortcode_tag", $shortcode ), $function );
18
+        foreach ($shortcodes as $shortcode => $function) {
19
+            add_shortcode(apply_filters("{$shortcode}_shortcode_tag", $shortcode), $function);
20 20
         }
21 21
         
22
-        add_shortcode( 'wpinv_messages', __CLASS__ . '::messages' );
22
+        add_shortcode('wpinv_messages', __CLASS__ . '::messages');
23 23
     }
24 24
 
25 25
     public static function shortcode_wrapper(
@@ -33,25 +33,25 @@  discard block
 block discarded – undo
33 33
     ) {
34 34
         ob_start();
35 35
 
36
-        echo empty( $wrapper['before'] ) ? '<div class="' . esc_attr( $wrapper['class'] ) . '">' : $wrapper['before'];
37
-        call_user_func( $function, $atts );
38
-        echo empty( $wrapper['after'] ) ? '</div>' : $wrapper['after'];
36
+        echo empty($wrapper['before']) ? '<div class="' . esc_attr($wrapper['class']) . '">' : $wrapper['before'];
37
+        call_user_func($function, $atts);
38
+        echo empty($wrapper['after']) ? '</div>' : $wrapper['after'];
39 39
 
40 40
         return ob_get_clean();
41 41
     }
42 42
 
43
-    public static function checkout( $atts = array(), $content = null ) {
44
-        return wpinv_checkout_form( $atts, $content );
43
+    public static function checkout($atts = array(), $content = null) {
44
+        return wpinv_checkout_form($atts, $content);
45 45
     }
46 46
 
47
-    public static function messages( $atts, $content = null ) {
47
+    public static function messages($atts, $content = null) {
48 48
         ob_start();
49 49
         wpinv_print_errors();
50 50
         return '<div class="wpinv">' . ob_get_clean() . '</div>';
51 51
     }
52 52
     
53
-    public static function history( $atts, $content = null ) {
54
-        return self::shortcode_wrapper( array( __CLASS__, 'history_output' ), $atts );
53
+    public static function history($atts, $content = null) {
54
+        return self::shortcode_wrapper(array(__CLASS__, 'history_output'), $atts);
55 55
     }
56 56
 
57 57
     /**
@@ -59,28 +59,28 @@  discard block
 block discarded – undo
59 59
      *
60 60
      * @param array $atts
61 61
      */
62
-    public static function history_output( $atts ) {
63
-        do_action( 'wpinv_before_user_invoice_history' );
64
-        wpinv_get_template_part( 'wpinv-invoice-history', $atts );
65
-        do_action( 'wpinv_after_user_invoice_history' );
62
+    public static function history_output($atts) {
63
+        do_action('wpinv_before_user_invoice_history');
64
+        wpinv_get_template_part('wpinv-invoice-history', $atts);
65
+        do_action('wpinv_after_user_invoice_history');
66 66
     }
67 67
     
68
-    public static function receipt( $atts, $content = null ) {
69
-        return wpinv_payment_receipt( $atts, $content );
68
+    public static function receipt($atts, $content = null) {
69
+        return wpinv_payment_receipt($atts, $content);
70 70
     }
71 71
 
72
-    public static function buy( $atts, $content = null ) {
73
-        $a = shortcode_atts( array(
72
+    public static function buy($atts, $content = null) {
73
+        $a = shortcode_atts(array(
74 74
             'items' => '', // should be used like: item_id|quantity,item_id|quantity,item_id|quantity
75
-            'title' => __('Buy Now', 'invoicing' ), // the button title
75
+            'title' => __('Buy Now', 'invoicing'), // the button title
76 76
             'post_id' => '', // any related post_id
77
-        ), $atts );
77
+        ), $atts);
78 78
         
79 79
         $post_id = isset($a['post_id']) ? (int)$a['post_id'] : '';
80 80
 
81 81
         $html = '<div class="wpi-buy-button-wrapper">';
82
-        $html .= '<input type="submit" name="submit" class="button button-primary wpi-buy-button" value="'.$a['title'].'" onclick="wpi_buy(\''.$a['items'].'\','.$post_id.');" />';
83
-        $html .= wp_nonce_field( 'wpinv_buy_items', 'wpinv_buy_nonce', true, false );
82
+        $html .= '<input type="submit" name="submit" class="button button-primary wpi-buy-button" value="' . $a['title'] . '" onclick="wpi_buy(\'' . $a['items'] . '\',' . $post_id . ');" />';
83
+        $html .= wp_nonce_field('wpinv_buy_items', 'wpinv_buy_nonce', true, false);
84 84
         $html .= '</div>';
85 85
 
86 86
 
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 1 patch
Spacing   +688 added lines, -688 removed lines patch added patch discarded remove patch
@@ -7,101 +7,101 @@  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', 'invoicing/' );
22
+    return apply_filters('wpinv_template_path', 'invoicing/');
23 23
 }
24 24
 
25
-function wpinv_post_class( $classes, $class, $post_id ) {
25
+function wpinv_post_class($classes, $class, $post_id) {
26 26
     global $pagenow, $typenow;
27 27
 
28
-    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' ) {
28
+    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow && get_post_meta($post_id, '_wpinv_type', true) == 'package') {
29 29
         $classes[] = 'wpi-gd-package';
30 30
     }
31 31
     return $classes;
32 32
 }
33
-add_filter( 'post_class', 'wpinv_post_class', 10, 3 );
33
+add_filter('post_class', 'wpinv_post_class', 10, 3);
34 34
 
35
-function wpinv_display_invoice_top_bar( $invoice ) {
36
-    if ( empty( $invoice ) ) {
35
+function wpinv_display_invoice_top_bar($invoice) {
36
+    if (empty($invoice)) {
37 37
         return;
38 38
     }
39 39
     ?>
40 40
     <div class="row wpinv-top-bar no-print">
41 41
         <div class="container">
42 42
             <div class="col-xs-6">
43
-                <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?>
43
+                <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?>
44 44
             </div>
45 45
             <div class="col-xs-6 text-right">
46
-                <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?>
46
+                <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?>
47 47
             </div>
48 48
         </div>
49 49
     </div>
50 50
     <?php
51 51
 }
52 52
 
53
-function wpinv_invoice_display_left_actions( $invoice ) {
54
-    if ( empty( $invoice ) ) {
53
+function wpinv_invoice_display_left_actions($invoice) {
54
+    if (empty($invoice)) {
55 55
         return; // Exit if invoice is not set.
56 56
     }
57 57
     
58
-    if ( $invoice->post_type == 'wpi_invoice' ) {
59
-        if ( $invoice->needs_payment() ) {
60
-            ?> <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
58
+    if ($invoice->post_type == 'wpi_invoice') {
59
+        if ($invoice->needs_payment()) {
60
+            ?> <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
61 61
         }
62 62
     }
63 63
     do_action('wpinv_invoice_display_left_actions', $invoice);
64 64
 }
65 65
 
66
-function wpinv_invoice_display_right_actions( $invoice ) {
67
-    if ( empty( $invoice ) ) {
66
+function wpinv_invoice_display_right_actions($invoice) {
67
+    if (empty($invoice)) {
68 68
         return; // Exit if invoice is not set.
69 69
     }
70 70
 
71
-    if ( $invoice->post_type == 'wpi_invoice' ) { ?>
72
-        <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a>
73
-        <?php if ( is_user_logged_in() ) { ?>
74
-        &nbsp;&nbsp;<a class="btn btn-warning btn-sm" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a>
71
+    if ($invoice->post_type == 'wpi_invoice') { ?>
72
+        <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a>
73
+        <?php if (is_user_logged_in()) { ?>
74
+        &nbsp;&nbsp;<a class="btn btn-warning btn-sm" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a>
75 75
         <?php }
76 76
     }
77 77
     do_action('wpinv_invoice_display_right_actions', $invoice);
78 78
 }
79 79
 
80
-function wpinv_before_invoice_content( $content ) {
80
+function wpinv_before_invoice_content($content) {
81 81
     global $post;
82 82
 
83
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
83
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
84 84
         ob_start();
85
-        do_action( 'wpinv_before_invoice_content', $post->ID );
85
+        do_action('wpinv_before_invoice_content', $post->ID);
86 86
         $content = ob_get_clean() . $content;
87 87
     }
88 88
 
89 89
     return $content;
90 90
 }
91
-add_filter( 'the_content', 'wpinv_before_invoice_content' );
91
+add_filter('the_content', 'wpinv_before_invoice_content');
92 92
 
93
-function wpinv_after_invoice_content( $content ) {
93
+function wpinv_after_invoice_content($content) {
94 94
     global $post;
95 95
 
96
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
96
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
97 97
         ob_start();
98
-        do_action( 'wpinv_after_invoice_content', $post->ID );
98
+        do_action('wpinv_after_invoice_content', $post->ID);
99 99
         $content .= ob_get_clean();
100 100
     }
101 101
 
102 102
     return $content;
103 103
 }
104
-add_filter( 'the_content', 'wpinv_after_invoice_content' );
104
+add_filter('the_content', 'wpinv_after_invoice_content');
105 105
 
106 106
 function wpinv_get_templates_dir() {
107 107
     return WPINV_PLUGIN_DIR . 'templates';
@@ -111,105 +111,105 @@  discard block
 block discarded – undo
111 111
     return WPINV_PLUGIN_URL . 'templates';
112 112
 }
113 113
 
114
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
115
-    if ( ! empty( $args ) && is_array( $args ) ) {
116
-		extract( $args );
114
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
115
+    if (!empty($args) && is_array($args)) {
116
+		extract($args);
117 117
 	}
118 118
 
119
-	$located = wpinv_locate_template( $template_name, $template_path, $default_path );
119
+	$located = wpinv_locate_template($template_name, $template_path, $default_path);
120 120
 	// Allow 3rd party plugin filter template file from their plugin.
121
-	$located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path );
121
+	$located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path);
122 122
 
123
-	if ( ! file_exists( $located ) ) {
124
-        _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
123
+	if (!file_exists($located)) {
124
+        _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1');
125 125
 		return;
126 126
 	}
127 127
 
128
-	do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
128
+	do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args);
129 129
 
130
-	include( $located );
130
+	include($located);
131 131
 
132
-	do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
132
+	do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args);
133 133
 }
134 134
 
135
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
135
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
136 136
 	ob_start();
137
-	wpinv_get_template( $template_name, $args, $template_path, $default_path );
137
+	wpinv_get_template($template_name, $args, $template_path, $default_path);
138 138
 	return ob_get_clean();
139 139
 }
140 140
 
141
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
142
-    if ( ! $template_path ) {
141
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
142
+    if (!$template_path) {
143 143
         $template_path = wpinv_template_path();
144 144
     }
145 145
 
146
-    if ( ! $default_path ) {
146
+    if (!$default_path) {
147 147
         $default_path = WPINV_PLUGIN_DIR . 'templates/';
148 148
     }
149 149
 
150 150
     // Look within passed path within the theme - this is priority.
151 151
     $template = locate_template(
152 152
         array(
153
-            trailingslashit( $template_path ) . $template_name,
153
+            trailingslashit($template_path) . $template_name,
154 154
             $template_name
155 155
         )
156 156
     );
157 157
 
158 158
     // Get default templates/
159
-    if ( !$template && $default_path ) {
160
-        $template = trailingslashit( $default_path ) . $template_name;
159
+    if (!$template && $default_path) {
160
+        $template = trailingslashit($default_path) . $template_name;
161 161
     }
162 162
 
163 163
     // Return what we found.
164
-    return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path );
164
+    return apply_filters('wpinv_locate_template', $template, $template_name, $template_path);
165 165
 }
166 166
 
167
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
168
-	do_action( 'get_template_part_' . $slug, $slug, $name );
167
+function wpinv_get_template_part($slug, $name = null, $load = true) {
168
+	do_action('get_template_part_' . $slug, $slug, $name);
169 169
 
170 170
 	// Setup possible parts
171 171
 	$templates = array();
172
-	if ( isset( $name ) )
172
+	if (isset($name))
173 173
 		$templates[] = $slug . '-' . $name . '.php';
174 174
 	$templates[] = $slug . '.php';
175 175
 
176 176
 	// Allow template parts to be filtered
177
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
177
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
178 178
 
179 179
 	// Return the part that is found
180
-	return wpinv_locate_tmpl( $templates, $load, false );
180
+	return wpinv_locate_tmpl($templates, $load, false);
181 181
 }
182 182
 
183
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
183
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
184 184
 	// No file found yet
185 185
 	$located = false;
186 186
 
187 187
 	// Try to find a template file
188
-	foreach ( (array)$template_names as $template_name ) {
188
+	foreach ((array)$template_names as $template_name) {
189 189
 
190 190
 		// Continue if template is empty
191
-		if ( empty( $template_name ) )
191
+		if (empty($template_name))
192 192
 			continue;
193 193
 
194 194
 		// Trim off any slashes from the template name
195
-		$template_name = ltrim( $template_name, '/' );
195
+		$template_name = ltrim($template_name, '/');
196 196
 
197 197
 		// try locating this template file by looping through the template paths
198
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
198
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
199 199
 
200
-			if( file_exists( $template_path . $template_name ) ) {
200
+			if (file_exists($template_path . $template_name)) {
201 201
 				$located = $template_path . $template_name;
202 202
 				break;
203 203
 			}
204 204
 		}
205 205
 
206
-		if( !empty( $located ) ) {
206
+		if (!empty($located)) {
207 207
 			break;
208 208
 		}
209 209
 	}
210 210
 
211
-	if ( ( true == $load ) && ! empty( $located ) )
212
-		load_template( $located, $require_once );
211
+	if ((true == $load) && !empty($located))
212
+		load_template($located, $require_once);
213 213
 
214 214
 	return $located;
215 215
 }
@@ -218,143 +218,143 @@  discard block
 block discarded – undo
218 218
 	$template_dir = wpinv_get_theme_template_dir_name();
219 219
 
220 220
 	$file_paths = array(
221
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
222
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
221
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
222
+		10 => trailingslashit(get_template_directory()) . $template_dir,
223 223
 		100 => wpinv_get_templates_dir()
224 224
 	);
225 225
 
226
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
226
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
227 227
 
228 228
 	// sort the file paths based on priority
229
-	ksort( $file_paths, SORT_NUMERIC );
229
+	ksort($file_paths, SORT_NUMERIC);
230 230
 
231
-	return array_map( 'trailingslashit', $file_paths );
231
+	return array_map('trailingslashit', $file_paths);
232 232
 }
233 233
 
234 234
 function wpinv_get_theme_template_dir_name() {
235
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'wpinv_templates' ) );
235
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'wpinv_templates'));
236 236
 }
237 237
 
238 238
 function wpinv_checkout_meta_tags() {
239 239
 
240 240
 	$pages   = array();
241
-	$pages[] = wpinv_get_option( 'success_page' );
242
-	$pages[] = wpinv_get_option( 'failure_page' );
243
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
241
+	$pages[] = wpinv_get_option('success_page');
242
+	$pages[] = wpinv_get_option('failure_page');
243
+	$pages[] = wpinv_get_option('invoice_history_page');
244 244
 
245
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
245
+	if (!wpinv_is_checkout() && !is_page($pages)) {
246 246
 		return;
247 247
 	}
248 248
 
249 249
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
250 250
 }
251
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
251
+add_action('wp_head', 'wpinv_checkout_meta_tags');
252 252
 
253
-function wpinv_add_body_classes( $class ) {
253
+function wpinv_add_body_classes($class) {
254 254
 	$classes = (array)$class;
255 255
 
256
-	if( wpinv_is_checkout() ) {
256
+	if (wpinv_is_checkout()) {
257 257
 		$classes[] = 'wpinv-checkout';
258 258
 		$classes[] = 'wpinv-page';
259 259
 	}
260 260
 
261
-	if( wpinv_is_success_page() ) {
261
+	if (wpinv_is_success_page()) {
262 262
 		$classes[] = 'wpinv-success';
263 263
 		$classes[] = 'wpinv-page';
264 264
 	}
265 265
 
266
-	if( wpinv_is_failed_transaction_page() ) {
266
+	if (wpinv_is_failed_transaction_page()) {
267 267
 		$classes[] = 'wpinv-failed-transaction';
268 268
 		$classes[] = 'wpinv-page';
269 269
 	}
270 270
 
271
-	if( wpinv_is_invoice_history_page() ) {
271
+	if (wpinv_is_invoice_history_page()) {
272 272
 		$classes[] = 'wpinv-history';
273 273
 		$classes[] = 'wpinv-page';
274 274
 	}
275 275
 
276
-	if( wpinv_is_test_mode() ) {
276
+	if (wpinv_is_test_mode()) {
277 277
 		$classes[] = 'wpinv-test-mode';
278 278
 		$classes[] = 'wpinv-page';
279 279
 	}
280 280
 
281
-	return array_unique( $classes );
281
+	return array_unique($classes);
282 282
 }
283
-add_filter( 'body_class', 'wpinv_add_body_classes' );
283
+add_filter('body_class', 'wpinv_add_body_classes');
284 284
 
285
-function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) {
286
-    $args = array( 'nopaging' => true );
285
+function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') {
286
+    $args = array('nopaging' => true);
287 287
 
288
-    if ( ! empty( $status ) )
288
+    if (!empty($status))
289 289
         $args['post_status'] = $status;
290 290
 
291
-    $discounts = wpinv_get_discounts( $args );
291
+    $discounts = wpinv_get_discounts($args);
292 292
     $options   = array();
293 293
 
294
-    if ( $discounts ) {
295
-        foreach ( $discounts as $discount ) {
296
-            $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) );
294
+    if ($discounts) {
295
+        foreach ($discounts as $discount) {
296
+            $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID));
297 297
         }
298 298
     } else {
299
-        $options[0] = __( 'No discounts found', 'invoicing' );
299
+        $options[0] = __('No discounts found', 'invoicing');
300 300
     }
301 301
 
302
-    $output = wpinv_html_select( array(
302
+    $output = wpinv_html_select(array(
303 303
         'name'             => $name,
304 304
         'selected'         => $selected,
305 305
         'options'          => $options,
306 306
         'show_option_all'  => false,
307 307
         'show_option_none' => false,
308
-    ) );
308
+    ));
309 309
 
310 310
     return $output;
311 311
 }
312 312
 
313
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
314
-    $current     = date( 'Y' );
315
-    $start_year  = $current - absint( $years_before );
316
-    $end_year    = $current + absint( $years_after );
317
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
313
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
314
+    $current     = date('Y');
315
+    $start_year  = $current - absint($years_before);
316
+    $end_year    = $current + absint($years_after);
317
+    $selected    = empty($selected) ? date('Y') : $selected;
318 318
     $options     = array();
319 319
 
320
-    while ( $start_year <= $end_year ) {
321
-        $options[ absint( $start_year ) ] = $start_year;
320
+    while ($start_year <= $end_year) {
321
+        $options[absint($start_year)] = $start_year;
322 322
         $start_year++;
323 323
     }
324 324
 
325
-    $output = wpinv_html_select( array(
325
+    $output = wpinv_html_select(array(
326 326
         'name'             => $name,
327 327
         'selected'         => $selected,
328 328
         'options'          => $options,
329 329
         'show_option_all'  => false,
330 330
         'show_option_none' => false
331
-    ) );
331
+    ));
332 332
 
333 333
     return $output;
334 334
 }
335 335
 
336
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
336
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
337 337
     $month   = 1;
338 338
     $options = array();
339
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
339
+    $selected = empty($selected) ? date('n') : $selected;
340 340
 
341
-    while ( $month <= 12 ) {
342
-        $options[ absint( $month ) ] = wpinv_month_num_to_name( $month );
341
+    while ($month <= 12) {
342
+        $options[absint($month)] = wpinv_month_num_to_name($month);
343 343
         $month++;
344 344
     }
345 345
 
346
-    $output = wpinv_html_select( array(
346
+    $output = wpinv_html_select(array(
347 347
         'name'             => $name,
348 348
         'selected'         => $selected,
349 349
         'options'          => $options,
350 350
         'show_option_all'  => false,
351 351
         'show_option_none' => false
352
-    ) );
352
+    ));
353 353
 
354 354
     return $output;
355 355
 }
356 356
 
357
-function wpinv_html_select( $args = array() ) {
357
+function wpinv_html_select($args = array()) {
358 358
     $defaults = array(
359 359
         'options'          => array(),
360 360
         'name'             => null,
@@ -364,8 +364,8 @@  discard block
 block discarded – undo
364 364
         'chosen'           => false,
365 365
         'placeholder'      => null,
366 366
         'multiple'         => false,
367
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
368
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
367
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
368
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
369 369
         'data'             => array(),
370 370
         'onchange'         => null,
371 371
         'required'         => false,
@@ -373,78 +373,78 @@  discard block
 block discarded – undo
373 373
         'readonly'         => false,
374 374
     );
375 375
 
376
-    $args = wp_parse_args( $args, $defaults );
376
+    $args = wp_parse_args($args, $defaults);
377 377
 
378 378
     $data_elements = '';
379
-    foreach ( $args['data'] as $key => $value ) {
380
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
379
+    foreach ($args['data'] as $key => $value) {
380
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
381 381
     }
382 382
 
383
-    if( $args['multiple'] ) {
383
+    if ($args['multiple']) {
384 384
         $multiple = ' MULTIPLE';
385 385
     } else {
386 386
         $multiple = '';
387 387
     }
388 388
 
389
-    if( $args['chosen'] ) {
389
+    if ($args['chosen']) {
390 390
         $args['class'] .= ' wpinv-select-chosen';
391 391
     }
392 392
 
393
-    if( $args['placeholder'] ) {
393
+    if ($args['placeholder']) {
394 394
         $placeholder = $args['placeholder'];
395 395
     } else {
396 396
         $placeholder = '';
397 397
     }
398 398
     
399 399
     $options = '';
400
-    if( !empty( $args['onchange'] ) ) {
401
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
400
+    if (!empty($args['onchange'])) {
401
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
402 402
     }
403 403
     
404
-    if( !empty( $args['required'] ) ) {
404
+    if (!empty($args['required'])) {
405 405
         $options .= ' required="required"';
406 406
     }
407 407
     
408
-    if( !empty( $args['disabled'] ) ) {
408
+    if (!empty($args['disabled'])) {
409 409
         $options .= ' disabled';
410 410
     }
411 411
     
412
-    if( !empty( $args['readonly'] ) ) {
412
+    if (!empty($args['readonly'])) {
413 413
         $options .= ' readonly';
414 414
     }
415 415
 
416
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
417
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
416
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
417
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
418 418
 
419
-    if ( $args['show_option_all'] ) {
420
-        if( $args['multiple'] ) {
421
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
419
+    if ($args['show_option_all']) {
420
+        if ($args['multiple']) {
421
+            $selected = selected(true, in_array(0, $args['selected']), false);
422 422
         } else {
423
-            $selected = selected( $args['selected'], 0, false );
423
+            $selected = selected($args['selected'], 0, false);
424 424
         }
425
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
425
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
426 426
     }
427 427
 
428
-    if ( !empty( $args['options'] ) ) {
428
+    if (!empty($args['options'])) {
429 429
 
430
-        if ( $args['show_option_none'] ) {
431
-            if( $args['multiple'] ) {
432
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
430
+        if ($args['show_option_none']) {
431
+            if ($args['multiple']) {
432
+                $selected = selected(true, in_array("", $args['selected']), false);
433 433
             } else {
434
-                $selected = selected( $args['selected'] === "", true, false );
434
+                $selected = selected($args['selected'] === "", true, false);
435 435
             }
436
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
436
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
437 437
         }
438 438
 
439
-        foreach( $args['options'] as $key => $option ) {
439
+        foreach ($args['options'] as $key => $option) {
440 440
 
441
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
442
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
441
+            if ($args['multiple'] && is_array($args['selected'])) {
442
+                $selected = selected(true, (bool)in_array($key, $args['selected']), false);
443 443
             } else {
444
-                $selected = selected( $args['selected'], $key, false );
444
+                $selected = selected($args['selected'], $key, false);
445 445
             }
446 446
 
447
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
447
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
448 448
         }
449 449
     }
450 450
 
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
     return $output;
454 454
 }
455 455
 
456
-function wpinv_item_dropdown( $args = array() ) {
456
+function wpinv_item_dropdown($args = array()) {
457 457
     $defaults = array(
458 458
         'name'              => 'wpi_item',
459 459
         'id'                => 'wpi_item',
@@ -462,15 +462,15 @@  discard block
 block discarded – undo
462 462
         'selected'          => 0,
463 463
         'chosen'            => false,
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
         'with_packages'     => true,
470 470
         'show_recurring'    => false,
471 471
     );
472 472
 
473
-    $args = wp_parse_args( $args, $defaults );
473
+    $args = wp_parse_args($args, $defaults);
474 474
 
475 475
     $item_args = array(
476 476
         'post_type'      => 'wpi_item',
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
         'posts_per_page' => $args['number']
480 480
     );
481 481
     
482
-    if ( !$args['with_packages'] ) {
482
+    if (!$args['with_packages']) {
483 483
         $item_args['meta_query'] = array(
484 484
             array(
485 485
                 'key'       => '_wpinv_type',
@@ -489,42 +489,42 @@  discard block
 block discarded – undo
489 489
         );
490 490
     }
491 491
 
492
-    $items      = get_posts( $item_args );
492
+    $items      = get_posts($item_args);
493 493
     $options    = array();
494
-    if ( $items ) {
495
-        foreach ( $items as $item ) {
496
-            $title = esc_html( $item->post_title );
494
+    if ($items) {
495
+        foreach ($items as $item) {
496
+            $title = esc_html($item->post_title);
497 497
             
498
-            if ( !empty( $args['show_recurring'] ) ) {
499
-                $title .= wpinv_get_item_suffix( $item->ID, false );
498
+            if (!empty($args['show_recurring'])) {
499
+                $title .= wpinv_get_item_suffix($item->ID, false);
500 500
             }
501 501
             
502
-            $options[ absint( $item->ID ) ] = $title;
502
+            $options[absint($item->ID)] = $title;
503 503
         }
504 504
     }
505 505
 
506 506
     // This ensures that any selected items are included in the drop down
507
-    if( is_array( $args['selected'] ) ) {
508
-        foreach( $args['selected'] as $item ) {
509
-            if( ! in_array( $item, $options ) ) {
510
-                $title = get_the_title( $item );
511
-                if ( !empty( $args['show_recurring'] ) ) {
512
-                    $title .= wpinv_get_item_suffix( $item, false );
507
+    if (is_array($args['selected'])) {
508
+        foreach ($args['selected'] as $item) {
509
+            if (!in_array($item, $options)) {
510
+                $title = get_the_title($item);
511
+                if (!empty($args['show_recurring'])) {
512
+                    $title .= wpinv_get_item_suffix($item, false);
513 513
                 }
514 514
                 $options[$item] = $title;
515 515
             }
516 516
         }
517
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
518
-        if ( ! in_array( $args['selected'], $options ) ) {
519
-            $title = get_the_title( $args['selected'] );
520
-            if ( !empty( $args['show_recurring'] ) ) {
521
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
517
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
518
+        if (!in_array($args['selected'], $options)) {
519
+            $title = get_the_title($args['selected']);
520
+            if (!empty($args['show_recurring'])) {
521
+                $title .= wpinv_get_item_suffix($args['selected'], false);
522 522
             }
523
-            $options[$args['selected']] = get_the_title( $args['selected'] );
523
+            $options[$args['selected']] = get_the_title($args['selected']);
524 524
         }
525 525
     }
526 526
 
527
-    $output = wpinv_html_select( array(
527
+    $output = wpinv_html_select(array(
528 528
         'name'             => $args['name'],
529 529
         'selected'         => $args['selected'],
530 530
         'id'               => $args['id'],
@@ -536,12 +536,12 @@  discard block
 block discarded – undo
536 536
         'show_option_all'  => $args['show_option_all'],
537 537
         'show_option_none' => $args['show_option_none'],
538 538
         'data'             => $args['data'],
539
-    ) );
539
+    ));
540 540
 
541 541
     return $output;
542 542
 }
543 543
 
544
-function wpinv_html_checkbox( $args = array() ) {
544
+function wpinv_html_checkbox($args = array()) {
545 545
     $defaults = array(
546 546
         'name'     => null,
547 547
         'current'  => null,
@@ -552,38 +552,38 @@  discard block
 block discarded – undo
552 552
         )
553 553
     );
554 554
 
555
-    $args = wp_parse_args( $args, $defaults );
555
+    $args = wp_parse_args($args, $defaults);
556 556
 
557
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
557
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
558 558
     $options = '';
559
-    if ( ! empty( $args['options']['disabled'] ) ) {
559
+    if (!empty($args['options']['disabled'])) {
560 560
         $options .= ' disabled="disabled"';
561
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
561
+    } elseif (!empty($args['options']['readonly'])) {
562 562
         $options .= ' readonly';
563 563
     }
564 564
 
565
-    $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 ) . ' />';
565
+    $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) . ' />';
566 566
 
567 567
     return $output;
568 568
 }
569 569
 
570
-function wpinv_html_text( $args = array() ) {
570
+function wpinv_html_text($args = array()) {
571 571
     // Backwards compatibility
572
-    if ( func_num_args() > 1 ) {
572
+    if (func_num_args() > 1) {
573 573
         $args = func_get_args();
574 574
 
575 575
         $name  = $args[0];
576
-        $value = isset( $args[1] ) ? $args[1] : '';
577
-        $label = isset( $args[2] ) ? $args[2] : '';
578
-        $desc  = isset( $args[3] ) ? $args[3] : '';
576
+        $value = isset($args[1]) ? $args[1] : '';
577
+        $label = isset($args[2]) ? $args[2] : '';
578
+        $desc  = isset($args[3]) ? $args[3] : '';
579 579
     }
580 580
 
581 581
     $defaults = array(
582 582
         'id'           => '',
583
-        'name'         => isset( $name )  ? $name  : 'text',
584
-        'value'        => isset( $value ) ? $value : null,
585
-        'label'        => isset( $label ) ? $label : null,
586
-        'desc'         => isset( $desc )  ? $desc  : null,
583
+        'name'         => isset($name) ? $name : 'text',
584
+        'value'        => isset($value) ? $value : null,
585
+        'label'        => isset($label) ? $label : null,
586
+        'desc'         => isset($desc) ? $desc : null,
587 587
         'placeholder'  => '',
588 588
         'class'        => 'regular-text',
589 589
         'disabled'     => false,
@@ -593,51 +593,51 @@  discard block
 block discarded – undo
593 593
         'data'         => false
594 594
     );
595 595
 
596
-    $args = wp_parse_args( $args, $defaults );
596
+    $args = wp_parse_args($args, $defaults);
597 597
 
598
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
598
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
599 599
     $options = '';
600
-    if( $args['required'] ) {
600
+    if ($args['required']) {
601 601
         $options .= ' required="required"';
602 602
     }
603
-    if( $args['readonly'] ) {
603
+    if ($args['readonly']) {
604 604
         $options .= ' readonly';
605 605
     }
606
-    if( $args['readonly'] ) {
606
+    if ($args['readonly']) {
607 607
         $options .= ' readonly';
608 608
     }
609 609
 
610 610
     $data = '';
611
-    if ( !empty( $args['data'] ) ) {
612
-        foreach ( $args['data'] as $key => $value ) {
613
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
611
+    if (!empty($args['data'])) {
612
+        foreach ($args['data'] as $key => $value) {
613
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
614 614
         }
615 615
     }
616 616
 
617
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
618
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
619
-    if ( ! empty( $args['desc'] ) ) {
620
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
617
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
618
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
619
+    if (!empty($args['desc'])) {
620
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
621 621
     }
622 622
 
623
-    $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 ) . '/>';
623
+    $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) . '/>';
624 624
 
625 625
     $output .= '</span>';
626 626
 
627 627
     return $output;
628 628
 }
629 629
 
630
-function wpinv_html_date_field( $args = array() ) {
631
-    if( empty( $args['class'] ) ) {
630
+function wpinv_html_date_field($args = array()) {
631
+    if (empty($args['class'])) {
632 632
         $args['class'] = 'wpiDatepicker';
633
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
633
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
634 634
         $args['class'] .= ' wpiDatepicker';
635 635
     }
636 636
 
637
-    return wpinv_html_text( $args );
637
+    return wpinv_html_text($args);
638 638
 }
639 639
 
640
-function wpinv_html_textarea( $args = array() ) {
640
+function wpinv_html_textarea($args = array()) {
641 641
     $defaults = array(
642 642
         'name'        => 'textarea',
643 643
         'value'       => null,
@@ -647,31 +647,31 @@  discard block
 block discarded – undo
647 647
         'disabled'    => false
648 648
     );
649 649
 
650
-    $args = wp_parse_args( $args, $defaults );
650
+    $args = wp_parse_args($args, $defaults);
651 651
 
652
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
652
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
653 653
     $disabled = '';
654
-    if( $args['disabled'] ) {
654
+    if ($args['disabled']) {
655 655
         $disabled = ' disabled="disabled"';
656 656
     }
657 657
 
658
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
659
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
660
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
658
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
659
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
660
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
661 661
 
662
-    if ( ! empty( $args['desc'] ) ) {
663
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
662
+    if (!empty($args['desc'])) {
663
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
664 664
     }
665 665
     $output .= '</span>';
666 666
 
667 667
     return $output;
668 668
 }
669 669
 
670
-function wpinv_html_ajax_user_search( $args = array() ) {
670
+function wpinv_html_ajax_user_search($args = array()) {
671 671
     $defaults = array(
672 672
         'name'        => 'user_id',
673 673
         'value'       => null,
674
-        'placeholder' => __( 'Enter username', 'invoicing' ),
674
+        'placeholder' => __('Enter username', 'invoicing'),
675 675
         'label'       => null,
676 676
         'desc'        => null,
677 677
         'class'       => '',
@@ -680,13 +680,13 @@  discard block
 block discarded – undo
680 680
         'data'        => false
681 681
     );
682 682
 
683
-    $args = wp_parse_args( $args, $defaults );
683
+    $args = wp_parse_args($args, $defaults);
684 684
 
685 685
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
686 686
 
687 687
     $output  = '<span class="wpinv_user_search_wrap">';
688
-        $output .= wpinv_html_text( $args );
689
-        $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>';
688
+        $output .= wpinv_html_text($args);
689
+        $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>';
690 690
     $output .= '</span>';
691 691
 
692 692
     return $output;
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
 function wpinv_ip_geolocation() {
696 696
     global $wpinv_euvat;
697 697
     
698
-    $ip         = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : '';    
698
+    $ip         = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : '';    
699 699
     $content    = '';
700 700
     $iso        = '';
701 701
     $country    = '';
@@ -706,69 +706,69 @@  discard block
 block discarded – undo
706 706
     $credit     = '';
707 707
     $address    = '';
708 708
     
709
-    if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) {
709
+    if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) {
710 710
         try {
711 711
             $iso        = $geoip2_city->country->isoCode;
712 712
             $country    = $geoip2_city->country->name;
713
-            $region     = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : '';
713
+            $region     = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : '';
714 714
             $city       = $geoip2_city->city->name;
715 715
             $longitude  = $geoip2_city->location->longitude;
716 716
             $latitude   = $geoip2_city->location->latitude;
717
-            $credit     = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' );
718
-        } catch( Exception $e ) { }
717
+            $credit     = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing');
718
+        } catch (Exception $e) { }
719 719
     }
720 720
     
721
-    if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) {
721
+    if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) {
722 722
         try {
723
-            $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
723
+            $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
724 724
             
725
-            if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) {
725
+            if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) {
726 726
                 $iso        = $load_xml->geoplugin_countryCode;
727 727
                 $country    = $load_xml->geoplugin_countryName;
728
-                $region     = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : '';
729
-                $city       = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : '';
728
+                $region     = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : '';
729
+                $city       = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : '';
730 730
                 $longitude  = $load_xml->geoplugin_longitude;
731 731
                 $latitude   = $load_xml->geoplugin_latitude;
732 732
                 $credit     = $load_xml->geoplugin_credit;
733
-                $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;
733
+                $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;
734 734
             }
735
-        } catch( Exception $e ) { }
735
+        } catch (Exception $e) { }
736 736
     }
737 737
     
738
-    if ( $iso && $longitude && $latitude ) {
739
-        if ( $city ) {
738
+    if ($iso && $longitude && $latitude) {
739
+        if ($city) {
740 740
             $address .= $city . ', ';
741 741
         }
742 742
         
743
-        if ( $region ) {
743
+        if ($region) {
744 744
             $address .= $region . ', ';
745 745
         }
746 746
         
747 747
         $address .= $country . ' (' . $iso . ')';
748
-        $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>';
749
-        $content .= '<p>'. $credit . '</p>';
748
+        $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>';
749
+        $content .= '<p>' . $credit . '</p>';
750 750
     } else {
751
-        $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>';
751
+        $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>';
752 752
     }
753 753
     ?>
754 754
 <!DOCTYPE html>
755
-<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>
755
+<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>
756 756
 <body>
757
-    <?php if ( $latitude && $latitude ) { ?>
757
+    <?php if ($latitude && $latitude) { ?>
758 758
     <div id="map"></div>
759 759
         <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script>
760 760
         <script type="text/javascript">
761 761
         var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
762 762
             osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
763 763
             osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}),
764
-            latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>);
764
+            latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
765 765
 
766 766
         var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]});
767 767
 
768 768
         var marker = new L.Marker(latlng);
769 769
         map.addLayer(marker);
770 770
 
771
-        marker.bindPopup("<p><?php esc_attr_e( $address );?></p>");
771
+        marker.bindPopup("<p><?php esc_attr_e($address); ?></p>");
772 772
     </script>
773 773
     <?php } ?>
774 774
     <div style="height:100px"><?php echo $content; ?></div>
@@ -776,31 +776,31 @@  discard block
 block discarded – undo
776 776
 <?php
777 777
     exit;
778 778
 }
779
-add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
780
-add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
779
+add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
780
+add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
781 781
 
782 782
 // Set up the template for the invoice.
783
-function wpinv_template( $template ) {
783
+function wpinv_template($template) {
784 784
     global $post, $wp_query;
785 785
     
786
-    if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) {
787
-        if ( wpinv_user_can_print_invoice( $post->ID ) ) {
788
-            $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false );
786
+    if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) {
787
+        if (wpinv_user_can_print_invoice($post->ID)) {
788
+            $template = wpinv_get_template_part('wpinv-invoice-print', false, false);
789 789
         } else {
790
-            if ( !is_user_logged_in() && !empty( $_REQUEST['_wpipay'] ) && $invoice = wpinv_get_invoice( $post->ID ) ) {
790
+            if (!is_user_logged_in() && !empty($_REQUEST['_wpipay']) && $invoice = wpinv_get_invoice($post->ID)) {
791 791
                 $user_id = $invoice->get_user_id();
792
-                $secret = sanitize_text_field( $_GET['_wpipay'] );
792
+                $secret = sanitize_text_field($_GET['_wpipay']);
793 793
 
794
-                if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key() ) ) { // valid invoice link
795
-                    $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
794
+                if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key())) { // valid invoice link
795
+                    $redirect_to = remove_query_arg('_wpipay', get_permalink());
796 796
 
797
-                    wpinv_guest_redirect( $redirect_to, $user_id );
797
+                    wpinv_guest_redirect($redirect_to, $user_id);
798 798
                     wpinv_die();
799 799
                 }
800 800
             }
801
-            $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
801
+            $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
802 802
 
803
-            wp_redirect( $redirect_to );
803
+            wp_redirect($redirect_to);
804 804
             wpinv_die();
805 805
         }
806 806
     }
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
 
811 811
 function wpinv_get_business_address() {
812 812
     $business_address   = wpinv_store_address();
813
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
813
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
814 814
     
815 815
     /*
816 816
     $default_country    = wpinv_get_default_country();
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
     
835 835
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
836 836
     
837
-    return apply_filters( 'wpinv_get_business_address', $business_address );
837
+    return apply_filters('wpinv_get_business_address', $business_address);
838 838
 }
839 839
 
840 840
 function wpinv_display_from_address() {
@@ -844,188 +844,188 @@  discard block
 block discarded – undo
844 844
     if (empty($from_name)) {
845 845
         $from_name = wpinv_get_business_name();
846 846
     }
847
-    ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div>
847
+    ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div>
848 848
     <div class="wrapper col-xs-10">
849
-        <div class="name"><?php echo esc_html( $from_name ); ?></div>
850
-        <?php if ( $address = wpinv_get_business_address() ) { ?>
851
-        <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div>
849
+        <div class="name"><?php echo esc_html($from_name); ?></div>
850
+        <?php if ($address = wpinv_get_business_address()) { ?>
851
+        <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div>
852 852
         <?php } ?>
853
-        <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?>
854
-        <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s' ), $email_from );?></div>
853
+        <?php if ($email_from = wpinv_mail_get_from_address()) { ?>
854
+        <div class="email_from"><?php echo wp_sprintf(__('Email: %s'), $email_from); ?></div>
855 855
         <?php } ?>
856 856
     </div>
857 857
     <?php
858 858
 }
859 859
 
860
-function wpinv_watermark( $id = 0 ) {
861
-    $output = wpinv_get_watermark( $id );
860
+function wpinv_watermark($id = 0) {
861
+    $output = wpinv_get_watermark($id);
862 862
     
863
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
863
+    return apply_filters('wpinv_get_watermark', $output, $id);
864 864
 }
865 865
 
866
-function wpinv_get_watermark( $id ) {
867
-    if ( !$id > 0 ) {
866
+function wpinv_get_watermark($id) {
867
+    if (!$id > 0) {
868 868
         return NULL;
869 869
     }
870
-    $invoice = wpinv_get_invoice( $id );
870
+    $invoice = wpinv_get_invoice($id);
871 871
     
872
-    if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) {
873
-        if ( $invoice->is_paid() ) {
874
-            return __( 'Paid', 'invoicing' );
872
+    if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) {
873
+        if ($invoice->is_paid()) {
874
+            return __('Paid', 'invoicing');
875 875
         }
876
-        if ( $invoice->is_refunded() ) {
877
-            return __( 'Refunded', 'invoicing' );
876
+        if ($invoice->is_refunded()) {
877
+            return __('Refunded', 'invoicing');
878 878
         }
879
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
880
-            return __( 'Cancelled', 'invoicing' );
879
+        if ($invoice->has_status(array('wpi-cancelled'))) {
880
+            return __('Cancelled', 'invoicing');
881 881
         }
882 882
     }
883 883
     
884 884
     return NULL;
885 885
 }
886 886
 
887
-function wpinv_display_invoice_details( $invoice ) {
887
+function wpinv_display_invoice_details($invoice) {
888 888
     global $wpinv_euvat;
889 889
     
890 890
     $invoice_id = $invoice->ID;
891 891
     $vat_name   = $wpinv_euvat->get_vat_name();
892 892
     $use_taxes  = wpinv_use_taxes();
893 893
     
894
-    $invoice_status = wpinv_get_invoice_status( $invoice_id );
894
+    $invoice_status = wpinv_get_invoice_status($invoice_id);
895 895
     
896
-    if($invoice->post_type == 'wpi_invoice') $type = 'Invoice';
897
-    elseif($invoice->post_type == 'wpi_quote') $type = 'Quote';
896
+    if ($invoice->post_type == 'wpi_invoice') $type = 'Invoice';
897
+    elseif ($invoice->post_type == 'wpi_quote') $type = 'Quote';
898 898
     ?>
899 899
     <table class="table table-bordered table-sm">
900
-        <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?>
900
+        <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?>
901 901
             <tr class="wpi-row-number">
902
-                <th><?php echo sprintf(__( '%s Number', 'invoicing' ), $type); ?></th>
903
-                <td><?php echo esc_html( $invoice_number ); ?></td>
902
+                <th><?php echo sprintf(__('%s Number', 'invoicing'), $type); ?></th>
903
+                <td><?php echo esc_html($invoice_number); ?></td>
904 904
             </tr>
905 905
         <?php } ?>
906 906
         <tr class="wpi-row-status">
907
-            <th><?php echo wp_sprintf(__( '%s Status', 'invoicing' ), $type); ?></th>
908
-            <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td>
907
+            <th><?php echo wp_sprintf(__('%s Status', 'invoicing'), $type); ?></th>
908
+            <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td>
909 909
         </tr>
910
-        <?php if ( $invoice->is_renewal() ) { ?>
910
+        <?php if ($invoice->is_renewal()) { ?>
911 911
         <tr class="wpi-row-parent">
912
-            <th><?php echo wp_sprintf(__( 'Parent %s', 'invoicing' ), $type); ?></th>
913
-            <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td>
912
+            <th><?php echo wp_sprintf(__('Parent %s', 'invoicing'), $type); ?></th>
913
+            <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td>
914 914
         </tr>
915 915
         <?php } ?>
916 916
         <tr class="wpi-row-gateway">
917
-            <th><?php _e( 'Payment Method', 'invoicing' ); ?></th>
918
-            <td><?php echo wpinv_get_payment_gateway_name( $invoice_id ); ?></td>
917
+            <th><?php _e('Payment Method', 'invoicing'); ?></th>
918
+            <td><?php echo wpinv_get_payment_gateway_name($invoice_id); ?></td>
919 919
         </tr>
920
-        <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?>
920
+        <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?>
921 921
             <tr class="wpi-row-date">
922
-                <th><?php echo wp_sprintf(__( '%s Date', 'invoicing' ), $type); ?></th>
922
+                <th><?php echo wp_sprintf(__('%s Date', 'invoicing'), $type); ?></th>
923 923
                 <td><?php echo $invoice_date; ?></td>
924 924
             </tr>
925 925
         <?php } ?>
926
-        <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?>
926
+        <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?>
927 927
             <tr class="wpi-row-date">
928
-                <th><?php _e( 'Due Date', 'invoicing' ); ?></th>
928
+                <th><?php _e('Due Date', 'invoicing'); ?></th>
929 929
                 <td><?php echo $due_date; ?></td>
930 930
             </tr>
931 931
         <?php } ?>
932
-        <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?>
932
+        <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?>
933 933
             <tr class="wpi-row-ovatno">
934
-                <th><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></th>
934
+                <th><?php echo wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name); ?></th>
935 935
                 <td><?php echo $owner_vat_number; ?></td>
936 936
             </tr>
937 937
         <?php } ?>
938
-        <?php if ( $use_taxes && $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) { ?>
938
+        <?php if ($use_taxes && $user_vat_number = wpinv_get_invoice_vat_number($invoice_id)) { ?>
939 939
             <tr class="wpi-row-uvatno">
940
-                <th><?php echo wp_sprintf( __( 'Your %s Number', 'invoicing' ), $vat_name ); ?></th>
940
+                <th><?php echo wp_sprintf(__('Your %s Number', 'invoicing'), $vat_name); ?></th>
941 941
                 <td><?php echo $user_vat_number; ?></td>
942 942
             </tr>
943 943
         <?php } ?>
944 944
         <tr class="table-active tr-total wpi-row-total">
945
-            <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th>
946
-            <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td>
945
+            <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th>
946
+            <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td>
947 947
         </tr>
948 948
     </table>
949 949
 <?php
950 950
 }
951 951
 
952
-function wpinv_display_to_address( $invoice_id = 0 ) {
953
-    $invoice = wpinv_get_invoice( $invoice_id );
952
+function wpinv_display_to_address($invoice_id = 0) {
953
+    $invoice = wpinv_get_invoice($invoice_id);
954 954
     
955
-    if ( empty( $invoice ) ) {
955
+    if (empty($invoice)) {
956 956
         return NULL;
957 957
     }
958 958
     
959 959
     $billing_details = $invoice->get_user_info();
960
-    $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>';
960
+    $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>';
961 961
     $output .= '<div class="wrapper col-xs-10">';
962 962
     
963 963
     ob_start();
964
-    do_action( 'wpinv_display_to_address_top', $invoice );
964
+    do_action('wpinv_display_to_address_top', $invoice);
965 965
     $output .= ob_get_clean();
966 966
     
967
-    $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>';
968
-    if ( $company = $billing_details['company'] ) {
969
-        $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>';
967
+    $output .= '<div class="name">' . esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])) . '</div>';
968
+    if ($company = $billing_details['company']) {
969
+        $output .= '<div class="company">' . wpautop(wp_kses_post($company)) . '</div>';
970 970
     }
971 971
     $address_row = '';
972
-    if ( $address = $billing_details['address'] ) {
973
-        $address_row .= wpautop( wp_kses_post( $address ) );
972
+    if ($address = $billing_details['address']) {
973
+        $address_row .= wpautop(wp_kses_post($address));
974 974
     }
975 975
     
976 976
     $address_fields = array();
977
-    if ( !empty( $billing_details['city'] ) ) {
977
+    if (!empty($billing_details['city'])) {
978 978
         $address_fields[] = $billing_details['city'];
979 979
     }
980 980
     
981
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
982
-    if ( !empty( $billing_details['state'] ) ) {
983
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
981
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
982
+    if (!empty($billing_details['state'])) {
983
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
984 984
     }
985 985
     
986
-    if ( !empty( $billing_country ) ) {
987
-        $address_fields[] = wpinv_country_name( $billing_country );
986
+    if (!empty($billing_country)) {
987
+        $address_fields[] = wpinv_country_name($billing_country);
988 988
     }
989 989
     
990
-    if ( !empty( $address_fields ) ) {
991
-        $address_fields = implode( ", ", $address_fields );
990
+    if (!empty($address_fields)) {
991
+        $address_fields = implode(", ", $address_fields);
992 992
         
993
-        if ( !empty( $billing_details['zip'] ) ) {
993
+        if (!empty($billing_details['zip'])) {
994 994
             $address_fields .= ' ' . $billing_details['zip'];
995 995
         }
996 996
         
997
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
997
+        $address_row .= wpautop(wp_kses_post($address_fields));
998 998
     }
999 999
     
1000
-    if ( $address_row ) {
1000
+    if ($address_row) {
1001 1001
         $output .= '<div class="address">' . $address_row . '</div>';
1002 1002
     }
1003 1003
     
1004
-    if ( $phone = $invoice->get_phone() ) {
1005
-        $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s', 'invoicing' ), esc_html( $phone ) ) . '</div>';
1004
+    if ($phone = $invoice->get_phone()) {
1005
+        $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s', 'invoicing'), esc_html($phone)) . '</div>';
1006 1006
     }
1007
-    if ( $email = $invoice->get_email() ) {
1008
-        $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' , 'invoicing'), esc_html( $email ) ) . '</div>';
1007
+    if ($email = $invoice->get_email()) {
1008
+        $output .= '<div class="email">' . wp_sprintf(__('Email: %s', 'invoicing'), esc_html($email)) . '</div>';
1009 1009
     }
1010 1010
     
1011 1011
     ob_start();
1012
-    do_action( 'wpinv_display_to_address_bottom', $invoice );
1012
+    do_action('wpinv_display_to_address_bottom', $invoice);
1013 1013
     $output .= ob_get_clean();
1014 1014
     
1015 1015
     $output .= '</div>';
1016
-    $output = apply_filters( 'wpinv_display_to_address', $output, $invoice );
1016
+    $output = apply_filters('wpinv_display_to_address', $output, $invoice);
1017 1017
 
1018 1018
     echo $output;
1019 1019
 }
1020 1020
 
1021
-function wpinv_display_line_items( $invoice_id = 0 ) {
1021
+function wpinv_display_line_items($invoice_id = 0) {
1022 1022
     global $wpinv_euvat, $ajax_cart_details;
1023
-    $invoice            = wpinv_get_invoice( $invoice_id );
1023
+    $invoice            = wpinv_get_invoice($invoice_id);
1024 1024
     $quantities_enabled = wpinv_item_quantities_enabled();
1025 1025
     $use_taxes          = wpinv_use_taxes();
1026 1026
     $zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
1027
-    $tax_label           = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
1028
-    $tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
1027
+    $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
1028
+    $tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
1029 1029
     
1030 1030
     $cart_details       = $invoice->get_cart_details();
1031 1031
     $ajax_cart_details  = $cart_details;
@@ -1034,68 +1034,68 @@  discard block
 block discarded – undo
1034 1034
     <table class="table table-sm table-bordered table-responsive">
1035 1035
         <thead>
1036 1036
             <tr>
1037
-                <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th>
1038
-                <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th>
1037
+                <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th>
1038
+                <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th>
1039 1039
                 <?php if ($quantities_enabled) { ?>
1040
-                    <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th>
1040
+                    <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th>
1041 1041
                 <?php } ?>
1042 1042
                 <?php if ($use_taxes && !$zero_tax) { ?>
1043 1043
                     <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th>
1044 1044
                 <?php } ?>
1045
-                <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th>
1045
+                <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th>
1046 1046
             </tr>
1047 1047
         </thead>
1048 1048
         <tbody>
1049 1049
         <?php 
1050
-            if ( !empty( $cart_details ) ) {
1051
-                do_action( 'wpinv_display_line_items_start', $invoice );
1050
+            if (!empty($cart_details)) {
1051
+                do_action('wpinv_display_line_items_start', $invoice);
1052 1052
                 
1053 1053
                 $count = 0;
1054 1054
                 $cols  = 3;
1055
-                foreach ( $cart_details as $key => $cart_item ) {
1056
-                    $item_id    = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : '';
1057
-                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount( $cart_item["item_price"] ) : 0;
1058
-                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount( $cart_item["subtotal"] ) : 0;
1059
-                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1;
1055
+                foreach ($cart_details as $key => $cart_item) {
1056
+                    $item_id    = !empty($cart_item['id']) ? absint($cart_item['id']) : '';
1057
+                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount($cart_item["item_price"]) : 0;
1058
+                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount($cart_item["subtotal"]) : 0;
1059
+                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1;
1060 1060
                     
1061
-                    $item       = $item_id ? new WPInv_Item( $item_id ) : NULL;
1061
+                    $item       = $item_id ? new WPInv_Item($item_id) : NULL;
1062 1062
                     $summary    = '';
1063 1063
                     $cols       = 3;
1064
-                    if ( !empty($item) ) {
1064
+                    if (!empty($item)) {
1065 1065
                         $item_name  = $item->get_name();
1066 1066
                         $summary    = $item->get_summary();
1067 1067
                     }
1068
-                    $item_name  = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1068
+                    $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1069 1069
                     
1070 1070
                     if (!empty($item) && $item->is_package() && !empty($cart_item['meta']['post_id'])) {
1071
-                        $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>';
1072
-                        $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $item->get_custom_singular_name(), $post_link );
1071
+                        $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>';
1072
+                        $summary = wp_sprintf(__('%s: %s', 'invoicing'), $item->get_custom_singular_name(), $post_link);
1073 1073
                     }
1074
-                    $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice );
1074
+                    $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice);
1075 1075
                     
1076 1076
                     $item_tax       = '';
1077 1077
                     $tax_rate       = '';
1078
-                    if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1079
-                        $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) );
1080
-                        $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1081
-                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1078
+                    if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1079
+                        $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']));
1080
+                        $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1081
+                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
1082 1082
                         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : '';
1083 1083
                     }
1084 1084
                     
1085 1085
                     $line_item_tax = $item_tax . $tax_rate;
1086 1086
                     
1087
-                    if ( $line_item_tax === '' ) {
1087
+                    if ($line_item_tax === '') {
1088 1088
                         $line_item_tax = 0; // Zero tax
1089 1089
                     }
1090 1090
                     
1091
-                    $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">';
1092
-                        $line_item .= '<td class="name">' . esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item );
1093
-                        if ( $summary !== '' ) {
1094
-                            $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>';
1091
+                    $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">';
1092
+                        $line_item .= '<td class="name">' . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item);
1093
+                        if ($summary !== '') {
1094
+                            $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>';
1095 1095
                         }
1096 1096
                         $line_item .= '</td>';
1097 1097
                         
1098
-                        $line_item .= '<td class="rate">' . esc_html__( wpinv_price( wpinv_format_amount( $item_price ), $invoice->get_currency() ) ) . '</td>';
1098
+                        $line_item .= '<td class="rate">' . esc_html__(wpinv_price(wpinv_format_amount($item_price), $invoice->get_currency())) . '</td>';
1099 1099
                         if ($quantities_enabled) {
1100 1100
                             $cols++;
1101 1101
                             $line_item .= '<td class="qty">' . $quantity . '</td>';
@@ -1104,55 +1104,55 @@  discard block
 block discarded – undo
1104 1104
                             $cols++;
1105 1105
                             $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1106 1106
                         }
1107
-                        $line_item .= '<td class="total">' . esc_html__( wpinv_price( wpinv_format_amount( $line_total ), $invoice->get_currency() ) ) . '</td>';
1107
+                        $line_item .= '<td class="total">' . esc_html__(wpinv_price(wpinv_format_amount($line_total), $invoice->get_currency())) . '</td>';
1108 1108
                     $line_item .= '</tr>';
1109 1109
                     
1110
-                    echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols );
1110
+                    echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols);
1111 1111
 
1112 1112
                     $count++;
1113 1113
                 }
1114 1114
                 
1115
-                do_action( 'wpinv_display_before_subtotal', $invoice, $cols );
1115
+                do_action('wpinv_display_before_subtotal', $invoice, $cols);
1116 1116
                 ?>
1117 1117
                 <tr class="row-sub-total row_odd">
1118
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1119
-                    <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1118
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1119
+                    <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1120 1120
                 </tr>
1121 1121
                 <?php
1122
-                do_action( 'wpinv_display_after_subtotal', $invoice, $cols );
1122
+                do_action('wpinv_display_after_subtotal', $invoice, $cols);
1123 1123
                 
1124
-                if ( wpinv_discount( $invoice_id, false ) > 0 ) {
1125
-                    do_action( 'wpinv_display_before_discount', $invoice, $cols );
1124
+                if (wpinv_discount($invoice_id, false) > 0) {
1125
+                    do_action('wpinv_display_before_discount', $invoice, $cols);
1126 1126
                     ?>
1127 1127
                         <tr class="row-discount">
1128
-                            <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td>
1129
-                            <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1128
+                            <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td>
1129
+                            <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1130 1130
                         </tr>
1131 1131
                     <?php
1132
-                    do_action( 'wpinv_display_after_discount', $invoice, $cols );
1132
+                    do_action('wpinv_display_after_discount', $invoice, $cols);
1133 1133
                 }
1134 1134
                 
1135
-                if ( $use_taxes ) {
1136
-                    do_action( 'wpinv_display_before_tax', $invoice, $cols );
1135
+                if ($use_taxes) {
1136
+                    do_action('wpinv_display_before_tax', $invoice, $cols);
1137 1137
                     ?>
1138 1138
                     <tr class="row-tax">
1139
-                        <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td>
1140
-                        <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1139
+                        <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td>
1140
+                        <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1141 1141
                     </tr>
1142 1142
                     <?php
1143
-                    do_action( 'wpinv_display_after_tax', $invoice, $cols );
1143
+                    do_action('wpinv_display_after_tax', $invoice, $cols);
1144 1144
                 }
1145 1145
                 
1146
-                do_action( 'wpinv_display_before_total', $invoice, $cols );
1146
+                do_action('wpinv_display_before_total', $invoice, $cols);
1147 1147
                 ?>
1148 1148
                 <tr class="table-active row-total">
1149
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1150
-                    <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1149
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1150
+                    <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1151 1151
                 </tr>
1152 1152
                 <?php
1153
-                do_action( 'wpinv_display_after_total', $invoice, $cols );
1153
+                do_action('wpinv_display_after_total', $invoice, $cols);
1154 1154
                 
1155
-                do_action( 'wpinv_display_line_end', $invoice, $cols );
1155
+                do_action('wpinv_display_line_end', $invoice, $cols);
1156 1156
             }
1157 1157
         ?>
1158 1158
         </tbody>
@@ -1161,35 +1161,35 @@  discard block
 block discarded – undo
1161 1161
     echo ob_get_clean();
1162 1162
 }
1163 1163
 
1164
-function wpinv_display_invoice_totals( $invoice_id = 0 ) {    
1164
+function wpinv_display_invoice_totals($invoice_id = 0) {    
1165 1165
     $use_taxes = wpinv_use_taxes();
1166 1166
     
1167
-    do_action( 'wpinv_before_display_totals_table', $invoice_id ); 
1167
+    do_action('wpinv_before_display_totals_table', $invoice_id); 
1168 1168
     ?>
1169 1169
     <table class="table table-sm table-bordered table-responsive">
1170 1170
         <tbody>
1171
-            <?php do_action( 'wpinv_before_display_totals' ); ?>
1171
+            <?php do_action('wpinv_before_display_totals'); ?>
1172 1172
             <tr class="row-sub-total">
1173
-                <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td>
1174
-                <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1173
+                <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td>
1174
+                <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1175 1175
             </tr>
1176
-            <?php do_action( 'wpinv_after_display_totals' ); ?>
1177
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
1176
+            <?php do_action('wpinv_after_display_totals'); ?>
1177
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
1178 1178
                 <tr class="row-discount">
1179
-                    <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td>
1180
-                    <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1179
+                    <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td>
1180
+                    <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1181 1181
                 </tr>
1182
-            <?php do_action( 'wpinv_after_display_discount' ); ?>
1182
+            <?php do_action('wpinv_after_display_discount'); ?>
1183 1183
             <?php } ?>
1184
-            <?php if ( $use_taxes ) { ?>
1184
+            <?php if ($use_taxes) { ?>
1185 1185
             <tr class="row-tax">
1186
-                <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td>
1187
-                <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1186
+                <td class="rate"><?php _e('Tax', 'invoicing'); ?></td>
1187
+                <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1188 1188
             </tr>
1189
-            <?php do_action( 'wpinv_after_display_tax' ); ?>
1189
+            <?php do_action('wpinv_after_display_tax'); ?>
1190 1190
             <?php } ?>
1191
-            <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?>
1192
-                <?php foreach ( $fees as $fee ) { ?>
1191
+            <?php if ($fees = wpinv_get_fees($invoice_id)) { ?>
1192
+                <?php foreach ($fees as $fee) { ?>
1193 1193
                     <tr class="row-fee">
1194 1194
                         <td class="rate"><?php echo $fee['label']; ?></td>
1195 1195
                         <td class="total"><?php echo $fee['amount_display']; ?></td>
@@ -1197,72 +1197,72 @@  discard block
 block discarded – undo
1197 1197
                 <?php } ?>
1198 1198
             <?php } ?>
1199 1199
             <tr class="table-active row-total">
1200
-                <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td>
1201
-                <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1200
+                <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td>
1201
+                <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1202 1202
             </tr>
1203
-            <?php do_action( 'wpinv_after_totals' ); ?>
1203
+            <?php do_action('wpinv_after_totals'); ?>
1204 1204
         </tbody>
1205 1205
 
1206 1206
     </table>
1207 1207
 
1208
-    <?php do_action( 'wpinv_after_totals_table' );
1208
+    <?php do_action('wpinv_after_totals_table');
1209 1209
 }
1210 1210
 
1211
-function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) {
1212
-    $invoice = wpinv_get_invoice( $invoice_id );
1211
+function wpinv_display_payments_info($invoice_id = 0, $echo = true) {
1212
+    $invoice = wpinv_get_invoice($invoice_id);
1213 1213
     
1214 1214
     ob_start();
1215
-    do_action( 'wpinv_before_display_payments_info', $invoice_id );
1216
-    if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() || $invoice->is_refunded() ) {
1215
+    do_action('wpinv_before_display_payments_info', $invoice_id);
1216
+    if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid() || $invoice->is_refunded()) {
1217 1217
         ?>
1218 1218
         <div class="wpi-payment-info">
1219
-            <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p>
1220
-            <?php if ( $gateway_title ) { ?>
1221
-            <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p>
1219
+            <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p>
1220
+            <?php if ($gateway_title) { ?>
1221
+            <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p>
1222 1222
             <?php } ?>
1223 1223
         </div>
1224 1224
         <?php
1225 1225
     }
1226
-    do_action( 'wpinv_after_display_payments_info', $invoice_id );
1226
+    do_action('wpinv_after_display_payments_info', $invoice_id);
1227 1227
     $outout = ob_get_clean();
1228 1228
     
1229
-    if ( $echo ) {
1229
+    if ($echo) {
1230 1230
         echo $outout;
1231 1231
     } else {
1232 1232
         return $outout;
1233 1233
     }
1234 1234
 }
1235 1235
 
1236
-function wpinv_display_style( $invoice ) {
1237
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION );
1236
+function wpinv_display_style($invoice) {
1237
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION);
1238 1238
     
1239
-    wp_print_styles( 'open-sans' );
1240
-    wp_print_styles( 'wpinv-single-style' );
1239
+    wp_print_styles('open-sans');
1240
+    wp_print_styles('wpinv-single-style');
1241 1241
 }
1242
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
1242
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
1243 1243
 
1244 1244
 function wpinv_checkout_billing_details() {  
1245 1245
     $invoice_id = (int)wpinv_get_invoice_cart_id();
1246 1246
     if (empty($invoice_id)) {
1247
-        wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ );
1247
+        wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__);
1248 1248
         return null;
1249 1249
     }
1250 1250
     
1251
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
1251
+    $invoice = wpinv_get_invoice_cart($invoice_id);
1252 1252
     if (empty($invoice)) {
1253
-        wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ );
1253
+        wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__);
1254 1254
         return null;
1255 1255
     }
1256 1256
     $user_id        = $invoice->get_user_id();
1257 1257
     $user_info      = $invoice->get_user_info();
1258
-    $address_info   = wpinv_get_user_address( $user_id );
1258
+    $address_info   = wpinv_get_user_address($user_id);
1259 1259
     
1260
-    if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) {
1260
+    if (empty($user_info['first_name']) && !empty($user_info['first_name'])) {
1261 1261
         $user_info['first_name'] = $user_info['first_name'];
1262 1262
         $user_info['last_name'] = $user_info['last_name'];
1263 1263
     }
1264 1264
     
1265
-    if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) {
1265
+    if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) {
1266 1266
         $user_info['country']   = $address_info['country'];
1267 1267
         $user_info['state']     = $address_info['state'];
1268 1268
         $user_info['city']      = $address_info['city'];
@@ -1278,103 +1278,103 @@  discard block
 block discarded – undo
1278 1278
         'address'
1279 1279
     );
1280 1280
     
1281
-    foreach ( $address_fields as $field ) {
1282
-        if ( empty( $user_info[$field] ) ) {
1281
+    foreach ($address_fields as $field) {
1282
+        if (empty($user_info[$field])) {
1283 1283
             $user_info[$field] = $address_info[$field];
1284 1284
         }
1285 1285
     }
1286 1286
     
1287
-    return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice );
1287
+    return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice);
1288 1288
 }
1289 1289
 
1290 1290
 function wpinv_admin_get_line_items($invoice = array()) {
1291 1291
     $item_quantities    = wpinv_item_quantities_enabled();
1292 1292
     $use_taxes          = wpinv_use_taxes();
1293 1293
     
1294
-    if ( empty( $invoice ) ) {
1294
+    if (empty($invoice)) {
1295 1295
         return NULL;
1296 1296
     }
1297 1297
     
1298 1298
     $cart_items = $invoice->get_cart_details();
1299
-    if ( empty( $cart_items ) ) {
1299
+    if (empty($cart_items)) {
1300 1300
         return NULL;
1301 1301
     }
1302 1302
     ob_start();
1303 1303
     
1304
-    do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice );
1304
+    do_action('wpinv_admin_before_line_items', $cart_items, $invoice);
1305 1305
     
1306 1306
     $count = 0;
1307
-    foreach ( $cart_items as $key => $cart_item ) {
1307
+    foreach ($cart_items as $key => $cart_item) {
1308 1308
         $item_id    = $cart_item['id'];
1309
-        $wpi_item   = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL;
1309
+        $wpi_item   = $item_id > 0 ? new WPInv_Item($item_id) : NULL;
1310 1310
         
1311 1311
         if (empty($wpi_item)) {
1312 1312
             continue;
1313 1313
         }
1314 1314
         
1315
-        $item_price     = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ) );
1316
-        $quantity       = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1317
-        $item_subtotal  = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ) );
1315
+        $item_price     = wpinv_price(wpinv_format_amount($cart_item['item_price']));
1316
+        $quantity       = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1317
+        $item_subtotal  = wpinv_price(wpinv_format_amount($cart_item['subtotal']));
1318 1318
         $can_remove     = true;
1319 1319
         
1320 1320
         $summary = '';
1321 1321
         if ($wpi_item->is_package() && !empty($cart_item['meta']['post_id'])) {
1322
-            $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>';
1323
-            $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_custom_singular_name(), $post_link );
1322
+            $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>';
1323
+            $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_custom_singular_name(), $post_link);
1324 1324
         }
1325
-        $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice );
1325
+        $summary = apply_filters('wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice);
1326 1326
         
1327 1327
         $item_tax       = '';
1328 1328
         $tax_rate       = '';
1329
-        if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1330
-            $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) );
1331
-            $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1332
-            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1329
+        if ($cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1330
+            $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']));
1331
+            $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1332
+            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
1333 1333
             $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : '';
1334 1334
         }
1335 1335
         $line_item_tax = $item_tax . $tax_rate;
1336 1336
         
1337
-        if ( $line_item_tax === '' ) {
1337
+        if ($line_item_tax === '') {
1338 1338
             $line_item_tax = 0; // Zero tax
1339 1339
         }
1340 1340
 
1341
-        $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">';
1341
+        $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">';
1342 1342
             $line_item .= '<td class="id">' . $item_id . '</td>';
1343
-            $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 );
1344
-            if ( $summary !== '' ) {
1345
-                $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>';
1343
+            $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);
1344
+            if ($summary !== '') {
1345
+                $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>';
1346 1346
             }
1347 1347
             $line_item .= '</td>';
1348 1348
             $line_item .= '<td class="price">' . $item_price . '</td>';
1349 1349
             
1350
-            if ( $item_quantities ) {
1351
-                if ( count( $cart_items ) == 1 && $quantity <= 1 ) {
1350
+            if ($item_quantities) {
1351
+                if (count($cart_items) == 1 && $quantity <= 1) {
1352 1352
                     $can_remove = false;
1353 1353
                 }
1354 1354
                 $line_item .= '<td class="qty" data-quantity="' . $quantity . '">&nbsp;&times;&nbsp;' . $quantity . '</td>';
1355 1355
             } else {
1356
-                if ( count( $cart_items ) == 1 ) {
1356
+                if (count($cart_items) == 1) {
1357 1357
                     $can_remove = false;
1358 1358
                 }
1359 1359
             }
1360 1360
             $line_item .= '<td class="total">' . $item_subtotal . '</td>';
1361 1361
             
1362
-            if ( $use_taxes ) {
1362
+            if ($use_taxes) {
1363 1363
                 $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1364 1364
             }
1365 1365
             $line_item .= '<td class="action">';
1366
-            if ( !$invoice->is_paid() && !$invoice->is_refunded() && $can_remove ) {
1366
+            if (!$invoice->is_paid() && !$invoice->is_refunded() && $can_remove) {
1367 1367
                 $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>';
1368 1368
             }
1369 1369
             $line_item .= '</td>';
1370 1370
         $line_item .= '</tr>';
1371 1371
         
1372
-        echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice );
1372
+        echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice);
1373 1373
         
1374 1374
         $count++;
1375 1375
     } 
1376 1376
     
1377
-    do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice );
1377
+    do_action('wpinv_admin_after_line_items', $cart_items, $invoice);
1378 1378
     
1379 1379
     return ob_get_clean();
1380 1380
 }
@@ -1385,35 +1385,35 @@  discard block
 block discarded – undo
1385 1385
     // Set current invoice id.
1386 1386
     $wpi_checkout_id = wpinv_get_invoice_cart_id();
1387 1387
     
1388
-    $form_action  = esc_url( wpinv_get_checkout_uri() );
1388
+    $form_action = esc_url(wpinv_get_checkout_uri());
1389 1389
 
1390 1390
     ob_start();
1391 1391
         echo '<div id="wpinv_checkout_wrap">';
1392 1392
         
1393
-        if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) {
1393
+        if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) {
1394 1394
             ?>
1395 1395
             <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive">
1396
-                <?php do_action( 'wpinv_before_checkout_form' ); ?>
1396
+                <?php do_action('wpinv_before_checkout_form'); ?>
1397 1397
                 <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST">
1398 1398
                     <?php
1399
-                    do_action( 'wpinv_checkout_form_top' );
1400
-                    do_action( 'wpinv_checkout_billing_info' );
1401
-                    do_action( 'wpinv_checkout_cart' );
1402
-                    do_action( 'wpinv_payment_mode_select'  );
1403
-                    do_action( 'wpinv_checkout_form_bottom' )
1399
+                    do_action('wpinv_checkout_form_top');
1400
+                    do_action('wpinv_checkout_billing_info');
1401
+                    do_action('wpinv_checkout_cart');
1402
+                    do_action('wpinv_payment_mode_select');
1403
+                    do_action('wpinv_checkout_form_bottom')
1404 1404
                     ?>
1405 1405
                 </form>
1406
-                <?php do_action( 'wpinv_after_purchase_form' ); ?>
1406
+                <?php do_action('wpinv_after_purchase_form'); ?>
1407 1407
             </div><!--end #wpinv_checkout_form_wrap-->
1408 1408
         <?php
1409 1409
         } else {
1410
-            do_action( 'wpinv_cart_empty' );
1410
+            do_action('wpinv_cart_empty');
1411 1411
         }
1412 1412
         echo '</div><!--end #wpinv_checkout_wrap-->';
1413 1413
     return ob_get_clean();
1414 1414
 }
1415 1415
 
1416
-function wpinv_checkout_cart( $cart_details = array(), $echo = true ) {
1416
+function wpinv_checkout_cart($cart_details = array(), $echo = true) {
1417 1417
     global $ajax_cart_details;
1418 1418
     $ajax_cart_details = $cart_details;
1419 1419
     /*
@@ -1428,25 +1428,25 @@  discard block
 block discarded – undo
1428 1428
     }
1429 1429
     */
1430 1430
     ob_start();
1431
-    do_action( 'wpinv_before_checkout_cart' );
1431
+    do_action('wpinv_before_checkout_cart');
1432 1432
     echo '<div id="wpinv_checkout_cart_form" method="post">';
1433 1433
         echo '<div id="wpinv_checkout_cart_wrap">';
1434
-            wpinv_get_template_part( 'wpinv-checkout-cart' );
1434
+            wpinv_get_template_part('wpinv-checkout-cart');
1435 1435
         echo '</div>';
1436 1436
     echo '</div>';
1437
-    do_action( 'wpinv_after_checkout_cart' );
1437
+    do_action('wpinv_after_checkout_cart');
1438 1438
     $content = ob_get_clean();
1439 1439
     
1440
-    if ( $echo ) {
1440
+    if ($echo) {
1441 1441
         echo $content;
1442 1442
     } else {
1443 1443
         return $content;
1444 1444
     }
1445 1445
 }
1446
-add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 );
1446
+add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10);
1447 1447
 
1448 1448
 function wpinv_empty_cart_message() {
1449
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1449
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1450 1450
 }
1451 1451
 
1452 1452
 /**
@@ -1458,91 +1458,91 @@  discard block
 block discarded – undo
1458 1458
 function wpinv_empty_checkout_cart() {
1459 1459
 	echo wpinv_empty_cart_message();
1460 1460
 }
1461
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1461
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1462 1462
 
1463 1463
 function wpinv_save_cart_button() {
1464
-    if ( wpinv_is_cart_saving_disabled() )
1464
+    if (wpinv_is_cart_saving_disabled())
1465 1465
         return;
1466 1466
 ?>
1467
-    <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url( add_query_arg( 'wpi_action', 'save_cart' ) ); ?>"><?php _e( 'Save Cart', 'invoicing' ); ?></a>
1467
+    <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url(add_query_arg('wpi_action', 'save_cart')); ?>"><?php _e('Save Cart', 'invoicing'); ?></a>
1468 1468
 <?php
1469 1469
 }
1470 1470
 
1471 1471
 function wpinv_update_cart_button() {
1472
-    if ( !wpinv_item_quantities_enabled() )
1472
+    if (!wpinv_item_quantities_enabled())
1473 1473
         return;
1474 1474
 ?>
1475
-    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/>
1475
+    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/>
1476 1476
     <input type="hidden" name="wpi_action" value="update_cart"/>
1477 1477
 <?php
1478 1478
 }
1479 1479
 
1480 1480
 function wpinv_checkout_cart_columns() {
1481 1481
     $default = 3;
1482
-    if ( wpinv_item_quantities_enabled() ) {
1482
+    if (wpinv_item_quantities_enabled()) {
1483 1483
         $default++;
1484 1484
     }
1485 1485
     
1486
-    if ( wpinv_use_taxes() ) {
1486
+    if (wpinv_use_taxes()) {
1487 1487
         $default++;
1488 1488
     }
1489 1489
 
1490
-    return apply_filters( 'wpinv_checkout_cart_columns', $default );
1490
+    return apply_filters('wpinv_checkout_cart_columns', $default);
1491 1491
 }
1492 1492
 
1493 1493
 function wpinv_display_cart_messages() {
1494 1494
     global $wpi_session;
1495 1495
 
1496
-    $messages = $wpi_session->get( 'wpinv_cart_messages' );
1496
+    $messages = $wpi_session->get('wpinv_cart_messages');
1497 1497
 
1498
-    if ( $messages ) {
1499
-        foreach ( $messages as $message_id => $message ) {
1498
+    if ($messages) {
1499
+        foreach ($messages as $message_id => $message) {
1500 1500
             // Try and detect what type of message this is
1501
-            if ( strpos( strtolower( $message ), 'error' ) ) {
1501
+            if (strpos(strtolower($message), 'error')) {
1502 1502
                 $type = 'error';
1503
-            } elseif ( strpos( strtolower( $message ), 'success' ) ) {
1503
+            } elseif (strpos(strtolower($message), 'success')) {
1504 1504
                 $type = 'success';
1505 1505
             } else {
1506 1506
                 $type = 'info';
1507 1507
             }
1508 1508
 
1509
-            $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) );
1509
+            $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type));
1510 1510
 
1511
-            echo '<div class="' . implode( ' ', $classes ) . '">';
1511
+            echo '<div class="' . implode(' ', $classes) . '">';
1512 1512
                 // Loop message codes and display messages
1513 1513
                     echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>';
1514 1514
             echo '</div>';
1515 1515
         }
1516 1516
 
1517 1517
         // Remove all of the cart saving messages
1518
-        $wpi_session->set( 'wpinv_cart_messages', null );
1518
+        $wpi_session->set('wpinv_cart_messages', null);
1519 1519
     }
1520 1520
 }
1521
-add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' );
1521
+add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages');
1522 1522
 
1523 1523
 function wpinv_discount_field() {
1524
-    if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) {
1524
+    if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) {
1525 1525
         return; // Only show before a payment method has been selected if ajax is disabled
1526 1526
     }
1527 1527
 
1528
-    if ( !wpinv_is_checkout() ) {
1528
+    if (!wpinv_is_checkout()) {
1529 1529
         return;
1530 1530
     }
1531 1531
 
1532
-    if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) {
1532
+    if (wpinv_has_active_discounts() && wpinv_get_cart_total()) {
1533 1533
     ?>
1534 1534
     <div id="wpinv-discount-field" class="panel panel-default">
1535 1535
         <div class="panel-body">
1536 1536
             <p>
1537
-                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label>
1538
-                <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span>
1537
+                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label>
1538
+                <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span>
1539 1539
             </p>
1540 1540
             <div class="form-group row">
1541 1541
                 <div class="col-sm-4">
1542
-                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/>
1542
+                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/>
1543 1543
                 </div>
1544 1544
                 <div class="col-sm-3">
1545
-                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button>
1545
+                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button>
1546 1546
                 </div>
1547 1547
                 <div style="clear:both"></div>
1548 1548
                 <div class="col-sm-12 wpinv-discount-msg">
@@ -1555,10 +1555,10 @@  discard block
 block discarded – undo
1555 1555
 <?php
1556 1556
     }
1557 1557
 }
1558
-add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 );
1558
+add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10);
1559 1559
 
1560 1560
 function wpinv_agree_to_terms_js() {
1561
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
1561
+    if (wpinv_get_option('show_agree_to_terms', false)) {
1562 1562
 ?>
1563 1563
 <script type="text/javascript">
1564 1564
     jQuery(document).ready(function($){
@@ -1573,126 +1573,126 @@  discard block
 block discarded – undo
1573 1573
 <?php
1574 1574
     }
1575 1575
 }
1576
-add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' );
1576
+add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js');
1577 1577
 
1578 1578
 function wpinv_payment_mode_select() {
1579
-    $gateways = wpinv_get_enabled_payment_gateways( true );
1580
-    $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways );
1579
+    $gateways = wpinv_get_enabled_payment_gateways(true);
1580
+    $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways);
1581 1581
     $page_URL = wpinv_get_current_page_url();
1582
-    $invoice = wpinv_get_invoice( 0, true );
1582
+    $invoice = wpinv_get_invoice(0, true);
1583 1583
     
1584 1584
     do_action('wpinv_payment_mode_top');
1585 1585
     $invoice_id = (int)$invoice->ID;
1586
-    $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id );
1586
+    $chosen_gateway = wpinv_get_chosen_gateway($invoice_id);
1587 1587
     ?>
1588
-    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( $invoice->is_free() ? 'style="display:none;"' : '' ); ?>>
1589
-            <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?>
1588
+    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ($invoice->is_free() ? 'style="display:none;"' : ''); ?>>
1589
+            <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?>
1590 1590
             <div id="wpinv-payment-mode-wrap" class="panel panel-default">
1591
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div>
1591
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div>
1592 1592
                 <div class="panel-body list-group wpi-payment_methods">
1593 1593
                     <?php
1594
-                    do_action( 'wpinv_payment_mode_before_gateways' );
1594
+                    do_action('wpinv_payment_mode_before_gateways');
1595 1595
                     
1596
-                    if(!empty($gateways)){
1597
-	                    foreach ( $gateways as $gateway_id => $gateway ) {
1598
-		                    $checked = checked( $gateway_id, $chosen_gateway, false );
1599
-		                    $button_label = wpinv_get_gateway_button_label( $gateway_id );
1600
-		                    $description = wpinv_get_gateway_description( $gateway_id );
1596
+                    if (!empty($gateways)) {
1597
+	                    foreach ($gateways as $gateway_id => $gateway) {
1598
+		                    $checked = checked($gateway_id, $chosen_gateway, false);
1599
+		                    $button_label = wpinv_get_gateway_button_label($gateway_id);
1600
+		                    $description = wpinv_get_gateway_description($gateway_id);
1601 1601
 		                    ?>
1602 1602
 		                    <div class="list-group-item">
1603 1603
 			                    <div class="radio">
1604
-				                    <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['checkout_label'] ); ?></label>
1604
+				                    <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['checkout_label']); ?></label>
1605 1605
 			                    </div>
1606
-			                    <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert">
1607
-				                    <?php if ( !empty( $description ) ) { ?>
1608
-					                    <div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div>
1606
+			                    <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert">
1607
+				                    <?php if (!empty($description)) { ?>
1608
+					                    <div class="wpi-gateway-desc alert alert-info"><?php echo $description; ?></div>
1609 1609
 				                    <?php } ?>
1610
-				                    <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?>
1610
+				                    <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?>
1611 1611
 			                    </div>
1612 1612
 		                    </div>
1613 1613
 		                    <?php
1614 1614
 	                    }
1615
-                    }else{
1616
-	                    echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>';
1615
+                    } else {
1616
+	                    echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>';
1617 1617
                     }
1618 1618
 
1619
-                    do_action( 'wpinv_payment_mode_after_gateways' );
1619
+                    do_action('wpinv_payment_mode_after_gateways');
1620 1620
                     ?>
1621 1621
                 </div>
1622 1622
             </div>
1623
-            <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?>
1623
+            <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?>
1624 1624
     </div>
1625 1625
     <?php
1626 1626
     do_action('wpinv_payment_mode_bottom');
1627 1627
 }
1628
-add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' );
1628
+add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select');
1629 1629
 
1630 1630
 function wpinv_checkout_billing_info() {    
1631
-    if ( wpinv_is_checkout() ) {
1631
+    if (wpinv_is_checkout()) {
1632 1632
         $logged_in          = is_user_logged_in();
1633 1633
         $billing_details    = wpinv_checkout_billing_details();
1634
-        $selected_country   = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country();
1634
+        $selected_country   = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country();
1635 1635
         ?>
1636 1636
         <div id="wpinv-fields" class="clearfix">
1637 1637
             <div id="wpi-billing" class="wpi-billing clearfix panel panel-default">
1638
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div>
1638
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div>
1639 1639
                 <div id="wpinv-fields-box" class="panel-body">
1640
-                    <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?>
1640
+                    <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?>
1641 1641
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1642
-                        <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>
1642
+                        <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>
1643 1643
                         <?php
1644
-                        echo wpinv_html_text( array(
1644
+                        echo wpinv_html_text(array(
1645 1645
                                 'id'            => 'wpinv_first_name',
1646 1646
                                 'name'          => 'wpinv_first_name',
1647 1647
                                 'value'         => $billing_details['first_name'],
1648 1648
                                 'class'         => 'wpi-input form-control',
1649
-                                'placeholder'   => __( 'First name', 'invoicing' ),
1650
-                                'required'      => (bool)wpinv_get_option( 'fname_mandatory' ),
1651
-                            ) );
1649
+                                'placeholder'   => __('First name', 'invoicing'),
1650
+                                'required'      => (bool)wpinv_get_option('fname_mandatory'),
1651
+                            ));
1652 1652
                         ?>
1653 1653
                     </p>
1654 1654
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1655
-                        <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>
1655
+                        <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>
1656 1656
                         <?php
1657
-                        echo wpinv_html_text( array(
1657
+                        echo wpinv_html_text(array(
1658 1658
                                 'id'            => 'wpinv_last_name',
1659 1659
                                 'name'          => 'wpinv_last_name',
1660 1660
                                 'value'         => $billing_details['last_name'],
1661 1661
                                 'class'         => 'wpi-input form-control',
1662
-                                'placeholder'   => __( 'Last name', 'invoicing' ),
1663
-                                'required'      => (bool)wpinv_get_option( 'lname_mandatory' ),
1664
-                            ) );
1662
+                                'placeholder'   => __('Last name', 'invoicing'),
1663
+                                'required'      => (bool)wpinv_get_option('lname_mandatory'),
1664
+                            ));
1665 1665
                         ?>
1666 1666
                     </p>
1667 1667
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1668
-                        <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>
1668
+                        <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>
1669 1669
                         <?php
1670
-                        echo wpinv_html_text( array(
1670
+                        echo wpinv_html_text(array(
1671 1671
                                 'id'            => 'wpinv_address',
1672 1672
                                 'name'          => 'wpinv_address',
1673 1673
                                 'value'         => $billing_details['address'],
1674 1674
                                 'class'         => 'wpi-input form-control',
1675
-                                'placeholder'   => __( 'Address', 'invoicing' ),
1676
-                                'required'      => (bool)wpinv_get_option( 'address_mandatory' ),
1677
-                            ) );
1675
+                                'placeholder'   => __('Address', 'invoicing'),
1676
+                                'required'      => (bool)wpinv_get_option('address_mandatory'),
1677
+                            ));
1678 1678
                         ?>
1679 1679
                     </p>
1680 1680
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1681
-                        <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>
1681
+                        <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>
1682 1682
                         <?php
1683
-                        echo wpinv_html_text( array(
1683
+                        echo wpinv_html_text(array(
1684 1684
                                 'id'            => 'wpinv_city',
1685 1685
                                 'name'          => 'wpinv_city',
1686 1686
                                 'value'         => $billing_details['city'],
1687 1687
                                 'class'         => 'wpi-input form-control',
1688
-                                'placeholder'   => __( 'City', 'invoicing' ),
1689
-                                'required'      => (bool)wpinv_get_option( 'city_mandatory' ),
1690
-                            ) );
1688
+                                'placeholder'   => __('City', 'invoicing'),
1689
+                                'required'      => (bool)wpinv_get_option('city_mandatory'),
1690
+                            ));
1691 1691
                         ?>
1692 1692
                     </p>
1693 1693
                     <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf">
1694
-                        <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>
1695
-                        <?php echo wpinv_html_select( array(
1694
+                        <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>
1695
+                        <?php echo wpinv_html_select(array(
1696 1696
                             'options'          => wpinv_get_country_list(),
1697 1697
                             'name'             => 'wpinv_country',
1698 1698
                             'id'               => 'wpinv_country',
@@ -1700,16 +1700,16 @@  discard block
 block discarded – undo
1700 1700
                             'show_option_all'  => false,
1701 1701
                             'show_option_none' => false,
1702 1702
                             'class'            => 'wpi-input form-control',
1703
-                            'placeholder'      => __( 'Choose a country', 'invoicing' ),
1704
-                            'required'         => (bool)wpinv_get_option( 'country_mandatory' ),
1705
-                        ) ); ?>
1703
+                            'placeholder'      => __('Choose a country', 'invoicing'),
1704
+                            'required'         => (bool)wpinv_get_option('country_mandatory'),
1705
+                        )); ?>
1706 1706
                     </p>
1707 1707
                     <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll">
1708
-                        <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>
1708
+                        <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>
1709 1709
                         <?php
1710
-                        $states = wpinv_get_country_states( $selected_country );
1711
-                        if( !empty( $states ) ) {
1712
-                            echo wpinv_html_select( array(
1710
+                        $states = wpinv_get_country_states($selected_country);
1711
+                        if (!empty($states)) {
1712
+                            echo wpinv_html_select(array(
1713 1713
                                 'options'          => $states,
1714 1714
                                 'name'             => 'wpinv_state',
1715 1715
                                 'id'               => 'wpinv_state',
@@ -1717,61 +1717,61 @@  discard block
 block discarded – undo
1717 1717
                                 'show_option_all'  => false,
1718 1718
                                 'show_option_none' => false,
1719 1719
                                 'class'            => 'wpi-input form-control',
1720
-                                'placeholder'      => __( 'Choose a state', 'invoicing' ),
1721
-                                'required'         => (bool)wpinv_get_option( 'state_mandatory' ),
1722
-                            ) );
1720
+                                'placeholder'      => __('Choose a state', 'invoicing'),
1721
+                                'required'         => (bool)wpinv_get_option('state_mandatory'),
1722
+                            ));
1723 1723
                         } else {
1724
-                            echo wpinv_html_text( array(
1724
+                            echo wpinv_html_text(array(
1725 1725
                                 'name'          => 'wpinv_state',
1726 1726
                                 'value'         => $billing_details['state'],
1727 1727
                                 'id'            => 'wpinv_state',
1728 1728
                                 'class'         => 'wpi-input form-control',
1729
-                                'placeholder'   => __( 'State / Province', 'invoicing' ),
1730
-                                'required'      => (bool)wpinv_get_option( 'state_mandatory' ),
1731
-                            ) );
1729
+                                'placeholder'   => __('State / Province', 'invoicing'),
1730
+                                'required'      => (bool)wpinv_get_option('state_mandatory'),
1731
+                            ));
1732 1732
                         }
1733 1733
                         ?>
1734 1734
                     </p>
1735 1735
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1736
-                        <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>
1736
+                        <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>
1737 1737
                         <?php
1738
-                        echo wpinv_html_text( array(
1738
+                        echo wpinv_html_text(array(
1739 1739
                                 'name'          => 'wpinv_zip',
1740 1740
                                 'value'         => $billing_details['zip'],
1741 1741
                                 'id'            => 'wpinv_zip',
1742 1742
                                 'class'         => 'wpi-input form-control',
1743
-                                'placeholder'   => __( 'ZIP / Postcode', 'invoicing' ),
1744
-                                'required'      => (bool)wpinv_get_option( 'zip_mandatory' ),
1745
-                            ) );
1743
+                                'placeholder'   => __('ZIP / Postcode', 'invoicing'),
1744
+                                'required'      => (bool)wpinv_get_option('zip_mandatory'),
1745
+                            ));
1746 1746
                         ?>
1747 1747
                     </p>
1748 1748
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1749
-                        <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>
1749
+                        <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>
1750 1750
                         <?php
1751
-                        echo wpinv_html_text( array(
1751
+                        echo wpinv_html_text(array(
1752 1752
                                 'id'            => 'wpinv_phone',
1753 1753
                                 'name'          => 'wpinv_phone',
1754 1754
                                 'value'         => $billing_details['phone'],
1755 1755
                                 'class'         => 'wpi-input form-control',
1756
-                                'placeholder'   => __( 'Phone', 'invoicing' ),
1757
-                                'required'      => (bool)wpinv_get_option( 'phone_mandatory' ),
1758
-                            ) );
1756
+                                'placeholder'   => __('Phone', 'invoicing'),
1757
+                                'required'      => (bool)wpinv_get_option('phone_mandatory'),
1758
+                            ));
1759 1759
                         ?>
1760 1760
                     </p>
1761
-                    <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?>
1761
+                    <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?>
1762 1762
                     <div class="clearfix"></div>
1763 1763
                 </div>
1764 1764
             </div>
1765
-            <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?>
1765
+            <?php do_action('wpinv_after_billing_fields', $billing_details); ?>
1766 1766
         </div>
1767 1767
         <?php
1768 1768
     }
1769 1769
 }
1770
-add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' );
1770
+add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info');
1771 1771
 
1772 1772
 function wpinv_checkout_hidden_fields() {
1773 1773
 ?>
1774
-    <?php if ( is_user_logged_in() ) { ?>
1774
+    <?php if (is_user_logged_in()) { ?>
1775 1775
     <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/>
1776 1776
     <?php } ?>
1777 1777
     <input type="hidden" name="wpi_action" value="payment" />
@@ -1781,9 +1781,9 @@  discard block
 block discarded – undo
1781 1781
 function wpinv_checkout_button_purchase() {
1782 1782
     ob_start();
1783 1783
 ?>
1784
-    <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' ) ?>"/>
1784
+    <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') ?>"/>
1785 1785
 <?php
1786
-    return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() );
1786
+    return apply_filters('wpinv_checkout_button_purchase', ob_get_clean());
1787 1787
 }
1788 1788
 
1789 1789
 function wpinv_checkout_total() {
@@ -1792,96 +1792,96 @@  discard block
 block discarded – undo
1792 1792
 <div id="wpinv_checkout_total" class="panel panel-info">
1793 1793
     <div class="panel-body">
1794 1794
     <?php
1795
-    do_action( 'wpinv_purchase_form_before_checkout_total' );
1795
+    do_action('wpinv_purchase_form_before_checkout_total');
1796 1796
     ?>
1797
-    <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span>
1797
+    <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span>
1798 1798
     <?php
1799
-    do_action( 'wpinv_purchase_form_after_checkout_total' );
1799
+    do_action('wpinv_purchase_form_after_checkout_total');
1800 1800
     ?>
1801 1801
     </div>
1802 1802
 </div>
1803 1803
 <?php
1804 1804
 }
1805
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 );
1805
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998);
1806 1806
 
1807 1807
 function wpinv_checkout_submit() {
1808 1808
 ?>
1809 1809
 <div id="wpinv_purchase_submit" class="panel panel-success">
1810 1810
     <div class="panel-body text-center">
1811 1811
     <?php
1812
-    do_action( 'wpinv_purchase_form_before_submit' );
1812
+    do_action('wpinv_purchase_form_before_submit');
1813 1813
     wpinv_checkout_hidden_fields();
1814 1814
     echo wpinv_checkout_button_purchase();
1815
-    do_action( 'wpinv_purchase_form_after_submit' );
1815
+    do_action('wpinv_purchase_form_after_submit');
1816 1816
     ?>
1817 1817
     </div>
1818 1818
 </div>
1819 1819
 <?php
1820 1820
 }
1821
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 );
1821
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999);
1822 1822
 
1823
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1824
-    $invoice = wpinv_get_invoice( $invoice_id );
1823
+function wpinv_receipt_billing_address($invoice_id = 0) {
1824
+    $invoice = wpinv_get_invoice($invoice_id);
1825 1825
     
1826
-    if ( empty( $invoice ) ) {
1826
+    if (empty($invoice)) {
1827 1827
         return NULL;
1828 1828
     }
1829 1829
     
1830 1830
     $billing_details = $invoice->get_user_info();
1831 1831
     $address_row = '';
1832
-    if ( $address = $billing_details['address'] ) {
1833
-        $address_row .= wpautop( wp_kses_post( $address ) );
1832
+    if ($address = $billing_details['address']) {
1833
+        $address_row .= wpautop(wp_kses_post($address));
1834 1834
     }
1835 1835
     
1836 1836
     $address_fields = array();
1837
-    if ( !empty( $billing_details['city'] ) ) {
1837
+    if (!empty($billing_details['city'])) {
1838 1838
         $address_fields[] = $billing_details['city'];
1839 1839
     }
1840 1840
     
1841
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
1842
-    if ( !empty( $billing_details['state'] ) ) {
1843
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
1841
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
1842
+    if (!empty($billing_details['state'])) {
1843
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
1844 1844
     }
1845 1845
     
1846
-    if ( !empty( $billing_country ) ) {
1847
-        $address_fields[] = wpinv_country_name( $billing_country );
1846
+    if (!empty($billing_country)) {
1847
+        $address_fields[] = wpinv_country_name($billing_country);
1848 1848
     }
1849 1849
     
1850
-    if ( !empty( $address_fields ) ) {
1851
-        $address_fields = implode( ", ", $address_fields );
1850
+    if (!empty($address_fields)) {
1851
+        $address_fields = implode(", ", $address_fields);
1852 1852
         
1853
-        if ( !empty( $billing_details['zip'] ) ) {
1853
+        if (!empty($billing_details['zip'])) {
1854 1854
             $address_fields .= ' ' . $billing_details['zip'];
1855 1855
         }
1856 1856
         
1857
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
1857
+        $address_row .= wpautop(wp_kses_post($address_fields));
1858 1858
     }
1859 1859
     ob_start();
1860 1860
     ?>
1861 1861
     <table class="table table-bordered table-sm wpi-billing-details">
1862 1862
         <tbody>
1863 1863
             <tr class="wpi-receipt-name">
1864
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1865
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1864
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1865
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1866 1866
             </tr>
1867 1867
             <tr class="wpi-receipt-email">
1868
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1869
-                <td><?php echo $billing_details['email'] ;?></td>
1868
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1869
+                <td><?php echo $billing_details['email']; ?></td>
1870 1870
             </tr>
1871
-            <?php if ( $billing_details['company'] ) { ?>
1871
+            <?php if ($billing_details['company']) { ?>
1872 1872
             <tr class="wpi-receipt-company">
1873
-                <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th>
1874
-                <td><?php echo esc_html( $billing_details['company'] ) ;?></td>
1873
+                <th class="text-left"><?php _e('Company', 'invoicing'); ?></th>
1874
+                <td><?php echo esc_html($billing_details['company']); ?></td>
1875 1875
             </tr>
1876 1876
             <?php } ?>
1877 1877
             <tr class="wpi-receipt-address">
1878
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1879
-                <td><?php echo $address_row ;?></td>
1878
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1879
+                <td><?php echo $address_row; ?></td>
1880 1880
             </tr>
1881
-            <?php if ( $billing_details['phone'] ) { ?>
1881
+            <?php if ($billing_details['phone']) { ?>
1882 1882
             <tr class="wpi-receipt-phone">
1883
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1884
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1883
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1884
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1885 1885
             </tr>
1886 1886
             <?php } ?>
1887 1887
         </tbody>
@@ -1889,103 +1889,103 @@  discard block
 block discarded – undo
1889 1889
     <?php
1890 1890
     $output = ob_get_clean();
1891 1891
     
1892
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1892
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1893 1893
 
1894 1894
     echo $output;
1895 1895
 }
1896 1896
 
1897
-function wpinv_filter_success_page_content( $content ) {
1898
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1899
-        if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) {
1900
-            $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content );
1897
+function wpinv_filter_success_page_content($content) {
1898
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1899
+        if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) {
1900
+            $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content);
1901 1901
         }
1902 1902
     }
1903 1903
 
1904 1904
     return $content;
1905 1905
 }
1906
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1906
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1907 1907
 
1908
-function wpinv_receipt_actions( $invoice ) {
1909
-    if ( !empty( $invoice ) ) {
1908
+function wpinv_receipt_actions($invoice) {
1909
+    if (!empty($invoice)) {
1910 1910
         $actions = array();
1911 1911
 
1912
-        if ( wpinv_user_can_print_invoice( $invoice->ID ) ) {
1913
-            $actions['print']   = array(
1914
-                'url'  => $invoice->get_view_url( false, true ),
1915
-                'name' => __( 'Print Invoice', 'invoicing' ),
1912
+        if (wpinv_user_can_print_invoice($invoice->ID)) {
1913
+            $actions['print'] = array(
1914
+                'url'  => $invoice->get_view_url(false, true),
1915
+                'name' => __('Print Invoice', 'invoicing'),
1916 1916
                 'class' => 'btn-primary',
1917 1917
             );
1918 1918
         }
1919 1919
 
1920
-        if ( is_user_logged_in() ) {
1920
+        if (is_user_logged_in()) {
1921 1921
             $actions['history'] = array(
1922 1922
                 'url'  => wpinv_get_history_page_uri(),
1923
-                'name' => __( 'Invoice History', 'invoicing' ),
1923
+                'name' => __('Invoice History', 'invoicing'),
1924 1924
                 'class' => 'btn-warning',
1925 1925
             );
1926 1926
         }
1927 1927
 
1928
-        $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice );
1928
+        $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice);
1929 1929
         
1930
-        if ( !empty( $actions ) ) {
1930
+        if (!empty($actions)) {
1931 1931
         ?>
1932 1932
         <div class="wpinv-receipt-actions text-right">
1933
-            <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?>
1934
-            <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>
1933
+            <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?>
1934
+            <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>
1935 1935
             <?php } ?>
1936 1936
         </div>
1937 1937
         <?php
1938 1938
         }
1939 1939
     }
1940 1940
 }
1941
-add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 );
1941
+add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1);
1942 1942
 
1943
-function wpinv_invoice_link( $invoice_id ) {
1944
-    $invoice = wpinv_get_invoice( $invoice_id );
1943
+function wpinv_invoice_link($invoice_id) {
1944
+    $invoice = wpinv_get_invoice($invoice_id);
1945 1945
     
1946
-    if ( empty( $invoice ) ) {
1946
+    if (empty($invoice)) {
1947 1947
         return NULL;
1948 1948
     }
1949 1949
     
1950
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1950
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1951 1951
     
1952
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1952
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1953 1953
 }
1954 1954
 
1955
-function wpinv_invoice_subscription_details( $invoice ) {
1956
-    if ( !empty( $invoice ) && $invoice->is_recurring() && !wpinv_is_subscription_payment( $invoice ) ) {
1955
+function wpinv_invoice_subscription_details($invoice) {
1956
+    if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) {
1957 1957
         $total_payments = (int)$invoice->get_total_payments();
1958 1958
         $payments       = $invoice->get_child_payments();
1959 1959
         
1960 1960
         $subscription   = $invoice->get_subscription_data();
1961 1961
         
1962
-        if ( !( !empty( $subscription ) && !empty( $subscription['item_id'] ) ) ) {
1962
+        if (!(!empty($subscription) && !empty($subscription['item_id']))) {
1963 1963
             return;
1964 1964
         }
1965 1965
         
1966
-        $billing_cycle  = wpinv_get_billing_cycle( $subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency() );
1967
-        $times_billed   = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] );
1966
+        $billing_cycle  = wpinv_get_billing_cycle($subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency());
1967
+        $times_billed   = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']);
1968 1968
         
1969 1969
         $subscription_status = $invoice->get_subscription_status();
1970 1970
         
1971 1971
         $status_desc = '';
1972
-        if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) {
1973
-            $status_desc = wp_sprintf( __( 'Until: %s', 'invoicing' ), $trial_end_date );
1974
-        } else if ( $subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date() ) {
1975
-            $status_desc = wp_sprintf( __( 'On: %s', 'invoicing' ), $cancelled_date );
1972
+        if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) {
1973
+            $status_desc = wp_sprintf(__('Until: %s', 'invoicing'), $trial_end_date);
1974
+        } else if ($subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date()) {
1975
+            $status_desc = wp_sprintf(__('On: %s', 'invoicing'), $cancelled_date);
1976 1976
         }
1977 1977
         $status_desc = $status_desc != '' ? '<span class="meta">' . $status_desc . '</span>' : '';
1978 1978
         ?>
1979 1979
         <div class="wpinv-subscriptions-details">
1980
-            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3>
1980
+            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3>
1981 1981
             <table class="table">
1982 1982
                 <thead>
1983 1983
                     <tr>
1984
-                        <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th>
1985
-                        <th><?php _e( 'Start Date', 'invoicing' ) ;?></th>
1986
-                        <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th>
1987
-                        <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th>
1988
-                        <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th>
1984
+                        <th><?php _e('Billing Cycle', 'invoicing'); ?></th>
1985
+                        <th><?php _e('Start Date', 'invoicing'); ?></th>
1986
+                        <th><?php _e('Expiration Date', 'invoicing'); ?></th>
1987
+                        <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th>
1988
+                        <th class="text-center"><?php _e('Status', 'invoicing'); ?></th>
1989 1989
                     </tr>
1990 1990
                 </thead>
1991 1991
                 <tbody>
@@ -1994,32 +1994,32 @@  discard block
 block discarded – undo
1994 1994
                         <td><?php echo $invoice->get_subscription_start(); ?></td>
1995 1995
                         <td><?php echo $invoice->get_subscription_end(); ?></td>
1996 1996
                         <td class="text-center"><?php echo $times_billed; ?></td>
1997
-                        <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label() ;?>
1997
+                        <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label(); ?>
1998 1998
                         <?php echo $status_desc; ?>
1999 1999
                         </td>
2000 2000
                     </tr>
2001 2001
                 </tbody>
2002 2002
             </table>
2003 2003
         </div>
2004
-        <?php if ( !empty( $payments ) ) { ?>
2004
+        <?php if (!empty($payments)) { ?>
2005 2005
         <div class="wpinv-renewal-payments">
2006
-            <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3>
2006
+            <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3>
2007 2007
             <table class="table">
2008 2008
                 <thead>
2009 2009
                     <tr>
2010 2010
                         <th>#</th>
2011
-                        <th><?php _e( 'Invoice', 'invoicing' ) ;?></th>
2012
-                        <th><?php _e( 'Date', 'invoicing' ) ;?></th>
2013
-                        <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th>
2011
+                        <th><?php _e('Invoice', 'invoicing'); ?></th>
2012
+                        <th><?php _e('Date', 'invoicing'); ?></th>
2013
+                        <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th>
2014 2014
                     </tr>
2015 2015
                 </thead>
2016 2016
                 <tbody>
2017
-                    <?php foreach ( $payments as $key => $invoice_id ) { ?>
2017
+                    <?php foreach ($payments as $key => $invoice_id) { ?>
2018 2018
                     <tr>
2019
-                        <th scope="row"><?php echo ( $key + 1 );?></th>
2020
-                        <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td>
2021
-                        <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td>
2022
-                        <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td>
2019
+                        <th scope="row"><?php echo ($key + 1); ?></th>
2020
+                        <td><?php echo wpinv_invoice_link($invoice_id); ?></td>
2021
+                        <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td>
2022
+                        <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td>
2023 2023
                     </tr>
2024 2024
                     <?php } ?>
2025 2025
                     <tr><td colspan="4" style="padding:0"></td></tr>
@@ -2031,52 +2031,52 @@  discard block
 block discarded – undo
2031 2031
     }
2032 2032
 }
2033 2033
 
2034
-function wpinv_cart_total_label( $label, $invoice ) {
2035
-    if ( empty( $invoice ) ) {
2034
+function wpinv_cart_total_label($label, $invoice) {
2035
+    if (empty($invoice)) {
2036 2036
         return $label;
2037 2037
     }
2038 2038
     
2039 2039
     $prefix_label = '';
2040
-    if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) {        
2041
-        $prefix_label   = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice );
2042
-    } else if ( $invoice->is_renewal() ) {
2043
-        $prefix_label   = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> ';        
2040
+    if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) {        
2041
+        $prefix_label   = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice);
2042
+    } else if ($invoice->is_renewal()) {
2043
+        $prefix_label   = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> ';        
2044 2044
     }
2045 2045
     
2046
-    if ( $prefix_label != '' ) {
2047
-        $label  = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2046
+    if ($prefix_label != '') {
2047
+        $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2048 2048
     }
2049 2049
     
2050 2050
     return $label;
2051 2051
 }
2052
-add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2053
-add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2054
-add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2052
+add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2053
+add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2054
+add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2055 2055
 
2056
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 );
2056
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1);
2057 2057
 
2058
-function wpinv_invoice_print_description( $invoice ) {
2059
-    if ( empty( $invoice ) ) {
2058
+function wpinv_invoice_print_description($invoice) {
2059
+    if (empty($invoice)) {
2060 2060
         return NULL;
2061 2061
     }
2062
-    if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) {
2062
+    if ($description = wpinv_get_invoice_description($invoice->ID)) {
2063 2063
         ?>
2064 2064
         <div class="row wpinv-lower">
2065 2065
             <div class="col-sm-12 wpinv-description">
2066
-                <?php echo wpautop( $description ); ?>
2066
+                <?php echo wpautop($description); ?>
2067 2067
             </div>
2068 2068
         </div>
2069 2069
         <?php
2070 2070
     }
2071 2071
 }
2072
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 );
2072
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1);
2073 2073
 
2074
-function wpinv_invoice_print_payment_info( $invoice ) {
2075
-    if ( empty( $invoice ) ) {
2074
+function wpinv_invoice_print_payment_info($invoice) {
2075
+    if (empty($invoice)) {
2076 2076
         return NULL;
2077 2077
     }
2078 2078
     
2079
-    if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) {
2079
+    if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) {
2080 2080
         ?>
2081 2081
         <div class="row wpinv-payments">
2082 2082
             <div class="col-sm-12">
@@ -2088,43 +2088,43 @@  discard block
 block discarded – undo
2088 2088
 }
2089 2089
 // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 );
2090 2090
 
2091
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
2092
-    if ( empty( $note ) ) {
2091
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
2092
+    if (empty($note)) {
2093 2093
         return NULL;
2094 2094
     }
2095 2095
     
2096
-    if ( is_int( $note ) ) {
2097
-        $note = get_comment( $note );
2096
+    if (is_int($note)) {
2097
+        $note = get_comment($note);
2098 2098
     }
2099 2099
     
2100
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
2100
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
2101 2101
         return NULL;
2102 2102
     }
2103 2103
     
2104
-    $note_classes   = array( 'note' );
2105
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
2106
-    $note_classes[] = $note->comment_author === __( 'System', 'invoicing' ) ? 'system-note' : '';
2107
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
2108
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
2104
+    $note_classes   = array('note');
2105
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
2106
+    $note_classes[] = $note->comment_author === __('System', 'invoicing') ? 'system-note' : '';
2107
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
2108
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
2109 2109
     
2110 2110
     ob_start();
2111 2111
     ?>
2112
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>">
2112
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>">
2113 2113
         <div class="note_content">
2114
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
2114
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
2115 2115
         </div>
2116 2116
         <p class="meta">
2117
-            <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;
2118
-            <?php if($note->comment_author !== 'System') {?>
2119
-                <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
2117
+            <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;
2118
+            <?php if ($note->comment_author !== 'System') {?>
2119
+                <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
2120 2120
             <?php } ?>
2121 2121
         </p>
2122 2122
     </li>
2123 2123
     <?php
2124 2124
     $note_content = ob_get_clean();
2125
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
2125
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
2126 2126
     
2127
-    if ( $echo ) {
2127
+    if ($echo) {
2128 2128
         echo $note_content;
2129 2129
     } else {
2130 2130
         return $note_content;
Please login to merge, or discard this patch.
invoicing.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -11,19 +11,19 @@  discard block
 block discarded – undo
11 11
 */
12 12
 
13 13
 // MUST have WordPress.
14
-if ( !defined( 'WPINC' ) ) {
15
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
14
+if (!defined('WPINC')) {
15
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
16 16
 }
17 17
 
18
-if ( !defined( 'WPINV_VERSION' ) ) {
19
-    define( 'WPINV_VERSION', '0.0.41' );
18
+if (!defined('WPINV_VERSION')) {
19
+    define('WPINV_VERSION', '0.0.41');
20 20
 }
21 21
 
22
-if ( !defined( 'WPINV_PLUGIN_FILE' ) ) {
23
-    define( 'WPINV_PLUGIN_FILE', __FILE__ );
22
+if (!defined('WPINV_PLUGIN_FILE')) {
23
+    define('WPINV_PLUGIN_FILE', __FILE__);
24 24
 }
25 25
 
26
-require plugin_dir_path( __FILE__ ) . 'includes/class-wpinv.php';
26
+require plugin_dir_path(__FILE__) . 'includes/class-wpinv.php';
27 27
 
28 28
 function wpinv_run() {
29 29
     global $invoicing;
@@ -40,16 +40,16 @@  discard block
 block discarded – undo
40 40
 /**
41 41
  * Show update plugin admin notification.
42 42
  */
43
-if(is_admin()){
43
+if (is_admin()) {
44 44
     if (!function_exists('ayecode_show_update_plugin_requirement')) {//only load the update file if needed
45 45
         function ayecode_show_update_plugin_requirement() {
46
-            if ( !defined( 'WP_EASY_UPDATES_ACTIVE' ) ) {
46
+            if (!defined('WP_EASY_UPDATES_ACTIVE')) {
47 47
                 ?>
48 48
                 <div class="notice notice-warning is-dismissible">
49 49
                     <p>
50 50
                         <strong>
51 51
                             <?php
52
-                            echo sprintf( __( 'The plugin %sWP Easy Updates%s is required to check for and update some installed plugins, please install it now.', 'geodirectory' ), '<a href="https://wpeasyupdates.com/" target="_blank" title="WP Easy Updates">', '</a>' );
52
+                            echo sprintf(__('The plugin %sWP Easy Updates%s is required to check for and update some installed plugins, please install it now.', 'geodirectory'), '<a href="https://wpeasyupdates.com/" target="_blank" title="WP Easy Updates">', '</a>');
53 53
                             ?>
54 54
                         </strong>
55 55
                     </p>
@@ -58,6 +58,6 @@  discard block
 block discarded – undo
58 58
             }
59 59
         }
60 60
 
61
-        add_action( 'admin_notices', 'ayecode_show_update_plugin_requirement' );
61
+        add_action('admin_notices', 'ayecode_show_update_plugin_requirement');
62 62
     }
63 63
 }
Please login to merge, or discard this patch.