Completed
Push — master ( 238a55...aa706f )
by Gerhard
11:13 queued 10s
created

WC_Admin_Addons::get_in_app_purchase_url_params()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 10
ccs 0
cts 8
cp 0
crap 2
rs 9.9332
c 0
b 0
f 0
1
<?php
2
/**
3
 * Addons Page
4
 *
5
 * @package  WooCommerce/Admin
6
 * @version  2.5.0
7
 */
8
9
if ( ! defined( 'ABSPATH' ) ) {
10
	exit;
11
}
12
13
/**
14
 * WC_Admin_Addons Class.
15
 */
16
class WC_Admin_Addons {
17
18
	/**
19
	 * Get featured for the addons screen
20
	 *
21
	 * @return array of objects
22
	 */
23
	public static function get_featured() {
24
		$featured = get_transient( 'wc_addons_featured' );
25
		if ( false === $featured ) {
26
			$raw_featured = wp_safe_remote_get( 'https://d3t0oesq8995hv.cloudfront.net/add-ons/featured-v2.json', array( 'user-agent' => 'WooCommerce Addons Page' ) );
27
			if ( ! is_wp_error( $raw_featured ) ) {
28
				$featured = json_decode( wp_remote_retrieve_body( $raw_featured ) );
29
				if ( $featured ) {
30
					set_transient( 'wc_addons_featured', $featured, WEEK_IN_SECONDS );
31
				}
32
			}
33
		}
34
35
		if ( is_object( $featured ) ) {
36
			self::output_featured_sections( $featured->sections );
37
			return $featured;
38
		}
39
	}
40
41
	/**
42
	 * Build url parameter string
43
	 *
44
	 * @param  string $category Addon (sub) category.
45
	 * @param  string $term     Search terms.
46
	 * @param  string $country  Store country.
47
	 *
48
	 * @return string url parameter string
49
	 */
50
	public static function build_parameter_string( $category, $term, $country ) {
51
52
		$paramters = array(
53
			'category' => $category,
54
			'term'     => $term,
55
			'country'  => $country,
56
		);
57
58
		return '?' . http_build_query( $paramters );
59
	}
60
61
	/**
62
	 * Call API to get extensions
63
	 *
64
	 * @param  string $category Addon (sub) category.
65
	 * @param  string $term     Search terms.
66
	 * @param  string $country  Store country.
67
	 *
68
	 * @return array of extensions
69
	 */
70
	public static function get_extension_data( $category, $term, $country ) {
71
		$parameters     = self::build_parameter_string( $category, $term, $country );
72
		$raw_extensions = wp_remote_get(
73
			'https://woocommerce.com/wp-json/wccom-extensions/1.0/search' . $parameters
74
		);
75
		if ( ! is_wp_error( $raw_extensions ) ) {
76
			$addons = json_decode( wp_remote_retrieve_body( $raw_extensions ) )->products;
77
		}
78
		return $addons;
79
	}
80
81
	/**
82
	 * Get sections for the addons screen
83
	 *
84
	 * @return array of objects
85
	 */
86
	public static function get_sections() {
87
		$addon_sections = get_transient( 'wc_addons_sections' );
88
		if ( false === ( $addon_sections ) ) {
89
			$raw_sections = wp_safe_remote_get(
90
				'https://woocommerce.com/wp-json/wccom-extensions/1.0/categories'
91
			);
92
			if ( ! is_wp_error( $raw_sections ) ) {
93
				$addon_sections = json_decode( wp_remote_retrieve_body( $raw_sections ) );
94
				if ( $addon_sections ) {
95
					set_transient( 'wc_addons_sections', $addon_sections, WEEK_IN_SECONDS );
96
				}
97
			}
98
		}
99
		return apply_filters( 'woocommerce_addons_sections', $addon_sections );
100
	}
101
102
	/**
103
	 * Get section for the addons screen.
104
	 *
105
	 * @param  string $section_id Required section ID.
106
	 *
107
	 * @return object|bool
108
	 */
109
	public static function get_section( $section_id ) {
110
		$sections = self::get_sections();
111
		if ( isset( $sections[ $section_id ] ) ) {
112
			return $sections[ $section_id ];
113
		}
114
		return false;
115
	}
116
117
	/**
118
	 * Get section content for the addons screen.
119
	 *
120
	 * @param  string $section_id Required section ID.
121
	 *
122
	 * @return array
123
	 */
124
	public static function get_section_data( $section_id ) {
125
		$section      = self::get_section( $section_id );
126
		$section_data = '';
127
128
		if ( ! empty( $section->endpoint ) ) {
129
			$section_data = get_transient( 'wc_addons_section_' . $section_id );
130
			if ( false === $section_data ) {
131
				$raw_section = wp_safe_remote_get( esc_url_raw( $section->endpoint ), array( 'user-agent' => 'WooCommerce Addons Page' ) );
132
133
				if ( ! is_wp_error( $raw_section ) ) {
134
					$section_data = json_decode( wp_remote_retrieve_body( $raw_section ) );
135
136
					if ( ! empty( $section_data->products ) ) {
137
						set_transient( 'wc_addons_section_' . $section_id, $section_data, WEEK_IN_SECONDS );
138
					}
139
				}
140
			}
141
		}
142
143
		return apply_filters( 'woocommerce_addons_section_data', $section_data->products, $section_id );
144
	}
145
146
	/**
147
	 * Handles the outputting of a contextually aware Storefront link (points to child themes if Storefront is already active).
148
	 */
149
	public static function output_storefront_button() {
150
		$template   = get_option( 'template' );
151
		$stylesheet = get_option( 'stylesheet' );
152
153
		if ( 'storefront' === $template ) {
154
			if ( 'storefront' === $stylesheet ) {
155
				$url         = 'https://woocommerce.com/product-category/themes/storefront-child-theme-themes/';
156
				$text        = __( 'Need a fresh look? Try Storefront child themes', 'woocommerce' );
157
				$utm_content = 'nostorefrontchildtheme';
158
			} else {
159
				$url         = 'https://woocommerce.com/product-category/themes/storefront-child-theme-themes/';
160
				$text        = __( 'View more Storefront child themes', 'woocommerce' );
161
				$utm_content = 'hasstorefrontchildtheme';
162
			}
163
		} else {
164
			$url         = 'https://woocommerce.com/storefront/';
165
			$text        = __( 'Need a theme? Try Storefront', 'woocommerce' );
166
			$utm_content = 'nostorefront';
167
		}
168
169
		$url = add_query_arg(
170
			array(
171
				'utm_source'   => 'addons',
172
				'utm_medium'   => 'product',
173
				'utm_campaign' => 'woocommerceplugin',
174
				'utm_content'  => $utm_content,
175
			),
176
			$url
177
		);
178
179
		echo '<a href="' . esc_url( $url ) . '" class="add-new-h2">' . esc_html( $text ) . '</a>' . "\n";
180
	}
181
182
	/**
183
	 * Handles the outputting of a banner block.
184
	 *
185
	 * @param object $block Banner data.
186
	 */
187 View Code Duplication
	public static function output_banner_block( $block ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
188
		?>
189
		<div class="addons-banner-block">
190
			<h1><?php echo esc_html( $block->title ); ?></h1>
191
			<p><?php echo esc_html( $block->description ); ?></p>
192
			<div class="addons-banner-block-items">
193
				<?php foreach ( $block->items as $item ) : ?>
194
					<?php if ( self::show_extension( $item ) ) : ?>
195
						<div class="addons-banner-block-item">
196
							<div class="addons-banner-block-item-icon">
197
								<img class="addons-img" src="<?php echo esc_url( $item->image ); ?>" />
198
							</div>
199
							<div class="addons-banner-block-item-content">
200
								<h3><?php echo esc_html( $item->title ); ?></h3>
201
								<p><?php echo esc_html( $item->description ); ?></p>
202
								<?php
203
									self::output_button(
204
										$item->href,
205
										$item->button,
206
										'addons-button-solid',
207
										$item->plugin
208
									);
209
								?>
210
							</div>
211
						</div>
212
					<?php endif; ?>
213
				<?php endforeach; ?>
214
			</div>
215
		</div>
216
		<?php
217
	}
218
219
	/**
220
	 * Handles the outputting of a column.
221
	 *
222
	 * @param object $block Column data.
223
	 */
224
	public static function output_column( $block ) {
225
		if ( isset( $block->container ) && 'column_container_start' === $block->container ) {
226
			?>
227
			<div class="addons-column-section">
228
			<?php
229
		}
230
		if ( 'column_start' === $block->module ) {
231
			?>
232
			<div class="addons-column">
233
			<?php
234
		} else {
235
			?>
236
			</div>
237
			<?php
238
		}
239
		if ( isset( $block->container ) && 'column_container_end' === $block->container ) {
240
			?>
241
			</div>
242
			<?php
243
		}
244
	}
245
246
	/**
247
	 * Handles the outputting of a column block.
248
	 *
249
	 * @param object $block Column block data.
250
	 */
251 View Code Duplication
	public static function output_column_block( $block ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
252
		?>
253
		<div class="addons-column-block">
254
			<h1><?php echo esc_html( $block->title ); ?></h1>
255
			<p><?php echo esc_html( $block->description ); ?></p>
256
			<?php foreach ( $block->items as $item ) : ?>
257
				<?php if ( self::show_extension( $item ) ) : ?>
258
					<div class="addons-column-block-item">
259
						<div class="addons-column-block-item-icon">
260
							<img class="addons-img" src="<?php echo esc_url( $item->image ); ?>" />
261
						</div>
262
						<div class="addons-column-block-item-content">
263
							<h2><?php echo esc_html( $item->title ); ?></h2>
264
							<?php
265
								self::output_button(
266
									$item->href,
267
									$item->button,
268
									'addons-button-solid',
269
									$item->plugin
270
								);
271
							?>
272
							<p><?php echo esc_html( $item->description ); ?></p>
273
						</div>
274
					</div>
275
				<?php endif; ?>
276
			<?php endforeach; ?>
277
		</div>
278
279
		<?php
280
	}
281
282
	/**
283
	 * Handles the outputting of a small light block.
284
	 *
285
	 * @param object $block Block data.
286
	 */
287 View Code Duplication
	public static function output_small_light_block( $block ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
288
		?>
289
		<div class="addons-small-light-block">
290
			<img class="addons-img" src="<?php echo esc_url( $block->image ); ?>" />
291
			<div class="addons-small-light-block-content">
292
				<h1><?php echo esc_html( $block->title ); ?></h1>
293
				<p><?php echo esc_html( $block->description ); ?></p>
294
				<div class="addons-small-light-block-buttons">
295
					<?php foreach ( $block->buttons as $button ) : ?>
296
						<?php
297
							self::output_button(
298
								$button->href,
299
								$button->text,
300
								'addons-button-solid'
301
							);
302
						?>
303
					<?php endforeach; ?>
304
				</div>
305
			</div>
306
		</div>
307
		<?php
308
	}
309
310
	/**
311
	 * Handles the outputting of a small dark block.
312
	 *
313
	 * @param object $block Block data.
314
	 */
315 View Code Duplication
	public static function output_small_dark_block( $block ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
316
		?>
317
		<div class="addons-small-dark-block">
318
			<h1><?php echo esc_html( $block->title ); ?></h1>
319
			<p><?php echo esc_html( $block->description ); ?></p>
320
			<div class="addons-small-dark-items">
321
				<?php foreach ( $block->items as $item ) : ?>
322
					<div class="addons-small-dark-item">
323
						<?php if ( ! empty( $item->image ) ) : ?>
324
							<div class="addons-small-dark-item-icon">
325
								<img class="addons-img" src="<?php echo esc_url( $item->image ); ?>" />
326
							</div>
327
						<?php endif; ?>
328
						<?php
329
							self::output_button(
330
								$item->href,
331
								$item->button,
332
								'addons-button-outline-white'
333
							);
334
						?>
335
					</div>
336
				<?php endforeach; ?>
337
			</div>
338
		</div>
339
		<?php
340
	}
341
342
	/**
343
	 * Handles the outputting of the WooCommerce Services banner block.
344
	 *
345
	 * @param object $block Block data.
346
	 */
347
	public static function output_wcs_banner_block( $block = array() ) {
348
		$is_active = is_plugin_active( 'woocommerce-services/woocommerce-services.php' );
349
		$location  = wc_get_base_location();
350
351
		if (
352
			! in_array( $location['country'], array( 'US', 'CA' ), true ) ||
353
			$is_active ||
354
			! current_user_can( 'install_plugins' ) ||
355
			! current_user_can( 'activate_plugins' )
356
		) {
357
			return;
358
		}
359
360
		$button_url = wp_nonce_url(
361
			add_query_arg(
362
				array(
363
					'install-addon' => 'woocommerce-services',
364
				)
365
			),
366
			'install-addon_woocommerce-services'
367
		);
368
369
		$defaults = array(
370
			'image'       => WC()->plugin_url() . '/assets/images/wcs-extensions-banner-3x.png',
371
			'image_alt'   => __( 'WooCommerce Services', 'woocommerce' ),
372
			'title'       => __( 'Buy discounted shipping labels — then print them from your dashboard.', 'woocommerce' ),
373
			'description' => __( 'Integrate your store with USPS to buy discounted shipping labels, and print them directly from your WooCommerce dashboard. Powered by WooCommerce Services.', 'woocommerce' ),
374
			'button'      => __( 'Free - Install now', 'woocommerce' ),
375
			'href'        => $button_url,
376
			'logos'       => array(),
377
		);
378
379
		switch ( $location['country'] ) {
380
			case 'CA':
381
				$local_defaults = array(
382
					'image'       => WC()->plugin_url() . '/assets/images/wcs-truck-banner-3x.png',
383
					'title'       => __( 'Show Canada Post shipping rates', 'woocommerce' ),
384
					'description' => __( 'Display live rates from Canada Post at checkout to make shipping a breeze. Powered by WooCommerce Services.', 'woocommerce' ),
385
					'logos'       => array_merge(
386
						$defaults['logos'],
387
						array(
388
							array(
389
								'link' => WC()->plugin_url() . '/assets/images/wcs-canada-post-logo.jpg',
390
								'alt'  => 'Canada Post logo',
391
							),
392
						)
393
					),
394
				);
395
				break;
396
			case 'US':
397
				$local_defaults = array(
398
					'logos' => array_merge(
399
						$defaults['logos'],
400
						array(
401
							array(
402
								'link' => WC()->plugin_url() . '/assets/images/wcs-usps-logo.png',
403
								'alt'  => 'USPS logo',
404
							),
405
						)
406
					),
407
				);
408
				break;
409
			default:
410
				$local_defaults = array();
411
		}
412
413
		$block_data = array_merge( $defaults, $local_defaults, $block );
414
		?>
415
		<div class="addons-wcs-banner-block">
416
			<div class="addons-wcs-banner-block-image">
417
				<img
418
					class="addons-img"
419
					src="<?php echo esc_url( $block_data['image'] ); ?>"
420
					alt="<?php echo esc_attr( $block_data['image_alt'] ); ?>"
421
				/>
422
			</div>
423
			<div class="addons-wcs-banner-block-content">
424
				<h1><?php echo esc_html( $block_data['title'] ); ?></h1>
425
				<p><?php echo esc_html( $block_data['description'] ); ?></p>
426
				<ul>
427
					<?php foreach ( $block_data['logos'] as $logo ) : ?>
428
						<li>
429
							<img
430
								alt="<?php echo esc_url( $logo['alt'] ); ?>"
431
								class="wcs-service-logo"
432
								src="<?php echo esc_url( $logo['link'] ); ?>"
433
							>
434
						</li>
435
					<?php endforeach; ?>
436
				</ul>
437
				<?php
438
					self::output_button(
439
						$block_data['href'],
440
						$block_data['button'],
441
						'addons-button-outline-green'
442
					);
443
				?>
444
			</div>
445
		</div>
446
		<?php
447
	}
448
449
	/**
450
	 * Handles the outputting of featured sections
451
	 *
452
	 * @param array $sections Section data.
453
	 */
454
	public static function output_featured_sections( $sections ) {
455
		foreach ( $sections as $section ) {
456
			switch ( $section->module ) {
457
				case 'banner_block':
458
					self::output_banner_block( $section );
459
					break;
460
				case 'column_start':
461
					self::output_column( $section );
0 ignored issues
show
Unused Code introduced by
The call to the method WC_Admin_Addons::output_column() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
462
					break;
463
				case 'column_end':
464
					self::output_column( $section );
0 ignored issues
show
Unused Code introduced by
The call to the method WC_Admin_Addons::output_column() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
465
					break;
466
				case 'column_block':
467
					self::output_column_block( $section );
468
					break;
469
				case 'small_light_block':
470
					self::output_small_light_block( $section );
471
					break;
472
				case 'small_dark_block':
473
					self::output_small_dark_block( $section );
474
					break;
475
				case 'wcs_banner_block':
476
					self::output_wcs_banner_block( (array) $section );
477
					break;
478
			}
479
		}
480
	}
481
482
	/**
483
	 * Returns in-app-purchase URL params.
484
	 */
485
	public static function get_in_app_purchase_url_params() {
486
		// Get url (from path onward) for the current page,
487
		// so WCCOM "back" link returns user to where they were.
488
		$back_admin_path = add_query_arg( array() );
489
		return array(
490
			'in-app-purchase-site'        => site_url(),
491
			'in-app-purchase-back'        => esc_url( $back_admin_path ),
492
			'in-app-purchase-woo-version' => WC_VERSION,
493
		);
494
	}
495
496
	/**
497
	 * Add in-app-purchase URL params to link.
498
	 *
499
	 * Adds various url parameters to a url to support a streamlined
500
	 * flow for obtaining and setting up WooCommerce extensons.
501
	 *
502
	 * @param string $url    Destination URL.
503
	 */
504
	public static function add_in_app_purchase_url_params( $url ) {
505
		return add_query_arg(
506
			self::get_in_app_purchase_url_params(),
507
			$url
508
		);
509
	}
510
511
	/**
512
	 * Outputs a button.
513
	 *
514
	 * @param string $url    Destination URL.
515
	 * @param string $text   Button label text.
516
	 * @param string $style  Button style class.
517
	 * @param string $plugin The plugin the button is promoting.
518
	 */
519
	public static function output_button( $url, $text, $style, $plugin = '' ) {
520
		$style = __( 'Free', 'woocommerce' ) === $text ? 'addons-button-outline-green' : $style;
521
		$style = is_plugin_active( $plugin ) ? 'addons-button-installed' : $style;
522
		$text  = is_plugin_active( $plugin ) ? __( 'Installed', 'woocommerce' ) : $text;
523
		$url   = self::add_in_app_purchase_url_params( $url );
524
		?>
525
		<a
526
			class="addons-button <?php echo esc_attr( $style ); ?>"
527
			href="<?php echo esc_url( $url ); ?>">
528
			<?php echo esc_html( $text ); ?>
529
		</a>
530
		<?php
531
	}
532
533
534
	/**
535
	 * Handles output of the addons page in admin.
536
	 */
537
	public static function output() {
538
		$section = isset( $_GET['section'] ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : '_featured';
539
		$search = isset( $_GET['search'] ) ? sanitize_text_field( wp_unslash( $_GET['search'] ) ) : '';
540
541
		if ( isset( $_GET['section'] ) && 'helper' === $_GET['section'] ) {
542
			do_action( 'woocommerce_helper_output' );
543
			return;
544
		}
545
546
		if ( isset( $_GET['install-addon'] ) && 'woocommerce-services' === $_GET['install-addon'] ) {
547
			self::install_woocommerce_services_addon();
548
		}
549
550
		$sections        = self::get_sections();
0 ignored issues
show
Unused Code introduced by
$sections is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
551
		$theme           = wp_get_theme();
0 ignored issues
show
Unused Code introduced by
$theme is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
552
		$current_section = isset( $_GET['section'] ) ? $section : '_featured';
553
		$addons          = array();
0 ignored issues
show
Unused Code introduced by
$addons is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
554
555
		if ( '_featured' !== $current_section ) {
556
			$category = $section ? $section : null;
557
			$term     = $search ? $search : null;
558
			$country  = WC()->countries->get_base_country();
559
			$addons   = self::get_extension_data( $category, $term, $country );
0 ignored issues
show
Unused Code introduced by
$addons is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
560
		}
561
562
		/**
563
		 * Addon page view.
564
		 *
565
		 * @uses $addons
566
		 * @uses $sections
567
		 * @uses $theme
568
		 * @uses $current_section
569
		 */
570
		include_once dirname( __FILE__ ) . '/views/html-admin-page-addons.php';
571
	}
572
573
	/**
574
	 * Install WooCommerce Services from Extensions screens.
575
	 */
576
	public static function install_woocommerce_services_addon() {
577
		check_admin_referer( 'install-addon_woocommerce-services' );
578
579
		$services_plugin_id = 'woocommerce-services';
580
		$services_plugin    = array(
581
			'name'      => __( 'WooCommerce Services', 'woocommerce' ),
582
			'repo-slug' => 'woocommerce-services',
583
		);
584
585
		WC_Install::background_installer( $services_plugin_id, $services_plugin );
586
587
		wp_safe_redirect( remove_query_arg( array( 'install-addon', '_wpnonce' ) ) );
588
		exit;
589
	}
590
591
	/**
592
	 * Should an extension be shown on the featured page.
593
	 *
594
	 * @param object $item Item data.
595
	 * @return boolean
596
	 */
597
	public static function show_extension( $item ) {
598
		$location = WC()->countries->get_base_country();
599
		if ( isset( $item->geowhitelist ) && ! in_array( $location, $item->geowhitelist, true ) ) {
600
			return false;
601
		}
602
603
		if ( isset( $item->geoblacklist ) && in_array( $location, $item->geoblacklist, true ) ) {
604
			return false;
605
		}
606
607
		if ( is_plugin_active( $item->plugin ) ) {
608
			return false;
609
		}
610
611
		return true;
612
	}
613
}
614