Passed
Pull Request — master (#438)
by Brian
04:42
created
includes/admin/class-getpaid-admin.php 1 patch
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -14,62 +14,62 @@  discard block
 block discarded – undo
14 14
 class GetPaid_Admin {
15 15
 
16 16
     /**
17
-	 * Local path to this plugins admin directory
18
-	 *
19
-	 * @var         string
20
-	 */
21
-	public $admin_path;
22
-
23
-	/**
24
-	 * Web path to this plugins admin directory
25
-	 *
26
-	 * @var         string
27
-	 */
17
+     * Local path to this plugins admin directory
18
+     *
19
+     * @var         string
20
+     */
21
+    public $admin_path;
22
+
23
+    /**
24
+     * Web path to this plugins admin directory
25
+     *
26
+     * @var         string
27
+     */
28 28
     public $admin_url;
29 29
 
30 30
     /**
31
-	 * Class constructor.
32
-	 */
33
-	public function __construct(){
31
+     * Class constructor.
32
+     */
33
+    public function __construct(){
34 34
 
35 35
         $this->admin_path  = plugin_dir_path( __FILE__ );
36 36
         $this->admin_url   = plugins_url( '/', __FILE__ );
37 37
 
38 38
         if ( is_admin() ) {
39
-			$this->init_admin_hooks();
39
+            $this->init_admin_hooks();
40 40
         }
41 41
 
42 42
     }
43 43
 
44 44
     /**
45
-	 * Init action and filter hooks
46
-	 *
47
-	 */
48
-	private function init_admin_hooks() {
45
+     * Init action and filter hooks
46
+     *
47
+     */
48
+    private function init_admin_hooks() {
49 49
         add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
50 50
         add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
51 51
         add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
52 52
         add_action( 'admin_init', array( $this, 'activation_redirect') );
53 53
         add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
54
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
55
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
56
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
57
-		do_action( 'getpaid_init_admin_hooks', $this );
54
+        add_action( 'admin_notices', array( $this, 'show_notices' ) );
55
+        add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
56
+        add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
57
+        do_action( 'getpaid_init_admin_hooks', $this );
58 58
 
59 59
     }
60 60
 
61 61
     /**
62
-	 * Register admin scripts
63
-	 *
64
-	 */
65
-	public function enqeue_scripts() {
62
+     * Register admin scripts
63
+     *
64
+     */
65
+    public function enqeue_scripts() {
66 66
         global $current_screen, $pagenow;
67 67
 
68
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
69
-		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
68
+        $page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
69
+        $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
70 70
 
71 71
         if ( ! empty( $current_screen->post_type ) ) {
72
-			$page = $current_screen->post_type;
72
+            $page = $current_screen->post_type;
73 73
         }
74 74
 
75 75
         // General styles.
@@ -93,30 +93,30 @@  discard block
 block discarded – undo
93 93
         }
94 94
 
95 95
         // Payment form scripts.
96
-		if ( 'wpi_payment_form' == $page && $editing ) {
96
+        if ( 'wpi_payment_form' == $page && $editing ) {
97 97
             $this->load_payment_form_scripts();
98 98
         }
99 99
 
100 100
         if ( $page == 'wpinv-subscriptions' ) {
101
-			wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
102
-			wp_enqueue_script( 'wpinv-sub-admin-script' );
103
-		}
101
+            wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
102
+            wp_enqueue_script( 'wpinv-sub-admin-script' );
103
+        }
104 104
 
105
-		if ( $page == 'wpinv-reports' ) {
106
-			wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
107
-		}
105
+        if ( $page == 'wpinv-reports' ) {
106
+            wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
107
+        }
108 108
 
109
-		if ( $page == 'wpinv-subscriptions' ) {
110
-			wp_enqueue_script( 'postbox' );
111
-		}
109
+        if ( $page == 'wpinv-subscriptions' ) {
110
+            wp_enqueue_script( 'postbox' );
111
+        }
112 112
 
113 113
     }
114 114
 
115 115
     /**
116
-	 * Returns admin js translations.
117
-	 *
118
-	 */
119
-	protected function get_admin_i18() {
116
+     * Returns admin js translations.
117
+     *
118
+     */
119
+    protected function get_admin_i18() {
120 120
         global $post;
121 121
 
122 122
         $i18n = array(
@@ -152,50 +152,50 @@  discard block
 block discarded – undo
152 152
             'searching'                 => __( 'Searching', 'invoicing' ),
153 153
         );
154 154
 
155
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
155
+        if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
156 156
 
157
-			$invoice              = new WPInv_Invoice( $post );
158
-			$i18n['save_invoice'] = sprintf(
159
-				__( 'Save %s', 'invoicing' ),
160
-				ucfirst( $invoice->get_type() )
161
-			);
157
+            $invoice              = new WPInv_Invoice( $post );
158
+            $i18n['save_invoice'] = sprintf(
159
+                __( 'Save %s', 'invoicing' ),
160
+                ucfirst( $invoice->get_type() )
161
+            );
162 162
 
163
-			$i18n['invoice_description'] = sprintf(
164
-				__( '%s Description', 'invoicing' ),
165
-				ucfirst( $invoice->get_type() )
166
-			);
163
+            $i18n['invoice_description'] = sprintf(
164
+                __( '%s Description', 'invoicing' ),
165
+                ucfirst( $invoice->get_type() )
166
+            );
167 167
 
168
-		}
169
-		return $i18n;
168
+        }
169
+        return $i18n;
170 170
     }
171 171
 
172 172
     /**
173
-	 * Loads payment form js.
174
-	 *
175
-	 */
176
-	protected function load_payment_form_scripts() {
173
+     * Loads payment form js.
174
+     *
175
+     */
176
+    protected function load_payment_form_scripts() {
177 177
         global $post;
178 178
 
179 179
         wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
180
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
181
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
180
+        wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
181
+        wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
182 182
 
183
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
184
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
183
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
184
+        wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
185 185
 
186
-		wp_localize_script(
186
+        wp_localize_script(
187 187
             'wpinv-admin-payment-form-script',
188 188
             'wpinvPaymentFormAdmin',
189 189
             array(
190
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
191
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
192
-				'currency'      => wpinv_currency_symbol(),
193
-				'position'      => wpinv_currency_position(),
194
-				'decimals'      => (int) wpinv_decimals(),
195
-				'thousands_sep' => wpinv_thousands_separator(),
196
-				'decimals_sep'  => wpinv_decimal_separator(),
197
-				'form_items'    => gepaid_get_form_items( $post->ID ),
198
-				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
190
+                'elements'      => wpinv_get_data( 'payment-form-elements' ),
191
+                'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
192
+                'currency'      => wpinv_currency_symbol(),
193
+                'position'      => wpinv_currency_position(),
194
+                'decimals'      => (int) wpinv_decimals(),
195
+                'thousands_sep' => wpinv_thousands_separator(),
196
+                'decimals_sep'  => wpinv_decimal_separator(),
197
+                'form_items'    => gepaid_get_form_items( $post->ID ),
198
+                'is_default'    => $post->ID == wpinv_get_default_payment_form(),
199 199
             )
200 200
         );
201 201
 
@@ -204,20 +204,20 @@  discard block
 block discarded – undo
204 204
     }
205 205
 
206 206
     /**
207
-	 * Add our classes to admin pages.
207
+     * Add our classes to admin pages.
208 208
      *
209 209
      * @param string $classes
210 210
      * @return string
211
-	 *
212
-	 */
211
+     *
212
+     */
213 213
     public function admin_body_class( $classes ) {
214
-		global $pagenow, $post, $current_screen;
214
+        global $pagenow, $post, $current_screen;
215 215
 
216 216
 
217 217
         $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
218 218
 
219 219
         if ( ! empty( $current_screen->post_type ) ) {
220
-			$page = $current_screen->post_type;
220
+            $page = $current_screen->post_type;
221 221
         }
222 222
 
223 223
         if ( false !== stripos( $page, 'wpi' ) ) {
@@ -226,29 +226,29 @@  discard block
 block discarded – undo
226 226
 
227 227
         if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
228 228
             $classes .= ' wpinv-cpt wpinv';
229
-		}
229
+        }
230 230
 		
231
-		if ( getpaid_is_invoice_post_type( $page ) ) {
231
+        if ( getpaid_is_invoice_post_type( $page ) ) {
232 232
             $classes .= ' getpaid-is-invoice-cpt';
233 233
         }
234 234
 
235
-		return $classes;
235
+        return $classes;
236 236
     }
237 237
 
238 238
     /**
239
-	 * Maybe show the AyeCode Connect Notice.
240
-	 */
241
-	public function init_ayecode_connect_helper(){
239
+     * Maybe show the AyeCode Connect Notice.
240
+     */
241
+    public function init_ayecode_connect_helper(){
242 242
 
243 243
         new AyeCode_Connect_Helper(
244 244
             array(
245
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
246
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
247
-				'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
248
-				'connect_button'    => __("Connect Site","invoicing"),
249
-				'connecting_button'    => __("Connecting...","invoicing"),
250
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
251
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
245
+                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
246
+                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
247
+                'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
248
+                'connect_button'    => __("Connect Site","invoicing"),
249
+                'connecting_button'    => __("Connecting...","invoicing"),
250
+                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
251
+                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
252 252
             ),
253 253
             array( 'wpi-addons' )
254 254
         );
@@ -260,21 +260,21 @@  discard block
 block discarded – undo
260 260
      */
261 261
     public function activation_redirect() {
262 262
 
263
-		// Bail if no activation redirect.
264
-		if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) {
265
-			return;
266
-		}
263
+        // Bail if no activation redirect.
264
+        if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) {
265
+            return;
266
+        }
267 267
 
268
-		// Delete the redirect transient.
269
-		delete_transient( '_wpinv_activation_redirect' );
268
+        // Delete the redirect transient.
269
+        delete_transient( '_wpinv_activation_redirect' );
270 270
 
271
-		// Bail if activating from network, or bulk
272
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
273
-			return;
274
-		}
271
+        // Bail if activating from network, or bulk
272
+        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
273
+            return;
274
+        }
275 275
 
276
-		wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
277
-		exit;
276
+        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
277
+        exit;
278 278
     }
279 279
 
280 280
     /**
@@ -289,150 +289,150 @@  discard block
 block discarded – undo
289 289
 
290 290
     }
291 291
 
292
-	/**
292
+    /**
293 293
      * Sends a payment reminder to a customer.
294
-	 * 
295
-	 * @param array $args
294
+     * 
295
+     * @param array $args
296 296
      */
297 297
     public function send_customer_invoice( $args ) {
298
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
298
+        $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
299 299
 
300
-		if ( $sent ) {
301
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
302
-		} else {
303
-			$this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
304
-		}
300
+        if ( $sent ) {
301
+            $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
302
+        } else {
303
+            $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
304
+        }
305 305
 
306
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
307
-		exit;
308
-	}
306
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
307
+        exit;
308
+    }
309 309
 
310
-	/**
310
+    /**
311 311
      * Sends a payment reminder to a customer.
312
-	 * 
313
-	 * @param array $args
312
+     * 
313
+     * @param array $args
314 314
      */
315 315
     public function send_customer_payment_reminder( $args ) {
316
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
316
+        $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
317 317
 
318
-		if ( $sent ) {
319
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
320
-		} else {
321
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
322
-		}
318
+        if ( $sent ) {
319
+            $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
320
+        } else {
321
+            $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
322
+        }
323 323
 
324
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
325
-		exit;
326
-	}
324
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
325
+        exit;
326
+    }
327 327
 
328 328
     /**
329
-	 * Returns an array of admin notices.
330
-	 *
331
-	 * @since       1.0.19
329
+     * Returns an array of admin notices.
330
+     *
331
+     * @since       1.0.19
332 332
      * @return array
333
-	 */
334
-	public function get_notices() {
335
-		$notices = get_option( 'wpinv_admin_notices' );
333
+     */
334
+    public function get_notices() {
335
+        $notices = get_option( 'wpinv_admin_notices' );
336 336
         return is_array( $notices ) ? $notices : array();
337
-	}
338
-
339
-	/**
340
-	 * Clears all admin notices
341
-	 *
342
-	 * @access      public
343
-	 * @since       1.0.19
344
-	 */
345
-	public function clear_notices() {
346
-		delete_option( 'wpinv_admin_notices' );
347
-	}
348
-
349
-	/**
350
-	 * Saves a new admin notice
351
-	 *
352
-	 * @access      public
353
-	 * @since       1.0.19
354
-	 */
355
-	public function save_notice( $type, $message ) {
356
-		$notices = $this->get_notices();
357
-
358
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
359
-			$notices[ $type ] = array();
360
-		}
361
-
362
-		$notices[ $type ][] = $message;
363
-
364
-		update_option( 'wpinv_admin_notices', $notices );
365
-	}
366
-
367
-	/**
368
-	 * Displays a success notice
369
-	 *
370
-	 * @param       string $msg The message to qeue.
371
-	 * @access      public
372
-	 * @since       1.0.19
373
-	 */
374
-	public function show_success( $msg ) {
375
-		$this->save_notice( 'success', $msg );
376
-	}
377
-
378
-	/**
379
-	 * Displays a error notice
380
-	 *
381
-	 * @access      public
382
-	 * @param       string $msg The message to qeue.
383
-	 * @since       1.0.19
384
-	 */
385
-	public function show_error( $msg ) {
386
-		$this->save_notice( 'error', $msg );
387
-	}
388
-
389
-	/**
390
-	 * Displays a warning notice
391
-	 *
392
-	 * @access      public
393
-	 * @param       string $msg The message to qeue.
394
-	 * @since       1.0.19
395
-	 */
396
-	public function show_warning( $msg ) {
397
-		$this->save_notice( 'warning', $msg );
398
-	}
399
-
400
-	/**
401
-	 * Displays a info notice
402
-	 *
403
-	 * @access      public
404
-	 * @param       string $msg The message to qeue.
405
-	 * @since       1.0.19
406
-	 */
407
-	public function show_info( $msg ) {
408
-		$this->save_notice( 'info', $msg );
409
-	}
410
-
411
-	/**
412
-	 * Show notices
413
-	 *
414
-	 * @access      public
415
-	 * @since       1.0.19
416
-	 */
417
-	public function show_notices() {
337
+    }
338
+
339
+    /**
340
+     * Clears all admin notices
341
+     *
342
+     * @access      public
343
+     * @since       1.0.19
344
+     */
345
+    public function clear_notices() {
346
+        delete_option( 'wpinv_admin_notices' );
347
+    }
348
+
349
+    /**
350
+     * Saves a new admin notice
351
+     *
352
+     * @access      public
353
+     * @since       1.0.19
354
+     */
355
+    public function save_notice( $type, $message ) {
356
+        $notices = $this->get_notices();
357
+
358
+        if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
359
+            $notices[ $type ] = array();
360
+        }
361
+
362
+        $notices[ $type ][] = $message;
363
+
364
+        update_option( 'wpinv_admin_notices', $notices );
365
+    }
366
+
367
+    /**
368
+     * Displays a success notice
369
+     *
370
+     * @param       string $msg The message to qeue.
371
+     * @access      public
372
+     * @since       1.0.19
373
+     */
374
+    public function show_success( $msg ) {
375
+        $this->save_notice( 'success', $msg );
376
+    }
377
+
378
+    /**
379
+     * Displays a error notice
380
+     *
381
+     * @access      public
382
+     * @param       string $msg The message to qeue.
383
+     * @since       1.0.19
384
+     */
385
+    public function show_error( $msg ) {
386
+        $this->save_notice( 'error', $msg );
387
+    }
388
+
389
+    /**
390
+     * Displays a warning notice
391
+     *
392
+     * @access      public
393
+     * @param       string $msg The message to qeue.
394
+     * @since       1.0.19
395
+     */
396
+    public function show_warning( $msg ) {
397
+        $this->save_notice( 'warning', $msg );
398
+    }
399
+
400
+    /**
401
+     * Displays a info notice
402
+     *
403
+     * @access      public
404
+     * @param       string $msg The message to qeue.
405
+     * @since       1.0.19
406
+     */
407
+    public function show_info( $msg ) {
408
+        $this->save_notice( 'info', $msg );
409
+    }
410
+
411
+    /**
412
+     * Show notices
413
+     *
414
+     * @access      public
415
+     * @since       1.0.19
416
+     */
417
+    public function show_notices() {
418 418
 
419 419
         $notices = $this->get_notices();
420 420
         $this->clear_notices();
421 421
 
422
-		foreach ( $notices as $type => $messages ) {
422
+        foreach ( $notices as $type => $messages ) {
423 423
 
424
-			if ( ! is_array( $messages ) ) {
425
-				continue;
426
-			}
424
+            if ( ! is_array( $messages ) ) {
425
+                continue;
426
+            }
427 427
 
428 428
             $type  = sanitize_key( $type );
429
-			foreach ( $messages as $message ) {
429
+            foreach ( $messages as $message ) {
430 430
                 $message = wp_kses_post( $message );
431
-				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
431
+                echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
432 432
             }
433 433
 
434 434
         }
435 435
 
436
-	}
436
+    }
437 437
 
438 438
 }
