jetpack = $jetpack; } /** * Verify the intent to install WooCommerce Services, and kick off installation. */ public function try_install() { if ( ! isset( $_GET['wc-services-action'] ) ) { return; } check_admin_referer( 'wc-services-install' ); $result = false; switch ( $_GET['wc-services-action'] ) { case 'install': if ( current_user_can( 'install_plugins' ) ) { $this->jetpack->stat( 'jitm', 'wooservices-install-' . JETPACK__VERSION ); $result = $this->install(); if ( $result ) { $result = $this->activate(); } } break; case 'activate': if ( current_user_can( 'activate_plugins' ) ) { $this->jetpack->stat( 'jitm', 'wooservices-activate-' . JETPACK__VERSION ); $result = $this->activate(); } break; } if ( isset( $_GET['redirect'] ) ) { $redirect = home_url( esc_url_raw( wp_unslash( $_GET['redirect'] ) ) ); } else { $redirect = admin_url(); } if ( $result ) { $this->jetpack->stat( 'jitm', 'wooservices-activated-' . JETPACK__VERSION ); } else { $redirect = add_query_arg( 'wc-services-install-error', true, $redirect ); } wp_safe_redirect( $redirect ); exit; } /** * Set up installation error admin notice. */ public function add_error_notice() { if ( ! empty( $_GET['wc-services-install-error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended add_action( 'admin_notices', array( $this, 'error_notice' ) ); } } /** * Notify the user that the installation of WooCommerce Services failed. */ public function error_notice() { ?>