Passed
Push — master ( 67eff9...f05b42 )
by Brian
04:47
created
includes/class-wpinv-addons.php 1 patch
Indentation   +216 added lines, -216 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  *
7 7
  */
8 8
 if ( ! defined( 'ABSPATH' ) ) {
9
-	exit;
9
+    exit;
10 10
 }
11 11
 
12 12
 /**
@@ -15,85 +15,85 @@  discard block
 block discarded – undo
15 15
 class WPInv_Admin_Addons extends Ayecode_Addons {
16 16
 
17 17
 
18
-	/**
19
-	 * Get the extensions page tabs.
20
-	 *
21
-	 * @return array of tabs.
22
-	 */
23
-	public function get_tabs(){
24
-		$tabs = array(
25
-			'addons' => __("Addons", "invoicing"),
18
+    /**
19
+     * Get the extensions page tabs.
20
+     *
21
+     * @return array of tabs.
22
+     */
23
+    public function get_tabs(){
24
+        $tabs = array(
25
+            'addons' => __("Addons", "invoicing"),
26 26
             'gateways' => __("Payment Gateways", "invoicing"),
27 27
             'recommended_plugins' => __("Recommended plugins", "invoicing"),
28 28
             'membership' => __("Membership", "invoicing"),
29
-		);
30
-
31
-		return $tabs;
32
-	}
33
-
34
-	/**
35
-	 * Get section content for the addons screen.
36
-	 *
37
-	 * @param  string $section_id
38
-	 *
39
-	 * @return array
40
-	 */
41
-	public function get_section_data( $section_id ) {
42
-		$section      = self::get_tab( $section_id );
43
-		$api_url = "https://wpinvoicing.com/edd-api/v2/products/";
44
-		$section_data = new stdClass();
45
-
46
-		if($section_id=='recommended_plugins'){
47
-			$section_data->products = self::get_recommend_wp_plugins_edd_formatted();
48
-		}
49
-		elseif ( ! empty( $section ) ) {
50
-			if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing
51
-			//if ( 1==1) {
52
-
53
-				$query_args = array( 'category' => $section_id, 'number' => 100);
54
-				$query_args = apply_filters('wpeu_edd_api_query_args',$query_args,$api_url,$section_id);
55
-
56
-				$raw_section = wp_safe_remote_get( esc_url_raw( add_query_arg($query_args ,$api_url) ), array( 'user-agent' => 'Invoicing Addons Page','timeout'     => 15, ) );
57
-
58
-				if ( ! is_wp_error( $raw_section ) ) {
59
-					$section_data = json_decode( wp_remote_retrieve_body( $raw_section ) );
60
-
61
-					if ( ! empty( $section_data->products ) ) {
62
-						set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS );
63
-					}
64
-				}
65
-			}
66
-
67
-		}
68
-
69
-		$products = isset($section_data->products) ? $section_data->products : array();
70
-		if ( 'addons' == $section_id ) {
71
-
72
-			$quotes = new stdClass();
73
-			$quotes->info = new stdClass();
74
-			$quotes->info->id = '';
75
-			$quotes->info->slug = 'invoicing-quotes';
76
-			$quotes->info->title = __( 'Quotes', 'invoicing' );
77
-			$quotes->info->excerpt = __( 'Create quotes and estimates', 'invoicing' );
78
-			$quotes->info->link = 'https://wordpress.org/plugins/invoicing-quotes/';
79
-			$quotes->info->thumbnail = 'https://wpgetpaid.com/wp-content/uploads/sites/13/edd/2019/11/Quotes-1-768x384.png';
80
-
81
-			$products[] = $quotes;
82
-		}
29
+        );
30
+
31
+        return $tabs;
32
+    }
33
+
34
+    /**
35
+     * Get section content for the addons screen.
36
+     *
37
+     * @param  string $section_id
38
+     *
39
+     * @return array
40
+     */
41
+    public function get_section_data( $section_id ) {
42
+        $section      = self::get_tab( $section_id );
43
+        $api_url = "https://wpinvoicing.com/edd-api/v2/products/";
44
+        $section_data = new stdClass();
45
+
46
+        if($section_id=='recommended_plugins'){
47
+            $section_data->products = self::get_recommend_wp_plugins_edd_formatted();
48
+        }
49
+        elseif ( ! empty( $section ) ) {
50
+            if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing
51
+            //if ( 1==1) {
52
+
53
+                $query_args = array( 'category' => $section_id, 'number' => 100);
54
+                $query_args = apply_filters('wpeu_edd_api_query_args',$query_args,$api_url,$section_id);
55
+
56
+                $raw_section = wp_safe_remote_get( esc_url_raw( add_query_arg($query_args ,$api_url) ), array( 'user-agent' => 'Invoicing Addons Page','timeout'     => 15, ) );
57
+
58
+                if ( ! is_wp_error( $raw_section ) ) {
59
+                    $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) );
60
+
61
+                    if ( ! empty( $section_data->products ) ) {
62
+                        set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS );
63
+                    }
64
+                }
65
+            }
66
+
67
+        }
68
+
69
+        $products = isset($section_data->products) ? $section_data->products : array();
70
+        if ( 'addons' == $section_id ) {
71
+
72
+            $quotes = new stdClass();
73
+            $quotes->info = new stdClass();
74
+            $quotes->info->id = '';
75
+            $quotes->info->slug = 'invoicing-quotes';
76
+            $quotes->info->title = __( 'Quotes', 'invoicing' );
77
+            $quotes->info->excerpt = __( 'Create quotes and estimates', 'invoicing' );
78
+            $quotes->info->link = 'https://wordpress.org/plugins/invoicing-quotes/';
79
+            $quotes->info->thumbnail = 'https://wpgetpaid.com/wp-content/uploads/sites/13/edd/2019/11/Quotes-1-768x384.png';
80
+
81
+            $products[] = $quotes;
82
+        }
83 83
 		
84
-		return apply_filters( 'wpi_addons_section_data', $products, $section_id );
85
-	}
86
-
87
-	/**
88
-	 * Outputs a button.
89
-	 *ccc
90
-	 * @param string $url
91
-	 * @param string $text
92
-	 * @param string $theme
93
-	 * @param string $plugin
94
-	 */
95
-	public function output_button( $addon ) {
96
-		$current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
84
+        return apply_filters( 'wpi_addons_section_data', $products, $section_id );
85
+    }
86
+
87
+    /**
88
+     * Outputs a button.
89
+     *ccc
90
+     * @param string $url
91
+     * @param string $text
92
+     * @param string $theme
93
+     * @param string $plugin
94
+     */
95
+    public function output_button( $addon ) {
96
+        $current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
97 97
 //		$button_text = __('Free','invoicing');
98 98
 //		$licensing = false;
99 99
 //		$installed = false;
@@ -105,123 +105,123 @@  discard block
 block discarded – undo
105 105
 //		$install_status = 'get';
106 106
 //		$onclick = '';
107 107
 
108
-		$wp_org_themes = array('supreme-directory','directory-starter');
109
-
110
-		$button_args = array(
111
-			'type' => ($current_tab == 'addons' || $current_tab =='gateways') ? 'addons' : $current_tab,
112
-			'id' => isset($addon->info->id) ? absint($addon->info->id) : '',
113
-			'title' => isset($addon->info->title) ? $addon->info->title : '',
114
-			'button_text' => __('Free','invoicing'),
115
-			'price_text' => __('Free','invoicing'),
116
-			'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product
117
-			'url' => isset($addon->info->link) ? $addon->info->link : '', // button url
118
-			'class' => 'button-primary',
119
-			'install_status' => 'get',
120
-			'installed' => false,
121
-			'price' => '',
122
-			'licensing' => isset($addon->licensing->enabled) && $addon->licensing->enabled ? true : false,
123
-			'license' => isset($addon->licensing->license) && $addon->licensing->license ? $addon->licensing->license : '',
124
-			'onclick' => '',
125
-			'slug' => isset($addon->info->slug) ? $addon->info->slug : '',
126
-			'active' => false,
127
-			'file' => '',
128
-			'update_url' => '',
129
-		);
130
-
131
-		if( 'invoicing-quotes' == $addon->info->slug || 'getpaid-stripe-payments' == $addon->info->slug || ( $current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug )){
132
-			include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
133
-			$status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>""));
134
-			$button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install';
135
-			$button_args['file'] = isset($status['file']) ? $status['file'] : '';
136
-		}elseif( ($current_tab == 'addons' || $current_tab =='gateways') && isset($addon->info->id) && $addon->info->id){
137
-			include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
138
-			if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;}
139
-			$status = self::install_plugin_install_status($addon);
140
-			$button_args['file'] = isset($status['file']) ? $status['file'] : '';
141
-			if(isset($status['status'])){$button_args['install_status'] = $status['status'];}
142
-			$button_args['update_url'] = "https://wpinvoicing.com";
143
-		}elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) {
144
-			if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;}
145
-			$button_args['installed'] = self::is_theme_installed($addon);
146
-			if(!in_array($button_args['slug'],$wp_org_themes)){
147
-				$button_args['update_url'] = "https://wpinvoicing.com";
148
-			}
149
-		}
150
-
151
-		// set price
152
-		if(isset($addon->pricing) && !empty($addon->pricing)){
153
-			if(is_object($addon->pricing)){
154
-				$prices = (Array)$addon->pricing;
155
-				$button_args['price'] = reset($prices);
156
-			}elseif(isset($addon->pricing)){
157
-				$button_args['price'] = $addon->pricing;
158
-			}
159
-		}
160
-
161
-		// set price text
162
-		if( $button_args['price'] && $button_args['price'] != '0.00' ){
163
-			$button_args['price_text'] = sprintf( __('From: $%d', 'invoicing'), $button_args['price']);
164
-		}
165
-
166
-
167
-		// set if installed
168
-		if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){
169
-			$button_args['installed'] = true;
170
-		}
108
+        $wp_org_themes = array('supreme-directory','directory-starter');
109
+
110
+        $button_args = array(
111
+            'type' => ($current_tab == 'addons' || $current_tab =='gateways') ? 'addons' : $current_tab,
112
+            'id' => isset($addon->info->id) ? absint($addon->info->id) : '',
113
+            'title' => isset($addon->info->title) ? $addon->info->title : '',
114
+            'button_text' => __('Free','invoicing'),
115
+            'price_text' => __('Free','invoicing'),
116
+            'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product
117
+            'url' => isset($addon->info->link) ? $addon->info->link : '', // button url
118
+            'class' => 'button-primary',
119
+            'install_status' => 'get',
120
+            'installed' => false,
121
+            'price' => '',
122
+            'licensing' => isset($addon->licensing->enabled) && $addon->licensing->enabled ? true : false,
123
+            'license' => isset($addon->licensing->license) && $addon->licensing->license ? $addon->licensing->license : '',
124
+            'onclick' => '',
125
+            'slug' => isset($addon->info->slug) ? $addon->info->slug : '',
126
+            'active' => false,
127
+            'file' => '',
128
+            'update_url' => '',
129
+        );
130
+
131
+        if( 'invoicing-quotes' == $addon->info->slug || 'getpaid-stripe-payments' == $addon->info->slug || ( $current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug )){
132
+            include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
133
+            $status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>""));
134
+            $button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install';
135
+            $button_args['file'] = isset($status['file']) ? $status['file'] : '';
136
+        }elseif( ($current_tab == 'addons' || $current_tab =='gateways') && isset($addon->info->id) && $addon->info->id){
137
+            include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
138
+            if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;}
139
+            $status = self::install_plugin_install_status($addon);
140
+            $button_args['file'] = isset($status['file']) ? $status['file'] : '';
141
+            if(isset($status['status'])){$button_args['install_status'] = $status['status'];}
142
+            $button_args['update_url'] = "https://wpinvoicing.com";
143
+        }elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) {
144
+            if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;}
145
+            $button_args['installed'] = self::is_theme_installed($addon);
146
+            if(!in_array($button_args['slug'],$wp_org_themes)){
147
+                $button_args['update_url'] = "https://wpinvoicing.com";
148
+            }
149
+        }
150
+
151
+        // set price
152
+        if(isset($addon->pricing) && !empty($addon->pricing)){
153
+            if(is_object($addon->pricing)){
154
+                $prices = (Array)$addon->pricing;
155
+                $button_args['price'] = reset($prices);
156
+            }elseif(isset($addon->pricing)){
157
+                $button_args['price'] = $addon->pricing;
158
+            }
159
+        }
160
+
161
+        // set price text
162
+        if( $button_args['price'] && $button_args['price'] != '0.00' ){
163
+            $button_args['price_text'] = sprintf( __('From: $%d', 'invoicing'), $button_args['price']);
164
+        }
165
+
166
+
167
+        // set if installed
168
+        if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){
169
+            $button_args['installed'] = true;
170
+        }
171 171
 