Please login to merge, or discard this patch.
includes/data/item-schema.php 1 patch
Indentation   +228 added lines, -228 removed lines patch added patch discarded remove patch
@@ -13,233 +13,233 @@
 block discarded – undo
13 13
 
14 14
 return array(
15 15
 
16
-	'id'              => array(
17
-		'description' => __( 'Unique identifier for the item.', 'invoicing' ),
18
-		'type'        => 'integer',
19
-		'context'     => array( 'view', 'edit', 'embed' ),
20
-		'readonly'    => true,
21
-	),
22
-
23
-	'parent_id'       => array(
24
-		'description' => __( 'Parent item ID.', 'invoicing' ),
25
-		'type'        => 'integer',
26
-		'context'     => array( 'view', 'edit', 'embed' ),
27
-		'default'     => 0,
28
-	),
29
-
30
-	'status'          => array(
31
-		'description' => __( 'A named status for the item.', 'invoicing' ),
32
-		'type'        => 'string',
33
-		'enum'        => array( 'draft', 'pending', 'publish' ),
34
-		'context'     => array( 'view', 'edit', 'embed' ),
35
-		'default'     => 'draft',
36
-	),
37
-
38
-	'version'         => array(
39
-		'description' => __( 'Plugin version when the item was created.', 'invoicing' ),
40
-		'type'        => 'string',
41
-		'context'     => array( 'view', 'edit' ),
42
-		'readonly'    => true,
43
-	),
44
-
45
-	'date_created'    => array(
46
-		'description' => __( "The date the item was created, in the site's timezone.", 'invoicing' ),
47
-		'type'        => 'string',
48
-		'context'     => array( 'view', 'edit', 'embed' ),
49
-	),
50
-
51
-	'date_created_gmt'    => array(
52
-		'description' => __( 'The GMT date the item was created.', 'invoicing' ),
53
-		'type'        => 'string',
54
-		'context'     => array( 'view', 'edit', 'embed' ),
55
-		'readonly'    => true,
56
-	),
57
-
58
-	'date_modified'   => array(
59
-		'description' => __( "The date the item was last modified, in the site's timezone.", 'invoicing' ),
60
-		'type'        => 'string',
61
-		'context'     => array( 'view', 'edit', 'embed' ),
62
-		'readonly'    => true,
63
-	),
64
-
65
-	'date_modified_gmt'    => array(
66
-		'description' => __( 'The GMT date the item was last modified.', 'invoicing' ),
67
-		'type'        => 'string',
68
-		'context'     => array( 'view', 'edit', 'embed' ),
69
-		'readonly'    => true,
70
-	),
71
-
72
-	'name'			  => array(
73
-		'description' => __( "The item's name.", 'invoicing' ),
74
-		'type'        => 'string',
75
-		'context'     => array( 'view', 'edit', 'embed' ),
76
-		'required'    => true,
77
-	),
78
-
79
-	'description'     => array(
80
-		'description' => __( "The item's description.", 'invoicing' ),
81
-		'type'        => 'string',
82
-		'context'     => array( 'view', 'edit', 'embed' ),
83
-	),
84
-
85
-	'owner'           => array(
86
-		'description' => __( 'The owner of the item (user id).', 'invoicing' ),
87
-		'type'        => 'integer',
88
-		'context'     => array( 'view', 'edit', 'embed' ),
89
-	),
90
-
91
-	'price'           => array(
92
-		'description' => __( 'The price of the item.', 'invoicing' ),
93
-		'type'        => 'number',
94
-		'context'     => array( 'view', 'edit', 'embed' ),
95
-		'required'    => true,
96
-	),
97
-
98
-	'the_price'       => array(
99
-		'description' => __( 'The formatted price of the item.', 'invoicing' ),
100
-		'type'        => 'string',
101
-		'context'     => array( 'view', 'edit', 'embed' ),
102
-		'readonly'    => true,
103
-	),
104
-
105
-	'type'       => array(
106
-		'description' => __( 'The item type.', 'invoicing' ),
107
-		'type'        => 'string',
108
-		'enum'        => wpinv_item_types(),
109
-		'default'     => 'custom',
110
-		'context'     => array( 'view', 'edit', 'embed' ),
111
-	),
112
-
113
-	'vat_rule'       => array(
114
-		'description' => __( 'VAT rule applied to the item.', 'invoicing' ),
115
-		'type'        => 'string',
116
-		'enum'        => array_keys( getpaid_tax()->get_rules() ),
117
-		'context'     => array( 'view', 'edit', 'embed' ),
118
-	),
119
-
120
-	'vat_class'       => array(
121
-		'description' => __( 'VAT class for the item.', 'invoicing' ),
122
-		'type'        => 'string',
123
-		'context'     => array( 'view', 'edit', 'embed' ),
124
-		'enum'        => array_keys( getpaid_tax()->get_vat_groups() ),
125
-	),
126
-
127
-	'custom_id'       => array(
128
-		'description' => __( 'Custom id for the item.', 'invoicing' ),
129
-		'type'        => 'string',
130
-		'context'     => array( 'view', 'edit', 'embed' ),
131
-	),
16
+    'id'              => array(
17
+        'description' => __( 'Unique identifier for the item.', 'invoicing' ),
18
+        'type'        => 'integer',
19
+        'context'     => array( 'view', 'edit', 'embed' ),
20
+        'readonly'    => true,
21
+    ),
22
+
23
+    'parent_id'       => array(
24
+        'description' => __( 'Parent item ID.', 'invoicing' ),
25
+        'type'        => 'integer',
26
+        'context'     => array( 'view', 'edit', 'embed' ),
27
+        'default'     => 0,
28
+    ),
29
+
30
+    'status'          => array(
31
+        'description' => __( 'A named status for the item.', 'invoicing' ),
32
+        'type'        => 'string',
33
+        'enum'        => array( 'draft', 'pending', 'publish' ),
34
+        'context'     => array( 'view', 'edit', 'embed' ),
35
+        'default'     => 'draft',
36
+    ),
37
+
38
+    'version'         => array(
39
+        'description' => __( 'Plugin version when the item was created.', 'invoicing' ),
40
+        'type'        => 'string',
41
+        'context'     => array( 'view', 'edit' ),
42
+        'readonly'    => true,
43
+    ),
44
+
45
+    'date_created'    => array(
46
+        'description' => __( "The date the item was created, in the site's timezone.", 'invoicing' ),
47
+        'type'        => 'string',
48
+        'context'     => array( 'view', 'edit', 'embed' ),
49
+    ),
50
+
51
+    'date_created_gmt'    => array(
52
+        'description' => __( 'The GMT date the item was created.', 'invoicing' ),
53
+        'type'        => 'string',
54
+        'context'     => array( 'view', 'edit', 'embed' ),
55
+        'readonly'    => true,
56
+    ),
57
+
58
+    'date_modified'   => array(
59
+        'description' => __( "The date the item was last modified, in the site's timezone.", 'invoicing' ),
60
+        'type'        => 'string',
61
+        'context'     => array( 'view', 'edit', 'embed' ),
62
+        'readonly'    => true,
63
+    ),
64
+
65
+    'date_modified_gmt'    => array(
66
+        'description' => __( 'The GMT date the item was last modified.', 'invoicing' ),
67
+        'type'        => 'string',
68
+        'context'     => array( 'view', 'edit', 'embed' ),
69
+        'readonly'    => true,
70
+    ),
71
+
72
+    'name'			  => array(
73
+        'description' => __( "The item's name.", 'invoicing' ),
74
+        'type'        => 'string',
75
+        'context'     => array( 'view', 'edit', 'embed' ),
76
+        'required'    => true,
77
+    ),
78
+
79
+    'description'     => array(
80
+        'description' => __( "The item's description.", 'invoicing' ),
81
+        'type'        => 'string',
82
+        'context'     => array( 'view', 'edit', 'embed' ),
83
+    ),
84
+
85
+    'owner'           => array(
86
+        'description' => __( 'The owner of the item (user id).', 'invoicing' ),
87
+        'type'        => 'integer',
88
+        'context'     => array( 'view', 'edit', 'embed' ),
89
+    ),
90
+
91
+    'price'           => array(
92
+        'description' => __( 'The price of the item.', 'invoicing' ),
93
+        'type'        => 'number',
94
+        'context'     => array( 'view', 'edit', 'embed' ),
95
+        'required'    => true,
96
+    ),
97
+
98
+    'the_price'       => array(
99
+        'description' => __( 'The formatted price of the item.', 'invoicing' ),
100
+        'type'        => 'string',
101
+        'context'     => array( 'view', 'edit', 'embed' ),
102
+        'readonly'    => true,
103
+    ),
104
+
105
+    'type'       => array(
106
+        'description' => __( 'The item type.', 'invoicing' ),
107
+        'type'        => 'string',
108
+        'enum'        => wpinv_item_types(),
109
+        'default'     => 'custom',
110
+        'context'     => array( 'view', 'edit', 'embed' ),
111
+    ),
112
+
113
+    'vat_rule'       => array(
114
+        'description' => __( 'VAT rule applied to the item.', 'invoicing' ),
115
+        'type'        => 'string',
116
+        'enum'        => array_keys( getpaid_tax()->get_rules() ),
117
+        'context'     => array( 'view', 'edit', 'embed' ),
118
+    ),
119
+
120
+    'vat_class'       => array(
121
+        'description' => __( 'VAT class for the item.', 'invoicing' ),
122
+        'type'        => 'string',
123
+        'context'     => array( 'view', 'edit', 'embed' ),
124
+        'enum'        => array_keys( getpaid_tax()->get_vat_groups() ),
125
+    ),
126
+
127
+    'custom_id'       => array(
128
+        'description' => __( 'Custom id for the item.', 'invoicing' ),
129
+        'type'        => 'string',
130
+        'context'     => array( 'view', 'edit', 'embed' ),
131
+    ),
132 132
 	
133
-	'custom_name'       => array(
134
-		'description' => __( 'Custom name for the item.', 'invoicing' ),
135
-		'type'        => 'string',
136
-		'context'     => array( 'view', 'edit', 'embed' ),
137
-	),
138
-
139
-	'custom_singular_name'       => array(
140
-		'description' => __( 'Custom singular name for the item.', 'invoicing' ),
141
-		'type'        => 'string',
142
-		'context'     => array( 'view', 'edit', 'embed' ),
143
-	),
144
-
145
-	'is_dynamic_pricing'     => array(
146
-		'description' => __( 'Whether or not customers can enter their own prices when checking out.', 'invoicing' ),
147
-		'type'        => 'integer',
148
-		'enum'        => array( 0, 1 ),
149
-		'context'     => array( 'view', 'edit', 'embed' ),
150
-	),
151
-
152
-	'minimum_price'   => array(
153
-		'description' => __( 'For dynamic prices, this is the minimum price that a user can set.', 'invoicing' ),
154
-		'type'        => 'number',
155
-		'context'     => array( 'view', 'edit', 'embed' ),
156
-	),
157
-
158
-	'is_recurring'        => array(
159
-		'description' => __( 'Whether or not this is a subscription item.', 'invoicing' ),
160
-		'type'        => 'integer',
161
-		'enum'        => array( 0, 1 ),
162
-		'context'     => array( 'view', 'edit', 'embed' ),
163
-	),
164
-
165
-	'initial_price'   => array(
166
-		'description' => __( 'The initial price of the item.', 'invoicing' ),
167
-		'type'        => 'number',
168
-		'context'     => array( 'view', 'edit', 'embed' ),
169
-		'readonly'    => true,
170
-	),
171
-
172
-	'the_initial_price'       => array(
173
-		'description' => __( 'The formatted initial price of the item.', 'invoicing' ),
174
-		'type'        => 'string',
175
-		'context'     => array( 'view', 'edit', 'embed' ),
176
-		'readonly'    => true,
177
-	),
178
-
179
-	'recurring_price' => array(
180
-		'description' => __( 'The recurring price of the item.', 'invoicing' ),
181
-		'type'        => 'number',
182
-		'context'     => array( 'view', 'edit', 'embed' ),
183
-		'readonly'    => true,
184
-	),
185
-
186
-	'the_recurring_price'       => array(
187
-		'description' => __( 'The formatted recurring price of the item.', 'invoicing' ),
188
-		'type'        => 'string',
189
-		'context'     => array( 'view', 'edit', 'embed' ),
190
-		'readonly'    => true,
191
-	),
192
-
193
-	'recurring_period'        => array(
194
-		'description' => __( 'The recurring period for a recurring item.', 'invoicing' ),
195
-		'type'        => 'string',
196
-		'context'     => array( 'view', 'edit', 'embed' ),
197
-		'enum'        => array( 'D', 'W', 'M', 'Y' ),
198
-	),
199
-
200
-	'recurring_interval'        => array(
201
-		'description' => __( 'The recurring interval for a subscription item.', 'invoicing' ),
202
-		'type'        => 'integer',
203
-		'context'     => array( 'view', 'edit', 'embed' ),
204
-	),
205
-
206
-	'recurring_limit' => array(
207
-		'description' => __( 'The maximum number of renewals for a subscription item.', 'invoicing' ),
208
-		'type'        => 'integer',
209
-		'context'     => array( 'view', 'edit', 'embed' ),
210
-	),
211
-
212
-	'is_free_trial'   => array(
213
-		'description' => __( 'Whether the item has a free trial period.', 'invoicing' ),
214
-		'type'        => 'integer',
215
-		'enum'        => array( 0, 1 ),
216
-		'context'     => array( 'view', 'edit', 'embed' ),
217
-	),
218
-
219
-	'trial_period'    => array(
220
-		'description' => __( 'The trial period.', 'invoicing' ),
221
-		'type'        => 'string',
222
-		'context'     => array( 'view', 'edit', 'embed' ),
223
-		'enum'        => array( 'D', 'W', 'M', 'Y' ),
224
-	),
225
-
226
-	'trial_interval'  => array(
227
-		'description' => __( 'The trial interval.', 'invoicing' ),
228
-		'type'        => 'integer',
229
-		'context'     => array( 'view', 'edit', 'embed' ),
230
-	),
231
-
232
-	'first_renewal_date'       => array(
233
-		'description' => __( 'The first renewal date in case the item was to be bought today.', 'invoicing' ),
234
-		'type'        => 'string',
235
-		'context'     => array( 'view', 'edit', 'embed' ),
236
-		'readonly'    => true,
237
-	),
238
-
239
-	'edit_url'        => array(
240
-		'description' => __( 'The URL to edit an item.', 'invoicing' ),
241
-		'type'        => 'string',
242
-		'context'     => array( 'view', 'edit', 'embed' ),
243
-		'readonly'    => true,
244
-	),
133
+    'custom_name'       => array(
134
+        'description' => __( 'Custom name for the item.', 'invoicing' ),
135
+        'type'        => 'string',
136
+        'context'     => array( 'view', 'edit', 'embed' ),
137
+    ),
138
+
139
+    'custom_singular_name'       => array(
140
+        'description' => __( 'Custom singular name for the item.', 'invoicing' ),
141
+        'type'        => 'string',
142
+        'context'     => array( 'view', 'edit', 'embed' ),
143
+    ),
144
+
145
+    'is_dynamic_pricing'     => array(
146
+        'description' => __( 'Whether or not customers can enter their own prices when checking out.', 'invoicing' ),
147
+        'type'        => 'integer',
148
+        'enum'        => array( 0, 1 ),
149
+        'context'     => array( 'view', 'edit', 'embed' ),
150
+    ),
151
+
152
+    'minimum_price'   => array(
153
+        'description' => __( 'For dynamic prices, this is the minimum price that a user can set.', 'invoicing' ),
154
+        'type'        => 'number',
155
+        'context'     => array( 'view', 'edit', 'embed' ),
156
+    ),
157
+
158
+    'is_recurring'        => array(
159
+        'description' => __( 'Whether or not this is a subscription item.', 'invoicing' ),
160
+        'type'        => 'integer',
161
+        'enum'        => array( 0, 1 ),
162
+        'context'     => array( 'view', 'edit', 'embed' ),
163
+    ),
164
+
165
+    'initial_price'   => array(
166
+        'description' => __( 'The initial price of the item.', 'invoicing' ),
167
+        'type'        => 'number',
168
+        'context'     => array( 'view', 'edit', 'embed' ),
169
+        'readonly'    => true,
170
+    ),
171
+
172
+    'the_initial_price'       => array(
173
+        'description' => __( 'The formatted initial price of the item.', 'invoicing' ),
174
+        'type'        => 'string',
175
+        'context'     => array( 'view', 'edit', 'embed' ),
176
+        'readonly'    => true,
177
+    ),
178
+
179
+    'recurring_price' => array(
180
+        'description' => __( 'The recurring price of the item.', 'invoicing' ),
181
+        'type'        => 'number',
182
+        'context'     => array( 'view', 'edit', 'embed' ),
183
+        'readonly'    => true,
184
+    ),
185
+
186
+    'the_recurring_price'       => array(
187
+        'description' => __( 'The formatted recurring price of the item.', 'invoicing' ),
188
+        'type'        => 'string',
189
+        'context'     => array( 'view', 'edit', 'embed' ),
190
+        'readonly'    => true,
191
+    ),
192
+
193
+    'recurring_period'        => array(
194
+        'description' => __( 'The recurring period for a recurring item.', 'invoicing' ),
195
+        'type'        => 'string',
196
+        'context'     => array( 'view', 'edit', 'embed' ),
197
+        'enum'        => array( 'D', 'W', 'M', 'Y' ),
198
+    ),
199
+
200
+    'recurring_interval'        => array(
201
+        'description' => __( 'The recurring interval for a subscription item.', 'invoicing' ),
202
+        'type'        => 'integer',
203
+        'context'     => array( 'view', 'edit', 'embed' ),
204
+    ),
205
+
206
+    'recurring_limit' => array(
207
+        'description' => __( 'The maximum number of renewals for a subscription item.', 'invoicing' ),
208
+        'type'        => 'integer',
209
+        'context'     => array( 'view', 'edit', 'embed' ),
210
+    ),
211
+
212
+    'is_free_trial'   => array(
213
+        'description' => __( 'Whether the item has a free trial period.', 'invoicing' ),
214
+        'type'        => 'integer',
215
+        'enum'        => array( 0, 1 ),
216
+        'context'     => array( 'view', 'edit', 'embed' ),
217
+    ),
218
+
219
+    'trial_period'    => array(
220
+        'description' => __( 'The trial period.', 'invoicing' ),
221
+        'type'        => 'string',
222
+        'context'     => array( 'view', 'edit', 'embed' ),
223
+        'enum'        => array( 'D', 'W', 'M', 'Y' ),
224
+    ),
225
+
226
+    'trial_interval'  => array(
227
+        'description' => __( 'The trial interval.', 'invoicing' ),
228
+        'type'        => 'integer',
229
+        'context'     => array( 'view', 'edit', 'embed' ),
230
+    ),
231
+
232
+    'first_renewal_date'       => array(
233
+        'description' => __( 'The first renewal date in case the item was to be bought today.', 'invoicing' ),
234
+        'type'        => 'string',
235
+        'context'     => array( 'view', 'edit', 'embed' ),
236
+        'readonly'    => true,
237
+    ),
238
+
239
+    'edit_url'        => array(
240
+        'description' => __( 'The URL to edit an item.', 'invoicing' ),
241
+        'type'        => 'string',
242
+        'context'     => array( 'view', 'edit', 'embed' ),
243
+        'readonly'    => true,
244
+    ),
245 245
 );
