1 | <?php |
||
7 | class WC_Services_Installer { |
||
8 | |||
9 | /** |
||
10 | * @var Jetpack |
||
11 | **/ |
||
12 | private $jetpack; |
||
13 | |||
14 | /** |
||
15 | * @var WC_Services_Installer |
||
16 | **/ |
||
17 | private static $instance = null; |
||
18 | |||
19 | static function init() { |
||
25 | |||
26 | public function __construct() { |
||
32 | |||
33 | /** |
||
34 | * Verify the intent to install WooCommerce Services, and kick off installation. |
||
35 | */ |
||
36 | public function try_install() { |
||
37 | if ( ! isset( $_GET['wc-services-action'] ) ) { |
||
38 | return; |
||
39 | } |
||
40 | check_admin_referer( 'wc-services-install' ); |
||
41 | |||
42 | $result = false; |
||
43 | |||
44 | switch ( $_GET['wc-services-action'] ) { |
||
45 | case 'install': |
||
46 | if ( current_user_can( 'install_plugins' ) ) { |
||
47 | $this->jetpack->stat( 'jitm', 'wooservices-install-' . JETPACK__VERSION ); |
||
48 | $result = $this->install(); |
||
49 | if ( $result ) { |
||
50 | $result = $this->activate(); |
||
51 | } |
||
52 | } |
||
53 | break; |
||
54 | |||
55 | case 'activate': |
||
56 | if ( current_user_can( 'activate_plugins' ) ) { |
||
57 | $this->jetpack->stat( 'jitm', 'wooservices-activate-' . JETPACK__VERSION ); |
||
58 | $result = $this->activate(); |
||
59 | } |
||
60 | break; |
||
61 | } |
||
62 | |||
63 | $redirect = isset( $_GET['redirect'] ) ? admin_url( $_GET['redirect'] ) : wp_get_referer(); |
||
64 | |||
65 | if ( $result ) { |
||
66 | $this->jetpack->stat( 'jitm', 'wooservices-activated-' . JETPACK__VERSION ); |
||
67 | } else { |
||
68 | $redirect = add_query_arg( 'wc-services-install-error', true, $redirect ); |
||
69 | } |
||
70 | |||
71 | wp_safe_redirect( $redirect ); |
||
72 | |||
73 | exit; |
||
|
|||
74 | } |
||
75 | |||
76 | /** |
||
77 | * Set up installation error admin notice. |
||
78 | */ |
||
79 | public function add_error_notice() { |
||
84 | |||
85 | /** |
||
86 | * Notify the user that the installation of WooCommerce Services failed. |
||
87 | */ |
||
88 | public function error_notice() { |
||
95 | |||
96 | /** |
||
97 | * Download and install the WooCommerce Services plugin. |
||
98 | * |
||
99 | * @return bool result of installation |
||
100 | */ |
||
101 | private function install() { |
||
119 | |||
120 | /** |
||
121 | * Activate the WooCommerce Services plugin. |
||
122 | * |
||
123 | * @return bool result of activation |
||
124 | */ |
||
125 | private function activate() { |
||
131 | } |
||
132 | |||
134 |
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.