172 172
 //		print_r($button_args);
173
-		// set if active
174
-		if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){
175
-			if($button_args['type'] != 'themes'){
176
-				$button_args['active'] = is_plugin_active($button_args['file']);
177
-			}else{
178
-				$button_args['active'] = self::is_theme_active($addon);
179
-			}
180
-		}
181
-
182
-		// set button text and class
183
-		if($button_args['active']){
184
-			$button_args['button_text'] = __('Active','invoicing');
185
-			$button_args['class'] = ' button-secondary disabled ';
186
-		}elseif($button_args['installed']){
187
-			$button_args['button_text'] = __('Activate','invoicing');
188
-
189
-			if($button_args['type'] != 'themes'){
190
-				if ( current_user_can( 'manage_options' ) ) {
191
-					$button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']);
192
-				}else{
193
-					$button_args['url'] = '#';
194
-				}
195
-			}else{
196
-				if ( current_user_can( 'switch_themes' ) ) {
197
-					$button_args['url'] = self::get_theme_activation_url($addon);
198
-				}else{
199
-					$button_args['url'] = '#';
200
-				}
201
-			}
202
-
203
-		}else{
204
-			if($button_args['type'] == 'recommended_plugins'){
205
-				$button_args['button_text'] = __('Install','invoicing');
206
-			}else{
207
-				$button_args['button_text'] = __('Get it','invoicing');
208
-
209
-				/*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){
173
+        // set if active
174
+        if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){
175
+            if($button_args['type'] != 'themes'){
176
+                $button_args['active'] = is_plugin_active($button_args['file']);
177
+            }else{
178
+                $button_args['active'] = self::is_theme_active($addon);
179
+            }
180
+        }
181
+
182
+        // set button text and class
183
+        if($button_args['active']){
184
+            $button_args['button_text'] = __('Active','invoicing');
185
+            $button_args['class'] = ' button-secondary disabled ';
186
+        }elseif($button_args['installed']){
187
+            $button_args['button_text'] = __('Activate','invoicing');
188
+
189
+            if($button_args['type'] != 'themes'){
190
+                if ( current_user_can( 'manage_options' ) ) {
191
+                    $button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']);
192
+                }else{
193
+                    $button_args['url'] = '#';
194
+                }
195
+            }else{
196
+                if ( current_user_can( 'switch_themes' ) ) {
197
+                    $button_args['url'] = self::get_theme_activation_url($addon);
198
+                }else{
199
+                    $button_args['url'] = '#';
200
+                }
201
+            }
202
+
203
+        }else{
204
+            if($button_args['type'] == 'recommended_plugins'){
205
+                $button_args['button_text'] = __('Install','invoicing');
206
+            }else{
207
+                $button_args['button_text'] = __('Get it','invoicing');
208
+
209
+                /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){
210 210
 					$button_args['button_text'] = __('Install','invoicing');
211 211
 					$button_args['url'] = self::get_theme_install_url($button_args['slug']);
212 212
 					$button_args['onclick'] = 'gd_set_button_installing(this);';
213 213
 				}*/
214 214
 
215
-			}
216
-		}
215
+            }
216
+        }
217 217
 
218 218
 		
219
-		// filter the button arguments
220
-		$button_args = apply_filters('edd_api_button_args',$button_args);
219
+        // filter the button arguments
220
+        $button_args = apply_filters('edd_api_button_args',$button_args);
221 221
 //		print_r($button_args);
222
-		// set price text
223
-		if(isset($button_args['price_text'])){
224
-			?>
222
+        // set price text
223
+        if(isset($button_args['price_text'])){
224
+            ?>
225 225
 			<a
226 226
 				target="_blank"
227 227
 				class="addons-price-text"
@@ -229,15 +229,15 @@  discard block
 block discarded – undo
229 229
 				<?php echo esc_html( $button_args['price_text'] ); ?>
230 230
 			</a>
231 231
 			<?php
232
-		}
232
+        }
233 233
 
234 234
 
235
-		$target = '';
236
-		if ( ! empty( $button_args['url'] ) ) {
237
-			$target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" ';
238
-		}
235
+        $target = '';
236
+        if ( ! empty( $button_args['url'] ) ) {
237
+            $target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" ';
238
+        }
239 239
 
240
-		?>
240
+        ?>
241 241
 		<a
242 242
 			data-licence="<?php echo esc_attr($button_args['license']);?>"
243 243
 			data-licensing="<?php echo $button_args['licensing'] ? 1 : 0;?>"
@@ -260,33 +260,33 @@  discard block
 block discarded – undo
260 260
 		<?php
261 261
 
262 262
 
263
-	}
264
-
265
-
266
-	/**
267
-	 * Handles output of the addons page in admin.
268
-	 */
269
-	public function output() {
270
-		$tabs            = self::get_tabs();
271
-		$sections        = self::get_sections();
272
-		$theme           = wp_get_theme();
273
-		$section_keys    = array_keys( $sections );
274
-		$current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys );
275
-		$current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
276
-		include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' );
277
-	}
278
-
279
-	/**
280
-	 * A list of recommended wp.org plugins.
281
-	 * @return array
282
-	 */
283
-	public function get_recommend_wp_plugins(){
284
-		$plugins = array(
263
+    }
264
+
265
+
266
+    /**
267
+     * Handles output of the addons page in admin.
268
+     */
269
+    public function output() {
270
+        $tabs            = self::get_tabs();
271
+        $sections        = self::get_sections();
272
+        $theme           = wp_get_theme();
273
+        $section_keys    = array_keys( $sections );
274
+        $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys );
275
+        $current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
276
+        include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' );
277
+    }
278
+
279
+    /**
280
+     * A list of recommended wp.org plugins.
281
+     * @return array
282
+     */
283
+    public function get_recommend_wp_plugins(){
284
+        $plugins = array(
285 285
             'invoicing-quotes' => array(
286 286
                 'url'   => 'https://wordpress.org/plugins/invoicing-quotes/',
287 287
                 'slug'   => 'invoicing-quotes',
288
-				'name'   => 'Quotes',
289
-				'thumbnail'  => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.png',
288
+                'name'   => 'Quotes',
289
+                'thumbnail'  => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.png',
290 290
                 'desc'   => __('Allows you to create quotes, send them to clients and convert them to Invoices when accepted by the customer.','invoicing'),
291 291
             ),
292 292
             'geodirectory' => array(
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
                 'name'   => 'UsersWP',
302 302
                 'desc'   => __('Allow frontend user login and registration as well as have slick profile pages.','invoicing'),
303 303
             ),
304
-		);
304
+        );
305 305
 
306
-		return $plugins;
307
-	}
306
+        return $plugins;
307
+    }
308 308
 }
Please login to merge, or discard this patch.
vendor/ayecode/wp-font-awesome-settings/wp-font-awesome-settings.php 1 patch
Indentation   +403 added lines, -403 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * Bail if we are not in WP.
14 14
  */
15 15
 if ( ! defined( 'ABSPATH' ) ) {
16
-	exit;
16
+    exit;
17 17
 }
18 18
 
19 19
 /**
@@ -21,300 +21,300 @@  discard block
 block discarded – undo
21 21
  */