Please login to merge, or discard this patch.
includes/admin/register-settings.php 1 patch
Indentation   +341 added lines, -341 removed lines patch added patch discarded remove patch
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
     $cb      = "wpinv_{$option['type']}_callback";
197 197
     $section = "wpinv_settings_{$tab}_$section";
198 198
 
199
-	if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) {
200
-		$tip   = esc_attr( $option['desc'] );
201
-		$name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
202
-		unset( $option['desc'] );
203
-	}
199
+    if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) {
200
+        $tip   = esc_attr( $option['desc'] );
201
+        $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
202
+        unset( $option['desc'] );
203
+    }
204 204
 
205 205
     // Loop through all tabs.
206 206
     add_settings_field(
@@ -279,10 +279,10 @@  discard block
 block discarded – undo
279 279
         }
280 280
 
281 281
         // General filter
282
-		$input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
282
+        $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
283 283
 
284
-		// Key specific filter.
285
-		$input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
284
+        // Key specific filter.
285
+        $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
286 286
     }
287 287
 
288 288
     // Loop through the whitelist and unset any that are empty for the tab being saved
@@ -427,333 +427,333 @@  discard block
 block discarded – undo
427 427
 }
428 428
 
429 429
 function wpinv_get_pages( $with_slug = false, $default_label = NULL ) {
430
-	$pages_options = array();
430
+    $pages_options = array();
431 431
 
432
-	if( $default_label !== NULL && $default_label !== false ) {
433
-		$pages_options = array( '' => $default_label ); // Blank option
434
-	}
432
+    if( $default_label !== NULL && $default_label !== false ) {
433
+        $pages_options = array( '' => $default_label ); // Blank option
434
+    }
435 435
 
436
-	$pages = get_pages();
437
-	if ( $pages ) {
438
-		foreach ( $pages as $page ) {
439
-			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
436
+    $pages = get_pages();
437
+    if ( $pages ) {
438
+        foreach ( $pages as $page ) {
439
+            $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
440 440
             $pages_options[ $page->ID ] = $title;
441
-		}
442
-	}
441
+        }
442
+    }
443 443
 
444
-	return $pages_options;
444
+    return $pages_options;
445 445
 }
446 446
 
447 447
 function wpinv_header_callback( $args ) {
448
-	if ( !empty( $args['desc'] ) ) {
448
+    if ( !empty( $args['desc'] ) ) {
449 449
         echo $args['desc'];
450 450
     }
451 451
 }
452 452
 
453 453
 function wpinv_hidden_callback( $args ) {
454
-	global $wpinv_options;
455
-
456
-	if ( isset( $args['set_value'] ) ) {
457
-		$value = $args['set_value'];
458
-	} elseif ( isset( $wpinv_options[ $args['id'] ] ) ) {
459
-		$value = $wpinv_options[ $args['id'] ];
460
-	} else {
461
-		$value = isset( $args['std'] ) ? $args['std'] : '';
462
-	}
463
-
464
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
465
-		$args['readonly'] = true;
466
-		$value = isset( $args['std'] ) ? $args['std'] : '';
467
-		$name  = '';
468
-	} else {
469
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
470
-	}
471
-
472
-	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
454
+    global $wpinv_options;
455
+
456
+    if ( isset( $args['set_value'] ) ) {
457
+        $value = $args['set_value'];
458
+    } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) {
459
+        $value = $wpinv_options[ $args['id'] ];
460
+    } else {
461
+        $value = isset( $args['std'] ) ? $args['std'] : '';
462
+    }
463
+
464
+    if ( isset( $args['faux'] ) && true === $args['faux'] ) {
465
+        $args['readonly'] = true;
466
+        $value = isset( $args['std'] ) ? $args['std'] : '';
467
+        $name  = '';
468
+    } else {
469
+        $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
470
+    }
471
+
472
+    $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
473 473
     
474
-	echo $html;
474
+    echo $html;
475 475
 }
476 476
 
477 477
 function wpinv_checkbox_callback( $args ) {
478
-	global $wpinv_options;
478
+    global $wpinv_options;
479 479
     
480 480
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
481 481
 
482
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
483
-		$name = '';
484
-	} else {
485
-		$name = 'name="wpinv_settings[' . $sanitize_id . ']"';
486
-	}
482
+    if ( isset( $args['faux'] ) && true === $args['faux'] ) {
483
+        $name = '';
484
+    } else {
485
+        $name = 'name="wpinv_settings[' . $sanitize_id . ']"';
486
+    }
487 487
 
488
-	$std     = isset( $args['std'] ) ? $args['std'] : 0;
489
-	$value   = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std;
490
-	$checked = checked( empty( $value ), false, false );
488
+    $std     = isset( $args['std'] ) ? $args['std'] : 0;
489
+    $value   = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std;
490
+    $checked = checked( empty( $value ), false, false );
491 491
 
492
-	$html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>';
493
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
492
+    $html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>';
493
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
494 494
 
495
-	echo $html;
495
+    echo $html;
496 496
 }
497 497
 
498 498
 function wpinv_multicheck_callback( $args ) {
499
-	global $wpinv_options;
499
+    global $wpinv_options;
500 500
 
501
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
502
-	$class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
501
+    $sanitize_id = wpinv_sanitize_key( $args['id'] );
502
+    $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
503 503
 
504
-	if ( ! empty( $args['options'] ) ) {
504
+    if ( ! empty( $args['options'] ) ) {
505 505
 
506
-		$std     = isset( $args['std'] ) ? $args['std'] : array();
507
-		$value   = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std;
506
+        $std     = isset( $args['std'] ) ? $args['std'] : array();
507
+        $value   = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std;
508 508
 
509
-		echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">';
509
+        echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">';
510 510
         foreach( $args['options'] as $key => $option ):
511
-			$sanitize_key = wpinv_sanitize_key( $key );
512
-			if ( in_array( $sanitize_key, $value ) ) { 
513
-				$enabled = $sanitize_key;
514
-			} else { 
515
-				$enabled = NULL; 
516
-			}
517
-			echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
518
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>';
519
-		endforeach;
520
-		echo '</div>';
521
-		echo '<p class="description">' . $args['desc'] . '</p>';
522
-	}
511
+            $sanitize_key = wpinv_sanitize_key( $key );
512
+            if ( in_array( $sanitize_key, $value ) ) { 
513
+                $enabled = $sanitize_key;
514
+            } else { 
515
+                $enabled = NULL; 
516
+            }
517
+            echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
518
+            echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>';
519
+        endforeach;
520
+        echo '</div>';
521
+        echo '<p class="description">' . $args['desc'] . '</p>';
522
+    }
523 523
 }
524 524
 
525 525
 function wpinv_payment_icons_callback( $args ) {
526
-	global $wpinv_options;
526
+    global $wpinv_options;
527 527
     
528 528
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
529 529
 
530
-	if ( ! empty( $args['options'] ) ) {
531
-		foreach( $args['options'] as $key => $option ) {
530
+    if ( ! empty( $args['options'] ) ) {
531
+        foreach( $args['options'] as $key => $option ) {
532 532
             $sanitize_key = wpinv_sanitize_key( $key );
533 533
             
534
-			if( isset( $wpinv_options[$args['id']][$key] ) ) {
535
-				$enabled = $option;
536
-			} else {
537
-				$enabled = NULL;
538
-			}
539
-
540
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
541
-
542
-				echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
543
-
544
-				if ( wpinv_string_is_image_url( $key ) ) {
545
-					echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
546
-				} else {
547
-					$card = strtolower( str_replace( ' ', '', $option ) );
548
-
549
-					if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
550
-						$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
551
-					} else {
552
-						$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
553
-						$content_dir = WP_CONTENT_DIR;
554
-
555
-						if ( function_exists( 'wp_normalize_path' ) ) {
556
-							// Replaces backslashes with forward slashes for Windows systems
557
-							$image = wp_normalize_path( $image );
558
-							$content_dir = wp_normalize_path( $content_dir );
559
-						}
560
-
561
-						$image = str_replace( $content_dir, content_url(), $image );
562
-					}
563
-
564
-					echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
565
-				}
566
-			echo $option . '</label>';
567
-		}
568
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
569
-	}
534
+            if( isset( $wpinv_options[$args['id']][$key] ) ) {
535
+                $enabled = $option;
536
+            } else {
537
+                $enabled = NULL;
538
+            }
539
+
540
+            echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
541
+
542
+                echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
543
+
544
+                if ( wpinv_string_is_image_url( $key ) ) {
545
+                    echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
546
+                } else {
547
+                    $card = strtolower( str_replace( ' ', '', $option ) );
548
+
549
+                    if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
550
+                        $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
551
+                    } else {
552
+                        $image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
553
+                        $content_dir = WP_CONTENT_DIR;
554
+
555
+                        if ( function_exists( 'wp_normalize_path' ) ) {
556
+                            // Replaces backslashes with forward slashes for Windows systems
557
+                            $image = wp_normalize_path( $image );
558
+                            $content_dir = wp_normalize_path( $content_dir );
559
+                        }
560
+
561
+                        $image = str_replace( $content_dir, content_url(), $image );
562
+                    }
563
+
564
+                    echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
565
+                }
566
+            echo $option . '</label>';
567
+        }
568
+        echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
569
+    }
570 570
 }
571 571
 
572 572
 function wpinv_radio_callback( $args ) {
573
-	global $wpinv_options;
573
+    global $wpinv_options;
574 574
     
575 575
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
576 576
     
577 577
     foreach ( $args['options'] as $key => $option ) :
578
-		$sanitize_key = wpinv_sanitize_key( $key );
578
+        $sanitize_key = wpinv_sanitize_key( $key );
579 579
         
580 580
         $checked = false;
581 581
 
582
-		if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key )
583
-			$checked = true;
584
-		elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) )
585
-			$checked = true;
582
+        if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key )
583
+            $checked = true;
584
+        elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) )
585
+            $checked = true;
586 586
 
587
-		echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/>&nbsp;';
588
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>';
589
-	endforeach;
587
+        echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/>&nbsp;';
588
+        echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>';
589
+    endforeach;
590 590
 
591
-	echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
591
+    echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
592 592
 }
593 593
 
594 594
 function wpinv_gateways_callback( $args ) {
595
-	global $wpinv_options;
595
+    global $wpinv_options;
596 596
     
597 597
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
598 598
 
599
-	foreach ( $args['options'] as $key => $option ) :
600
-		$sanitize_key = wpinv_sanitize_key( $key );
599
+    foreach ( $args['options'] as $key => $option ) :
600
+        $sanitize_key = wpinv_sanitize_key( $key );
601 601
         
602 602
         if ( isset( $wpinv_options['gateways'][ $key ] ) )
603
-			$enabled = '1';
604
-		else
605
-			$enabled = null;
603
+            $enabled = '1';
604
+        else
605
+            $enabled = null;
606 606
 
607
-		echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/>&nbsp;';
608
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>';
609
-	endforeach;
607
+        echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/>&nbsp;';
608
+        echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>';
609
+    endforeach;
610 610
 }
611 611
 
612 612
 function wpinv_gateway_select_callback($args) {
613
-	global $wpinv_options;
613
+    global $wpinv_options;
614 614
     
615 615
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
616 616
     $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
617 617
 
618
-	echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >';
618
+    echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >';
619 619
 
620
-	foreach ( $args['options'] as $key => $option ) :
621
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
620
+    foreach ( $args['options'] as $key => $option ) :
621
+        if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
622 622
             $selected = selected( $key, $args['selected'], false );
623 623
         } else {
624 624
             $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : '';
625 625
         }
626
-		echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
627
-	endforeach;
626
+        echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
627
+    endforeach;
628 628
 
629
-	echo '</select>';
630
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
629
+    echo '</select>';
630
+    echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
631 631
 }
632 632
 
