Passed
Push — master ( 33e595...2bb08e )
by Brian
03:54
created
vendor/composer/InstalledVersions.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -11,93 +11,93 @@
 block discarded – undo
11 11
 
12 12
 class InstalledVersions
13 13
 {
14
-private static $installed = array (
14
+private static $installed = array(
15 15
   'root' => 
16
-  array (
16
+  array(
17 17
     'pretty_version' => 'dev-master',
18 18
     'version' => 'dev-master',
19 19
     'aliases' => 
20
-    array (
20
+    array(
21 21
     ),
22 22
     'reference' => '33e5957c96b7d35ab719f0db131755db4a02680f',
23 23
     'name' => 'ayecode/invoicing',
24 24
   ),
25 25
   'versions' => 
26
-  array (
26
+  array(
27 27
     'ayecode/ayecode-connect-helper' => 
28
-    array (
28
+    array(
29 29
       'pretty_version' => '1.0.3',
30 30
       'version' => '1.0.3.0',
31 31
       'aliases' => 
32
-      array (
32
+      array(
33 33
       ),
34 34
       'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4',
35 35
     ),
36 36
     'ayecode/invoicing' => 
37
-    array (
37
+    array(
38 38
       'pretty_version' => 'dev-master',
39 39
       'version' => 'dev-master',
40 40
       'aliases' => 
41
-      array (
41
+      array(
42 42
       ),
43 43
       'reference' => '33e5957c96b7d35ab719f0db131755db4a02680f',
44 44
     ),
45 45
     'ayecode/wp-ayecode-ui' => 
46
-    array (
46
+    array(
47 47
       'pretty_version' => '0.1.35',
48 48
       'version' => '0.1.35.0',
49 49
       'aliases' => 
50
-      array (
50
+      array(
51 51
       ),
52 52
       'reference' => 'e5d7955f648c6b350a8fe72e0110b8d78645c60f',
53 53
     ),
54 54
     'ayecode/wp-font-awesome-settings' => 
55
-    array (
55
+    array(
56 56
       'pretty_version' => '1.0.12',
57 57
       'version' => '1.0.12.0',
58 58
       'aliases' => 
59
-      array (
59
+      array(
60 60
       ),
61 61
       'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288',
62 62
     ),
63 63
     'ayecode/wp-super-duper' => 
64
-    array (
64
+    array(
65 65
       'pretty_version' => '1.0.22',
66 66
       'version' => '1.0.22.0',
67 67
       'aliases' => 
68
-      array (
68
+      array(
69 69
       ),
70 70
       'reference' => '42b638502c9e4be0877f27903df7c7ed2080bdac',
71 71
     ),
72 72
     'composer/installers' => 
73
-    array (
73
+    array(
74 74
       'pretty_version' => 'v1.9.0',
75 75
       'version' => '1.9.0.0',
76 76
       'aliases' => 
77
-      array (
77
+      array(
78 78
       ),
79 79
       'reference' => 'b93bcf0fa1fccb0b7d176b0967d969691cd74cca',
80 80
     ),
81 81
     'maxmind-db/reader' => 
82
-    array (
82
+    array(
83 83
       'pretty_version' => 'v1.6.0',
84 84
       'version' => '1.6.0.0',
85 85
       'aliases' => 
86
-      array (
86
+      array(
87 87
       ),
88 88
       'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4',
89 89
     ),
90 90
     'roundcube/plugin-installer' => 
91
-    array (
91
+    array(
92 92
       'replaced' => 
93
-      array (
93
+      array(
94 94
         0 => '*',
95 95
       ),
96 96
     ),
97 97
     'shama/baton' => 
98
-    array (
98
+    array(
99 99
       'replaced' => 
100
-      array (
100
+      array(
101 101
         0 => '*',
102 102
       ),
103 103
     ),
Please login to merge, or discard this patch.
vendor/composer/installed.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -1,90 +1,90 @@
 block discarded – undo
1
-<?php return array (
1
+<?php return array(
2 2
   'root' => 
3
-  array (
3
+  array(
4 4
     'pretty_version' => 'dev-master',
5 5
     'version' => 'dev-master',
6 6
     'aliases' => 
7
-    array (
7
+    array(
8 8
     ),
9 9
     'reference' => '33e5957c96b7d35ab719f0db131755db4a02680f',
10 10
     'name' => 'ayecode/invoicing',
11 11
   ),
12 12
   'versions' => 
13
-  array (
13
+  array(
14 14
     'ayecode/ayecode-connect-helper' => 
15
-    array (
15
+    array(
16 16
       'pretty_version' => '1.0.3',
17 17
       'version' => '1.0.3.0',
18 18
       'aliases' => 
19
-      array (
19
+      array(
20 20
       ),
21 21
       'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4',
22 22
     ),
23 23
     'ayecode/invoicing' => 
24
-    array (
24
+    array(
25 25
       'pretty_version' => 'dev-master',
26 26
       'version' => 'dev-master',
27 27
       'aliases' => 
28
-      array (
28
+      array(
29 29
       ),
30 30
       'reference' => '33e5957c96b7d35ab719f0db131755db4a02680f',
31 31
     ),
32 32
     'ayecode/wp-ayecode-ui' => 
33
-    array (
33
+    array(
34 34
       'pretty_version' => '0.1.35',
35 35
       'version' => '0.1.35.0',
36 36
       'aliases' => 
37
-      array (
37
+      array(
38 38
       ),
39 39
       'reference' => 'e5d7955f648c6b350a8fe72e0110b8d78645c60f',
40 40
     ),
41 41
     'ayecode/wp-font-awesome-settings' => 
42
-    array (
42
+    array(
43 43
       'pretty_version' => '1.0.12',
44 44
       'version' => '1.0.12.0',
45 45
       'aliases' => 
46
-      array (
46
+      array(
47 47
       ),
48 48
       'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288',
49 49
     ),
50 50
     'ayecode/wp-super-duper' => 
51
-    array (
51
+    array(
52 52
       'pretty_version' => '1.0.22',
53 53
       'version' => '1.0.22.0',
54 54
       'aliases' => 
55
-      array (
55
+      array(
56 56
       ),
57 57
       'reference' => '42b638502c9e4be0877f27903df7c7ed2080bdac',
58 58
     ),
59 59
     'composer/installers' => 
60
-    array (
60
+    array(
61 61
       'pretty_version' => 'v1.9.0',
62 62
       'version' => '1.9.0.0',
63 63
       'aliases' => 
64
-      array (
64
+      array(
65 65
       ),
66 66
       'reference' => 'b93bcf0fa1fccb0b7d176b0967d969691cd74cca',
67 67
     ),
68 68
     'maxmind-db/reader' => 
69
-    array (
69
+    array(
70 70
       'pretty_version' => 'v1.6.0',
71 71
       'version' => '1.6.0.0',
72 72
       'aliases' => 
73
-      array (
73
+      array(
74 74
       ),
75 75
       'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4',
76 76
     ),
77 77
     'roundcube/plugin-installer' => 
78
-    array (
78
+    array(
79 79
       'replaced' => 
80
-      array (
80
+      array(
81 81
         0 => '*',
82 82
       ),
83 83
     ),
84 84
     'shama/baton' => 
85
-    array (
85
+    array(
86 86
       'replaced' => 
87
-      array (
87
+      array(
88 88
         0 => '*',
89 89
       ),
90 90
     ),
Please login to merge, or discard this patch.
includes/geolocation/class-getpaid-maxmind-database-service.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * The service class responsible for interacting with MaxMind databases.
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @param string|null $database_prefix A prefix for the MaxMind database filename.
37 37
 	 */
38
-	public function __construct( $database_prefix ) {
38
+	public function __construct($database_prefix) {
39 39
 		$this->database_prefix = $database_prefix;
40 40
 	}
41 41
 
@@ -47,14 +47,14 @@  discard block
 block discarded – undo
47 47
 	public function get_database_path() {
48 48
 		$uploads_dir = wp_upload_dir();
49 49
 
50
-		$database_path = trailingslashit( $uploads_dir['basedir'] ) . 'invoicing/';
51
-		if ( ! empty( $this->database_prefix ) ) {
50
+		$database_path = trailingslashit($uploads_dir['basedir']) . 'invoicing/';
51
+		if (!empty($this->database_prefix)) {
52 52
 			$database_path .= $this->database_prefix . '-';
53 53
 		}
54 54
 		$database_path .= self::DATABASE . self::DATABASE_EXTENSION;
55 55
 
56 56
 		// Filter the geolocation database storage path.
57
-		return apply_filters( 'getpaid_maxmind_geolocation_database_path', $database_path );
57
+		return apply_filters('getpaid_maxmind_geolocation_database_path', $database_path);
58 58
 	}
59 59
 
60 60
 	/**
@@ -63,12 +63,12 @@  discard block
 block discarded – undo
63 63
 	 * @param string $license_key The license key to be used when downloading the database.
64 64
 	 * @return string|WP_Error The path to the database file or an error if invalid.
65 65
 	 */
66
-	public function download_database( $license_key ) {
66
+	public function download_database($license_key) {
67 67
 
68 68
 		$download_uri = add_query_arg(
69 69
 			array(
70 70
 				'edition_id'  => self::DATABASE,
71
-				'license_key' => urlencode( wpinv_clean( $license_key ) ),
71
+				'license_key' => urlencode(wpinv_clean($license_key)),
72 72
 				'suffix'      => 'tar.gz',
73 73
 			),
74 74
 			'https://download.maxmind.com/app/geoip_download'
@@ -77,23 +77,23 @@  discard block
 block discarded – undo
77 77
 		// Needed for the download_url call right below.
78 78
 		require_once ABSPATH . 'wp-admin/includes/file.php';
79 79
 
80
-		$tmp_archive_path = download_url( esc_url_raw( $download_uri ) );
80
+		$tmp_archive_path = download_url(esc_url_raw($download_uri));
81 81
 
82
-		if ( is_wp_error( $tmp_archive_path ) ) {
82
+		if (is_wp_error($tmp_archive_path)) {
83 83
 			// Transform the error into something more informative.
84 84
 			$error_data = $tmp_archive_path->get_error_data();
85
-			if ( isset( $error_data['code'] ) && $error_data['code'] == 401 ) {
85
+			if (isset($error_data['code']) && $error_data['code'] == 401) {
86 86
 				return new WP_Error(
87 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' )
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 89
 				);
90 90
 			}
91 91
 
92
-			return new WP_Error( 'getpaid_maxmind_geolocation_database_download', __( 'Failed to download the MaxMind database.', 'invoicing' ) );
92
+			return new WP_Error('getpaid_maxmind_geolocation_database_download', __('Failed to download the MaxMind database.', 'invoicing'));
93 93
 		}
94 94
 
95 95
 		// Extract the database from the archive.
96
-		return $this->extract_downloaded_database( $tmp_archive_path );
96
+		return $this->extract_downloaded_database($tmp_archive_path);
97 97
 
98 98
 	}
99 99
 
@@ -103,27 +103,27 @@  discard block
 block discarded – undo
103 103
 	 * @param string $tmp_archive_path The database archive path.
104 104
 	 * @return string|WP_Error The path to the database file or an error if invalid.
105 105
 	 */
106
-	protected function extract_downloaded_database( $tmp_archive_path ) {
106
+	protected function extract_downloaded_database($tmp_archive_path) {
107 107
 
108 108
 		// Extract the database from the archive.
109 109
 		$tmp_database_path = '';
110 110
 
111 111
 		try {
112 112
 
113
-			$file              = new PharData( $tmp_archive_path );
114
-			$tmp_database_path = trailingslashit( dirname( $tmp_archive_path ) ) . trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION;
113
+			$file              = new PharData($tmp_archive_path);
114
+			$tmp_database_path = trailingslashit(dirname($tmp_archive_path)) . trailingslashit($file->current()->getFilename()) . self::DATABASE . self::DATABASE_EXTENSION;
115 115
 
116 116
 			$file->extractTo(
117
-				dirname( $tmp_archive_path ),
118
-				trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION,
117
+				dirname($tmp_archive_path),
118
+				trailingslashit($file->current()->getFilename()) . self::DATABASE . self::DATABASE_EXTENSION,
119 119
 				true
120 120
 			);
121 121
 
122
-		} catch ( Exception $exception ) {
123
-			return new WP_Error( 'invoicing_maxmind_geolocation_database_archive', $exception->getMessage() );
122
+		} catch (Exception $exception) {
123
+			return new WP_Error('invoicing_maxmind_geolocation_database_archive', $exception->getMessage());
124 124
 		} finally {
125 125
 			// Remove the archive since we only care about a single file in it.
126
-			unlink( $tmp_archive_path );
126
+			unlink($tmp_archive_path);
127 127
 		}
128 128
 
129 129
 		return $tmp_database_path;
@@ -135,29 +135,29 @@  discard block
 block discarded – undo
135 135
 	 * @param string $ip_address The IP address to find the country code for.
136 136
 	 * @return string The country code for the IP address, or empty if not found.
137 137
 	 */
138
-	public function get_iso_country_code_for_ip( $ip_address ) {
138
+	public function get_iso_country_code_for_ip($ip_address) {
139 139
 		$country_code = '';
140 140
 
141
-		if ( ! class_exists( 'MaxMind\Db\Reader' ) ) {
141
+		if (!class_exists('MaxMind\Db\Reader')) {
142 142
 			return $country_code;
143 143
 		}
144 144
 
145 145
 		$database_path = $this->get_database_path();
146
-		if ( ! file_exists( $database_path ) ) {
146
+		if (!file_exists($database_path)) {
147 147
 			return $country_code;
148 148
 		}
149 149
 
150 150
 		try {
151
-			$reader = new MaxMind\Db\Reader( $database_path );
152
-			$data   = $reader->get( $ip_address );
151
+			$reader = new MaxMind\Db\Reader($database_path);
152
+			$data   = $reader->get($ip_address);
153 153
 
154
-			if ( isset( $data['country']['iso_code'] ) ) {
154
+			if (isset($data['country']['iso_code'])) {
155 155
 				$country_code = $data['country']['iso_code'];
156 156
 			}
157 157
 
158 158
 			$reader->close();
159
-		} catch ( Exception $e ) {
160
-			wpinv_error_log( $e->getMessage(), 'SOURCE: MaxMind GeoLocation' );
159
+		} catch (Exception $e) {
160
+			wpinv_error_log($e->getMessage(), 'SOURCE: MaxMind GeoLocation');
161 161
 		}
162 162
 
163 163
 		return $country_code;
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-subscription-data-store.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * GetPaid_Subscription_Data_Store class file.
5 5
  *
6 6
  */
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
 	exit;
9 9
 }
10 10
 
@@ -50,29 +50,29 @@  discard block
 block discarded – undo
50 50
 	 *
51 51
 	 * @param WPInv_Subscription $subscription Subscription object.
52 52
 	 */
53
-	public function create( &$subscription ) {
53
+	public function create(&$subscription) {
54 54
 		global $wpdb;
55 55
 
56 56
 		$values  = array();
57 57
 		$formats = array();
58 58
 
59 59
 		$fields = $this->database_fields_to_data_type;
60
-		unset( $fields['id'] );
60
+		unset($fields['id']);
61 61
 
62
-		foreach ( $fields as $key => $format ) {
62
+		foreach ($fields as $key => $format) {
63 63
 			$method       = "get_$key";
64
-			$values[$key] = $subscription->$method( 'edit' );
64
+			$values[$key] = $subscription->$method('edit');
65 65
 			$formats[]    = $format;
66 66
 		}
67 67
 
68
-		$result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $values, $formats );
68
+		$result = $wpdb->insert($wpdb->prefix . 'wpinv_subscriptions', $values, $formats);
69 69
 
70
-		if ( $result ) {
71
-			$subscription->set_id( $wpdb->insert_id );
70
+		if ($result) {
71
+			$subscription->set_id($wpdb->insert_id);
72 72
 			$subscription->apply_changes();
73 73
 			$subscription->clear_cache();
74
-			update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() );
75
-			do_action( 'getpaid_new_subscription', $subscription );
74
+			update_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id());
75
+			do_action('getpaid_new_subscription', $subscription);
76 76
 			return true;
77 77
 		}
78 78
 
@@ -85,22 +85,22 @@  discard block
 block discarded – undo
85 85
 	 * @param WPInv_Subscription $subscription Subscription object.
86 86
 	 *
87 87
 	 */
88
-	public function read( &$subscription ) {
88
+	public function read(&$subscription) {
89 89
 		global $wpdb;
90 90
 
91 91
 		$subscription->set_defaults();
92 92
 
93
-		if ( ! $subscription->get_id() ) {
94
-			$subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
95
-			$subscription->set_id( 0 );
93
+		if (!$subscription->get_id()) {
94
+			$subscription->last_error = __('Invalid subscription ID.', 'invoicing');
95
+			$subscription->set_id(0);
96 96
 			return false;
97 97
 		}
98 98
 
99 99
 		// Maybe retrieve from the cache.
100
-		$raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' );
100
+		$raw_subscription = wp_cache_get($subscription->get_id(), 'getpaid_subscriptions');
101 101
 
102 102
 		// If not found, retrieve from the db.
103
-		if ( false === $raw_subscription ) {
103
+		if (false === $raw_subscription) {
104 104
 
105 105
 			$raw_subscription = $wpdb->get_row(
106 106
 				$wpdb->prepare(
@@ -110,22 +110,22 @@  discard block
 block discarded – undo
110 110
 			);
111 111
 
112 112
 			// Update the cache with our data
113
-			wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' );
113
+			wp_cache_set($subscription->get_id(), $raw_subscription, 'getpaid_subscriptions');
114 114
 
115 115
 		}
116 116
 
117
-		if ( ! $raw_subscription ) {
118
-			$subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
117
+		if (!$raw_subscription) {
118
+			$subscription->last_error = __('Invalid subscription ID.', 'invoicing');
119 119
 			return false;
120 120
 		}
121 121
 
122
-		foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) {
123
-			$method     = "set_$key";
124
-			$subscription->$method( $raw_subscription->$key );
122
+		foreach (array_keys($this->database_fields_to_data_type) as $key) {
123
+			$method = "set_$key";
124
+			$subscription->$method($raw_subscription->$key);
125 125
 		}
126 126
 
127
-		$subscription->set_object_read( true );
128
-		do_action( 'getpaid_read_subscription', $subscription );
127
+		$subscription->set_object_read(true);
128
+		do_action('getpaid_read_subscription', $subscription);
129 129
 
130 130
 	}
131 131
 
@@ -134,22 +134,22 @@  discard block
 block discarded – undo
134 134
 	 *
135 135
 	 * @param WPInv_Subscription $subscription Subscription object.
136 136
 	 */
137
-	public function update( &$subscription ) {
137
+	public function update(&$subscription) {
138 138
 		global $wpdb;
139 139
 
140 140
 		$changes = $subscription->get_changes();
141 141
 		$values  = array();
142 142
 		$formats = array();
143 143
 
144
-		foreach ( $this->database_fields_to_data_type as $key => $format ) {
145
-			if ( array_key_exists( $key, $changes ) ) {
144
+		foreach ($this->database_fields_to_data_type as $key => $format) {
145
+			if (array_key_exists($key, $changes)) {
146 146
 				$method       = "get_$key";
147
-				$values[$key] = $subscription->$method( 'edit' );
147
+				$values[$key] = $subscription->$method('edit');
148 148
 				$formats[]    = $format;
149 149
 			}
150 150
 		}
151 151
 
152
-		if ( empty( $values ) ) {
152
+		if (empty($values)) {
153 153
 			return;
154 154
 		}
155 155
 
@@ -169,10 +169,10 @@  discard block
 block discarded – undo
169 169
 		// Delete cache.
170 170
 		$subscription->clear_cache();
171 171
 
172
-		update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id() );
172
+		update_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id());
173 173
 
174 174
 		// Fire a hook.
175
-		do_action( 'getpaid_update_subscription', $subscription );
175
+		do_action('getpaid_update_subscription', $subscription);
176 176
 
177 177
 	}
178 178
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 	 *
182 182
 	 * @param WPInv_Subscription $subscription
183 183
 	 */
184
-	public function delete( &$subscription ) {
184
+	public function delete(&$subscription) {
185 185
 		global $wpdb;
186 186
 
187 187
 		$wpdb->query(
@@ -192,16 +192,16 @@  discard block
 block discarded – undo
192 192
 			)
193 193
 		);
194 194
 
195
-		delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id' );
196
-		delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id' );
195
+		delete_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id');
196
+		delete_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscription_id');
197 197
 
198 198
 		// Delete cache.
199 199
 		$subscription->clear_cache();
200 200
 
201 201
 		// Fire a hook.
202
-		do_action( 'getpaid_delete_subscription', $subscription );
202
+		do_action('getpaid_delete_subscription', $subscription);
203 203
 
204
-		$subscription->set_id( 0 );
204
+		$subscription->set_id(0);
205 205
 	}
206 206
 
207 207
 	/*
Please login to merge, or discard this patch.
includes/class-wpinv-item.php 1 patch
Spacing   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -78,30 +78,30 @@  discard block
 block discarded – undo
78 78
 	 *
79 79
 	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80 80
 	 */
81
-	public function __construct( $item = 0 ) {
82
-		parent::__construct( $item );
83
-
84
-		if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
85
-			$this->set_id( $item );
86
-		} elseif ( $item instanceof self ) {
87
-			$this->set_id( $item->get_id() );
88
-		} elseif ( ! empty( $item->ID ) ) {
89
-			$this->set_id( $item->ID );
90
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
91
-			$this->set_id( $item_id );
92
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
93
-			$this->set_id( $item_id );
81
+	public function __construct($item = 0) {
82
+		parent::__construct($item);
83
+
84
+		if (!empty($item) && is_numeric($item) && 'wpi_item' == get_post_type($item)) {
85
+			$this->set_id($item);
86
+		} elseif ($item instanceof self) {
87
+			$this->set_id($item->get_id());
88
+		} elseif (!empty($item->ID)) {
89
+			$this->set_id($item->ID);
90
+		} elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'custom_id')) {
91
+			$this->set_id($item_id);
92
+		} elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'name')) {
93
+			$this->set_id($item_id);
94 94
 		} else {
95
-			$this->set_object_read( true );
95
+			$this->set_object_read(true);
96 96
 		}
97 97
 
98 98
         // Load the datastore.
99
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
99
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
100 100
 
101
-		if ( $this->get_id() > 0 ) {
102
-            $this->post = get_post( $this->get_id() );
101
+		if ($this->get_id() > 0) {
102
+            $this->post = get_post($this->get_id());
103 103
             $this->ID   = $this->get_id();
104
-			$this->data_store->read( $this );
104
+			$this->data_store->read($this);
105 105
         }
106 106
 
107 107
 	}
@@ -128,8 +128,8 @@  discard block
 block discarded – undo
128 128
 	 * @param  string $context View or edit context.
129 129
 	 * @return int
130 130
 	 */
131
-	public function get_parent_id( $context = 'view' ) {
132
-		return (int) $this->get_prop( 'parent_id', $context );
131
+	public function get_parent_id($context = 'view') {
132
+		return (int) $this->get_prop('parent_id', $context);
133 133
     }
134 134
 
135 135
     /**
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
 	 * @param  string $context View or edit context.
140 140
 	 * @return string
141 141
 	 */
142
-	public function get_status( $context = 'view' ) {
143
-		return $this->get_prop( 'status', $context );
142
+	public function get_status($context = 'view') {
143
+		return $this->get_prop('status', $context);
144 144
     }
145 145
 
146 146
     /**
@@ -150,8 +150,8 @@  discard block
 block discarded – undo
150 150
 	 * @param  string $context View or edit context.
151 151
 	 * @return string
152 152
 	 */
153
-	public function get_version( $context = 'view' ) {
154
-		return $this->get_prop( 'version', $context );
153
+	public function get_version($context = 'view') {
154
+		return $this->get_prop('version', $context);
155 155
     }
156 156
 
157 157
     /**
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
 	 * @param  string $context View or edit context.
162 162
 	 * @return string
163 163
 	 */
164
-	public function get_date_created( $context = 'view' ) {
165
-		return $this->get_prop( 'date_created', $context );
164
+	public function get_date_created($context = 'view') {
165
+		return $this->get_prop('date_created', $context);
166 166
     }
167 167
 
168 168
     /**
@@ -172,11 +172,11 @@  discard block
 block discarded – undo
172 172
 	 * @param  string $context View or edit context.
173 173
 	 * @return string
174 174
 	 */
175
-	public function get_date_created_gmt( $context = 'view' ) {
176
-        $date = $this->get_date_created( $context );
175
+	public function get_date_created_gmt($context = 'view') {
176
+        $date = $this->get_date_created($context);
177 177
 
178
-        if ( $date ) {
179
-            $date = get_gmt_from_date( $date );
178
+        if ($date) {
179
+            $date = get_gmt_from_date($date);
180 180
         }
181 181
 		return $date;
182 182
     }
@@ -188,8 +188,8 @@  discard block
 block discarded – undo
188 188
 	 * @param  string $context View or edit context.
189 189
 	 * @return string
190 190
 	 */
191
-	public function get_date_modified( $context = 'view' ) {
192
-		return $this->get_prop( 'date_modified', $context );
191
+	public function get_date_modified($context = 'view') {
192
+		return $this->get_prop('date_modified', $context);
193 193
     }
194 194
 
195 195
     /**
@@ -199,11 +199,11 @@  discard block
 block discarded – undo
199 199
 	 * @param  string $context View or edit context.
200 200
 	 * @return string
201 201
 	 */
202
-	public function get_date_modified_gmt( $context = 'view' ) {
203
-        $date = $this->get_date_modified( $context );
202
+	public function get_date_modified_gmt($context = 'view') {
203
+        $date = $this->get_date_modified($context);
204 204
 
205
-        if ( $date ) {
206
-            $date = get_gmt_from_date( $date );
205
+        if ($date) {
206
+            $date = get_gmt_from_date($date);
207 207
         }
208 208
 		return $date;
209 209
     }
@@ -215,8 +215,8 @@  discard block
 block discarded – undo
215 215
 	 * @param  string $context View or edit context.
216 216
 	 * @return string
217 217
 	 */
218
-	public function get_name( $context = 'view' ) {
219
-		return $this->get_prop( 'name', $context );
218
+	public function get_name($context = 'view') {
219
+		return $this->get_prop('name', $context);
220 220
     }
221 221
 
222 222
     /**
@@ -226,8 +226,8 @@  discard block
 block discarded – undo
226 226
 	 * @param  string $context View or edit context.
227 227
 	 * @return string
228 228
 	 */
229
-	public function get_title( $context = 'view' ) {
230
-		return $this->get_name( $context );
229
+	public function get_title($context = 'view') {
230
+		return $this->get_name($context);
231 231
     }
232 232
 
233 233
     /**
@@ -237,8 +237,8 @@  discard block
 block discarded – undo
237 237
 	 * @param  string $context View or edit context.
238 238
 	 * @return string
239 239
 	 */
240
-	public function get_description( $context = 'view' ) {
241
-		return $this->get_prop( 'description', $context );
240
+	public function get_description($context = 'view') {
241
+		return $this->get_prop('description', $context);
242 242
     }
243 243
 
244 244
     /**
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
 	 * @param  string $context View or edit context.
249 249
 	 * @return string
250 250
 	 */
251
-	public function get_excerpt( $context = 'view' ) {
252
-		return $this->get_description( $context );
251
+	public function get_excerpt($context = 'view') {
252
+		return $this->get_description($context);
253 253
     }
254 254
 
255 255
     /**
@@ -259,8 +259,8 @@  discard block
 block discarded – undo
259 259
 	 * @param  string $context View or edit context.
260 260
 	 * @return string
261 261
 	 */
262
-	public function get_summary( $context = 'view' ) {
263
-		return $this->get_description( $context );
262
+	public function get_summary($context = 'view') {
263
+		return $this->get_description($context);
264 264
     }
265 265
 
266 266
     /**
@@ -270,8 +270,8 @@  discard block
 block discarded – undo
270 270
 	 * @param  string $context View or edit context.
271 271
 	 * @return int
272 272
 	 */
273
-	public function get_author( $context = 'view' ) {
274
-		return (int) $this->get_prop( 'author', $context );
273
+	public function get_author($context = 'view') {
274
+		return (int) $this->get_prop('author', $context);
275 275
 	}
276 276
 	
277 277
 	/**
@@ -281,8 +281,8 @@  discard block
 block discarded – undo
281 281
 	 * @param  string $context View or edit context.
282 282
 	 * @return int
283 283
 	 */
284
-	public function get_owner( $context = 'view' ) {
285
-		return $this->get_author( $context );
284
+	public function get_owner($context = 'view') {
285
+		return $this->get_author($context);
286 286
     }
287 287
 
288 288
     /**
@@ -292,8 +292,8 @@  discard block
 block discarded – undo
292 292
 	 * @param  string $context View or edit context.
293 293
 	 * @return float
294 294
 	 */
295
-	public function get_price( $context = 'view' ) {
296
-        return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
295
+	public function get_price($context = 'view') {
296
+        return wpinv_sanitize_amount($this->get_prop('price', $context));
297 297
 	}
298 298
 	
299 299
 	/**
@@ -303,15 +303,15 @@  discard block
 block discarded – undo
303 303
 	 * @param  string $context View or edit context.
304 304
 	 * @return float
305 305
 	 */
306
-	public function get_initial_price( $context = 'view' ) {
306
+	public function get_initial_price($context = 'view') {
307 307
 
308
-		$price = (float) $this->get_price( $context );
308
+		$price = (float) $this->get_price($context);
309 309
 
310
-		if ( $this->has_free_trial() ) {
310
+		if ($this->has_free_trial()) {
311 311
 			$price = 0;
312 312
 		}
313 313
 
314
-        return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) );
314
+        return wpinv_sanitize_amount(apply_filters('wpinv_get_initial_item_price', $price, $this));
315 315
     }
316 316
 
317 317
     /**
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 	 * @return string
323 323
 	 */
324 324
     public function get_the_price() {
325
-        return wpinv_price( wpinv_format_amount( $this->get_price() ) );
325
+        return wpinv_price(wpinv_format_amount($this->get_price()));
326 326
 	}
327 327
 
328 328
 	/**
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 	 * @return string
334 334
 	 */
335 335
     public function get_the_initial_price() {
336
-        return wpinv_price( wpinv_format_amount( $this->get_initial_price() ) );
336
+        return wpinv_price(wpinv_format_amount($this->get_initial_price()));
337 337
     }
338 338
 
339 339
     /**
@@ -343,8 +343,8 @@  discard block
 block discarded – undo
343 343
 	 * @param  string $context View or edit context.
344 344
 	 * @return string
345 345
 	 */
346
-	public function get_vat_rule( $context = 'view' ) {
347
-        return $this->get_prop( 'vat_rule', $context );
346
+	public function get_vat_rule($context = 'view') {
347
+        return $this->get_prop('vat_rule', $context);
348 348
     }
349 349
 
350 350
     /**
@@ -354,8 +354,8 @@  discard block
 block discarded – undo
354 354
 	 * @param  string $context View or edit context.
355 355
 	 * @return string
356 356
 	 */
357
-	public function get_vat_class( $context = 'view' ) {
358
-        return $this->get_prop( 'vat_class', $context );
357
+	public function get_vat_class($context = 'view') {
358
+        return $this->get_prop('vat_class', $context);
359 359
     }
360 360
 
361 361
     /**
@@ -365,8 +365,8 @@  discard block
 block discarded – undo
365 365
 	 * @param  string $context View or edit context.
366 366
 	 * @return string
367 367
 	 */
368
-	public function get_type( $context = 'view' ) {
369
-        return $this->get_prop( 'type', $context );
368
+	public function get_type($context = 'view') {
369
+        return $this->get_prop('type', $context);
370 370
     }
371 371
 
372 372
     /**
@@ -376,8 +376,8 @@  discard block
 block discarded – undo
376 376
 	 * @param  string $context View or edit context.
377 377
 	 * @return string
378 378
 	 */
379
-	public function get_custom_id( $context = 'view' ) {
380
-        return $this->get_prop( 'custom_id', $context );
379
+	public function get_custom_id($context = 'view') {
380
+        return $this->get_prop('custom_id', $context);
381 381
     }
382 382
 
383 383
     /**
@@ -387,8 +387,8 @@  discard block
 block discarded – undo
387 387
 	 * @param  string $context View or edit context.
388 388
 	 * @return string
389 389
 	 */
390
-	public function get_custom_name( $context = 'view' ) {
391
-        return $this->get_prop( 'custom_name', $context );
390
+	public function get_custom_name($context = 'view') {
391
+        return $this->get_prop('custom_name', $context);
392 392
     }
393 393
 
394 394
     /**
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
 	 * @param  string $context View or edit context.
399 399
 	 * @return string
400 400
 	 */
401
-	public function get_custom_singular_name( $context = 'view' ) {
402
-        return $this->get_prop( 'custom_singular_name', $context );
401
+	public function get_custom_singular_name($context = 'view') {
402
+        return $this->get_prop('custom_singular_name', $context);
403 403
     }
404 404
 
405 405
     /**
@@ -409,8 +409,8 @@  discard block
 block discarded – undo
409 409
 	 * @param  string $context View or edit context.
410 410
 	 * @return int
411 411
 	 */
412
-	public function get_is_editable( $context = 'view' ) {
413
-        return (int) $this->get_prop( 'is_editable', $context );
412
+	public function get_is_editable($context = 'view') {
413
+        return (int) $this->get_prop('is_editable', $context);
414 414
     }
415 415
 
416 416
     /**
@@ -420,8 +420,8 @@  discard block
 block discarded – undo
420 420
 	 * @param  string $context View or edit context.
421 421
 	 * @return int
422 422
 	 */
423
-	public function get_editable( $context = 'view' ) {
424
-		return $this->get_is_editable( $context );
423
+	public function get_editable($context = 'view') {
424
+		return $this->get_is_editable($context);
425 425
     }
426 426
 
427 427
     /**
@@ -431,8 +431,8 @@  discard block
 block discarded – undo
431 431
 	 * @param  string $context View or edit context.
432 432
 	 * @return int
433 433
 	 */
434
-	public function get_is_dynamic_pricing( $context = 'view' ) {
435
-        return (int) $this->get_prop( 'is_dynamic_pricing', $context );
434
+	public function get_is_dynamic_pricing($context = 'view') {
435
+        return (int) $this->get_prop('is_dynamic_pricing', $context);
436 436
     }
437 437
 
438 438
     /**
@@ -442,8 +442,8 @@  discard block
 block discarded – undo
442 442
 	 * @param  string $context View or edit context.
443 443
 	 * @return float
444 444
 	 */
445
-	public function get_minimum_price( $context = 'view' ) {
446
-        return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
445
+	public function get_minimum_price($context = 'view') {
446
+        return wpinv_sanitize_amount($this->get_prop('minimum_price', $context));
447 447
     }
448 448
 
449 449
     /**
@@ -453,8 +453,8 @@  discard block
 block discarded – undo
453 453
 	 * @param  string $context View or edit context.
454 454
 	 * @return int
455 455
 	 */
456
-	public function get_is_recurring( $context = 'view' ) {
457
-        return (int) $this->get_prop( 'is_recurring', $context );
456
+	public function get_is_recurring($context = 'view') {
457
+        return (int) $this->get_prop('is_recurring', $context);
458 458
 	}
459 459
 	
460 460
 	/**
@@ -464,9 +464,9 @@  discard block
 block discarded – undo
464 464
 	 * @param  string $context View or edit context.
465 465
 	 * @return float
466 466
 	 */
467
-	public function get_recurring_price( $context = 'view' ) {
468
-		$price = $this->get_price( $context );
469
-        return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
467
+	public function get_recurring_price($context = 'view') {
468
+		$price = $this->get_price($context);
469
+        return wpinv_sanitize_amount(apply_filters('wpinv_get_recurring_item_price', $price, $this->ID));
470 470
 	}
471 471
 
472 472
 	/**
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 	 * @return string
478 478
 	 */
479 479
     public function get_the_recurring_price() {
480
-        return wpinv_price( wpinv_format_amount( $this->get_recurring_price() ) );
480
+        return wpinv_price(wpinv_format_amount($this->get_recurring_price()));
481 481
 	}
482 482
 
483 483
 	/**
@@ -498,15 +498,15 @@  discard block
 block discarded – undo
498 498
 		$period   = $this->get_recurring_period();
499 499
 		$interval = $this->get_recurring_interval();
500 500
 
501
-		if ( $this->has_free_trial() ) {
501
+		if ($this->has_free_trial()) {
502 502
 			$period   = $this->get_trial_period();
503 503
 			$interval = $this->get_trial_interval();
504 504
 		}
505 505
 
506
-		$period       = $periods[ $period ];
507
-		$interval     = empty( $interval ) ? 1 : $interval;
508
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
509
-        return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
506
+		$period       = $periods[$period];
507
+		$interval     = empty($interval) ? 1 : $interval;
508
+		$next_renewal = strtotime("+$interval $period", current_time('timestamp'));
509
+        return apply_filters('wpinv_get_first_renewal_date', $next_renewal, $this);
510 510
     }
511 511
 
512 512
     /**
@@ -516,14 +516,14 @@  discard block
 block discarded – undo
516 516
 	 * @param  bool $full Return abbreviation or in full.
517 517
 	 * @return string
518 518
 	 */
519
-	public function get_recurring_period( $full = false ) {
520
-        $period = $this->get_prop( 'recurring_period', 'view' );
519
+	public function get_recurring_period($full = false) {
520
+        $period = $this->get_prop('recurring_period', 'view');
521 521
 
522
-        if ( $full && ! is_bool( $full ) ) {
522
+        if ($full && !is_bool($full)) {
523 523
             $full = false;
524 524
         }
525 525
 
526
-        return getpaid_sanitize_recurring_period( $period, $full );
526
+        return getpaid_sanitize_recurring_period($period, $full);
527 527
     }
528 528
 
529 529
     /**
@@ -533,10 +533,10 @@  discard block
 block discarded – undo
533 533
 	 * @param  string $context View or edit context.
534 534
 	 * @return int
535 535
 	 */
536
-	public function get_recurring_interval( $context = 'view' ) {
537
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
536
+	public function get_recurring_interval($context = 'view') {
537
+		$interval = absint($this->get_prop('recurring_interval', $context));
538 538
 
539
-		if ( $interval < 1 ) {
539
+		if ($interval < 1) {
540 540
 			$interval = 1;
541 541
 		}
542 542
 
@@ -550,8 +550,8 @@  discard block
 block discarded – undo
550 550
 	 * @param  string $context View or edit context.
551 551
 	 * @return int
552 552
 	 */
553
-	public function get_recurring_limit( $context = 'view' ) {
554
-        return (int) $this->get_prop( 'recurring_limit', $context );
553
+	public function get_recurring_limit($context = 'view') {
554
+        return (int) $this->get_prop('recurring_limit', $context);
555 555
     }
556 556
 
557 557
     /**
@@ -561,8 +561,8 @@  discard block
 block discarded – undo
561 561
 	 * @param  string $context View or edit context.
562 562
 	 * @return int
563 563
 	 */
564
-	public function get_is_free_trial( $context = 'view' ) {
565
-        return (int) $this->get_prop( 'is_free_trial', $context );
564
+	public function get_is_free_trial($context = 'view') {
565
+        return (int) $this->get_prop('is_free_trial', $context);
566 566
     }
567 567
 
568 568
     /**
@@ -572,8 +572,8 @@  discard block
 block discarded – undo
572 572
 	 * @param  string $context View or edit context.
573 573
 	 * @return int
574 574
 	 */
575
-	public function get_free_trial( $context = 'view' ) {
576
-        return $this->get_is_free_trial( $context );
575
+	public function get_free_trial($context = 'view') {
576
+        return $this->get_is_free_trial($context);
577 577
     }
578 578
 
579 579
     /**
@@ -583,14 +583,14 @@  discard block
 block discarded – undo
583 583
 	 * @param  bool $full Return abbreviation or in full.
584 584
 	 * @return string
585 585
 	 */
586
-	public function get_trial_period( $full = false ) {
587
-        $period = $this->get_prop( 'trial_period', 'view' );
586
+	public function get_trial_period($full = false) {
587
+        $period = $this->get_prop('trial_period', 'view');
588 588
 
589
-        if ( $full && ! is_bool( $full ) ) {
589
+        if ($full && !is_bool($full)) {
590 590
             $full = false;
591 591
         }
592 592
 
593
-        return getpaid_sanitize_recurring_period( $period, $full );
593
+        return getpaid_sanitize_recurring_period($period, $full);
594 594
     }
595 595
 
596 596
     /**
@@ -600,8 +600,8 @@  discard block
 block discarded – undo
600 600
 	 * @param  string $context View or edit context.
601 601
 	 * @return int
602 602
 	 */
603
-	public function get_trial_interval( $context = 'view' ) {
604
-        return (int) $this->get_prop( 'trial_interval', $context );
603
+	public function get_trial_interval($context = 'view') {
604
+        return (int) $this->get_prop('trial_interval', $context);
605 605
 	}
606 606
 	
607 607
 	/**
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
 	 * @return string
612 612
 	 */
613 613
 	public function get_edit_url() {
614
-        return get_edit_post_link( $this->get_id() );
614
+        return get_edit_post_link($this->get_id());
615 615
 	}
616 616
 
617 617
 	/**
@@ -625,35 +625,35 @@  discard block
 block discarded – undo
625 625
 	 * @since 1.0.15
626 626
 	 * @return int
627 627
 	 */
628
-	public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
628
+	public static function get_item_id_by_field($value, $field = 'custom_id', $type = '') {
629 629
 
630 630
 		// Trim the value.
631
-		$value = sanitize_text_field( $value );
632
-		if ( empty( $value ) ) {
631
+		$value = sanitize_text_field($value);
632
+		if (empty($value)) {
633 633
 			return 0;
634 634
 		}
635 635
 
636 636
         // Valid fields.
637
-        $fields = array( 'custom_id', 'name', 'slug' );
637
+        $fields = array('custom_id', 'name', 'slug');
638 638
 
639 639
 		// Ensure a field has been passed.
640
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
640
+		if (empty($field) || !in_array($field, $fields)) {
641 641
 			return 0;
642 642
 		}
643 643
 
644
-		if ( $field == 'name' ) {
644
+		if ($field == 'name') {
645 645
 			$field = 'slug';
646 646
 		}
647 647
 
648 648
 		// Maybe retrieve from the cache.
649
-		$item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
650
-		if ( ! empty( $item_id ) ) {
649
+		$item_id = wp_cache_get($value, "getpaid_{$type}_item_{$field}s_to_item_ids");
650
+		if (!empty($item_id)) {
651 651
 			return $item_id;
652 652
 		}
653 653
 
654 654
 		// Fetch from the db.
655 655
 		$items = array();
656
-		if ( $field == 'slug' ) {
656
+		if ($field == 'slug') {
657 657
 			$items = get_posts(
658 658
 				array(
659 659
 					'post_type'      => 'wpi_item',
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
 			);
665 665
 		}
666 666
 
667
-		if ( $field =='custom_id' ) {
667
+		if ($field == 'custom_id') {
668 668
 			$items = get_posts(
669 669
 				array(
670 670
 					'post_type'      => 'wpi_item',
@@ -684,12 +684,12 @@  discard block
 block discarded – undo
684 684
 			);
685 685
 		}
686 686
 
687
-		if ( empty( $items ) ) {
687
+		if (empty($items)) {
688 688
 			return 0;
689 689
 		}
690 690
 
691 691
 		// Update the cache with our data
692
-		wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
692
+		wp_cache_set($value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids");
693 693
 
694 694
 		return $items[0]->ID;
695 695
     }
@@ -697,19 +697,19 @@  discard block
 block discarded – undo
697 697
     /**
698 698
      * Margic method for retrieving a property.
699 699
      */
700
-    public function __get( $key ) {
700
+    public function __get($key) {
701 701
 
702 702
         // Check if we have a helper method for that.
703
-        if ( method_exists( $this, 'get_' . $key ) ) {
704
-            return call_user_func( array( $this, 'get_' . $key ) );
703
+        if (method_exists($this, 'get_' . $key)) {
704
+            return call_user_func(array($this, 'get_' . $key));
705 705
         }
706 706
 
707 707
         // Check if the key is in the associated $post object.
708
-        if ( ! empty( $this->post ) && isset( $this->post->$key ) ) {
708
+        if (!empty($this->post) && isset($this->post->$key)) {
709 709
             return $this->post->$key;
710 710
         }
711 711
 
712
-        return $this->get_prop( $key );
712
+        return $this->get_prop($key);
713 713
 
714 714
     }
715 715
 
@@ -728,11 +728,11 @@  discard block
 block discarded – undo
728 728
 	 *
729 729
 	 * @since 1.0.19
730 730
 	 */
731
-	public function set_parent_id( $value ) {
732
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
731
+	public function set_parent_id($value) {
732
+		if ($value && ($value === $this->get_id() || !get_post($value))) {
733 733
 			return;
734 734
 		}
735
-		$this->set_prop( 'parent_id', absint( $value ) );
735
+		$this->set_prop('parent_id', absint($value));
736 736
 	}
737 737
 
738 738
     /**
@@ -742,10 +742,10 @@  discard block
 block discarded – undo
742 742
 	 * @param  string $status New status.
743 743
 	 * @return array details of change.
744 744
 	 */
745
-	public function set_status( $status ) {
745
+	public function set_status($status) {
746 746
         $old_status = $this->get_status();
747 747
 
748
-        $this->set_prop( 'status', $status );
748
+        $this->set_prop('status', $status);
749 749
 
750 750
 		return array(
751 751
 			'from' => $old_status,
@@ -758,8 +758,8 @@  discard block
 block discarded – undo
758 758
 	 *
759 759
 	 * @since 1.0.19
760 760
 	 */
761
-	public function set_version( $value ) {
762
-		$this->set_prop( 'version', $value );
761
+	public function set_version($value) {
762
+		$this->set_prop('version', $value);
763 763
     }
764 764
 
765 765
     /**
@@ -769,11 +769,11 @@  discard block
 block discarded – undo
769 769
 	 * @param string $value Value to set.
770 770
      * @return bool Whether or not the date was set.
771 771
 	 */
772
-	public function set_date_created( $value ) {
773
-        $date = strtotime( $value );
772
+	public function set_date_created($value) {
773
+        $date = strtotime($value);
774 774
 
775
-        if ( $date ) {
776
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
775
+        if ($date) {
776
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
777 777
             return true;
778 778
         }
779 779
 
@@ -788,11 +788,11 @@  discard block
 block discarded – undo
788 788
 	 * @param string $value Value to set.
789 789
      * @return bool Whether or not the date was set.
790 790
 	 */
791
-	public function set_date_modified( $value ) {
792
-        $date = strtotime( $value );
791
+	public function set_date_modified($value) {
792
+        $date = strtotime($value);
793 793
 
794
-        if ( $date ) {
795
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
794
+        if ($date) {
795
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
796 796
             return true;
797 797
         }
798 798
 
@@ -806,9 +806,9 @@  discard block
 block discarded – undo
806 806
 	 * @since 1.0.19
807 807
 	 * @param  string $value New name.
808 808
 	 */
809
-	public function set_name( $value ) {
810
-        $name = sanitize_text_field( $value );
811
-		$this->set_prop( 'name', $name );
809
+	public function set_name($value) {
810
+        $name = sanitize_text_field($value);
811
+		$this->set_prop('name', $name);
812 812
     }
813 813
 
814 814
     /**
@@ -817,8 +817,8 @@  discard block
 block discarded – undo
817 817
 	 * @since 1.0.19
818 818
 	 * @param  string $value New name.
819 819
 	 */
820
-	public function set_title( $value ) {
821
-		$this->set_name( $value );
820
+	public function set_title($value) {
821
+		$this->set_name($value);
822 822
     }
823 823
 
824 824
     /**
@@ -827,9 +827,9 @@  discard block
 block discarded – undo
827 827
 	 * @since 1.0.19
828 828
 	 * @param  string $value New description.
829 829
 	 */
830
-	public function set_description( $value ) {
831
-        $description = wp_kses_post( $value );
832
-		return $this->set_prop( 'description', $description );
830
+	public function set_description($value) {
831
+        $description = wp_kses_post($value);
832
+		return $this->set_prop('description', $description);
833 833
     }
834 834
 
835 835
     /**
@@ -838,8 +838,8 @@  discard block
 block discarded – undo
838 838
 	 * @since 1.0.19
839 839
 	 * @param  string $value New description.
840 840
 	 */
841
-	public function set_excerpt( $value ) {
842
-		$this->set_description( $value );
841
+	public function set_excerpt($value) {
842
+		$this->set_description($value);
843 843
     }
844 844
 
845 845
     /**
@@ -848,8 +848,8 @@  discard block
 block discarded – undo
848 848
 	 * @since 1.0.19
849 849
 	 * @param  string $value New description.
850 850
 	 */
851
-	public function set_summary( $value ) {
852
-		$this->set_description( $value );
851
+	public function set_summary($value) {
852
+		$this->set_description($value);
853 853
     }
854 854
 
855 855
     /**
@@ -858,8 +858,8 @@  discard block
 block discarded – undo
858 858
 	 * @since 1.0.19
859 859
 	 * @param  int $value New author.
860 860
 	 */
861
-	public function set_author( $value ) {
862
-		$this->set_prop( 'author', (int) $value );
861
+	public function set_author($value) {
862
+		$this->set_prop('author', (int) $value);
863 863
 	}
864 864
 	
865 865
 	/**
@@ -868,8 +868,8 @@  discard block
 block discarded – undo
868 868
 	 * @since 1.0.19
869 869
 	 * @param  int $value New author.
870 870
 	 */
871
-	public function set_owner( $value ) {
872
-		$this->set_author( $value );
871
+	public function set_owner($value) {
872
+		$this->set_author($value);
873 873
     }
874 874
 
875 875
     /**
@@ -878,8 +878,8 @@  discard block
 block discarded – undo
878 878
 	 * @since 1.0.19
879 879
 	 * @param  float $value New price.
880 880
 	 */
881
-	public function set_price( $value ) {
882
-        $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
881
+	public function set_price($value) {
882
+        $this->set_prop('price', (float) wpinv_sanitize_amount($value));
883 883
     }
884 884
 
885 885
     /**
@@ -888,8 +888,8 @@  discard block
 block discarded – undo
888 888
 	 * @since 1.0.19
889 889
 	 * @param  string $value new rule.
890 890
 	 */
891
-	public function set_vat_rule( $value ) {
892
-        $this->set_prop( 'vat_rule', $value );
891
+	public function set_vat_rule($value) {
892
+        $this->set_prop('vat_rule', $value);
893 893
     }
894 894
 
895 895
     /**
@@ -898,8 +898,8 @@  discard block
 block discarded – undo
898 898
 	 * @since 1.0.19
899 899
 	 * @param  string $value new class.
900 900
 	 */
901
-	public function set_vat_class( $value ) {
902
-        $this->set_prop( 'vat_class', $value );
901
+	public function set_vat_class($value) {
902
+        $this->set_prop('vat_class', $value);
903 903
     }
904 904
 
905 905
     /**
@@ -909,13 +909,13 @@  discard block
 block discarded – undo
909 909
 	 * @param  string $value new item type.
910 910
 	 * @return string
911 911
 	 */
912
-	public function set_type( $value ) {
912
+	public function set_type($value) {
913 913
 
914
-        if ( empty( $value ) ) {
914
+        if (empty($value)) {
915 915
             $value = 'custom';
916 916
         }
917 917
 
918
-        $this->set_prop( 'type', $value );
918
+        $this->set_prop('type', $value);
919 919
     }
920 920
 
921 921
     /**
@@ -924,8 +924,8 @@  discard block
 block discarded – undo
924 924
 	 * @since 1.0.19
925 925
 	 * @param  string $value new custom id.
926 926
 	 */
927
-	public function set_custom_id( $value ) {
928
-        $this->set_prop( 'custom_id', $value );
927
+	public function set_custom_id($value) {
928
+        $this->set_prop('custom_id', $value);
929 929
     }
930 930
 
931 931
     /**
@@ -934,8 +934,8 @@  discard block
 block discarded – undo
934 934
 	 * @since 1.0.19
935 935
 	 * @param  string $value new custom name.
936 936
 	 */
937
-	public function set_custom_name( $value ) {
938
-        $this->set_prop( 'custom_name', $value );
937
+	public function set_custom_name($value) {
938
+        $this->set_prop('custom_name', $value);
939 939
     }
940 940
 
941 941
     /**
@@ -944,8 +944,8 @@  discard block
 block discarded – undo
944 944
 	 * @since 1.0.19
945 945
 	 * @param  string $value new custom singular name.
946 946
 	 */
947
-	public function set_custom_singular_name( $value ) {
948
-        $this->set_prop( 'custom_singular_name', $value );
947
+	public function set_custom_singular_name($value) {
948
+        $this->set_prop('custom_singular_name', $value);
949 949
     }
950 950
 
951 951
     /**
@@ -954,8 +954,8 @@  discard block
 block discarded – undo
954 954
 	 * @since 1.0.19
955 955
 	 * @param  int|bool $value whether or not the item is editable.
956 956
 	 */
957
-	public function set_is_editable( $value ) {
958
-		$this->set_prop( 'is_editable', (int) $value );
957
+	public function set_is_editable($value) {
958
+		$this->set_prop('is_editable', (int) $value);
959 959
     }
960 960
 
961 961
     /**
@@ -964,8 +964,8 @@  discard block
 block discarded – undo
964 964
 	 * @since 1.0.19
965 965
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
966 966
 	 */
967
-	public function set_is_dynamic_pricing( $value ) {
968
-        $this->set_prop( 'is_dynamic_pricing', (int) $value );
967
+	public function set_is_dynamic_pricing($value) {
968
+        $this->set_prop('is_dynamic_pricing', (int) $value);
969 969
     }
970 970
 
971 971
     /**
@@ -974,8 +974,8 @@  discard block
 block discarded – undo
974 974
 	 * @since 1.0.19
975 975
 	 * @param  float $value minimum price.
976 976
 	 */
977
-	public function set_minimum_price( $value ) {
978
-        $this->set_prop( 'minimum_price',  (float) wpinv_sanitize_amount( $value ) );
977
+	public function set_minimum_price($value) {
978
+        $this->set_prop('minimum_price', (float) wpinv_sanitize_amount($value));
979 979
     }
980 980
 
981 981
     /**
@@ -984,8 +984,8 @@  discard block
 block discarded – undo
984 984
 	 * @since 1.0.19
985 985
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
986 986
 	 */
987
-	public function set_is_recurring( $value ) {
988
-        $this->set_prop( 'is_recurring', (int) $value );
987
+	public function set_is_recurring($value) {
988
+        $this->set_prop('is_recurring', (int) $value);
989 989
     }
990 990
 
991 991
     /**
@@ -994,8 +994,8 @@  discard block
 block discarded – undo
994 994
 	 * @since 1.0.19
995 995
 	 * @param  string $value new period.
996 996
 	 */
997
-	public function set_recurring_period( $value ) {
998
-        $this->set_prop( 'recurring_period', $value );
997
+	public function set_recurring_period($value) {
998
+        $this->set_prop('recurring_period', $value);
999 999
     }
1000 1000
 
1001 1001
     /**
@@ -1004,8 +1004,8 @@  discard block
 block discarded – undo
1004 1004
 	 * @since 1.0.19
1005 1005
 	 * @param  int $value recurring interval.
1006 1006
 	 */
1007
-	public function set_recurring_interval( $value ) {
1008
-        return $this->set_prop( 'recurring_interval', (int) $value );
1007
+	public function set_recurring_interval($value) {
1008
+        return $this->set_prop('recurring_interval', (int) $value);
1009 1009
     }
1010 1010
 
1011 1011
     /**
@@ -1014,8 +1014,8 @@  discard block
 block discarded – undo
1014 1014
 	 * @param  int $value The recurring limit.
1015 1015
 	 * @return int
1016 1016
 	 */
1017
-	public function set_recurring_limit( $value ) {
1018
-        $this->set_prop( 'recurring_limit', (int) $value );
1017
+	public function set_recurring_limit($value) {
1018
+        $this->set_prop('recurring_limit', (int) $value);
1019 1019
     }
1020 1020
 
1021 1021
     /**
@@ -1024,8 +1024,8 @@  discard block
 block discarded – undo
1024 1024
 	 * @since 1.0.19
1025 1025
 	 * @param  int|bool $value whether or not it has a free trial.
1026 1026
 	 */
1027
-	public function set_is_free_trial( $value ) {
1028
-        $this->set_prop( 'is_free_trial', (int) $value );
1027
+	public function set_is_free_trial($value) {
1028
+        $this->set_prop('is_free_trial', (int) $value);
1029 1029
     }
1030 1030
 
1031 1031
     /**
@@ -1034,8 +1034,8 @@  discard block
 block discarded – undo
1034 1034
 	 * @since 1.0.19
1035 1035
 	 * @param  string $value trial period.
1036 1036
 	 */
1037
-	public function set_trial_period( $value ) {
1038
-        $this->set_prop( 'trial_period', $value );
1037
+	public function set_trial_period($value) {
1038
+        $this->set_prop('trial_period', $value);
1039 1039
     }
1040 1040
 
1041 1041
     /**
@@ -1044,8 +1044,8 @@  discard block
 block discarded – undo
1044 1044
 	 * @since 1.0.19
1045 1045
 	 * @param  int $value trial interval.
1046 1046
 	 */
1047
-	public function set_trial_interval( $value ) {
1048
-        $this->set_prop( 'trial_interval', $value );
1047
+	public function set_trial_interval($value) {
1048
+        $this->set_prop('trial_interval', $value);
1049 1049
     }
1050 1050
 
1051 1051
     /**
@@ -1054,11 +1054,11 @@  discard block
 block discarded – undo
1054 1054
      * @deprecated
1055 1055
 	 * @return int item id
1056 1056
      */
1057
-    public function create( $data = array() ) {
1057
+    public function create($data = array()) {
1058 1058
 
1059 1059
 		// Set the properties.
1060
-		if ( is_array( $data ) ) {
1061
-			$this->set_props( $data );
1060
+		if (is_array($data)) {
1061
+			$this->set_props($data);
1062 1062
 		}
1063 1063
 
1064 1064
 		// Save the item.
@@ -1072,8 +1072,8 @@  discard block
 block discarded – undo
1072 1072
      * @deprecated
1073 1073
 	 * @return int item id
1074 1074
      */
1075
-    public function update( $data = array() ) {
1076
-        return $this->create( $data );
1075
+    public function update($data = array()) {
1076
+        return $this->create($data);
1077 1077
     }
1078 1078
 
1079 1079
     /*
@@ -1113,7 +1113,7 @@  discard block
 block discarded – undo
1113 1113
 	 */
1114 1114
     public function has_free_trial() {
1115 1115
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
1116
-        return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
1116
+        return (bool) apply_filters('wpinv_item_has_free_trial', $has_trial, $this->ID, $this);
1117 1117
     }
1118 1118
 
1119 1119
     /**
@@ -1123,8 +1123,8 @@  discard block
 block discarded – undo
1123 1123
 	 * @return bool
1124 1124
 	 */
1125 1125
     public function is_free() {
1126
-        $is_free   = $this->get_price() == 0;
1127
-        return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
1126
+        $is_free = $this->get_price() == 0;
1127
+        return (bool) apply_filters('wpinv_is_free_item', $is_free, $this->ID, $this);
1128 1128
     }
1129 1129
 
1130 1130
     /**
@@ -1133,9 +1133,9 @@  discard block
 block discarded – undo
1133 1133
 	 * @param array|string $status Status to check.
1134 1134
 	 * @return bool
1135 1135
 	 */
1136
-	public function has_status( $status ) {
1137
-		$has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1138
-		return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1136
+	public function has_status($status) {
1137
+		$has_status = (is_array($status) && in_array($this->get_status(), $status, true)) || $this->get_status() === $status;
1138
+		return (bool) apply_filters('getpaid_item_has_status', $has_status, $this, $status);
1139 1139
     }
1140 1140
 
1141 1141
     /**
@@ -1144,9 +1144,9 @@  discard block
 block discarded – undo
1144 1144
 	 * @param array|string $type Type to check.
1145 1145
 	 * @return bool
1146 1146
 	 */
1147
-	public function is_type( $type ) {
1148
-		$is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1149
-		return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1147
+	public function is_type($type) {
1148
+		$is_type = (is_array($type) && in_array($this->get_type(), $type, true)) || $this->get_type() === $type;
1149
+		return (bool) apply_filters('getpaid_item_is_type', $is_type, $this, $type);
1150 1150
 	}
1151 1151
 
1152 1152
     /**
@@ -1157,7 +1157,7 @@  discard block
 block discarded – undo
1157 1157
 	 */
1158 1158
     public function is_editable() {
1159 1159
         $is_editable = $this->get_is_editable();
1160
-        return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1160
+        return (bool) apply_filters('wpinv_item_is_editable', $is_editable, $this->ID, $this);
1161 1161
 	}
1162 1162
 
1163 1163
 	/**
@@ -1176,11 +1176,11 @@  discard block
 block discarded – undo
1176 1176
     public function can_purchase() {
1177 1177
         $can_purchase = $this->exists();
1178 1178
 
1179
-        if ( ! current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) {
1179
+        if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') {
1180 1180
             $can_purchase = false;
1181 1181
         }
1182 1182
 
1183
-        return (bool) apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );
1183
+        return (bool) apply_filters('wpinv_can_purchase_item', $can_purchase, $this);
1184 1184
     }
1185 1185
 
1186 1186
     /**
@@ -1190,6 +1190,6 @@  discard block
 block discarded – undo
1190 1190
 	 * @return bool
1191 1191
 	 */
1192 1192
     public function supports_dynamic_pricing() {
1193
-        return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1193
+        return (bool) apply_filters('wpinv_item_supports_dynamic_pricing', true, $this);
1194 1194
     }
1195 1195
 }
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports-report-earnings.php 1 patch
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Reports_Report_Earnings Class.
@@ -20,14 +20,14 @@  discard block
 block discarded – undo
20 20
 
21 21
 		$graphs = array(
22 22
 
23
-            'total'      => __( 'Earnings', 'invoicing' ),
24
-            'discount'   => __( 'Discount', 'invoicing' ),
25
-			'fees_total' => __( 'Fees', 'invoicing' ),
26
-			'tax'        => __( 'Tax', 'invoicing' ),
23
+            'total'      => __('Earnings', 'invoicing'),
24
+            'discount'   => __('Discount', 'invoicing'),
25
+			'fees_total' => __('Fees', 'invoicing'),
26
+			'tax'        => __('Tax', 'invoicing'),
27 27
 
28 28
 		);
29 29
 
30
-		return apply_filters( 'getpaid_earning_graphs', $graphs );
30
+		return apply_filters('getpaid_earning_graphs', $graphs);
31 31
 
32 32
 	}
33 33
 
@@ -35,19 +35,19 @@  discard block
 block discarded – undo
35 35
 	 * Retrieves the earning sql.
36 36
 	 *
37 37
 	 */
38
-	public function get_sql( $range ) {
38
+	public function get_sql($range) {
39 39
 		global $wpdb;
40 40
 
41 41
 		$table      = $wpdb->prefix . 'getpaid_invoices';
42
-		$clauses    = $this->get_range_sql( $range );
43
-		$graphs     = array_keys( $this->get_graphs() );
42
+		$clauses    = $this->get_range_sql($range);
43
+		$graphs     = array_keys($this->get_graphs());
44 44
 		$graphs_sql = array();
45 45
 
46
-		foreach ( $graphs as $graph ) {
46
+		foreach ($graphs as $graph) {
47 47
 			$graphs_sql[] = "SUM( meta.$graph ) AS $graph";
48 48
 		}
49 49
 
50
-		$graphs_sql = implode( ', ', $graphs_sql );
50
+		$graphs_sql = implode(', ', $graphs_sql);
51 51
 		$sql        = "SELECT {$clauses[0]} AS completed_date, $graphs_sql
52 52
             FROM $wpdb->posts
53 53
             LEFT JOIN $table as meta ON meta.post_id = $wpdb->posts.ID
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
             GROUP BY {$clauses[0]}
59 59
         ";
60 60
 
61
-		return apply_filters( 'getpaid_earning_graphs_get_sql', $sql, $range );
61
+		return apply_filters('getpaid_earning_graphs_get_sql', $sql, $range);
62 62
 
63 63
 	}
64 64
 
@@ -68,68 +68,68 @@  discard block
 block discarded – undo
68 68
 	 */
69 69
 	public function prepare_stats() {
70 70
 		global $wpdb;
71
-		$this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) );
71
+		$this->stats = $wpdb->get_results($this->get_sql($this->get_range()));
72 72
 	}
73 73
 
74 74
 	/**
75 75
 	 * Retrieves report labels.
76 76
 	 *
77 77
 	 */
78
-	public function get_labels( $range ) {
78
+	public function get_labels($range) {
79 79
 
80 80
 		$labels = array(
81 81
 			'today'     => $this->get_hours_in_a_day(),
82 82
 			'yesterday' => $this->get_hours_in_a_day(),
83
-			'7_days'    => $this->get_days_in_period( 7 ),
84
-			'30_days'   => $this->get_days_in_period( 30 ),
85
-			'60_days'   => $this->get_days_in_period( 60 ),
86
-			'90_days'   => $this->get_weeks_in_period( 90 ),
87
-			'180_days'  => $this->get_weeks_in_period( 180 ),
88
-			'360_days'  => $this->get_weeks_in_period( 360 ),
83
+			'7_days'    => $this->get_days_in_period(7),
84
+			'30_days'   => $this->get_days_in_period(30),
85
+			'60_days'   => $this->get_days_in_period(60),
86
+			'90_days'   => $this->get_weeks_in_period(90),
87
+			'180_days'  => $this->get_weeks_in_period(180),
88
+			'360_days'  => $this->get_weeks_in_period(360),
89 89
 		);
90 90
 
91
-		$label = isset( $labels[ $range ] ) ? $labels[ $range ] : $labels[ '7_days' ];
92
-		return apply_filters( 'getpaid_earning_graphs_get_labels', $label, $range );
91
+		$label = isset($labels[$range]) ? $labels[$range] : $labels['7_days'];
92
+		return apply_filters('getpaid_earning_graphs_get_labels', $label, $range);
93 93
 	}
94 94
 
95 95
 	/**
96 96
 	 * Retrieves report datasets.
97 97
 	 *
98 98
 	 */
99
-	public function get_datasets( $labels ) {
99
+	public function get_datasets($labels) {
100 100
 
101 101
 		$datasets = array();
102 102
 
103
-		foreach ( $this->get_graphs() as $key => $label ) {
104
-			$datasets[ $key ] = array(
103
+		foreach ($this->get_graphs() as $key => $label) {
104
+			$datasets[$key] = array(
105 105
 				'label' => $label,
106
-				'data'  => $this->get_data( $key, $labels )
106
+				'data'  => $this->get_data($key, $labels)
107 107
 			);
108 108
 		}
109 109
 
110
-		return apply_filters( 'getpaid_earning_graphs_get_datasets', $datasets, $labels );
110
+		return apply_filters('getpaid_earning_graphs_get_datasets', $datasets, $labels);
111 111
 	}
112 112
 
113 113
 	/**
114 114
 	 * Retrieves report data.
115 115
 	 *
116 116
 	 */
117
-	public function get_data( $key, $labels ) {
117
+	public function get_data($key, $labels) {
118 118
 
119
-		$data     = wp_list_pluck( $this->stats, $key, 'completed_date' );
119
+		$data     = wp_list_pluck($this->stats, $key, 'completed_date');
120 120
 		$prepared = array();
121 121
 
122
-		foreach ( $labels as $label ) {
122
+		foreach ($labels as $label) {
123 123
 
124 124
 			$value = 0;
125
-			if ( isset( $data[ $label ] ) ) {
126
-				$value = wpinv_round_amount( wpinv_sanitize_amount( $data[ $label ] ) );
125
+			if (isset($data[$label])) {
126
+				$value = wpinv_round_amount(wpinv_sanitize_amount($data[$label]));
127 127
 			}
128 128
 
129 129
 			$prepared[] = $value;
130 130
 		}
131 131
 
132
-		return apply_filters( 'getpaid_earning_graphs_get_data', $prepared, $key, $labels );
132
+		return apply_filters('getpaid_earning_graphs_get_data', $prepared, $key, $labels);
133 133
 
134 134
 	}
135 135
 
@@ -139,15 +139,15 @@  discard block
 block discarded – undo
139 139
 	 */
140 140
 	public function display() {
141 141
 
142
-		$labels     = $this->get_labels( $this->get_range() );
142
+		$labels     = $this->get_labels($this->get_range());
143 143
 		$chart_data = array(
144
-			'labels'   => array_values( $labels ),
145
-			'datasets' => $this->get_datasets( array_keys( $labels ) ),
144
+			'labels'   => array_values($labels),
145
+			'datasets' => $this->get_datasets(array_keys($labels)),
146 146
 		);
147 147
 
148 148
 		?>
149 149
 
150
-			<?php foreach ( $chart_data['datasets'] as $key => $dataset ) : ?>
150
+			<?php foreach ($chart_data['datasets'] as $key => $dataset) : ?>
151 151
 				<div class="row mb-4">
152 152
 					<div class="col-12">
153 153
 						<div class="card m-0 p-0" style="max-width:100%">
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 								<?php $this->display_range_selector(); ?>
157 157
 							</div>
158 158
 							<div class="card-body">
159
-								<?php $this->display_graph( $key, $dataset, $chart_data['labels'] ); ?>
159
+								<?php $this->display_graph($key, $dataset, $chart_data['labels']); ?>
160 160
 							</div>
161 161
 						</div>
162 162
 					</div>
@@ -171,26 +171,26 @@  discard block
 block discarded – undo
171 171
 	 * Displays the actual report.
172 172
 	 *
173 173
 	 */
174
-	public function display_graph( $key, $dataset, $labels ) {
174
+	public function display_graph($key, $dataset, $labels) {
175 175
 
176 176
 		?>
177 177
 
178
-		<canvas id="getpaid-chartjs-earnings-<?php echo sanitize_key( $key ); ?>"></canvas>
178
+		<canvas id="getpaid-chartjs-earnings-<?php echo sanitize_key($key); ?>"></canvas>
179 179
 
180 180
 		<script>
181 181
 			window.addEventListener( 'DOMContentLoaded', function() {
182 182
 
183
-				var ctx = document.getElementById( 'getpaid-chartjs-earnings-<?php echo sanitize_key( $key ); ?>' ).getContext('2d');
183
+				var ctx = document.getElementById( 'getpaid-chartjs-earnings-<?php echo sanitize_key($key); ?>' ).getContext('2d');
184 184
 				new Chart(
185 185
 					ctx,
186 186
 					{
187 187
 						type: 'line',
188 188
 						data: {
189
-							'labels': <?php echo wp_json_encode( $labels ); ?>,
189
+							'labels': <?php echo wp_json_encode($labels); ?>,
190 190
 							'datasets': [
191 191
 								{
192
-									label: '<?php echo esc_attr( $dataset['label'] ); ?>',
193
-									data: <?php echo wp_json_encode( $dataset['data'] ); ?>,
192
+									label: '<?php echo esc_attr($dataset['label']); ?>',
193
+									data: <?php echo wp_json_encode($dataset['data']); ?>,
194 194
 									backgroundColor: 'rgba(54, 162, 235, 0.1)',
195 195
 									borderColor: 'rgb(54, 162, 235)',
196 196
 									borderWidth: 4,
@@ -242,15 +242,15 @@  discard block
 block discarded – undo
242 242
 			<form method="get" class="getpaid-filter-earnings">
243 243
 				<?php
244 244
 
245
-					getpaid_hidden_field( 'page', 'wpinv-reports' );
246
-					getpaid_hidden_field( 'tab', 'reports' );
245
+					getpaid_hidden_field('page', 'wpinv-reports');
246
+					getpaid_hidden_field('tab', 'reports');
247 247
 
248 248
 					$html = aui()->select(
249 249
 						array(
250 250
 							'name'        => 'date_range',
251
-							'id'          => 'view' . uniqid( '_' ),
252
-							'placeholder' => __( 'Select a date range', 'invoicing' ),
253
-							'label'       => __( 'Date Range', 'invoicing' ),
251
+							'id'          => 'view' . uniqid('_'),
252
+							'placeholder' => __('Select a date range', 'invoicing'),
253
+							'label'       => __('Date Range', 'invoicing'),
254 254
 							'options'     => $this->get_periods(),
255 255
 							'value'       => $this->get_range(),
256 256
 							'no_wrap'     => true,
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 						)
261 261
 					);
262 262
 
263
-					echo str_replace( 'custom-select', '', $html );
263
+					echo str_replace('custom-select', '', $html);
264 264
 				?>
265 265
 
266 266
 			</form>
Please login to merge, or discard this patch.
includes/libraries/wpinv-euvat/class-wpinv-euvat.php 1 patch
Spacing   +521 added lines, -521 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 class WPInv_EUVat {
10 10
 
@@ -24,125 +24,125 @@  discard block
 block discarded – undo
24 24
     public function init() {
25 25
 
26 26
         // If this is an admin page...
27
-        if ( is_admin() ) {
27
+        if (is_admin()) {
28 28
 
29 29
             // Register our scripts.
30
-            add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
31
-            add_action( 'wpinv_settings_sections_taxes', array( $this, 'section_vat_settings' ) );
32
-            add_action( 'wpinv_settings_taxes', array( $this, 'vat_settings' ) );
33
-            add_filter( 'wpinv_settings_taxes-vat_sanitize', array( $this, 'sanitize_vat_settings' ) );
34
-            add_filter( 'wpinv_settings_taxes-vat_rates_sanitize', array( $this, 'sanitize_vat_rates' ) );
35
-            add_action( 'wp_ajax_wpinv_add_vat_class', array( $this, 'add_class' ) );
36
-            add_action( 'wp_ajax_nopriv_wpinv_add_vat_class', array( $this, 'add_class' ) );
37
-            add_action( 'wp_ajax_wpinv_delete_vat_class', array( $this, 'delete_class' ) );
38
-            add_action( 'wp_ajax_nopriv_wpinv_delete_vat_class', array( $this, 'delete_class' ) );
39
-            add_action( 'wp_ajax_wpinv_update_vat_rates', array( $this, 'update_eu_rates' ) );
40
-            add_action( 'wp_ajax_nopriv_wpinv_update_vat_rates', array( $this, 'update_eu_rates' ) );
30
+            add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'));
31
+            add_action('wpinv_settings_sections_taxes', array($this, 'section_vat_settings'));
32
+            add_action('wpinv_settings_taxes', array($this, 'vat_settings'));
33
+            add_filter('wpinv_settings_taxes-vat_sanitize', array($this, 'sanitize_vat_settings'));
34
+            add_filter('wpinv_settings_taxes-vat_rates_sanitize', array($this, 'sanitize_vat_rates'));
35
+            add_action('wp_ajax_wpinv_add_vat_class', array($this, 'add_class'));
36
+            add_action('wp_ajax_nopriv_wpinv_add_vat_class', array($this, 'add_class'));
37
+            add_action('wp_ajax_wpinv_delete_vat_class', array($this, 'delete_class'));
38
+            add_action('wp_ajax_nopriv_wpinv_delete_vat_class', array($this, 'delete_class'));
39
+            add_action('wp_ajax_wpinv_update_vat_rates', array($this, 'update_eu_rates'));
40
+            add_action('wp_ajax_nopriv_wpinv_update_vat_rates', array($this, 'update_eu_rates'));
41 41
         }
42 42
 
43
-        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_vat_scripts' ) );
44
-        add_filter( 'wpinv_default_billing_country', array( $this, 'get_user_country' ), 10 );
45
-        add_filter( 'wpinv_get_user_country', array( $this, 'set_user_country' ), 10 );
46
-        add_action( 'wp_ajax_wpinv_vat_validate', array( $this, 'ajax_vat_validate' ) );
47
-        add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( $this, 'ajax_vat_validate' ) );
43
+        add_action('wp_enqueue_scripts', array($this, 'enqueue_vat_scripts'));
44
+        add_filter('wpinv_default_billing_country', array($this, 'get_user_country'), 10);
45
+        add_filter('wpinv_get_user_country', array($this, 'set_user_country'), 10);
46
+        add_action('wp_ajax_wpinv_vat_validate', array($this, 'ajax_vat_validate'));
47
+        add_action('wp_ajax_nopriv_wpinv_vat_validate', array($this, 'ajax_vat_validate'));
48 48
 
49
-        if ( wpinv_use_taxes() && self::allow_vat_rules() ) {
50
-            add_filter( 'wpinv_tax_rate', array( $this, 'get_rate' ), 10, 4 );
49
+        if (wpinv_use_taxes() && self::allow_vat_rules()) {
50
+            add_filter('wpinv_tax_rate', array($this, 'get_rate'), 10, 4);
51 51
         }
52 52
     }
53 53
 
54
-    public static function get_eu_states( $sort = true ) {
55
-        $eu_states = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' );
56
-        if ( $sort ) {
57
-            $sort = sort( $eu_states );
54
+    public static function get_eu_states($sort = true) {
55
+        $eu_states = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE');
56
+        if ($sort) {
57
+            $sort = sort($eu_states);
58 58
         }
59 59
 
60
-        return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort );
60
+        return apply_filters('wpinv_get_eu_states', $eu_states, $sort);
61 61
     }
62 62
 
63
-    public static function get_gst_countries( $sort = true ) {
64
-        $gst_countries  = array( 'AU', 'NZ', 'CA', 'CN' );
63
+    public static function get_gst_countries($sort = true) {
64
+        $gst_countries = array('AU', 'NZ', 'CA', 'CN');
65 65
 
66
-        if ( $sort ) {
67
-            $sort = sort( $gst_countries );
66
+        if ($sort) {
67
+            $sort = sort($gst_countries);
68 68
         }
69 69
 
70
-        return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort );
70
+        return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort);
71 71
     }
72 72
 
73
-    public static function is_eu_state( $country_code ) {
74
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false;
73
+    public static function is_eu_state($country_code) {
74
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false;
75 75
 
76
-        return apply_filters( 'wpinv_is_eu_state', $return, $country_code );
76
+        return apply_filters('wpinv_is_eu_state', $return, $country_code);
77 77
     }
78 78
 
79
-    public static function is_gst_country( $country_code ) {
80
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false;
79
+    public static function is_gst_country($country_code) {
80
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false;
81 81
 
82
-        return apply_filters( 'wpinv_is_gst_country', $return, $country_code );
82
+        return apply_filters('wpinv_is_gst_country', $return, $country_code);
83 83
     }
84 84
 
85 85
     public function enqueue_vat_scripts() {
86
-        if( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ) {
86
+        if (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules')) {
87 87
             $this->load_vat_scripts();
88 88
         }
89 89
     }
90 90
 
91
-    public function load_vat_scripts(){
92
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
91
+    public function load_vat_scripts() {
92
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
93 93
 
94
-        wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
95
-        wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
94
+        wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
95
+        wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
96 96
 
97
-        $vat_name   = $this->get_vat_name();
97
+        $vat_name = $this->get_vat_name();
98 98
 
99 99
         $vars = array();
100 100
         $vars['UseTaxes'] = wpinv_use_taxes();
101 101
         $vars['EUStates'] = self::get_eu_states();
102
-        $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' );
103
-        $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' );
104
-        $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
105
-        $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name );
106
-        $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name );
107
-        $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name );
108
-        $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name );
109
-        $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' );
102
+        $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing');
103
+        $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing');
104
+        $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
105
+        $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name);
106
+        $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name);
107
+        $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name);
108
+        $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name);
109
+        $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing');
110 110
         $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false;
111
-        $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' );
112
-        $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' );
113
-        $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' );
114
-        $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' );
115
-        $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' );
116
-        $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' );
117
-        $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' );
118
-        $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' );
119
-        $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name );
120
-        $vars['VatReseting'] = __( 'Reseting...', 'invoicing' );
121
-        $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
122
-        $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
123
-        $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' );
111
+        $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing');
112
+        $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing');
113
+        $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing');
114
+        $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing');
115
+        $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing');
116
+        $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing');
117
+        $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing');
118
+        $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing');
119
+        $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name);
120
+        $vars['VatReseting'] = __('Reseting...', 'invoicing');
121
+        $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
122
+        $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
123
+        $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing');
124 124
         $vars['isFront'] = is_admin() ? false : true;
125 125
         $vars['baseCountry'] = wpinv_get_default_country();
126
-        $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false );
127
-        $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false;
126
+        $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false);
127
+        $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false;
128 128
 
129
-        wp_enqueue_script( 'wpinv-vat-validation-script' );
130
-        wp_enqueue_script( 'wpinv-vat-script' );
131
-        wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars );
129
+        wp_enqueue_script('wpinv-vat-validation-script');
130
+        wp_enqueue_script('wpinv-vat-script');
131
+        wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars);
132 132
     }
133 133
 
134 134
     public static function enqueue_admin_scripts() {
135
-        if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) {
135
+        if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) {
136 136
             self::load_vat_scripts();
137 137
         }
138 138
     }
139 139
 
140
-    public static function section_vat_settings( $sections ) {
141
-        if ( !empty( $sections ) ) {
142
-            $sections['vat'] = __( 'EU VAT Settings', 'invoicing' );
140
+    public static function section_vat_settings($sections) {
141
+        if (!empty($sections)) {
142
+            $sections['vat'] = __('EU VAT Settings', 'invoicing');
143 143
 
144
-            if ( self::allow_vat_classes() ) {
145
-                $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' );
144
+            if (self::allow_vat_classes()) {
145
+                $sections['vat_rates'] = __('EU VAT Rates', 'invoicing');
146 146
             }
147 147
         }
148 148
         return $sections;
@@ -151,52 +151,52 @@  discard block
 block discarded – undo
151 151
     public static function vat_rates_settings() {
152 152
         $vat_classes = self::get_rate_classes();
153 153
         $vat_rates = array();
154
-        $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new';
155
-        $current_url = remove_query_arg( 'wpi_sub' );
154
+        $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new';
155
+        $current_url = remove_query_arg('wpi_sub');
156 156
 
157 157
         $vat_rates['vat_rates_header'] = array(
158 158
             'id' => 'vat_rates_header',
159
-            'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>',
159
+            'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>',
160 160
             'desc' => '',
161 161
             'type' => 'header',
162 162
             'size' => 'regular'
163 163
         );
164 164
         $vat_rates['vat_rates_class'] = array(
165 165
             'id'          => 'vat_rates_class',
166
-            'name'        => __( 'Edit VAT Rates', 'invoicing' ),
167
-            'desc'        => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ),
166
+            'name'        => __('Edit VAT Rates', 'invoicing'),
167
+            'desc'        => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'),
168 168
             'type'        => 'select',
169
-            'options'     => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ),
170
-            'placeholder' => __( 'Select a VAT Rate', 'invoicing' ),
169
+            'options'     => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))),
170
+            'placeholder' => __('Select a VAT Rate', 'invoicing'),
171 171
             'selected'    => $vat_class,
172 172
             'class'       => 'wpi_select2',
173 173
             'onchange'    => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;',
174 174
         );
175 175
 
176
-        if ( $vat_class != '_standard' && $vat_class != '_new' ) {
176
+        if ($vat_class != '_standard' && $vat_class != '_new') {
177 177
             $vat_rates['vat_rate_delete'] = array(
178 178
                 'id'   => 'vat_rate_delete',
179 179
                 'type' => 'vat_rate_delete',
180 180
             );
181 181
         }
182 182
 
183
-        if ( $vat_class == '_new' ) {
183
+        if ($vat_class == '_new') {
184 184
             $vat_rates['vat_rates_settings'] = array(
185 185
                 'id' => 'vat_rates_settings',
186
-                'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>',
186
+                'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>',
187 187
                 'type' => 'header',
188 188
             );
189 189
             $vat_rates['vat_rate_name'] = array(
190 190
                 'id'   => 'vat_rate_name',
191
-                'name' => __( 'Name', 'invoicing' ),
192
-                'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ),
191
+                'name' => __('Name', 'invoicing'),
192
+                'desc' => __('A short name for the new VAT Rate class', 'invoicing'),
193 193
                 'type' => 'text',
194 194
                 'size' => 'regular',
195 195
             );
196 196
             $vat_rates['vat_rate_desc'] = array(
197 197
                 'id'   => 'vat_rate_desc',
198
-                'name' => __( 'Description', 'invoicing' ),
199
-                'desc' => __( 'Manage VAT Rate class', 'invoicing' ),
198
+                'name' => __('Description', 'invoicing'),
199
+                'desc' => __('Manage VAT Rate class', 'invoicing'),
200 200
                 'type' => 'text',
201 201
                 'size' => 'regular',
202 202
             );
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
             $vat_rates['vat_rates'] = array(
209 209
                 'id'   => 'vat_rates',
210 210
                 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>',
211
-                'desc' => self::get_class_desc( $vat_class ),
211
+                'desc' => self::get_class_desc($vat_class),
212 212
                 'type' => 'vat_rates',
213 213
             );
214 214
         }
@@ -216,12 +216,12 @@  discard block
 block discarded – undo
216 216
         return $vat_rates;
217 217
     }
218 218
 
219
-    public static function vat_settings( $settings ) {
220
-        if ( !empty( $settings ) ) {
219
+    public static function vat_settings($settings) {
220
+        if (!empty($settings)) {
221 221
             $vat_settings = array();
222 222
             $vat_settings['vat_company_title'] = array(
223 223
                 'id' => 'vat_company_title',
224
-                'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>',
224
+                'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>',
225 225
                 'desc' => '',
226 226
                 'type' => 'header',
227 227
                 'size' => 'regular'
@@ -229,22 +229,22 @@  discard block
 block discarded – undo
229 229
 
230 230
             $vat_settings['vat_company_name'] = array(
231 231
                 'id' => 'vat_company_name',
232
-                'name' => __( 'Your Company Name', 'invoicing' ),
233
-                'desc' => wp_sprintf(__( 'Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
232
+                'name' => __('Your Company Name', 'invoicing'),
233
+                'desc' => wp_sprintf(__('Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
234 234
                 'type' => 'text',
235 235
                 'size' => 'regular',
236 236
             );
237 237
 
238 238
             $vat_settings['vat_number'] = array(
239 239
                 'id'   => 'vat_number',
240
-                'name' => __( 'Your VAT Number', 'invoicing' ),
240
+                'name' => __('Your VAT Number', 'invoicing'),
241 241
                 'type' => 'vat_number',
242 242
                 'size' => 'regular',
243 243
             );
244 244
 
245 245
             $vat_settings['vat_settings_title'] = array(
246 246
                 'id' => 'vat_settings_title',
247
-                'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>',
247
+                'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>',
248 248
                 'desc' => '',
249 249
                 'type' => 'header',
250 250
                 'size' => 'regular'
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
 
253 253
             $vat_settings['apply_vat_rules'] = array(
254 254
                 'id' => 'apply_vat_rules',
255
-                'name' => __( 'Enable VAT Rules', 'invoicing' ),
256
-                'desc' => __( 'Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable unless you know what you are doing.', 'invoicing' ) . '</font>',
255
+                'name' => __('Enable VAT Rules', 'invoicing'),
256
+                'desc' => __('Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable unless you know what you are doing.', 'invoicing') . '</font>',
257 257
                 'type' => 'checkbox',
258 258
                 'std' => '1'
259 259
             );
@@ -269,8 +269,8 @@  discard block
 block discarded – undo
269 269
 
270 270
             $vat_settings['vat_prevent_b2c_purchase'] = array(
271 271
                 'id' => 'vat_prevent_b2c_purchase',
272
-                'name' => __( 'Prevent EU B2C Sales', 'invoicing' ),
273
-                'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ),
272
+                'name' => __('Prevent EU B2C Sales', 'invoicing'),
273
+                'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'),
274 274
                 'type' => 'checkbox'
275 275
             );
276 276
 
@@ -278,22 +278,22 @@  discard block
 block discarded – undo
278 278
 
279 279
             $vat_settings['vat_same_country_rule'] = array(
280 280
                 'id'          => 'vat_same_country_rule',
281
-                'name'        => __( 'Same Country Rule', 'invoicing' ),
282
-                'desc'        => __( 'Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing' ),
281
+                'name'        => __('Same Country Rule', 'invoicing'),
282
+                'desc'        => __('Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing'),
283 283
                 'type'        => 'select',
284 284
                 'options'     => array(
285
-                    ''          => __( 'Normal', 'invoicing' ),
286
-                    'no'        => __( 'No VAT', 'invoicing' ),
287
-                    'always'    => __( 'Always apply VAT', 'invoicing' ),
285
+                    ''          => __('Normal', 'invoicing'),
286
+                    'no'        => __('No VAT', 'invoicing'),
287
+                    'always'    => __('Always apply VAT', 'invoicing'),
288 288
                 ),
289
-                'placeholder' => __( 'Select an option', 'invoicing' ),
289
+                'placeholder' => __('Select an option', 'invoicing'),
290 290
                 'std'         => '',
291 291
                 'class'   => 'wpi_select2',
292 292
             );
293 293
 
294 294
             $vat_settings['vat_checkout_title'] = array(
295 295
                 'id' => 'vat_checkout_title',
296
-                'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>',
296
+                'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>',
297 297
                 'desc' => '',
298 298
                 'type' => 'header',
299 299
                 'size' => 'regular'
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 
302 302
             $vat_settings['vies_validation_title'] = array(
303 303
                 'id' => 'vies_validation_title',
304
-                'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>',
304
+                'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>',
305 305
                 'desc' => '',
306 306
                 'type' => 'header',
307 307
                 'size' => 'regular'
@@ -309,37 +309,37 @@  discard block
 block discarded – undo
309 309
 
310 310
             $vat_settings['vat_vies_check'] = array(
311 311
                 'id' => 'vat_vies_check',
312
-                'name' => __( 'Disable VIES VAT ID Check', 'invoicing' ),
313
-                'desc' => wp_sprintf( __( 'Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
312
+                'name' => __('Disable VIES VAT ID Check', 'invoicing'),
313
+                'desc' => wp_sprintf(__('Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
314 314
                 'type' => 'checkbox'
315 315
             );
316 316
 
317 317
             $vat_settings['vat_disable_company_name_check'] = array(
318 318
                 'id' => 'vat_disable_company_name_check',
319
-                'name' => __( 'Disable VIES Name Check', 'invoicing' ),
320
-                'desc' => wp_sprintf( __( 'Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
319
+                'name' => __('Disable VIES Name Check', 'invoicing'),
320
+                'desc' => wp_sprintf(__('Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
321 321
                 'type' => 'checkbox'
322 322
             );
323 323
 
324 324
             $vat_settings['vat_offline_check'] = array(
325 325
                 'id' => 'vat_offline_check',
326
-                'name' => __( 'Disable Basic Checks', 'invoicing' ),
327
-                'desc' => __( 'Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing' ),
326
+                'name' => __('Disable Basic Checks', 'invoicing'),
327
+                'desc' => __('Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing'),
328 328
                 'type' => 'checkbox'
329 329
             );
330 330
 
331 331
 
332 332
             $settings['vat'] = $vat_settings;
333 333
 
334
-            if ( self::allow_vat_classes() ) {
334
+            if (self::allow_vat_classes()) {
335 335
                 $settings['vat_rates'] = self::vat_rates_settings();
336 336
             }
337 337
 
338 338
             $eu_fallback_rate = array(
339 339
                 'id'   => 'eu_fallback_rate',
340
-                'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>',
340
+                'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>',
341 341
                 'type' => 'eu_fallback_rate',
342
-                'desc' => __( 'Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing' ),
342
+                'desc' => __('Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing'),
343 343
                 'std'  => '20',
344 344
                 'size' => 'small'
345 345
             );
@@ -430,66 +430,66 @@  discard block
 block discarded – undo
430 430
         return getpaid_get_ip_country();
431 431
     }
432 432
 
433
-    public static function sanitize_vat_settings( $input ) {
433
+    public static function sanitize_vat_settings($input) {
434 434
         global $wpinv_options;
435 435
 
436 436
         $valid      = false;
437 437
         $message    = '';
438 438
 
439
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
440
-            if ( empty( $wpinv_options['vat_offline_check'] ) ) {
441
-                $valid = self::offline_check( $input['vat_number'] );
439
+        if (!empty($wpinv_options['vat_vies_check'])) {
440
+            if (empty($wpinv_options['vat_offline_check'])) {
441
+                $valid = self::offline_check($input['vat_number']);
442 442
             } else {
443 443
                 $valid = true;
444 444
             }
445 445
 
446
-            $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' );
446
+            $message = $valid ? '' : __('VAT number not validated', 'invoicing');
447 447
         } else {
448
-            $result = self::check_vat( $input['vat_number'] );
448
+            $result = self::check_vat($input['vat_number']);
449 449
 
450
-            if ( empty( $result['valid'] ) ) {
450
+            if (empty($result['valid'])) {
451 451
                 $valid      = false;
452 452
                 $message    = $result['message'];
453 453
             } else {
454
-                $valid      = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] );
455
-                $message    = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' );
454
+                $valid      = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']);
455
+                $message    = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing');
456 456
             }
457 457
         }
458 458
 
459
-        if ( $message && self::is_vat_validated() != $valid ) {
460
-            add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) );
459
+        if ($message && self::is_vat_validated() != $valid) {
460
+            add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error'));
461 461
         }
462 462
 
463 463
         $input['vat_valid'] = $valid;
464 464
         return $input;
465 465
     }
466 466
 
467
-    public static function sanitize_vat_rates( $input ) {
468
-        if( !wpinv_current_user_can_manage_invoicing() ) {
469
-            add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' );
467
+    public static function sanitize_vat_rates($input) {
468
+        if (!wpinv_current_user_can_manage_invoicing()) {
469
+            add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error');
470 470
             return $input;
471 471
         }
472 472
 
473 473
         $vat_classes = self::get_rate_classes();
474
-        $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : '';
474
+        $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : '';
475 475
 
476
-        if ( empty( $vat_class ) ) {
477
-            add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' );
476
+        if (empty($vat_class)) {
477
+            add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error');
478 478
 
479 479
             return $input;
480 480
         }
481 481
 
482
-        $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array();
482
+        $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array();
483 483
 
484
-        if ( $vat_class === '_standard' ) {
484
+        if ($vat_class === '_standard') {
485 485
             // Save the active rates in the invoice settings
486
-            update_option( 'wpinv_tax_rates', $new_rates );
486
+            update_option('wpinv_tax_rates', $new_rates);
487 487
         } else {
488 488
             // Get the existing set of rates
489 489
             $rates = self::get_non_standard_rates();
490 490
             $rates[$vat_class] = $new_rates;
491 491
 
492
-            update_option( 'wpinv_vat_rates', $rates );
492
+            update_option('wpinv_vat_rates', $rates);
493 493
         }
494 494
 
495 495
         return $input;
@@ -499,71 +499,71 @@  discard block
 block discarded – undo
499 499
         $response = array();
500 500
         $response['success'] = false;
501 501
 
502
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
503
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
504
-            wp_send_json( $response );
502
+        if (!wpinv_current_user_can_manage_invoicing()) {
503
+            $response['error'] = __('Invalid access!', 'invoicing');
504
+            wp_send_json($response);
505 505
         }
506 506
 
507
-        $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false;
508
-        $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false;
507
+        $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false;
508
+        $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false;
509 509
 
510
-        if ( empty( $vat_class_name ) ) {
511
-            $response['error'] = __( 'Select the VAT rate name', 'invoicing' );
512
-            wp_send_json( $response );
510
+        if (empty($vat_class_name)) {
511
+            $response['error'] = __('Select the VAT rate name', 'invoicing');
512
+            wp_send_json($response);
513 513
         }
514 514
 
515
-        $vat_classes = (array)self::get_rate_classes();
515
+        $vat_classes = (array) self::get_rate_classes();
516 516
 
517
-        if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) {
518
-            $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name );
519
-            wp_send_json( $response );
517
+        if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) {
518
+            $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name);
519
+            wp_send_json($response);
520 520
         }
521 521
 
522
-        $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name );
523
-        $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) );
522
+        $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name);
523
+        $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key));
524 524
 
525
-        $vat_classes = (array)self::get_rate_classes( true );
526
-        $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc );
525
+        $vat_classes = (array) self::get_rate_classes(true);
526
+        $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc);
527 527
 
528
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
528
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
529 529
 
530 530
         $response['success'] = true;
531
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key );
531
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key);
532 532
 
533
-        wp_send_json( $response );
533
+        wp_send_json($response);
534 534
     }
535 535
 
536 536
     public static function delete_class() {
537 537
         $response = array();
538 538
         $response['success'] = false;
539 539
 
540
-        if ( !wpinv_current_user_can_manage_invoicing() || !isset( $_POST['class'] ) ) {
541
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
542
-            wp_send_json( $response );
540
+        if (!wpinv_current_user_can_manage_invoicing() || !isset($_POST['class'])) {
541
+            $response['error'] = __('Invalid access!', 'invoicing');
542
+            wp_send_json($response);
543 543
         }
544 544
 
545
-        $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false;
546
-        $vat_classes = (array)self::get_rate_classes();
545
+        $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false;
546
+        $vat_classes = (array) self::get_rate_classes();
547 547
 
548
-        if ( !isset( $vat_classes[$vat_class] ) ) {
549
-            $response['error'] = __( 'Requested class does not exists', 'invoicing' );
550
-            wp_send_json( $response );
548
+        if (!isset($vat_classes[$vat_class])) {
549
+            $response['error'] = __('Requested class does not exists', 'invoicing');
550
+            wp_send_json($response);
551 551
         }
552 552
 
553
-        if ( $vat_class == '_new' || $vat_class == '_standard' ) {
554
-            $response['error'] = __( 'You can not delete standard rates class', 'invoicing' );
555
-            wp_send_json( $response );
553
+        if ($vat_class == '_new' || $vat_class == '_standard') {
554
+            $response['error'] = __('You can not delete standard rates class', 'invoicing');
555
+            wp_send_json($response);
556 556
         }
557 557
 
558
-        $vat_classes = (array)self::get_rate_classes( true );
559
-        unset( $vat_classes[$vat_class] );
558
+        $vat_classes = (array) self::get_rate_classes(true);
559
+        unset($vat_classes[$vat_class]);
560 560
 
561
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
561
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
562 562
 
563 563
         $response['success'] = true;
564
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new' );
564
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new');
565 565
 
566
-        wp_send_json( $response );
566
+        wp_send_json($response);
567 567
     }
568 568
 
569 569
     public static function update_eu_rates() {
@@ -572,24 +572,24 @@  discard block
 block discarded – undo
572 572
         $response['error']      = null;
573 573
         $response['data']       = null;
574 574
 
575
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
576
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
577
-            wp_send_json( $response );
575
+        if (!wpinv_current_user_can_manage_invoicing()) {
576
+            $response['error'] = __('Invalid access!', 'invoicing');
577
+            wp_send_json($response);
578 578
         }
579 579
 
580
-        $group      = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : '';
581
-        $euvatrates = self::request_euvatrates( $group );
580
+        $group      = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : '';
581
+        $euvatrates = self::request_euvatrates($group);
582 582
 
583
-        if ( !empty( $euvatrates ) ) {
584
-            if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) {
583
+        if (!empty($euvatrates)) {
584
+            if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) {
585 585
                 $response['success']        = true;
586 586
                 $response['data']['rates']  = $euvatrates['rates'];
587
-            } else if ( !empty( $euvatrates['error'] ) ) {
587
+            } else if (!empty($euvatrates['error'])) {
588 588
                 $response['error']          = $euvatrates['error'];
589 589
             }
590 590
         }
591 591
 
592
-        wp_send_json( $response );
592
+        wp_send_json($response);
593 593
     }
594 594
 
595 595
     /**
@@ -598,46 +598,46 @@  discard block
 block discarded – undo
598 598
     public static function hide_vat_fields() {}
599 599
 
600 600
     public static function same_country_rule() {
601
-        $same_country_rule = wpinv_get_option( 'vat_same_country_rule' );
601
+        $same_country_rule = wpinv_get_option('vat_same_country_rule');
602 602
 
603
-        return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule );
603
+        return apply_filters('wpinv_vat_same_country_rule', $same_country_rule);
604 604
     }
605 605
 
606 606
     /**
607 607
      * Retrieves the vat name.
608 608
      */
609 609
     public function get_vat_name() {
610
-        $vat_name = wpinv_get_option( 'vat_name' );
611
-        return empty( $vat_name ) ? __( 'VAT', 'invoicing' ) : sanitize_text_field( $vat_name );
610
+        $vat_name = wpinv_get_option('vat_name');
611
+        return empty($vat_name) ? __('VAT', 'invoicing') : sanitize_text_field($vat_name);
612 612
     }
613 613
 
614 614
     public static function get_company_name() {
615
-        $company_name = wpinv_get_option( 'vat_company_name' );
615
+        $company_name = wpinv_get_option('vat_company_name');
616 616
 
617
-        return apply_filters( 'wpinv_get_owner_company_name', $company_name );
617
+        return apply_filters('wpinv_get_owner_company_name', $company_name);
618 618
     }
619 619
 
620 620
     public static function get_vat_number() {
621
-        $vat_number = wpinv_get_option( 'vat_number' );
621
+        $vat_number = wpinv_get_option('vat_number');
622 622
 
623
-        return apply_filters( 'wpinv_get_owner_vat_number', $vat_number );
623
+        return apply_filters('wpinv_get_owner_vat_number', $vat_number);
624 624
     }
625 625
 
626 626
     public static function is_vat_validated() {
627
-        $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' );
627
+        $validated = self::get_vat_number() && wpinv_get_option('vat_valid');
628 628
 
629
-        return apply_filters( 'wpinv_is_owner_vat_validated', $validated );
629
+        return apply_filters('wpinv_is_owner_vat_validated', $validated);
630 630
     }
631 631
 
632
-    public static function sanitize_vat( $vat_number, $country_code = '' ) {
633
-        $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) );
632
+    public static function sanitize_vat($vat_number, $country_code = '') {
633
+        $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number)));
634 634
 
635
-        if ( empty( $country_code ) ) {
636
-            $country_code = substr( $vat_number, 0, 2 );
635
+        if (empty($country_code)) {
636
+            $country_code = substr($vat_number, 0, 2);
637 637
         }
638 638
 
639
-        if ( strpos( $vat_number , $country_code ) === 0 ) {
640
-            $vat = str_replace( $country_code, '', $vat_number );
639
+        if (strpos($vat_number, $country_code) === 0) {
640
+            $vat = str_replace($country_code, '', $vat_number);
641 641
         } else {
642 642
             $vat = $country_code . $vat_number;
643 643
         }
@@ -650,140 +650,140 @@  discard block
 block discarded – undo
650 650
         return $return;
651 651
     }
652 652
 
653
-    public static function offline_check( $vat_number, $country_code = '', $formatted = false ) {
654
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
653
+    public static function offline_check($vat_number, $country_code = '', $formatted = false) {
654
+        $vat            = self::sanitize_vat($vat_number, $country_code);
655 655
         $vat_number     = $vat['vat_number'];
656 656
         $country_code   = $vat['iso'];
657 657
         $regex          = array();
658 658
 
659
-        switch ( $country_code ) {
659
+        switch ($country_code) {
660 660
             case 'AT':
661
-                $regex[] = '/^(AT)U(\d{8})$/';                           // Austria
661
+                $regex[] = '/^(AT)U(\d{8})$/'; // Austria
662 662
                 break;
663 663
             case 'BE':
664
-                $regex[] = '/^(BE)(0?\d{9})$/';                          // Belgium
664
+                $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium
665 665
                 break;
666 666
             case 'BG':
667
-                $regex[] = '/^(BG)(\d{9,10})$/';                         // Bulgaria
667
+                $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria
668 668
                 break;
669 669
             case 'CH':
670 670
             case 'CHE':
671
-                $regex[] = '/^(CHE)(\d{9})MWST$/';                       // Switzerland (Not EU)
671
+                $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU)
672 672
                 break;
673 673
             case 'CY':
674
-                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/';                // Cyprus
674
+                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus
675 675
                 break;
676 676
             case 'CZ':
677
-                $regex[] = '/^(CZ)(\d{8,13})$/';                         // Czech Republic
677
+                $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic
678 678
                 break;
679 679
             case 'DE':
680
-                $regex[] = '/^(DE)([1-9]\d{8})$/';                       // Germany
680
+                $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany
681 681
                 break;
682 682
             case 'DK':
683
-                $regex[] = '/^(DK)(\d{8})$/';                            // Denmark
683
+                $regex[] = '/^(DK)(\d{8})$/'; // Denmark
684 684
                 break;
685 685
             case 'EE':
686
-                $regex[] = '/^(EE)(10\d{7})$/';                          // Estonia
686
+                $regex[] = '/^(EE)(10\d{7})$/'; // Estonia
687 687
                 break;
688 688
             case 'EL':
689
-                $regex[] = '/^(EL)(\d{9})$/';                            // Greece
689
+                $regex[] = '/^(EL)(\d{9})$/'; // Greece
690 690
                 break;
691 691
             case 'ES':
692
-                $regex[] = '/^(ES)([A-Z]\d{8})$/';                       // Spain (National juridical entities)
693
-                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/';            // Spain (Other juridical entities)
694
-                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/';              // Spain (Personal entities type 1)
695
-                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/';              // Spain (Personal entities type 2)
692
+                $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities)
693
+                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities)
694
+                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1)
695
+                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2)
696 696
                 break;
697 697
             case 'EU':
698
-                $regex[] = '/^(EU)(\d{9})$/';                            // EU-type
698
+                $regex[] = '/^(EU)(\d{9})$/'; // EU-type
699 699
                 break;
700 700
             case 'FI':
701
-                $regex[] = '/^(FI)(\d{8})$/';                            // Finland
701
+                $regex[] = '/^(FI)(\d{8})$/'; // Finland
702 702
                 break;
703 703
             case 'FR':
704
-                $regex[] = '/^(FR)(\d{11})$/';                           // France (1)
705
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/';        // France (2)
706
-                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/';       // France (3)
707
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/';      // France (4)
704
+                $regex[] = '/^(FR)(\d{11})$/'; // France (1)
705
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2)
706
+                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3)
707
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4)
708 708
                 break;
709 709
             case 'GB':
710
-                $regex[] = '/^(GB)?(\d{9})$/';                           // UK (Standard)
711
-                $regex[] = '/^(GB)?(\d{12})$/';                          // UK (Branches)
712
-                $regex[] = '/^(GB)?(GD\d{3})$/';                         // UK (Government)
713
-                $regex[] = '/^(GB)?(HA\d{3})$/';                         // UK (Health authority)
710
+                $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard)
711
+                $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches)
712
+                $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government)
713
+                $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority)
714 714
                 break;
715 715
             case 'GR':
716
-                $regex[] = '/^(GR)(\d{8,9})$/';                          // Greece
716
+                $regex[] = '/^(GR)(\d{8,9})$/'; // Greece
717 717
                 break;
718 718
             case 'HR':
719
-                $regex[] = '/^(HR)(\d{11})$/';                           // Croatia
719
+                $regex[] = '/^(HR)(\d{11})$/'; // Croatia
720 720
                 break;
721 721
             case 'HU':
722
-                $regex[] = '/^(HU)(\d{8})$/';                            // Hungary
722
+                $regex[] = '/^(HU)(\d{8})$/'; // Hungary
723 723
                 break;
724 724
             case 'IE':
725
-                $regex[] = '/^(IE)(\d{7}[A-W])$/';                       // Ireland (1)
726
-                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/';        // Ireland (2)
727
-                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/';                   // Ireland (3) (new format from 1 Jan 2013)
725
+                $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1)
726
+                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2)
727
+                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013)
728 728
                 break;
729 729
             case 'IT':
730
-                $regex[] = '/^(IT)(\d{11})$/';                           // Italy
730
+                $regex[] = '/^(IT)(\d{11})$/'; // Italy
731 731
                 break;
732 732
             case 'LV':
733
-                $regex[] = '/^(LV)(\d{11})$/';                           // Latvia
733
+                $regex[] = '/^(LV)(\d{11})$/'; // Latvia
734 734
                 break;
735 735
             case 'LT':
736
-                $regex[] = '/^(LT)(\d{9}|\d{12})$/';                     // Lithuania
736
+                $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania
737 737
                 break;
738 738
             case 'LU':
739
-                $regex[] = '/^(LU)(\d{8})$/';                            // Luxembourg
739
+                $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg
740 740
                 break;
741 741
             case 'MT':
742
-                $regex[] = '/^(MT)([1-9]\d{7})$/';                       // Malta
742
+                $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta
743 743
                 break;
744 744
             case 'NL':
745
-                $regex[] = '/^(NL)(\d{9})B\d{2}$/';                      // Netherlands
745
+                $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands
746 746
                 break;
747 747
             case 'NO':
748
-                $regex[] = '/^(NO)(\d{9})$/';                            // Norway (Not EU)
748
+                $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU)
749 749
                 break;
750 750
             case 'PL':
751
-                $regex[] = '/^(PL)(\d{10})$/';                           // Poland
751
+                $regex[] = '/^(PL)(\d{10})$/'; // Poland
752 752
                 break;
753 753
             case 'PT':
754
-                $regex[] = '/^(PT)(\d{9})$/';                            // Portugal
754
+                $regex[] = '/^(PT)(\d{9})$/'; // Portugal
755 755
                 break;
756 756
             case 'RO':
757
-                $regex[] = '/^(RO)([1-9]\d{1,9})$/';                     // Romania
757
+                $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania
758 758
                 break;
759 759
             case 'RS':
760
-                $regex[] = '/^(RS)(\d{9})$/';                            // Serbia (Not EU)
760
+                $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU)
761 761
                 break;
762 762
             case 'SI':
763
-                $regex[] = '/^(SI)([1-9]\d{7})$/';                       // Slovenia
763
+                $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia
764 764
                 break;
765 765
             case 'SK':
766
-                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/';        // Slovakia Republic
766
+                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic
767 767
                 break;
768 768
             case 'SE':
769
-                $regex[] = '/^(SE)(\d{10}01)$/';                         // Sweden
769
+                $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden
770 770
                 break;
771 771
             default:
772 772
                 $regex = array();
773 773
             break;
774 774
         }
775 775
 
776
-        if ( empty( $regex ) ) {
776
+        if (empty($regex)) {
777 777
             return false;
778 778
         }
779 779
 
780
-        foreach ( $regex as $pattern ) {
780
+        foreach ($regex as $pattern) {
781 781
             $matches = null;
782
-            preg_match_all( $pattern, $vat_number, $matches );
782
+            preg_match_all($pattern, $vat_number, $matches);
783 783
 
784
-            if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) {
785
-                if ( $formatted ) {
786
-                    return array( 'code' => $matches[1][0], 'number' => $matches[2][0] );
784
+            if (!empty($matches[1][0]) && !empty($matches[2][0])) {
785
+                if ($formatted) {
786
+                    return array('code' => $matches[1][0], 'number' => $matches[2][0]);
787 787
                 } else {
788 788
                     return true;
789 789
                 }
@@ -793,76 +793,76 @@  discard block
 block discarded – undo
793 793
         return false;
794 794
     }
795 795
 
796
-    public static function vies_check( $vat_number, $country_code = '', $result = false ) {
797
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
796
+    public static function vies_check($vat_number, $country_code = '', $result = false) {
797
+        $vat            = self::sanitize_vat($vat_number, $country_code);
798 798
         $vat_number     = $vat['vat'];
799 799
         $iso            = $vat['iso'];
800 800
         $response       = false;
801 801
 
802
-        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number );
802
+        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number);
803 803
 
804
-        if ( ini_get( 'allow_url_fopen' ) ) {
805
-            $response = file_get_contents( $url );
806
-        } else if ( function_exists( 'curl_init' ) ) {
804
+        if (ini_get('allow_url_fopen')) {
805
+            $response = file_get_contents($url);
806
+        } else if (function_exists('curl_init')) {
807 807
             $ch = curl_init();
808 808
 
809
-            curl_setopt( $ch, CURLOPT_URL, $url );
810
-            curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 );
811
-            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
812
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
813
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
809
+            curl_setopt($ch, CURLOPT_URL, $url);
810
+            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
811
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
812
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
813
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
814 814
 
815
-            $response = curl_exec( $ch );
815
+            $response = curl_exec($ch);
816 816
 
817
-            if ( curl_errno( $ch ) ) {
818
-                wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' );
817
+            if (curl_errno($ch)) {
818
+                wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR');
819 819
                 $response = '';
820 820
             }
821 821
 
822
-            curl_close( $ch );
822
+            curl_close($ch);
823 823
         } else {
824
-            wpinv_error_log( 'To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR' );
824
+            wpinv_error_log('To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR');
825 825
         }
826 826
 
827
-        if ( empty( $response ) ) {
827
+        if (empty($response)) {
828 828
             return $result;
829 829
         }
830 830
 
831
-        if ( preg_match( '/invalid VAT number/i', $response ) ) {
831
+        if (preg_match('/invalid VAT number/i', $response)) {
832 832
             return false;
833
-        } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) {
834
-            $content = explode( "valid VAT number", htmlentities( $response ) );
833
+        } else if (preg_match('/valid VAT number/i', $response, $matches)) {
834
+            $content = explode("valid VAT number", htmlentities($response));
835 835
 
836
-            if ( !empty( $content[1] ) ) {
837
-                preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches );
836
+            if (!empty($content[1])) {
837
+                preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches);
838 838
 
839
-                if ( !empty( $matches[2] ) && $matches[3] ) {
839
+                if (!empty($matches[2]) && $matches[3]) {
840 840
                     $return = array();
841 841
 
842
-                    foreach ( $matches[2] as $key => $label ) {
843
-                        $label = trim( $label );
842
+                    foreach ($matches[2] as $key => $label) {
843
+                        $label = trim($label);
844 844
 
845
-                        switch ( strtolower( $label ) ) {
845
+                        switch (strtolower($label)) {
846 846
                             case 'member state':
847
-                                $return['state'] = trim( strip_tags( $matches[3][$key] ) );
847
+                                $return['state'] = trim(strip_tags($matches[3][$key]));
848 848
                             break;
849 849
                             case 'vat number':
850
-                                $return['number'] = trim( strip_tags( $matches[3][$key] ) );
850
+                                $return['number'] = trim(strip_tags($matches[3][$key]));
851 851
                             break;
852 852
                             case 'name':
853
-                                $return['company'] = trim( strip_tags( $matches[3][$key] ) );
853
+                                $return['company'] = trim(strip_tags($matches[3][$key]));
854 854
                             break;
855 855
                             case 'address':
856
-                                $address           = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) );
857
-                                $return['address'] = trim( strip_tags( $address, '<br>' ) );
856
+                                $address           = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key])));
857
+                                $return['address'] = trim(strip_tags($address, '<br>'));
858 858
                             break;
859 859
                             case 'consultation number':
860
-                                $return['consultation'] = trim( strip_tags( $matches[3][$key] ) );
860
+                                $return['consultation'] = trim(strip_tags($matches[3][$key]));
861 861
                             break;
862 862
                         }
863 863
                     }
864 864
 
865
-                    if ( !empty( $return ) ) {
865
+                    if (!empty($return)) {
866 866
                         return $return;
867 867
                     }
868 868
                 }
@@ -874,62 +874,62 @@  discard block
 block discarded – undo
874 874
         }
875 875
     }
876 876
 
877
-    public static function check_vat( $vat_number, $country_code = '' ) {
877
+    public static function check_vat($vat_number, $country_code = '') {
878 878
         $vat_name           = getpaid_vat_name();
879 879
 
880 880
         $return             = array();
881 881
         $return['valid']    = false;
882
-        $return['message']  = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
882
+        $return['message']  = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
883 883
 
884
-        if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) {
884
+        if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) {
885 885
             return $return;
886 886
         }
887 887
 
888
-        $response = self::vies_check( $vat_number, $country_code );
888
+        $response = self::vies_check($vat_number, $country_code);
889 889
 
890
-        if ( $response ) {
891
-            $return['valid']    = true;
890
+        if ($response) {
891
+            $return['valid'] = true;
892 892
 
893
-            if ( is_array( $response ) ) {
894
-                $return['company'] = isset( $response['company'] ) ? $response['company'] : '';
895
-                $return['address'] = isset( $response['address'] ) ? $response['address'] : '';
893
+            if (is_array($response)) {
894
+                $return['company'] = isset($response['company']) ? $response['company'] : '';
895
+                $return['address'] = isset($response['address']) ? $response['address'] : '';
896 896
                 $return['message'] = $return['company'] . '<br/>' . $return['address'];
897 897
             }
898 898
         } else {
899 899
             $return['valid']    = false;
900
-            $return['message']  = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
900
+            $return['message']  = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
901 901
         }
902 902
 
903 903
         return $return;
904 904
     }
905 905
 
906
-    public static function request_euvatrates( $group ) {
906
+    public static function request_euvatrates($group) {
907 907
         $response               = array();
908 908
         $response['success']    = false;
909 909
         $response['error']      = null;
910 910
         $response['eurates']    = null;
911 911
 
912 912
         $euvatrates_url = 'https://euvatrates.com/rates.json';
913
-        $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url );
914
-        $api_response   = wp_remote_get( $euvatrates_url );
913
+        $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url);
914
+        $api_response   = wp_remote_get($euvatrates_url);
915 915
 
916 916
         try {
917
-            if ( is_wp_error( $api_response ) ) {
918
-                $response['error']      = __( $api_response->get_error_message(), 'invoicing' );
917
+            if (is_wp_error($api_response)) {
918
+                $response['error'] = __($api_response->get_error_message(), 'invoicing');
919 919
             } else {
920
-                $body = json_decode( $api_response['body'] );
921
-                if ( isset( $body->rates ) ) {
920
+                $body = json_decode($api_response['body']);
921
+                if (isset($body->rates)) {
922 922
                     $rates = array();
923 923
 
924
-                    foreach ( $body->rates as $country_code => $rate ) {
924
+                    foreach ($body->rates as $country_code => $rate) {
925 925
                         $vat_rate = array();
926 926
                         $vat_rate['country']        = $rate->country;
927
-                        $vat_rate['standard']       = (float)$rate->standard_rate;
928
-                        $vat_rate['reduced']        = (float)$rate->reduced_rate;
929
-                        $vat_rate['superreduced']   = (float)$rate->super_reduced_rate;
930
-                        $vat_rate['parking']        = (float)$rate->parking_rate;
927
+                        $vat_rate['standard']       = (float) $rate->standard_rate;
928
+                        $vat_rate['reduced']        = (float) $rate->reduced_rate;
929
+                        $vat_rate['superreduced']   = (float) $rate->super_reduced_rate;
930
+                        $vat_rate['parking']        = (float) $rate->parking_rate;
931 931
 
932
-                        if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) {
932
+                        if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) {
933 933
                             $vat_rate_group = array();
934 934
                             $vat_rate_group['country'] = $rate->country;
935 935
                             $vat_rate_group[$group]    = $vat_rate[$group];
@@ -941,79 +941,79 @@  discard block
 block discarded – undo
941 941
                     }
942 942
 
943 943
                     $response['success']    = true;
944
-                    $response['rates']      = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group );
944
+                    $response['rates']      = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group);
945 945
                 } else {
946
-                    $response['error']      = __( 'No EU rates found!', 'invoicing' );
946
+                    $response['error']      = __('No EU rates found!', 'invoicing');
947 947
                 }
948 948
             }
949
-        } catch ( Exception $e ) {
950
-            $response['error'] = __( $e->getMessage(), 'invoicing' );
949
+        } catch (Exception $e) {
950
+            $response['error'] = __($e->getMessage(), 'invoicing');
951 951
         }
952 952
 
953
-        return apply_filters( 'wpinv_response_euvatrates', $response, $group );
953
+        return apply_filters('wpinv_response_euvatrates', $response, $group);
954 954
     }
955 955
 
956
-    public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) {
956
+    public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) {
957 957
         global $wpi_item_id, $wpi_country;
958 958
 
959
-        if ( !empty( $_POST['wpinv_country'] ) ) {
960
-            $country_code = trim( $_POST['wpinv_country'] );
961
-        } else if ( !empty( $_POST['country'] ) ) {
962
-            $country_code = trim( $_POST['country'] );
963
-        } else if ( !empty( $wpi_country ) ) {
959
+        if (!empty($_POST['wpinv_country'])) {
960
+            $country_code = trim($_POST['wpinv_country']);
961
+        } else if (!empty($_POST['country'])) {
962
+            $country_code = trim($_POST['country']);
963
+        } else if (!empty($wpi_country)) {
964 964
             $country_code = $wpi_country;
965 965
         } else {
966
-            $country_code = self::get_user_country( '', $user_id );
966
+            $country_code = self::get_user_country('', $user_id);
967 967
         }
968 968
 
969
-        if ( $is_digital === null && $wpi_item_id ) {
970
-            $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules();
969
+        if ($is_digital === null && $wpi_item_id) {
970
+            $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules();
971 971
         }
972 972
 
973
-        if ( !empty( $country_code ) ) {
974
-            $requires_vat = ( self::is_eu_state( $country_code ) && ( self::is_eu_state( wpinv_get_default_country() ) || $is_digital ) ) || ( self::is_gst_country( $country_code ) && self::is_gst_country( wpinv_get_default_country() ) );
973
+        if (!empty($country_code)) {
974
+            $requires_vat = (self::is_eu_state($country_code) && (self::is_eu_state(wpinv_get_default_country()) || $is_digital)) || (self::is_gst_country($country_code) && self::is_gst_country(wpinv_get_default_country()));
975 975
         }
976 976
 
977
-        return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id );
977
+        return apply_filters('wpinv_requires_vat', $requires_vat, $user_id);
978 978
     }
979 979
 
980
-    public static function tax_label( $label = '' ) {
980
+    public static function tax_label($label = '') {
981 981
         global $wpi_requires_vat;
982 982
 
983
-        if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) {
984
-            $wpi_requires_vat = self::requires_vat( 0, false );
983
+        if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) {
984
+            $wpi_requires_vat = self::requires_vat(0, false);
985 985
         }
986 986
 
987
-        return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) );
987
+        return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing'));
988 988
     }
989 989
 
990 990
     public static function standard_rates_label() {
991
-        return __( 'Standard Rates', 'invoicing' );
991
+        return __('Standard Rates', 'invoicing');
992 992
     }
993 993
 
994
-    public static function get_rate_classes( $with_desc = false ) {
995
-        $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true );
996
-        $classes = maybe_unserialize( $rate_classes_option );
994
+    public static function get_rate_classes($with_desc = false) {
995
+        $rate_classes_option = get_option('_wpinv_vat_rate_classes', true);
996
+        $classes = maybe_unserialize($rate_classes_option);
997 997
 
998
-        if ( empty( $classes ) || !is_array( $classes ) ) {
998
+        if (empty($classes) || !is_array($classes)) {
999 999
             $classes = array();
1000 1000
         }
1001 1001
 
1002 1002
         $rate_classes = array();
1003
-        if ( !array_key_exists( '_standard', $classes ) ) {
1004
-            if ( $with_desc ) {
1005
-                $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) );
1003
+        if (!array_key_exists('_standard', $classes)) {
1004
+            if ($with_desc) {
1005
+                $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing'));
1006 1006
             } else {
1007 1007
                 $rate_classes['_standard'] = self::standard_rates_label();
1008 1008
             }
1009 1009
         }
1010 1010
 
1011
-        foreach ( $classes as $key => $class ) {
1012
-            $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key;
1013
-            $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : '';
1011
+        foreach ($classes as $key => $class) {
1012
+            $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key;
1013
+            $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : '';
1014 1014
 
1015
-            if ( $with_desc ) {
1016
-                $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc );
1015
+            if ($with_desc) {
1016
+                $rate_classes[$key] = array('name' => $name, 'desc' => $desc);
1017 1017
             } else {
1018 1018
                 $rate_classes[$key] = $name;
1019 1019
             }
@@ -1024,15 +1024,15 @@  discard block
 block discarded – undo
1024 1024
 
1025 1025
     public static function get_all_classes() {
1026 1026
         $classes            = self::get_rate_classes();
1027
-        $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' );
1027
+        $classes['_exempt'] = __('Exempt (0%)', 'invoicing');
1028 1028
 
1029
-        return apply_filters( 'wpinv_vat_get_all_classes', $classes );
1029
+        return apply_filters('wpinv_vat_get_all_classes', $classes);
1030 1030
     }
1031 1031
 
1032
-    public static function get_class_desc( $rate_class ) {
1033
-        $rate_classes = self::get_rate_classes( true );
1032
+    public static function get_class_desc($rate_class) {
1033
+        $rate_classes = self::get_rate_classes(true);
1034 1034
 
1035
-        if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) {
1035
+        if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) {
1036 1036
             return $rate_classes[$rate_class]['desc'];
1037 1037
         }
1038 1038
 
@@ -1048,107 +1048,107 @@  discard block
 block discarded – undo
1048 1048
             'increased'     => 'Increased'
1049 1049
         );
1050 1050
 
1051
-        return apply_filters( 'wpinv_get_vat_groups', $vat_groups );
1051
+        return apply_filters('wpinv_get_vat_groups', $vat_groups);
1052 1052
     }
1053 1053
 
1054 1054
     public static function get_rules() {
1055 1055
         $vat_rules = array(
1056
-            'digital' => __( 'Digital Product', 'invoicing' ),
1057
-            'physical' => __( 'Physical Product', 'invoicing' ),
1058
-            '_exempt' => __( 'Tax-Free Product', 'invoicing' ),
1056
+            'digital' => __('Digital Product', 'invoicing'),
1057
+            'physical' => __('Physical Product', 'invoicing'),
1058
+            '_exempt' => __('Tax-Free Product', 'invoicing'),
1059 1059
         );
1060
-        return apply_filters( 'wpinv_get_vat_rules', $vat_rules );
1060
+        return apply_filters('wpinv_get_vat_rules', $vat_rules);
1061 1061
     }
1062 1062
 
1063
-    public static function get_vat_rates( $class ) {
1064
-        if ( $class === '_standard' ) {
1063
+    public static function get_vat_rates($class) {
1064
+        if ($class === '_standard') {
1065 1065
             return wpinv_get_tax_rates();
1066 1066
         }
1067 1067
 
1068 1068
         $rates = self::get_non_standard_rates();
1069 1069
 
1070
-        return array_key_exists( $class, $rates ) ? $rates[$class] : array();
1070
+        return array_key_exists($class, $rates) ? $rates[$class] : array();
1071 1071
     }
1072 1072
 
1073 1073
     public static function get_non_standard_rates() {
1074
-        $option = get_option( 'wpinv_vat_rates', array());
1075
-        return is_array( $option ) ? $option : array();
1074
+        $option = get_option('wpinv_vat_rates', array());
1075
+        return is_array($option) ? $option : array();
1076 1076
     }
1077 1077
 
1078 1078
     public static function allow_vat_rules() {
1079
-        return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false );
1079
+        return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false);
1080 1080
     }
1081 1081
 
1082 1082
     public static function allow_vat_classes() {
1083 1083
         return false; // TODO
1084
-        return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false );
1084
+        return (wpinv_get_option('vat_allow_classes') ? true : false);
1085 1085
     }
1086 1086
 
1087
-    public static function get_item_class( $postID ) {
1088
-        $class = get_post_meta( $postID, '_wpinv_vat_class', true );
1087
+    public static function get_item_class($postID) {
1088
+        $class = get_post_meta($postID, '_wpinv_vat_class', true);
1089 1089
 
1090
-        if ( empty( $class ) ) {
1090
+        if (empty($class)) {
1091 1091
             $class = '_standard';
1092 1092
         }
1093 1093
 
1094
-        return apply_filters( 'wpinv_get_item_vat_class', $class, $postID );
1094
+        return apply_filters('wpinv_get_item_vat_class', $class, $postID);
1095 1095
     }
1096 1096
 
1097
-    public static function item_class_label( $postID ) {
1097
+    public static function item_class_label($postID) {
1098 1098
         $vat_classes = self::get_all_classes();
1099 1099
 
1100
-        $class = self::get_item_class( $postID );
1101
-        $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' );
1100
+        $class = self::get_item_class($postID);
1101
+        $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing');
1102 1102
 
1103
-        return apply_filters( 'wpinv_item_class_label', $class, $postID );
1103
+        return apply_filters('wpinv_item_class_label', $class, $postID);
1104 1104
     }
1105 1105
 
1106
-    public static function get_item_rule( $postID ) {
1107
-        $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true );
1106
+    public static function get_item_rule($postID) {
1107
+        $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true);
1108 1108
 
1109
-        if ( empty( $rule_type ) ) {
1109
+        if (empty($rule_type)) {
1110 1110
             $rule_type = self::allow_vat_rules() ? 'digital' : 'physical';
1111 1111
         }
1112 1112
 
1113
-        return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID );
1113
+        return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID);
1114 1114
     }
1115 1115
 
1116
-    public static function item_rule_label( $postID ) {
1116
+    public static function item_rule_label($postID) {
1117 1117
         $vat_rules  = self::get_rules();
1118
-        $vat_rule   = self::get_item_rule( $postID );
1119
-        $vat_rule   = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule;
1118
+        $vat_rule   = self::get_item_rule($postID);
1119
+        $vat_rule   = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule;
1120 1120
 
1121
-        return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID );
1121
+        return apply_filters('wpinv_item_rule_label', $vat_rule, $postID);
1122 1122
     }
1123 1123
 
1124
-    public static function item_has_digital_rule( $item_id = 0 ) {
1125
-        return self::get_item_rule( $item_id ) == 'digital' ? true : false;
1124
+    public static function item_has_digital_rule($item_id = 0) {
1125
+        return self::get_item_rule($item_id) == 'digital' ? true : false;
1126 1126
     }
1127 1127
 
1128
-    public static function invoice_has_digital_rule( $invoice = 0 ) {
1129
-        if ( !self::allow_vat_rules() ) {
1128
+    public static function invoice_has_digital_rule($invoice = 0) {
1129
+        if (!self::allow_vat_rules()) {
1130 1130
             return false;
1131 1131
         }
1132 1132
 
1133
-        if ( empty( $invoice ) ) {
1133
+        if (empty($invoice)) {
1134 1134
             return true;
1135 1135
         }
1136 1136
 
1137
-        if ( is_int( $invoice ) ) {
1138
-            $invoice = new WPInv_Invoice( $invoice );
1137
+        if (is_int($invoice)) {
1138
+            $invoice = new WPInv_Invoice($invoice);
1139 1139
         }
1140 1140
 
1141
-        if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) {
1141
+        if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) {
1142 1142
             return true;
1143 1143
         }
1144 1144
 
1145
-        $cart_items  = $invoice->get_cart_details();
1145
+        $cart_items = $invoice->get_cart_details();
1146 1146
 
1147
-        if ( !empty( $cart_items ) ) {
1147
+        if (!empty($cart_items)) {
1148 1148
             $has_digital_rule = false;
1149 1149
 
1150
-            foreach ( $cart_items as $key => $item ) {
1151
-                if ( self::item_has_digital_rule( $item['id'] ) ) {
1150
+            foreach ($cart_items as $key => $item) {
1151
+                if (self::item_has_digital_rule($item['id'])) {
1152 1152
                     $has_digital_rule = true;
1153 1153
                     break;
1154 1154
                 }
@@ -1160,71 +1160,71 @@  discard block
 block discarded – undo
1160 1160
         return $has_digital_rule;
1161 1161
     }
1162 1162
 
1163
-    public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) {
1164
-        if ( !wpinv_use_taxes() ) {
1163
+    public static function item_is_taxable($item_id = 0, $country = false, $state = false) {
1164
+        if (!wpinv_use_taxes()) {
1165 1165
             return false;
1166 1166
         }
1167 1167
 
1168 1168
         $is_taxable = true;
1169 1169
 
1170
-        if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) {
1170
+        if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') {
1171 1171
             $is_taxable = false;
1172 1172
         }
1173 1173
 
1174
-        if ( !empty( $item_id ) && self::get_item_rule( $item_id ) == '_exempt' ) {
1174
+        if (!empty($item_id) && self::get_item_rule($item_id) == '_exempt') {
1175 1175
             $is_taxable = false;
1176 1176
         }
1177 1177
 
1178
-        return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state );
1178
+        return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state);
1179 1179
     }
1180 1180
 
1181
-    public static function find_rate( $country, $state, $rate, $class ) {
1181
+    public static function find_rate($country, $state, $rate, $class) {
1182 1182
         global $wpi_zero_tax;
1183 1183
 
1184
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1184
+        if ($class === '_exempt' || $wpi_zero_tax) {
1185 1185
             return 0;
1186 1186
         }
1187 1187
 
1188
-        $tax_rates   = wpinv_get_tax_rates();
1188
+        $tax_rates = wpinv_get_tax_rates();
1189 1189
 
1190
-        if ( $class !== '_standard' ) {
1191
-            $class_rates = self::get_vat_rates( $class );
1190
+        if ($class !== '_standard') {
1191
+            $class_rates = self::get_vat_rates($class);
1192 1192
 
1193
-            if ( is_array( $class_rates ) ) {
1193
+            if (is_array($class_rates)) {
1194 1194
                 $indexed_class_rates = array();
1195 1195
 
1196
-                foreach ( $class_rates as $key => $cr ) {
1196
+                foreach ($class_rates as $key => $cr) {
1197 1197
                     $indexed_class_rates[$cr['country']] = $cr;
1198 1198
                 }
1199 1199
 
1200
-                $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) {
1200
+                $tax_rates = array_map(function($tr) use($indexed_class_rates) {
1201 1201
                     $tr_country = $tr['country'];
1202
-                    if ( !isset( $indexed_class_rates[$tr_country] ) ) {
1202
+                    if (!isset($indexed_class_rates[$tr_country])) {
1203 1203
                         return $tr;
1204 1204
                     }
1205 1205
                     $icr = $indexed_class_rates[$tr_country];
1206
-                    return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr;
1206
+                    return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr;
1207 1207
 
1208
-                }, $tax_rates, $class_rates );
1208
+                }, $tax_rates, $class_rates);
1209 1209
             }
1210 1210
         }
1211 1211
 
1212
-        if ( !empty( $tax_rates ) ) {
1213
-            foreach ( $tax_rates as $key => $tax_rate ) {
1214
-                if ( $country != $tax_rate['country'] )
1212
+        if (!empty($tax_rates)) {
1213
+            foreach ($tax_rates as $key => $tax_rate) {
1214
+                if ($country != $tax_rate['country'])
1215 1215
                     continue;
1216 1216
 
1217
-                if ( !empty( $tax_rate['global'] ) ) {
1218
-                    if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) {
1219
-                        $rate = number_format( $tax_rate['rate'], 4 );
1217
+                if (!empty($tax_rate['global'])) {
1218
+                    if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) {
1219
+                        $rate = number_format($tax_rate['rate'], 4);
1220 1220
                     }
1221 1221
                 } else {
1222
-                    if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
1222
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
1223 1223
                         continue;
1224 1224
 
1225 1225
                     $state_rate = $tax_rate['rate'];
1226
-                    if ( 0 !== $state_rate || !empty( $state_rate ) ) {
1227
-                        $rate = number_format( $state_rate, 4 );
1226
+                    if (0 !== $state_rate || !empty($state_rate)) {
1227
+                        $rate = number_format($state_rate, 4);
1228 1228
                     }
1229 1229
                 }
1230 1230
             }
@@ -1233,84 +1233,84 @@  discard block
 block discarded – undo
1233 1233
         return $rate;
1234 1234
     }
1235 1235
 
1236
-    public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) {
1236
+    public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) {
1237 1237
         global $wpinv_options, $wpi_item_id, $wpi_zero_tax;
1238 1238
 
1239 1239
         $item_id = $item_id > 0 ? $item_id : $wpi_item_id;
1240 1240
         $allow_vat_classes = self::allow_vat_classes();
1241
-        $class = $item_id ? self::get_item_class( $item_id ) : '_standard';
1241
+        $class = $item_id ? self::get_item_class($item_id) : '_standard';
1242 1242
 
1243
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1243
+        if ($class === '_exempt' || $wpi_zero_tax) {
1244 1244
             return 0;
1245
-        } else if ( !$allow_vat_classes ) {
1245
+        } else if (!$allow_vat_classes) {
1246 1246
             $class = '_standard';
1247 1247
         }
1248 1248
 
1249
-        if( !empty( $_POST['wpinv_country'] ) ) {
1249
+        if (!empty($_POST['wpinv_country'])) {
1250 1250
             $post_country = $_POST['wpinv_country'];
1251
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
1251
+        } elseif (!empty($_POST['wpinv_country'])) {
1252 1252
             $post_country = $_POST['wpinv_country'];
1253
-        } elseif( !empty( $_POST['country'] ) ) {
1253
+        } elseif (!empty($_POST['country'])) {
1254 1254
             $post_country = $_POST['country'];
1255 1255
         } else {
1256 1256
             $post_country = '';
1257 1257
         }
1258 1258
 
1259
-        $country        = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country );
1260
-        $base_country   = wpinv_is_base_country( $country );
1259
+        $country        = !empty($post_country) ? $post_country : wpinv_default_billing_country($country);
1260
+        $base_country   = wpinv_is_base_country($country);
1261 1261
 
1262
-        $requires_vat   = self::requires_vat( 0, false );
1263
-        $is_digital     = self::get_item_rule( $item_id ) == 'digital' ;
1264
-        $rate           = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate;
1262
+        $requires_vat   = self::requires_vat(0, false);
1263
+        $is_digital     = self::get_item_rule($item_id) == 'digital';
1264
+        $rate           = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate;
1265 1265
 
1266
-        if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country
1266
+        if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country
1267 1267
             $rate = 0;
1268
-        } else if ( $requires_vat ) {
1269
-            $vat_number = self::get_user_vat_number( '', 0, true );
1268
+        } else if ($requires_vat) {
1269
+            $vat_number = self::get_user_vat_number('', 0, true);
1270 1270
             $vat_info   = self::current_vat_data();
1271 1271
 
1272
-            if ( is_array( $vat_info ) ) {
1273
-                $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : "";
1272
+            if (is_array($vat_info)) {
1273
+                $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : "";
1274 1274
             }
1275 1275
 
1276
-            if ( $country == 'UK' ) {
1276
+            if ($country == 'UK') {
1277 1277
                 $country = 'GB';
1278 1278
             }
1279 1279
 
1280
-            if ( !empty( $vat_number ) ) {
1280
+            if (!empty($vat_number)) {
1281 1281
                 $rate = 0;
1282 1282
             } else {
1283
-                $rate = self::find_rate( $country, $state, $rate, $class ); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate
1283
+                $rate = self::find_rate($country, $state, $rate, $class); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate
1284 1284
             }
1285 1285
 
1286
-            if ( empty( $vat_number ) && !$is_digital ) {
1287
-                if ( $base_country ) {
1288
-                    $rate = self::find_rate( $country, null, $rate, $class );
1286
+            if (empty($vat_number) && !$is_digital) {
1287
+                if ($base_country) {
1288
+                    $rate = self::find_rate($country, null, $rate, $class);
1289 1289
                 } else {
1290
-                    if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1290
+                    if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1291 1291
                         $rate = $wpinv_options['eu_fallback_rate'];
1292
-                    } else if( !empty( $country ) ) {
1293
-                        $rate = self::find_rate( $country, $state, $rate, $class );
1292
+                    } else if (!empty($country)) {
1293
+                        $rate = self::find_rate($country, $state, $rate, $class);
1294 1294
                     }
1295 1295
                 }
1296
-            } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) {
1297
-                if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1296
+            } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) {
1297
+                if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1298 1298
                     $rate = $wpinv_options['eu_fallback_rate'];
1299
-                } else if( !empty( $country ) ) {
1300
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1299
+                } else if (!empty($country)) {
1300
+                    $rate = self::find_rate($country, $state, $rate, $class);
1301 1301
                 }
1302 1302
             }
1303 1303
         } else {
1304
-            if ( $is_digital ) {
1304
+            if ($is_digital) {
1305 1305
                 $ip_country_code = getpaid_get_ip_country();
1306 1306
 
1307
-                if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) {
1308
-                    $rate = self::find_rate( $ip_country_code, '', 0, $class );
1307
+                if ($ip_country_code && self::is_eu_state($ip_country_code)) {
1308
+                    $rate = self::find_rate($ip_country_code, '', 0, $class);
1309 1309
                 } else {
1310
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1310
+                    $rate = self::find_rate($country, $state, $rate, $class);
1311 1311
                 }
1312 1312
             } else {
1313
-                $rate = self::find_rate( $country, $state, $rate, $class );
1313
+                $rate = self::find_rate($country, $state, $rate, $class);
1314 1314
             }
1315 1315
         }
1316 1316
 
@@ -1318,44 +1318,44 @@  discard block
 block discarded – undo
1318 1318
     }
1319 1319
 
1320 1320
     public static function current_vat_data() {
1321
-        return getpaid_session()->get( 'user_vat_data' );
1321
+        return getpaid_session()->get('user_vat_data');
1322 1322
     }
1323 1323
 
1324
-    public static function get_user_country( $country = '', $user_id = 0 ) {
1325
-        $user_address = wpinv_get_user_address( $user_id, false );
1324
+    public static function get_user_country($country = '', $user_id = 0) {
1325
+        $user_address = wpinv_get_user_address($user_id, false);
1326 1326
 
1327
-        $country    = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country'];
1328
-        $result     = apply_filters( 'wpinv_get_user_country', $country, $user_id );
1327
+        $country    = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country'];
1328
+        $result     = apply_filters('wpinv_get_user_country', $country, $user_id);
1329 1329
 
1330
-        if ( empty( $result ) ) {
1330
+        if (empty($result)) {
1331 1331
             $result = getpaid_get_ip_country();
1332 1332
         }
1333 1333
 
1334 1334
         return $result;
1335 1335
     }
1336 1336
 
1337
-    public static function set_user_country( $country = '', $user_id = 0 ) {
1337
+    public static function set_user_country($country = '', $user_id = 0) {
1338 1338
         global $wpi_userID;
1339 1339
 
1340
-        if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) {
1340
+        if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) {
1341 1341
             $country = wpinv_get_default_country();
1342 1342
         }
1343 1343
 
1344 1344
         return $country;
1345 1345
     }
1346 1346
 
1347
-    public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) {
1347
+    public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) {
1348 1348
         global $wpi_current_id, $wpi_userID;
1349 1349
 
1350
-        if ( !empty( $_POST['new_user'] ) ) {
1350
+        if (!empty($_POST['new_user'])) {
1351 1351
             return '';
1352 1352
         }
1353 1353
 
1354
-        if ( empty( $user_id ) ) {
1355
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1354
+        if (empty($user_id)) {
1355
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1356 1356
         }
1357 1357
 
1358
-        $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true );
1358
+        $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true);
1359 1359
 
1360 1360
         /* TODO
1361 1361
         if ( $is_valid && $vat_number ) {
@@ -1366,38 +1366,38 @@  discard block
 block discarded – undo
1366 1366
         }
1367 1367
         */
1368 1368
 
1369
-        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid );
1369
+        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid);
1370 1370
     }
1371 1371
 
1372
-    public static function get_user_company( $company = '', $user_id = 0 ) {
1372
+    public static function get_user_company($company = '', $user_id = 0) {
1373 1373
         global $wpi_current_id, $wpi_userID;
1374 1374
 
1375
-        if ( empty( $user_id ) ) {
1376
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1375
+        if (empty($user_id)) {
1376
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1377 1377
         }
1378 1378
 
1379
-        $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
1379
+        $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
1380 1380
 
1381
-        return apply_filters( 'wpinv_user_company', $company, $user_id );
1381
+        return apply_filters('wpinv_user_company', $company, $user_id);
1382 1382
     }
1383 1383
 
1384
-    public static function save_user_vat_details( $company = '', $vat_number = '' ) {
1385
-        $save = apply_filters( 'wpinv_allow_save_user_vat_details', true );
1384
+    public static function save_user_vat_details($company = '', $vat_number = '') {
1385
+        $save = apply_filters('wpinv_allow_save_user_vat_details', true);
1386 1386
 
1387
-        if ( is_user_logged_in() && $save ) {
1387
+        if (is_user_logged_in() && $save) {
1388 1388
             $user_id = get_current_user_id();
1389 1389
 
1390
-            if ( !empty( $vat_number ) ) {
1391
-                update_user_meta( $user_id, '_wpinv_vat_number', $vat_number );
1390
+            if (!empty($vat_number)) {
1391
+                update_user_meta($user_id, '_wpinv_vat_number', $vat_number);
1392 1392
             } else {
1393
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1393
+                delete_user_meta($user_id, '_wpinv_vat_number');
1394 1394
             }
1395 1395
 
1396
-            if ( !empty( $company ) ) {
1397
-                update_user_meta( $user_id, '_wpinv_company', $company );
1396
+            if (!empty($company)) {
1397
+                update_user_meta($user_id, '_wpinv_company', $company);
1398 1398
             } else {
1399
-                delete_user_meta( $user_id, '_wpinv_company');
1400
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1399
+                delete_user_meta($user_id, '_wpinv_company');
1400
+                delete_user_meta($user_id, '_wpinv_vat_number');
1401 1401
             }
1402 1402
         }
1403 1403
 
@@ -1410,74 +1410,74 @@  discard block
 block discarded – undo
1410 1410
         $response               = array();
1411 1411
         $response['success']    = false;
1412 1412
 
1413
-        if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) {
1414
-            $response['error'] = __( 'Invalid security nonce', 'invoicing' );
1415
-            wp_send_json( $response );
1413
+        if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) {
1414
+            $response['error'] = __('Invalid security nonce', 'invoicing');
1415
+            wp_send_json($response);
1416 1416
         }
1417 1417
 
1418 1418
         $vat_name   = self::get_vat_name();
1419 1419
 
1420
-        $company    = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : '';
1421
-        $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : '';
1420
+        $company    = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : '';
1421
+        $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : '';
1422 1422
 
1423
-        $vat_info = getpaid_session()->get( 'user_vat_data' );
1424
-        if ( !is_array( $vat_info ) || empty( $vat_info ) ) {
1425
-            $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true );
1423
+        $vat_info = getpaid_session()->get('user_vat_data');
1424
+        if (!is_array($vat_info) || empty($vat_info)) {
1425
+            $vat_info = array('company'=> $company, 'number' => '', 'valid' => true);
1426 1426
         }
1427 1427
 
1428
-        if ( empty( $vat_number ) ) {
1429
-            $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
1428
+        if (empty($vat_number)) {
1429
+            $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
1430 1430
             $vat_info['valid'] = false;
1431
-            getpaid_session()->set( 'user_vat_data', $vat_info );
1432
-            wp_send_json( $response );
1431
+            getpaid_session()->set('user_vat_data', $vat_info);
1432
+            wp_send_json($response);
1433 1433
         }
1434 1434
 
1435
-        if ( empty( $company ) ) {
1435
+        if (empty($company)) {
1436 1436
             $vat_info['valid'] = false;
1437
-            getpaid_session()->set( 'user_vat_data', $vat_info );
1437
+            getpaid_session()->set('user_vat_data', $vat_info);
1438 1438
 
1439
-            $response['error'] = __( 'Please enter your registered company name!', 'invoicing' );
1440
-            wp_send_json( $response );
1439
+            $response['error'] = __('Please enter your registered company name!', 'invoicing');
1440
+            wp_send_json($response);
1441 1441
         }
1442 1442
 
1443
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
1444
-            if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1443
+        if (!empty($wpinv_options['vat_vies_check'])) {
1444
+            if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1445 1445
                 $vat_info['valid'] = false;
1446
-                getpaid_session()->set( 'user_vat_data', $vat_info );
1446
+                getpaid_session()->set('user_vat_data', $vat_info);
1447 1447
 
1448
-                $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1449
-                wp_send_json( $response );
1448
+                $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1449
+                wp_send_json($response);
1450 1450
             }
1451 1451
 
1452 1452
             $response['success'] = true;
1453
-            $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1453
+            $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1454 1454
         } else {
1455
-            $result = self::check_vat( $vat_number );
1455
+            $result = self::check_vat($vat_number);
1456 1456
 
1457
-            if ( empty( $result['valid'] ) ) {
1457
+            if (empty($result['valid'])) {
1458 1458
                 $response['error'] = $result['message'];
1459
-                wp_send_json( $response );
1459
+                wp_send_json($response);
1460 1460
             }
1461 1461
 
1462
-            $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1463
-            $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1462
+            $vies_company = !empty($result['company']) ? $result['company'] : '';
1463
+            $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1464 1464
 
1465
-            $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1465
+            $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1466 1466
 
1467
-            if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) {
1467
+            if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) {
1468 1468
                 $response['success'] = true;
1469
-                $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1469
+                $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1470 1470
             } else {
1471 1471
                 $vat_info['valid'] = false;
1472
-                getpaid_session()->set( 'user_vat_data', $vat_info );
1472
+                getpaid_session()->set('user_vat_data', $vat_info);
1473 1473
 
1474 1474
                 $response['success'] = false;
1475
-                $response['message'] = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1476
-                wp_send_json( $response );
1475
+                $response['message'] = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1476
+                wp_send_json($response);
1477 1477
             }
1478 1478
         }
1479 1479
 
1480
-        wp_send_json( $response );
1480
+        wp_send_json($response);
1481 1481
     }
1482 1482
 
1483 1483
     /**
@@ -1485,16 +1485,16 @@  discard block
 block discarded – undo
1485 1485
      * 
1486 1486
      * @return string
1487 1487
      */
1488
-    public static function validate_vat_number( $vat_number, $company, $country ) {
1488
+    public static function validate_vat_number($vat_number, $company, $country) {
1489 1489
         global $wpinv_options;
1490 1490
 
1491 1491
         // If we are not checking the vat number via view...
1492
-        if ( ! empty( $wpinv_options['vat_vies_check'] ) ) {
1492
+        if (!empty($wpinv_options['vat_vies_check'])) {
1493 1493
 
1494 1494
             // Try validating via regex.
1495
-            if ( empty( $wpinv_options['vat_offline_check'] ) && ! self::offline_check( $vat_number, $country ) ) {
1495
+            if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number, $country)) {
1496 1496
                 return wp_sprintf(
1497
-                    __( 'Your %s number is invalid', 'invoicing' ),
1497
+                    __('Your %s number is invalid', 'invoicing'),
1498 1498
                     getpaid_vat_name()
1499 1499
                 );
1500 1500
             }
@@ -1503,23 +1503,23 @@  discard block
 block discarded – undo
1503 1503
         }
1504 1504
 
1505 1505
         // Validate the vat number.
1506
-        $result = self::check_vat( $vat_number, $country );
1506
+        $result = self::check_vat($vat_number, $country);
1507 1507
 
1508
-        if ( empty( $result['valid'] ) ) {
1508
+        if (empty($result['valid'])) {
1509 1509
             return wp_sprintf(
1510
-                __( 'Failed to validate the %s number via EU Commission VAT server (VIES).', 'invoicing' ),
1510
+                __('Failed to validate the %s number via EU Commission VAT server (VIES).', 'invoicing'),
1511 1511
                 getpaid_vat_name()
1512 1512
             );
1513 1513
         }
1514 1514
 
1515 1515
         // Validate the company.
1516
-        $vies_company  = ! empty( $result['company'] ) ? $result['company'] : '';
1517
-        $vies_company  = apply_filters( 'wpinv_vies_company_name', $vies_company );
1518
-        $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1516
+        $vies_company  = !empty($result['company']) ? $result['company'] : '';
1517
+        $vies_company  = apply_filters('wpinv_vies_company_name', $vies_company);
1518
+        $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1519 1519
 
1520
-        if ( ! $valid_company && ! empty( $wpinv_options['vat_disable_company_name_check'] ) ) {
1520
+        if (!$valid_company && !empty($wpinv_options['vat_disable_company_name_check'])) {
1521 1521
            return wp_sprintf(
1522
-                __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ),
1522
+                __('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'),
1523 1523
                 getpaid_vat_name()
1524 1524
             );
1525 1525
         }
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 1 patch
Spacing   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Retrieves an item by it's ID.
@@ -14,9 +14,9 @@  discard block
 block discarded – undo
14 14
  * @param int the item ID to retrieve.
15 15
  * @return WPInv_Item|false
16 16
  */
17
-function wpinv_get_item_by_id( $id ) {
18
-    $item = wpinv_get_item( $id );
19
-    return empty( $item ) || $id != $item->get_id() ? false : $item;
17
+function wpinv_get_item_by_id($id) {
18
+    $item = wpinv_get_item($id);
19
+    return empty($item) || $id != $item->get_id() ? false : $item;
20 20
 }
21 21
 
22 22
 /**
@@ -24,14 +24,14 @@  discard block
 block discarded – undo
24 24
  * 
25 25
  * @return WPInv_Item|false
26 26
  */
27
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
27
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
28 28
 
29
-    if ( 'id' == strtolower( $field ) ) {
30
-        return wpinv_get_item_by_id( $field );
29
+    if ('id' == strtolower($field)) {
30
+        return wpinv_get_item_by_id($field);
31 31
     }
32 32
 
33
-    $id = WPInv_Item::get_item_id_by_field( $value, strtolower( $field ), $type );
34
-    return empty( $id ) ? false : wpinv_get_item( $id );
33
+    $id = WPInv_Item::get_item_id_by_field($value, strtolower($field), $type);
34
+    return empty($id) ? false : wpinv_get_item($id);
35 35
 
36 36
 }
37 37
 
@@ -41,22 +41,22 @@  discard block
 block discarded – undo
41 41
  * @param int|WPInv_Item the item to retrieve.
42 42
  * @return WPInv_Item|false
43 43
  */
44
-function wpinv_get_item( $item = 0 ) {
44
+function wpinv_get_item($item = 0) {
45 45
 
46
-    if ( empty( $item ) ) {
46
+    if (empty($item)) {
47 47
         return false;
48 48
     }
49 49
 
50
-    $item = new WPInv_Item( $item );
50
+    $item = new WPInv_Item($item);
51 51
     return $item->exists() ? $item : false;
52 52
 
53 53
 }
54 54
 
55
-function wpinv_get_all_items( $args = array() ) {
55
+function wpinv_get_all_items($args = array()) {
56 56
 
57
-    $args = wp_parse_args( $args, array(
58
-        'status'         => array( 'publish' ),
59
-        'limit'          => get_option( 'posts_per_page' ),
57
+    $args = wp_parse_args($args, array(
58
+        'status'         => array('publish'),
59
+        'limit'          => get_option('posts_per_page'),
60 60
         'page'           => 1,
61 61
         'exclude'        => array(),
62 62
         'orderby'        => 'date',
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
         'meta_query'     => array(),
66 66
         'return'         => 'objects',
67 67
         'paginate'       => false,
68
-    ) );
68
+    ));
69 69
 
70 70
     $wp_query_args = array(
71 71
         'post_type'      => 'wpi_item',
@@ -75,26 +75,26 @@  discard block
 block discarded – undo
75 75
         'fields'         => 'ids',
76 76
         'orderby'        => $args['orderby'],
77 77
         'order'          => $args['order'],
78
-        'paged'          => absint( $args['page'] ),
78
+        'paged'          => absint($args['page']),
79 79
     );
80 80
 
81
-    if ( ! empty( $args['exclude'] ) ) {
82
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
81
+    if (!empty($args['exclude'])) {
82
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
83 83
     }
84 84
 
85
-    if ( ! $args['paginate' ] ) {
85
+    if (!$args['paginate']) {
86 86
         $wp_query_args['no_found_rows'] = true;
87 87
     }
88 88
 
89
-    if ( ! empty( $args['search'] ) ) {
89
+    if (!empty($args['search'])) {
90 90
         $wp_query_args['s'] = $args['search'];
91 91
     }
92 92
 
93
-    if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) {
94
-        $types = wpinv_parse_list( $args['type'] );
93
+    if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) {
94
+        $types = wpinv_parse_list($args['type']);
95 95
         $wp_query_args['meta_query'][] = array(
96 96
             'key'     => '_wpinv_type',
97
-            'value'   => implode( ',', $types ),
97
+            'value'   => implode(',', $types),
98 98
             'compare' => 'IN',
99 99
         );
100 100
     }
@@ -102,17 +102,17 @@  discard block
 block discarded – undo
102 102
     $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args);
103 103
 
104 104
     // Get results.
105
-    $items = new WP_Query( $wp_query_args );
105
+    $items = new WP_Query($wp_query_args);
106 106
 
107
-    if ( 'objects' === $args['return'] ) {
108
-        $return = array_map( 'wpinv_get_item_by_id', $items->posts );
109
-    } elseif ( 'self' === $args['return'] ) {
107
+    if ('objects' === $args['return']) {
108
+        $return = array_map('wpinv_get_item_by_id', $items->posts);
109
+    } elseif ('self' === $args['return']) {
110 110
         return $items;
111 111
     } else {
112 112
         $return = $items->posts;
113 113
     }
114 114
 
115
-    if ( $args['paginate' ] ) {
115
+    if ($args['paginate']) {
116 116
         return (object) array(
117 117
             'items'      => $return,
118 118
             'total'         => $items->found_posts,
@@ -124,12 +124,12 @@  discard block
 block discarded – undo
124 124
 
125 125
 }
126 126
 
127
-function wpinv_is_free_item( $item_id = 0 ) {
128
-    if( empty( $item_id ) ) {
127
+function wpinv_is_free_item($item_id = 0) {
128
+    if (empty($item_id)) {
129 129
         return false;
130 130
     }
131 131
 
132
-    $item = new WPInv_Item( $item_id );
132
+    $item = new WPInv_Item($item_id);
133 133
     
134 134
     return $item->is_free();
135 135
 }
@@ -139,21 +139,21 @@  discard block
 block discarded – undo
139 139
  * 
140 140
  * @param WP_Post|WPInv_Item|Int $item The item to check for.
141 141
  */
142
-function wpinv_item_is_editable( $item = 0 ) {
142
+function wpinv_item_is_editable($item = 0) {
143 143
 
144 144
     // Fetch the item.
145
-    $item = new WPInv_Item( $item );
145
+    $item = new WPInv_Item($item);
146 146
 
147 147
     // Check if it is editable.
148 148
     return $item->is_editable();
149 149
 }
150 150
 
151
-function wpinv_get_item_price( $item_id = 0 ) {
152
-    if( empty( $item_id ) ) {
151
+function wpinv_get_item_price($item_id = 0) {
152
+    if (empty($item_id)) {
153 153
         return false;
154 154
     }
155 155
 
156
-    $item = new WPInv_Item( $item_id );
156
+    $item = new WPInv_Item($item_id);
157 157
     
158 158
     return $item->get_price();
159 159
 }
@@ -163,169 +163,169 @@  discard block
 block discarded – undo
163 163
  *
164 164
  * @param WPInv_Item|int $item
165 165
  */
166
-function wpinv_is_recurring_item( $item = 0 ) {
167
-    $item = new WPInv_Item( $item ); 
166
+function wpinv_is_recurring_item($item = 0) {
167
+    $item = new WPInv_Item($item); 
168 168
     return $item->is_recurring();
169 169
 }
170 170
 
171
-function wpinv_item_price( $item_id = 0 ) {
172
-    if( empty( $item_id ) ) {
171
+function wpinv_item_price($item_id = 0) {
172
+    if (empty($item_id)) {
173 173
         return false;
174 174
     }
175 175
 
176
-    $price = wpinv_get_item_price( $item_id );
177
-    $price = wpinv_price( wpinv_format_amount( $price ) );
176
+    $price = wpinv_get_item_price($item_id);
177
+    $price = wpinv_price(wpinv_format_amount($price));
178 178
     
179
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
179
+    return apply_filters('wpinv_item_price', $price, $item_id);
180 180
 }
181 181
 
182
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
183
-    if ( is_null( $amount_override ) ) {
184
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
182
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
183
+    if (is_null($amount_override)) {
184
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
185 185
     } else {
186 186
         $original_price = $amount_override;
187 187
     }
188 188
     
189 189
     $price = $original_price;
190 190
 
191
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
191
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
192 192
 }
193 193
 
194
-function wpinv_item_custom_singular_name( $item_id ) {
195
-    if( empty( $item_id ) ) {
194
+function wpinv_item_custom_singular_name($item_id) {
195
+    if (empty($item_id)) {
196 196
         return false;
197 197
     }
198 198
 
199
-    $item = new WPInv_Item( $item_id );
199
+    $item = new WPInv_Item($item_id);
200 200
     
201 201
     return $item->get_custom_singular_name();
202 202
 }
203 203
 
204 204
 function wpinv_get_item_types() {
205 205
     $item_types = array(
206
-            'custom'    => __( 'Standard', 'invoicing' ),
207
-            'fee'       => __( 'Fee', 'invoicing' ),
206
+            'custom'    => __('Standard', 'invoicing'),
207
+            'fee'       => __('Fee', 'invoicing'),
208 208
         );
209
-    return apply_filters( 'wpinv_get_item_types', $item_types );
209
+    return apply_filters('wpinv_get_item_types', $item_types);
210 210
 }
211 211
 
212 212
 function wpinv_item_types() {
213 213
     $item_types = wpinv_get_item_types();
214 214
     
215
-    return ( !empty( $item_types ) ? array_keys( $item_types ) : array() );
215
+    return (!empty($item_types) ? array_keys($item_types) : array());
216 216
 }
217 217
 
218
-function wpinv_get_item_type( $item_id ) {
219
-    if( empty( $item_id ) ) {
218
+function wpinv_get_item_type($item_id) {
219
+    if (empty($item_id)) {
220 220
         return false;
221 221
     }
222 222
 
223
-    $item = new WPInv_Item( $item_id );
223
+    $item = new WPInv_Item($item_id);
224 224
     
225 225
     return $item->get_type();
226 226
 }
227 227
 
228
-function wpinv_item_type( $item_id ) {
228
+function wpinv_item_type($item_id) {
229 229
     $item_types = wpinv_get_item_types();
230 230
     
231
-    $item_type = wpinv_get_item_type( $item_id );
231
+    $item_type = wpinv_get_item_type($item_id);
232 232
     
233
-    if ( empty( $item_type ) ) {
233
+    if (empty($item_type)) {
234 234
         $item_type = '-';
235 235
     }
236 236
     
237
-    $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' );
237
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
238 238
 
239
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
239
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
240 240
 }
241 241
 
242
-function wpinv_get_random_item( $post_ids = true ) {
243
-    wpinv_get_random_items( 1, $post_ids );
242
+function wpinv_get_random_item($post_ids = true) {
243
+    wpinv_get_random_items(1, $post_ids);
244 244
 }
245 245
 
246
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
247
-    if ( $post_ids ) {
248
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' );
246
+function wpinv_get_random_items($num = 3, $post_ids = true) {
247
+    if ($post_ids) {
248
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids');
249 249
     } else {
250
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num );
250
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num);
251 251
     }
252 252
     
253
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
253
+    $args = apply_filters('wpinv_get_random_items', $args);
254 254
     
255
-    return get_posts( $args );
255
+    return get_posts($args);
256 256
 }
257 257
 
258
-function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) {
258
+function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) {
259 259
     $tax = 0;
260
-    if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) {
261
-        $country = !empty( $_POST['country'] ) ? $_POST['country'] : false;
262
-        $state   = isset( $_POST['state'] ) ? $_POST['state'] : '';
260
+    if (!wpinv_item_is_tax_exclusive($item_id)) {
261
+        $country = !empty($_POST['country']) ? $_POST['country'] : false;
262
+        $state   = isset($_POST['state']) ? $_POST['state'] : '';
263 263
 
264
-        $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id );
264
+        $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id);
265 265
     }
266 266
 
267
-    return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options );
267
+    return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options);
268 268
 }
269 269
 
270
-function wpinv_cart_item_price( $item, $currency = '' ) {
270
+function wpinv_cart_item_price($item, $currency = '') {
271 271
 
272
-    if( empty( $currency ) ) {
272
+    if (empty($currency)) {
273 273
         $currency = wpinv_get_currency();
274 274
     }
275 275
 
276
-    $item_id    = isset( $item['id'] ) ? $item['id'] : 0;
277
-    $price      = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0;
278
-    $tax        = wpinv_price( wpinv_format_amount( $item['tax'] ) );
276
+    $item_id    = isset($item['id']) ? $item['id'] : 0;
277
+    $price      = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0;
278
+    $tax        = wpinv_price(wpinv_format_amount($item['tax']));
279 279
     
280
-    if ( !wpinv_is_free_item( $item_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) {
281
-        if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) {
280
+    if (!wpinv_is_free_item($item_id) && !wpinv_item_is_tax_exclusive($item_id)) {
281
+        if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) {
282 282
             $price += $tax;
283 283
         }
284 284
         
285
-        if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) {
285
+        if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) {
286 286
             $price -= $tax;
287 287
         }        
288 288
     }
289 289
 
290
-    $price = wpinv_price( wpinv_format_amount( $price ), $currency );
290
+    $price = wpinv_price(wpinv_format_amount($price), $currency);
291 291
 
292
-    return apply_filters( 'wpinv_cart_item_price_label', $price, $item );
292
+    return apply_filters('wpinv_cart_item_price_label', $price, $item);
293 293
 }
294 294
 
295
-function wpinv_cart_item_subtotal( $item, $currency = '' ) {
295
+function wpinv_cart_item_subtotal($item, $currency = '') {
296 296
 
297
-    if( empty( $currency ) ) {
297
+    if (empty($currency)) {
298 298
         $currency = wpinv_get_currency();
299 299
     }
300 300
 
301
-    $subtotal   = isset( $item['subtotal'] ) ? $item['subtotal'] : 0;
302
-    $subtotal   = wpinv_price( wpinv_format_amount( $subtotal ), $currency );
301
+    $subtotal   = isset($item['subtotal']) ? $item['subtotal'] : 0;
302
+    $subtotal   = wpinv_price(wpinv_format_amount($subtotal), $currency);
303 303
 
304
-    return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item );
304
+    return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item);
305 305
 }
306 306
 
307
-function wpinv_cart_item_tax( $item, $currency = '' ) {
307
+function wpinv_cart_item_tax($item, $currency = '') {
308 308
     $tax        = '';
309 309
     $tax_rate   = '';
310 310
 
311
-    if( empty( $currency ) ) {
311
+    if (empty($currency)) {
312 312
         $currency = wpinv_get_currency();
313 313
     }
314 314
     
315
-    if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) {
316
-        $tax      = wpinv_price( wpinv_format_amount( $item['tax'] ), $currency );
317
-        $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100;
318
-        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
315
+    if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) {
316
+        $tax      = wpinv_price(wpinv_format_amount($item['tax']), $currency);
317
+        $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100;
318
+        $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : '';
319 319
         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : '';
320 320
     }
321 321
     
322
-    $tax        = $tax . $tax_rate;
322
+    $tax = $tax . $tax_rate;
323 323
     
324
-    if ( $tax === '' ) {
324
+    if ($tax === '') {
325 325
         $tax = 0; // Zero tax
326 326
     }
327 327
 
328
-    return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item );
328
+    return apply_filters('wpinv_cart_item_tax_label', $tax, $item);
329 329
 }
330 330
 
331 331
 /**
@@ -334,13 +334,13 @@  discard block
 block discarded – undo
334 334
  * @param WPInv_Item|int $item
335 335
  * @param bool $html
336 336
  */
337
-function wpinv_get_item_suffix( $item, $html = true ) {
337
+function wpinv_get_item_suffix($item, $html = true) {
338 338
 
339
-    $item   = new WPInv_Item( $item );
340
-    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '';
341
-    $suffix = $html ? $suffix : strip_tags( $suffix );
339
+    $item   = new WPInv_Item($item);
340
+    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '';
341
+    $suffix = $html ? $suffix : strip_tags($suffix);
342 342
 
343
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
343
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
344 344
 }
345 345
 
346 346
 /**
@@ -349,9 +349,9 @@  discard block
 block discarded – undo
349 349
  * @param WPInv_Item|int $item
350 350
  * @param bool $force_delete
351 351
  */
352
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
353
-    $item = new WPInv_Item( $item );
354
-    $item->delete( $force_delete );
352
+function wpinv_remove_item($item = 0, $force_delete = false) {
353
+    $item = new WPInv_Item($item);
354
+    $item->delete($force_delete);
355 355
 }
356 356
 
357 357
 /**
@@ -390,45 +390,45 @@  discard block
 block discarded – undo
390 390
  * @param bool $wp_error whether or not to return a WP_Error on failure.
391 391
  * @return bool|WP_Error|WPInv_Item
392 392
  */
393
-function wpinv_create_item( $args = array(), $wp_error = false ) {
393
+function wpinv_create_item($args = array(), $wp_error = false) {
394 394
 
395 395
     // Prepare the item.
396
-    if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) {
397
-        $type = empty( $args['type'] ) ? 'custom' : $args['type'];
398
-        $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type );
396
+    if (!empty($args['custom_id']) && empty($args['ID'])) {
397
+        $type = empty($args['type']) ? 'custom' : $args['type'];
398
+        $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type);
399 399
 
400
-        if ( ! empty( $item ) ) {
400
+        if (!empty($item)) {
401 401
             $args['ID'] = $item->get_id();
402 402
         }
403 403
 
404 404
     }
405 405
 
406 406
     // Do we have an item?
407
-    if ( ! empty( $args['ID'] ) ) {
408
-        $item = new WPInv_Item( $args['ID'] );
407
+    if (!empty($args['ID'])) {
408
+        $item = new WPInv_Item($args['ID']);
409 409
     } else {
410 410
         $item = new WPInv_Item();
411 411
     }
412 412
 
413 413
     // Do we have an error?
414
-    if ( ! empty( $item->last_error ) ) {
415
-        return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false;
414
+    if (!empty($item->last_error)) {
415
+        return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false;
416 416
     }
417 417
 
418 418
     // Update item props.
419
-    $item->set_props( $args );
419
+    $item->set_props($args);
420 420
 
421 421
     // Save the item.
422 422
     $item->save();
423 423
 
424 424
     // Do we have an error?
425
-    if ( ! empty( $item->last_error ) ) {
426
-        return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false;
425
+    if (!empty($item->last_error)) {
426
+        return $wp_error ? new WP_Error('not_saved', $item->last_error) : false;
427 427
     }
428 428
 
429 429
     // Was the item saved?
430
-    if ( ! $item->get_id() ) {
431
-        return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false;
430
+    if (!$item->get_id()) {
431
+        return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false;
432 432
     }
433 433
 
434 434
     return $item;
@@ -440,14 +440,14 @@  discard block
 block discarded – undo
440 440
  * 
441 441
  * @see wpinv_create_item()
442 442
  */
443
-function wpinv_update_item( $args = array(), $wp_error = false ) {
444
-    return wpinv_create_item( $args, $wp_error );
443
+function wpinv_update_item($args = array(), $wp_error = false) {
444
+    return wpinv_create_item($args, $wp_error);
445 445
 }
446 446
 
447 447
 /**
448 448
  * Sanitizes a recurring period
449 449
  */
450
-function getpaid_sanitize_recurring_period( $period, $full = false ) {
450
+function getpaid_sanitize_recurring_period($period, $full = false) {
451 451
 
452 452
     $periods = array(
453 453
         'D' => 'day',
@@ -456,11 +456,11 @@  discard block
 block discarded – undo
456 456
         'Y' => 'year',
457 457
     );
458 458
 
459
-    if ( ! isset( $periods[ $period ] ) ) {
459
+    if (!isset($periods[$period])) {
460 460
         $period = 'D';
461 461
     }
462 462
 
463
-    return $full ? $periods[ $period ] : $period;
463
+    return $full ? $periods[$period] : $period;
464 464
 
465 465
 }
466 466
 
@@ -469,34 +469,34 @@  discard block
 block discarded – undo
469 469
  * 
470 470
  * @param WPInv_Item|GetPaid_Form_Item $item
471 471
  */
472
-function getpaid_item_recurring_price_help_text( $item, $currency = '' ) {
472
+function getpaid_item_recurring_price_help_text($item, $currency = '') {
473 473
 
474 474
     // Abort if it is not recurring.
475
-    if ( ! $item->is_recurring() ) {
475
+    if (!$item->is_recurring()) {
476 476
         return '';
477 477
     }
478 478
 
479
-    $initial_price   = wpinv_price( $item->get_initial_price(), $currency );
480
-    $recurring_price = wpinv_price( $item->get_recurring_price(), $currency );
481
-    $period          = getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' );
479
+    $initial_price   = wpinv_price($item->get_initial_price(), $currency);
480
+    $recurring_price = wpinv_price($item->get_recurring_price(), $currency);
481
+    $period          = getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '');
482 482
     $initial_class   = 'getpaid-item-initial-price';
483 483
     $recurring_class = 'getpaid-item-recurring-price';
484 484
 
485
-    if ( $item instanceof GetPaid_Form_Item ) {
486
-        $initial_price   = wpinv_price( $item->get_sub_total(), $currency );
487
-        $recurring_price = wpinv_price( $item->get_recurring_sub_total(), $currency );
485
+    if ($item instanceof GetPaid_Form_Item) {
486
+        $initial_price   = wpinv_price($item->get_sub_total(), $currency);
487
+        $recurring_price = wpinv_price($item->get_recurring_sub_total(), $currency);
488 488
     }
489 489
 
490 490
     // For free trial items.
491
-    if ( $item->has_free_trial() ) {
492
-        $trial_period = getpaid_get_subscription_period_label( $item->get_trial_period(), $item->get_trial_interval() );
491
+    if ($item->has_free_trial()) {
492
+        $trial_period = getpaid_get_subscription_period_label($item->get_trial_period(), $item->get_trial_interval());
493 493
 
494
-        if ( 0 == $item->get_initial_price() ) {
494
+        if (0 == $item->get_initial_price()) {
495 495
 
496 496
             return sprintf(
497 497
 
498 498
                 // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period
499
-                _x( 'Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing' ),
499
+                _x('Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing'),
500 500
                 $trial_period,
501 501
                 "<span class='$recurring_class'>$recurring_price</span>",
502 502
                 $period
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
         return sprintf(
509 509
 
510 510
             // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period
511
-            _x( '%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing' ),
511
+            _x('%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing'),
512 512
             "<span class='$initial_class'>$initial_price</span>",
513 513
             $trial_period,
514 514
             "<span class='$recurring_class'>$recurring_price</span>",
@@ -518,12 +518,12 @@  discard block
 block discarded – undo
518 518
 
519 519
     }
520 520
 
521
-    if ( $initial_price == $recurring_price ) {
521
+    if ($initial_price == $recurring_price) {
522 522
 
523 523
         return sprintf(
524 524
 
525 525
             // translators: $1: is the recurring price, $2: is the susbcription period
526
-            _x( '%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing' ),
526
+            _x('%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing'),
527 527
             "<span class='$recurring_class'>$recurring_price</span>",
528 528
             $period
529 529
 
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
     return sprintf(
535 535
 
536 536
         // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period
537
-        _x( 'Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing' ),
537
+        _x('Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing'),
538 538
         "<span class='$initial_class'>$initial_price</span>",
539 539
         "<span class='$recurring_class'>$recurring_price</span>",
540 540
         $period
Please login to merge, or discard this patch.