22 22
 if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) {
23 23
 
24
-	/**
25
-	 * A Class to be able to change settings for Font Awesome.
26
-	 *
27
-	 * Class WP_Font_Awesome_Settings
28
-	 * @since 1.0.10 Now able to pass wp.org theme check.
29
-	 * @since 1.0.11 Font Awesome Pro now supported.
30
-	 * @since 1.0.11 Font Awesome Kits now supported.
31
-	 * @since 1.0.13 RTL language support added.
32
-	 * @ver 1.0.13
33
-	 * @todo decide how to implement textdomain
34
-	 */
35
-	class WP_Font_Awesome_Settings {
36
-
37
-		/**
38
-		 * Class version version.
39
-		 *
40
-		 * @var string
41
-		 */
42
-		public $version = '1.0.13';
43
-
44
-		/**
45
-		 * Class textdomain.
46
-		 *
47
-		 * @var string
48
-		 */
49
-		public $textdomain = 'font-awesome-settings';
50
-
51
-		/**
52
-		 * Latest version of Font Awesome at time of publish published.
53
-		 *
54
-		 * @var string
55
-		 */
56
-		public $latest = "5.8.2";
57
-
58
-		/**
59
-		 * The title.
60
-		 *
61
-		 * @var string
62
-		 */
63
-		public $name = 'Font Awesome';
64
-
65
-		/**
66
-		 * Holds the settings values.
67
-		 *
68
-		 * @var array
69
-		 */
70
-		private $settings;
71
-
72
-		/**
73
-		 * WP_Font_Awesome_Settings instance.
74
-		 *
75
-		 * @access private
76
-		 * @since  1.0.0
77
-		 * @var    WP_Font_Awesome_Settings There can be only one!
78
-		 */
79
-		private static $instance = null;
80
-
81
-		/**
82
-		 * Main WP_Font_Awesome_Settings Instance.
83
-		 *
84
-		 * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
85
-		 *
86
-		 * @since 1.0.0
87
-		 * @static
88
-		 * @return WP_Font_Awesome_Settings - Main instance.
89
-		 */
90
-		public static function instance() {
91
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
92
-				self::$instance = new WP_Font_Awesome_Settings;
93
-
94
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
95
-
96
-				if ( is_admin() ) {
97
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
98
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
99
-				}
100
-
101
-				do_action( 'wp_font_awesome_settings_loaded' );
102
-			}
103
-
104
-			return self::$instance;
105
-		}
106
-
107
-		/**
108
-		 * Initiate the settings and add the required action hooks.
109
-		 *
110
-		 * @since 1.0.8 Settings name wrong - FIXED
111
-		 */
112
-		public function init() {
113
-			$this->settings = $this->get_settings();
114
-
115
-			if ( $this->settings['type'] == 'CSS' ) {
116
-
117
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
118
-					add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
119
-				}
120
-
121
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
122
-					add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
123
-				}
124
-
125
-			} else {
126
-
127
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
128
-					add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
129
-				}
130
-
131
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
132
-					add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
133
-				}
134
-			}
135
-
136
-			// remove font awesome if set to do so
137
-			if ( $this->settings['dequeue'] == '1' ) {
138
-				add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
139
-			}
140
-
141
-		}
142
-
143
-		/**
144
-		 * Adds the Font Awesome styles.
145
-		 */
146
-		public function enqueue_style() {
147
-			// build url
148
-			$url = $this->get_url();
149
-
150
-			wp_deregister_style( 'font-awesome' ); // deregister in case its already there
151
-			wp_register_style( 'font-awesome', $url, array(), null );
152
-			wp_enqueue_style( 'font-awesome' );
153
-
154
-			// RTL language support CSS.
155
-			if ( is_rtl() ) {
156
-				wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() );
157
-			}
158
-
159
-			if ( $this->settings['shims'] ) {
160
-				$url = $this->get_url( true );
161
-				wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
162
-				wp_register_style( 'font-awesome-shims', $url, array(), null );
163
-				wp_enqueue_style( 'font-awesome-shims' );
164
-			}
165
-		}
166
-
167
-		/**
168
-		 * Adds the Font Awesome JS.
169
-		 */
170
-		public function enqueue_scripts() {
171
-			// build url
172
-			$url = $this->get_url();
173
-
174
-			$deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
175
-			call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
176
-			wp_register_script( 'font-awesome', $url, array(), null );
177
-			wp_enqueue_script( 'font-awesome' );
178
-
179
-			if ( $this->settings['shims'] ) {
180
-				$url = $this->get_url( true );
181
-				call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
182
-				wp_register_script( 'font-awesome-shims', $url, array(), null );
183
-				wp_enqueue_script( 'font-awesome-shims' );
184
-			}
185
-		}
186
-
187
-		/**
188
-		 * Get the url of the Font Awesome files.
189
-		 *
190
-		 * @param bool $shims If this is a shim file or not.
191
-		 *
192
-		 * @return string The url to the file.
193
-		 */
194
-		public function get_url( $shims = false ) {
195
-			$script  = $shims ? 'v4-shims' : 'all';
196
-			$sub     = $this->settings['pro'] ? 'pro' : 'use';
197
-			$type    = $this->settings['type'];
198
-			$version = $this->settings['version'];
199
-			$kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : '';
200
-			$url     = '';
201
-
202
-			if ( $type == 'KIT' && $kit_url ) {
203
-				if ( $shims ) {
204
-					// if its a kit then we don't add shims here
205
-					return '';
206
-				}
207
-				$url .= $kit_url; // CDN
208
-				$url .= "?wpfas=true"; // set our var so our version is not removed
209
-			} else {
210
-				$url .= "https://$sub.fontawesome.com/releases/"; // CDN
211
-				$url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
212
-				$url .= $type == 'CSS' ? 'css/' : 'js/'; // type
213
-				$url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
214
-				$url .= "?wpfas=true"; // set our var so our version is not removed
215
-			}
216
-
217
-			return $url;
218
-		}
219
-
220
-		/**
221
-		 * Try and remove any other versions of Font Awesome added by other plugins/themes.
222
-		 *
223
-		 * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version.
224
-		 *
225
-		 * @param $url
226
-		 * @param $original_url
227
-		 * @param $_context
228
-		 *
229
-		 * @return string The filtered url.
230
-		 */
231
-		public function remove_font_awesome( $url, $original_url, $_context ) {
232
-
233
-			if ( $_context == 'display'
234
-			     && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
235
-			     && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
236
-			) {// it's a font-awesome-url (probably)
237
-
238
-				if ( strstr( $url, "wpfas=true" ) !== false ) {
239
-					if ( $this->settings['type'] == 'JS' ) {
240
-						if ( $this->settings['js-pseudo'] ) {
241
-							$url .= "' data-search-pseudo-elements defer='defer";
242
-						} else {
243
-							$url .= "' defer='defer";
244
-						}
245
-					}
246
-				} else {
247
-					$url = ''; // removing the url removes the file
248
-				}
249
-
250
-			}
251
-
252
-			return $url;
253
-		}
254
-
255
-		/**
256
-		 * Register the database settings with WordPress.
257
-		 */
258
-		public function register_settings() {
259
-			register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
260
-		}
261
-
262
-		/**
263
-		 * Add the WordPress settings menu item.
264
-		 * @since 1.0.10 Calling function name direct will fail theme check so we don't.
265
-		 */
266
-		public function menu_item() {
267
-			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
268
-			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
269
-				$this,
270
-				'settings_page'
271
-			) );
272
-		}
273
-
274
-		/**
275
-		 * Get the current Font Awesome output settings.
276
-		 *
277
-		 * @return array The array of settings.
278
-		 */
279
-		public function get_settings() {
280
-
281
-			$db_settings = get_option( 'wp-font-awesome-settings' );
282
-
283
-			$defaults = array(
284
-				'type'      => 'CSS', // type to use, CSS or JS or KIT
285
-				'version'   => '', // latest
286
-				'enqueue'   => '', // front and backend
287
-				'shims'     => '0', // default OFF now in 2020
288
-				'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
289
-				'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
290
-				'pro'       => '0', // if pro CDN url should be used
291
-				'kit-url'   => '', // the kit url
292
-			);
293
-
294
-			$settings = wp_parse_args( $db_settings, $defaults );
295
-
296
-			/**
297
-			 * Filter the Font Awesome settings.
298
-			 *
299
-			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
300
-			 */
301
-			return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
302
-		}
303
-
304
-
305
-		/**
306
-		 * The settings page html output.
307
-		 */
308
-		public function settings_page() {
309
-			if ( ! current_user_can( 'manage_options' ) ) {
310
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) );
311
-			}
312
-
313
-			// a hidden way to force the update of the version number via api instead of waiting the 48 hours
314
-			if ( isset( $_REQUEST['force-version-check'] ) ) {
315
-				$this->get_latest_version( $force_api = true );
316
-			}
317
-			?>
24
+    /**
25
+     * A Class to be able to change settings for Font Awesome.
26
+     *
27
+     * Class WP_Font_Awesome_Settings
28
+     * @since 1.0.10 Now able to pass wp.org theme check.
29
+     * @since 1.0.11 Font Awesome Pro now supported.
30
+     * @since 1.0.11 Font Awesome Kits now supported.
31
+     * @since 1.0.13 RTL language support added.
32
+     * @ver 1.0.13
33
+     * @todo decide how to implement textdomain
34
+     */
35
+    class WP_Font_Awesome_Settings {
36
+
37
+        /**
38
+         * Class version version.
39
+         *
40
+         * @var string
41
+         */
42
+        public $version = '1.0.13';
43
+
44
+        /**
45
+         * Class textdomain.
46
+         *
47
+         * @var string
48
+         */
49
+        public $textdomain = 'font-awesome-settings';
50
+
51
+        /**
52
+         * Latest version of Font Awesome at time of publish published.
53
+         *
54
+         * @var string
55
+         */
56
+        public $latest = "5.8.2";
57
+
58
+        /**
59
+         * The title.
60
+         *
61
+         * @var string
62
+         */
63
+        public $name = 'Font Awesome';
64
+
65
+        /**
66
+         * Holds the settings values.
67
+         *
68
+         * @var array
69
+         */
70
+        private $settings;
71
+
72
+        /**
73
+         * WP_Font_Awesome_Settings instance.
74
+         *
75
+         * @access private
76
+         * @since  1.0.0
77
+         * @var    WP_Font_Awesome_Settings There can be only one!
78
+         */
79
+        private static $instance = null;
80
+
81
+        /**
82
+         * Main WP_Font_Awesome_Settings Instance.
83
+         *
84
+         * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
85
+         *
86
+         * @since 1.0.0
87
+         * @static
88
+         * @return WP_Font_Awesome_Settings - Main instance.
89
+         */
90
+        public static function instance() {
91
+            if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
92
+                self::$instance = new WP_Font_Awesome_Settings;
93
+
94
+                add_action( 'init', array( self::$instance, 'init' ) ); // set settings
95
+
96
+                if ( is_admin() ) {
97
+                    add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
98
+                    add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
99
+                }
100
+
101
+                do_action( 'wp_font_awesome_settings_loaded' );
102
+            }
103
+
104
+            return self::$instance;
105
+        }
106
+
107
+        /**
108
+         * Initiate the settings and add the required action hooks.
109
+         *
110
+         * @since 1.0.8 Settings name wrong - FIXED
111
+         */
112
+        public function init() {
113
+            $this->settings = $this->get_settings();
114
+
115
+            if ( $this->settings['type'] == 'CSS' ) {
116
+
117
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
118
+                    add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
119
+                }
120
+
121
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
122
+                    add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
123
+                }
124
+
125
+            } else {
126
+
127
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
128
+                    add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
129
+                }
130
+
131
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
132
+                    add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
133
+                }
134
+            }
135
+
136
+            // remove font awesome if set to do so
137
+            if ( $this->settings['dequeue'] == '1' ) {
138
+                add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
139
+            }
140
+
141
+        }
142
+
143
+        /**
144
+         * Adds the Font Awesome styles.
145
+         */
146
+        public function enqueue_style() {
147
+            // build url
148
+            $url = $this->get_url();
149
+
150
+            wp_deregister_style( 'font-awesome' ); // deregister in case its already there
151
+            wp_register_style( 'font-awesome', $url, array(), null );
152
+            wp_enqueue_style( 'font-awesome' );
153
+
154
+            // RTL language support CSS.
155
+            if ( is_rtl() ) {
156
+                wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() );
157
+            }
158
+
159
+            if ( $this->settings['shims'] ) {
160
+                $url = $this->get_url( true );
161
+                wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
162
+                wp_register_style( 'font-awesome-shims', $url, array(), null );
163
+                wp_enqueue_style( 'font-awesome-shims' );
164
+            }
165
+        }
166
+
167
+        /**
168
+         * Adds the Font Awesome JS.
169
+         */
170
+        public function enqueue_scripts() {
171
+            // build url
172
+            $url = $this->get_url();
173
+
174
+            $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
175
+            call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
176
+            wp_register_script( 'font-awesome', $url, array(), null );
177
+            wp_enqueue_script( 'font-awesome' );
178
+
179
+            if ( $this->settings['shims'] ) {
180
+                $url = $this->get_url( true );
181
+                call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
182
+                wp_register_script( 'font-awesome-shims', $url, array(), null );
183
+                wp_enqueue_script( 'font-awesome-shims' );
184
+            }
185
+        }
186
+
187
+        /**
188
+         * Get the url of the Font Awesome files.
189
+         *
190
+         * @param bool $shims If this is a shim file or not.
191
+         *
192
+         * @return string The url to the file.
193
+         */
194
+        public function get_url( $shims = false ) {
195
+            $script  = $shims ? 'v4-shims' : 'all';
196
+            $sub     = $this->settings['pro'] ? 'pro' : 'use';
197
+            $type    = $this->settings['type'];
198
+            $version = $this->settings['version'];
199
+            $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : '';
200
+            $url     = '';
201
+
202
+            if ( $type == 'KIT' && $kit_url ) {
203
+                if ( $shims ) {
204
+                    // if its a kit then we don't add shims here
205
+                    return '';
206
+                }
207
+                $url .= $kit_url; // CDN
208
+                $url .= "?wpfas=true"; // set our var so our version is not removed
209
+            } else {
210
+                $url .= "https://$sub.fontawesome.com/releases/"; // CDN
211
+                $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
212
+                $url .= $type == 'CSS' ? 'css/' : 'js/'; // type
213
+                $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
214
+                $url .= "?wpfas=true"; // set our var so our version is not removed
215
+            }
216
+
217
+            return $url;
218
+        }
219
+
220
+        /**
221
+         * Try and remove any other versions of Font Awesome added by other plugins/themes.
222
+         *
223
+         * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version.
224
+         *
225
+         * @param $url
226
+         * @param $original_url
227
+         * @param $_context
228
+         *
229
+         * @return string The filtered url.
230
+         */
231
+        public function remove_font_awesome( $url, $original_url, $_context ) {
232
+
233
+            if ( $_context == 'display'
234
+                 && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
235
+                 && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
236
+            ) {// it's a font-awesome-url (probably)
237
+
238
+                if ( strstr( $url, "wpfas=true" ) !== false ) {
239
+                    if ( $this->settings['type'] == 'JS' ) {
240
+                        if ( $this->settings['js-pseudo'] ) {
241
+                            $url .= "' data-search-pseudo-elements defer='defer";
242
+                        } else {
243
+                            $url .= "' defer='defer";
244
+                        }
245
+                    }
246
+                } else {
247
+                    $url = ''; // removing the url removes the file
248
+                }
249
+
250
+            }
251
+
252
+            return $url;
253
+        }
254
+
255
+        /**
256
+         * Register the database settings with WordPress.
257
+         */
258
+        public function register_settings() {
259
+            register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
260
+        }
261
+
262
+        /**
263
+         * Add the WordPress settings menu item.
264
+         * @since 1.0.10 Calling function name direct will fail theme check so we don't.
265
+         */
266
+        public function menu_item() {
267
+            $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
268
+            call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
269
+                $this,
270
+                'settings_page'
271
+            ) );
272
+        }
273
+
274
+        /**
275
+         * Get the current Font Awesome output settings.
276
+         *
277
+         * @return array The array of settings.
278
+         */
279
+        public function get_settings() {
280
+
281
+            $db_settings = get_option( 'wp-font-awesome-settings' );
282
+
283
+            $defaults = array(
284
+                'type'      => 'CSS', // type to use, CSS or JS or KIT
285
+                'version'   => '', // latest
286
+                'enqueue'   => '', // front and backend
287
+                'shims'     => '0', // default OFF now in 2020
288
+                'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
289
+                'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
290
+                'pro'       => '0', // if pro CDN url should be used
291
+                'kit-url'   => '', // the kit url
292
+            );
293
+
294
+            $settings = wp_parse_args( $db_settings, $defaults );
295
+
296
+            /**
297
+             * Filter the Font Awesome settings.
298
+             *
299
+             * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
300
+             */
301
+            return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
302
+        }
303
+
304
+
305
+        /**
306
+         * The settings page html output.
307
+         */
308
+        public function settings_page() {
309
+            if ( ! current_user_can( 'manage_options' ) ) {
310
+                wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) );
311
+            }
312
+
313
+            // a hidden way to force the update of the version number via api instead of waiting the 48 hours
314
+            if ( isset( $_REQUEST['force-version-check'] ) ) {
315
+                $this->get_latest_version( $force_api = true );
316
+            }
317
+            ?>
318 318
 			<style>