633 633
 function wpinv_text_callback( $args ) {
634
-	global $wpinv_options;
634
+    global $wpinv_options;
635 635
     
636 636
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
637 637
 
638
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
639
-		$value = $wpinv_options[ $args['id'] ];
640
-	} else {
641
-		$value = isset( $args['std'] ) ? $args['std'] : '';
642
-	}
643
-
644
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
645
-		$args['readonly'] = true;
646
-		$value = isset( $args['std'] ) ? $args['std'] : '';
647
-		$name  = '';
648
-	} else {
649
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
650
-	}
651
-	$class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
652
-
653
-	$readonly = $args['readonly'] === true ? ' readonly="readonly"' : '';
654
-	$size     = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
655
-	$html     = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>';
656
-	$html    .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
657
-
658
-	echo $html;
638
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
639
+        $value = $wpinv_options[ $args['id'] ];
640
+    } else {
641
+        $value = isset( $args['std'] ) ? $args['std'] : '';
642
+    }
643
+
644
+    if ( isset( $args['faux'] ) && true === $args['faux'] ) {
645
+        $args['readonly'] = true;
646
+        $value = isset( $args['std'] ) ? $args['std'] : '';
647
+        $name  = '';
648
+    } else {
649
+        $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
650
+    }
651
+    $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
652
+
653
+    $readonly = $args['readonly'] === true ? ' readonly="readonly"' : '';
654
+    $size     = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
655
+    $html     = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>';
656
+    $html    .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
657
+
658
+    echo $html;
659 659
 }
660 660
 
661 661
 function wpinv_number_callback( $args ) {
662
-	global $wpinv_options;
662
+    global $wpinv_options;
663 663
     
664 664
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
665 665
 
666
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
667
-		$value = $wpinv_options[ $args['id'] ];
668
-	} else {
669
-		$value = isset( $args['std'] ) ? $args['std'] : '';
670
-	}
671
-
672
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
673
-		$args['readonly'] = true;
674
-		$value = isset( $args['std'] ) ? $args['std'] : '';
675
-		$name  = '';
676
-	} else {
677
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
678
-	}
679
-
680
-	$max  = isset( $args['max'] ) ? $args['max'] : 999999;
681
-	$min  = isset( $args['min'] ) ? $args['min'] : 0;
682
-	$step = isset( $args['step'] ) ? $args['step'] : 1;
683
-	$class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
684
-
685
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
686
-	$html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>';
687
-	$html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
688
-
689
-	echo $html;
666
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
667
+        $value = $wpinv_options[ $args['id'] ];
668
+    } else {
669
+        $value = isset( $args['std'] ) ? $args['std'] : '';
670
+    }
671
+
672
+    if ( isset( $args['faux'] ) && true === $args['faux'] ) {
673
+        $args['readonly'] = true;
674
+        $value = isset( $args['std'] ) ? $args['std'] : '';
675
+        $name  = '';
676
+    } else {
677
+        $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
678
+    }
679
+
680
+    $max  = isset( $args['max'] ) ? $args['max'] : 999999;
681
+    $min  = isset( $args['min'] ) ? $args['min'] : 0;
682
+    $step = isset( $args['step'] ) ? $args['step'] : 1;
683
+    $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
684
+
685
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
686
+    $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>';
687
+    $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
688
+
689
+    echo $html;
690 690
 }
691 691
 
692 692
 function wpinv_textarea_callback( $args ) {
693
-	global $wpinv_options;
693
+    global $wpinv_options;
694 694
     
695 695
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
696 696
 
697
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
698
-		$value = $wpinv_options[ $args['id'] ];
699
-	} else {
700
-		$value = isset( $args['std'] ) ? $args['std'] : '';
701
-	}
697
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
698
+        $value = $wpinv_options[ $args['id'] ];
699
+    } else {
700
+        $value = isset( $args['std'] ) ? $args['std'] : '';
701
+    }
702 702
     
703 703
     $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
704 704
     $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
705 705
 
706
-	$html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
707
-	$html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
706
+    $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
707
+    $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
708 708
 
709
-	echo $html;
709
+    echo $html;
710 710
 }
711 711
 
712 712
 function wpinv_password_callback( $args ) {
713
-	global $wpinv_options;
713
+    global $wpinv_options;
714 714
     
715 715
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
716 716
 
717
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
718
-		$value = $wpinv_options[ $args['id'] ];
719
-	} else {
720
-		$value = isset( $args['std'] ) ? $args['std'] : '';
721
-	}
717
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
718
+        $value = $wpinv_options[ $args['id'] ];
719
+    } else {
720
+        $value = isset( $args['std'] ) ? $args['std'] : '';
721
+    }
722 722
 
723
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
724
-	$html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
725
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
723
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
724
+    $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
725
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
726 726
 
727
-	echo $html;
727
+    echo $html;
728 728
 }
729 729
 
730 730
 function wpinv_missing_callback($args) {
731
-	printf(
732
-		__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
733
-		'<strong>' . $args['id'] . '</strong>'
734
-	);
731
+    printf(
732
+        __( 'The callback function used for the %s setting is missing.', 'invoicing' ),
733
+        '<strong>' . $args['id'] . '</strong>'
734
+    );
735 735
 }
736 736
 
737 737
 function wpinv_select_callback($args) {
738
-	global $wpinv_options;
738
+    global $wpinv_options;
739 739
     
740 740
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
741 741
 
742
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
743
-		$value = $wpinv_options[ $args['id'] ];
744
-	} else {
745
-		$value = isset( $args['std'] ) ? $args['std'] : '';
746
-	}
742
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
743
+        $value = $wpinv_options[ $args['id'] ];
744
+    } else {
745
+        $value = isset( $args['std'] ) ? $args['std'] : '';
746
+    }
747 747
     
748 748
     if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
749 749
         $value = $args['selected'];
750 750
     }
751 751
 
752
-	if ( isset( $args['placeholder'] ) ) {
753
-		$placeholder = $args['placeholder'];
754
-	} else {
755
-		$placeholder = '';
756
-	}
752
+    if ( isset( $args['placeholder'] ) ) {
753
+        $placeholder = $args['placeholder'];
754
+    } else {
755
+        $placeholder = '';
756
+    }
757 757
     
758 758
     if( !empty( $args['onchange'] ) ) {
759 759
         $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"';
@@ -763,143 +763,143 @@  discard block
 block discarded – undo
763 763
 
764 764
     $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
765 765
 
766
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'"  name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />';
766
+    $html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'"  name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />';
767 767
 
768
-	foreach ( $args['options'] as $option => $name ) {
769
-		$selected = selected( $option, $value, false );
770
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
771
-	}
768
+    foreach ( $args['options'] as $option => $name ) {
769
+        $selected = selected( $option, $value, false );
770
+        $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
771
+    }
772 772
 
773
-	$html .= '</select>';
774
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
773
+    $html .= '</select>';
774
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
775 775
 
776
-	echo $html;
776
+    echo $html;
777 777
 }
778 778
 
779 779
 function wpinv_color_select_callback( $args ) {
780
-	global $wpinv_options;
780
+    global $wpinv_options;
781 781
     
782 782
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
783 783
 
784
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
785
-		$value = $wpinv_options[ $args['id'] ];
786
-	} else {
787
-		$value = isset( $args['std'] ) ? $args['std'] : '';
788
-	}
784
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
785
+        $value = $wpinv_options[ $args['id'] ];
786
+    } else {
787
+        $value = isset( $args['std'] ) ? $args['std'] : '';
788
+    }
789 789
 
790
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
790
+    $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
791 791
 
792
-	foreach ( $args['options'] as $option => $color ) {
793
-		$selected = selected( $option, $value, false );
794
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
795
-	}
792
+    foreach ( $args['options'] as $option => $color ) {
793
+        $selected = selected( $option, $value, false );
794
+        $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
795
+    }
796 796
 
797
-	$html .= '</select>';
798
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
797
+    $html .= '</select>';
798
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
799 799
 
800
-	echo $html;
800
+    echo $html;
801 801
 }
802 802
 
803 803
 function wpinv_rich_editor_callback( $args ) {
804
-	global $wpinv_options, $wp_version;
804
+    global $wpinv_options, $wp_version;
805 805
     
806 806
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
807 807
 
808
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
809
-		$value = $wpinv_options[ $args['id'] ];
808
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
809
+        $value = $wpinv_options[ $args['id'] ];
810 810
 
811
-		if( empty( $args['allow_blank'] ) && empty( $value ) ) {
812
-			$value = isset( $args['std'] ) ? $args['std'] : '';
813
-		}
814
-	} else {
815
-		$value = isset( $args['std'] ) ? $args['std'] : '';
816
-	}
811
+        if( empty( $args['allow_blank'] ) && empty( $value ) ) {
812
+            $value = isset( $args['std'] ) ? $args['std'] : '';
813
+        }
814
+    } else {
815
+        $value = isset( $args['std'] ) ? $args['std'] : '';
816
+    }
817 817
 
818
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
818
+    $rows = isset( $args['size'] ) ? $args['size'] : 20;
819 819
 
820
-	$html = '<div class="getpaid-settings-editor-input">';
821
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
822
-		ob_start();
823
-		wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) );
824
-		$html .= ob_get_clean();
825
-	} else {
826
-		$html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
827
-	}
820
+    $html = '<div class="getpaid-settings-editor-input">';
821
+    if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
822
+        ob_start();
823
+        wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) );
824
+        $html .= ob_get_clean();
825
+    } else {
826
+        $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
827
+    }
828 828
 
829
-	$html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
829
+    $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
830 830
 
831
-	echo $html;
831
+    echo $html;
832 832
 }
833 833
 
834 834
 function wpinv_upload_callback( $args ) {
835
-	global $wpinv_options;
835
+    global $wpinv_options;
836 836
     
837 837
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
838 838
 
839
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
840
-		$value = $wpinv_options[$args['id']];
841
-	} else {
842
-		$value = isset($args['std']) ? $args['std'] : '';
843
-	}
839
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
840
+        $value = $wpinv_options[$args['id']];
841
+    } else {
842
+        $value = isset($args['std']) ? $args['std'] : '';
843
+    }
844 844
 
845
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
846
-	$html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
847
-	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
848
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
845
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
846
+    $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
847
+    $html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
848
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
849 849
 
850
-	echo $html;
850
+    echo $html;
851 851
 }
852 852
 
853 853
 function wpinv_color_callback( $args ) {
854
-	global $wpinv_options;
854
+    global $wpinv_options;
855 855
     
856 856
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
857 857
 
858
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
859
-		$value = $wpinv_options[ $args['id'] ];
860
-	} else {
861
-		$value = isset( $args['std'] ) ? $args['std'] : '';
862
-	}
858
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
859
+        $value = $wpinv_options[ $args['id'] ];
860
+    } else {
861
+        $value = isset( $args['std'] ) ? $args['std'] : '';
862
+    }
863 863
 
864
-	$default = isset( $args['std'] ) ? $args['std'] : '';
864
+    $default = isset( $args['std'] ) ? $args['std'] : '';
865 865
 
866
-	$html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />';
867
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
866
+    $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />';
867
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
868 868
 
869
-	echo $html;
869
+    echo $html;
870 870
 }
871 871
 
872 872
 function wpinv_country_states_callback($args) {
873
-	global $wpinv_options;
873
+    global $wpinv_options;
874 874
     
875 875
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
876 876
 
877
-	if ( isset( $args['placeholder'] ) ) {
878
-		$placeholder = $args['placeholder'];
879
-	} else {
880
-		$placeholder = '';
881
-	}
877
+    if ( isset( $args['placeholder'] ) ) {
878
+        $placeholder = $args['placeholder'];
879
+    } else {
880
+        $placeholder = '';
881
+    }
882 882
 
883
-	$states = wpinv_get_country_states();
883
+    $states = wpinv_get_country_states();
884 884
 
885
-	$class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
886
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
885
+    $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
886
+    $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
887 887
 
888
-	foreach ( $states as $option => $name ) {
889
-		$selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : '';
890
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
891
-	}
888
+    foreach ( $states as $option => $name ) {
889
+        $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : '';
890
+        $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
891
+    }
892 892
 
893
-	$html .= '</select>';
894
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
893
+    $html .= '</select>';
894
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
895 895
 
896
-	echo $html;
896
+    echo $html;
897 897
 }
898 898
 
899 899
 function wpinv_tax_rates_callback($args) {
900
-	global $wpinv_options;
901
-	$rates = wpinv_get_tax_rates();
902
-	ob_start(); ?>
900
+    global $wpinv_options;
901
+    $rates = wpinv_get_tax_rates();
902
+    ob_start(); ?>
903 903
     </td><tr>
904 904
     <td colspan="2" class="wpinv_tax_tdbox">
905 905
 	<p><?php echo $args['desc']; ?></p>
@@ -923,40 +923,40 @@  discard block
 block discarded – undo
923 923
 			<tr>
924 924
 				<td class="wpinv_tax_country">
925 925
 					<?php
926
-					echo wpinv_html_select( array(
927
-						'options'          => wpinv_get_country_list( true ),
928
-						'name'             => 'tax_rates[' . $sanitized_key . '][country]',
926
+                    echo wpinv_html_select( array(
927
+                        'options'          => wpinv_get_country_list( true ),
928
+                        'name'             => 'tax_rates[' . $sanitized_key . '][country]',
929 929
                         'id'               => 'tax_rates[' . $sanitized_key . '][country]',
930
-						'selected'         => $rate['country'],
931
-						'show_option_all'  => false,
932
-						'show_option_none' => false,
933
-						'class'            => 'wpinv-tax-country wpi_select2',
934
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
935
-					) );
936
-					?>
930
+                        'selected'         => $rate['country'],
931
+                        'show_option_all'  => false,
932
+                        'show_option_none' => false,
933
+                        'class'            => 'wpinv-tax-country wpi_select2',
934
+                        'placeholder'      => __( 'Choose a country', 'invoicing' )
935
+                    ) );
936
+                    ?>
937 937
 				</td>
938 938
 				<td class="wpinv_tax_state">
939 939
 					<?php
940
-					$states = wpinv_get_country_states( $rate['country'] );
941
-					if( !empty( $states ) ) {
942
-						echo wpinv_html_select( array(
943
-							'options'          => array_merge( array( '' => '' ), $states ),
944
-							'name'             => 'tax_rates[' . $sanitized_key . '][state]',
940
+                    $states = wpinv_get_country_states( $rate['country'] );
941
+                    if( !empty( $states ) ) {
942
+                        echo wpinv_html_select( array(
943
+                            'options'          => array_merge( array( '' => '' ), $states ),
944
+                            'name'             => 'tax_rates[' . $sanitized_key . '][state]',
945 945
                             'id'               => 'tax_rates[' . $sanitized_key . '][state]',
946
-							'selected'         => $rate['state'],
947
-							'show_option_all'  => false,
948
-							'show_option_none' => false,
946
+                            'selected'         => $rate['state'],
947
+                            'show_option_all'  => false,
948
+                            'show_option_none' => false,
949 949
                             'class'            => 'wpi_select2',
950
-							'placeholder'      => __( 'Choose a state', 'invoicing' )
951
-						) );
952
-					} else {
953
-						echo wpinv_html_text( array(
954
-							'name'  => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'],
955
-							'value' => ! empty( $rate['state'] ) ? $rate['state'] : '',
950
+                            'placeholder'      => __( 'Choose a state', 'invoicing' )
951
+                        ) );
952
+                    } else {
953
+                        echo wpinv_html_text( array(
954
+                            'name'  => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'],
955
+                            'value' => ! empty( $rate['state'] ) ? $rate['state'] : '',
956 956
                             'id'    => 'tax_rates[' . $sanitized_key . '][state]',
957
-						) );
958
-					}
959
-					?>
957
+                        ) );
958
+                    }
959
+                    ?>
960 960
 				</td>
961 961
 				<td class="wpinv_tax_global">
962 962
 					<input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked( true, ! empty( $rate['global'] ) ); ?>/>
@@ -971,19 +971,19 @@  discard block
 block discarded – undo
971 971
 			<tr>
972 972
 				<td class="wpinv_tax_country">
973 973
 					<?php
974
-					echo wpinv_html_select( array(
975
-						'options'          => wpinv_get_country_list( true ),
976
-						'name'             => 'tax_rates[0][country]',
977
-						'show_option_all'  => false,
978
-						'show_option_none' => false,
979
-						'class'            => 'wpinv-tax-country wpi_select2',
980
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
981
-					) ); ?>
974
+                    echo wpinv_html_select( array(
975
+                        'options'          => wpinv_get_country_list( true ),
976
+                        'name'             => 'tax_rates[0][country]',
977
+                        'show_option_all'  => false,
978
+                        'show_option_none' => false,
979
+                        'class'            => 'wpinv-tax-country wpi_select2',
980
+                        'placeholder'      => __( 'Choose a country', 'invoicing' )
981
+                    ) ); ?>
982 982
 				</td>
983 983
 				<td class="wpinv_tax_state">
984 984
 					<?php echo wpinv_html_text( array(
985
-						'name' => 'tax_rates[0][state]'
986
-					) ); ?>
985
+                        'name' => 'tax_rates[0][state]'
986
+                    ) ); ?>
987 987
 				</td>
