Completed
Push — woo/services-funnel ( 2be7ee...e318a8 )
by Jeff
08:04
created

WC_Services_Installer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A try_install() 0 9 2
B install() 0 28 4
1
<?php
2
3
if ( ! defined( 'ABSPATH' ) ) {
4
	exit;
5
}
6
7
class WC_Services_Installer {
8
9
	public function try_install() {
10
		$install = filter_input( INPUT_GET, 'wc-services-action' );
11
12
		if ( 'install' === $install ) {
13
			$this->install();
14
			wp_redirect( esc_url_raw( remove_query_arg( array( 'wc-services-action' ) ) ) );
15
			exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method try_install() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
16
		}
17
	}
18
19
	private function install() {
20
		include_once( ABSPATH . '/wp-admin/includes/admin.php' );
21
		include_once( ABSPATH . '/wp-admin/includes/plugin-install.php' );
22
		include_once( ABSPATH . '/wp-admin/includes/plugin.php' );
23
		include_once( ABSPATH . '/wp-admin/includes/class-wp-upgrader.php' );
24
		include_once( ABSPATH . '/wp-admin/includes/class-plugin-upgrader.php' );
25
26
		$api = plugins_api( 'plugin_information', array(
27
			'slug'   => 'connect-for-woocommerce',
28
		) );
29
30
		if ( is_wp_error( $api ) ) {
31
			wp_die( $api );
32
		}
33
34
		$upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
35
		$result   = $upgrader->install( $api->download_link );
36
37
		if ( is_wp_error( $result ) ) {
38
			wp_die( $result );
39
		}
40
41
		$result = activate_plugin( 'connect-for-woocommerce/woocommerce-connect-client.php' );
42
43
		if ( is_wp_error( $result ) ) {
44
			wp_die( $result );
45
		}
46
	}
47
}
48
49
$wc_services_installer = new WC_Services_Installer();
50
51
add_action( 'init', array( $wc_services_installer, 'try_install' ) );
52