319 319
 				.wpfas-kit-show {
320 320
 					display: none;
@@ -332,10 +332,10 @@  discard block
 block discarded – undo
332 332
 				<h1><?php echo $this->name; ?></h1>
333 333
 				<form method="post" action="options.php">
334 334
 					<?php
335
-					settings_fields( 'wp-font-awesome-settings' );
336
-					do_settings_sections( 'wp-font-awesome-settings' );
337
-					$kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : '';
338
-					?>
335
+                    settings_fields( 'wp-font-awesome-settings' );
336
+                    do_settings_sections( 'wp-font-awesome-settings' );
337
+                    $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : '';
338
+                    ?>
339 339
 					<table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>">
340 340
 						<tr valign="top">
341 341
 							<th scope="row"><label
@@ -361,12 +361,12 @@  discard block
 block discarded – undo
361 361
 								       value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>"
362 362
 								       placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/>
363 363
 								<span><?php
364
-									echo sprintf(
365
-										__( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ),
366
-										'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>',
367
-										'</a>'
368
-									);
369
-									?></span>
364
+                                    echo sprintf(
365
+                                        __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ),
366
+                                        '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>',
367
+                                        '</a>'
368
+                                    );
369
+                                    ?></span>
370 370
 							</td>
371 371
 						</tr>
372 372
 
@@ -426,14 +426,14 @@  discard block
 block discarded – undo
426 426
 								<input type="checkbox" name="wp-font-awesome-settings[pro]"
427 427
 								       value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/>
428 428
 								<span><?php
429
-									echo sprintf(
430
-										__( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ),
431
-										'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>',
432
-										'</a>',
433
-										'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>',
434
-										'</a>'
435
-									);
436
-									?></span>
429
+                                    echo sprintf(
430
+                                        __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ),
431
+                                        '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>',
432
+                                        '</a>',
433
+                                        '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>',
434
+                                        '</a>'
435
+                                    );
436
+                                    ?></span>
437 437
 							</td>
438 438
 						</tr>
439 439
 
@@ -476,100 +476,100 @@  discard block
 block discarded – undo
476 476
 
477 477
 					</table>
478 478
 					<?php
479
-					submit_button();
480
-					?>
479
+                    submit_button();
480
+                    ?>
481 481
 				</form>
482 482
 
483 483
 				<div id="wpfas-version"><?php echo $this->version; ?></div>
484 484
 			</div>
485 485
 
486 486
 			<?php
487
-		}
488
-
489
-		/**
490
-		 * Check a version number is valid and if so return it or else return an empty string.
491
-		 *
492
-		 * @param $version string The version number to check.
493
-		 *
494
-		 * @since 1.0.6
495
-		 *
496
-		 * @return string Either a valid version number or an empty string.
497
-		 */
498
-		public function validate_version_number( $version ) {
499
-
500
-			if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
501
-				// valid
502
-			} else {
503
-				$version = '';// not validated
504
-			}
505
-
506
-			return $version;
507
-		}
508
-
509
-
510
-		/**
511
-		 * Get the latest version of Font Awesome.
512
-		 *
513
-		 * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours.
514
-		 *
515
-		 * @since 1.0.7
516
-		 * @return mixed|string The latest version number found.
517
-		 */
518
-		public function get_latest_version( $force_api = false ) {
519
-			$latest_version = $this->latest;
520
-
521
-			$cache = get_transient( 'wp-font-awesome-settings-version' );
522
-
523
-			if ( $cache === false || $force_api ) { // its not set
524
-				$api_ver = $this->get_latest_version_from_api();
525
-				if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
526
-					$latest_version = $api_ver;
527
-					set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
528
-				}
529
-			} elseif ( $this->validate_version_number( $cache ) ) {
530
-				if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
531
-					$latest_version = $cache;
532
-				}
533
-			}
534
-
535
-			return $latest_version;
536
-		}
537
-
538
-		/**
539
-		 * Get the latest Font Awesome version from the github API.
540
-		 *
541
-		 * @since 1.0.7
542
-		 * @return string The latest version number or `0` on API fail.
543
-		 */
544
-		public function get_latest_version_from_api() {
545
-			$version  = "0";
546
-			$response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
547
-			if ( ! is_wp_error( $response ) && is_array( $response ) ) {
548
-				$api_response = json_decode( wp_remote_retrieve_body( $response ), true );
549
-				if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
550
-					$version = $api_response['tag_name'];
551
-				}
552
-			}
553
-
554
-			return $version;
555
-		}
556
-
557
-		/**
558
-		 * Inline CSS for RTL language support.
559
-		 *
560
-		 * @since 1.0.13
561
-		 * @return string Inline CSS.
562
-		 */
563
-		public function rtl_inline_css() {
564
-			$inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}';
565
-
566
-			return $inline_css;
567
-		}
568
-
569
-	}
570
-
571
-	/**
572
-	 * Run the class if found.
573
-	 */
574
-	WP_Font_Awesome_Settings::instance();
487
+        }
488
+
489
+        /**
490
+         * Check a version number is valid and if so return it or else return an empty string.
491
+         *
492
+         * @param $version string The version number to check.
493
+         *
494
+         * @since 1.0.6
495
+         *
496
+         * @return string Either a valid version number or an empty string.
497
+         */
498
+        public function validate_version_number( $version ) {
499
+
500
+            if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
501
+                // valid
502
+            } else {
503
+                $version = '';// not validated
504
+            }
505
+
506
+            return $version;
507
+        }
508
+
509
+
510
+        /**
511
+         * Get the latest version of Font Awesome.
512
+         *
513
+         * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours.
514
+         *
515
+         * @since 1.0.7
516
+         * @return mixed|string The latest version number found.
517
+         */
518
+        public function get_latest_version( $force_api = false ) {
519
+            $latest_version = $this->latest;
520
+
521
+            $cache = get_transient( 'wp-font-awesome-settings-version' );
522
+
523
+            if ( $cache === false || $force_api ) { // its not set
524
+                $api_ver = $this->get_latest_version_from_api();
525
+                if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
526
+                    $latest_version = $api_ver;
527
+                    set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
528
+                }
529
+            } elseif ( $this->validate_version_number( $cache ) ) {
530
+                if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
531
+                    $latest_version = $cache;
532
+                }
533
+            }
534
+
535
+            return $latest_version;
536
+        }
537
+
538
+        /**
539
+         * Get the latest Font Awesome version from the github API.
540
+         *
541
+         * @since 1.0.7
542
+         * @return string The latest version number or `0` on API fail.
543
+         */
544
+        public function get_latest_version_from_api() {
545
+            $version  = "0";
546
+            $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
547
+            if ( ! is_wp_error( $response ) && is_array( $response ) ) {
548
+                $api_response = json_decode( wp_remote_retrieve_body( $response ), true );
549
+                if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
550
+                    $version = $api_response['tag_name'];
551
+                }
552
+            }
553
+
554
+            return $version;
555
+        }
556
+
557
+        /**
558
+         * Inline CSS for RTL language support.
559
+         *
560
+         * @since 1.0.13
561
+         * @return string Inline CSS.
562
+         */
563
+        public function rtl_inline_css() {
564
+            $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}';
565
+
566
+            return $inline_css;
567
+        }
568
+
569
+    }
570
+
571
+    /**
572
+     * Run the class if found.
573
+     */
574
+    WP_Font_Awesome_Settings::instance();
575 575
 }