988 988
 				<td class="wpinv_tax_global">
989 989
 					<input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/>
@@ -998,7 +998,7 @@  discard block
 block discarded – undo
998 998
         <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span></td></tr></tfoot>
999 999
 	</table>
1000 1000
 	<?php
1001
-	echo ob_get_clean();
1001
+    echo ob_get_clean();
1002 1002
 }
1003 1003
 
1004 1004
 function wpinv_tools_callback($args) {
@@ -1026,15 +1026,15 @@  discard block
 block discarded – undo
1026 1026
 }
1027 1027
 
1028 1028
 function wpinv_descriptive_text_callback( $args ) {
1029
-	echo wp_kses_post( $args['desc'] );
1029
+    echo wp_kses_post( $args['desc'] );
1030 1030
 }
1031 1031
 
1032 1032
 function wpinv_hook_callback( $args ) {
1033
-	do_action( 'wpinv_' . $args['id'], $args );
1033
+    do_action( 'wpinv_' . $args['id'], $args );
1034 1034
 }
1035 1035
 
1036 1036
 function wpinv_set_settings_cap() {
1037
-	return wpinv_get_capability();
1037
+    return wpinv_get_capability();
1038 1038
 }
1039 1039
 add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
1040 1040
 
Please login to merge, or discard this patch.
includes/geolocation/class-getpaid-maxmind-geolocation.php 1 patch
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -16,164 +16,164 @@
 block discarded – undo
16 16
  */
17 17
 class GetPaid_MaxMind_Geolocation {
18 18
 
19
-	/**
20
-	 * The service responsible for interacting with the MaxMind database.
21
-	 *
22
-	 * @var GetPaid_MaxMind_Database_Service
23
-	 */
24
-	private $database_service;
25
-
26
-	/**
27
-	 * Initialize the integration.
28
-	 */
29
-	public function __construct() {
30
-
31
-		/**
32
-		 * Supports overriding the database service to be used.
33
-		 *
34
-		 * @since 1.0.19
35
-		 * @return mixed|null The geolocation database service.
36
-		 */
37
-		$this->database_service = apply_filters( 'getpaid_maxmind_geolocation_database_service', null );
38
-		if ( null === $this->database_service ) {
39
-			$this->database_service = new GetPaid_MaxMind_Database_Service( $this->get_database_prefix() );
40
-		}
41
-
42
-		// Bind to the scheduled updater action.
43
-		add_action( 'getpaid_update_geoip_databases', array( $this, 'update_database' ) );
44
-
45
-		// Bind to the geolocation filter for MaxMind database lookups.
46
-		add_filter( 'getpaid_get_geolocation', array( $this, 'get_geolocation' ), 10, 2 );
47
-
48
-		// Handle maxmind key updates.
49
-		add_filter( 'wpinv_settings_sanitize_maxmind_license_key', array( $this, 'handle_key_updates' ) );
50
-
51
-	}
52
-
53
-	/**
54
-	 * Get database service.
55
-	 *
56
-	 * @return GetPaid_MaxMind_Database_Service|null
57
-	 */
58
-	public function get_database_service() {
59
-		return $this->database_service;
60
-	}
61
-
62
-	/**
63
-	 * Checks to make sure that the license key is valid.
64
-	 *
65
-	 * @param string $license_key The new license key.
66
-	 * @return string
67
-	 */
68
-	public function handle_key_updates( $license_key ) {
69
-
70
-		// Trim whitespaces and strip slashes.
71
-		$license_key = trim( $license_key );
72
-
73
-		// Abort if the license key is empty or unchanged.
74
-		if ( empty( $license_key ) ) {
75
-			return $license_key;
76
-		}
77
-
78
-		// Abort if a database exists and the license key is unchaged.
79
-		if ( file_exists( $this->database_service->get_database_path() && $license_key == wpinv_get_option( 'maxmind_license_key' ) ) ) {
80
-			return $license_key;
81
-		}
82
-
83
-		// Check the license key by attempting to download the Geolocation database.
84
-		$tmp_database_path = $this->database_service->download_database( $license_key );
85
-		if ( is_wp_error( $tmp_database_path ) ) {
86
-			getpaid_admin()->show_error( $tmp_database_path->get_error_message() );
87
-			return $license_key;
88
-		}
89
-
90
-		$this->update_database( $tmp_database_path );
91
-
92
-	}
93
-
94
-	/**
95
-	 * Updates the database used for geolocation queries.
96
-	 *
97
-	 * @param string $tmp_database_path Temporary database path.
98
-	 */
99
-	public function update_database( $tmp_database_path = null ) {
100
-
101
-		// Allow us to easily interact with the filesystem.
102
-		require_once ABSPATH . 'wp-admin/includes/file.php';
103
-		WP_Filesystem();
104
-		global $wp_filesystem;
105
-
106
-		// Remove any existing archives to comply with the MaxMind TOS.
107
-		$target_database_path = $this->database_service->get_database_path();
108
-
109
-		// If there's no database path, we can't store the database.
110
-		if ( empty( $target_database_path ) ) {
111
-			return;
112
-		}
113
-
114
-		if ( $wp_filesystem->exists( $target_database_path ) ) {
115
-			$wp_filesystem->delete( $target_database_path );
116
-		}
117
-
118
-		// We can't download a database if there's no license key configured.
119
-		$license_key = wpinv_get_option( 'maxmind_license_key' );
120
-		if ( empty( $license_key ) ) {
121
-			return;
122
-		}
123
-
124
-		if ( empty( $tmp_database_path ) ) {
125
-			$tmp_database_path = $this->database_service->download_database( $license_key );
126
-		}
127
-
128
-		if ( is_wp_error( $tmp_database_path ) ) {
129
-			wpinv_error_log( $tmp_database_path->get_error_message() );
130
-			return;
131
-		}
132
-
133
-		// Move the new database into position.
134
-		$wp_filesystem->move( $tmp_database_path, $target_database_path, true );
135
-		$wp_filesystem->delete( dirname( $tmp_database_path ) );
136
-	}
137
-
138
-	/**
139
-	 * Performs a geolocation lookup against the MaxMind database for the given IP address.
140
-	 *
141
-	 * @param array  $data       Geolocation data.
142
-	 * @param string $ip_address The IP address to geolocate.
143
-	 * @return array Geolocation including country code, state, city and postcode based on an IP address.
144
-	 */
145
-	public function get_geolocation( $data, $ip_address ) {
146
-
147
-		if ( ! empty( $data['country'] ) || empty( $ip_address ) ) {
148
-			return $data;
149
-		}
150
-
151
-		$country_code = $this->database_service->get_iso_country_code_for_ip( $ip_address );
152
-
153
-		return array(
154
-			'country'  => $country_code,
155
-			'state'    => '',
156
-			'city'     => '',
157
-			'postcode' => '',
158
-		);
159
-
160
-	}
161
-
162
-	/**
163
-	 * Fetches the prefix for the MaxMind database file.
164
-	 *
165
-	 * @return string
166
-	 */
167
-	private function get_database_prefix() {
168
-
169
-		$prefix = get_option( 'wpinv_maxmind_database_prefix' );
170
-
171
-		if ( empty( $prefix ) ) {
172
-			$prefix = md5( uniqid( 'wpinv' ) );
173
-			update_option( 'wpinv_maxmind_database_prefix', $prefix );
174
-		}
175
-
176
-		return $prefix;
177
-	}
19
+    /**
20
+     * The service responsible for interacting with the MaxMind database.
21
+     *
22
+     * @var GetPaid_MaxMind_Database_Service
23
+     */
24
+    private $database_service;
25
+
26
+    /**
27
+     * Initialize the integration.
28
+     */
29
+    public function __construct() {
30
+
31
+        /**
32
+         * Supports overriding the database service to be used.
33
+         *
34
+         * @since 1.0.19
35
+         * @return mixed|null The geolocation database service.
36
+         */
37
+        $this->database_service = apply_filters( 'getpaid_maxmind_geolocation_database_service', null );
38
+        if ( null === $this->database_service ) {
39
+            $this->database_service = new GetPaid_MaxMind_Database_Service( $this->get_database_prefix() );
40
+        }
41
+
42
+        // Bind to the scheduled updater action.
43
+        add_action( 'getpaid_update_geoip_databases', array( $this, 'update_database' ) );
44
+
45
+        // Bind to the geolocation filter for MaxMind database lookups.
46
+        add_filter( 'getpaid_get_geolocation', array( $this, 'get_geolocation' ), 10, 2 );
47
+
48
+        // Handle maxmind key updates.
49
+        add_filter( 'wpinv_settings_sanitize_maxmind_license_key', array( $this, 'handle_key_updates' ) );
50
+
51
+    }
52
+
53
+    /**
54
+     * Get database service.
55
+     *
56
+     * @return GetPaid_MaxMind_Database_Service|null
57
+     */
58
+    public function get_database_service() {
59
+        return $this->database_service;
60
+    }
61
+
62
+    /**
63
+     * Checks to make sure that the license key is valid.
64
+     *
65
+     * @param string $license_key The new license key.
66
+     * @return string
67
+     */
68
+    public function handle_key_updates( $license_key ) {
69
+
70
+        // Trim whitespaces and strip slashes.
71
+        $license_key = trim( $license_key );
72
+
73
+        // Abort if the license key is empty or unchanged.
74
+        if ( empty( $license_key ) ) {
75
+            return $license_key;
76
+        }
77
+
78
+        // Abort if a database exists and the license key is unchaged.
79
+        if ( file_exists( $this->database_service->get_database_path() && $license_key == wpinv_get_option( 'maxmind_license_key' ) ) ) {
80
+            return $license_key;
81
+        }
82
+
83
+        // Check the license key by attempting to download the Geolocation database.
84
+        $tmp_database_path = $this->database_service->download_database( $license_key );
85
+        if ( is_wp_error( $tmp_database_path ) ) {
86
+            getpaid_admin()->show_error( $tmp_database_path->get_error_message() );
87
+            return $license_key;
88
+        }
89
+
90
+        $this->update_database( $tmp_database_path );
91
+
92
+    }
93
+
94
+    /**
95
+     * Updates the database used for geolocation queries.
96
+     *
97
+     * @param string $tmp_database_path Temporary database path.
98
+     */
99
+    public function update_database( $tmp_database_path = null ) {
100
+
101
+        // Allow us to easily interact with the filesystem.
102
+        require_once ABSPATH . 'wp-admin/includes/file.php';
103
+        WP_Filesystem();
104
+        global $wp_filesystem;
105
+
106
+        // Remove any existing archives to comply with the MaxMind TOS.
107
+        $target_database_path = $this->database_service->get_database_path();
108
+
109
+        // If there's no database path, we can't store the database.
110
+        if ( empty( $target_database_path ) ) {
111
+            return;
112
+        }
113
+
114
+        if ( $wp_filesystem->exists( $target_database_path ) ) {
115
+            $wp_filesystem->delete( $target_database_path );
116
+        }
117
+
118
+        // We can't download a database if there's no license key configured.
119
+        $license_key = wpinv_get_option( 'maxmind_license_key' );
120
+        if ( empty( $license_key ) ) {
121
+            return;
122
+        }
123
+
124
+        if ( empty( $tmp_database_path ) ) {
125
+            $tmp_database_path = $this->database_service->download_database( $license_key );
126
+        }
127
+
128
+        if ( is_wp_error( $tmp_database_path ) ) {
129
+            wpinv_error_log( $tmp_database_path->get_error_message() );
130
+            return;
131
+        }
132
+
133
+        // Move the new database into position.
134
+        $wp_filesystem->move( $tmp_database_path, $target_database_path, true );
135
+        $wp_filesystem->delete( dirname( $tmp_database_path ) );
136
+    }
137
+
138
+    /**
139
+     * Performs a geolocation lookup against the MaxMind database for the given IP address.
140
+     *
141
+     * @param array  $data       Geolocation data.
142
+     * @param string $ip_address The IP address to geolocate.
143
+     * @return array Geolocation including country code, state, city and postcode based on an IP address.
144
+     */
145
+    public function get_geolocation( $data, $ip_address ) {
146
+
147
+        if ( ! empty( $data['country'] ) || empty( $ip_address ) ) {
148
+            return $data;
149
+        }
150
+
151
+        $country_code = $this->database_service->get_iso_country_code_for_ip( $ip_address );
152
+
153
+        return array(
154
+            'country'  => $country_code,
155
+            'state'    => '',
156
+            'city'     => '',
157
+            'postcode' => '',
158
+        );
159
+
160
+    }
161
+
162
+    /**
163
+     * Fetches the prefix for the MaxMind database file.
164
+     *
165
+     * @return string
166
+     */
167
+    private function get_database_prefix() {
168
+
169
+        $prefix = get_option( 'wpinv_maxmind_database_prefix' );
170
+
171
+        if ( empty( $prefix ) ) {
172
+            $prefix = md5( uniqid( 'wpinv' ) );
173
+            update_option( 'wpinv_maxmind_database_prefix', $prefix );
174
+        }
175
+
176
+        return $prefix;
177
+    }
178 178
 
179 179
 }
Please login to merge, or discard this patch.
includes/geolocation/class-getpaid-geolocation.php 1 patch
Indentation   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -13,264 +13,264 @@
 block discarded – undo
13 13
  */
