Passed
Pull Request — master (#57)
by Kiran
04:16
created
includes/class-wpinv.php 1 patch
Spacing   +152 added lines, -152 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,193 +83,193 @@  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' );
224
-        wp_enqueue_script( 'wpinv-front-script' );
225
-        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
223
+        wp_enqueue_script('jquery-blockui');
224
+        wp_enqueue_script('wpinv-front-script');
225
+        wp_localize_script('wpinv-front-script', 'WPInv', $localize);
226 226
     }
227 227
     
228 228
     public function admin_enqueue_scripts() {
229 229
         global $post, $pagenow;
230 230
         
231 231
         $post_type  = wpinv_admin_post_type();
232
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
232
+        $suffix     = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
233 233
         
234
-        wp_deregister_style( 'font-awesome' );
235
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
236
-        wp_enqueue_style( 'font-awesome' );
234
+        wp_deregister_style('font-awesome');
235
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
236
+        wp_enqueue_style('font-awesome');
237 237
         
238
-        wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
239
-        wp_enqueue_style( 'jquery-ui-css' );
238
+        wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16');
239
+        wp_enqueue_style('jquery-ui-css');
240 240
         
241
-        wp_register_style( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2' );
242
-        wp_enqueue_style( 'jquery-chosen' );
241
+        wp_register_style('jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2');
242
+        wp_enqueue_style('jquery-chosen');
243 243
 
244
-        wp_register_script( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6.2' );
245
-        wp_enqueue_script( 'jquery-chosen' );
244
+        wp_register_script('jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array('jquery'), '1.6.2');
245
+        wp_enqueue_script('jquery-chosen');
246 246
         
247
-        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
248
-        wp_enqueue_style( 'wpinv_meta_box_style' );
247
+        wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
248
+        wp_enqueue_style('wpinv_meta_box_style');
249 249
         
250
-        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION );
251
-        wp_enqueue_style( 'wpinv_admin_style' );
250
+        wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION);
251
+        wp_enqueue_style('wpinv_admin_style');
252 252
         
253
-        if ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
254
-            wp_enqueue_script( 'jquery-ui-datepicker' );
253
+        if ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
254
+            wp_enqueue_script('jquery-ui-datepicker');
255 255
         }
256 256
 
257
-        wp_enqueue_style( 'wp-color-picker' );
258
-        wp_enqueue_script( 'wp-color-picker' );
257
+        wp_enqueue_style('wp-color-picker');
258
+        wp_enqueue_script('wp-color-picker');
259 259
         
260
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
260
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
261 261
         
262
-        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui' ),  WPINV_VERSION );
263
-        wp_enqueue_script( 'wpinv-admin-script' );
262
+        wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui'), WPINV_VERSION);
263
+        wp_enqueue_script('wpinv-admin-script');
264 264
         
265 265
         $localize                               = array();
266
-        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
267
-        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
268
-        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
269
-        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
270
-        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
271
-        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
272
-        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
266
+        $localize['ajax_url']                   = admin_url('admin-ajax.php');
267
+        $localize['post_ID']                    = isset($post->ID) ? $post->ID : '';
268
+        $localize['wpinv_nonce']                = wp_create_nonce('wpinv-nonce');
269
+        $localize['add_invoice_note_nonce']     = wp_create_nonce('add-invoice-note');
270
+        $localize['delete_invoice_note_nonce']  = wp_create_nonce('delete-invoice-note');
271
+        $localize['invoice_item_nonce']         = wp_create_nonce('invoice-item');
272
+        $localize['billing_details_nonce']      = wp_create_nonce('get-billing-details');
273 273
         $localize['tax']                        = wpinv_tax_amount();
274 274
         $localize['discount']                   = wpinv_discount_amount();
275 275
         $localize['currency_symbol']            = wpinv_currency_symbol();
@@ -277,61 +277,61 @@  discard block
 block discarded – undo
277 277
         $localize['thousand_sep']               = wpinv_thousands_separator();
278 278
         $localize['decimal_sep']                = wpinv_decimal_separator();
279 279
         $localize['decimals']                   = wpinv_decimals();
280
-        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
281
-        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
282
-        $localize['status_pending']             = wpinv_status_nicename( 'pending' );
283
-        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
284
-        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
285
-        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
286
-        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
287
-        $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' );
288
-        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
280
+        $localize['save_invoice']               = __('Save Invoice', 'invoicing');
281
+        $localize['status_publish']             = wpinv_status_nicename('publish');
282
+        $localize['status_pending']             = wpinv_status_nicename('pending');
283
+        $localize['delete_tax_rate']            = __('Are you sure you wish to delete this tax rate?', 'invoicing');
284
+        $localize['OneItemMin']                 = __('Invoice must contain at least one item', 'invoicing');
285
+        $localize['DeleteInvoiceItem']          = __('Are you sure you wish to delete this item?', 'invoicing');
286
+        $localize['FillBillingDetails']         = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing');
287
+        $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');
288
+        $localize['AreYouSure']                 = __('Are you sure?', 'invoicing');
289 289
         $localize['hasGD']                      = wpinv_gd_active();
290 290
         $localize['hasPM']                      = wpinv_pm_active();
291
-        $localize['emptyInvoice']               = __( 'Add atleast one item to save invoice!', 'invoicing' );
292
-        $localize['deletePackage']              = __( 'GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing' );
293
-        $localize['deletePackages']             = __( 'GD package items should be deleted from GD payment manager only', 'invoicing' );
294
-        $localize['deleteInvoiceFirst']         = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
291
+        $localize['emptyInvoice']               = __('Add atleast one item to save invoice!', 'invoicing');
292
+        $localize['deletePackage']              = __('GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing');
293
+        $localize['deletePackages']             = __('GD package items should be deleted from GD payment manager only', 'invoicing');
294
+        $localize['deleteInvoiceFirst']         = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing');
295 295
 
296
-        $localize = apply_filters( 'wpinv_admin_js_localize', $localize );
296
+        $localize = apply_filters('wpinv_admin_js_localize', $localize);
297 297
 
298
-        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
298
+        wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize);
299 299
     }
300 300
     