576 576
\ No newline at end of file
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-taxes.php 1 patch
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -12,228 +12,228 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Taxes {
14 14
 
15
-	/**
16
-	 * Submission taxes.
17
-	 * @var array
18
-	 */
19
-	public $taxes = array();
20
-
21
-	/**
22
-	 * Whether or not we should skip the taxes.
23
-	 * @var bool
24
-	 */
25
-	protected $skip_taxes = false;
15
+    /**
16
+     * Submission taxes.
17
+     * @var array
18
+     */
19
+    public $taxes = array();
20
+
21
+    /**
22
+     * Whether or not we should skip the taxes.
23
+     * @var bool
24
+     */
25
+    protected $skip_taxes = false;
26 26
 
27 27
     /**
28
-	 * Class constructor
29
-	 *
30
-	 * @param GetPaid_Payment_Form_Submission $submission
31
-	 */
32
-	public function __construct( $submission ) {
33
-
34
-		// Validate VAT number.
35
-		$this->validate_vat( $submission );
36
-
37
-		if ( $this->skip_taxes ) {
38
-			return;
39
-		}
40
-
41
-		foreach ( $submission->get_items() as $item ) {
42
-			$this->process_item_tax( $item, $submission );
43
-		}
44
-
45
-		// Process any existing invoice taxes.
46
-		if ( $submission->has_invoice() ) {
47
-			$this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
48
-		}
49
-
50
-	}
51
-
52
-	/**
53
-	 * Maybe process tax.
54
-	 *
55
-	 * @since 1.0.19
56
-	 * @param GetPaid_Form_Item $item
57
-	 * @param GetPaid_Payment_Form_Submission $submission
58
-	 */
59
-	public function process_item_tax( $item, $submission ) {
60
-
61
-		$rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
-		$rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
-		$taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
64
-		$r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
65
-
66
-		foreach ( $taxes as $name => $amount ) {
67
-			$recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
-			$tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
69
-
70
-			$item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
71
-
72
-			if ( ! isset( $this->taxes[ $name ] ) ) {
73
-				$this->taxes[ $name ] = $tax;
74
-				continue;
75
-			}
76
-
77
-			$this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
78
-			$this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
79
-
80
-		}
81
-
82
-	}
83
-
84
-	/**
85
-	 * Checks if the submission has a digital item.
86
-	 *
87
-	 * @param GetPaid_Payment_Form_Submission $submission
88
-	 * @since 1.0.19
89
-	 * @return bool
90
-	 */
91
-	public function has_digital_item( $submission ) {
92
-
93
-		foreach ( $submission->get_items() as $item ) {
94
-
95
-			if ( 'digital' == $item->get_vat_rule() ) {
96
-				return true;
97
-			}
98
-
99
-		}
100
-
101
-		return false;
102
-	}
103
-
104
-	/**
105
-	 * Checks if this is an eu store.
106
-	 *
107
-	 * @since 1.0.19
108
-	 * @return bool
109
-	 */
110
-	public static function is_eu_store() {
111
-		return self::is_eu_country( wpinv_get_default_country() );
112
-	}
113
-
114
-	/**
115
-	 * Checks if this is an eu country.
116
-	 *
117
-	 * @param string $country
118
-	 * @since 1.0.19
119
-	 * @return bool
120
-	 */
121
-	public static function is_eu_country( $country ) {
122
-		return getpaid_is_eu_state( $country );
123
-	}
124
-
125
-	/**
126
-	 * Checks if this is an eu purchase.
127
-	 *
128
-	 * @param string $customer_country
129
-	 * @since 1.0.19
130
-	 * @return bool
131
-	 */
132
-	public static function is_eu_transaction( $customer_country ) {
133
-		return self::is_eu_country( $customer_country ) && self::is_eu_store();
134
-	}
135
-
136
-	/**
137
-	 * Retrieves the vat number.
138
-	 *
139
-	 * @param GetPaid_Payment_Form_Submission $submission
140
-	 * @since 1.0.19
141
-	 * @return string
142
-	 */
143
-	public function get_vat_number( $submission ) {
144
-
145
-		// Retrieve from the posted number.
146
-		$vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
-		if ( ! is_null( $vat_number ) ) {
148
-			return wpinv_clean( $vat_number );
149
-		}
150
-
151
-		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
152
-	}
153
-
154
-	/**
155
-	 * Retrieves the company.
156
-	 *
157
-	 * @param GetPaid_Payment_Form_Submission $submission
158
-	 * @since 1.0.19
159
-	 * @return string
160
-	 */
161
-	public function get_company( $submission ) {
162
-
163
-		// Retrieve from the posted data.
164
-		$company = $submission->get_field( 'wpinv_company', 'billing' );
165
-		if ( ! empty( $company ) ) {
166
-			return wpinv_clean( $company );
167
-		}
168
-
169
-		// Retrieve from the invoice.
170
-		return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
171
-	}
172
-
173
-	/**
174
-	 * Checks if we require a VAT number.
175
-	 *
176
-	 * @param bool $ip_in_eu Whether the customer IP is from the EU
177
-	 * @param bool $country_in_eu Whether the customer country is from the EU
178
-	 * @since 1.0.19
179
-	 * @return string
180
-	 */
181
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
182
-
183
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
-		$prevent_b2c = ! empty( $prevent_b2c );
185
-		$is_eu       = $ip_in_eu || $country_in_eu;
186
-
187
-		return $prevent_b2c && $is_eu;
188
-	}
189
-
190
-	/**
191
-	 * Validate VAT data.
192
-	 *
193
-	 * @param GetPaid_Payment_Form_Submission $submission
194
-	 * @since 1.0.19
195
-	 */
196
-	public function validate_vat( $submission ) {
197
-
198
-		$in_eu = $this->is_eu_transaction( $submission->country );
199
-
200
-		// Abort if we are not validating vat numbers.
201
-		if ( ! $in_eu ) {
28
+     * Class constructor
29
+     *
30
+     * @param GetPaid_Payment_Form_Submission $submission
31
+     */
32
+    public function __construct( $submission ) {
33
+
34
+        // Validate VAT number.
35
+        $this->validate_vat( $submission );
36
+
37
+        if ( $this->skip_taxes ) {
202 38
             return;
203
-		}
39
+        }
40
+
41
+        foreach ( $submission->get_items() as $item ) {
42
+            $this->process_item_tax( $item, $submission );
43
+        }
44
+
45
+        // Process any existing invoice taxes.
46
+        if ( $submission->has_invoice() ) {
47
+            $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
48
+        }
49
+
50
+    }
51
+
52
+    /**
53
+     * Maybe process tax.
54
+     *
55
+     * @since 1.0.19
56
+     * @param GetPaid_Form_Item $item
57
+     * @param GetPaid_Payment_Form_Submission $submission
58
+     */
59
+    public function process_item_tax( $item, $submission ) {
60
+
61
+        $rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
+        $rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
+        $taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
64
+        $r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
65
+
66
+        foreach ( $taxes as $name => $amount ) {
67
+            $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
+            $tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
69
+
70
+            $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
71
+
72
+            if ( ! isset( $this->taxes[ $name ] ) ) {
73
+                $this->taxes[ $name ] = $tax;
74
+                continue;
75
+            }
76
+
77
+            $this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
78
+            $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
79
+
80
+        }
81
+
82
+    }
83
+
84
+    /**
85
+     * Checks if the submission has a digital item.
86
+     *
87
+     * @param GetPaid_Payment_Form_Submission $submission
88
+     * @since 1.0.19
89
+     * @return bool
90
+     */
91
+    public function has_digital_item( $submission ) {
92
+
93
+        foreach ( $submission->get_items() as $item ) {
94
+
95
+            if ( 'digital' == $item->get_vat_rule() ) {
96
+                return true;
97
+            }
98
+
99
+        }
204 100
 
205
-		// Prepare variables.
206
-		$vat_number  = $this->get_vat_number( $submission );
207
-		$ip_country  = getpaid_get_ip_country();
101
+        return false;
102
+    }
103
+
104
+    /**
105
+     * Checks if this is an eu store.
106
+     *
107
+     * @since 1.0.19
108
+     * @return bool
109
+     */
110
+    public static function is_eu_store() {
111
+        return self::is_eu_country( wpinv_get_default_country() );
112
+    }
113
+
114
+    /**
115
+     * Checks if this is an eu country.
116
+     *
117
+     * @param string $country
118
+     * @since 1.0.19
119
+     * @return bool
120
+     */
121
+    public static function is_eu_country( $country ) {
122
+        return getpaid_is_eu_state( $country );
123
+    }
124
+
125
+    /**
126
+     * Checks if this is an eu purchase.
127
+     *
128
+     * @param string $customer_country
129
+     * @since 1.0.19
130
+     * @return bool
131
+     */
132
+    public static function is_eu_transaction( $customer_country ) {
133
+        return self::is_eu_country( $customer_country ) && self::is_eu_store();
134
+    }
135
+
136
+    /**
137
+     * Retrieves the vat number.
138
+     *
139
+     * @param GetPaid_Payment_Form_Submission $submission
140
+     * @since 1.0.19
141
+     * @return string
142
+     */
143
+    public function get_vat_number( $submission ) {
144
+
145
+        // Retrieve from the posted number.
146
+        $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
+        if ( ! is_null( $vat_number ) ) {
148
+            return wpinv_clean( $vat_number );
149
+        }
150
+
151
+        return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
152
+    }
153
+
154
+    /**
155
+     * Retrieves the company.
156
+     *
157
+     * @param GetPaid_Payment_Form_Submission $submission
158
+     * @since 1.0.19
159
+     * @return string
160
+     */
161
+    public function get_company( $submission ) {
162
+
163
+        // Retrieve from the posted data.
164
+        $company = $submission->get_field( 'wpinv_company', 'billing' );
165
+        if ( ! empty( $company ) ) {
166
+            return wpinv_clean( $company );
167
+        }
168
+
169
+        // Retrieve from the invoice.
170
+        return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
171
+    }
172
+
173
+    /**
174
+     * Checks if we require a VAT number.
175
+     *
176
+     * @param bool $ip_in_eu Whether the customer IP is from the EU
177
+     * @param bool $country_in_eu Whether the customer country is from the EU
178
+     * @since 1.0.19
179
+     * @return string
180
+     */
181
+    public function requires_vat( $ip_in_eu, $country_in_eu ) {
182
+
183
+        $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
+        $prevent_b2c = ! empty( $prevent_b2c );
185
+        $is_eu       = $ip_in_eu || $country_in_eu;
186
+
187
+        return $prevent_b2c && $is_eu;
188
+    }
189
+
190
+    /**
191
+     * Validate VAT data.
192
+     *
193
+     * @param GetPaid_Payment_Form_Submission $submission
194
+     * @since 1.0.19
195
+     */
196
+    public function validate_vat( $submission ) {
197
+
198
+        $in_eu = $this->is_eu_transaction( $submission->country );
199
+
200
+        // Abort if we are not validating vat numbers.
201
+        if ( ! $in_eu ) {
202
+            return;
203
+        }
204
+
205
+        // Prepare variables.
206
+        $vat_number  = $this->get_vat_number( $submission );
207
+        $ip_country  = getpaid_get_ip_country();
208 208
         $is_eu       = $this->is_eu_country( $submission->country );
209 209
         $is_ip_eu    = $this->is_eu_country( $ip_country );
210 210
 
211
-		// Maybe abort early for initial fetches.
212
-		if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
213
-			return;
214
-		}
211
+        // Maybe abort early for initial fetches.
212
+        if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
213
+            return;
214
+        }
215 215
 
216
-		// If we're preventing business to consumer purchases,
217
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
216
+        // If we're preventing business to consumer purchases,
217
+        if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
218 218
 
219
-			// Ensure that a vat number has been specified.
220
-			throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) );
219
+            // Ensure that a vat number has been specified.
220
+            throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) );
221 221
 
222
-		}
222
+        }
223 223
 
224
-		if ( empty( $vat_number ) ) {
225
-			return;
226
-		}
224
+        if ( empty( $vat_number ) ) {
225
+            return;
226
+        }
227 227
 
228
-		if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
229
-			throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) );
230
-		}
228
+        if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
229
+            throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) );
230
+        }
231 231
 
232
-		if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
233
-			return;
234
-		}
232
+        if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
233
+            return;
234
+        }
235 235
 
236
-		$this->skip_taxes = true;
237
-	}
236
+        $this->skip_taxes = true;
237
+    }
238 238
 
239 239
 }
Please login to merge, or discard this patch.
vendor/ayecode/wp-super-duper/sd-functions.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -11,18 +11,18 @@  discard block
 block discarded – undo
11 11
  * @return mixed|void
12 12
  */
13 13
 function sd_pagenow_exclude(){
14
-	return apply_filters( 'sd_pagenow_exclude', array(
15
-		'upload.php',
16
-		'edit-comments.php',
17
-		'edit-tags.php',
18
-		'index.php',
19
-		'media-new.php',
20
-		'options-discussion.php',
21
-		'options-writing.php',
22
-		'edit.php',
23
-		'themes.php',
24
-		'users.php',
25
-	) );
14
+    return apply_filters( 'sd_pagenow_exclude', array(
15
+        'upload.php',
16
+        'edit-comments.php',
17
+        'edit-tags.php',
18
+        'index.php',
19
+        'media-new.php',
20
+        'options-discussion.php',
21
+        'options-writing.php',
22
+        'edit.php',
23
+        'themes.php',
24
+        'users.php',
25
+    ) );
26 26
 }
27 27
 
28 28
 
@@ -34,5 +34,5 @@  discard block
 block discarded – undo
34 34
  * @return mixed|void
35 35
  */
36 36
 function sd_widget_exclude(){
37
-	return apply_filters( 'sd_widget_exclude', array() );
37
+    return apply_filters( 'sd_widget_exclude', array() );
38 38
 }
39 39
\ No newline at end of file
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-items.php 1 patch
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -12,38 +12,38 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Items {
14 14
 
15
-	/**
16
-	 * Submission items.
17
-	 * @var GetPaid_Form_Item[]
18
-	 */
19
-	public $items = array();
15
+    /**
16
+     * Submission items.
17
+     * @var GetPaid_Form_Item[]
18
+     */
19
+    public $items = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$data         = $submission->get_data();
29
-		$payment_form = $submission->get_payment_form();
30
-
31
-		// Prepare the selected items.
32
-		$selected_items = array();
33
-		if ( ! empty( $data['getpaid-items'] ) ) {
34
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
35
-		}
36
-
37
-		// (Maybe) set form items.
38
-		if ( isset( $data['getpaid-form-items'] ) ) {
39
-
40
-			// Confirm items key.
41
-			$form_items = wpinv_clean( $data['getpaid-form-items'] );
42
-			if ( ! isset( $data['getpaid-form-items-key'] ) || $data['getpaid-form-items-key'] !== md5( NONCE_KEY . AUTH_KEY . $form_items ) ) {
43
-				throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) );
44
-			}
45
-
46
-			$items    = array();
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $data         = $submission->get_data();
29
+        $payment_form = $submission->get_payment_form();
30
+
31
+        // Prepare the selected items.
32
+        $selected_items = array();
33
+        if ( ! empty( $data['getpaid-items'] ) ) {
34
+            $selected_items = wpinv_clean( $data['getpaid-items'] );
35
+        }
36
+
37
+        // (Maybe) set form items.
38
+        if ( isset( $data['getpaid-form-items'] ) ) {
39
+
40
+            // Confirm items key.
41
+            $form_items = wpinv_clean( $data['getpaid-form-items'] );
42
+            if ( ! isset( $data['getpaid-form-items-key'] ) || $data['getpaid-form-items-key'] !== md5( NONCE_KEY . AUTH_KEY . $form_items ) ) {
43
+                throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) );
44
+            }
45
+
46
+            $items    = array();
47 47
             $item_ids = array();
48 48
 
49 49
             foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) {
@@ -74,58 +74,58 @@  discard block
 block discarded – undo
74 74
 
75 75
             $payment_form->set_items( $items );
76 76
 
77
-		}
78
-
79
-		// Process each individual item.
80
-		foreach ( $payment_form->get_items() as $item ) {
81
-			$this->process_item( $item, $selected_items, $submission );
82
-		}
83
-
84
-	}
77
+        }
85 78
 
86
-	/**
87
-	 * Process a single item.
88
-	 *
89
-	 * @param GetPaid_Form_Item $item
90
-	 * @param array $selected_items
91
-	 * @param GetPaid_Payment_Form_Submission $submission
92
-	 */
93
-	public function process_item( $item, $selected_items, $submission ) {
79
+        // Process each individual item.
80
+        foreach ( $payment_form->get_items() as $item ) {
81
+            $this->process_item( $item, $selected_items, $submission );
82
+        }
94 83
 
95
-		// Abort if this is an optional item and it has not been selected.
96
-		if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
97
-			return;
98
-		}
84
+    }
99 85
 
100
-		// (maybe) let customers change the quantities and prices.
101
-		if ( isset( $selected_items[ $item->get_id() ] ) ) {
102
-
103
-			// Maybe change the quantities.
104
-			if ( $item->allows_quantities() ) {
105
-				$item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
106
-			}
86
+    /**
87
+     * Process a single item.
88
+     *
89
+     * @param GetPaid_Form_Item $item
90
+     * @param array $selected_items
91
+     * @param GetPaid_Payment_Form_Submission $submission
92
+     */
93
+    public function process_item( $item, $selected_items, $submission ) {
94
+
95
+        // Abort if this is an optional item and it has not been selected.
96
+        if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
97
+            return;
98
+        }
99
+
100
+        // (maybe) let customers change the quantities and prices.
101
+        if ( isset( $selected_items[ $item->get_id() ] ) ) {
102
+
103
+            // Maybe change the quantities.
104
+            if ( $item->allows_quantities() ) {
105
+                $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
106
+            }
107 107
 
108
-			// Maybe change the price.
109
-			if ( $item->user_can_set_their_price() ) {
110
-				$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
108
+            // Maybe change the price.
109
+            if ( $item->user_can_set_their_price() ) {
110
+                $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
111 111
 
112
-				if ( $item->get_minimum_price() > $price ) {
113
-					throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) );
114
-				}
112
+                if ( $item->get_minimum_price() > $price ) {
113
+                    throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) );
114
+                }
115 115
 