14 14
 class GetPaid_Geolocation {
15 15
 
16
-	/**
17
-	 * Holds the current user's IP Address.
18
-	 *
19
-	 * @var string
20
-	 */
21
-	public static $current_user_ip;
22
-
23
-	/**
24
-	 * API endpoints for looking up a user IP address.
25
-	 *
26
-	 * For example, in case a user is on localhost.
27
-	 *
28
-	 * @var array
29
-	 */
30
-	protected static $ip_lookup_apis = array(
31
-		'ipify'             => 'http://api.ipify.org/',
32
-		'ipecho'            => 'http://ipecho.net/plain',
33
-		'ident'             => 'http://ident.me',
34
-		'whatismyipaddress' => 'http://bot.whatismyipaddress.com',
35
-	);
36
-
37
-	/**
38
-	 * API endpoints for geolocating an IP address
39
-	 *
40
-	 * @var array
41
-	 */
42
-	protected static $geoip_apis = array(
43
-		'ipinfo.io'  => 'https://ipinfo.io/%s/json',
44
-		'ip-api.com' => 'http://ip-api.com/json/%s',
45
-	);
46
-
47
-	/**
48
-	 * Get current user IP Address.
49
-	 *
50
-	 * @return string
51
-	 */
52
-	public static function get_ip_address() {
53
-		return wpinv_get_ip();
54
-	}
55
-
56
-	/**
57
-	 * Get user IP Address using an external service.
58
-	 * This can be used as a fallback for users on localhost where
59
-	 * get_ip_address() will be a local IP and non-geolocatable.
60
-	 *
61
-	 * @return string
62
-	 */
63
-	public static function get_external_ip_address() {
64
-
65
-		$transient_name = 'external_ip_address_0.0.0.0';
66
-
67
-		if ( '' !== self::get_ip_address() ) {
68
-			$transient_name      = 'external_ip_address_' . self::get_ip_address();
69
-		}
70
-
71
-		// Try retrieving from cache.
72
-		$external_ip_address = get_transient( $transient_name );
73
-
74
-		if ( false === $external_ip_address ) {
75
-			$external_ip_address     = '0.0.0.0';
76
-			$ip_lookup_services      = apply_filters( 'getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis );
77
-			$ip_lookup_services_keys = array_keys( $ip_lookup_services );
78
-			shuffle( $ip_lookup_services_keys );
79
-
80
-			foreach ( $ip_lookup_services_keys as $service_name ) {
81
-				$service_endpoint = $ip_lookup_services[ $service_name ];
82
-				$response         = wp_safe_remote_get( $service_endpoint, array( 'timeout' => 2 ) );
83
-
84
-				if ( ! is_wp_error( $response ) && rest_is_ip_address( $response['body'] ) ) {
85
-					$external_ip_address = apply_filters( 'getpaid_geolocation_ip_lookup_api_response', wpinv_clean( $response['body'] ), $service_name );
86
-					break;
87
-				}
88
-
89
-			}
90
-
91
-			set_transient( $transient_name, $external_ip_address, WEEK_IN_SECONDS );
92
-		}
93
-
94
-		return $external_ip_address;
95
-	}
96
-
97
-	/**
98
-	 * Geolocate an IP address.
99
-	 *
100
-	 * @param  string $ip_address   IP Address.
101
-	 * @param  bool   $fallback     If true, fallbacks to alternative IP detection (can be slower).
102
-	 * @param  bool   $api_fallback If true, uses geolocation APIs if the database file doesn't exist (can be slower).
103
-	 * @return array
104
-	 */
105
-	public static function geolocate_ip( $ip_address = '', $fallback = false, $api_fallback = true ) {
106
-
107
-		if ( empty( $ip_address ) ) {
108
-			$ip_address = self::get_ip_address();
109
-		}
110
-
111
-		// Update the current user's IP Address.
112
-		self::$current_user_ip = $ip_address;
113
-
114
-		// Filter to allow custom geolocation of the IP address.
115
-		$country_code = apply_filters( 'getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback );
116
-
117
-		if ( false !== $country_code ) {
118
-
119
-			return array(
120
-				'country'  => $country_code,
121
-				'state'    => '',
122
-				'city'     => '',
123
-				'postcode' => '',
124
-			);
125
-
126
-		}
127
-
128
-		$country_code = self::get_country_code_from_headers();
129
-
130
-		/**
131
-		 * Get geolocation filter.
132
-		 *
133
-		 * @since 1.0.19
134
-		 * @param array  $geolocation Geolocation data, including country, state, city, and postcode.
135
-		 * @param string $ip_address  IP Address.
136
-		 */
137
-		$geolocation  = apply_filters(
138
-			'getpaid_get_geolocation',
139
-			array(
140
-				'country'  => $country_code,
141
-				'state'    => '',
142
-				'city'     => '',
143
-				'postcode' => '',
144
-			),
145
-			$ip_address
146
-		);
147
-
148
-		// If we still haven't found a country code, let's consider doing an API lookup.
149
-		if ( '' === $geolocation['country'] && $api_fallback ) {
150
-			$geolocation['country'] = self::geolocate_via_api( $ip_address );
151
-		}
152
-
153
-		// It's possible that we're in a local environment, in which case the geolocation needs to be done from the
154
-		// external address.
155
-		if ( '' === $geolocation['country'] && $fallback ) {
156
-			$external_ip_address = self::get_external_ip_address();
157
-
158
-			// Only bother with this if the external IP differs.
159
-			if ( '0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address ) {
160
-				return self::geolocate_ip( $external_ip_address, false, $api_fallback );
161
-			}
162
-
163
-		}
164
-
165
-		return array(
166
-			'country'  => $geolocation['country'],
167
-			'state'    => $geolocation['state'],
168
-			'city'     => $geolocation['city'],
169
-			'postcode' => $geolocation['postcode'],
170
-		);
171
-
172
-	}
173
-
174
-	/**
175
-	 * Fetches the country code from the request headers, if one is available.
176
-	 *
177
-	 * @since 1.0.19
178
-	 * @return string The country code pulled from the headers, or empty string if one was not found.
179
-	 */
180
-	protected static function get_country_code_from_headers() {
181
-		$country_code = '';
182
-
183
-		$headers = array(
184
-			'MM_COUNTRY_CODE',
185
-			'GEOIP_COUNTRY_CODE',
186
-			'HTTP_CF_IPCOUNTRY',
187
-			'HTTP_X_COUNTRY_CODE',
188
-		);
189
-
190
-		foreach ( $headers as $header ) {
191
-			if ( empty( $_SERVER[ $header ] ) ) {
192
-				continue;
193
-			}
194
-
195
-			$country_code = strtoupper( sanitize_text_field( wp_unslash( $_SERVER[ $header ] ) ) );
196
-			break;
197
-		}
198
-
199
-		return $country_code;
200
-	}
201
-
202
-	/**
203
-	 * Use APIs to Geolocate the user.
204
-	 *
205
-	 * Geolocation APIs can be added through the use of the getpaid_geolocation_geoip_apis filter.
206
-	 * Provide a name=>value pair for service-slug=>endpoint.
207
-	 *
208
-	 * If APIs are defined, one will be chosen at random to fulfil the request. After completing, the result
209
-	 * will be cached in a transient.
210
-	 *
211
-	 * @param  string $ip_address IP address.
212
-	 * @return string
213
-	 */
214
-	protected static function geolocate_via_api( $ip_address ) {
215
-
216
-		// Retrieve from cache...
217
-		$country_code = get_transient( 'geoip_' . $ip_address );
218
-
219
-		// If missing, retrieve from the API.
220
-		if ( false === $country_code ) {
221
-			$geoip_services = apply_filters( 'getpaid_geolocation_geoip_apis', self::$geoip_apis );
222
-
223
-			if ( empty( $geoip_services ) ) {
224
-				return '';
225
-			}
226
-
227
-			$geoip_services_keys = array_keys( $geoip_services );
228
-
229
-			shuffle( $geoip_services_keys );
230
-
231
-			foreach ( $geoip_services_keys as $service_name ) {
232
-
233
-				$service_endpoint = $geoip_services[ $service_name ];
234
-				$response         = wp_safe_remote_get( sprintf( $service_endpoint, $ip_address ), array( 'timeout' => 2 ) );
235
-				$country_code     = sanitize_text_field( strtoupper( self::handle_geolocation_response( $response, $service_name ) ) );
236
-
237
-				if ( ! empty( $country_code ) ) {
238
-					break;
239
-				}
240
-
241
-			}
242
-
243
-			set_transient( 'geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS );
244
-		}
245
-
246
-		return $country_code;
247
-	}
248
-
249
-	/**
250
-	 * Handles geolocation response
251
-	 *
252
-	 * @param  WP_Error|String $geolocation_response
253
-	 * @param  String $geolocation_service
254
-	 * @return string Country code
255
-	 */
256
-	protected static function handle_geolocation_response( $geolocation_response, $geolocation_service ) {
257
-
258
-		if ( is_wp_error( $geolocation_response ) || empty( $geolocation_response['body'] ) ) {
259
-			return '';
260
-		}
261
-
262
-		if ( $geolocation_service === 'ipinfo.io' ) {
263
-			$data = json_decode( $geolocation_response['body'] );
264
-			return empty( $data ) ? '' : $data->country;
265
-		}
266
-
267
-		if ( $geolocation_service === 'ip-api.com' ) {
268
-			$data = json_decode( $geolocation_response['body'] );
269
-			return empty( $data ) ? '' : $data->countryCode;
270
-		}
271
-
272
-		return apply_filters( 'getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body'] );
273
-
274
-	}
16
+    /**
17
+     * Holds the current user's IP Address.
18
+     *
19
+     * @var string
20
+     */
21
+    public static $current_user_ip;
22
+
23
+    /**
24
+     * API endpoints for looking up a user IP address.
25
+     *
26
+     * For example, in case a user is on localhost.
27
+     *
28
+     * @var array
29
+     */
30
+    protected static $ip_lookup_apis = array(
31
+        'ipify'             => 'http://api.ipify.org/',
32
+        'ipecho'            => 'http://ipecho.net/plain',
33
+        'ident'             => 'http://ident.me',
34
+        'whatismyipaddress' => 'http://bot.whatismyipaddress.com',
35
+    );
36
+
37
+    /**
38
+     * API endpoints for geolocating an IP address
39
+     *
40
+     * @var array
41
+     */
42
+    protected static $geoip_apis = array(
43
+        'ipinfo.io'  => 'https://ipinfo.io/%s/json',
44
+        'ip-api.com' => 'http://ip-api.com/json/%s',
45
+    );
46
+
47
+    /**
48
+     * Get current user IP Address.
49
+     *
50
+     * @return string
51
+     */
52
+    public static function get_ip_address() {
53
+        return wpinv_get_ip();
54
+    }
55
+
56
+    /**
57
+     * Get user IP Address using an external service.
58
+     * This can be used as a fallback for users on localhost where
59
+     * get_ip_address() will be a local IP and non-geolocatable.
60
+     *
61
+     * @return string
62
+     */
63
+    public static function get_external_ip_address() {
64
+
65
+        $transient_name = 'external_ip_address_0.0.0.0';
66
+
67
+        if ( '' !== self::get_ip_address() ) {
68
+            $transient_name      = 'external_ip_address_' . self::get_ip_address();
69
+        }
70
+
71
+        // Try retrieving from cache.
72
+        $external_ip_address = get_transient( $transient_name );
73
+
74
+        if ( false === $external_ip_address ) {
75
+            $external_ip_address     = '0.0.0.0';
76
+            $ip_lookup_services      = apply_filters( 'getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis );
77
+            $ip_lookup_services_keys = array_keys( $ip_lookup_services );
78
+            shuffle( $ip_lookup_services_keys );
79
+
80
+            foreach ( $ip_lookup_services_keys as $service_name ) {
81
+                $service_endpoint = $ip_lookup_services[ $service_name ];
82
+                $response         = wp_safe_remote_get( $service_endpoint, array( 'timeout' => 2 ) );
83
+
84
+                if ( ! is_wp_error( $response ) && rest_is_ip_address( $response['body'] ) ) {
85
+                    $external_ip_address = apply_filters( 'getpaid_geolocation_ip_lookup_api_response', wpinv_clean( $response['body'] ), $service_name );
86
+                    break;
87
+                }
88
+
89
+            }
90
+
91
+            set_transient( $transient_name, $external_ip_address, WEEK_IN_SECONDS );
92
+        }
93
+
94
+        return $external_ip_address;
95
+    }
96
+
97
+    /**
98
+     * Geolocate an IP address.
99
+     *
100
+     * @param  string $ip_address   IP Address.
101
+     * @param  bool   $fallback     If true, fallbacks to alternative IP detection (can be slower).
102
+     * @param  bool   $api_fallback If true, uses geolocation APIs if the database file doesn't exist (can be slower).
103
+     * @return array
104
+     */
105
+    public static function geolocate_ip( $ip_address = '', $fallback = false, $api_fallback = true ) {
106
+
107
+        if ( empty( $ip_address ) ) {
108
+            $ip_address = self::get_ip_address();
109
+        }
110
+
111
+        // Update the current user's IP Address.
112
+        self::$current_user_ip = $ip_address;
113
+
114
+        // Filter to allow custom geolocation of the IP address.
115
+        $country_code = apply_filters( 'getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback );
116
+
117
+        if ( false !== $country_code ) {
118
+
119
+            return array(
120
+                'country'  => $country_code,
121
+                'state'    => '',
122
+                'city'     => '',
123
+                'postcode' => '',
124
+            );
125
+
126
+        }
127
+
128
+        $country_code = self::get_country_code_from_headers();
129
+
130
+        /**
131
+         * Get geolocation filter.
132
+         *
133
+         * @since 1.0.19
134
+         * @param array  $geolocation Geolocation data, including country, state, city, and postcode.
135
+         * @param string $ip_address  IP Address.
136
+         */
137
+        $geolocation  = apply_filters(
138
+            'getpaid_get_geolocation',
139
+            array(
140
+                'country'  => $country_code,
141
+                'state'    => '',
142
+                'city'     => '',
143
+                'postcode' => '',
144
+            ),
145
+            $ip_address
146
+        );
147
+
148
+        // If we still haven't found a country code, let's consider doing an API lookup.
149
+        if ( '' === $geolocation['country'] && $api_fallback ) {
150
+            $geolocation['country'] = self::geolocate_via_api( $ip_address );
151
+        }
152
+
153
+        // It's possible that we're in a local environment, in which case the geolocation needs to be done from the
154
+        // external address.
155
+        if ( '' === $geolocation['country'] && $fallback ) {
156
+            $external_ip_address = self::get_external_ip_address();
157
+
158
+            // Only bother with this if the external IP differs.
159
+            if ( '0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address ) {
160
+                return self::geolocate_ip( $external_ip_address, false, $api_fallback );
161
+            }
162
+
163
+        }
164
+
165
+        return array(
166
+            'country'  => $geolocation['country'],
167
+            'state'    => $geolocation['state'],
168
+            'city'     => $geolocation['city'],
169
+            'postcode' => $geolocation['postcode'],
170
+        );
171
+
172
+    }
173
+
174
+    /**
175
+     * Fetches the country code from the request headers, if one is available.
176
+     *
177
+     * @since 1.0.19
178
+     * @return string The country code pulled from the headers, or empty string if one was not found.
179
+     */
180
+    protected static function get_country_code_from_headers() {
181
+        $country_code = '';
182
+
183
+        $headers = array(
184
+            'MM_COUNTRY_CODE',
185
+            'GEOIP_COUNTRY_CODE',
186
+            'HTTP_CF_IPCOUNTRY',
187
+            'HTTP_X_COUNTRY_CODE',
188
+        );
189
+
190
+        foreach ( $headers as $header ) {
191
+            if ( empty( $_SERVER[ $header ] ) ) {
192
+                continue;
193
+            }
194
+
195
+            $country_code = strtoupper( sanitize_text_field( wp_unslash( $_SERVER[ $header ] ) ) );
196
+            break;
197
+        }
198
+
199
+        return $country_code;
200
+    }
201
+
202
+    /**
203
+     * Use APIs to Geolocate the user.
204
+     *
205
+     * Geolocation APIs can be added through the use of the getpaid_geolocation_geoip_apis filter.
206
+     * Provide a name=>value pair for service-slug=>endpoint.
207
+     *
208
+     * If APIs are defined, one will be chosen at random to fulfil the request. After completing, the result
209
+     * will be cached in a transient.
210
+     *
211
+     * @param  string $ip_address IP address.
212
+     * @return string
213
+     */
214
+    protected static function geolocate_via_api( $ip_address ) {
215
+
216
+        // Retrieve from cache...
217
+        $country_code = get_transient( 'geoip_' . $ip_address );
218
+
219
+        // If missing, retrieve from the API.
220
+        if ( false === $country_code ) {
221
+            $geoip_services = apply_filters( 'getpaid_geolocation_geoip_apis', self::$geoip_apis );
222
+
223
+            if ( empty( $geoip_services ) ) {
224
+                return '';
225
+            }
226
+
227
+            $geoip_services_keys = array_keys( $geoip_services );
228
+
229
+            shuffle( $geoip_services_keys );
230
+
231
+            foreach ( $geoip_services_keys as $service_name ) {
232
+
233
+                $service_endpoint = $geoip_services[ $service_name ];
234
+                $response         = wp_safe_remote_get( sprintf( $service_endpoint, $ip_address ), array( 'timeout' => 2 ) );
235
+                $country_code     = sanitize_text_field( strtoupper( self::handle_geolocation_response( $response, $service_name ) ) );
236
+
237
+                if ( ! empty( $country_code ) ) {
238
+                    break;
239
+                }
240
+
241
+            }
242
+
243
+            set_transient( 'geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS );
244
+        }
245
+
246
+        return $country_code;
247
+    }
248
+
249
+    /**
250
+     * Handles geolocation response
251
+     *
252
+     * @param  WP_Error|String $geolocation_response
253
+     * @param  String $geolocation_service
254
+     * @return string Country code
255
+     */
256
+    protected static function handle_geolocation_response( $geolocation_response, $geolocation_service ) {
257
+
258
+        if ( is_wp_error( $geolocation_response ) || empty( $geolocation_response['body'] ) ) {
259
+            return '';
260
+        }
261
+
262
+        if ( $geolocation_service === 'ipinfo.io' ) {
263
+            $data = json_decode( $geolocation_response['body'] );
264
+            return empty( $data ) ? '' : $data->country;
265
+        }
266
+
267
+        if ( $geolocation_service === 'ip-api.com' ) {
268
+            $data = json_decode( $geolocation_response['body'] );
269
+            return empty( $data ) ? '' : $data->countryCode;
270
+        }
271
+
272
+        return apply_filters( 'getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body'] );
273
+
274
+    }
275 275
 
276 276
 }
Please login to merge, or discard this patch.
includes/geolocation/class-getpaid-maxmind-database-service.php 1 patch
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -13,152 +13,152 @@
 block discarded – undo
13 13
  */
14 14
 class GetPaid_MaxMind_Database_Service {
15 15
 
16
-	/**
17
-	 * The name of the MaxMind database to utilize.
18
-	 */
19
-	const DATABASE = 'GeoLite2-Country';
20
-
21
-	/**
22
-	 * The extension for the MaxMind database.
23
-	 */
24
-	const DATABASE_EXTENSION = '.mmdb';
25
-
26
-	/**
27
-	 * A prefix for the MaxMind database filename.
28
-	 *
29
-	 * @var string
30
-	 */
31
-	private $database_prefix;
32
-
33
-	/**
34
-	 * Class constructor.
35
-	 *
36
-	 * @param string|null $database_prefix A prefix for the MaxMind database filename.
37
-	 */
38
-	public function __construct( $database_prefix ) {
39
-		$this->database_prefix = $database_prefix;
40
-	}
41
-
42
-	/**
43
-	 * Fetches the path that the database should be stored.
44
-	 *
45
-	 * @return string The local database path.
46
-	 */
47
-	public function get_database_path() {
48
-		$uploads_dir = wp_upload_dir();
49
-
50
-		$database_path = trailingslashit( $uploads_dir['basedir'] ) . 'invoicing/';
51
-		if ( ! empty( $this->database_prefix ) ) {
52
-			$database_path .= $this->database_prefix . '-';
53
-		}
54
-		$database_path .= self::DATABASE . self::DATABASE_EXTENSION;
55
-
56
-		// Filter the geolocation database storage path.
57
-		return apply_filters( 'getpaid_maxmind_geolocation_database_path', $database_path );
58
-	}
59
-
60
-	/**
61
-	 * Fetches the database from the MaxMind service.
62
-	 *
63
-	 * @param string $license_key The license key to be used when downloading the database.
64
-	 * @return string|WP_Error The path to the database file or an error if invalid.
65
-	 */
66
-	public function download_database( $license_key ) {
67
-
68
-		$download_uri = add_query_arg(
69
-			array(
70
-				'edition_id'  => self::DATABASE,
71
-				'license_key' => urlencode( wpinv_clean( $license_key ) ),
72
-				'suffix'      => 'tar.gz',
73
-			),
74
-			'https://download.maxmind.com/app/geoip_download'
75
-		);
76
-
77
-		// Needed for the download_url call right below.
78
-		require_once ABSPATH . 'wp-admin/includes/file.php';
79
-
80
-		$tmp_archive_path = download_url( esc_url_raw( $download_uri ) );
81
-
82
-		if ( is_wp_error( $tmp_archive_path ) ) {
83
-			// Transform the error into something more informative.
84
-			$error_data = $tmp_archive_path->get_error_data();
85
-			if ( isset( $error_data['code'] ) && $error_data['code'] == 401 ) {
86
-				return new WP_Error(
87
-					'getpaid_maxmind_geolocation_database_license_key',
88
-					__( 'The MaxMind license key is invalid. If you have recently created this key, you may need to wait for it to become active.', 'invoicing' )
89
-				);
90
-			}
91
-
92
-			return new WP_Error( 'getpaid_maxmind_geolocation_database_download', __( 'Failed to download the MaxMind database.', 'invoicing' ) );
93
-		}
94
-
95
-		// Extract the database from the archive.
96
-		return $this->extract_downloaded_database( $tmp_archive_path );
97
-
98
-	}
99
-
100
-	/**
101
-	 * Extracts the downloaded database.
102
-	 *
103
-	 * @param string $tmp_archive_path The database archive path.
104
-	 * @return string|WP_Error The path to the database file or an error if invalid.
105
-	 */
106
-	protected function extract_downloaded_database( $tmp_archive_path ) {
107
-
108
-		// Extract the database from the archive.
109
-		try {
110
-
111
-			$file              = new PharData( $tmp_archive_path );
112
-			$tmp_database_path = trailingslashit( dirname( $tmp_archive_path ) ) . trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION;
113
-
114
-			$file->extractTo(
115
-				dirname( $tmp_archive_path ),
116
-				trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION,
117
-				true
118
-			);
119
-
120
-		} catch ( Exception $exception ) {
121
-			return new WP_Error( 'invoicing_maxmind_geolocation_database_archive', $exception->getMessage() );
122
-		} finally {
123
-			// Remove the archive since we only care about a single file in it.
124
-			unlink( $tmp_archive_path );
125
-		}
126
-
127
-		return $tmp_database_path;
128
-	}
129
-
130
-	/**
131
-	 * Fetches the ISO country code associated with an IP address.
132
-	 *
133
-	 * @param string $ip_address The IP address to find the country code for.
134
-	 * @return string The country code for the IP address, or empty if not found.
135
-	 */
136
-	public function get_iso_country_code_for_ip( $ip_address ) {
137
-		$country_code = '';
138
-
139
-		if ( ! class_exists( 'MaxMind\Db\Reader' ) ) {
140
-			return $country_code;
141
-		}
142
-
143
-		$database_path = $this->get_database_path();
144
-		if ( ! file_exists( $database_path ) ) {
145
-			return $country_code;
146
-		}
147
-
148
-		try {
149
-			$reader = new MaxMind\Db\Reader( $database_path );
150
-			$data   = $reader->get( $ip_address );
151
-
152
-			if ( isset( $data['country']['iso_code'] ) ) {
153
-				$country_code = $data['country']['iso_code'];
154
-			}
155
-
156
-			$reader->close();
157
-		} catch ( Exception $e ) {
158
-			wpinv_error_log( $e->getMessage(), 'SOURCE: MaxMind GeoLocation' );
159
-		}
160
-
161
-		return $country_code;
162
-	}
16
+    /**
17
+     * The name of the MaxMind database to utilize.
18
+     */
19
+    const DATABASE = 'GeoLite2-Country';
20
+
21
+    /**
22
+     * The extension for the MaxMind database.
23
+     */
24
+    const DATABASE_EXTENSION = '.mmdb';
25
+
26
+    /**
27
+     * A prefix for the MaxMind database filename.
28
+     *
29
+     * @var string
30
+     */
31
+    private $database_prefix;
32
+
33
+    /**
34
+     * Class constructor.
35
+     *
36
+     * @param string|null $database_prefix A prefix for the MaxMind database filename.
37
+     */
38
+    public function __construct( $database_prefix ) {
39
+        $this->database_prefix = $database_prefix;
40
+    }
41
+
42
+    /**
43
+     * Fetches the path that the database should be stored.
44
+     *
45
+     * @return string The local database path.
46
+     */
47
+    public function get_database_path() {
48
+        $uploads_dir = wp_upload_dir();
49
+
50
+        $database_path = trailingslashit( $uploads_dir['basedir'] ) . 'invoicing/';
51
+        if ( ! empty( $this->database_prefix ) ) {
52
+            $database_path .= $this->database_prefix . '-';
53
+        }
54
+        $database_path .= self::DATABASE . self::DATABASE_EXTENSION;
55
+
56
+        // Filter the geolocation database storage path.
57
+        return apply_filters( 'getpaid_maxmind_geolocation_database_path', $database_path );
58
+    }
59
+
60
+    /**
61
+     * Fetches the database from the MaxMind service.
62
+     *
63
+     * @param string $license_key The license key to be used when downloading the database.
64
+     * @return string|WP_Error The path to the database file or an error if invalid.
65
+     */
66
+    public function download_database( $license_key ) {
67
+
68
+        $download_uri = add_query_arg(
69
+            array(
70
+                'edition_id'  => self::DATABASE,
71
+                'license_key' => urlencode( wpinv_clean( $license_key ) ),
72
+                'suffix'      => 'tar.gz',
73
+            ),
74
+            'https://download.maxmind.com/app/geoip_download'
75
+        );
76
+
77
+        // Needed for the download_url call right below.
78
+        require_once ABSPATH . 'wp-admin/includes/file.php';
79
+
80
+        $tmp_archive_path = download_url( esc_url_raw( $download_uri ) );
81
+
82
+        if ( is_wp_error( $tmp_archive_path ) ) {
83
+            // Transform the error into something more informative.
84
+            $error_data = $tmp_archive_path->get_error_data();
85
+            if ( isset( $error_data['code'] ) && $error_data['code'] == 401 ) {
86
+                return new WP_Error(
87
+                    'getpaid_maxmind_geolocation_database_license_key',
88
+                    __( 'The MaxMind license key is invalid. If you have recently created this key, you may need to wait for it to become active.', 'invoicing' )
89
+                );
90
+            }
91
+
92
+            return new WP_Error( 'getpaid_maxmind_geolocation_database_download', __( 'Failed to download the MaxMind database.', 'invoicing' ) );
93
+        }
94
+
95
+        // Extract the database from the archive.
96
+        return $this->extract_downloaded_database( $tmp_archive_path );
97
+
98
+    }
99
+
100
+    /**
101
+     * Extracts the downloaded database.
102
+     *
103
+     * @param string $tmp_archive_path The database archive path.
104
+     * @return string|WP_Error The path to the database file or an error if invalid.
105
+     */
106
+    protected function extract_downloaded_database( $tmp_archive_path ) {
107
+
108
+        // Extract the database from the archive.
109
+        try {
110
+
111
+            $file              = new PharData( $tmp_archive_path );
112
+            $tmp_database_path = trailingslashit( dirname( $tmp_archive_path ) ) . trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION;
113
+
114
+            $file->extractTo(
115
+                dirname( $tmp_archive_path ),
116
+                trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION,
117
+                true
118
+            );
119
+
120
+        } catch ( Exception $exception ) {
121
+            return new WP_Error( 'invoicing_maxmind_geolocation_database_archive', $exception->getMessage() );
122
+        } finally {
123
+            // Remove the archive since we only care about a single file in it.
124
+            unlink( $tmp_archive_path );
125
+        }
126
+
127
+        return $tmp_database_path;
128
+    }
129
+
130
+    /**
131
+     * Fetches the ISO country code associated with an IP address.
132
+     *
133
+     * @param string $ip_address The IP address to find the country code for.
134
+     * @return string The country code for the IP address, or empty if not found.
135
+     */
136
+    public function get_iso_country_code_for_ip( $ip_address ) {
137
+        $country_code = '';
138
+
139
+        if ( ! class_exists( 'MaxMind\Db\Reader' ) ) {
140
+            return $country_code;
141
+        }
142
+
143
+        $database_path = $this->get_database_path();
144
+        if ( ! file_exists( $database_path ) ) {
145
+            return $country_code;
146
+        }
147
+
148
+        try {
149
+            $reader = new MaxMind\Db\Reader( $database_path );
150
+            $data   = $reader->get( $ip_address );
151
+
152
+            if ( isset( $data['country']['iso_code'] ) ) {
153
+                $country_code = $data['country']['iso_code'];
154
+            }
155
+
156
+            $reader->close();
157
+        } catch ( Exception $e ) {
158
+            wpinv_error_log( $e->getMessage(), 'SOURCE: MaxMind GeoLocation' );
159
+        }
160
+
161
+        return $country_code;
162
+    }
163 163
 
164 164
 }
Please login to merge, or discard this patch.
includes/class-getpaid-daily-maintenance.php 1 patch
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -12,108 +12,108 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Daily_Maintenance {
14 14
 
15
-	/**
16
-	 * Class constructor.
17
-	 */
18
-	public function __construct(){
19
-
20
-		// Clear deprecated events.
21
-		add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) );
22
-
23
-		// (Maybe) schedule a cron that runs daily.
24
-		add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) );
25
-
26
-		// Fired everyday at 7 a.m (this might vary for sites with few visitors)
27
-		add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) );
28
-		add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) );
29
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) );
30
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) );
31
-
32
-	}
33
-
34
-	/**
35
-	 * Schedules a cron to run every day at 7 a.m
36
-	 *
37
-	 */
38
-	public function maybe_create_scheduled_event() {
39
-
40
-		if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
41
-			$timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
42
-			wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
43
-		}
44
-
45
-	}
46
-
47
-	/**
48
-	 * Clears deprecated events.
49
-	 *
50
-	 */
51
-	public function maybe_clear_deprecated_events() {
52
-
53
-		if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
54
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
55
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
56
-			update_option( 'wpinv_cleared_old_events', 1 );
57
-		}
58
-
59
-	}
60
-
61
-	/**
62
-	 * Fires the old hook for backwards compatibility.
63
-	 *
64
-	 */
65
-	public function backwards_compat() {
66
-		do_action( 'wpinv_register_schedule_event_daily' );
67
-	}
68
-
69
-	/**
70
-	 * Expires expired subscriptions.
71
-	 *
72
-	 */
73
-	public function maybe_expire_subscriptions() {
74
-
75
-		// Fetch expired subscriptions (skips those that expire today).
76
-		$args  = array(
77
-			'number'             => -1,
78
-			'count_total'        => false,
79
-			'status'             => 'trialling active failing cancelled',
80
-			'date_expires_query' => array(
81
-				'before'    => 'today',
82
-				'inclusive' => false,
83
-			),
84
-		);
85
-
86
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
87
-
88
-		foreach ( $subscriptions->get_results() as $subscription ) {
89
-			if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) {
90
-				$subscription->set_status( 'expired' );
91
-				$subscription->save();
92
-			}
93
-		}
94
-
95
-	}
96
-
97
-	/**
98
-	 * Logs cron runs.
99
-	 *
100
-	 */
101
-	public function log_cron_run() {
102
-		wpinv_error_log( 'GetPaid Daily Cron' );
103
-	}
104
-
105
-	/**
106
-	 * Updates GeoIP databases.
107
-	 *
108
-	 */
109
-	public function maybe_update_geoip_databases() {
110
-		$updated = get_transient( 'getpaid_updated_geoip_databases' );
111
-
112
-		if ( false === $updated ) {
113
-			set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS );
114
-			do_action( 'getpaid_update_geoip_databases' );
115
-		}
116
-
117
-	}
15
+    /**
16
+     * Class constructor.
17
+     */
18
+    public function __construct(){
19
+
20
+        // Clear deprecated events.
21
+        add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) );
22
+
23
+        // (Maybe) schedule a cron that runs daily.
24
+        add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) );
25
+
26
+        // Fired everyday at 7 a.m (this might vary for sites with few visitors)
27
+        add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) );
28
+        add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) );
29
+        add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) );
30
+        add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) );
31
+
32
+    }
33
+
34
+    /**
35
+     * Schedules a cron to run every day at 7 a.m
36
+     *
37
+     */
38
+    public function maybe_create_scheduled_event() {
39
+
40
+        if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
41
+            $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
42
+            wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
43
+        }
44
+
45
+    }
46
+
47
+    /**
48
+     * Clears deprecated events.
49
+     *
50
+     */
51
+    public function maybe_clear_deprecated_events() {
52
+
53
+        if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
54
+            wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
55
+            wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
56
+            update_option( 'wpinv_cleared_old_events', 1 );
57
+        }
58
+
59
+    }
60
+
61
+    /**
62
+     * Fires the old hook for backwards compatibility.
63
+     *
64
+     */
65
+    public function backwards_compat() {
66
+        do_action( 'wpinv_register_schedule_event_daily' );
67
+    }
68
+
69
+    /**
70
+     * Expires expired subscriptions.
71
+     *
72
+     */
73
+    public function maybe_expire_subscriptions() {
74
+
75
+        // Fetch expired subscriptions (skips those that expire today).
76
+        $args  = array(
77
+            'number'             => -1,
78
+            'count_total'        => false,
79
+            'status'             => 'trialling active failing cancelled',
80
+            'date_expires_query' => array(
81
+                'before'    => 'today',
82
+                'inclusive' => false,
83
+            ),
84
+        );
85
+
86
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
87
+
88
+        foreach ( $subscriptions->get_results() as $subscription ) {
89
+            if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) {
90
+                $subscription->set_status( 'expired' );
91
+                $subscription->save();
92
+            }
93
+        }
94
+
95
+    }
96
+
97
+    /**
98
+     * Logs cron runs.
99
+     *
100
+     */
101
+    public function log_cron_run() {
102
+        wpinv_error_log( 'GetPaid Daily Cron' );
103
+    }
104
+
105
+    /**
106
+     * Updates GeoIP databases.
107
+     *
108
+     */
109
+    public function maybe_update_geoip_databases() {
110
+        $updated = get_transient( 'getpaid_updated_geoip_databases' );
111
+
112
+        if ( false === $updated ) {
113
+            set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS );
114
+            do_action( 'getpaid_update_geoip_databases' );
115
+        }
116
+
117
+    }
118 118
 