301
-    public function admin_body_class( $classes ) {
301
+    public function admin_body_class($classes) {
302 302
         global $pagenow, $post;
303 303
         
304
-        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
304
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
305 305
 
306 306
         $add_class = false;
307
-        if ( $pagenow == 'admin.php' && $page ) {
308
-            $add_class = strpos( $page, 'wpinv-' );
307
+        if ($pagenow == 'admin.php' && $page) {
308
+            $add_class = strpos($page, 'wpinv-');
309 309
         }
310 310
         
311 311
         $settings_class = array();
312
-        if ( $page == 'wpinv-settings' ) {
313
-            if ( !empty( $_REQUEST['tab'] ) ) {
314
-                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
312
+        if ($page == 'wpinv-settings') {
313
+            if (!empty($_REQUEST['tab'])) {
314
+                $settings_class[] = sanitize_text_field($_REQUEST['tab']);
315 315
             }
316 316
             
317
-            if ( !empty( $_REQUEST['section'] ) ) {
318
-                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
317
+            if (!empty($_REQUEST['section'])) {
318
+                $settings_class[] = sanitize_text_field($_REQUEST['section']);
319 319
             }
320 320
             
321
-            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
321
+            $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main';
322 322
         }
323 323
         
324
-        if ( !empty( $settings_class ) ) {
325
-            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
324
+        if (!empty($settings_class)) {
325
+            $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-'));
326 326
         }
327 327
         
328 328
         $post_type = wpinv_admin_post_type();
329 329
 
330
-        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
330
+        if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) {
331 331
             return $classes .= ' wpinv';
332 332
         }
333 333
         
334
-        if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) {
334
+        if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) {
335 335
             $classes .= ' wpi-editable-n';
336 336
         }
337 337
 
@@ -343,20 +343,20 @@  discard block
 block discarded – undo
343 343
     }
344 344
     
345 345
     public function wpinv_actions() {
346
-        if ( isset( $_REQUEST['wpi_action'] ) ) {
347
-            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
346
+        if (isset($_REQUEST['wpi_action'])) {
347
+            do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
348 348
         }
349 349
     }
350 350
     
351
-    public function pre_get_posts( $wp_query ) {
352
-        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() ) {
353
-            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
351
+    public function pre_get_posts($wp_query) {
352
+        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()) {
353
+            $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
354 354
         }
355 355
         
356 356
         return $wp_query;
357 357
     }
358 358
     
359 359
     public function bp_invoicing_init() {
360
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
360
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
361 361
     }
362 362
 }
363 363
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-item.php 1 patch
Spacing   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5 5
 class WPInv_Item {
6 6
     public $ID = 0;
@@ -33,26 +33,26 @@  discard block
 block discarded – undo
33 33
     public $filter;
34 34
 
35 35
 
36
-    public function __construct( $_id = false, $_args = array() ) {
37
-        $item = WP_Post::get_instance( $_id );
38
-        return $this->setup_item( $item );
36
+    public function __construct($_id = false, $_args = array()) {
37
+        $item = WP_Post::get_instance($_id);
38
+        return $this->setup_item($item);
39 39
     }
40 40
 
41
-    private function setup_item( $item ) {
42
-        if( ! is_object( $item ) ) {
41
+    private function setup_item($item) {
42
+        if (!is_object($item)) {
43 43
             return false;
44 44
         }
45 45
 
46
-        if( ! is_a( $item, 'WP_Post' ) ) {
46
+        if (!is_a($item, 'WP_Post')) {
47 47
             return false;
48 48
         }
49 49
 
50
-        if( 'wpi_item' !== $item->post_type ) {
50
+        if ('wpi_item' !== $item->post_type) {
51 51
             return false;
52 52
         }
53 53
 
54
-        foreach ( $item as $key => $value ) {
55
-            switch ( $key ) {
54
+        foreach ($item as $key => $value) {
55
+            switch ($key) {
56 56
                 default:
57 57
                     $this->$key = $value;
58 58
                     break;
@@ -62,38 +62,38 @@  discard block
 block discarded – undo
62 62
         return true;
63 63
     }
64 64
 
65
-    public function __get( $key ) {
66
-        if ( method_exists( $this, 'get_' . $key ) ) {
67
-            return call_user_func( array( $this, 'get_' . $key ) );
65
+    public function __get($key) {
66
+        if (method_exists($this, 'get_' . $key)) {
67
+            return call_user_func(array($this, 'get_' . $key));
68 68
         } else {
69
-            return new WP_Error( 'wpinv-item-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) );
69
+            return new WP_Error('wpinv-item-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key));
70 70
         }
71 71
     }
72 72
 
73
-    public function create( $data = array(), $wp_error = false ) {
74
-        if ( $this->ID != 0 ) {
73
+    public function create($data = array(), $wp_error = false) {
74
+        if ($this->ID != 0) {
75 75
             return false;
76 76
         }
77 77
 
78 78
         $defaults = array(
79 79
             'post_type'   => 'wpi_item',
80 80
             'post_status' => 'draft',
81
-            'post_title'  => __( 'New Invoice Item', 'invoicing' )
81
+            'post_title'  => __('New Invoice Item', 'invoicing')
82 82
         );
83 83
 
84
-        $args = wp_parse_args( $data, $defaults );
84
+        $args = wp_parse_args($data, $defaults);
85 85
 
86
-        do_action( 'wpinv_item_pre_create', $args );
86
+        do_action('wpinv_item_pre_create', $args);
87 87
 
88
-        $id = wp_insert_post( $args, $wp_error );
88
+        $id = wp_insert_post($args, $wp_error);
89 89
         if ($wp_error && is_wp_error($id)) {
90 90
             return $id;
91 91
         }
92
-        if ( !$id ) {
92
+        if (!$id) {
93 93
             return false;
94 94
         }
95 95
         
96
-        $item = WP_Post::get_instance( $id );
96
+        $item = WP_Post::get_instance($id);
97 97
         
98 98
         if (!empty($item) && !empty($data['meta'])) {
99 99
             $this->ID = $item->ID;
@@ -101,47 +101,47 @@  discard block
 block discarded – undo
101 101
         }
102 102
         
103 103
         // Set custom id if not set.
104
-        if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) {
105
-            $this->save_metas( array( 'custom_id' => $id ) );
104
+        if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) {
105
+            $this->save_metas(array('custom_id' => $id));
106 106
         }
107 107
 
108
-        do_action( 'wpinv_item_create', $id, $args );
108
+        do_action('wpinv_item_create', $id, $args);
109 109
 
110
-        return $this->setup_item( $item );
110
+        return $this->setup_item($item);
111 111
     }
112 112
     
113
-    public function update( $data = array(), $wp_error = false ) {
114
-        if ( !$this->ID > 0 ) {
113
+    public function update($data = array(), $wp_error = false) {
114
+        if (!$this->ID > 0) {
115 115
             return false;
116 116
         }
117 117
         
118 118
         $data['ID'] = $this->ID;
119 119
 
120
-        do_action( 'wpinv_item_pre_update', $data );
120
+        do_action('wpinv_item_pre_update', $data);
121 121
         
122
-        $id = wp_update_post( $data, $wp_error );
122
+        $id = wp_update_post($data, $wp_error);
123 123
         if ($wp_error && is_wp_error($id)) {
124 124
             return $id;
125 125
         }
126 126
         
127
-        if ( !$id ) {
127
+        if (!$id) {
128 128
             return false;
129 129
         }
130 130
 
131
-        $item = WP_Post::get_instance( $id );
131
+        $item = WP_Post::get_instance($id);
132 132
         if (!empty($item) && !empty($data['meta'])) {
133 133
             $this->ID = $item->ID;
134 134
             $this->save_metas($data['meta']);
135 135
         }
136 136
         
137 137
         // Set custom id if not set.
138
-        if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) {
139
-            $this->save_metas( array( 'custom_id' => $id ) );
138
+        if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) {
139
+            $this->save_metas(array('custom_id' => $id));
140 140
         }
141 141
 
142
-        do_action( 'wpinv_item_update', $id, $data );
142
+        do_action('wpinv_item_update', $id, $data);
143 143
 
144
-        return $this->setup_item( $item );
144
+        return $this->setup_item($item);
145 145
     }
146 146
 
147 147
     public function get_ID() {
@@ -149,105 +149,105 @@  discard block
 block discarded – undo
149 149
     }
150 150
 
151 151
     public function get_name() {
152
-        return get_the_title( $this->ID );
152
+        return get_the_title($this->ID);
153 153
     }
154 154
     
155 155
     public function get_summary() {
156
-        return get_the_excerpt( $this->ID );
156
+        return get_the_excerpt($this->ID);
157 157
     }
158 158
 
159 159
     public function get_price() {
160
-        if ( ! isset( $this->price ) ) {
161
-            $this->price = get_post_meta( $this->ID, '_wpinv_price', true );
160
+        if (!isset($this->price)) {
161
+            $this->price = get_post_meta($this->ID, '_wpinv_price', true);
162 162
             
163
-            if ( $this->price ) {
164
-                $this->price = wpinv_sanitize_amount( $this->price );
163
+            if ($this->price) {
164
+                $this->price = wpinv_sanitize_amount($this->price);
165 165
             } else {
166 166
                 $this->price = 0;
167 167
             }
168 168
         }
169 169
         
170
-        return apply_filters( 'wpinv_get_item_price', $this->price, $this->ID );
170
+        return apply_filters('wpinv_get_item_price', $this->price, $this->ID);
171 171
     }
172 172
     
173 173
     public function get_the_price() {
174
-        $item_price = wpinv_price( wpinv_format_amount( $this->price ) );
174
+        $item_price = wpinv_price(wpinv_format_amount($this->price));
175 175
         
176
-        return apply_filters( 'wpinv_get_the_item_price', $item_price, $this->ID );
176
+        return apply_filters('wpinv_get_the_item_price', $item_price, $this->ID);
177 177
     }
178 178
     
179 179
     public function get_vat_rule() {
180 180
         global $wpinv_euvat;
181 181
         
182
-        if( !isset( $this->vat_rule ) ) {
183
-            $this->vat_rule = get_post_meta( $this->ID, '_wpinv_vat_rule', true );
182
+        if (!isset($this->vat_rule)) {
183
+            $this->vat_rule = get_post_meta($this->ID, '_wpinv_vat_rule', true);
184 184
 
185
-            if ( empty( $this->vat_rule ) ) {        
185
+            if (empty($this->vat_rule)) {        
186 186
                 $this->vat_rule = $wpinv_euvat->allow_vat_rules() ? 'digital' : 'physical';
187 187
             }
188 188
         }
189 189
         
190
-        return apply_filters( 'wpinv_get_item_vat_rule', $this->vat_rule, $this->ID );
190
+        return apply_filters('wpinv_get_item_vat_rule', $this->vat_rule, $this->ID);
191 191
     }
192 192
     
193 193
     public function get_vat_class() {
194
-        if( !isset( $this->vat_class ) ) {
195
-            $this->vat_class = get_post_meta( $this->ID, '_wpinv_vat_class', true );
194
+        if (!isset($this->vat_class)) {
195
+            $this->vat_class = get_post_meta($this->ID, '_wpinv_vat_class', true);
196 196
 
197
-            if ( empty( $this->vat_class ) ) {        
197
+            if (empty($this->vat_class)) {        
198 198
                 $this->vat_class = '_standard';
199 199
             }
200 200
         }
201 201
         
202
-        return apply_filters( 'wpinv_get_item_vat_class', $this->vat_class, $this->ID );
202
+        return apply_filters('wpinv_get_item_vat_class', $this->vat_class, $this->ID);
203 203
     }
204 204
 
205 205
     public function get_type() {
206
-        if( ! isset( $this->type ) ) {
207
-            $this->type = get_post_meta( $this->ID, '_wpinv_type', true );
206
+        if (!isset($this->type)) {
207
+            $this->type = get_post_meta($this->ID, '_wpinv_type', true);
208 208
 
209
-            if ( empty( $this->type ) ) {
209
+            if (empty($this->type)) {
210 210
                 $this->type = 'custom';
211 211
             }
212 212
         }
213 213
 
214
-        return apply_filters( 'wpinv_get_item_type', $this->type, $this->ID );
214
+        return apply_filters('wpinv_get_item_type', $this->type, $this->ID);
215 215
     }
216 216
     
217 217
     public function get_custom_id() {
218
-        $custom_id = get_post_meta( $this->ID, '_wpinv_custom_id', true );
218
+        $custom_id = get_post_meta($this->ID, '_wpinv_custom_id', true);
219 219
 
220
-        return apply_filters( 'wpinv_get_item_custom_id', $custom_id, $this->ID );
220
+        return apply_filters('wpinv_get_item_custom_id', $custom_id, $this->ID);
221 221
     }
222 222
     
223 223
     public function get_custom_name() {
224
-        $custom_name = get_post_meta( $this->ID, '_wpinv_custom_name', true );
224
+        $custom_name = get_post_meta($this->ID, '_wpinv_custom_name', true);
225 225
 
226
-        return apply_filters( 'wpinv_get_item_custom_name', $custom_name, $this->ID );
226
+        return apply_filters('wpinv_get_item_custom_name', $custom_name, $this->ID);
227 227
     }
228 228
     
229 229
     public function get_custom_singular_name() {
230
-        $custom_singular_name = get_post_meta( $this->ID, '_wpinv_custom_singular_name', true );
230
+        $custom_singular_name = get_post_meta($this->ID, '_wpinv_custom_singular_name', true);
231 231
 
232
-        return apply_filters( 'wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID );
232
+        return apply_filters('wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID);
233 233
     }
234 234
     
235 235
     public function is_recurring() {
236
-        $is_recurring = get_post_meta( $this->ID, '_wpinv_is_recurring', true );
236
+        $is_recurring = get_post_meta($this->ID, '_wpinv_is_recurring', true);
237 237
 
238
-        return (bool)apply_filters( 'wpinv_is_recurring_item', $is_recurring, $this->ID );
238
+        return (bool)apply_filters('wpinv_is_recurring_item', $is_recurring, $this->ID);
239 239
 
240 240
     }
241 241
     
242
-    public function get_recurring_period( $full = false ) {
243
-        $period = get_post_meta( $this->ID, '_wpinv_recurring_period', true );
242
+    public function get_recurring_period($full = false) {
243
+        $period = get_post_meta($this->ID, '_wpinv_recurring_period', true);
244 244
         
245
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
245
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
246 246
             $period = 'D';
247 247
         }
248 248
         
249
-        if ( $full ) {
250
-            switch( $period ) {
249
+        if ($full) {
250
+            switch ($period) {
251 251
                 case 'D':
252 252
                     $period = 'day';
253 253
                 break;
@@ -263,45 +263,45 @@  discard block
 block discarded – undo
263 263
             }
264 264
         }
265 265
 
266
-        return apply_filters( 'wpinv_item_recurring_period', $period, $full, $this->ID );
266
+        return apply_filters('wpinv_item_recurring_period', $period, $full, $this->ID);
267 267
 
268 268
     }
269 269
     
270 270
     public function get_recurring_interval() {
271
-        $interval = (int)get_post_meta( $this->ID, '_wpinv_recurring_interval', true );
271
+        $interval = (int)get_post_meta($this->ID, '_wpinv_recurring_interval', true);
272 272
         
273
-        if ( !$interval > 0 ) {
273
+        if (!$interval > 0) {
274 274
             $interval = 1;
275 275
         }
276 276
 
277
-        return apply_filters( 'wpinv_item_recurring_interval', $interval, $this->ID );
277
+        return apply_filters('wpinv_item_recurring_interval', $interval, $this->ID);
278 278
 
279 279
     }
280 280
     
281 281
     public function get_recurring_limit() {
282
-        $limit = get_post_meta( $this->ID, '_wpinv_recurring_limit', true );
282
+        $limit = get_post_meta($this->ID, '_wpinv_recurring_limit', true);
283 283
 
284
-        return (int)apply_filters( 'wpinv_item_recurring_limit', $limit, $this->ID );
284
+        return (int)apply_filters('wpinv_item_recurring_limit', $limit, $this->ID);
285 285
 
286 286
     }
287 287
     
288 288
     public function has_free_trial() {
289
-        $free_trial = get_post_meta( $this->ID, '_wpinv_free_trial', true );
290
-        $free_trial = $this->is_recurring() && !empty( $free_trial ) ? true : false;
289
+        $free_trial = get_post_meta($this->ID, '_wpinv_free_trial', true);
290
+        $free_trial = $this->is_recurring() && !empty($free_trial) ? true : false;
291 291
 
292
-        return (bool)apply_filters( 'wpinv_item_has_free_trial', $free_trial, $this->ID );
292
+        return (bool)apply_filters('wpinv_item_has_free_trial', $free_trial, $this->ID);
293 293
 
294 294
     }
295 295
     
296
-    public function get_trial_period( $full = false ) {
297
-        $period = get_post_meta( $this->ID, '_wpinv_trial_period', true );
296
+    public function get_trial_period($full = false) {
297
+        $period = get_post_meta($this->ID, '_wpinv_trial_period', true);
298 298
         
299
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
299
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
300 300
             $period = 'D';
301 301
         }
302 302
         
303
-        if ( $full ) {
304
-            switch( $period ) {
303
+        if ($full) {
304
+            switch ($period) {
305 305
                 case 'D':
306 306
                     $period = 'day';
307 307
                 break;
@@ -317,55 +317,55 @@  discard block
 block discarded – undo
317 317
             }
318 318
         }
319 319
 
320
-        return apply_filters( 'wpinv_item_trial_period', $period, $full, $this->ID );
320
+        return apply_filters('wpinv_item_trial_period', $period, $full, $this->ID);
321 321
 
322 322
     }
323 323
     
324 324
     public function get_trial_interval() {
325
-        $interval = absint( get_post_meta( $this->ID, '_wpinv_trial_interval', true ) );
325
+        $interval = absint(get_post_meta($this->ID, '_wpinv_trial_interval', true));
326 326
         
327
-        if ( !$interval > 0 ) {
327
+        if (!$interval > 0) {
328 328
             $interval = 1;
329 329
         }
330 330
 
331
-        return apply_filters( 'wpinv_item_trial_interval', $interval, $this->ID );
331
+        return apply_filters('wpinv_item_trial_interval', $interval, $this->ID);
332 332
 
333 333
     }
334 334
 
335 335
     public function is_free() {
336 336
         $is_free = false;
337 337
         
338
-        $price = get_post_meta( $this->ID, '_wpinv_price', true );
338
+        $price = get_post_meta($this->ID, '_wpinv_price', true);
339 339
 
340
-        if ( (float)$price == 0 ) {
340
+        if ((float)$price == 0) {
341 341
             $is_free = true;
342 342
         }
343 343
 
344
-        return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID );
344
+        return (bool)apply_filters('wpinv_is_free_item', $is_free, $this->ID);
345 345
 
346 346
     }
347 347
     
348 348
     public function is_package() {
349 349
         $is_package = $this->get_type() == 'package' ? true : false;
350 350
 
351
-        return (bool) apply_filters( 'wpinv_is_package_item', $is_package, $this->ID );
351
+        return (bool)apply_filters('wpinv_is_package_item', $is_package, $this->ID);
352 352
 
353 353
     }
354 354
     
355 355
     public function is_editable() {
356
-        $editable = get_post_meta( $this->ID, '_wpinv_editable', true );
356
+        $editable = get_post_meta($this->ID, '_wpinv_editable', true);
357 357
 
358 358
         $is_editable = $editable === 0 || $editable === '0' ? false : true;
359 359
 
360
-        return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID );
360
+        return (bool)apply_filters('wpinv_item_is_editable', $is_editable, $this->ID);
361 361
     }
362 362
     
363
-    public function save_metas( $metas = array() ) {
364
-        if ( empty( $metas ) ) {
363
+    public function save_metas($metas = array()) {
364
+        if (empty($metas)) {
365 365
             return false;
366 366
         }
367 367
         
368
-        foreach ( $metas as $meta_key => $meta_value ) {
368
+        foreach ($metas as $meta_key => $meta_value) {
369 369
             $meta_key = strpos($meta_key, '_wpinv_') !== 0 ? '_wpinv_' . $meta_key : $meta_key;
370 370
             
371 371
             $this->update_meta($meta_key, $meta_value);
@@ -374,66 +374,66 @@  discard block
 block discarded – undo
374 374
         return true;
375 375
     }
376 376
 
377
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
378
-        if ( empty( $meta_key ) ) {
377
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
378
+        if (empty($meta_key)) {
379 379
             return false;
380 380
         }
381 381
         
382
-        $meta_value = apply_filters( 'wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID );
382
+        $meta_value = apply_filters('wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID);
383 383
 
384
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
384
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
385 385
     }
386 386
     
387
-    public function get_fees( $type = 'fee', $item_id = 0 ) {
387
+    public function get_fees($type = 'fee', $item_id = 0) {
388 388
         global $wpi_session;
389 389
         
390
-        $fees = $wpi_session->get( 'wpi_cart_fees' );
390
+        $fees = $wpi_session->get('wpi_cart_fees');
391 391
 
392
-        if ( ! wpinv_get_cart_contents() ) {
392
+        if (!wpinv_get_cart_contents()) {
393 393
             // We can only get item type fees when the cart is empty
394 394
             $type = 'custom';
395 395
         }
396 396
 
397
-        if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) {
398
-            foreach( $fees as $key => $fee ) {
399
-                if( ! empty( $fee['type'] ) && $type != $fee['type'] ) {
400
-                    unset( $fees[ $key ] );
397
+        if (!empty($fees) && !empty($type) && 'all' !== $type) {
398
+            foreach ($fees as $key => $fee) {
399
+                if (!empty($fee['type']) && $type != $fee['type']) {
400
+                    unset($fees[$key]);
401 401
                 }
402 402
             }
403 403
         }
404 404
 
405
-        if ( ! empty( $fees ) && ! empty( $item_id ) ) {
405
+        if (!empty($fees) && !empty($item_id)) {
406 406
             // Remove fees that don't belong to the specified Item
407
-            foreach ( $fees as $key => $fee ) {
408
-                if ( (int) $item_id !== (int)$fee['custom_id'] ) {
409
-                    unset( $fees[ $key ] );
407
+            foreach ($fees as $key => $fee) {
408
+                if ((int)$item_id !== (int)$fee['custom_id']) {
409
+                    unset($fees[$key]);
410 410
                 }
411 411
             }
412 412
         }
413 413
 
414
-        if ( ! empty( $fees ) ) {
414
+        if (!empty($fees)) {
415 415
             // Remove fees that belong to a specific item but are not in the cart
416
-            foreach( $fees as $key => $fee ) {
417
-                if( empty( $fee['custom_id'] ) ) {
416
+            foreach ($fees as $key => $fee) {
417
+                if (empty($fee['custom_id'])) {
418 418
                     continue;
419 419
                 }
420 420
 
421
-                if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) {
422
-                    unset( $fees[ $key ] );
421
+                if (!wpinv_item_in_cart($fee['custom_id'])) {
422
+                    unset($fees[$key]);
423 423
                 }
424 424
             }
425 425
         }
426 426
 
427
-        return ! empty( $fees ) ? $fees : array();
427
+        return !empty($fees) ? $fees : array();
428 428
     }
429 429
     
430 430
     public function can_purchase() {
431 431
         $can_purchase = true;
432 432
 
433
-        if ( !current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) {
433
+        if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') {
434 434
             $can_purchase = false;
435 435
         }
436 436
 
437
-        return (bool)apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );
437
+        return (bool)apply_filters('wpinv_can_purchase_item', $can_purchase, $this);
438 438
     }
439 439
 }
Please login to merge, or discard this patch.
includes/wpinv-general-functions.php 1 patch
Spacing   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -7,195 +7,195 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_is_checkout() {
15 15
     global $wp_query;
16 16
 
17
-    $is_object_set    = isset( $wp_query->queried_object );
18
-    $is_object_id_set = isset( $wp_query->queried_object_id );
19
-    $is_checkout      = is_page( wpinv_get_option( 'checkout_page' ) );
17
+    $is_object_set    = isset($wp_query->queried_object);
18
+    $is_object_id_set = isset($wp_query->queried_object_id);
19
+    $is_checkout      = is_page(wpinv_get_option('checkout_page'));
20 20
 
21
-    if ( !$is_object_set ) {
22
-        unset( $wp_query->queried_object );
21
+    if (!$is_object_set) {
22
+        unset($wp_query->queried_object);
23 23
     }
24 24
 
25
-    if ( !$is_object_id_set ) {
26
-        unset( $wp_query->queried_object_id );
25
+    if (!$is_object_id_set) {
26
+        unset($wp_query->queried_object_id);
27 27
     }
28 28
 
29
-    return apply_filters( 'wpinv_is_checkout', $is_checkout );
29
+    return apply_filters('wpinv_is_checkout', $is_checkout);
30 30
 }
31 31
 
32 32
 function wpinv_can_checkout() {
33 33
 	$can_checkout = true; // Always true for now
34 34
 
35
-	return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout );
35
+	return (bool)apply_filters('wpinv_can_checkout', $can_checkout);
36 36
 }
37 37
 
38 38
 function wpinv_get_success_page_uri() {
39
-	$page_id = wpinv_get_option( 'success_page', 0 );
40
-	$page_id = absint( $page_id );
39
+	$page_id = wpinv_get_option('success_page', 0);
40
+	$page_id = absint($page_id);
41 41
 
42
-	return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) );
42
+	return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id));
43 43
 }
44 44
 
45 45
 function wpinv_get_history_page_uri() {
46
-	$page_id = wpinv_get_option( 'invoice_history_page', 0 );
47
-	$page_id = absint( $page_id );
46
+	$page_id = wpinv_get_option('invoice_history_page', 0);
47
+	$page_id = absint($page_id);
48 48
 
49
-	return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) );
49
+	return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id));
50 50
 }
51 51
 
52 52
 function wpinv_is_success_page() {
53
-	$is_success_page = wpinv_get_option( 'success_page', false );
54
-	$is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false;
53
+	$is_success_page = wpinv_get_option('success_page', false);
54
+	$is_success_page = isset($is_success_page) ? is_page($is_success_page) : false;
55 55
 
56
-	return apply_filters( 'wpinv_is_success_page', $is_success_page );
56
+	return apply_filters('wpinv_is_success_page', $is_success_page);
57 57
 }
58 58
 
59 59
 function wpinv_is_invoice_history_page() {
60
-	$ret = wpinv_get_option( 'invoice_history_page', false );
61
-	$ret = $ret ? is_page( $ret ) : false;
62
-	return apply_filters( 'wpinv_is_invoice_history_page', $ret );
60
+	$ret = wpinv_get_option('invoice_history_page', false);
61
+	$ret = $ret ? is_page($ret) : false;
62
+	return apply_filters('wpinv_is_invoice_history_page', $ret);
63 63
 }
64 64
 
65
-function wpinv_send_to_success_page( $args = null ) {
65
+function wpinv_send_to_success_page($args = null) {
66 66
 	$redirect = wpinv_get_success_page_uri();
67 67
     
68
-    if ( !empty( $args ) ) {
68
+    if (!empty($args)) {
69 69
         // Check for backward compatibility
70
-        if ( is_string( $args ) )
71
-            $args = str_replace( '?', '', $args );
70
+        if (is_string($args))
71
+            $args = str_replace('?', '', $args);
72 72
 
73
-        $args = wp_parse_args( $args );
73
+        $args = wp_parse_args($args);
74 74
 
75
-        $redirect = add_query_arg( $args, $redirect );
75
+        $redirect = add_query_arg($args, $redirect);
76 76
     }
77 77
 
78
-    $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';
78
+    $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';
79 79
     
80
-    $redirect = apply_filters( 'wpinv_success_page_redirect', $redirect, $gateway, $args );
81
-    wp_redirect( $redirect );
80
+    $redirect = apply_filters('wpinv_success_page_redirect', $redirect, $gateway, $args);
81
+    wp_redirect($redirect);
82 82
     exit;
83 83
 }
84 84
 
85
-function wpinv_send_to_failed_page( $args = null ) {
85
+function wpinv_send_to_failed_page($args = null) {
86 86
 	$redirect = wpinv_get_failed_transaction_uri();
87 87
     
88
-    if ( !empty( $args ) ) {
88
+    if (!empty($args)) {
89 89
         // Check for backward compatibility
90
-        if ( is_string( $args ) )
91
-            $args = str_replace( '?', '', $args );
90
+        if (is_string($args))
91
+            $args = str_replace('?', '', $args);
92 92
 
93
-        $args = wp_parse_args( $args );
93
+        $args = wp_parse_args($args);
94 94
 
95
-        $redirect = add_query_arg( $args, $redirect );
95
+        $redirect = add_query_arg($args, $redirect);
96 96
     }
97 97
 
98
-    $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';
98
+    $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';
99 99
     
100
-    $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args );
101
-    wp_redirect( $redirect );
100
+    $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args);
101
+    wp_redirect($redirect);
102 102
     exit;
103 103
 }
104 104
 
105
-function wpinv_get_checkout_uri( $args = array() ) {
106
-	$uri = wpinv_get_option( 'checkout_page', false );
107
-	$uri = isset( $uri ) ? get_permalink( $uri ) : NULL;
105
+function wpinv_get_checkout_uri($args = array()) {
106
+	$uri = wpinv_get_option('checkout_page', false);
107
+	$uri = isset($uri) ? get_permalink($uri) : NULL;
108 108
 
109
-	if ( !empty( $args ) ) {
109
+	if (!empty($args)) {
110 110
 		// Check for backward compatibility
111
-		if ( is_string( $args ) )
112
-			$args = str_replace( '?', '', $args );
111
+		if (is_string($args))
112
+			$args = str_replace('?', '', $args);
113 113
 
114
-		$args = wp_parse_args( $args );
114
+		$args = wp_parse_args($args);
115 115
 
116
-		$uri = add_query_arg( $args, $uri );
116
+		$uri = add_query_arg($args, $uri);
117 117
 	}
118 118
 
119
-	$scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';
119
+	$scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin';
120 120
 
121
-	$ajax_url = admin_url( 'admin-ajax.php', $scheme );
121
+	$ajax_url = admin_url('admin-ajax.php', $scheme);
122 122
 
123
-	if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) {
124
-		$uri = preg_replace( '/^http:/', 'https:', $uri );
123
+	if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) {
124
+		$uri = preg_replace('/^http:/', 'https:', $uri);
125 125
 	}
126 126
 
127
-	return apply_filters( 'wpinv_get_checkout_uri', $uri );
127
+	return apply_filters('wpinv_get_checkout_uri', $uri);
128 128
 }
129 129
 
130
-function wpinv_send_back_to_checkout( $args = array() ) {
130
+function wpinv_send_back_to_checkout($args = array()) {
131 131
 	$redirect = wpinv_get_checkout_uri();
132 132
 
133
-	if ( ! empty( $args ) ) {
133
+	if (!empty($args)) {
134 134
 		// Check for backward compatibility
135
-		if ( is_string( $args ) )
136
-			$args = str_replace( '?', '', $args );
135
+		if (is_string($args))
136
+			$args = str_replace('?', '', $args);
137 137
 
138
-		$args = wp_parse_args( $args );
138
+		$args = wp_parse_args($args);
139 139
 
140
-		$redirect = add_query_arg( $args, $redirect );
140
+		$redirect = add_query_arg($args, $redirect);
141 141
 	}
142 142
 
143
-	wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) );
143
+	wp_redirect(apply_filters('wpinv_send_back_to_checkout', $redirect, $args));
144 144
 	exit;
145 145
 }
146 146
 
147
-function wpinv_get_success_page_url( $query_string = null ) {
148
-	$success_page = wpinv_get_option( 'success_page', 0 );
149
-	$success_page = get_permalink( $success_page );
147
+function wpinv_get_success_page_url($query_string = null) {
148
+	$success_page = wpinv_get_option('success_page', 0);
149
+	$success_page = get_permalink($success_page);
150 150
 
151
-	if ( $query_string )
151
+	if ($query_string)
152 152
 		$success_page .= $query_string;
153 153
 
154
-	return apply_filters( 'wpinv_success_page_url', $success_page );
154
+	return apply_filters('wpinv_success_page_url', $success_page);
155 155
 }
156 156
 
157
-function wpinv_get_failed_transaction_uri( $extras = false ) {
158
-	$uri = wpinv_get_option( 'failure_page', '' );
159
-	$uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url();
157
+function wpinv_get_failed_transaction_uri($extras = false) {
158
+	$uri = wpinv_get_option('failure_page', '');
159
+	$uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url();
160 160
 
161
-	if ( $extras )
161
+	if ($extras)
162 162
 		$uri .= $extras;
163 163
 
164
-	return apply_filters( 'wpinv_get_failed_transaction_uri', $uri );
164
+	return apply_filters('wpinv_get_failed_transaction_uri', $uri);
165 165
 }
166 166
 
167 167
 function wpinv_is_failed_transaction_page() {
168
-	$ret = wpinv_get_option( 'failure_page', false );
169
-	$ret = isset( $ret ) ? is_page( $ret ) : false;
168
+	$ret = wpinv_get_option('failure_page', false);
169
+	$ret = isset($ret) ? is_page($ret) : false;
170 170
 
171
-	return apply_filters( 'wpinv_is_failure_page', $ret );
171
+	return apply_filters('wpinv_is_failure_page', $ret);
172 172
 }
173 173
 
174
-function wpinv_transaction_query( $type = 'start' ) {
174
+function wpinv_transaction_query($type = 'start') {
175 175
     global $wpdb;
176 176
 
177 177
     $wpdb->hide_errors();
178 178
 
179
-    if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) {
180
-        define( 'WPINV_USE_TRANSACTIONS', true );
179
+    if (!defined('WPINV_USE_TRANSACTIONS')) {
180
+        define('WPINV_USE_TRANSACTIONS', true);
181 181
     }
182 182
 
183
-    if ( WPINV_USE_TRANSACTIONS ) {
184
-        switch ( $type ) {
183
+    if (WPINV_USE_TRANSACTIONS) {
184
+        switch ($type) {
185 185
             case 'commit' :
186
-                $wpdb->query( 'COMMIT' );
186
+                $wpdb->query('COMMIT');
187 187
                 break;
188 188
             case 'rollback' :
189
-                $wpdb->query( 'ROLLBACK' );
189
+                $wpdb->query('ROLLBACK');
190 190
                 break;
191 191
             default :
192
-                $wpdb->query( 'START TRANSACTION' );
192
+                $wpdb->query('START TRANSACTION');
193 193
             break;
194 194
         }
195 195
     }
196 196
 }
197 197
 
198
-function wpinv_create_invoice( $args = array(), $data = array(), $wp_error = false ) {
198
+function wpinv_create_invoice($args = array(), $data = array(), $wp_error = false) {
199 199
     $default_args = array(
200 200
         'status'        => '',
201 201
         'user_id'       => null,
@@ -205,63 +205,63 @@  discard block
 block discarded – undo
205 205
         'parent'        => 0
206 206
     );
207 207
 
208
-    $args           = wp_parse_args( $args, $default_args );
208
+    $args           = wp_parse_args($args, $default_args);
209 209
     $invoice_data   = array();
210 210
 
211
-    if ( $args['invoice_id'] > 0 ) {
212
-        $updating           = true;
211
+    if ($args['invoice_id'] > 0) {
212
+        $updating = true;
213 213
         $invoice_data['post_type']  = 'wpi_invoice';
214 214
         $invoice_data['ID']         = $args['invoice_id'];
215 215
     } else {
216 216
         $updating                       = false;
217 217
         $invoice_data['post_type']      = 'wpi_invoice';
218
-        $invoice_data['post_status']    = apply_filters( 'wpinv_default_invoice_status', 'pending' );
218
+        $invoice_data['post_status']    = apply_filters('wpinv_default_invoice_status', 'pending');
219 219
         $invoice_data['ping_status']    = 'closed';
220
-        $invoice_data['post_author']    = !empty( $args['user_id'] ) ? $args['user_id'] : get_current_user_id();
221
-        $invoice_data['post_title']     = wpinv_format_invoice_number( '0' );
222
-        $invoice_data['post_parent']    = absint( $args['parent'] );
223
-        if ( !empty( $args['created_date'] ) ) {
220
+        $invoice_data['post_author']    = !empty($args['user_id']) ? $args['user_id'] : get_current_user_id();
221
+        $invoice_data['post_title']     = wpinv_format_invoice_number('0');
222
+        $invoice_data['post_parent']    = absint($args['parent']);
223
+        if (!empty($args['created_date'])) {
224 224
             $invoice_data['post_date']      = $args['created_date'];
225
-            $invoice_data['post_date_gmt']  = get_gmt_from_date( $args['created_date'] );
225
+            $invoice_data['post_date_gmt']  = get_gmt_from_date($args['created_date']);
226 226
         }
227 227
     }
228 228
 
229
-    if ( $args['status'] ) {
230
-        if ( ! in_array( $args['status'], array_keys( wpinv_get_invoice_statuses() ) ) ) {
231
-            return new WP_Error( 'wpinv_invalid_invoice_status', wp_sprintf( __( 'Invalid invoice status: %s', 'invoicing' ), $args['status'] ) );
229
+    if ($args['status']) {
230
+        if (!in_array($args['status'], array_keys(wpinv_get_invoice_statuses()))) {
231
+            return new WP_Error('wpinv_invalid_invoice_status', wp_sprintf(__('Invalid invoice status: %s', 'invoicing'), $args['status']));
232 232
         }
233
-        $invoice_data['post_status']    = $args['status'];
233
+        $invoice_data['post_status'] = $args['status'];
234 234
     }
235 235
 
236
-    if ( ! is_null( $args['user_note'] ) ) {
237
-        $invoice_data['post_excerpt']   = $args['user_note'];
236
+    if (!is_null($args['user_note'])) {
237
+        $invoice_data['post_excerpt'] = $args['user_note'];
238 238
     }
239 239
 
240
-    if ( $updating ) {
241
-        $invoice_id = wp_update_post( $invoice_data, true );
240
+    if ($updating) {
241
+        $invoice_id = wp_update_post($invoice_data, true);
242 242
     } else {
243
-        $invoice_id = wp_insert_post( apply_filters( 'wpinv_new_invoice_data', $invoice_data ), true );
243
+        $invoice_id = wp_insert_post(apply_filters('wpinv_new_invoice_data', $invoice_data), true);
244 244
     }
245 245
 
246
-    if ( is_wp_error( $invoice_id ) ) {
246
+    if (is_wp_error($invoice_id)) {
247 247
         return $wp_error ? $invoice_id : 0;
248 248
     }
249 249
     
250
-    $invoice = wpinv_get_invoice( $invoice_id );
251
-
252
-    if ( !$updating ) {
253
-        update_post_meta( $invoice_id, '_wpinv_key', apply_filters( 'wpinv_generate_invoice_key', uniqid( 'wpinv_' ) ) );
254
-        update_post_meta( $invoice_id, '_wpinv_currency', wpinv_get_currency() );
255
-        update_post_meta( $invoice_id, '_wpinv_include_tax', get_option( 'wpinv_prices_include_tax' ) );
256
-        update_post_meta( $invoice_id, '_wpinv_user_ip', wpinv_get_ip() );
257
-        update_post_meta( $invoice_id, '_wpinv_user_agent', wpinv_get_user_agent() );
258
-        update_post_meta( $invoice_id, '_wpinv_created_via', sanitize_text_field( $args['created_via'] ) );
250
+    $invoice = wpinv_get_invoice($invoice_id);
251
+
252
+    if (!$updating) {
253
+        update_post_meta($invoice_id, '_wpinv_key', apply_filters('wpinv_generate_invoice_key', uniqid('wpinv_')));
254
+        update_post_meta($invoice_id, '_wpinv_currency', wpinv_get_currency());
255
+        update_post_meta($invoice_id, '_wpinv_include_tax', get_option('wpinv_prices_include_tax'));
256
+        update_post_meta($invoice_id, '_wpinv_user_ip', wpinv_get_ip());
257
+        update_post_meta($invoice_id, '_wpinv_user_agent', wpinv_get_user_agent());
258
+        update_post_meta($invoice_id, '_wpinv_created_via', sanitize_text_field($args['created_via']));
259 259
         
260 260
         // Add invoice note
261
-        $invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
261
+        $invoice->add_note(wp_sprintf(__('Invoice is created with status %s.', 'invoicing'), wpinv_status_nicename($invoice->status)));
262 262
     }
263 263
 
264
-    update_post_meta( $invoice_id, '_wpinv_version', WPINV_VERSION );
264
+    update_post_meta($invoice_id, '_wpinv_version', WPINV_VERSION);
265 265
 
266 266
     return $invoice;
267 267
 }
@@ -269,118 +269,118 @@  discard block
 block discarded – undo
269 269
 function wpinv_get_prefix() {
270 270
     $invoice_prefix = 'INV-';
271 271
     
272
-    return apply_filters( 'wpinv_get_prefix', $invoice_prefix );
272
+    return apply_filters('wpinv_get_prefix', $invoice_prefix);
273 273
 }
274 274
 
275 275
 function wpinv_get_business_logo() {
276
-    $business_logo = wpinv_get_option( 'logo' );
277
-    return apply_filters( 'wpinv_get_business_logo', $business_logo );
276
+    $business_logo = wpinv_get_option('logo');
277
+    return apply_filters('wpinv_get_business_logo', $business_logo);
278 278
 }
279 279
 
280 280
 function wpinv_get_business_name() {
281 281
     $business_name = wpinv_get_option('store_name');
282
-    return apply_filters( 'wpinv_get_business_name', $business_name );
282
+    return apply_filters('wpinv_get_business_name', $business_name);
283 283
 }
284 284
 
285 285
 function wpinv_get_blogname() {
286
-    return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
286
+    return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
287 287
 }
288 288
 
289 289
 function wpinv_get_admin_email() {
290
-    $admin_email = get_option( 'admin_email' );
291
-    return apply_filters( 'wpinv_admin_email', $admin_email );
290
+    $admin_email = get_option('admin_email');
291
+    return apply_filters('wpinv_admin_email', $admin_email);
292 292
 }
293 293
 
294 294
 function wpinv_get_business_website() {
295
-    $business_website = home_url( '/' );
296
-    return apply_filters( 'wpinv_get_business_website', $business_website );
295
+    $business_website = home_url('/');
296
+    return apply_filters('wpinv_get_business_website', $business_website);
297 297
 }
298 298
 
299
-function wpinv_get_terms_text( $invoice_id = 0 ) {
299
+function wpinv_get_terms_text($invoice_id = 0) {
300 300
     $terms_text = '';
301
-    return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id );
301
+    return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id);
302 302
 }
303 303
 
304 304
 function wpinv_get_business_footer() {
305
-    $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>';
306
-    $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link );
307
-    return apply_filters( 'wpinv_get_business_footer', $business_footer );
305
+    $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>';
306
+    $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link);
307
+    return apply_filters('wpinv_get_business_footer', $business_footer);
308 308
 }
309 309
 
310 310
 function wpinv_checkout_required_fields() {
311 311
     $required_fields = array();
312 312
     
313 313
     // Let payment gateways and other extensions determine if address fields should be required
314
-    $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() );
314
+    $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes());
315 315
     
316
-    if ( $require_billing_details ) {
316
+    if ($require_billing_details) {
317 317
         ///$required_fields['email'] = array(
318 318
                 ///'error_id' => 'invalid_email',
319 319
                 ///'error_message' => __( 'Please enter a valid email address', 'invoicing' )
320 320
             ///);
321 321
         $required_fields['first_name'] = array(
322 322
                 'error_id' => 'invalid_first_name',
323
-                'error_message' => __( 'Please enter your first name', 'invoicing' )
323
+                'error_message' => __('Please enter your first name', 'invoicing')
324 324
             );
325 325
         $required_fields['address'] = array(
326 326
                 'error_id' => 'invalid_address',
327
-                'error_message' => __( 'Please enter your address', 'invoicing' )
327
+                'error_message' => __('Please enter your address', 'invoicing')
328 328
             );
329 329
         $required_fields['city'] = array(
330 330
                 'error_id' => 'invalid_city',
331
-                'error_message' => __( 'Please enter your billing city', 'invoicing' )
331
+                'error_message' => __('Please enter your billing city', 'invoicing')
332 332
             );
333 333
         $required_fields['state'] = array(
334 334
                 'error_id' => 'invalid_state',
335
-                'error_message' => __( 'Please enter billing state / province', 'invoicing' )
335
+                'error_message' => __('Please enter billing state / province', 'invoicing')
336 336
             );
337 337
         $required_fields['country'] = array(
338 338
                 'error_id' => 'invalid_country',
339
-                'error_message' => __( 'Please select your billing country', 'invoicing' )
339
+                'error_message' => __('Please select your billing country', 'invoicing')
340 340
             );
341 341
     }
342 342
 
343
-    return apply_filters( 'wpinv_checkout_required_fields', $required_fields );
343
+    return apply_filters('wpinv_checkout_required_fields', $required_fields);
344 344
 }
345 345
 
346 346
 function wpinv_is_ssl_enforced() {
347
-    $ssl_enforced = wpinv_get_option( 'enforce_ssl', false );
348
-    return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced );
347
+    $ssl_enforced = wpinv_get_option('enforce_ssl', false);
348
+    return (bool)apply_filters('wpinv_is_ssl_enforced', $ssl_enforced);
349 349
 }
350 350
 
351
-function wpinv_user_can_print_invoice( $post ) {
351
+function wpinv_user_can_print_invoice($post) {
352 352
     $allow = false;
353 353
     
354
-    if ( !( $user_id = get_current_user_id() ) ) {
354
+    if (!($user_id = get_current_user_id())) {
355 355
         return $allow;
356 356
     }
357 357
     
358
-    if ( is_int( $post ) ) {
359
-        $post = get_post( $post );
358
+    if (is_int($post)) {
359
+        $post = get_post($post);
360 360
     }
361 361
     
362 362
     // Allow to owner.
363
-    if ( is_object( $post ) && !empty( $post->post_author ) && $post->post_author == $user_id ) {
363
+    if (is_object($post) && !empty($post->post_author) && $post->post_author == $user_id) {
364 364
         $allow = true;
365 365
     }
366 366
     
367 367
     // Allow to admin user.
368
-    if ( current_user_can( 'manage_options' ) ) {
368
+    if (current_user_can('manage_options')) {
369 369
         $allow = true;
370 370
     }
371 371
     
372
-    return apply_filters( 'wpinv_can_print_invoice', $allow, $post );
372
+    return apply_filters('wpinv_can_print_invoice', $allow, $post);
373 373
 }
374 374
 
375 375
 function wpinv_schedule_events() {
376 376
     // hourly, daily and twicedaily
377
-    if ( !wp_next_scheduled( 'wpinv_register_schedule_event_twicedaily' ) ) {
378
-        wp_schedule_event( current_time( 'timestamp' ), 'twicedaily', 'wpinv_register_schedule_event_twicedaily' );
377
+    if (!wp_next_scheduled('wpinv_register_schedule_event_twicedaily')) {
378
+        wp_schedule_event(current_time('timestamp'), 'twicedaily', 'wpinv_register_schedule_event_twicedaily');
379 379
     }
380 380
 }
381
-add_action( 'wp', 'wpinv_schedule_events' );
381
+add_action('wp', 'wpinv_schedule_events');
382 382
 
383 383
 function wpinv_schedule_event_twicedaily() {
384 384
     wpinv_email_payment_reminders();
385 385
 }
386
-add_action( 'wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily' );
387 386
\ No newline at end of file
387
+add_action('wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily');
388 388
\ No newline at end of file
Please login to merge, or discard this patch.