116
-				$item->set_price( $price );
116
+                $item->set_price( $price );
117 117
 
118
-			}
118
+            }
119 119
 
120
-		}
120
+        }
121 121
 
122
-		if ( 0 == $item->get_quantity() ) {
123
-			return;
124
-		}
122
+        if ( 0 == $item->get_quantity() ) {
123
+            return;
124
+        }
125 125
 
126
-		// Save the item.
127
-		$this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission );
126
+        // Save the item.
127
+        $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission );
128 128
 
129
-	}
129
+    }
130 130
 
131 131
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-worldpay-gateway.php 1 patch
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -13,65 +13,65 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Worldpay_Gateway extends GetPaid_Payment_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'worldpay';
21 21
 
22 22
     /**
23
-	 * Payment method order.
24
-	 *
25
-	 * @var int
26
-	 */
23
+     * Payment method order.
24
+     *
25
+     * @var int
26
+     */
27 27
     public $order = 5;
28 28
 
29 29
     /**
30
-	 * Endpoint for requests from Worldpay.
31
-	 *
32
-	 * @var string
33
-	 */
34
-	protected $notify_url;
35
-
36
-	/**
37
-	 * Endpoint for requests to Worldpay.
38
-	 *
39
-	 * @var string
40
-	 */
30
+     * Endpoint for requests from Worldpay.
31
+     *
32
+     * @var string
33
+     */
34
+    protected $notify_url;
35
+
36
+    /**
37
+     * Endpoint for requests to Worldpay.
38
+     *
39
+     * @var string
40
+     */
41 41
     protected $endpoint;
42 42
 
43 43
     /**
44
-	 * An array of features that this gateway supports.
45
-	 *
46
-	 * @var array
47
-	 */
44
+     * An array of features that this gateway supports.
45
+     *
46
+     * @var array
47
+     */
48 48
     protected $supports = array( 'sandbox' );
49 49
     
50 50
     /**
51
-	 * Currencies this gateway is allowed for.
52
-	 *
53
-	 * @var array
54
-	 */
55
-	public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' );
51
+     * Currencies this gateway is allowed for.
52
+     *
53
+     * @var array
54
+     */
55
+    public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' );
56 56
 
57 57
     /**
58
-	 * URL to view a transaction.
59
-	 *
60
-	 * @var string
61
-	 */
58
+     * URL to view a transaction.
59
+     *
60
+     * @var string
61
+     */
62 62
     public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s';
63 63
 
64 64
     /**
65
-	 * URL to view a subscription.
66
-	 *
67
-	 * @var string
68
-	 */
69
-	public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
65
+     * URL to view a subscription.
66
+     *
67
+     * @var string
68
+     */
69
+    public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
70 70
 
71 71
     /**
72
-	 * Class constructor.
73
-	 */
74
-	public function __construct() {
72
+     * Class constructor.
73
+     */
74
+    public function __construct() {
75 75
 
76 76
         $this->method_title         = __( 'Worldpay', 'invoicing' );
77 77
         $this->title                = __( 'Worldpay - Credit Card / Debit Card', 'invoicing' );
@@ -85,15 +85,15 @@  discard block
 block discarded – undo
85 85
     }
86 86
 
87 87
     /**
88
-	 * Process Payment.
89
-	 *
90
-	 *
91
-	 * @param WPInv_Invoice $invoice Invoice.
92
-	 * @param array $submission_data Posted checkout fields.
93
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
94
-	 * @return array
95
-	 */
96
-	public function process_payment( $invoice, $submission_data, $submission ) {
88
+     * Process Payment.
89
+     *
90
+     *
91
+     * @param WPInv_Invoice $invoice Invoice.
92
+     * @param array $submission_data Posted checkout fields.
93
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
94
+     * @return array
95
+     */
96
+    public function process_payment( $invoice, $submission_data, $submission ) {
97 97
 
98 98
         // Get redirect url.
99 99
         $worldpay_redirect = esc_url( $this->get_request_url( $invoice ) );
@@ -128,31 +128,31 @@  discard block
 block discarded – undo
128 128
     }
129 129
 
130 130
     /**
131
-	 * Get the Worldpay request URL for an invoice.
132
-	 *
133
-	 * @param  WPInv_Invoice $invoice Invoice object.
134
-	 * @return string
135
-	 */
136
-	public function get_request_url( $invoice ) {
131
+     * Get the Worldpay request URL for an invoice.
132
+     *
133
+     * @param  WPInv_Invoice $invoice Invoice object.
134
+     * @return string
135
+     */
136
+    public function get_request_url( $invoice ) {
137 137
 
138 138
         // Endpoint for this request
139
-		$this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
139
+        $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
140 140
 
141 141
         return $this->endpoint;
142 142
 
143
-	}
143
+    }
144 144
 
145 145
     /**
146
-	 * Get Worldpay Args for passing to Worldpay.
147
-	 *
148
-	 * @param  WPInv_Invoice $invoice Invoice object.
149
-	 * @return array
150
-	 */
151
-	protected function get_worldpay_args( $invoice ) {
152
-
153
-		return apply_filters(
154
-			'getpaid_worldpay_args',
155
-			array(
146
+     * Get Worldpay Args for passing to Worldpay.
147
+     *
148
+     * @param  WPInv_Invoice $invoice Invoice object.
149
+     * @return array
150
+     */
151
+    protected function get_worldpay_args( $invoice ) {
152
+
153
+        return apply_filters(
154
+            'getpaid_worldpay_args',
155
+            array(
156 156
                 'amount'         => wpinv_sanitize_amount( $invoice->get_total() ), // mandatory
157 157
                 'cartId'         => wpinv_clean( $invoice->get_number() ), // mandatory reference for the item purchased
158 158
                 'currency'       => wpinv_clean( $invoice->get_currency() ), // mandatory
@@ -177,18 +177,18 @@  discard block
 block discarded – undo
177 177
                 'countryString'  => wpinv_clean( wpinv_country_name( $invoice->get_country() ) ),
178 178
                 'compName'       => wpinv_clean( $invoice->get_company() ),
179 179
             ),
180
-			$invoice
181
-		);
180
+            $invoice
181
+        );
182 182
 
183 183
     }
184 184
 
185 185
     /**
186
-	 * Secures worldpay args with an md5 hash.
187
-	 *
188
-	 * @param  array $args Gateway args.
189
-	 * @return array
190
-	 */
191
-	public function hash_args( $args ) {
186
+     * Secures worldpay args with an md5 hash.
187
+     *
188
+     * @param  array $args Gateway args.
189
+     * @return array
190
+     */
191
+    public function hash_args( $args ) {
192 192
 
193 193
         $md5_secret = $this->get_option( 'md5_secret' );
194 194
 
@@ -204,16 +204,16 @@  discard block
 block discarded – undo
204 204
     }
205 205
 
206 206
     /**
207
-	 * Processes ipns and marks payments as complete.
208
-	 *
209
-	 * @return void
210
-	 */
211
-	public function verify_ipn() {
207
+     * Processes ipns and marks payments as complete.
208
+     *
209
+     * @return void
210
+     */
211
+    public function verify_ipn() {
212 212
 
213 213
         // Validate the IPN.
214 214
         if ( empty( $_POST ) || ! $this->validate_ipn() ) {
215
-		    wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) );
216
-		}
215
+            wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) );
216
+        }
217 217
 
218 218
         // Process the IPN.
219 219
         $posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
@@ -229,8 +229,8 @@  discard block
 block discarded – undo
229 229
                 $invoice->set_transaction_id( wpinv_clean( $posted['transId'] ) );
230 230
             }
231 231
 
232
-             // Update the ip address.
233
-             if ( ! empty( $posted['ipAddress'] ) ) {
232
+                // Update the ip address.
233
+                if ( ! empty( $posted['ipAddress'] ) ) {
234 234
                 $invoice->set_ip( wpinv_clean( $posted['ipAddress'] ) );
235 235
             }
236 236
 
@@ -257,9 +257,9 @@  discard block
 block discarded – undo
257 257
     }
258 258
 
259 259
     /**
260
-	 * Check Worldpay IPN validity.
261
-	 */
262
-	public function validate_ipn() {
260
+     * Check Worldpay IPN validity.
261
+     */
262
+    public function validate_ipn() {
263 263
 
264 264
         wpinv_error_log( 'Validating Worldpay IPN response' );
265 265
 
@@ -305,11 +305,11 @@  discard block
 block discarded – undo
305 305
     }
306 306
 
307 307
     /**
308
-	 * Filters the gateway settings.
309
-	 * 
310
-	 * @param array $admin_settings
311
-	 */
312
-	public function admin_settings( $admin_settings ) {
308
+     * Filters the gateway settings.
309
+     * 
310
+     * @param array $admin_settings
311
+     */
312
+    public function admin_settings( $admin_settings ) {
313 313
 
314 314
         $currencies = sprintf(
315 315
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
             'readonly' => true
351 351
         );
352 352
 
353
-		return $admin_settings;
354
-	}
353
+        return $admin_settings;
354
+    }
355 355
 
356 356
 }
Please login to merge, or discard this patch.
admin/meta-boxes/class-getpaid-meta-box-invoice-shipping-address.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 if ( ! defined( 'ABSPATH' ) ) {
10
-	exit; // Exit if accessed directly
10
+    exit; // Exit if accessed directly
11 11
 }
12 12
 
13 13
 /**
@@ -15,22 +15,22 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Meta_Box_Invoice_Shipping_Address {
17 17
 
18
-	/**
19
-	 * Output the metabox.
20
-	 *
21
-	 * @param WP_Post $post
22
-	 */
23
-	public static function output( $post ) {
18
+    /**
19
+     * Output the metabox.
20
+     *
21
+     * @param WP_Post $post
22
+     */
23
+    public static function output( $post ) {
24 24
 
25
-		// Retrieve shipping address.
26
-		$shipping_address = get_post_meta( $post->ID, 'shipping_address', true );
25
+        // Retrieve shipping address.
26
+        $shipping_address = get_post_meta( $post->ID, 'shipping_address', true );
27 27
 
28
-		// Abort if it is invalid.
29
-		if ( ! is_array( $shipping_address ) ) {
30
-			return;
31
-		}
28
+        // Abort if it is invalid.
29
+        if ( ! is_array( $shipping_address ) ) {
30
+            return;
31
+        }
32 32
 
33
-		?>
33
+        ?>
34 34
 
35 35
 		<div class="bsui">
36 36
 
@@ -55,31 +55,31 @@  discard block
 block discarded – undo
55 55
 
56 56
 		<?php
57 57
 
58
-	}
58
+    }
59 59
 
60
-	/**
61
-	 * Prepares a value.
62
-	 *
63
-	 * @param array $address
64
-	 * @param string $key
65
-	 * @return string
66
-	 */
67
-	public static function prepare_for_display( $address, $key ) {
60
+    /**
61
+     * Prepares a value.
62
+     *
63
+     * @param array $address
64
+     * @param string $key
65
+     * @return string
66
+     */
67
+    public static function prepare_for_display( $address, $key ) {
68 68
 
69
-		// Prepare the value.
70
-		$value = $address[ $key ];
69
+        // Prepare the value.
70
+        $value = $address[ $key ];
71 71
 
72
-		if ( $key == 'country' ) {
73
-			$value = wpinv_country_name( $value );
74
-		}
72
+        if ( $key == 'country' ) {
73
+            $value = wpinv_country_name( $value );
74
+        }
75 75
 
76
-		if ( $key == 'state' ) {
77
-			$country = isset( $address[ 'country' ] ) ? $address[ 'country' ] : wpinv_get_default_country();
78
-			$value = wpinv_state_name( $value, $country );
79
-		}
76
+        if ( $key == 'state' ) {
77
+            $country = isset( $address[ 'country' ] ) ? $address[ 'country' ] : wpinv_get_default_country();
78
+            $value = wpinv_state_name( $value, $country );
79
+        }
80 80
 
81
-		return esc_html( $value );
81
+        return esc_html( $value );
82 82
 
83
-	}
83
+    }
84 84
 
85 85
 }
Please login to merge, or discard this patch.
includes/admin/class-wpinv-customers-table.php 1 patch
Indentation   +364 added lines, -364 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 // Load WP_List_Table if not loaded
11 11
 if ( ! class_exists( 'WP_List_Table' ) ) {
12
-	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
12
+    require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
13 13
 }
14 14
 