119 119
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-taxes.php 1 patch
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -12,231 +12,231 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Taxes {
14 14
 
15
-	/**
16
-	 * Submission taxes.
17
-	 * @var array
18
-	 */
19
-	public $taxes = array();
20
-
21
-	/**
22
-	 * Initial tax.
23
-	 * @var float
24
-	 */
25
-	protected $initial_tax = 0;
26
-
27
-	/**
28
-	 * Recurring tax.
29
-	 * @var float
30
-	 */
31
-	protected $recurring_tax = 0;
15
+    /**
16
+     * Submission taxes.
17
+     * @var array
18
+     */
19
+    public $taxes = array();
20
+
21
+    /**
22
+     * Initial tax.
23
+     * @var float
24
+     */
25
+    protected $initial_tax = 0;
26
+
27
+    /**
28
+     * Recurring tax.
29
+     * @var float
30
+     */
31
+    protected $recurring_tax = 0;
32
+
33
+    /**
34
+     * Class constructor
35
+     *
36
+     * @param GetPaid_Payment_Form_Submission $submission
37
+     */
38
+    public function __construct( $submission ) {
39
+
40
+        // Validate VAT number.
41
+        $this->validate_vat( $submission );
42
+
43
+        foreach ( $submission->get_items() as $item ) {
44
+            $this->process_item_tax( $item, $submission );
45
+        }
46
+
47
+        // Process any existing invoice taxes.
48
+        if ( $submission->has_invoice() ) {
49
+            $this->taxes = $submission->get_invoice()->get_taxes();
50
+        }
51
+
52
+        // Add VAT.
53
+        $this->taxes['vat'] = array(
54
+            'name'          => 'vat',
55
+            'initial_tax'   => $this->initial_tax,
56
+            'recurring_tax' => $this->recurring_tax,
57
+        );
58
+
59
+    }
60
+
61
+    /**
62
+     * Maybe process tax.
63
+     *
64
+     * @since 1.0.19
65
+     * @param GetPaid_Form_Item $item
66
+     * @param GetPaid_Payment_Form_Submission $submission
67
+     */
68
+    public function process_item_tax( $item, $submission ) {
69
+
70
+        $rate     = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() );
71
+        $price    = $item->get_sub_total();
72
+        $item_tax = $price * $rate * 0.01;
73
+
74
+        if ( wpinv_prices_include_tax() ) {
75
+            $item_tax = $price - ( $price - $price * $rate * 0.01 );
76
+        }
77
+
78
+        $this->initial_tax += $item_tax;
79
+
80
+        if ( $item->is_recurring() ) {
81
+            $this->recurring_tax += $item_tax;
82
+        }
83
+
84
+    }
85
+
86
+    /**
87
+     * Checks if the submission has a digital item.
88
+     *
89
+     * @param GetPaid_Payment_Form_Submission $submission
90
+     * @since 1.0.19
91
+     * @return bool
92
+     */
93
+    public function has_digital_item( $submission ) {
94
+
95
+        foreach ( $submission->get_items() as $item ) {
96
+
97
+            if ( 'digital' == $item->get_vat_rule() ) {
98
+                return true;
99
+            }
100
+
101
+        }
102
+
103
+        return false;
104
+    }
105
+
106
+    /**
107
+     * Checks if this is an eu store.
108
+     *
109
+     * @since 1.0.19
110
+     * @return bool
111
+     */
112
+    public function is_eu_store() {
113
+        return $this->is_eu_country( wpinv_get_default_country() );
114
+    }
115
+
116
+    /**
117
+     * Checks if this is an eu country.
118
+     *
119
+     * @param string $country
120
+     * @since 1.0.19
121
+     * @return bool
122
+     */
123
+    public function is_eu_country( $country ) {
124
+        return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country );
125
+    }
126
+
127
+    /**
128
+     * Checks if this is an eu purchase.
129
+     *
130
+     * @param string $customer_country
131
+     * @since 1.0.19
132
+     * @return bool
133
+     */
134
+    public function is_eu_transaction( $customer_country ) {
135
+        return $this->is_eu_country( $customer_country ) && $this->is_eu_store();
136
+    }
137
+
138
+    /**
139
+     * Retrieves the vat number.
140
+     *
141
+     * @param GetPaid_Payment_Form_Submission $submission
142
+     * @since 1.0.19
143
+     * @return string
144
+     */
145
+    public function get_vat_number( $submission ) {
146
+
147
+        // Retrieve from the posted number.
148
+        $vat_number = $submission->get_field( 'wpinv_vat_number' );
149
+        if ( ! empty( $vat_number ) ) {
150
+            return wpinv_clean( $vat_number );
151
+        }
152
+
153
+        // Retrieve from the invoice.
154
+        return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
155
+    }
156
+
157
+    /**
158
+     * Retrieves the company.
159
+     *
160
+     * @param GetPaid_Payment_Form_Submission $submission
161
+     * @since 1.0.19
162
+     * @return string
163
+     */
164
+    public function get_company( $submission ) {
165
+
166
+        // Retrieve from the posted data.
167
+        $company = $submission->get_field( 'wpinv_company' );
168
+        if ( ! empty( $company ) ) {
169
+            return wpinv_clean( $company );
170
+        }
171
+
172
+        // Retrieve from the invoice.
173
+        return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
174
+    }
175
+
176
+    /**
177
+     * Checks if we requires a VAT number.
178
+     *
179
+     * @param bool $ip_in_eu Whether the customer IP is from the EU
180
+     * @param bool $country_in_eu Whether the customer country is from the EU
181
+     * @since 1.0.19
182
+     * @return string
183
+     */
184
+    public function requires_vat( $ip_in_eu, $country_in_eu ) {
185
+
186
+        $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
187
+        $prevent_b2c = ! empty( $prevent_b2c );
188
+        $is_eu       = $ip_in_eu || $country_in_eu;
189
+
190
+        return $prevent_b2c && $is_eu;
191
+    }
32 192
 