15 15
 /**
@@ -21,367 +21,367 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class WPInv_Customers_Table extends WP_List_Table {
23 23
 
24
-	/**
25
-	 * @var int Number of items per page
26
-	 * @since 1.0.19
27
-	 */
28
-	public $per_page = 10;
29
-
30
-	/**
31
-	 * @var int Number of items
32
-	 * @since 1.0.19
33
-	 */
34
-	public $total = 0;
35
-
36
-	/**
37
-	 * Get things started
38
-	 *
39
-	 * @since 1.0.19
40
-	 * @see WP_List_Table::__construct()
41
-	 */
42
-	public function __construct() {
43
-
44
-		// Set parent defaults
45
-		parent::__construct( array(
46
-			'singular' => 'id',
47
-			'plural'   => 'ids',
48
-			'ajax'     => false,
49
-		) );
50
-
51
-	}
52
-
53
-	/**
54
-	 * Gets the name of the primary column.
55
-	 *
56
-	 * @since 1.0.19
57
-	 * @access protected
58
-	 *
59
-	 * @return string Name of the primary column.
60
-	 */
61
-	protected function get_primary_column_name() {
62
-		return 'name';
63
-	}
64
-
65
-	/**
66
-	 * This function renders most of the columns in the list table.
67
-	 *
68
-	 * @since 1.0.19
69
-	 *
70
-	 * @param WP_User $item
71
-	 * @param string $column_name The name of the column
72
-	 *
73
-	 * @return string Column Name
74
-	 */
75
-	public function column_default( $item, $column_name ) {
76
-		$value = esc_html( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) );
77
-		return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item );
78
-	}
79
-
80
-	/**
81
-	 * Displays the country column.
82
-	 *
83
-	 * @since 1.0.19
84
-	 *
85
-	 * @param WP_User $user
86
-	 *
87
-	 * @return string Column Name
88
-	 */
89
-	public function column_country( $user ) {
90
-		$country = wpinv_sanitize_country( $user->_wpinv_country );
91
-		if ( $country ) {
92
-			$country = wpinv_country_name( $country );
93
-		}
94
-		return esc_html( $country );
95
-	}
96
-
97
-	/**
98
-	 * Displays the state column.
99
-	 *
100
-	 * @since 1.0.19
101
-	 *
102
-	 * @param WP_User $user
103
-	 *
104
-	 * @return string Column Name
105
-	 */
106
-	public function column_state( $user ) {
107
-		$country = wpinv_sanitize_country( $user->_wpinv_country );
108
-		$state   = $user->_wpinv_state;
109
-		if ( $state ) {
110
-			$state = wpinv_state_name( $state, $country );
111
-		}
112
-
113
-		return esc_html( $state );
114
-	}
115
-
116
-	/**
117
-	 * Displays the signup column.
118
-	 *
119
-	 * @since 1.0.19
120
-	 *
121
-	 * @param WP_User $user
122
-	 *
123
-	 * @return string Column Name
124
-	 */
125
-	public function column_signup( $user ) {
126
-		return getpaid_format_date_value( $user->user_registered );
127
-	}
128
-
129
-	/**
130
-	 * Displays the total spent column.
131
-	 *
132
-	 * @since 1.0.19
133
-	 *
134
-	 * @param WP_User $user
135
-	 *
136
-	 * @return string Column Name
137
-	 */
138
-	public function column_total( $user ) {
139
-		return wpinv_price( $this->column_total_raw( $user ) );
140
-	}
141
-
142
-	/**
143
-	 * Displays the total spent column.
144
-	 *
145
-	 * @since 1.0.19
146
-	 *
147
-	 * @param WP_User $user
148
-	 *
149
-	 * @return float
150
-	 */
151
-	public function column_total_raw( $user ) {
152
-
153
-		$args = array(
154
-			'data'             => array(
155
-
156
-				'total'        => array(
157
-					'type'     => 'invoice_data',
158
-					'function' => 'SUM',
159
-					'name'     => 'total_sales',
160
-				)
161
-
162
-			),
163
-			'where'            => array(
164
-
165
-				'author'       => array(
166
-					'type'     => 'post_data',
167
-					'value'    => absint( $user->ID ),
168
-					'key'      => 'posts.post_author',
169
-					'operator' => '=',
170
-				),
171
-
172
-			),
173
-			'query_type'     => 'get_var',
174
-			'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ),
175
-		);
176
-
177
-		return wpinv_round_amount( GetPaid_Reports_Helper::get_invoice_report_data( $args ) );
178
-
179
-	}
180
-
181
-	/**
182
-	 * Displays the total spent column.
183
-	 *
184
-	 * @since 1.0.19
185
-	 *
186
-	 * @param WP_User $user
187
-	 *
188
-	 * @return string Column Name
189
-	 */
190
-	public function column_invoices( $user ) {
191
-
192
-		$args = array(
193
-			'data'             => array(
194
-
195
-				'ID'           => array(
196
-					'type'     => 'post_data',
197
-					'function' => 'COUNT',
198
-					'name'     => 'count',
199
-					'distinct' => true,
200
-				),
201
-
202
-			),
203
-			'where'            => array(
204
-
205
-				'author'       => array(
206
-					'type'     => 'post_data',
207
-					'value'    => absint( $user->ID ),
208
-					'key'      => 'posts.post_author',
209
-					'operator' => '=',
210
-				),
211
-
212
-			),
213
-			'query_type'     => 'get_var',
214
-			'invoice_status' => array_keys( wpinv_get_invoice_statuses() ),
215
-		);
216
-
217
-		return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) );
218
-
219
-	}
220
-
221
-	/**
222
-	 * Generates content for a single row of the table
223
-	 * @since 1.0.19
224
-	 *
225
-	 * @param int $item The user id.
226
-	 */
227
-	public function single_row( $item ) {
228
-		$item = get_user_by( 'id', $item );
229
-
230
-		if ( empty( $item ) ) {
231
-			return;
232
-		}
233
-
234
-		echo '<tr>';
235
-		$this->single_row_columns( $item );
236
-		echo '</tr>';
237
-	}
238
-
239
-	/**
240
-	 * Displays the customers name
241
-	 *
242
-	 * @param  WP_User $customer customer.
243
-	 * @return string
244
-	 */
245
-	public function column_name( $customer ) {
246
-
247
-		// Customer view URL.
248
-		$view_url    = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) );
249
-		$row_actions = $this->row_actions(
250
-			array(
251
-				'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>',
252
-			)
253
-		);
254
-
255
-		// Get user's address.
256
-		$address = wpinv_get_user_address( $customer->ID );
257
-
258
-		// Customer email address.
259
-		$email       = sanitize_email( $customer->user_email );
260
-
261
-		// Customer's avatar.
262
-		$avatar = esc_url( get_avatar_url( $email ) );
263
-		$avatar = "<img src='$avatar' height='32' width='32'/>";
264
-
265
-		// Customer's name.
266
-		$name   = esc_html( "{$address['first_name']} {$address['last_name']}" );
267
-
268
-		if ( ! empty( $name ) ) {
269
-			$name = "<div style='overflow: hidden;height: 18px;'>$name</div>";
270
-		}
271
-
272
-		$email = "<div class='row-title'><a href='$view_url'>$email</a></div>";
273
-
274
-		return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>";
275
-
276
-	}
277
-
278
-	/**
279
-	 * Retrieve the table columns
280
-	 *
281
-	 * @since 1.0.19
282
-	 * @return array $columns Array of all the list table columns
283
-	 */
284
-	public function get_columns() {
285
-
286
-		$columns = array(
287
-			'name'     => __( 'Name', 'invoicing' ),
288
-			'country'  => __( 'Country', 'invoicing' ),
289
-			'state'    => __( 'State', 'invoicing' ),
290
-			'city'     => __( 'City', 'invoicing' ),
291
-			'zip'      => __( 'ZIP', 'invoicing' ),
292
-			'address'  => __( 'Address', 'invoicing' ),
293
-			'phone'    => __( 'Phone', 'invoicing' ),
294
-			'company'  => __( 'Company', 'invoicing' ),
295
-			'invoices' => __( 'Invoices', 'invoicing' ),
296
-			'total'    => __( 'Total Spend', 'invoicing' ),
297
-			'signup'   => __( 'Date created', 'invoicing' ),
298
-		);
299
-		return apply_filters( 'wpinv_customers_table_columns', $columns );
300
-
301
-	}
302
-
303
-	/**
304
-	 * Retrieve the current page number
305
-	 *
306
-	 * @since 1.0.19
307
-	 * @return int Current page number
308
-	 */
309
-	public function get_paged() {
310
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
311
-	}
312
-
313
-	/**
314
-	 * Returns bulk actions.
315
-	 *
316
-	 * @since 1.0.19
317
-	 * @return void
318
-	 */
319
-	public function bulk_actions( $which = '' ) {
320
-		return array();
321
-	}
322
-
323
-	/**
324
-	 *  Prepares the display query
325
-	 */
326
-	public function prepare_query() {
327
-		global $wpdb;
328
-
329
-		$post_types = '';
330
-
331
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
332
-			$post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type );
333
-		}
334
-
335
-		$post_types = rtrim( $post_types, ' OR' );
336
-
337
-		// Maybe search.
338
-		if ( ! empty( $_POST['s'] ) ) {
339
-			$users = get_users(
340
-				array(
341
-					'search'         => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*',
342
-					'search_columns' => array( 'user_login', 'user_email', 'display_name' ),
343
-					'fields'         => 'ID',
344
-				)
345
-			);
346
-
347
-			$users      = implode( ', ', $users );
348
-			$post_types = "($post_types) AND ( post_author IN ( $users ) )";
349
-		}
350
-
351
-		// Users with invoices.
352
-    	$customers = $wpdb->get_col(
353
-			$wpdb->prepare(
354
-				"SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d",
355
-				$this->get_paged() * 10 - 10,
356
-				$this->per_page
357
-			)
358
-		);
359
-
360
-		$this->items = $customers;
361
-		$this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" );
362
-
363
-	}
364
-
365
-	/**
366
-	 * Setup the final data for the table
367
-	 *
368
-	 * @since 1.0.19
369
-	 * @return void
370
-	 */
371
-	public function prepare_items() {
372
-		$columns               = $this->get_columns();
373
-		$hidden                = array(); // No hidden columns
374
-		$sortable              = $this->get_sortable_columns();
375
-		$this->_column_headers = array( $columns, $hidden, $sortable );
376
-		$this->prepare_query();
377
-
378
-		$this->set_pagination_args(
379
-			array(
380
-			'total_items' => $this->total,
381
-			'per_page'    => $this->per_page,
382
-			'total_pages' => ceil( $this->total / $this->per_page )
383
-			)
384
-		);
385
-
386
-	}
24
+    /**
25
+     * @var int Number of items per page
26
+     * @since 1.0.19
27
+     */
28
+    public $per_page = 10;
29
+
30
+    /**
31
+     * @var int Number of items
32
+     * @since 1.0.19
33
+     */
34
+    public $total = 0;
35
+
36
+    /**
37
+     * Get things started
38
+     *
39
+     * @since 1.0.19
40
+     * @see WP_List_Table::__construct()
41
+     */
42
+    public function __construct() {
43
+
44
+        // Set parent defaults
45
+        parent::__construct( array(
46
+            'singular' => 'id',
47
+            'plural'   => 'ids',
48
+            'ajax'     => false,
49
+        ) );
50
+
51
+    }
52
+
53
+    /**
54
+     * Gets the name of the primary column.
55
+     *
56
+     * @since 1.0.19
57
+     * @access protected
58
+     *
59
+     * @return string Name of the primary column.
60
+     */
61
+    protected function get_primary_column_name() {
62
+        return 'name';
63
+    }
64
+
65
+    /**
66
+     * This function renders most of the columns in the list table.
67
+     *
68
+     * @since 1.0.19
69
+     *
70
+     * @param WP_User $item
71
+     * @param string $column_name The name of the column
72
+     *
73
+     * @return string Column Name
74
+     */
75
+    public function column_default( $item, $column_name ) {
76
+        $value = esc_html( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) );
77
+        return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item );
78
+    }
79
+
80
+    /**
81
+     * Displays the country column.
82
+     *
83
+     * @since 1.0.19
84
+     *
85
+     * @param WP_User $user
86
+     *
87
+     * @return string Column Name
88
+     */
89
+    public function column_country( $user ) {
90
+        $country = wpinv_sanitize_country( $user->_wpinv_country );
91
+        if ( $country ) {
92
+            $country = wpinv_country_name( $country );
93
+        }
94
+        return esc_html( $country );
95
+    }
96
+
97
+    /**
98
+     * Displays the state column.
99
+     *
100
+     * @since 1.0.19
101
+     *
102
+     * @param WP_User $user
103
+     *
104
+     * @return string Column Name
105
+     */
106
+    public function column_state( $user ) {
107
+        $country = wpinv_sanitize_country( $user->_wpinv_country );
108
+        $state   = $user->_wpinv_state;
109
+        if ( $state ) {
110
+            $state = wpinv_state_name( $state, $country );
111
+        }
112
+
113
+        return esc_html( $state );
114
+    }
115
+
116
+    /**
117
+     * Displays the signup column.
118
+     *
119
+     * @since 1.0.19
120
+     *
121
+     * @param WP_User $user
122
+     *
123
+     * @return string Column Name
124
+     */
125
+    public function column_signup( $user ) {
126
+        return getpaid_format_date_value( $user->user_registered );
127
+    }
128
+
129
+    /**
130
+     * Displays the total spent column.
131
+     *
132
+     * @since 1.0.19
133
+     *
134
+     * @param WP_User $user
135
+     *
136
+     * @return string Column Name
137
+     */
138
+    public function column_total( $user ) {
139
+        return wpinv_price( $this->column_total_raw( $user ) );
140
+    }
141
+
142
+    /**
143
+     * Displays the total spent column.
144
+     *
145
+     * @since 1.0.19
146
+     *
147
+     * @param WP_User $user
148
+     *
149
+     * @return float
150
+     */
151
+    public function column_total_raw( $user ) {
152
+
153
+        $args = array(
154
+            'data'             => array(
155
+
156
+                'total'        => array(
157
+                    'type'     => 'invoice_data',
158
+                    'function' => 'SUM',
159
+                    'name'     => 'total_sales',
160
+                )
161
+
162
+            ),
163
+            'where'            => array(
164
+
165
+                'author'       => array(
166
+                    'type'     => 'post_data',
167
+                    'value'    => absint( $user->ID ),
168
+                    'key'      => 'posts.post_author',
169
+                    'operator' => '=',
170
+                ),
171
+
172
+            ),
173
+            'query_type'     => 'get_var',
174
+            'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ),
175
+        );
176
+
177
+        return wpinv_round_amount( GetPaid_Reports_Helper::get_invoice_report_data( $args ) );
178
+
179
+    }
180
+
181
+    /**
182
+     * Displays the total spent column.
183
+     *
184
+     * @since 1.0.19
185
+     *
186
+     * @param WP_User $user
187
+     *
188
+     * @return string Column Name
189
+     */
190
+    public function column_invoices( $user ) {
191
+
192
+        $args = array(
193
+            'data'             => array(
194
+
195
+                'ID'           => array(
196
+                    'type'     => 'post_data',
197
+                    'function' => 'COUNT',
198
+                    'name'     => 'count',
199
+                    'distinct' => true,
200
+                ),
201
+
202
+            ),
203
+            'where'            => array(
204
+
205
+                'author'       => array(
206
+                    'type'     => 'post_data',
207
+                    'value'    => absint( $user->ID ),
208
+                    'key'      => 'posts.post_author',
209
+                    'operator' => '=',
210
+                ),
211
+
212
+            ),
213
+            'query_type'     => 'get_var',
214
+            'invoice_status' => array_keys( wpinv_get_invoice_statuses() ),
215
+        );
216
+
217
+        return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) );
218
+
219
+    }
220
+
221
+    /**
222
+     * Generates content for a single row of the table
223
+     * @since 1.0.19
224
+     *
225
+     * @param int $item The user id.
226
+     */
227
+    public function single_row( $item ) {
228
+        $item = get_user_by( 'id', $item );
229
+
230
+        if ( empty( $item ) ) {
231
+            return;
232
+        }
233
+
234
+        echo '<tr>';
235
+        $this->single_row_columns( $item );
236
+        echo '</tr>';
237
+    }
238
+
239
+    /**
240
+     * Displays the customers name
241
+     *
242
+     * @param  WP_User $customer customer.
243
+     * @return string
244
+     */
245
+    public function column_name( $customer ) {
246
+
247
+        // Customer view URL.
248
+        $view_url    = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) );
249
+        $row_actions = $this->row_actions(
250
+            array(
251
+                'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>',
252
+            )
253
+        );
254
+
255
+        // Get user's address.
256
+        $address = wpinv_get_user_address( $customer->ID );
257
+
258
+        // Customer email address.
259
+        $email       = sanitize_email( $customer->user_email );
260
+
261
+        // Customer's avatar.
262
+        $avatar = esc_url( get_avatar_url( $email ) );
263
+        $avatar = "<img src='$avatar' height='32' width='32'/>";
264
+
265
+        // Customer's name.
266
+        $name   = esc_html( "{$address['first_name']} {$address['last_name']}" );
267
+
268
+        if ( ! empty( $name ) ) {
269
+            $name = "<div style='overflow: hidden;height: 18px;'>$name</div>";
270
+        }
271
+
272
+        $email = "<div class='row-title'><a href='$view_url'>$email</a></div>";
273
+
274
+        return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>";
275
+
276
+    }
277
+
278
+    /**
279
+     * Retrieve the table columns
280
+     *
281
+     * @since 1.0.19
282
+     * @return array $columns Array of all the list table columns
283
+     */
284
+    public function get_columns() {
285
+
286
+        $columns = array(
287
+            'name'     => __( 'Name', 'invoicing' ),
288
+            'country'  => __( 'Country', 'invoicing' ),
289
+            'state'    => __( 'State', 'invoicing' ),
290
+            'city'     => __( 'City', 'invoicing' ),
291
+            'zip'      => __( 'ZIP', 'invoicing' ),
292
+            'address'  => __( 'Address', 'invoicing' ),
293
+            'phone'    => __( 'Phone', 'invoicing' ),
294
+            'company'  => __( 'Company', 'invoicing' ),
295
+            'invoices' => __( 'Invoices', 'invoicing' ),
296
+            'total'    => __( 'Total Spend', 'invoicing' ),
297
+            'signup'   => __( 'Date created', 'invoicing' ),
298
+        );
299
+        return apply_filters( 'wpinv_customers_table_columns', $columns );
300
+
301
+    }
302
+
303
+    /**
304
+     * Retrieve the current page number
305
+     *
306
+     * @since 1.0.19
307
+     * @return int Current page number
308
+     */
309
+    public function get_paged() {
310
+        return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
311
+    }
312
+
313
+    /**
314
+     * Returns bulk actions.
315
+     *
316
+     * @since 1.0.19
317
+     * @return void
318
+     */
319
+    public function bulk_actions( $which = '' ) {
320
+        return array();
321
+    }
322
+
323
+    /**
324
+     *  Prepares the display query
325
+     */
326
+    public function prepare_query() {
327
+        global $wpdb;
328
+
329
+        $post_types = '';
330
+
331
+        foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
332
+            $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type );
333
+        }
334
+
335
+        $post_types = rtrim( $post_types, ' OR' );
336
+
337
+        // Maybe search.
338
+        if ( ! empty( $_POST['s'] ) ) {
339
+            $users = get_users(
340
+                array(
341
+                    'search'         => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*',
342
+                    'search_columns' => array( 'user_login', 'user_email', 'display_name' ),
343
+                    'fields'         => 'ID',
344
+                )
345
+            );
346
+
347
+            $users      = implode( ', ', $users );
348
+            $post_types = "($post_types) AND ( post_author IN ( $users ) )";
349
+        }
350
+
351
+        // Users with invoices.
352
+        $customers = $wpdb->get_col(
353
+            $wpdb->prepare(
354
+                "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d",
355
+                $this->get_paged() * 10 - 10,
356
+                $this->per_page
357
+            )
358
+        );
359
+
360
+        $this->items = $customers;
361
+        $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" );
362
+
363
+    }
364
+
365
+    /**
366
+     * Setup the final data for the table
367
+     *
368
+     * @since 1.0.19
369
+     * @return void
370
+     */
371
+    public function prepare_items() {
372
+        $columns               = $this->get_columns();
373
+        $hidden                = array(); // No hidden columns
374
+        $sortable              = $this->get_sortable_columns();
375
+        $this->_column_headers = array( $columns, $hidden, $sortable );
376
+        $this->prepare_query();
377
+
378
+        $this->set_pagination_args(
379
+            array(
380
+            'total_items' => $this->total,
381
+            'per_page'    => $this->per_page,
382
+            'total_pages' => ceil( $this->total / $this->per_page )
383
+            )
384
+        );
385
+
386
+    }
387 387
 }
Please login to merge, or discard this patch.
templates/subscriptions/subscription-details.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -46,64 +46,64 @@  discard block
 block discarded – undo
46 46
 				<td style="width: 65%">
47 47
 					<?php
48 48
 
49
-						switch ( $key ) {
49
+                        switch ( $key ) {
50 50
 
51
-							case 'status':
52
-								echo esc_html( $subscription->get_status_label() );
53
-								break;
51
+                            case 'status':
52
+                                echo esc_html( $subscription->get_status_label() );
53
+                                break;
54 54
 
55
-							case 'start_date':
56
-								echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) );
57
-								break;
55
+                            case 'start_date':
56
+                                echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) );
57
+                                break;
58 58
 
59
-							case 'expiry_date':
60
-								echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) );
61
-								break;
59
+                            case 'expiry_date':
60
+                                echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) );
61
+                                break;
62 62
 
63
-							case 'initial_amount':
64
-								echo wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
63
+                            case 'initial_amount':
64
+                                echo wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
65 65
 
66
-								if ( $subscription->has_trial_period() ) {
66
+                                if ( $subscription->has_trial_period() ) {
67 67
 
68
-									echo "<small class='text-muted'>&nbsp;";
69
-									printf(
70
-										_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ),
71
-										esc_html( $subscription->get_trial_period() )
72
-									);
73
-									echo '</small>';
68
+                                    echo "<small class='text-muted'>&nbsp;";
69
+                                    printf(
70
+                                        _x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ),
71
+                                        esc_html( $subscription->get_trial_period() )
72
+                                    );
73
+                                    echo '</small>';
74 74
 
75
-								}
75
+                                }
76 76
 
77
-								break;
77
+                                break;
78 78
 
79
-							case 'recurring_amount':
80
-								$frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
81
-								$amount    = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
82
-								echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" );
83
-								break;
79
+                            case 'recurring_amount':
80
+                                $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
81
+                                $amount    = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
82
+                                echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" );
83
+                                break;
84 84
 
85
-							case 'item':
85
+                            case 'item':
86 86
 
87
-								if ( empty( $subscription_group ) ) {
88
-									echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() );
89
-								} else {
90
-									$markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
91
-									echo implode( ' | ', $markup );
92
-								}
87
+                                if ( empty( $subscription_group ) ) {
88
+                                    echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() );
89
+                                } else {
90
+                                    $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
91
+                                    echo implode( ' | ', $markup );
92
+                                }
93 93
 
94
-								break;
94
+                                break;
95 95
 
96
-							case 'payments':
96
+                            case 'payments':
97 97
 
98
-								$max_activations = (int) $subscription->get_bill_times();
99
-								echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "&infin;" : $max_activations );
98
+                                $max_activations = (int) $subscription->get_bill_times();
99
+                                echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "&infin;" : $max_activations );
100 100
 
101
-								break;
101
+                                break;
102 102
 
103
-						}
104
-						do_action( "getpaid_render_single_subscription_column_$key", $subscription );
103
+                        }
104
+                        do_action( "getpaid_render_single_subscription_column_$key", $subscription );
105 105
 
106
-					?>
106
+                    ?>
107 107
 				</td>
108 108
 
109 109
 			</tr>
@@ -130,17 +130,17 @@  discard block
 block discarded – undo
130 130
 <span class="form-text">
131 131
 
132 132
 	<?php
133
-		if ( $subscription->can_cancel() ) {
134
-			printf(
135
-				'<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a>&nbsp;&nbsp;',
136
-				esc_url( $subscription->get_cancel_url() ),
137
-				esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ),
138
-				__( 'Cancel Subscription', 'invoicing' )
139
-			);
140
-		}
141
-
142
-		do_action( 'getpaid-single-subscription-page-actions', $subscription );
143
-	?>
133
+        if ( $subscription->can_cancel() ) {
134
+            printf(
135
+                '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a>&nbsp;&nbsp;',
136
+                esc_url( $subscription->get_cancel_url() ),
137
+                esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ),
138
+                __( 'Cancel Subscription', 'invoicing' )
139
+            );
140
+        }
141
+
142
+        do_action( 'getpaid-single-subscription-page-actions', $subscription );
143
+    ?>
144 144
 
145 145
 	<a href="<?php echo esc_url( getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); ?>" class="btn btn-secondary btn-sm"><?php _e( 'Go Back', 'invoicing' ); ?></a>
146 146
 </span>
Please login to merge, or discard this patch.