33 193
     /**
34
-	 * Class constructor
35
-	 *
36
-	 * @param GetPaid_Payment_Form_Submission $submission
37
-	 */
38
-	public function __construct( $submission ) {
39
-
40
-		// Validate VAT number.
41
-		$this->validate_vat( $submission );
42
-
43
-		foreach ( $submission->get_items() as $item ) {
44
-			$this->process_item_tax( $item, $submission );
45
-		}
46
-
47
-		// Process any existing invoice taxes.
48
-		if ( $submission->has_invoice() ) {
49
-			$this->taxes = $submission->get_invoice()->get_taxes();
50
-		}
51
-
52
-		// Add VAT.
53
-		$this->taxes['vat'] = array(
54
-			'name'          => 'vat',
55
-			'initial_tax'   => $this->initial_tax,
56
-			'recurring_tax' => $this->recurring_tax,
57
-		);
58
-
59
-	}
60
-
61
-	/**
62
-	 * Maybe process tax.
63
-	 *
64
-	 * @since 1.0.19
65
-	 * @param GetPaid_Form_Item $item
66
-	 * @param GetPaid_Payment_Form_Submission $submission
67
-	 */
68
-	public function process_item_tax( $item, $submission ) {
69
-
70
-		$rate     = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() );
71
-		$price    = $item->get_sub_total();
72
-		$item_tax = $price * $rate * 0.01;
73
-
74
-		if ( wpinv_prices_include_tax() ) {
75
-			$item_tax = $price - ( $price - $price * $rate * 0.01 );
76
-		}
77
-
78
-		$this->initial_tax += $item_tax;
79
-
80
-		if ( $item->is_recurring() ) {
81
-			$this->recurring_tax += $item_tax;
82
-		}
83
-
84
-	}
85
-
86
-	/**
87
-	 * Checks if the submission has a digital item.
88
-	 *
89
-	 * @param GetPaid_Payment_Form_Submission $submission
90
-	 * @since 1.0.19
91
-	 * @return bool
92
-	 */
93
-	public function has_digital_item( $submission ) {
94
-
95
-		foreach ( $submission->get_items() as $item ) {
96
-
97
-			if ( 'digital' == $item->get_vat_rule() ) {
98
-				return true;
99
-			}
100
-
101
-		}
102
-
103
-		return false;
104
-	}
105
-
106
-	/**
107
-	 * Checks if this is an eu store.
108
-	 *
109
-	 * @since 1.0.19
110
-	 * @return bool
111
-	 */
112
-	public function is_eu_store() {
113
-		return $this->is_eu_country( wpinv_get_default_country() );
114
-	}
115
-
116
-	/**
117
-	 * Checks if this is an eu country.
118
-	 *
119
-	 * @param string $country
120
-	 * @since 1.0.19
121
-	 * @return bool
122
-	 */
123
-	public function is_eu_country( $country ) {
124
-		return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country );
125
-	}
126
-
127
-	/**
128
-	 * Checks if this is an eu purchase.
129
-	 *
130
-	 * @param string $customer_country
131
-	 * @since 1.0.19
132
-	 * @return bool
133
-	 */
134
-	public function is_eu_transaction( $customer_country ) {
135
-		return $this->is_eu_country( $customer_country ) && $this->is_eu_store();
136
-	}
137
-
138
-	/**
139
-	 * Retrieves the vat number.
140
-	 *
141
-	 * @param GetPaid_Payment_Form_Submission $submission
142
-	 * @since 1.0.19
143
-	 * @return string
144
-	 */
145
-	public function get_vat_number( $submission ) {
146
-
147
-		// Retrieve from the posted number.
148
-		$vat_number = $submission->get_field( 'wpinv_vat_number' );
149
-		if ( ! empty( $vat_number ) ) {
150
-			return wpinv_clean( $vat_number );
151
-		}
152
-
153
-		// Retrieve from the invoice.
154
-		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
155
-	}
156
-
157
-	/**
158
-	 * Retrieves the company.
159
-	 *
160
-	 * @param GetPaid_Payment_Form_Submission $submission
161
-	 * @since 1.0.19
162
-	 * @return string
163
-	 */
164
-	public function get_company( $submission ) {
165
-
166
-		// Retrieve from the posted data.
167
-		$company = $submission->get_field( 'wpinv_company' );
168
-		if ( ! empty( $company ) ) {
169
-			return wpinv_clean( $company );
170
-		}
171
-
172
-		// Retrieve from the invoice.
173
-		return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
174
-	}
175
-
176
-	/**
177
-	 * Checks if we requires a VAT number.
178
-	 *
179
-	 * @param bool $ip_in_eu Whether the customer IP is from the EU
180
-	 * @param bool $country_in_eu Whether the customer country is from the EU
181
-	 * @since 1.0.19
182
-	 * @return string
183
-	 */
184
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
185
-
186
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
187
-		$prevent_b2c = ! empty( $prevent_b2c );
188
-		$is_eu       = $ip_in_eu || $country_in_eu;
189
-
190
-		return $prevent_b2c && $is_eu;
191
-	}
192
-
193
-	/**
194
-	 * Validate VAT data.
195
-	 *
196
-	 * @param GetPaid_Payment_Form_Submission $submission
197
-	 * @since 1.0.19
198
-	 */
199
-	public function validate_vat( $submission ) {
200
-
201
-		$has_digital = $this->has_digital_item( $submission );
202
-		$in_eu       = $this->is_eu_transaction( $submission->country );
203
-
204
-		// Abort if we are not validating vat numbers.
205
-		if ( ! $has_digital && ! $in_eu ) {
194
+     * Validate VAT data.
195
+     *
196
+     * @param GetPaid_Payment_Form_Submission $submission
197
+     * @since 1.0.19
198
+     */
199
+    public function validate_vat( $submission ) {
200
+
201
+        $has_digital = $this->has_digital_item( $submission );
202
+        $in_eu       = $this->is_eu_transaction( $submission->country );
203
+
204
+        // Abort if we are not validating vat numbers.
205
+        if ( ! $has_digital && ! $in_eu ) {
206 206
             return;
207
-		}
207
+        }
208 208
 
209
-		// Prepare variables.
210
-		$vat_number  = $this->get_vat_number( $submission );
211
-		$company     = $this->get_company( $submission );
212
-		$ip_country  = getpaid_get_ip_country();
209
+        // Prepare variables.
210
+        $vat_number  = $this->get_vat_number( $submission );
211
+        $company     = $this->get_company( $submission );
212
+        $ip_country  = getpaid_get_ip_country();
213 213
         $is_eu       = $this->is_eu_country( $submission->country );
214 214
         $is_ip_eu    = $this->is_eu_country( $ip_country );
215 215
 
216
-		// If we're preventing business to consumer purchases, ensure
217
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
216
+        // If we're preventing business to consumer purchases, ensure
217
+        if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
218 218
 
219
-			// Ensure that a vat number has been specified.
220
-			throw new Exception(
221
-				wp_sprintf(
222
-					__( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ),
223
-					getpaid_vat_name()
224
-				)
225
-			);
219
+            // Ensure that a vat number has been specified.
220
+            throw new Exception(
221
+                wp_sprintf(
222
+                    __( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ),
223
+                    getpaid_vat_name()
224
+                )
225
+            );
226 226
 
227
-		}
227
+        }
228 228
 
229
-		// Abort if we are not validating vat (vat number should exist, user should be in eu and business too).
230
-		if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) {
229
+        // Abort if we are not validating vat (vat number should exist, user should be in eu and business too).
230
+        if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) {
231 231
             return;
232
-		}
232
+        }
233 233
 
234
-		$is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country );
234
+        $is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country );
235 235
 
236
-		if ( is_string( $is_valid ) ) {
237
-			throw new Exception( $is_valid );
238
-		}
236
+        if ( is_string( $is_valid ) ) {
237
+            throw new Exception( $is_valid );
238
+        }
239 239
 
240
-	}
240
+    }
241 241
 
242 242
 }
Please login to merge, or discard this patch.
includes/libraries/wpinv-euvat/class-wpinv-euvat.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -350,23 +350,23 @@  discard block
 block discarded – undo
350 350
     }
351 351
 
352 352
     /**
353
-	 *
354
-	 * @deprecated
355
-	 */
353
+     *
354
+     * @deprecated
355
+     */
356 356
     public static function maxmind_folder() {
357 357
         return false;
358 358
     }
359 359
 
360 360
     /**
361
-	 *
362
-	 * @deprecated
363
-	 */
361
+     *
362
+     * @deprecated
363
+     */
364 364
     public static function geoip2_download_database() {}
365 365
 
366 366
     /**
367
-	 *
368
-	 * @deprecated
369
-	 */
367
+     *
368
+     * @deprecated
369
+     */
370 370
     public static function geoip2_download_file() {}
371 371
 
372 372
     /**
@@ -1517,7 +1517,7 @@  discard block
 block discarded – undo
1517 1517
         $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1518 1518
 
1519 1519
         if ( ! $valid_company && ! empty( $wpinv_options['vat_disable_company_name_check'] ) ) {
1520
-           return wp_sprintf(
1520
+            return wp_sprintf(
1521 1521
                 __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ),
1522 1522
                 getpaid_vat_name()
1523 1523
             );
Please login to merge, or discard this patch.